WiserAssertions: improve conversion of mime Multipart message to string

Previously the message was written to an output stream. Headers and mime
boundaries included. Assertions which use this method are looking at the
content of the message, rather than the wrappings.

Now we just look at the content of the multiparts.

Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
This commit is contained in:
Paul Campbell 2015-10-21 23:01:45 +01:00
parent 5fe7ec7cc4
commit 14cc99fd88

View file

@ -3,7 +3,6 @@ package net.kemitix.wiser.assertions;
import org.subethamail.wiser.Wiser; import org.subethamail.wiser.Wiser;
import org.subethamail.wiser.WiserMessage; import org.subethamail.wiser.WiserMessage;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
@ -256,7 +255,8 @@ public final class WiserAssertions {
} }
/** /**
* Converts a {@link MimeMultipart} into a {@link String}. * Converts a {@link MimeMultipart} into a {@link String} stripping out the
* mime part boundary and headers..
* *
* @param mimeMultipart the message part to convert * @param mimeMultipart the message part to convert
* *
@ -267,9 +267,11 @@ public final class WiserAssertions {
*/ */
private String getMimeMultipartAsString(final MimeMultipart mimeMultipart) private String getMimeMultipartAsString(final MimeMultipart mimeMultipart)
throws MessagingException, IOException { throws MessagingException, IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream(); final StringBuilder sb = new StringBuilder();
mimeMultipart.writeTo(os); for (int i = 0; i < mimeMultipart.getCount(); i++) {
return os.toString("UTF-8"); sb.append(mimeMultipart.getBodyPart(i).getContent());
}
return sb.toString();
} }
/** /**