-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from HubSpot/src_fix_envelopeparser
Add log to collect info about imap envelope parsing issue
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 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
78 changes: 78 additions & 0 deletions
78
src/test/java/com/hubspot/imap/utils/parsers/EnvelopeParserTest.java
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.hubspot.imap.utils.parsers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import com.hubspot.imap.protocol.message.Envelope; | ||
import com.hubspot.imap.protocol.message.ImapAddress; | ||
import com.hubspot.imap.utils.parsers.fetch.EnvelopeParser; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.Test; | ||
|
||
public class EnvelopeParserTest { | ||
|
||
@Test | ||
public void testParseWithAllElements() { | ||
List<Object> envelopeResponse = Arrays.asList( | ||
"Tue, 21 Jul 2015 16:02:13 EDT", // date | ||
"Test Subject", // subject | ||
Arrays.asList(List.of("John Doe", "smtp", "john.doe", "example.com")), // from | ||
Arrays.asList(List.of("Jane Doe", "smtp", "jane.doe", "example.com")), // sender | ||
Arrays.asList(List.of("Reply To", "smtp", "reply.to", "example.com")), // reply-to | ||
Arrays.asList(List.of("Recipient", "smtp", "recipient", "example.com")), // to | ||
Arrays.asList(List.of("CC", "smtp", "cc", "example.com")), // cc | ||
Arrays.asList(List.of("BCC", "smtp", "bcc", "example.com")), // bcc | ||
"In-Reply-To", // in-reply-to | ||
"Message-ID" // message-id | ||
); | ||
|
||
Envelope envelope = EnvelopeParser.parse(envelopeResponse); | ||
|
||
assertThat(envelope.getDateString()).isEqualTo("Tue, 21 Jul 2015 16:02:13 EDT"); | ||
assertThat(envelope.getSubject()).isEqualTo("Test Subject"); | ||
assertThat(envelope.getFrom()) | ||
.extracting(ImapAddress::getAddress) | ||
.containsExactly("[email protected]"); | ||
assertThat(envelope.getSender()) | ||
.extracting(ImapAddress::getAddress) | ||
.containsExactly("[email protected]"); | ||
assertThat(envelope.getReplyTo()) | ||
.extracting(ImapAddress::getAddress) | ||
.containsExactly("[email protected]"); | ||
assertThat(envelope.getTo()) | ||
.extracting(ImapAddress::getAddress) | ||
.containsExactly("[email protected]"); | ||
assertThat(envelope.getCc()) | ||
.extracting(ImapAddress::getAddress) | ||
.containsExactly("[email protected]"); | ||
assertThat(envelope.getBcc()) | ||
.extracting(ImapAddress::getAddress) | ||
.containsExactly("[email protected]"); | ||
assertThat(envelope.getInReplyTo()).isEqualTo("In-Reply-To"); | ||
assertThat(envelope.getMessageId()).isEqualTo("Message-ID"); | ||
} | ||
|
||
@Test | ||
public void testParseWithOnly9Elements() { | ||
List<Object> envelopeResponse = Arrays.asList( | ||
"Tue, 21 Jul 2015 16:02:13 EDT", // date | ||
"Test Subject", // subject | ||
Arrays.asList(List.of("John Doe", "smtp", "john.doe", "example.com")), // from | ||
Arrays.asList(List.of("Jane Doe", "smtp", "jane.doe", "example.com")), // sender | ||
Arrays.asList(List.of("Reply To", "smtp", "reply.to", "example.com")), // reply-to | ||
Arrays.asList(List.of("Recipient", "smtp", "recipient", "example.com")), // to | ||
Arrays.asList(List.of("CC", "smtp", "cc", "example.com")), // cc | ||
Arrays.asList(List.of("BCC", "smtp", "bcc", "example.com")), // bcc | ||
// missing in-reply-to | ||
"Message-ID" // message-id | ||
); | ||
|
||
assertThrows( | ||
ArrayIndexOutOfBoundsException.class, | ||
() -> { | ||
EnvelopeParser.parse(envelopeResponse); | ||
} | ||
); | ||
} | ||
} |