diff --git a/src/parsing.rs b/src/parsing.rs index 776fc6e..5d93237 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -75,6 +75,54 @@ Content-Type: text/html; charset="UTF-8" "#; + const MULTIPART_MIXED_ALTERNATIVE: &str = r#"From: Andrey Golovizin +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" + + + + + +

Tu=C4=8Dn=C3=BD HTML text

+ + +--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(()) + } }