eclipse-ee4j / eclipse-ee4j/angus-mail

POP3Message ignores allowutf8 flag when loading headers

Open
#190 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
87
Forks
23
PR merge metrics
No merged PRs in 30d

Description

When `mail.mime.allowutf8` is set to `true` in a POP3 session, the expectation is that header values (e.g. to address) in a message will be parsed as UTF-8, however `org.eclipse.angus.mail.pop3.POP3Message#loadHeaders` is using the `InternetHeaders(InputStream)` constructor, which defaults to not allowing UTF-8. This means that if receiving an email sent to an address with non-ASCII characters in it, e.g. `böb@example.com`, the UTF-8 encoded bytes will be decoded as ISO-8859-1, resulting in an incorrect value.

**To Reproduce**
Steps to reproduce the behavior:

1. Send an email with a to address containing non-ASCII characters (such as `böb@example.com`), if necessary using something like Mailpit which supports SMTPUTF8 and also POP3.
2. Using the Jakarta Mail API, retrieve the message via POP3, with `mail.mime.allowutf8` set to `true` in the session properties.

**Expected behavior**

The value of the parsed To header should be exactly the same as the original To address specified, with any unicode characters unmolested.

This should be trivial to fix, as `jakarta.mail.internet.MimeMessage` has a private `allowutf8` field that is correctly set when `mail.mime.allowutf8` has been set to `true`, and has a `createInternetHeaders(InputStream)` method as below:
```
protected InternetHeaders createInternetHeaders(InputStream is)
throws MessagingException {
return new InternetHeaders(is, allowutf8);
}
```
This method could be called by `POP3Message#loadHeaders` instead of it using the `InternetHeaders(InputStream)` constructor directly, and that should result in the correct behaviour.

Contributor guide

Open the contributing guide

Research direction

Start in POP3Message#loadHeaders and compare its InternetHeaders construction with MimeMessage#createInternetHeaders(InputStream), using the issue's allowutf8 behavior as the guide. Reproduce with a POP3 message addressed to böb@example.com and verify that the parsed To header preserves the original Unicode address.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.