jakartaee / jakartaee/mail-api
ParameterList fails to parse filename from Content-Disposition header encoded in UTF-8 with Q encoding
- Dominant language
- Java
- Stars
- 285
- Forks
- 109
- Avg merge
- 15h 19m
- Merged PRs (30d)
- 1
Description
**Describe the bug**
We are using the mail-api to parse incoming emails (MimeMessages), we received a particular email with a PDF attachment.
The filename of this attachment is encoded in the Content-Disposition header in a "weird" way.
This leads to the following exception
Stacktrace:
```
Caused by: jakarta.mail.internet.ParseException: In parameter list <;
filename==?utf-8?Q?XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXXXXXXXXXX?=
=?utf-8?Q?XXXXXXXXXXXXXXXXXXX=2Epdf?=;
filename*0*=utf-8''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXX;
filename*1*=XXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf>, expected parameter value, got "="
at jakarta.mail.internet.ParameterList.(ParameterList.java:273)
at jakarta.mail.internet.ContentDisposition.(ContentDisposition.java:86)
at jakarta.mail.internet.MimeBodyPart.getDisposition(MimeBodyPart.java:1239)
at jakarta.mail.internet.MimeBodyPart.getDisposition(MimeBodyPart.java:327)
```
After googling I found that the header is encoded in "Q encoding" (https://en.wikipedia.org/wiki/MIME#Difference_between_Q-encoding_and_quoted-printable) It is also mentioned in RFC2047 (https://www.ietf.org/rfc/rfc2047.txt).
The method jakarta.mail.internet.MimeUtility.decodeText(String etext) is actually able to parse such strings.
**To Reproduce**
See test cases in attached pull request #688
**Expected behavior**
See test cases in attached pull request #688
**Envorinment:**
- Version: 2.0.1
Contributor guide
Research direction
Start with jakarta.mail.internet.ParameterList.java around the failing line 273 and compare its handling of the header with MimeUtility.decodeText(String etext). Use the test cases referenced in pull request #688 to reproduce the UTF-8 Q-encoded filename, then verify the expected behavior described there.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100