开发者

Convert 8bit MIME message to quoted-printable

What is the easiest way to convert a MIME e-mail containing raw 8bit parts to a RFC822 compliant message cont开发者_如何转开发aining only 7bit parts ?

The parts have to be automatically converted to "Content-Transfer-Encoding: quoted-printable".

My app is developed in Java. But a command-line tool would be great. I tried reformime but this tool seems buggy and doesn't rewrite message properly :-(

Thanks for any help,

Olivier


JavaMail seems like a good solution. Create a MimeMessage from your file, find the body parts whose content transfer encodings you want to change, call MimeBodyPart.setHeader("Content-Transfer-Encoding", "quoted-printable"), and write the resulting message out via MimeMessage.writeTo().

Something along the lines of this:

Session session = Session.getInstance(new Properties());
MimeMessage mm = new MimeMessage(new FileInputStream(msgfile));
// assuming we know that it's a multipart; otherwise, check Content-Type first...
MimeMultipart multi = (MimeMultipart) mm.getContent();
for (int i = 0; i < multi.getCount(); i++) {
    MimeBodyPart mbp = (MimeBodyPart) multi.getBodyPart(i);
    mbp.setHeader("Content-Transfer-Encoding", "quoted-printable");
}
mm.saveChanges();
mm.writeTo(new FileOutputStream(outfile));

Note that MimeMessage by default will reset the Message-ID header when you've made changes to the message. If you don't want this, override MimeMessage.updateMessageID() to a no-op.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜