Add another test

This commit is contained in:
Andrey Golovizin 2021-07-17 21:44:37 +02:00
parent 19981b4671
commit ec11a2e038

View file

@ -75,6 +75,54 @@ Content-Type: text/html; charset="UTF-8"
"#;
const MULTIPART_MIXED_ALTERNATIVE: &str = r#"From: Andrey Golovizin <ag@sologoc.com>
Subject: Plain text with html and attachment
Date: Sat, 17 Jul 2021 21:39:08 +0200
Message-ID: <3054314.5fSG56mABF@sakuragaoka>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="nextPart1698715.VLH7GnMWUR"
Content-Transfer-Encoding: 7Bit
This is a multi-part message in MIME format.
--nextPart1698715.VLH7GnMWUR
Content-Type: multipart/alternative; boundary="nextPart5630828.MhkbZ0Pkbq"
Content-Transfer-Encoding: 7Bit
This is a multi-part message in MIME format.
--nextPart5630828.MhkbZ0Pkbq
Content-Transfer-Encoding: base64
Content-Type: text/plain; charset="UTF-8"
UHJvc3TDvSB0ZXh0Lg==
--nextPart5630828.MhkbZ0Pkbq
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="UTF-8"
<html>
<head>
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3DUTF-8">
</head>
<body><p style=3D"margin-top:0;margin-bottom:0;margin-left:0;margin-right:0=
;"><strong>Tu=C4=8Dn=C3=BD HTML text</strong></p>
</body>
</html>
--nextPart5630828.MhkbZ0Pkbq--
--nextPart1698715.VLH7GnMWUR
Content-Disposition: attachment; filename="test.txt"
Content-Transfer-Encoding: base64
Content-Type: text/plain; charset="UTF-8"; name="test.txt"
TsSbamFrw6EgcMWZw61sb2hhLgo=
--nextPart1698715.VLH7GnMWUR--
"#;
#[test]
fn test_plain_text_body() -> Result<(), anyhow::Error> {
let message = mailparse::parse_mail(TEXT_PLAIN.as_bytes())?;
@ -88,4 +136,11 @@ Content-Type: text/html; charset="UTF-8"
assert_eq!(message.get_body_text()?.unwrap_or_default(), "Prostý text.");
Ok(())
}
#[test]
fn test_multipart_mixed_alternative_text_body() -> Result<(), anyhow::Error> {
let message = mailparse::parse_mail(MULTIPART_MIXED_ALTERNATIVE.as_bytes())?;
assert_eq!(message.get_body_text()?.unwrap_or_default(), "Prostý text.");
Ok(())
}
}