-
Notifications
You must be signed in to change notification settings - Fork 677
fix cc mailaddress display name Garbled on multibyte character #1329
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
Open
ken-takagi
wants to merge
7
commits into
playframework:master
Choose a base branch
from
ken-takagi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d891844
Update Mailer.java
ken-takagi b814932
Merge pull request #1 from ken-takagi/fix_mailer_cc_mail_display_name…
ken-takagi 2145557
Merge branch 'playframework:master' into master
ken-takagi 584637c
add test
4864f5b
Merge pull request #2 from ken-takagi/fix_mailer_cc_mail_display_name…
ken-takagi 04fbb81
fix unit test
7ff417d
Merge pull request #3 from ken-takagi/fix_mailer_cc_mail_display_name…
ken-takagi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package play.mvc; | ||
|
|
||
| import org.apache.commons.mail.Email; | ||
| import org.apache.commons.mail.EmailException; | ||
| import org.apache.commons.mail.SimpleEmail; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| public class MailerTest { | ||
| static class MailInitializer extends Mailer { | ||
| /** | ||
| * The method annotated with @Before seems to be executed in a separate thread from the test method. | ||
| * This method initializes thread-local variables and must be called at the beginning of the test method. | ||
| */ | ||
| public static void init() { | ||
| infos.set(new HashMap<>()); | ||
| } | ||
| public static void clear() { | ||
| infos.remove(); | ||
| } | ||
| } | ||
|
|
||
| private static String exampleAddress = "user@example.com"; | ||
| private static String multibyteCharAddress = "Eva Nováková <eva@example.com>"; | ||
| private static String encodedAddress = "=?UTF-8?Q?Eva_Nov=C3=A1kov=C3=A1?= <eva@example.com>"; | ||
|
|
||
| @Test | ||
| public void mailFromSupportsMultibyteCharAddress() throws EmailException { | ||
| MailInitializer.init(); | ||
| try { | ||
| Email email = new SimpleEmail(); | ||
| Mailer.addRecipient(exampleAddress); | ||
| Mailer.setFrom(multibyteCharAddress); | ||
| Mailer.setAddresses(email); | ||
| assertEquals(encodedAddress, email.getFromAddress().toString()); | ||
| } finally { | ||
| MailInitializer.clear(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void mailReplyToSupportsMultibyteCharAddress() throws EmailException { | ||
| MailInitializer.init(); | ||
| try { | ||
| Email email = new SimpleEmail(); | ||
| Mailer.addRecipient(exampleAddress); | ||
| Mailer.setReplyTo(multibyteCharAddress); | ||
| Mailer.setAddresses(email); | ||
| assertEquals(encodedAddress, email.getReplyToAddresses().get(0).toString()); | ||
| } finally { | ||
| MailInitializer.clear(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void mailToSupportsMultibyteCharAddress() throws EmailException { | ||
| MailInitializer.init(); | ||
| try { | ||
| Email email = new SimpleEmail(); | ||
| Mailer.addRecipient(multibyteCharAddress); | ||
| Mailer.setAddresses(email); | ||
| assertEquals(encodedAddress, email.getToAddresses().get(0).toString()); | ||
| } finally { | ||
| MailInitializer.clear(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void mailCcSupportsMultibyteCharAddress() throws EmailException { | ||
| MailInitializer.init(); | ||
| try { | ||
| Email email = new SimpleEmail(); | ||
| Mailer.addRecipient(exampleAddress); | ||
| Mailer.addCc(multibyteCharAddress); | ||
| Mailer.setAddresses(email); | ||
| assertEquals(encodedAddress, email.getCcAddresses().get(0).toString()); | ||
| } finally { | ||
| MailInitializer.clear(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void mailBccSupportsMultibyteCharAddress() throws EmailException { | ||
| MailInitializer.init(); | ||
| try { | ||
| Email email = new SimpleEmail(); | ||
| Mailer.addRecipient(exampleAddress); | ||
| Mailer.addBcc(multibyteCharAddress); | ||
| Mailer.setAddresses(email); | ||
| assertEquals(encodedAddress, email.getBccAddresses().get(0).toString()); | ||
| } finally { | ||
| MailInitializer.clear(); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why forced the charset to utf-8 here ? in the upper code you only set the charset if define ?
Do you mean that a default value is need ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xael-fry
This encoding fix was originally written, in line 543.
This line appears to have been moved to the setAddresses () method as it relates to setting addresses.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to keep the behavior of the original code.
In the original code, the encoding is changed to UTF-8 before setting the from, reply-to, to, cc, and bcc addresses, and is changed to
charsetbefore setting the subject.(I'm a co-worker of @ken-takagi and @yuba )