From 655e3144e22fdf4c47402f30ccad15c3f4186315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20Tonkovi=C4=87?= Date: Fri, 5 Jun 2026 10:25:57 +0200 Subject: [PATCH] Allow the text/plain part for bounce reason parsing Additionally, if a read error is encountered, skip the message and move to the next one. --- internal/bounce/mailbox/pop.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/bounce/mailbox/pop.go b/internal/bounce/mailbox/pop.go index c17150934..2b8ca0adb 100644 --- a/internal/bounce/mailbox/pop.go +++ b/internal/bounce/mailbox/pop.go @@ -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) @@ -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 } }