use of org.apache.james.mime4j.codec.QuotedPrintableOutputStream in project k-9 by k9mail.
the class SignSafeOutputStreamTest method testSignSafeQuotedPrintableOutputStream.
@Test
public void testSignSafeQuotedPrintableOutputStream() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
OutputStream signSafeOutputStream = new SignSafeOutputStream(byteArrayOutputStream);
OutputStream quotedPrintableOutputStream = new QuotedPrintableOutputStream(signSafeOutputStream, false);
quotedPrintableOutputStream.write(INPUT_STRING.getBytes("US-ASCII"));
quotedPrintableOutputStream.close();
signSafeOutputStream.close();
assertEquals(EXPECTED_QUOTED_PRINTABLE_SIGNSAFE, new String(byteArrayOutputStream.toByteArray(), "US-ASCII"));
}
use of org.apache.james.mime4j.codec.QuotedPrintableOutputStream in project k-9 by k9mail.
the class BinaryTempFileBody method setEncoding.
public void setEncoding(String encoding) throws MessagingException {
if (mEncoding != null && mEncoding.equalsIgnoreCase(encoding)) {
return;
}
// The encoding changed, so we need to convert the message
if (!MimeUtil.ENC_8BIT.equalsIgnoreCase(mEncoding)) {
throw new RuntimeException("Can't convert from encoding: " + mEncoding);
}
try {
File newFile = File.createTempFile("body", null, mTempDirectory);
final OutputStream out = new FileOutputStream(newFile);
try {
OutputStream wrappedOut = null;
if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(encoding)) {
wrappedOut = new QuotedPrintableOutputStream(out, false);
} else if (MimeUtil.ENC_BASE64.equals(encoding)) {
wrappedOut = new Base64OutputStream(out);
} else {
throw new RuntimeException("Target encoding not supported: " + encoding);
}
InputStream in = getInputStream();
try {
IOUtils.copy(in, wrappedOut);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(wrappedOut);
}
} finally {
IOUtils.closeQuietly(out);
}
mFile = newFile;
mEncoding = encoding;
} catch (IOException e) {
throw new MessagingException("Unable to convert body", e);
}
}
use of org.apache.james.mime4j.codec.QuotedPrintableOutputStream in project k-9 by k9mail.
the class BinaryAttachmentBody method writeTo.
@Override
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();
}
}
} finally {
in.close();
}
}
use of org.apache.james.mime4j.codec.QuotedPrintableOutputStream in project k-9 by k9mail.
the class MigrationTo51 method insertTextualPartIntoDatabase.
private static MimeStructureState insertTextualPartIntoDatabase(SQLiteDatabase db, MimeStructureState structureState, MimeHeader mimeHeader, String content, boolean isHtml) throws IOException {
if (mimeHeader == null) {
mimeHeader = new MimeHeader();
}
mimeHeader.setHeader(MimeHeader.HEADER_CONTENT_TYPE, isHtml ? "text/html; charset=\"utf-8\"" : "text/plain; charset=\"utf-8\"");
mimeHeader.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, MimeUtil.ENC_QUOTED_PRINTABLE);
byte[] contentBytes;
int decodedBodySize;
int dataLocation;
if (content != null) {
ByteArrayOutputStream contentOutputStream = new ByteArrayOutputStream();
QuotedPrintableOutputStream quotedPrintableOutputStream = new QuotedPrintableOutputStream(contentOutputStream, false);
quotedPrintableOutputStream.write(content.getBytes());
quotedPrintableOutputStream.flush();
dataLocation = DATA_LOCATION__IN_DATABASE;
contentBytes = contentOutputStream.toByteArray();
decodedBodySize = content.length();
} else {
dataLocation = DATA_LOCATION__MISSING;
contentBytes = null;
decodedBodySize = 0;
}
ContentValues cv = new ContentValues();
cv.put("type", MESSAGE_PART_TYPE__UNKNOWN);
cv.put("data_location", dataLocation);
cv.put("mime_type", isHtml ? "text/html" : "text/plain");
cv.put("header", mimeHeader.toString());
cv.put("data", contentBytes);
cv.put("decoded_body_size", decodedBodySize);
cv.put("encoding", MimeUtil.ENC_QUOTED_PRINTABLE);
cv.put("charset", "utf-8");
structureState.applyValues(cv);
long partId = db.insertOrThrow("message_parts", null, cv);
return structureState.nextChild(partId);
}
use of org.apache.james.mime4j.codec.QuotedPrintableOutputStream in project k-9 by k9mail.
the class SignSafeOutputStreamTest method testQuotedPrintableOutputStream.
@Test
public void testQuotedPrintableOutputStream() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
OutputStream output = new QuotedPrintableOutputStream(byteArrayOutputStream, false);
output.write(INPUT_STRING.getBytes("US-ASCII"));
output.close();
assertEquals(EXPECTED_QUOTED_PRINTABLE, new String(byteArrayOutputStream.toByteArray(), "US-ASCII"));
}
Aggregations