oxedyne/fe2o3/fe2o3_mail/tests/message_structure.rs
3.7 KiB, 1 run
created by r1870400018:74944, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | //! The displayed body and the attachment list follow the MIME structure (RFC 2046): plain over |
| 2 | //! HTML only within a `multipart/alternative`, the parts of a `mixed` in order, and an attached |
| 3 | //! message one attachment of its parent, never the source of this message's text. The cases |
| 4 | //! are QA F2b (b)'s regressions R1 to R5, out of the shared corpus. |
| 5 | |
| 6 | mod mime_corpus; |
| 7 | |
| 8 | use crate::mime_corpus::corpus; |
| 9 | |
| 10 | use oxedyne_fe2o3_mail::message::ParsedMessage; |
| 11 | |
| 12 | |
| 13 | fn case(name: &str) -> ParsedMessage { |
| 14 | let raw = corpus().into_iter() |
| 15 | .find(|(n, _)| n.starts_with(name)) |
| 16 | .map(|(_, r)| r) |
| 17 | .unwrap_or_default(); |
| 18 | assert!(!raw.is_empty(), "no corpus case {}", name); |
| 19 | ParsedMessage::parse(&raw) |
| 20 | } |
| 21 | |
| 22 | const FOOTER: &str = "_______________\nlist mailing list\nhttps://lists.x/listinfo"; |
| 23 | |
| 24 | #[test] |
| 25 | fn an_attached_message_is_one_attachment() { |
| 26 | // R1: a message/rfc822 part is listed under its file name, also when base64-encoded. |
| 27 | let m = case("07 "); |
| 28 | assert_eq!(m.body, "see below"); |
| 29 | assert_eq!(m.attachments, vec!["fwd.eml".to_string()]); |
| 30 | let m = case("25 "); |
| 31 | assert_eq!(m.body, "the plain body"); |
| 32 | assert_eq!(m.attachments, vec!["m.eml".to_string()]); |
| 33 | } |
| 34 | |
| 35 | #[test] |
| 36 | fn text_never_comes_from_inside_an_attached_message() { |
| 37 | // R2: the outer text is HTML only, or its text/plain is empty. |
| 38 | let m = case("08 "); |
| 39 | assert_eq!(m.body, "outer html note"); |
| 40 | assert_eq!(m.attachments, vec!["fwd.eml".to_string()]); |
| 41 | let m = case("09 "); |
| 42 | assert_eq!(m.body, "the html body"); |
| 43 | assert_eq!(m.attachments, vec!["fwd.eml".to_string()]); |
| 44 | } |
| 45 | |
| 46 | #[test] |
| 47 | fn a_list_footer_follows_the_html_body() { |
| 48 | // R3: mixed > [related > [html, img], text/plain footer]. |
| 49 | let m = case("19 "); |
| 50 | assert_eq!(m.body, format!("the html body\n\n{}", FOOTER)); |
| 51 | assert_eq!(m.attachments, vec!["image001.png".to_string()]); |
| 52 | let m = case("19b"); |
| 53 | assert_eq!(m.body, format!("the plain body\n\n{}", FOOTER)); |
| 54 | let m = case("19c"); |
| 55 | assert_eq!(m.body, format!("the html body\n\n{}", FOOTER)); |
| 56 | } |
| 57 | |
| 58 | #[test] |
| 59 | fn a_quoted_file_name_keeps_its_semicolon() { |
| 60 | // R4. |
| 61 | assert_eq!(case("20 ").attachments, vec!["a;b.pdf".to_string()]); |
| 62 | } |
| 63 | |
| 64 | #[test] |
| 65 | fn an_rfc_2231_file_name_is_decoded() { |
| 66 | assert_eq!(case("21 ").attachments, vec!["résumé.pdf".to_string()]); |
| 67 | } |
| 68 | |
| 69 | #[test] |
| 70 | fn a_bounce_lists_the_returned_message_not_its_attachments() { |
| 71 | // R5: the bounced message is one attachment, named by its subject; its report.pdf is not |
| 72 | // the bounce's own. |
| 73 | let m = case("23 "); |
| 74 | assert_eq!(m.body, "Delivery failed"); |
| 75 | assert_eq!(m.attachments, vec!["Café test".to_string()]); |
| 76 | } |
| 77 | |
| 78 | #[test] |
| 79 | fn alternative_prefers_plain_among_its_own_parts() { |
| 80 | assert_eq!(case("02 ").body, "the plain body"); |
| 81 | assert_eq!(case("05 ").body, "the plain body"); |
| 82 | assert_eq!(case("05 ").attachments, vec!["image001.png".to_string(), "report.pdf".to_string()]); |
| 83 | assert_eq!(case("06 ").body, "the plain body"); |
| 84 | assert_eq!(case("30 ").body, "the plain body"); |
| 85 | assert_eq!(case("29 ").body, "the plain body"); |
| 86 | } |
| 87 | |
| 88 | #[test] |
| 89 | fn mixed_parts_read_in_order() { |
| 90 | // Apple Mail's inline image between two HTML parts, reached when there is no plain. |
| 91 | let raw = mime_corpus::msg("", &mime_corpus::mp("multipart/mixed", "APM", &[ |
| 92 | mime_corpus::leaf("text/html", "", "<p>before</p>"), |
| 93 | mime_corpus::leaf("image/png; name=\"i.png\"", "Content-Disposition: inline; filename=\"i.png\"\r\n", "x"), |
| 94 | mime_corpus::leaf("text/html", "", "<p>after</p>"), |
| 95 | ])); |
| 96 | let m = ParsedMessage::parse(raw.as_bytes()); |
| 97 | assert_eq!(m.body, "before\n\nafter"); |
| 98 | assert_eq!(m.attachments, vec!["i.png".to_string()]); |
| 99 | // An attached text file is not the body. |
| 100 | assert_eq!(case("24 ").body, "the html body"); |
| 101 | assert_eq!(case("24 ").attachments, vec!["log.txt".to_string()]); |
| 102 | } |