oxedyne/fe2o3/fe2o3_mail/tests/mime_corpus/mod.rs
8.1 KiB, 1 run
created by r1870400018:74946, 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 36-message MIME corpus of QA F2b (b), 2026-10-26: the shapes real clients send |
| 2 | //! (Outlook, Apple Mail, Mailman, bounces, forwards as attachments) and the malformed ones a |
| 3 | //! mailbox still holds. Shared by `message_structure` and `parser_compare`. |
| 4 | #![allow(dead_code)] |
| 5 | |
| 6 | pub mod old_message; |
| 7 | |
| 8 | pub fn mp(ct: &str, b: &str, parts: &[String]) -> String { |
| 9 | let mut s = fmt(ct, b); |
| 10 | s.push_str("This is a multi-part message in MIME format.\r\n\r\n"); |
| 11 | for p in parts { s.push_str(&format!("--{}\r\n{}\r\n", b, p)); } |
| 12 | s.push_str(&format!("--{}--\r\n", b)); |
| 13 | s |
| 14 | } |
| 15 | pub fn fmt(ct: &str, b: &str) -> String { format!("Content-Type: {}; boundary=\"{}\"\r\n\r\n", ct, b) } |
| 16 | pub fn leaf(ct: &str, extra: &str, body: &str) -> String { format!("Content-Type: {}\r\n{}\r\n{}", ct, extra, body) } |
| 17 | pub fn msg(hdr: &str, rest: &str) -> String { |
| 18 | format!("From: Bob <bob@x.org>\r\nTo: a@b\r\nSubject: =?ISO-8859-1?Q?Caf=E9?= test\r\n{}{}", hdr, rest) |
| 19 | } |
| 20 | |
| 21 | pub fn corpus() -> Vec<(&'static str, Vec<u8>)> { |
| 22 | let plain = leaf("text/plain; charset=utf-8", "", "the plain body"); |
| 23 | let html = leaf("text/html; charset=utf-8", "", "<p>the html body</p>"); |
| 24 | let pdf = leaf("application/pdf; name=\"report.pdf\"", "Content-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"report.pdf\"\r\n", "JVBERi0xLjQK"); |
| 25 | let img = leaf("image/png; name=\"image001.png\"", "Content-Transfer-Encoding: base64\r\nContent-ID: <i1>\r\nContent-Disposition: inline; filename=\"image001.png\"\r\n", "iVBORw0KGgo="); |
| 26 | let alt = mp("multipart/alternative", "ALT", &[plain.clone(), html.clone()]); |
| 27 | let inner_msg = msg("Message-ID: <in@x>\r\nMIME-Version: 1.0\r\n", &mp("multipart/alternative", "IN", &[leaf("text/plain", "", "INNER forwarded text"), leaf("text/html", "", "<p>INNER html</p>")])); |
| 28 | let rfc822 = format!("Content-Type: message/rfc822; name=\"fwd.eml\"\r\nContent-Disposition: attachment; filename=\"fwd.eml\"\r\n\r\n{}", inner_msg); |
| 29 | let mut v: Vec<(&str, String)> = Vec::new(); |
| 30 | v.push(("01 plain", msg("Content-Type: text/plain; charset=utf-8\r\n\r\n", "hello\r\nworld\r\n"))); |
| 31 | v.push(("02 alt", msg("", &alt))); |
| 32 | v.push(("03 html only", msg("Content-Type: text/html\r\n\r\n", "<html><body><p>only html</p></body></html>"))); |
| 33 | v.push(("04 mixed alt+pdf", msg("", &mp("multipart/mixed", "MIX", &[alt.clone(), pdf.clone()])))); |
| 34 | let related = mp("multipart/related", "REL", &[html.clone(), img.clone()]); |
| 35 | let ol_alt = mp("multipart/alternative", "OALT", &[plain.clone(), related.clone()]); |
| 36 | v.push(("05 outlook mixed>alt>related+pdf", msg("", &mp("multipart/mixed", "OMIX", &[ol_alt.clone(), pdf.clone()])))); |
| 37 | v.push(("06 outlook related>alt,img", msg("", &mp("multipart/related", "OREL", &[alt.clone(), img.clone()])))); |
| 38 | v.push(("07 fwd-as-attachment plain", msg("", &mp("multipart/mixed", "F1", &[leaf("text/plain", "", "see below"), rfc822.clone()])))); |
| 39 | let empty_alt = mp("multipart/alternative", "EALT", &[leaf("text/plain", "", "\r\n"), leaf("text/html", "", "<p>outer html note</p>")]); |
| 40 | v.push(("08 fwd empty-plain outer", msg("", &mp("multipart/mixed", "F2", &[empty_alt, rfc822.clone()])))); |
| 41 | v.push(("09 fwd html-only outer", msg("", &mp("multipart/mixed", "F3", &[html.clone(), rfc822.clone()])))); |
| 42 | v.push(("10 qp latin1", msg("Content-Type: text/plain; charset=iso-8859-1\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n", "Gr=FC=DFe aus K=F6ln, caf=E9=\r\n soft\r\n"))); |
| 43 | v.push(("11 b64 utf8", msg("Content-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n\r\n", "R3LDvMOfZSDwn5iA\r\n"))); |
| 44 | let mut v12 = msg("Content-Type: text/plain; charset=windows-1252\r\n\r\n", "").into_bytes(); |
| 45 | v12.extend_from_slice(b"\x93smart\x94 \x96 dash \x80 euro\r\n"); |
| 46 | let mut v13 = msg("Content-Type: text/plain; charset=koi8-r\r\nContent-Transfer-Encoding: 8bit\r\n\r\n", "").into_bytes(); |
| 47 | v13.extend_from_slice(b"\xf0\xd2\xc9\xd7\xc5\xd4 ascii-tail\r\n"); |
| 48 | let v14 = msg("Content-Type: text/plain; charset=iso-8859-1\r\n\r\n", "mislabelled café\r\n"); |
| 49 | v.push(("15 multipart no boundary", msg("Content-Type: multipart/mixed\r\n\r\n", "--X\r\nContent-Type: text/plain\r\n\r\nbody\r\n--X--\r\n"))); |
| 50 | v.push(("16 unclosed boundary", msg("", &mp("multipart/mixed", "U", &[plain.clone()]).replace("--U--\r\n", "")))); |
| 51 | v.push(("17 no blank line", "From: a@b\r\nSubject: hi\r\n".to_string())); |
| 52 | v.push(("18 bare LF", msg("", &alt).replace("\r\n", "\n"))); |
| 53 | let footer = leaf("text/plain; charset=us-ascii", "Content-Disposition: inline\r\n", "_______________\r\nlist mailing list\r\nhttps://lists.x/listinfo"); |
| 54 | v.push(("19 mailman footer after related", msg("", &mp("multipart/mixed", "MM", &[related.clone(), footer.clone()])))); |
| 55 | v.push(("19b mailman footer after alt", msg("", &mp("multipart/mixed", "MM", &[alt.clone(), footer.clone()])))); |
| 56 | v.push(("19c mailman footer after html", msg("", &mp("multipart/mixed", "MM", &[html.clone(), footer.clone()])))); |
| 57 | v.push(("20 filename with ;", msg("", &mp("multipart/mixed", "S", &[plain.clone(), leaf("application/pdf", "Content-Disposition: attachment; filename=\"a;b.pdf\"\r\n", "x")])))); |
| 58 | v.push(("21 rfc2231", msg("", &mp("multipart/mixed", "S", &[plain.clone(), leaf("application/pdf", "Content-Disposition: attachment;\r\n filename*=UTF-8''r%C3%A9sum%C3%A9.pdf\r\n", "x")])))); |
| 59 | v.push(("22 encoded-word filename", msg("", &mp("multipart/mixed", "S", &[plain.clone(), leaf("application/pdf; name=\"=?UTF-8?B?csOpc3Vtw6kucGRm?=\"", "Content-Disposition: attachment\r\n", "x")])))); |
| 60 | v.push(("23 bounce report", msg("", &mp("multipart/report; report-type=delivery-status", "R", &[leaf("text/plain", "", "Delivery failed"), leaf("message/delivery-status", "", "Reporting-MTA: dns; x\r\n"), format!("Content-Type: message/rfc822\r\n\r\n{}", msg("", &mp("multipart/mixed", "BM", &[leaf("text/plain", "", "orig"), pdf.clone()])))])))); |
| 61 | v.push(("24 txt attachment + html", msg("", &mp("multipart/mixed", "T", &[html.clone(), leaf("text/plain; name=\"log.txt\"", "Content-Disposition: attachment; filename=\"log.txt\"\r\n", "LOG CONTENT")])))); |
| 62 | v.push(("25 b64 message/rfc822", msg("", &mp("multipart/mixed", "B", &[plain.clone(), format!("Content-Type: message/rfc822\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"m.eml\"\r\n\r\nRnJvbTogYUBiDQpTdWJqZWN0OiBpbm5lcg0KDQppbm5lciBib2R5DQo=\r\n")])))); |
| 63 | let mut deep = plain.clone(); |
| 64 | for i in 0..10 { deep = mp("multipart/mixed", &format!("D{}", i), &[deep]); } |
| 65 | v.push(("26 deep 10", msg("", &deep))); |
| 66 | v.push(("28 boundary = spaced", msg("Content-Type: Multipart/Mixed; boundary = \"SP\"\r\n\r\n", "--SP\r\nContent-Type: text/plain\r\n\r\nspaced body\r\n--SP--\r\n"))); |
| 67 | v.push(("29 calendar", msg("", &mp("multipart/alternative", "C", &[plain.clone(), html.clone(), leaf("text/calendar; method=REQUEST; name=\"invite.ics\"", "", "BEGIN:VCALENDAR")])))); |
| 68 | v.push(("30 apple inline", msg("", &mp("multipart/alternative", "AP", &[plain.clone(), mp("multipart/mixed", "APM", &[html.clone(), img.clone(), leaf("text/html", "", "<p>after</p>")])])))); |
| 69 | v.push(("31 signed", msg("", &mp("multipart/signed; protocol=\"application/pkcs7-signature\"", "SG", &[alt.clone(), leaf("application/pkcs7-signature; name=\"smime.p7s\"", "Content-Disposition: attachment; filename=\"smime.p7s\"\r\n", "MIAG")])))); |
| 70 | v.push(("32 folded headers", "From: =?UTF-8?Q?J=C3=BCrgen?=\r\n <j@x>\r\nSubject: long\r\n\tsubject\r\nContent-Type: text/plain\r\n\r\nb\r\n".to_string())); |
| 71 | let mut v33 = msg("Content-Type: text/plain; charset=\"ISO-8859-1\"\r\n\r\n", "").into_bytes(); |
| 72 | v33.extend_from_slice(b"8bit caf\xe9\r\n"); |
| 73 | v.push(("34 plain part with name only (no disposition)", msg("", &mp("multipart/mixed", "N", &[leaf("text/plain; name=\"body.txt\"", "", "named body text"), html.clone()])))); |
| 74 | v.push(("35 boundary mid-line", msg("", &mp("multipart/mixed", "Q", &[leaf("text/plain", "", "text with --Q inside line"), pdf.clone()])))); |
| 75 | let mut out: Vec<(&str, Vec<u8>)> = v.into_iter().map(|(n, s)| (n, s.into_bytes())).collect(); |
| 76 | out.push(("12 cp1252", v12)); |
| 77 | out.push(("13 koi8-r", v13)); |
| 78 | out.push(("14 mislabelled", v14.into_bytes())); |
| 79 | out.push(("33 8bit latin1", v33)); |
| 80 | out |
| 81 | } |