commit 5acd8b1ba0702aa96c36c49046bdaada3f78008d from: Oliver Lowe date: Thu Mar 21 02:46:11 2024 UTC apub: handle unmarshalling from quoted-printable mail MailMate, for example, using quoted-printable encoding when lines are about 80 chars long. Blegh! commit - 16b05de44f3a6f511fad431d0ccf13bb44e744ad commit + 5acd8b1ba0702aa96c36c49046bdaada3f78008d blob - 458c8f0cb20eb90b6cf6df2fd6cf78733b74ee13 blob + 8c6ca2bbf8647620db0e563e89e85eb6c2c6fc87 --- mail.go +++ mail.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "mime/quotedprintable" "net/mail" "net/smtp" "strings" @@ -119,10 +120,6 @@ func UnmarshalMail(msg *mail.Message, client *Client) if strings.HasPrefix(ct, "multipart") { return nil, fmt.Errorf("cannot unmarshal from multipart message") } - enc := msg.Header.Get("Content-Transfer-Encoding") - if enc == "quoted-printable" { - return nil, fmt.Errorf("cannot decode message with transfer encoding: %s", enc) - } date, err := msg.Header.Date() if err != nil { @@ -181,7 +178,12 @@ func UnmarshalMail(msg *mail.Message, client *Client) } buf := &bytes.Buffer{} - if _, err := io.Copy(buf, msg.Body); err != nil { + if msg.Header.Get("Content-Transfer-Encoding") == "quoted-printable" { + _, err = io.Copy(buf, quotedprintable.NewReader(msg.Body)) + } else { + _, err = io.Copy(buf, msg.Body) + } + if err != nil { return nil, fmt.Errorf("read message body: %v", err) } content := strings.TrimSpace(strings.ReplaceAll(buf.String(), "\r", ""))