diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 094c51975..9d952612b 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -1517,6 +1517,16 @@ mod tests { assert_eq!(filename, Some("Maßn'ah'men Okt. 2020.html".to_string())) } + #[test] + fn test_get_attachment_filename_encoded_words_bad_delimiter() { + let mail = load_mail_with_attachment(include_bytes!( + "../test-data/message/attach_filename_encoded_words_bad_delimiter.eml" + )); + let filename = get_attachment_filename(&mail.subparts[1]).unwrap(); + // not decoded as a space is missing after encoded-words part + assert_eq!(filename, Some("=?utf-8?q?foo?=.bar".to_string())) + } + #[test] fn test_get_attachment_filename_combined() { // test that if `filename` and `filename*0` are given, the filename is not doubled diff --git a/test-data/message/attach_filename_encoded_words_bad_delimiter.eml b/test-data/message/attach_filename_encoded_words_bad_delimiter.eml new file mode 100644 index 000000000..a1ae8207c --- /dev/null +++ b/test-data/message/attach_filename_encoded_words_bad_delimiter.eml @@ -0,0 +1,29 @@ +Subject: Test encoded-words filenames +Message-ID: 123456@testrun.org +Date: Sat, 07 Dec 2019 19:00:27 +0000 +Chat-Version: 1.0 +To: recp@testrun.org +From: sender@testrun.org +Content-Type: multipart/mixed; boundary="==BREAK==" + + +--==BREAK== +Content-Type: text/plain; charset=utf-8 + +there MUST be a space between encoded words and plain text, +if there is none, decoding should return the original string +https://tools.ietf.org/html/rfc2047 5.1: + +"Ordinary ASCII text and 'encoded-word's may appear together in the +same header field. However, an 'encoded-word' that appears in a +header field defined as '*text' MUST be separated from any adjacent +'encoded-word' or 'text' by 'linear-white-space'." + +--==BREAK== +Content-Type: text/html +Content-Disposition: attachment; filename="=?utf-8?q?foo?=.bar"; +Content-Transfer-Encoding: base64 + +PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh + +--==BREAK==--