From 14cc99fd886997db83eda9346bb23d893c58425c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 21 Oct 2015 23:01:45 +0100 Subject: [PATCH] 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 --- .../kemitix/wiser/assertions/WiserAssertions.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java b/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java index 9ed4f29..a2fc2b6 100644 --- a/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java +++ b/src/main/java/net/kemitix/wiser/assertions/WiserAssertions.java @@ -3,7 +3,6 @@ package net.kemitix.wiser.assertions; import org.subethamail.wiser.Wiser; import org.subethamail.wiser.WiserMessage; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.text.MessageFormat; 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 * @@ -267,9 +267,11 @@ public final class WiserAssertions { */ private String getMimeMultipartAsString(final MimeMultipart mimeMultipart) throws MessagingException, IOException { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - mimeMultipart.writeTo(os); - return os.toString("UTF-8"); + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < mimeMultipart.getCount(); i++) { + sb.append(mimeMultipart.getBodyPart(i).getContent()); + } + return sb.toString(); } /**