Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ func parseMultiPartBody(root *Part, e *Envelope) error {

// Locate attachments
e.Attachments = root.BreadthMatchAll(func(p *Part) bool {
return p.Disposition == cdAttachment || p.ContentType == ctAppOctetStream
return (p.Disposition == cdAttachment || p.ContentType == ctAppOctetStream) && p.ContentID == "" && p.FileName != ""
})

// Locate inlines
e.Inlines = root.BreadthMatchAll(func(p *Part) bool {
return p.Disposition == cdInline && !strings.HasPrefix(p.ContentType, ctMultipartPrefix)
return p.Disposition == cdInline && !strings.HasPrefix(p.ContentType, ctMultipartPrefix) && p.ContentID != ""
})

// Locate others parts not considered in attachments or inlines
Expand Down
1 change: 0 additions & 1 deletion envelope_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build go1.18
// +build go1.18

package enmime

Expand Down
9 changes: 5 additions & 4 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package enmime
import (
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -117,16 +118,16 @@ func TestErrorEnvelopeWarnings(t *testing.T) {
}
}
if !satisfied {
var errorList string
var errorList strings.Builder
for _, perr := range e.Errors {
errorList += perr.Error()
errorList += "\n"
errorList.WriteString(perr.Error())
errorList.WriteString("\n")
}
t.Errorf(
"File %q should have error of type %q, got these instead:\n%s",
tt.filename,
tt.perror,
errorList)
errorList.String())
}
})
}
Expand Down
9 changes: 7 additions & 2 deletions internal/textproto/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err err
func (r *Reader) ReadResponse(expectCode int) (code int, message string, err error) {
code, continued, message, err := r.readCodeLine(expectCode)
multi := continued
var messageBuilder strings.Builder
messageBuilder.WriteString(message)
for continued {
line, err := r.ReadLine()
if err != nil {
Expand All @@ -283,12 +285,15 @@ func (r *Reader) ReadResponse(expectCode int) (code int, message string, err err
var moreMessage string
code2, continued, moreMessage, err = parseCodeLine(line, 0)
if err != nil || code2 != code {
message += "\n" + strings.TrimRight(line, "\r\n")
messageBuilder.WriteString("\n")
messageBuilder.WriteString(strings.TrimRight(line, "\r\n"))
continued = true
continue
}
message += "\n" + moreMessage
messageBuilder.WriteString("\n")
messageBuilder.WriteString(moreMessage)
}
message = messageBuilder.String()
if err != nil && multi && message != "" {
// replace one line error message with all lines (full message)
err = &textproto.Error{Code: code, Msg: message}
Expand Down
4 changes: 3 additions & 1 deletion internal/textproto/textproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package textproto

import (
"bufio"
"context"
"io"
"net"
)
Expand Down Expand Up @@ -59,7 +60,8 @@ func (c *Conn) Close() error {
// Dial connects to the given address on the given network using net.Dial
// and then returns a new Conn for the connection.
func Dial(network, addr string) (*Conn, error) {
c, err := net.Dial(network, addr)
d := &net.Dialer{}
c, err := d.DialContext(context.Background(), network, addr)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions testdata/mail/inlinemultipart.raw
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ cmNlIChXZUpYRnh

--0__=4EBB0828DFD318FF8f9e8a93df938690918c4EBB0828DFD318FF
Content-Type: text/plain; name="test.txt"; name="test.txt"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="test.txt"
Content-Disposition: inline; filename="test.txt"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless I'm missing something, we should be introducing a new testdata file, or adding a new attachment to this one instead of modifying the existing one.

Content-Id: <8B8481A2-25CA-4886-9B5A-8EB9115DD064@skynet>

Text attachment.

Expand Down
Loading