在 javamail 中设置 "mail.strictly_mime.parm_folding"

Set "mail.strictly_mime.parm_folding" in javamail

我确实使用 javamail 发送带有长文件名附件的邮件。 javamail 根据最新的 RFC 采取行动,并将文件名跨越邮件的两行 header,例如:

------=_Part_0_978693914.1433356404377
Content-Disposition: ATTACHMENT;
    filename*0="=?UTF-8?Q?arquivo_com_nome_grande_e_acentua=C3=A7=C3=A3o.png\"; f";
    filename*1="ilename*1=\"?="
Content-Type: APPLICATION/OCTET-STREAM;
    name*0="=?UTF-8?Q?arquivo_com_nome_grande_e_acentua=C3=A7=C3=A3o.png\"; n";
    name*1="ame*1=\"?="
Content-Transfer-Encoding: BASE64

像 Outlook 这样的邮件客户端不理解它,所以我需要让 javamail 不把文件名分成两行。

阅读 RFC,我发现一个属性说不要拆分: "mail.strictly_mime.parm_folding"

如何在 javamail 中设置它?

mail.strictly_mime.parm_folding 属性 适用于 Thunderbird,它不在 RFC 中。

根据 Outlook 支持的 this Thunderbird article, Outlook doesn't support RFC 2231, which JavaMail is using to encode the filename parameter. You can disable RFC 2231 encoding by setting the JavaMail System property "mail.mime.encodeparameters" to "false". You'll probably want to set the System property "mail.mime.encodefilename" to "true" to use the non-standard filename encoding

我在 Wildfly Server V 上发现了这个问题10.x

通过插入格式解决="flowed" 到内容类型

MimeBodyPart part = new MimeBodyPart();
part.addHeader("Content-Type", "application/pdf; charset=\"UTF-8\"; format=\"flowed\"  ");
part.setFileName(MimeUtility.encodeText(file.getName(), "UTF-8", null));
//setDataHandler