mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-19 20:21:45 -05:00
Modify BinaryTempFileBody to retain the encoded body
For now this breaks a lot of things, e.g. saving messages to the database and making messages 7-bit safe.
This commit is contained in:
parent
d32d6eed0e
commit
9f4f0cf6a8
@ -2,10 +2,7 @@ package com.fsck.k9.mail.internet;
|
|||||||
|
|
||||||
import com.fsck.k9.mail.Body;
|
import com.fsck.k9.mail.Body;
|
||||||
import com.fsck.k9.mail.MessagingException;
|
import com.fsck.k9.mail.MessagingException;
|
||||||
import com.fsck.k9.mail.filter.Base64OutputStream;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.james.mime4j.codec.QuotedPrintableOutputStream;
|
|
||||||
import org.apache.james.mime4j.util.MimeUtil;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@ -32,8 +29,7 @@ public class BinaryTempFileBody implements Body {
|
|||||||
|
|
||||||
public BinaryTempFileBody() {
|
public BinaryTempFileBody() {
|
||||||
if (mTempDirectory == null) {
|
if (mTempDirectory == null) {
|
||||||
throw new
|
throw new RuntimeException("setTempDirectory has not been called on BinaryTempFileBody!");
|
||||||
RuntimeException("setTempDirectory has not been called on BinaryTempFileBody!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,23 +49,8 @@ public class BinaryTempFileBody implements Body {
|
|||||||
|
|
||||||
public void writeTo(OutputStream out) throws IOException, MessagingException {
|
public void writeTo(OutputStream out) throws IOException, MessagingException {
|
||||||
InputStream in = getInputStream();
|
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 {
|
try {
|
||||||
IOUtils.copy(in, out);
|
IOUtils.copy(in, out);
|
||||||
} finally {
|
|
||||||
if (closeStream) {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
@ -531,8 +531,7 @@ public class MimeMessage extends Message {
|
|||||||
public void body(BodyDescriptor bd, InputStream in) throws IOException {
|
public void body(BodyDescriptor bd, InputStream in) throws IOException {
|
||||||
expect(Part.class);
|
expect(Part.class);
|
||||||
try {
|
try {
|
||||||
Body body = MimeUtility.decodeBody(in,
|
Body body = MimeUtility.createBody(in, bd.getTransferEncoding(), bd.getMimeType());
|
||||||
bd.getTransferEncoding(), bd.getMimeType());
|
|
||||||
((Part)stack.peek()).setBody(body);
|
((Part)stack.peek()).setBody(body);
|
||||||
} catch (MessagingException me) {
|
} catch (MessagingException me) {
|
||||||
throw new Error(me);
|
throw new Error(me);
|
||||||
|
@ -1127,24 +1127,11 @@ public class MimeUtility {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static Body createBody(InputStream in, String contentTransferEncoding, String contentType)
|
||||||
* Removes any content transfer encoding from the stream and returns a Body.
|
|
||||||
* @throws MessagingException
|
|
||||||
*/
|
|
||||||
public static Body decodeBody(InputStream in,
|
|
||||||
String contentTransferEncoding, String contentType)
|
|
||||||
throws IOException, MessagingException {
|
throws IOException, MessagingException {
|
||||||
/*
|
|
||||||
* We'll remove any transfer encoding by wrapping the stream.
|
|
||||||
*/
|
|
||||||
if (contentTransferEncoding != null) {
|
if (contentTransferEncoding != null) {
|
||||||
contentTransferEncoding =
|
contentTransferEncoding = MimeUtility.getHeaderParameter(contentTransferEncoding, null);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryTempFileBody tempBody;
|
BinaryTempFileBody tempBody;
|
||||||
@ -1154,12 +1141,14 @@ public class MimeUtility {
|
|||||||
tempBody = new BinaryTempFileBody();
|
tempBody = new BinaryTempFileBody();
|
||||||
}
|
}
|
||||||
tempBody.setEncoding(contentTransferEncoding);
|
tempBody.setEncoding(contentTransferEncoding);
|
||||||
|
|
||||||
OutputStream out = tempBody.getOutputStream();
|
OutputStream out = tempBody.getOutputStream();
|
||||||
try {
|
try {
|
||||||
IOUtils.copy(in, out);
|
IOUtils.copy(in, out);
|
||||||
} finally {
|
} finally {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return tempBody;
|
return tempBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ import java.security.GeneralSecurityException;
|
|||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
@ -1625,7 +1623,7 @@ public class ImapStore extends Store {
|
|||||||
.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING)[0];
|
.getHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING)[0];
|
||||||
String contentType = part
|
String contentType = part
|
||||||
.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0];
|
.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0];
|
||||||
MimeMessageHelper.setBody(part, MimeUtility.decodeBody(bodyStream,
|
MimeMessageHelper.setBody(part, MimeUtility.createBody(bodyStream,
|
||||||
contentTransferEncoding, contentType));
|
contentTransferEncoding, contentType));
|
||||||
} else {
|
} else {
|
||||||
// This shouldn't happen
|
// This shouldn't happen
|
||||||
@ -3594,7 +3592,7 @@ public class ImapStore extends Store {
|
|||||||
String contentType = mPart
|
String contentType = mPart
|
||||||
.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0];
|
.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0];
|
||||||
|
|
||||||
return MimeUtility.decodeBody(literal, contentTransferEncoding,
|
return MimeUtility.createBody(literal, contentTransferEncoding,
|
||||||
contentType);
|
contentType);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -332,12 +332,12 @@ public class MessageTest extends AndroidTestCase {
|
|||||||
private MimeBodyPart binaryBodyPart() throws IOException,
|
private MimeBodyPart binaryBodyPart() throws IOException,
|
||||||
MessagingException {
|
MessagingException {
|
||||||
String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
+ "abcdefghijklmnopqrstuvwxyz0123456789+/";
|
+ "abcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
|
||||||
|
|
||||||
BinaryTempFileBody tempFileBody = new BinaryTempFileBody();
|
BinaryTempFileBody tempFileBody = new BinaryTempFileBody();
|
||||||
|
|
||||||
InputStream in = new Base64InputStream(new ByteArrayInputStream(
|
InputStream in = new ByteArrayInputStream(
|
||||||
encodedTestString.getBytes("UTF-8")));
|
encodedTestString.getBytes("UTF-8"));
|
||||||
|
|
||||||
OutputStream out = tempFileBody.getOutputStream();
|
OutputStream out = tempFileBody.getOutputStream();
|
||||||
try {
|
try {
|
||||||
|
@ -37,9 +37,10 @@ public class ReconstructMessageTest extends AndroidTestCase {
|
|||||||
"\r\n" +
|
"\r\n" +
|
||||||
"------Boundary\r\n" +
|
"------Boundary\r\n" +
|
||||||
"Content-Type: text/plain\r\n" +
|
"Content-Type: text/plain\r\n" +
|
||||||
"Content-Transfer-Encoding: quoted-printable\r\n" +
|
"Content-Transfer-Encoding: base64\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"=2E=2E=2E\r\n" +
|
"VGhpcyBpcyBhIHRl\r\n" +
|
||||||
|
"c3QgbWVzc2FnZQ==\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
"------Boundary--\r\n";
|
"------Boundary--\r\n";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user