mirror of
https://github.com/moparisthebest/k-9
synced 2024-08-13 17:03:48 -04:00
34 lines
1.1 KiB
Java
34 lines
1.1 KiB
Java
|
package com.fsck.k9.mail.store.local;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.io.OutputStream;
|
||
|
|
||
|
import org.apache.commons.io.IOUtils;
|
||
|
import org.apache.james.mime4j.util.MimeUtil;
|
||
|
|
||
|
import com.fsck.k9.mail.MessagingException;
|
||
|
import com.fsck.k9.mail.internet.MimeMessage;
|
||
|
|
||
|
public class AttachmentMessageBodyUtil {
|
||
|
public static void writeTo(BinaryAttachmentBody body, OutputStream out) throws IOException,
|
||
|
MessagingException {
|
||
|
InputStream in = body.getInputStream();
|
||
|
try {
|
||
|
if (MimeUtil.ENC_7BIT.equalsIgnoreCase(body.getEncoding())) {
|
||
|
/*
|
||
|
* If we knew the message was already 7bit clean, then it
|
||
|
* could be sent along without processing. But since we
|
||
|
* don't know, we recursively parse it.
|
||
|
*/
|
||
|
MimeMessage message = new MimeMessage(in, true);
|
||
|
message.setUsing7bitTransport();
|
||
|
message.writeTo(out);
|
||
|
} else {
|
||
|
IOUtils.copy(in, out);
|
||
|
}
|
||
|
} finally {
|
||
|
in.close();
|
||
|
}
|
||
|
}
|
||
|
}
|