-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Describe the bug
If an incoming email contains an attachment, and attachments's filename contains:
- a whitespace
- AND is long enough for the client to perform folding
then the following error occurs:
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
DEBUG IMAP: trying to connect to host "linux-test-server.internal.inetsoftware.de", port 143, isSSL false
* OK IMAP4rev1 Server GreenMail v2.0.0-alpha-2 ready
A0 CAPABILITY
* CAPABILITY IMAP4rev1 LITERAL+ SORT UIDPLUS IDLE QUOTA
A0 OK CAPABILITY completed.
DEBUG IMAP: protocolConnect login, host=linux-test-server.internal.inetsoftware.de, user=sinssystems@sins.com, password=<non-null>
DEBUG IMAP: mechanism PLAIN not supported by server
DEBUG IMAP: mechanism LOGIN not supported by server
DEBUG IMAP: mechanism NTLM not supported by server
DEBUG IMAP: mechanism XOAUTH2 disabled by property: mail.imap.auth.xoauth2.disable
DEBUG IMAP: LOGIN command trace suppressed
DEBUG IMAP: LOGIN command result: A1 OK LOGIN completed.
A2 CAPABILITY
* CAPABILITY IMAP4rev1 LITERAL+ SORT UIDPLUS IDLE QUOTA
A2 OK CAPABILITY completed.
DEBUG IMAP: connection available -- size: 1
A3 EXAMINE inbox
* FLAGS (\Answered \Deleted \Draft \Flagged \Seen \*)
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1749633681]
* OK [UIDNEXT 41]
* OK [UNSEEN 1] Message 1 is the first unseen
* OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen \*)]
A3 OK [READ-ONLY] EXAMINE completed.
A4 SEARCH UNSEEN ALL
* SEARCH 1
A4 OK SEARCH completed.
1 mails
A5 FETCH 1 (BODYSTRUCTURE)
* 1 FETCH (BODYSTRUCTURE (("TEXT" "PLAIN" ("format" "flowed" "charset" "UTF-8") NIL NIL "7bit" 6 1 NIL NIL NIL)("APPLICATION" "PDF" ("name" "ReportQuarz_ua2_PAC_UA_Report_(3)d
fkkffkvmfmkvmfkmfvkfmkvmfkmfkv.pdf") NIL NIL "base64" 473870 NIL ("attachment" ("filename*1" "kmfkv.pdf" "filename*0" "ReportQuarz_ua2_PAC_UA_Report_(3)d fkkffkvmfmkvmfkmfvkfmkvmf")) NIL) "mixed" ("boundary" "------------AbFzpICJf2Pp3U60VY2l60LJ") NIL NIL))
DEBUG IMAP: ignoring bad response, THROW:
org.eclipse.angus.mail.iap.ParsingException: BODYSTRUCTURE parse error: APPLICATION/PDF: null name in parameter list
at org.eclipse.angus.mail.imap.protocol.BODYSTRUCTURE.parseParameters(BODYSTRUCTURE.java:411)
at org.eclipse.angus.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:231)
at org.eclipse.angus.mail.imap.protocol.BODYSTRUCTURE.<init>(BODYSTRUCTURE.java:87)
at org.eclipse.angus.mail.imap.protocol.FetchResponse.parseItem(FetchResponse.java:243)
at org.eclipse.angus.mail.imap.protocol.FetchResponse.parse(FetchResponse.java:195)
at org.eclipse.angus.mail.imap.protocol.FetchResponse.<init>(FetchResponse.java:79)
at org.eclipse.angus.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:415)
at org.eclipse.angus.mail.iap.Protocol.command(Protocol.java:378)
at org.eclipse.angus.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2158)
at org.eclipse.angus.mail.imap.protocol.IMAPProtocol.fetch(IMAPProtocol.java:2150)
at org.eclipse.angus.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:1724)
at org.eclipse.angus.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1566)
at org.eclipse.angus.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:613)
at Sample.main(Sample.java:33)
It seems to only have problems if the headers in the email looks like this:
--------------AbFzpICJf2Pp3U60VY2l60LJ
Content-Type: application/pdf; name="ReportQuarz_ua2_PAC_UA_Report_(3)d
fkkffkvmfmkvmfkmfvkfmkvmfkmfkv.pdf"
Content-Disposition: attachment;
filename*0="ReportQuarz_ua2_PAC_UA_Report_(3)d fkkffkvmfmkvmfkmfvkfmkvmf";
filename*1="kmfkv.pdf"
Content-Transfer-Encoding: base64
The client sending the email...
- use quotes for the Content-type name-parameter, because it contains a special character '( )'
- is deciding to insert a "folding white space" because the line will be longer than 78 characters and there is a space in the filename (see RFC 5322 section 2.3.3 /3.2.2 / 3.2.4) - as far as I understood, it is correct to do this.
In this case angus cannot read the body. Maybe it misses the unfolding of the folding white spaces (FWS) in case of quoted strings.
haha - agarth (agarth@stone.age) - 2025-09-04 1606.eml
To Reproduce
- Send an email to a receiver, attach a file with a name of 100 characters or more which contains a space and a bracket. Or put attached email in your receiver inbox.
- Read the mail from the account using angus mail api, see example attached
Expected behavior
The example should read the mail without any issues.
Screenshots
Desktop (please complete the following information):
- OS: win11
- Browser n/a
- Version angus-mail-2.0.4
Mail server:
- Protocol being used: imap
Additional context
Email clients seems to behave different in when to insert folding white spaces in the header-parameter. The attached email was created with thunderbird 140.2.1esr