jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
244 stars 101 forks source link

Error parsing email attachment name #586

Open drencrom opened 2 years ago

drencrom commented 2 years ago

Describe the bug I found a problem parsing the name of an email attachment. If I open the same email in outlook or thunderbird the attachment name is shown correctly. Also tested with an RFC 2047 decoder and works OK.

To Reproduce Send an email with an attachment whose name is encoded in the following way:

Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;
        name="=?iso-8859-1?Q?Preparaci=F3n_de_puesto_de_trabajo_Sofia_Cafaro_-_Altenix_?=
 =?iso-8859-1?Q?BC.lsx?="
Content-Description:
        =?iso-8859-1?Q?Preparaci=F3n_de_puesto_de_trabajo_Sofia_Cafaro_-_Altenix_?=
 =?iso-8859-1?Q?BC.xlsx?=
Content-Disposition: attachment;
        filename="=?iso-8859-1?Q?Preparaci=F3n_de_puesto_de_trabajo_Sofia_Cafaro_-_Altenix_?=
 =?iso-8859-1?Q?BC.xlsx?="; size=69949;
        creation-date="Tue, 19 Oct 2021 18:50:44 GMT";
        modification-date="Tue, 19 Oct 2021 18:50:44 GMT"
Content-Transfer-Encoding: base64

Expected behavior The attachment name should be Preparación de puesto de trabajo Sofia Cafaro - Altenix BC.xlsx but the api shows it as =?iso-8859-1?Q?Preparaci=F3n_de_puesto_de_trabajo_Sofia_Cafaro_-_Altenix_?= =?iso-8859-1?Q?BC.xlsx?=

Version tested:

Mail server:

mrraghur commented 2 years ago

=?iso-8859-1?Q?Preparaci=F3n_de_puesto_de_trabajo_SofiaCafaro-Altenix?= =?iso-8859-1?Q?BC.xlsx?=

This is undecoded filename. Using iso-8859-1, in your code, you must decode the rest of the string to get human readable file name. This is probably what outlook and thunderbird are already doing.