Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set "mail.strictly_mime.parm_folding" in javamail

I'do use javamail to send mail with long filename attachments. The javamail acts accordingly to more recent RFC, and span the filename in two lines of the mail's header, like this example:

------=_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

Mail clients like Outlook don't understand it, so I need to make javamail don;t split the filename in two lines.

Reading the RFC, I found an attribute that says to don't split: "mail.strictly_mime.parm_folding"

How do I set it in javamail?

like image 240
Anderson Fagionato Avatar asked Jun 03 '15 18:06

Anderson Fagionato


2 Answers

The mail.strictly_mime.parm_folding property is for Thunderbird, it's not in the RFC.

According to 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 that Outlook supports.

like image 159
Bill Shannon Avatar answered Nov 11 '22 19:11

Bill Shannon


I found this problem on Wildfly Server V.10.x

Solving by insert format="flowed" into Content Type

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
like image 35
Veeranon K. Avatar answered Nov 11 '22 19:11

Veeranon K.