fix(GODT-2464): Filter attachment name from content-type parameter to not send it twice to the API.

This commit is contained in:
Romain Le Jeune
2023-05-02 07:13:21 +00:00
parent 50709acc5f
commit 543c35041d
7 changed files with 255 additions and 0 deletions

View File

@ -673,6 +673,40 @@ func TestParsePanic(t *testing.T) {
require.Error(t, err)
}
func TestParseTextPlainWithPdfttachmentCyrillic(t *testing.T) {
f := getFileReader("text_plain_pdf_attachment_cyrillic.eml")
m, err := Parse(f)
require.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "Shake that body", string(m.RichBody))
assert.Equal(t, "Shake that body", string(m.PlainBody))
require.Len(t, m.Attachments, 1)
require.Equal(t, "application/pdf", m.Attachments[0].MIMEType)
assert.Equal(t, "АБВГДЃЕЖЗЅИЈКЛЉМНЊОПРСТЌУФХЧЏЗШ.pdf", m.Attachments[0].Name)
}
func TestParseTextPlainWithDocxAttachmentCyrillic(t *testing.T) {
f := getFileReader("text_plain_docx_attachment_cyrillic.eml")
m, err := Parse(f)
require.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "Shake that body", string(m.RichBody))
assert.Equal(t, "Shake that body", string(m.PlainBody))
require.Len(t, m.Attachments, 1)
require.Equal(t, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", m.Attachments[0].MIMEType)
assert.Equal(t, "АБВГДЃЕЖЗЅИЈКЛЉМНЊОПРСТЌУФХЧЏЗШ.docx", m.Attachments[0].Name)
}
func getFileReader(filename string) io.Reader {
f, err := os.Open(filepath.Join("testdata", filename))
if err != nil {

View File

@ -0,0 +1,24 @@
Content-Type: multipart/mixed; boundary="------------nq8WTMHkJcymWO6pWfby0uY3"
To: "Receiver" <receiver@pm.me>
From: "Sender" <sender@pm.me>
Subject: Test with cyrillic attachment
--------------nq8WTMHkJcymWO6pWfby0uY3
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Shake that body
--------------nq8WTMHkJcymWO6pWfby0uY3
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;
name="=?UTF-8?B?0JDQkdCS0JPQlNCD0JXQltCX0IXQmNCI0JrQm9CJ0JzQndCK0J7Qn9Cg?=
=?UTF-8?B?0KHQotCM0KPQpNCl0KfQj9CX0KguZG9jeA==?="
Content-Disposition: attachment;
filename*0*=UTF-8''%D0%90%D0%91%D0%92%D0%93%D0%94%D0%83%D0%95%D0%96%D0%97;
filename*1*=%D0%85%D0%98%D0%88%D0%9A%D0%9B%D0%89%D0%9C%D0%9D%D0%8A%D0%9E;
filename*2*=%D0%9F%D0%A0%D0%A1%D0%A2%D0%8C%D0%A3%D0%A4%D0%A5%D0%A7%D0%8F;
filename*3*=%D0%97%D0%A8%2E%64%6F%63%78
Content-Transfer-Encoding: base64
0JDQkdCS0JPQlNCD0JXQltCX0IXQmNCI0JrQm9CJ0JzQndCK0J7Qn9Cg0KHQotCM0KPQpNCl0KfQj9CX0Kg=
--------------nq8WTMHkJcymWO6pWfby0uY3--

View File

@ -0,0 +1,25 @@
Content-Type: multipart/mixed; boundary="------------bYzsV6z0EdKTbltmCDZgIM15"
To: "Receiver" <receiver@pm.me>
From: "Sender" <sender@pm.me>
Subject: Test with cyrillic attachment
--------------bYzsV6z0EdKTbltmCDZgIM15
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=utf-8
Shake that body
--------------bYzsV6z0EdKTbltmCDZgIM15
Content-Type: application/pdf;
name="=?UTF-8?B?0JDQkdCS0JPQlNCD0JXQltCX0IXQmNCI0JrQm9CJ0JzQndCK0J7Qn9Cg?=
=?UTF-8?B?0KHQotCM0KPQpNCl0KfQj9CX0KgucGRm?="
Content-Disposition: attachment;
filename*0*=UTF-8''%D0%90%D0%91%D0%92%D0%93%D0%94%D0%83%D0%95%D0%96%D0%97;
filename*1*=%D0%85%D0%98%D0%88%D0%9A%D0%9B%D0%89%D0%9C%D0%9D%D0%8A%D0%9E;
filename*2*=%D0%9F%D0%A0%D0%A1%D0%A2%D0%8C%D0%A3%D0%A4%D0%A5%D0%A7%D0%8F;
filename*3*=%D0%97%D0%A8%2E%70%64%66
Content-Transfer-Encoding: base64
0JDQkdCS0JPQlNCD0JXQltCX0IXQmNCI0JrQm9CJ0JzQndCK0J7Qn9Cg0KHQotCM0KPQpNCl0KfQj9CX0Kg=
--------------bYzsV6z0EdKTbltmCDZgIM15--