From 441b388f62d9018a0b0bac8bec09c03b34227e7d Mon Sep 17 00:00:00 2001 From: Romain Le Jeune Date: Thu, 5 Oct 2023 12:27:43 +0000 Subject: [PATCH] fix(GODT-2966): Add more test regarding quoted/unquoted filename in attachment. --- tests/features/imap/message/import.feature | 95 ++++++++----------- tests/features/smtp/send/attachment.feature | 80 +++++++++++++++- .../mixed_with_attachment_encoded.eml | 27 ++++++ ...mixed_with_attachment_encoded_no_quote.eml | 27 ++++++ .../mixed_with_attachment_no_quote.eml | 27 ++++++ 5 files changed, 199 insertions(+), 57 deletions(-) create mode 100644 tests/testdata/multipart/mixed_with_attachment_encoded.eml create mode 100644 tests/testdata/multipart/mixed_with_attachment_encoded_no_quote.eml create mode 100644 tests/testdata/multipart/mixed_with_attachment_no_quote.eml diff --git a/tests/features/imap/message/import.feature b/tests/features/imap/message/import.feature index 377cbaa7..ddc8331c 100644 --- a/tests/features/imap/message/import.feature +++ b/tests/features/imap/message/import.feature @@ -67,58 +67,46 @@ Feature: IMAP import messages """ - Scenario: Import message with attachment name encoded by RFC 2047 without quoting - When IMAP client "1" appends the following message to "INBOX": - """ - From: Bridge Test - Date: 01 Jan 1980 00:00:00 +0000 - To: Internal Bridge - Subject: Message with attachment name encoded by RFC 2047 without quoting - Content-type: multipart/mixed; boundary="boundary" - Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000 - - --boundary - Content-Type: text/plain - - Hello - - --boundary - Content-Type: application/pdf; name==?US-ASCII?Q?filename?= - Content-Disposition: attachment; filename==?US-ASCII?Q?filename?= - - somebytes - - --boundary-- - - """ + Scenario Outline: Import multipart message with attachment + When IMAP client "1" appends to "INBOX" Then it succeeds -# And IMAP client "1" eventually sees the following message in "INBOX" with this structure: -# """ -# { -# "from": "Bridge Test ", -# "date": "01 Jan 80 00:00 +0000", -# "to": "Internal Bridge ", -# "subject": "Message with attachment name encoded by RFC 2047 without quoting", -# "body-contains": "Hello", -# "content": { -# "content-type": "multipart/mixed; boundary=\"boundary\"", -# "sections":[ -# { -# "content-type": "text/plain", -# "body-is": "Hello" -# }, -# { -# "content-type": "application/pdf", -# "content-type-name": "=?US-ASCII?Q?filename?=", -# "content-disposition": "attachment", -# "content-disposition-filename": "=?US-ASCII?Q?filename?=", -# "body-is": "somebytes" -# } -# ] -# } -# } -# """ - + And IMAP client "1" eventually sees the following message in "INBOX" with this structure: + """ + { + "from": "Bridge Test ", + "date": "01 Jan 80 00:00 +0000", + "to": "Internal Bridge ", + "subject": "Message with attachment name", + "body-contains": "Hello", + "content": { + "content-type": "multipart/mixed", + "sections":[ + { + "content-type": "text/plain", + "body-is": "Hello" + }, + { + "content-type": "text/html", + "content-type-charset": "utf-8", + "transfer-encoding": "7bit", + "body-contains": "HELLO" + }, + { + "content-type": "application/pdf", + "content-type-name": , + "content-disposition": "attachment", + "content-disposition-filename": , + "body-is": "somebytes" + } + ] + } + } + """ + Examples: + | message | filename | + | "multipart/mixed_with_attachment_encoded.eml" | "=?US-ASCII?Q?filename?=" | +# | "multipart/mixed_with_attachment_encoded_no_quote.eml" | =?US-ASCII?Q?filename?= | @todo GODT-2966 +# | "multipart/mixed_with_attachment_no_quote.eml" | "filename" | @todo GODT-2966 # The message is imported as UTF-8 and the content type is determined at build time. Scenario: Import message as latin1 without content type @@ -322,8 +310,6 @@ Feature: IMAP import messages Content-Type: multipart/mixed; boundary="boundary" Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000 - --boundary - This is a multi-part message in MIME format. --boundary @@ -366,9 +352,6 @@ Feature: IMAP import messages "content": { "content-type": "multipart/mixed", "sections":[ - { - "body-is": "This is a multi-part message in MIME format." - }, { "content-type": "text/plain", "content-type-charset": "utf-8", diff --git a/tests/features/smtp/send/attachment.feature b/tests/features/smtp/send/attachment.feature index d8151a3c..5984c0cf 100644 --- a/tests/features/smtp/send/attachment.feature +++ b/tests/features/smtp/send/attachment.feature @@ -140,4 +140,82 @@ Feature: SMTP sending with attachment "Disposition": "attachment" } } - """ \ No newline at end of file + """ + + + Scenario Outline: Send message with attachment + When SMTP client "1" sends the following message from "[user:user1]@[domain]" to "[user:user2]@[domain]": + """ + Subject: Message with attachment name + Content-type: multipart/mixed; boundary="boundary" + Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000 + + This is a multi-part message in MIME format. + + --boundary + Content-Type: text/plain + + Hello + + --boundary + Content-Type: application/pdf; name= + Content-Disposition: attachment; filename= + + somebytes + + --boundary-- + """ + Then it succeeds + And IMAP client "1" eventually sees the following message in "Sent" with this structure: + """ + { + "subject": "Message with attachment name", + "body-contains": "Hello", + "content": { + "content-type": "multipart/mixed", + "sections":[ + { + "content-type": "text/plain", + "body-is": "Hello" + }, + { + "content-type": "application/pdf", + "content-type-name": "filename", + "content-disposition": "attachment", + "content-disposition-filename": "filename", + "transfer-encoding":"base64", + "body-is": "c29tZWJ5dGVzDQo=" + } + ] + } + } + """ + Examples: + | UseCase | filename | + | encoded quoted | "=?US-ASCII?Q?filename?=" | +# | non quoted | filename | @todo GODT-2974 + + Scenario: Send message with attachment with name unquoted containing special character + When SMTP client "1" sends the following message from "[user:user1]@[domain]" to "[user:user2]@[domain]": + """ + Subject: Message with attachment name + Content-type: multipart/mixed; boundary="boundary" + Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000 + + This is a multi-part message in MIME format. + + --boundary + Content-Type: text/plain + + Hello + + --boundary + Content-Type: application/pdf; name==?US-ASCII?Q?filename?= + Content-Disposition: attachment; filename==?US-ASCII?Q?filename?= + + somebytes + + --boundary-- + """ + Then it fails + And bridge reports a message with "failed to collect attachments: mime: invalid media parameter" \ No newline at end of file diff --git a/tests/testdata/multipart/mixed_with_attachment_encoded.eml b/tests/testdata/multipart/mixed_with_attachment_encoded.eml new file mode 100644 index 00000000..c6774264 --- /dev/null +++ b/tests/testdata/multipart/mixed_with_attachment_encoded.eml @@ -0,0 +1,27 @@ +From: Bridge Test +Date: 01 Jan 1980 00:00:00 +0000 +To: Internal Bridge +Subject: Message with attachment name +Content-type: multipart/mixed; boundary="boundary" +Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000 + +This is a multi-part message in MIME format. + +--boundary +Content-Type: text/plain + +Hello + +--boundary +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: 7bit + +

HELLO

+ +--boundary +Content-Type: application/pdf; name="=?US-ASCII?Q?filename?=" +Content-Disposition: attachment; filename="=?US-ASCII?Q?filename?=" + +somebytes + +--boundary-- diff --git a/tests/testdata/multipart/mixed_with_attachment_encoded_no_quote.eml b/tests/testdata/multipart/mixed_with_attachment_encoded_no_quote.eml new file mode 100644 index 00000000..c60fead3 --- /dev/null +++ b/tests/testdata/multipart/mixed_with_attachment_encoded_no_quote.eml @@ -0,0 +1,27 @@ +From: Bridge Test +Date: 01 Jan 1980 00:00:00 +0000 +To: Internal Bridge +Subject: Message with attachment name +Content-type: multipart/mixed; boundary="boundary" +Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000 + +This is a multi-part message in MIME format. + +--boundary +Content-Type: text/plain + +Hello + +--boundary +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: 7bit + +

HELLO

+ +--boundary +Content-Type: application/pdf; name==?US-ASCII?Q?filename?= +Content-Disposition: attachment; filename==?US-ASCII?Q?filename?= + +somebytes + +--boundary-- diff --git a/tests/testdata/multipart/mixed_with_attachment_no_quote.eml b/tests/testdata/multipart/mixed_with_attachment_no_quote.eml new file mode 100644 index 00000000..67d3b9c2 --- /dev/null +++ b/tests/testdata/multipart/mixed_with_attachment_no_quote.eml @@ -0,0 +1,27 @@ +From: Bridge Test +Date: 01 Jan 1980 00:00:00 +0000 +To: Internal Bridge +Subject: Message with attachment name +Content-type: multipart/mixed; boundary="boundary" +Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000 + +This is a multi-part message in MIME format. + +--boundary +Content-Type: text/plain + +Hello + +--boundary +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: 7bit + +

HELLO

+ +--boundary +Content-Type: application/pdf; name=filename +Content-Disposition: attachment; filename=filename + +somebytes + +--boundary--