Skip to content

Conversation

andybalholm
Copy link

BODYSTRUCTURE responses from Dovecot for message/global attachments don't include the extra data that would be included for message/rfc822 attachments. So parsing them was returning an error. This PR makes that data optional.

@emersion emersion added the non-standard Interoperability with software violating the specs label Aug 3, 2025
@emersion
Copy link
Owner

emersion commented Aug 3, 2025

Marking as non-standard because this contradicts the spec:

body-type-msg   = media-message SP body-fields SP envelope
                  SP body SP body-fld-lines
media-message   = DQUOTE "MESSAGE" DQUOTE SP
                  DQUOTE ("RFC822" / "GLOBAL") DQUOTE
                    ; Defined in [MIME-IMT]

Would be nice to report a bug to Dovecot. Also we should add a comment to explain why we deviate from the spec.

if err != nil {
return nil, err
}
if err == nil {
Copy link
Owner

Choose a reason for hiding this comment

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

err is ignored when non-nil. We should never throw away an error value: it can happen for many reasons, e.g. I/O error.

Instead, we should only parse the envelope if there's one.

Copy link
Author

Choose a reason for hiding this comment

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

How can we detect whether the envelope is there or not? All I could figure out to do was to try to parse it and see if I got an error.

Copy link
Author

Choose a reason for hiding this comment

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

Does imapwire.Decoder have any sort of Peek or Unread feature?

@andybalholm
Copy link
Author

andybalholm commented Aug 4, 2025

According to section 6 of RFC 9755, treating message/global as equivalent to message/rfc822 is only required for IMAP4rev2. It's not quite clear to me, but it might not even be allowed under rev1 unless UTF8=ACCEPT has been enabled.

The BODYSTRUCTURE response for a message/global attachment may or may
not contain the data that would be included for message/rfc822.
In my experience with Dovecot, it does not.

Fixes emersion#678
@andybalholm
Copy link
Author

Adding a method to imapwire.Decoder enabled a much cleaner implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-standard Interoperability with software violating the specs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants