-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#230: properly handle missing address value in headers
- Loading branch information
Showing
3 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.simplejavamail.converter.internal.mimemessage; | ||
|
||
import org.assertj.core.api.ThrowableAssert; | ||
import org.junit.Test; | ||
import org.simplejavamail.converter.EmailConverter; | ||
import org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.ParsedMimeMessageComponents; | ||
|
@@ -9,11 +10,15 @@ | |
import org.simplejavamail.email.Recipient; | ||
import testutil.ConfigLoaderTestHelper; | ||
|
||
import javax.mail.internet.AddressException; | ||
import javax.mail.internet.InternetAddress; | ||
import javax.mail.util.ByteArrayDataSource; | ||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
import static javax.mail.Message.RecipientType.TO; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.moveInvalidEmbeddedResourcesToAttachments; | ||
|
||
public class MimeMessageParserTest { | ||
|
@@ -51,7 +56,37 @@ public void testMoveInvalidEmbeddedResourcesToAttachments_Invalid() throws IOExc | |
assertThat(parsedComponents.cidMap).containsOnlyKeys("moo1"); | ||
assertThat(parsedComponents.attachmentList).extracting("key").containsOnly("moo2"); | ||
} | ||
|
||
|
||
@Test | ||
public void testCreateAddress() throws AddressException, UnsupportedEncodingException { | ||
assertThat(interpretRecipient("[email protected]")).isEqualTo(new InternetAddress("[email protected]", null)); | ||
assertThat(interpretRecipient(" [email protected] ")).isEqualTo(new InternetAddress("[email protected]", null)); | ||
assertThat(interpretRecipient(" <[email protected]> ")).isEqualTo(new InternetAddress("[email protected]", null)); | ||
assertThat(interpretRecipient(" < [email protected] > ")).isEqualTo(new InternetAddress("[email protected]", null)); | ||
assertThat(interpretRecipient("moo <[email protected]>")).isEqualTo(new InternetAddress("[email protected]", "moo")); | ||
assertThat(interpretRecipient("moo<[email protected]>")).isEqualTo(new InternetAddress("[email protected]", "moo")); | ||
assertThat(interpretRecipient(" moo< [email protected] > ")).isEqualTo(new InternetAddress("[email protected]", "moo")); | ||
assertThat(interpretRecipient("\"moo\" <[email protected]>")).isEqualTo(new InternetAddress("[email protected]", "moo")); | ||
assertThat(interpretRecipient("\"moo\"<[email protected]>")).isEqualTo(new InternetAddress("[email protected]", "moo")); | ||
assertThat(interpretRecipient(" \"moo\"< [email protected] > ")).isEqualTo(new InternetAddress("[email protected]", "moo")); | ||
assertThat(interpretRecipient(" \" m oo \"< [email protected] > ")).isEqualTo(new InternetAddress("[email protected]", " m oo ")); | ||
assertThat(interpretRecipient("< >")).isNull(); | ||
|
||
// next one is unparsable by InternetAddress#parse(), so it should be taken as is | ||
assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { | ||
@Override | ||
public void call() throws Throwable { | ||
interpretRecipient(" \" m oo \" [email protected] "); | ||
} | ||
}) | ||
.isInstanceOf(MimeMessageParseException.class) | ||
.hasMessage("Error parsing [TO] address [ \" m oo \" [email protected] ]"); | ||
} | ||
|
||
private InternetAddress interpretRecipient(String address) { | ||
return MimeMessageParser.createAddress(address, "TO"); | ||
} | ||
|
||
@Test | ||
// https://github.com/bbottema/simple-java-mail/issues/227 | ||
public void testSemiColonSeparatedToAddresses() { | ||
|