Merge pull request #2903 from k9mail/decrypted-preamble

Don't ignore preamble and epilogue in decrypted messages
This commit is contained in:
cketti 2017-11-05 14:44:38 +01:00 committed by GitHub
commit cd5c4bf9a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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() + "'");
}
}
}
}