Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAP BODYSTRUCTURE parse error with long, encoded filenames #498

Closed
marcelmay opened this issue Nov 5, 2022 · 0 comments
Closed

IMAP BODYSTRUCTURE parse error with long, encoded filenames #498

marcelmay opened this issue Nov 5, 2022 · 0 comments
Labels
Milestone

Comments

@marcelmay
Copy link
Member

Based on #483 (thanks to @boris-petrov and @Mulgish for reporting):

When using MimeUtility#encodeText for creating mail with encoded and long attachment filename, the created mail contains an illegal CRLF in the Content-Disposition header.

SMTP trace, CRLF after 'esti?=':

13:39:34,487 (smtp:127.0.0.1:3025<-/127.0.0.1:63907) DEBUG         util.LineLoggingBuffer| C: Content-Disposition: attachment; \r\n
13:39:34,487 (smtp:127.0.0.1:3025<-/127.0.0.1:63907) DEBUG         util.LineLoggingBuffer| C: \tfilename*0="=?UTF-8?Q?=D0=BA=D0=B8=D1=80=D0=B8=D0=BB=D0=B8=D1=86=D0=B0_t"; \r\n

# UNEXPECTED CRLF IN NEXT LINE
13:39:34,488 (smtp:127.0.0.1:3025<-/127.0.0.1:63907) DEBUG         util.LineLoggingBuffer| C: \tfilename*1="esti?=\r\n

13:39:34,488 (smtp:127.0.0.1:3025<-/127.0.0.1:63907) DEBUG         util.LineLoggingBuffer| C:  =?UTF-8?Q?mage=5F=C3=BCnic=C3=B6de=5F=F0=9F=8C=B6?="\r\n

This will fail an IMAP client trying to read and parse the mail:

13:39:34,642 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| C: A4 FETCH 1 (BODYSTRUCTURE)\r\n
13:39:34,643 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| S: * 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("charset" "us-ascii") NIL NIL "7bit" 4 1 NIL NIL NIL)("IMAGE" "GIF" ("name*0" "=?UTF-8[WRAP]
13:39:34,643 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| S: ?Q?=D0=BA=D0=B8=D1=80=D0=B8=D0=BB=D0=B8=D1=86=D0=B0_t" "name*1" "esti?= =?UTF-8?Q?mage=5F=C3=BCnic=C3=B6de=5F=F0=9F=8C=B6?=") NIL[WRAP]
13:39:34,643 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| S:  "testimage_description" "base64" 4 NIL ("attachment" ("filename*0" "=?UTF-8?Q?=D0=BA=D0=B8=D1=80=D0=B8=D0=BB=D0=B8=D1=86=D0=B0_t[WRAP]

# UNEXPECTED CRLF IN NEXT LINE
13:39:34,643 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| S: " "filename*1" "esti?=\r\n

13:39:34,643 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| S:  =?UTF-8?Q?mage=5F=C3=BCnic=C3=B6de=5F=F0=9F=8C=B6?=")) NIL) "mixed" ("boundary" "----=_Part_0_1540374340.1667651974397") NIL NIL[WRAP]
13:39:34,643 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| S: ))\r\n
13:39:34,643 (imap:127.0.0.1:3143<-/127.0.0.1:63908) DEBUG         util.LineLoggingBuffer| S: A4 OK FETCH completed.\r\n

Failing client:

jakarta.mail.MessagingException: Unable to load BODYSTRUCTURE
	at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1540)
	at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:784)
	at jakarta.mail.internet.MimeMessage.getContent(MimeMessage.java:1484)

Seems related to line break for long filenames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant