diff --git a/k9mail/src/main/java/com/fsck/k9/mailstore/MimePartStreamParser.java b/k9mail/src/main/java/com/fsck/k9/mailstore/MimePartStreamParser.java index 8ece00d09..6b21a8229 100644 --- a/k9mail/src/main/java/com/fsck/k9/mailstore/MimePartStreamParser.java +++ b/k9mail/src/main/java/com/fsck/k9/mailstore/MimePartStreamParser.java @@ -1,6 +1,7 @@ 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() + "'"); + } + } } }