Merge pull request #4 from jonjo-manywho/issue-1-nested-multipart-mails
Issue #1: Add support for nested multipart messages
This commit is contained in:
commit
6b866a0ddd
3 changed files with 17 additions and 10 deletions
|
@ -269,7 +269,13 @@ public final class WiserAssertions {
|
||||||
throws MessagingException, IOException {
|
throws MessagingException, IOException {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (int i = 0; i < mimeMultipart.getCount(); i++) {
|
for (int i = 0; i < mimeMultipart.getCount(); i++) {
|
||||||
sb.append(mimeMultipart.getBodyPart(i).getContent());
|
Object content = mimeMultipart.getBodyPart(i).getContent();
|
||||||
|
|
||||||
|
if (content instanceof MimeMultipart) {
|
||||||
|
sb.append(getMimeMultipartAsString((MimeMultipart) content));
|
||||||
|
} else {
|
||||||
|
sb.append(content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ public abstract class AbstractWiserTest {
|
||||||
|
|
||||||
protected Session getSession() {
|
protected Session getSession() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty("mail.transport.protocol", "smtp");
|
||||||
properties.setProperty("mail.smtp.host", "localhost");
|
properties.setProperty("mail.smtp.host", "localhost");
|
||||||
properties.setProperty("mail.smtp.port", "" + WiserAssertionsTest.PORT);
|
properties.setProperty("mail.smtp.port", "" + WiserAssertionsTest.PORT);
|
||||||
Session session = Session.getDefaultInstance(properties);
|
Session session = Session.getDefaultInstance(properties);
|
||||||
|
|
|
@ -14,24 +14,24 @@ import javax.mail.Message;
|
||||||
*/
|
*/
|
||||||
public class Issue1Test extends AbstractWiserTest {
|
public class Issue1Test extends AbstractWiserTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test {@link WiserAssertions#withContentContains(String)} where
|
||||||
|
* the nested multipart message contains the expected text
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldParseNestedMultiPartEmails() {
|
public void shouldParseNestedMultiPartEmails() {
|
||||||
//given
|
//given
|
||||||
final Email email = new Email();
|
final Email email = new Email();
|
||||||
email.addRecipient("Jonjo McKay", "jonjo.mckay@manywho.com",
|
email.addRecipient("Carl", "carl@b.com",
|
||||||
Message.RecipientType.TO);
|
Message.RecipientType.TO);
|
||||||
email.setFromAddress("ManyWho", "no-reply@manywho.com");
|
email.setFromAddress("Bob", "bob@a.com");
|
||||||
email.setSubject("New activity");
|
email.setSubject("Subject");
|
||||||
email.setText("Hi Jonjo McKay,\n\nA new message was just posted in a "
|
email.setText("Hi Carl,\n\nA new message was just posted.");
|
||||||
+ "stream you follow on ManyWho. The message was:\n\nLance "
|
|
||||||
+ "Drake Mandrell: \"This is a test message\"\n\nJoin the flow "
|
|
||||||
+ "at https://flow.manywho.com to read the stream and reply.\n"
|
|
||||||
+ "\nManyWho Email Bot");
|
|
||||||
Mailer mailer = new Mailer(getSession());
|
Mailer mailer = new Mailer(getSession());
|
||||||
//when
|
//when
|
||||||
mailer.sendMail(email);
|
mailer.sendMail(email);
|
||||||
//then
|
//then
|
||||||
getAssertions().withContent("Hi Jonjo McKay");
|
getAssertions().withContentContains("Hi Carl");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue