eclipse-ee4j / eclipse-ee4j/angus-mail
ParsingException on email-reading if mail-attachment's filename is folded
- Dominant language
- Java
- Stars
- 87
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
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=
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.(BODYSTRUCTURE.java:231)
at org.eclipse.angus.mail.imap.protocol.BODYSTRUCTURE.(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.(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](https://github.com/user-attachments/files/22140745/haha.-.agarth.agarth%40stone.age.-.2025-09-04.1606.eml)
[Sample.java](https://github.com/user-attachments/files/22140800/Sample.java)
**To Reproduce**
1. 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.
2. 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
Contributor guide
Research direction
Start with org.eclipse.angus.mail.imap.protocol.BODYSTRUCTURE.java, especially parseParameters at the reported stack-trace location, and use Sample.java with the attached .eml file to reproduce the BODYSTRUCTURE failure. Done means the provided folded attachment filename is parsed successfully and the sample reads the message without a ParsingException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100