~rjarry/aerc#7: 
aerc tries to parse message bodies as headers

I keep getting errors "malformed MIME header line" or "malformed MIME header key", and I know that aerc uses go-message to fetch and parse IMAP messages.

So, I created a github issue in go-message repository with examples and detailed explanation: https://github.com/emersion/go-message/issues/144

But it's maintainer said:

Seems like an aerc bug. It tries to parse message bodies as headers.

UPD: After discovering this fork, I tried again with aerc-0.6.0 -- problem persists

Status
REPORTED
Submitter
~banderlog
Assigned to
Submitted
2 years ago
Updated
1 year, 7 months ago
Labels
bug

~banderlog 2 years ago

Before I tried v0.5.2 and 0b19b5e70e408bbaac5555b0b61a9451189406f8 commit (latest from old repo)

~rjarry 2 years ago

I cannot reproduce the issue with the example message you provided. Did you check with the current master?

~heywoodlh 1 year, 10 months ago

I am also experiencing this issue using Davmail to interface with my corporate O365 instance. My other accounts don't have issues but the Davmail account does.

Currently on aerc version 0.13.0.

~finnekit 1 year, 7 months ago*

Can confirm issue still persist with aerc with davmail

aerc 0.14.0 +notmuch (go1.19.6 amd64 linux)

davmail 6.0.1.3390-5

I saved the email via :pipe -m tee emailfile

heres the results of cat -vE emailfile

https://paste.sr.ht/~finnekit/4696fd71a49f7f93e87d8853fd0fe07e73305ed6

(X-MS-Exchange and Received: header has been stripped out to help readability)

Screenshot of error: https://not-a.link/4tAKFBw.png

We also believe the error is caused by aerc parsing message bodies as headers.

~rjarry 1 year, 7 months ago

Hi there,

I tried importing that message you pasted. I cannot reproduce the issue. I don't have any o365 account to test this properly.

My wild guess is that o365 sends messages that do not comply with go-message parsing. Would you have a way to export the complete headers in a raw paste?

:pipe -m tee email-relou.eml

And send it as is without any edition/redaction. Thanks.

~finnekit 1 year, 7 months ago

Here you go, https://not-a.link/9vwU4KY.eml Please let me know if there is anything else you need. I don't think its o365, but instead davmail, the daemon that we use to access o365 via modernAuth.

~rjarry 1 year, 7 months ago

I still cannot reproduce :(

I imported that message using :import-mbox into an empty folder. I added a dummy

From foo@bar

line on top to make the mbox parser happy, and I have no issues opening it. My IMAP provider is Gmail. That is most likely the difference here.

Could you try applying that diff locally and reproduce the error:

diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go
index 62451308af99..91d48667b2cd 100644
--- a/worker/imap/fetch.go
+++ b/worker/imap/fetch.go
@@ -2,6 +2,7 @@ package imap
 
 import (
 	"bufio"
+	"bytes"
 	"fmt"
 
 	"github.com/emersion/go-imap"
@@ -53,8 +54,11 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders(
 			if reader == nil {
 				return fmt.Errorf("failed to find part: %v", section)
 			}
-			textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(reader))
+			buf := make([]byte, 65536)
+			_, _ = reader.Read(buf)
+			textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(bytes.NewReader(buf)))
 			if err != nil {
+				log.Errorf("wtf: %s", buf)
 				return fmt.Errorf("failed to read part header: %w", err)
 			}
 			header := &mail.Header{Header: message.Header{Header: textprotoHeader}}
@@ -122,11 +126,13 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart(
 			if body == nil {
 				return fmt.Errorf("failed to find part: %v", partHeaderSection)
 			}
-			h, err := textproto.ReadHeader(bufio.NewReader(body))
+			buf := make([]byte, 65536)
+			_, _ = body.Read(buf)
+			h, err := textproto.ReadHeader(bufio.NewReader(bytes.NewReader(buf)))
 			if err != nil {
+				log.Errorf("wtf: %s", buf)
 				return fmt.Errorf("failed to read part header: %w", err)
 			}
-
 			part, err := message.New(message.Header{Header: h},
 				_msg.GetBody(&partBodySection))
 			if message.IsUnknownCharset(err) {

And share the wtf: log lines (possibly with some context around them if you can).

Thanks.

~finnekit (edited) 1 year, 7 months ago*

ERROR 2023/03/09 18:43:26.690076 fetch.go:133: wtf: FOOBAR: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras portt=
itor ante a mollis ultricies. Mauris sed dignissim massa, non finibus felis=
. Maecenas ut leo at diam tempus malesuada a vel nulla. In posuere elit nec=
 ante facilisis ullamcorper. Nullam rutrum quam eget eros scelerisque, vene=
natis maximus sapien auctor. Morbi dui enim, congue ut augue ut, rhoncus so=
dales odio. Sed lobortis lectus est, in lacinia neque sagittis nec. Nunc le=
ctus neque, facilisis rhoncus urna at, volutpat rhoncus lorem. Mauris sit a=
met quam sed augue gravida vestibulum id sit amet est. Praesent auctor sapi=
en eget erat condimentum, at imperdiet urna varius. Morbi suscipit tincidun=
t sem, eget feugiat nunc. Nunc feugiat posuere rutrum. Duis non tellus et t=
urpis accumsan sollicitudin. Aenean sodales eleifend volutpat.

https://not-a.link/7iQrwin.png

~finnekit 1 year, 7 months ago

You can try to reproduce the error with davmail and an outlook account, if you wish.

~poldi1405 1 year, 7 months ago

I have a setup that allows me to reproduce this.

Register here or Log in to comment, or comment via email.