mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
streamline test
This commit is contained in:
@@ -1392,6 +1392,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::*;
|
use crate::test_utils::*;
|
||||||
|
use mailparse::ParsedMail;
|
||||||
|
|
||||||
impl AvatarAction {
|
impl AvatarAction {
|
||||||
pub fn is_change(&self) -> bool {
|
pub fn is_change(&self) -> bool {
|
||||||
@@ -1461,26 +1462,29 @@ mod tests {
|
|||||||
assert!(is_attachment_disposition(&mail.subparts[1]));
|
assert!(is_attachment_disposition(&mail.subparts[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn load_mail_with_attachment(raw: &[u8]) -> ParsedMail {
|
||||||
fn test_get_attachment_filename() {
|
|
||||||
let raw = include_bytes!("../test-data/message/html_attach.eml");
|
|
||||||
let mail = mailparse::parse_mail(raw).unwrap();
|
let mail = mailparse::parse_mail(raw).unwrap();
|
||||||
assert!(get_attachment_filename(&mail).unwrap().is_none());
|
assert!(get_attachment_filename(&mail).unwrap().is_none());
|
||||||
assert!(get_attachment_filename(&mail.subparts[0])
|
assert!(get_attachment_filename(&mail.subparts[0])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.is_none());
|
.is_none());
|
||||||
|
mail
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_attachment_filename() {
|
||||||
|
let mail = load_mail_with_attachment(include_bytes!(
|
||||||
|
"../test-data/message/attach_filename_simple.eml"
|
||||||
|
));
|
||||||
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
||||||
assert_eq!(filename, Some("test.html".to_string()))
|
assert_eq!(filename, Some("test.html".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_attachment_filename_encoded_words() {
|
fn test_get_attachment_filename_encoded_words() {
|
||||||
let raw = include_bytes!("../test-data/message/html_attach_encoded_words.eml");
|
let mail = load_mail_with_attachment(include_bytes!(
|
||||||
let mail = mailparse::parse_mail(raw).unwrap();
|
"../test-data/message/attach_filename_encoded_words.eml"
|
||||||
assert!(get_attachment_filename(&mail).unwrap().is_none());
|
));
|
||||||
assert!(get_attachment_filename(&mail.subparts[0])
|
|
||||||
.unwrap()
|
|
||||||
.is_none());
|
|
||||||
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
||||||
assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string()))
|
assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string()))
|
||||||
}
|
}
|
||||||
@@ -1488,24 +1492,19 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_get_attachment_filename_encoded_words_cont() {
|
fn test_get_attachment_filename_encoded_words_cont() {
|
||||||
// test continued encoded-words and also test apostropes work that way
|
// test continued encoded-words and also test apostropes work that way
|
||||||
let raw = include_bytes!("../test-data/message/html_attach_encoded_words_cont.eml");
|
let mail = load_mail_with_attachment(include_bytes!(
|
||||||
let mail = mailparse::parse_mail(raw).unwrap();
|
"../test-data/message/attach_filename_encoded_words_cont.eml"
|
||||||
assert!(get_attachment_filename(&mail).unwrap().is_none());
|
));
|
||||||
assert!(get_attachment_filename(&mail.subparts[0])
|
|
||||||
.unwrap()
|
|
||||||
.is_none());
|
|
||||||
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
||||||
assert_eq!(filename, Some("Maßn'ah'men Okt. 2020.html".to_string()))
|
assert_eq!(filename, Some("Maßn'ah'men Okt. 2020.html".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_attachment_filename_combined() {
|
fn test_get_attachment_filename_combined() {
|
||||||
let raw = include_bytes!("../test-data/message/html_attach_combined.eml");
|
// test that if `filename` and `filename*0` are given, the filename is not doubled
|
||||||
let mail = mailparse::parse_mail(raw).unwrap();
|
let mail = load_mail_with_attachment(include_bytes!(
|
||||||
assert!(get_attachment_filename(&mail).unwrap().is_none());
|
"../test-data/message/attach_filename_combined.eml"
|
||||||
assert!(get_attachment_filename(&mail.subparts[0])
|
));
|
||||||
.unwrap()
|
|
||||||
.is_none());
|
|
||||||
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
let filename = get_attachment_filename(&mail.subparts[1]).unwrap();
|
||||||
assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string()))
|
assert_eq!(filename, Some("Maßnahmen Okt. 2020.html".to_string()))
|
||||||
}
|
}
|
||||||
|
|||||||
31
test-data/message/attach_filename_combined.eml
Normal file
31
test-data/message/attach_filename_combined.eml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
Subject: Test combined filenames
|
||||||
|
Message-ID: 12345@testrun.org
|
||||||
|
Date: Sat, 07 Dec 2019 19:00:27 +0000
|
||||||
|
X-Mailer: Kopano 8.7.16
|
||||||
|
To: recp@testrun.org
|
||||||
|
From: sender@testrun.org
|
||||||
|
Content-Type: multipart/mixed; boundary="NwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z"
|
||||||
|
|
||||||
|
|
||||||
|
--NwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
|
yip, filename may be given twice,
|
||||||
|
seen this way in Kopano.
|
||||||
|
|
||||||
|
normally, both filenames will be the same,
|
||||||
|
for the test, we use different filenames,
|
||||||
|
we define that `filename` has a higher precedence.
|
||||||
|
|
||||||
|
--
|
||||||
|
Sent with my Delta Chat Messenger: https://delta.chat
|
||||||
|
|
||||||
|
--NwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
||||||
|
Content-Type: text/html
|
||||||
|
Content-Disposition: attachment; filename="=?utf-8?Q?Ma=C3=9Fnahmen_Okt=2E_2020=2Ehtml?=";
|
||||||
|
filename*=utf-8''Ma%C3%9Fnahmen%20Okt.%202020.ignored.html
|
||||||
|
Content-Transfer-Encoding: base64
|
||||||
|
|
||||||
|
PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh
|
||||||
|
|
||||||
|
--NwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z--
|
||||||
23
test-data/message/attach_filename_encoded_words.eml
Normal file
23
test-data/message/attach_filename_encoded_words.eml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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="mwkNRwabw1M5n2xcr2ODfAqvTjcj9Z"
|
||||||
|
|
||||||
|
|
||||||
|
--mwkNRwabw1M5n2xcr2ODfAqvTjcj9Z
|
||||||
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
|
--
|
||||||
|
Sent with my Delta Chat Messenger: https://delta.chat
|
||||||
|
|
||||||
|
--mwkNRwabw1M5n2xcr2ODfAqvTjcj9Z
|
||||||
|
Content-Type: text/html
|
||||||
|
Content-Disposition: attachment; filename="=?utf-8?Q?Ma=C3=9Fnahmen_Okt=2E_2020=2Ehtml?=";
|
||||||
|
Content-Transfer-Encoding: base64
|
||||||
|
|
||||||
|
PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh
|
||||||
|
|
||||||
|
--mwkNRwabw1M5n2xcr2ODfAqvTjcj9Z--
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
Chat-Disposition-Notification-To: tmp_6272287793210918@testrun.org
|
Subject: Test encoded-words filenames, spanning different lines
|
||||||
Subject: =?utf-8?q?Chat=3A_File_=E2=80=93_test=2Ehtml?=
|
|
||||||
Message-ID: Mr.XA6y3og8-az.WGbH9_dNcQx@testrun.org
|
Message-ID: Mr.XA6y3og8-az.WGbH9_dNcQx@testrun.org
|
||||||
Date: Sat, 07 Dec 2019 19:00:27 +0000
|
Date: Sat, 07 Dec 2019 19:00:27 +0000
|
||||||
X-Mailer: Delta Chat Core 1.0.0-beta.12/DcFFI
|
X-Mailer: Delta Chat Core 1.0.0-beta.12/DcFFI
|
||||||
Chat-Version: 1.0
|
Chat-Version: 1.0
|
||||||
To: <tmp_5890965001269692@testrun.org>
|
To: recp@testrun.org
|
||||||
From: "=?utf-8?q??=" <tmp_6272287793210918@testrun.org>
|
From: sender@testrun.org
|
||||||
Content-Type: multipart/mixed; boundary="mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z"
|
Content-Type: multipart/mixed; boundary="maaNRwaJw1M5n2xcr2ODfAqvTjcj9Z"
|
||||||
|
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
--maaNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
||||||
Content-Type: text/plain; charset=utf-8
|
Content-Type: text/plain; charset=utf-8
|
||||||
|
|
||||||
--
|
--
|
||||||
Sent with my Delta Chat Messenger: https://delta.chat
|
Sent with my Delta Chat Messenger: https://delta.chat
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
--maaNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
||||||
Content-Type: text/html
|
Content-Type: text/html
|
||||||
Content-Disposition: attachment; filename*0="=?utf-8?Q?Ma=C3=9Fn'ah'men_?=";
|
Content-Disposition: attachment; filename*0="=?utf-8?Q?Ma=C3=9Fn'ah'men_?=";
|
||||||
filename*1="=?utf-8?Q?Okt=2E_2020=2Ehtml?=";
|
filename*1="=?utf-8?Q?Okt=2E_2020=2Ehtml?=";
|
||||||
@@ -23,4 +22,4 @@ Content-Transfer-Encoding: base64
|
|||||||
|
|
||||||
PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh
|
PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z--
|
--maaNRwaJw1M5n2xcr2ODfAqvTjcj9Z--
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
Chat-Disposition-Notification-To: tmp_6272287793210918@testrun.org
|
|
||||||
Subject: =?utf-8?q?Chat=3A_File_=E2=80=93_test=2Ehtml?=
|
|
||||||
Message-ID: 12345@testrun.org
|
|
||||||
Date: Sat, 07 Dec 2019 19:00:27 +0000
|
|
||||||
X-Mailer: Kopano 8.7.16
|
|
||||||
To: <tmp_5890965001269692@testrun.org>
|
|
||||||
From: "=?utf-8?q??=" <tmp_6272287793210918@testrun.org>
|
|
||||||
Content-Type: multipart/mixed; boundary="mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z"
|
|
||||||
|
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
|
||||||
Content-Type: text/plain; charset=utf-8
|
|
||||||
|
|
||||||
yip, filename may be given twice,
|
|
||||||
seen this way in Kopano
|
|
||||||
|
|
||||||
--
|
|
||||||
Sent with my Delta Chat Messenger: https://delta.chat
|
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
|
||||||
Content-Type: text/html
|
|
||||||
Content-Disposition: attachment; filename="=?utf-8?Q?Ma=C3=9Fnahmen_Okt=2E_2020=2Ehtml?=";
|
|
||||||
filename*=utf-8''Ma%C3%9Fnahmen%20Okt.%202020.html
|
|
||||||
Content-Transfer-Encoding: base64
|
|
||||||
|
|
||||||
PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh
|
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z--
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
Chat-Disposition-Notification-To: tmp_6272287793210918@testrun.org
|
|
||||||
Subject: =?utf-8?q?Chat=3A_File_=E2=80=93_test=2Ehtml?=
|
|
||||||
Message-ID: Mr.XA6y3og8-az.WGbH9_dNcQx@testrun.org
|
|
||||||
Date: Sat, 07 Dec 2019 19:00:27 +0000
|
|
||||||
X-Mailer: Delta Chat Core 1.0.0-beta.12/DcFFI
|
|
||||||
Chat-Version: 1.0
|
|
||||||
To: <tmp_5890965001269692@testrun.org>
|
|
||||||
From: "=?utf-8?q??=" <tmp_6272287793210918@testrun.org>
|
|
||||||
Content-Type: multipart/mixed; boundary="mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z"
|
|
||||||
|
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
|
||||||
Content-Type: text/plain; charset=utf-8
|
|
||||||
|
|
||||||
--
|
|
||||||
Sent with my Delta Chat Messenger: https://delta.chat
|
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z
|
|
||||||
Content-Type: text/html
|
|
||||||
Content-Disposition: attachment; filename="=?utf-8?Q?Ma=C3=9Fnahmen_Okt=2E_2020=2Ehtml?=";
|
|
||||||
Content-Transfer-Encoding: base64
|
|
||||||
|
|
||||||
PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh
|
|
||||||
|
|
||||||
--mwkNRwaJw1M5n2xcr2ODfAqvTjcj9Z--
|
|
||||||
Reference in New Issue
Block a user