Skip to content
Open
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
19 changes: 14 additions & 5 deletions internal/bounce/mailbox/pop.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (p *POP) Scan(limit int, ch chan models.Bounce) error {
}

// Download messages.
MESSAGES_LOOP:
for id := 1; id <= count; id++ {
// Retrieve the raw bytes of the message.
b, err := c.RetrRaw(id)
Expand All @@ -123,16 +124,24 @@ func (p *POP) Scan(limit int, ch chan models.Bounce) error {

h := m

// If this is a multipart message, find the last part.
// If this is a multipart message, prefer the text/plain part, otherwise use the last part.
if mr := m.MultipartReader(); mr != nil {
for {
part, err := mr.NextPart()
if err == io.EOF {
break
} else if err != nil {
if err == nil {
if strings.HasPrefix(strings.ToLower(part.Header.Get("Content-Type")), "text/plain") {
h = part
break
}
} else {
if err == io.EOF {
break
}

p.lo.Printf("error reading multipart bounce message %d: %v", id, err)
continue
continue MESSAGES_LOOP
}

h = part
}
}
Expand Down