diff --git a/src/com/fsck/k9/mail/internet/BinaryTempFileBody.java b/src/com/fsck/k9/mail/internet/BinaryTempFileBody.java index f0dd6f473..dceec19e1 100644 --- a/src/com/fsck/k9/mail/internet/BinaryTempFileBody.java +++ b/src/com/fsck/k9/mail/internet/BinaryTempFileBody.java @@ -2,10 +2,7 @@ package com.fsck.k9.mail.internet; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.MessagingException; -import com.fsck.k9.mail.filter.Base64OutputStream; import org.apache.commons.io.IOUtils; -import org.apache.james.mime4j.codec.QuotedPrintableOutputStream; -import org.apache.james.mime4j.util.MimeUtil; import java.io.*; @@ -27,13 +24,12 @@ public class BinaryTempFileBody implements Body { } public void setEncoding(String encoding) throws MessagingException { - mEncoding = encoding; + mEncoding = encoding; } public BinaryTempFileBody() { if (mTempDirectory == null) { - throw new - RuntimeException("setTempDirectory has not been called on BinaryTempFileBody!"); + throw new RuntimeException("setTempDirectory has not been called on BinaryTempFileBody!"); } } @@ -54,22 +50,7 @@ public class BinaryTempFileBody implements Body { public void writeTo(OutputStream out) throws IOException, MessagingException { InputStream in = getInputStream(); try { - boolean closeStream = false; - if (MimeUtil.isBase64Encoding(mEncoding)) { - out = new Base64OutputStream(out); - closeStream = true; - } else if (MimeUtil.isQuotedPrintableEncoded(mEncoding)){ - out = new QuotedPrintableOutputStream(out, false); - closeStream = true; - } - - try { - IOUtils.copy(in, out); - } finally { - if (closeStream) { - out.close(); - } - } + IOUtils.copy(in, out); } finally { in.close(); } diff --git a/src/com/fsck/k9/mail/internet/MimeMessage.java b/src/com/fsck/k9/mail/internet/MimeMessage.java index 012f2c377..8eb3dfe95 100644 --- a/src/com/fsck/k9/mail/internet/MimeMessage.java +++ b/src/com/fsck/k9/mail/internet/MimeMessage.java @@ -531,8 +531,7 @@ public class MimeMessage extends Message { public void body(BodyDescriptor bd, InputStream in) throws IOException { expect(Part.class); try { - Body body = MimeUtility.decodeBody(in, - bd.getTransferEncoding(), bd.getMimeType()); + Body body = MimeUtility.createBody(in, bd.getTransferEncoding(), bd.getMimeType()); ((Part)stack.peek()).setBody(body); } catch (MessagingException me) { throw new Error(me); diff --git a/src/com/fsck/k9/mail/internet/MimeUtility.java b/src/com/fsck/k9/mail/internet/MimeUtility.java index 80efdf5c6..cdd63789e 100644 --- a/src/com/fsck/k9/mail/internet/MimeUtility.java +++ b/src/com/fsck/k9/mail/internet/MimeUtility.java @@ -1127,24 +1127,11 @@ public class MimeUtility { return false; } - /** - * Removes any content transfer encoding from the stream and returns a Body. - * @throws MessagingException - */ - public static Body decodeBody(InputStream in, - String contentTransferEncoding, String contentType) + public static Body createBody(InputStream in, String contentTransferEncoding, String contentType) throws IOException, MessagingException { - /* - * We'll remove any transfer encoding by wrapping the stream. - */ + if (contentTransferEncoding != null) { - contentTransferEncoding = - MimeUtility.getHeaderParameter(contentTransferEncoding, null); - if (MimeUtil.ENC_QUOTED_PRINTABLE.equalsIgnoreCase(contentTransferEncoding)) { - in = new QuotedPrintableInputStream(in); - } else if (MimeUtil.ENC_BASE64.equalsIgnoreCase(contentTransferEncoding)) { - in = new Base64InputStream(in); - } + contentTransferEncoding = MimeUtility.getHeaderParameter(contentTransferEncoding, null); } BinaryTempFileBody tempBody; @@ -1154,12 +1141,14 @@ public class MimeUtility { tempBody = new BinaryTempFileBody(); } tempBody.setEncoding(contentTransferEncoding); + OutputStream out = tempBody.getOutputStream(); try { IOUtils.copy(in, out); } finally { out.close(); } + return tempBody; } diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index 91406c838..cc714c0e6 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -25,8 +25,6 @@ import java.security.GeneralSecurityException; import java.security.Security; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Deque; @@ -1625,7 +1623,7 @@ public class ImapStore extends Store { .getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING)[0]; String contentType = part .getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]; - MimeMessageHelper.setBody(part, MimeUtility.decodeBody(bodyStream, + MimeMessageHelper.setBody(part, MimeUtility.createBody(bodyStream, contentTransferEncoding, contentType)); } else { // This shouldn't happen @@ -3594,7 +3592,7 @@ public class ImapStore extends Store { String contentType = mPart .getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]; - return MimeUtility.decodeBody(literal, contentTransferEncoding, + return MimeUtility.createBody(literal, contentTransferEncoding, contentType); } return null; diff --git a/tests/src/com/fsck/k9/mail/MessageTest.java b/tests/src/com/fsck/k9/mail/MessageTest.java index 054a3d01a..c5fc39c74 100644 --- a/tests/src/com/fsck/k9/mail/MessageTest.java +++ b/tests/src/com/fsck/k9/mail/MessageTest.java @@ -332,12 +332,12 @@ public class MessageTest extends AndroidTestCase { private MimeBodyPart binaryBodyPart() throws IOException, MessagingException { String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - + "abcdefghijklmnopqrstuvwxyz0123456789+/"; + + "abcdefghijklmnopqrstuvwxyz0123456789+/\r\n"; BinaryTempFileBody tempFileBody = new BinaryTempFileBody(); - InputStream in = new Base64InputStream(new ByteArrayInputStream( - encodedTestString.getBytes("UTF-8"))); + InputStream in = new ByteArrayInputStream( + encodedTestString.getBytes("UTF-8")); OutputStream out = tempFileBody.getOutputStream(); try { diff --git a/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java b/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java index 0989581cf..1e6528c99 100644 --- a/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java +++ b/tests/src/com/fsck/k9/mail/ReconstructMessageTest.java @@ -37,9 +37,10 @@ public class ReconstructMessageTest extends AndroidTestCase { "\r\n" + "------Boundary\r\n" + "Content-Type: text/plain\r\n" + - "Content-Transfer-Encoding: quoted-printable\r\n" + + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + - "=2E=2E=2E\r\n" + + "VGhpcyBpcyBhIHRl\r\n" + + "c3QgbWVzc2FnZQ==\r\n" + "\r\n" + "------Boundary--\r\n";