From 3919c9d2d6483f432b14814bfd44875423a872ca Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 7 Dec 2014 03:31:58 +0100 Subject: [PATCH] Save multi part epilogue in MimeMultipart --- src/com/fsck/k9/mail/internet/MimeMessage.java | 6 ++++++ src/com/fsck/k9/mail/internet/MimeMultipart.java | 8 ++++++++ tests/src/com/fsck/k9/mail/ReconstructMessageTest.java | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/mail/internet/MimeMessage.java b/src/com/fsck/k9/mail/internet/MimeMessage.java index 8eb3dfe95..857d1ad76 100644 --- a/src/com/fsck/k9/mail/internet/MimeMessage.java +++ b/src/com/fsck/k9/mail/internet/MimeMessage.java @@ -2,6 +2,7 @@ package com.fsck.k9.mail.internet; import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -14,6 +15,7 @@ import java.util.Locale; import java.util.Set; import java.util.UUID; +import org.apache.commons.io.IOUtils; import org.apache.james.mime4j.MimeException; import org.apache.james.mime4j.dom.field.DateTimeField; import org.apache.james.mime4j.field.DefaultFieldParser; @@ -575,6 +577,10 @@ public class MimeMessage extends Message { @Override public void epilogue(InputStream is) throws IOException { + expect(MimeMultipart.class); + ByteArrayOutputStream epilogue = new ByteArrayOutputStream(); + IOUtils.copy(is, epilogue); + ((MimeMultipart) stack.peek()).setEpilogue(epilogue.toByteArray()); } @Override diff --git a/src/com/fsck/k9/mail/internet/MimeMultipart.java b/src/com/fsck/k9/mail/internet/MimeMultipart.java index 124ca5e4c..6775fdaea 100644 --- a/src/com/fsck/k9/mail/internet/MimeMultipart.java +++ b/src/com/fsck/k9/mail/internet/MimeMultipart.java @@ -11,6 +11,7 @@ import java.util.Random; public class MimeMultipart extends Multipart { private String mPreamble; + private byte[] mEpilogue; private String mContentType; @@ -53,6 +54,10 @@ public class MimeMultipart extends Multipart { this.mPreamble = preamble; } + public void setEpilogue(byte[] epilogue) { + mEpilogue = epilogue; + } + @Override public String getContentType() { return mContentType; @@ -90,6 +95,9 @@ public class MimeMultipart extends Multipart { writer.write(mBoundary); writer.write("--\r\n"); writer.flush(); + if (mEpilogue != null) { + out.write(mEpilogue); + } } @Override diff --git a/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java b/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java index 1e6528c99..e36854354 100644 --- a/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java +++ b/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java @@ -42,7 +42,8 @@ public class ReconstructMessageTest extends AndroidTestCase { "VGhpcyBpcyBhIHRl\r\n" + "c3QgbWVzc2FnZQ==\r\n" + "\r\n" + - "------Boundary--\r\n"; + "------Boundary--\r\n" + + "Hi, I'm the epilogue"; BinaryTempFileBody.setTempDirectory(getContext().getCacheDir());