Don't ignore preamble and epilogue in decrypted messages
package com.fsck.k9.mailstore;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -134,12 +135,18 @@ public class MimePartStreamParser {
@Override
public void preamble(InputStream is) throws MimeException, IOException {
- // Do nothing
+ expect(MimeMultipart.class);
+ ByteArrayOutputStream preamble = new ByteArrayOutputStream();
+ IOUtils.copy(is, preamble);
+ ((MimeMultipart)stack.peek()).setPreamble(preamble.toByteArray());
}
@Override
public void epilogue(InputStream is) throws MimeException, IOException {
- // Do nothing
+ expect(MimeMultipart.class);
+ ByteArrayOutputStream epilogue = new ByteArrayOutputStream();
+ IOUtils.copy(is, epilogue);
+ ((MimeMultipart) stack.peek()).setEpilogue(epilogue.toByteArray());
}
@Override
@@ -174,5 +181,12 @@ public class MimePartStreamParser {
public void raw(InputStream is) throws MimeException, IOException {
throw new IllegalStateException("Not implemented");
}
+
+ private void expect(Class<?> c) {
+ if (!c.isInstance(stack.peek())) {
+ throw new IllegalStateException("Internal stack error: " + "Expected '"
+ + c.getName() + "' found '" + stack.peek().getClass().getName() + "'");
+ }
+ }
}
}
