将 8 位 MIME 消息转换为可引用打印

发布于 2024-10-12 19:29:09 字数 233 浏览 4 评论 0原文

将包含原始 8 位部分的 MIME 电子邮件转换为仅包含 7 位部分的 RFC822 兼容消息的最简单方法是什么?
这些部分必须自动转换为“Content-Transfer-Encoding:quoted-printable”。

我的应用程序是用 Java 开发的。但如果有一个命令行工具那就太好了。我尝试了 Reformime,但这个工具似乎有问题,并且无法正确重写消息:-(

感谢您的帮助,
奥利维尔

What is the easiest way to convert a MIME e-mail containing raw 8bit parts to a RFC822 compliant message containing 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝情姑娘 2024-10-19 19:29:09

JavaMail 似乎是一个很好的解决方案。从您的文件创建一个 MimeMessage,找到要更改其内容传输编码的正文部分,调用 MimeBodyPart.setHeader("Content-Transfer-Encoding", "quoted-printable")< /code>,并通过 MimeMessage.writeTo() 写出结果消息。

大致如下:

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));

请注意,当您对消息进行更改时,MimeMessage 默认情况下会重置 Message-ID 标头。如果您不想这样做,请将 MimeMessage.updateMessageID() 重写为无操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文