1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
use crate::MailMimeParser;
use crate::{
collection,
message::{
mail::{BodyType, Mail, MailHeaders},
mime_type::{Mime, MimeBodyType, MimeHeader, MimeMultipart},
},
MailParser,
};
const MAIL: &str = include_str!("../../mail/rfc2049/A.eml");
#[test]
#[allow(clippy::too_many_lines)]
#[ignore]
fn simple() {
let parsed = MailMimeParser::default()
.parse_sync(
MAIL.lines()
.map(|l| l.as_bytes().to_vec())
.collect::<Vec<_>>(),
)
.unwrap()
.unwrap_right();
pretty_assertions::assert_eq!(
parsed,
Mail {
headers: MailHeaders(
[
("mime-version", "1.0"),
("from", "Nathaniel Borenstein <nsb@nsb.fv.com>"),
("date", "Fri, 07 Oct 1994 16:15:05 -0700 (PDT)"),
("to", "Ned Freed <ned@innosoft.com>"),
("subject", "A multipart example"),
]
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect::<Vec<_>>()
),
body: BodyType::Mime(Box::new(Mime {
headers: [MimeHeader {
name: "content-type".to_string(),
value: "multipart/mixed".to_string(),
args: collection! {
"boundary".to_string() => "unique-boundary-1".to_string(),
},
},]
.to_vec(),
content: MimeBodyType::Multipart(MimeMultipart {
preamble: [
"This is the preamble area of a multipart message.\r\n",
"Mail readers that understand multipart format\r\n",
"should ignore this preamble.\r\n",
"\r\n",
"If you are reading this text, you might want to\r\n",
"consider changing to a mail reader that understands\r\n",
"how to properly display multipart messages.\r\n"
]
.concat(),
parts: vec![
Mime {
headers: vec![],
content: MimeBodyType::Regular(
[
" ... Some text appears here ...",
"",
"[Note that the blank between the boundary and the start",
" of the text in this part means no header fields were",
" given and this is text in the US-ASCII character set.",
" It could have been done with explicit typing as in the",
" next part.]",
"",
]
.into_iter()
.map(str::to_string)
.collect::<Vec<_>>()
)
},
Mime {
headers: vec![MimeHeader {
name: "content-type".to_string(),
value: "text/plain".to_string(),
args: collection! {
"charset".to_string() => "US-ASCII".to_string(),
},
},],
content: MimeBodyType::Regular(
[
"This could have been part of the previous part, but",
"illustrates explicit versus implicit typing of body",
"parts.",
"",
]
.into_iter()
.map(str::to_string)
.collect::<Vec<_>>(),
),
},
Mime {
headers: vec![MimeHeader {
name: "content-type".to_string(),
value: "multipart/parallel".to_string(),
args: collection! {
"boundary".to_string()=> "unique-boundary-2".to_string(),
},
},],
content: MimeBodyType::Multipart(MimeMultipart {
preamble: String::new(),
parts: vec![
Mime {
headers: vec![
MimeHeader {
name: "content-type".to_string(),
value: "audio/basic".to_string(),
args: collection! {},
},
MimeHeader {
name: "content-transfer-encoding".to_string(),
value: "base64".to_string(),
args: collection! {},
},
],
content: MimeBodyType::Regular(
[
" ... base64-encoded 8000 Hz single-channel",
" mu-law-format audio data goes here ...",
"",
]
.into_iter()
.map(str::to_string)
.collect::<Vec<_>>(),
)
},
Mime {
headers: vec![
MimeHeader {
name: "content-type".to_string(),
value: "image/jpeg".to_string(),
args: collection! {},
},
MimeHeader {
name: "content-transfer-encoding".to_string(),
value: "base64".to_string(),
args: collection! {},
},
],
content: MimeBodyType::Regular(
[" ... base64-encoded image data goes here ...", "",]
.into_iter()
.map(str::to_string)
.collect::<Vec<_>>(),
)
}
],
epilogue: String::new()
})
},
Mime {
headers: vec![MimeHeader {
name: "content-type".to_string(),
value: "text/enriched".to_string(),
args: collection! {},
},],
content: MimeBodyType::Regular(
[
"This is <bold><italic>enriched.</italic></bold>",
"<smaller>as defined in RFC 1896</smaller>",
"",
"Isn't it",
"<bigger><bigger>cool?</bigger></bigger>",
"",
]
.into_iter()
.map(str::to_string)
.collect::<Vec<_>>(),
)
},
Mime {
headers: vec![MimeHeader {
name: "content-type".to_string(),
value: "message/rfc822".to_string(),
args: collection! {},
},],
content: MimeBodyType::Embedded(Mail {
headers: MailHeaders(
[
("date", "(date in US-ASCII)"),
("from", "(mailbox in US-ASCII)"),
("to", "(address in US-ASCII)"),
("subject", "(subject in US-ASCII)"),
]
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.collect::<Vec<_>>()
),
// FIXME: line 68 and 69 are skipped (from .eml)
body: BodyType::Regular(
[" ... Additional text in ISO-8859-1 goes here ...", "",]
.into_iter()
.map(str::to_string)
.collect::<Vec<_>>(),
)
})
}
],
epilogue: String::new(),
})
}))
}
);
pretty_assertions::assert_eq!(parsed.to_string(), MAIL.replace('\n', "\r\n"));
}