@@ -35,42 +35,46 @@ Performance and memory safety were two important factors while designing _mail-p
35
35
## Usage Example
36
36
37
37
``` rust
38
- let input = concat! (
39
- " From: Art Vandelay <art@vandelay.com> (Vandelay Industries)\ n" ,
40
- " To: \ " Colleagues\ " : \ " James Smythe\ " <james@vandelay.com>; Friends:\ n" ,
41
- " jane@example.com, =?UTF-8?Q?John_Sm=C3=AEth?= <john@example.com>;\ n" ,
42
- " Date: Sat, 20 Nov 2021 14:22:01 -0800\ n" ,
43
- " Subject: Why not both importing AND exporting? =?utf-8?b?4pi6?=\ n" ,
44
- " Content-Type: multipart/mixed; boundary=\ " festivus\ " ;\ n\ n" ,
45
- " --festivus\ n" ,
46
- " Content-Type: text/html; charset=\ " us-ascii\ "\ n" ,
47
- " Content-Transfer-Encoding: base64\ n\ n" ,
48
- " PGh0bWw+PHA+SSB3YXMgdGhpbmtpbmcgYWJvdXQgcXVpdHRpbmcgdGhlICZsZHF1bztle\ n" ,
49
- " HBvcnRpbmcmcmRxdW87IHRvIGZvY3VzIGp1c3Qgb24gdGhlICZsZHF1bztpbXBvcnRpbm\ n" ,
50
- " cmcmRxdW87LDwvcD48cD5idXQgdGhlbiBJIHRob3VnaHQsIHdoeSBub3QgZG8gYm90aD8\ n" ,
51
- " gJiN4MjYzQTs8L3A+PC9odG1sPg==\ n" ,
52
- " --festivus\ n" ,
53
- " Content-Type: message/rfc822\ n\ n" ,
54
- " From: \ " Cosmo Kramer\ " <kramer@kramerica.com>\ n" ,
55
- " Subject: Exporting my book about coffee tables\ n" ,
56
- " Content-Type: multipart/mixed; boundary=\ " giddyup\ " ;\ n\ n" ,
57
- " --giddyup\ n" ,
58
- " Content-Type: text/plain; charset=\ " utf-16\ "\ n" ,
59
- " Content-Transfer-Encoding: quoted-printable\ n\ n" ,
60
- " =FF=FE=0C!5=D8\ " =DD5=D8)=DD5=D8-=DD =005=D8*=DD5=D8\ " =DD =005=D8\ " =\ n" ,
61
- " =DD5=D85=DD5=D8-=DD5=D8,=DD5=D8/=DD5=D81=DD =005=D8*=DD5=D86=DD =\ n" ,
62
- " =005=D8=1F=DD5=D8,=DD5=D8,=DD5=D8(=DD =005=D8-=DD5=D8)=DD5=D8\ " =\ n" ,
63
- " =DD5=D8=1E=DD5=D80=DD5=D8\ " =DD!=00\ n" ,
64
- " --giddyup\ n" ,
65
- " Content-Type: image/gif; name*1=\ " about \ " ; name*0=\ " Book \ " ;\ n" ,
66
- " name*2*=utf-8''%e2%98%95 tables.gif\ n" ,
67
- " Content-Transfer-Encoding: Base64\ n" ,
68
- " Content-Disposition: attachment\ n\ n" ,
69
- " R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\ n" ,
70
- " --giddyup--\ n" ,
71
- " --festivus--\ n" ,
72
- )
73
- . as_bytes ();
38
+ let input = br # " From: Art Vandelay <art@vandelay.com> (Vandelay Industries)
39
+ To: "Colleagues": "James Smythe" <james@vandelay.com>; Friends:
40
+ jane@example.com, =?UTF-8?Q?John_Sm=C3=AEth?= <john@example.com>;
41
+ Date: Sat, 20 Nov 2021 14:22:01 -0800
42
+ Subject: Why not both importing AND exporting? =?utf-8?b?4pi6?=
43
+ Content-Type: multipart/mixed; boundary="festivus";
44
+
45
+ --festivus
46
+ Content-Type: text/html; charset="us-ascii"
47
+ Content-Transfer-Encoding: base64
48
+
49
+ PGh0bWw+PHA+SSB3YXMgdGhpbmtpbmcgYWJvdXQgcXVpdHRpbmcgdGhlICZsZHF1bztle
50
+ HBvcnRpbmcmcmRxdW87IHRvIGZvY3VzIGp1c3Qgb24gdGhlICZsZHF1bztpbXBvcnRpbm
51
+ cmcmRxdW87LDwvcD48cD5idXQgdGhlbiBJIHRob3VnaHQsIHdoeSBub3QgZG8gYm90aD8
52
+ gJiN4MjYzQTs8L3A+PC9odG1sPg==
53
+ --festivus
54
+ Content-Type: message/rfc822
55
+
56
+ From: "Cosmo Kramer" <kramer@kramerica.com>
57
+ Subject: Exporting my book about coffee tables
58
+ Content-Type: multipart/mixed; boundary="giddyup";
59
+
60
+ --giddyup
61
+ Content-Type: text/plain; charset="utf-16"
62
+ Content-Transfer-Encoding: quoted-printable
63
+
64
+ =FF=FE=0C!5=D8"=DD5=D8)=DD5=D8-=DD =005=D8*=DD5=D8"=DD =005=D8"=
65
+ =DD5=D85=DD5=D8-=DD5=D8,=DD5=D8/=DD5=D81=DD =005=D8*=DD5=D86=DD =
66
+ =005=D8=1F=DD5=D8,=DD5=D8,=DD5=D8(=DD =005=D8-=DD5=D8)=DD5=D8"=
67
+ =DD5=D8=1E=DD5=D80=DD5=D8"=DD!=00
68
+ --giddyup
69
+ Content-Type: image/gif; name*1="about "; name*0="Book ";
70
+ name*2*=utf-8''%e2%98%95 tables.gif
71
+ Content-Transfer-Encoding: Base64
72
+ Content-Disposition: attachment
73
+
74
+ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
75
+ --giddyup--
76
+ --festivus--
77
+ " # ;
74
78
75
79
let message = Message :: parse (input ). unwrap ();
76
80
@@ -119,9 +123,9 @@ Performance and memory safety were two important factors while designing _mail-p
119
123
" Why not both importing AND exporting? ☺"
120
124
);
121
125
122
- // HTML and text body parts are returned conforming to RFC8621, Section 4.1.4
126
+ // HTML and text body parts are returned conforming to RFC8621, Section 4.1.4
123
127
assert_eq! (
124
- message . get_html_body (0 ). unwrap (). to_string () ,
128
+ message . get_html_body (0 ). unwrap (),
125
129
concat! (
126
130
" <html><p>I was thinking about quitting the “exporting” to " ,
127
131
" focus just on the “importing”,</p><p>but then I thought," ,
@@ -131,18 +135,19 @@ Performance and memory safety were two important factors while designing _mail-p
131
135
132
136
// HTML parts are converted to plain text (and viceversa) when missing
133
137
assert_eq! (
134
- message . get_text_body (0 ). unwrap (). to_string () ,
138
+ message . get_text_body (0 ). unwrap (),
135
139
concat! (
136
140
" I was thinking about quitting the “exporting” to focus just on the" ,
137
141
" “importing”,\ n but then I thought, why not do both? ☺\ n"
138
142
)
139
143
);
140
144
141
145
// Supports nested messages as well as multipart/digest
142
- let nested_message = match message . get_attachment (0 ). unwrap () {
143
- MessagePart :: Message (v ) => v ,
144
- _ => unreachable! (),
145
- };
146
+ let nested_message = message
147
+ . get_attachment (0 )
148
+ . unwrap ()
149
+ . unwrap_message ()
150
+ . get_body ();
146
151
147
152
assert_eq! (
148
153
nested_message . get_subject (). unwrap (),
@@ -151,18 +156,15 @@ Performance and memory safety were two important factors while designing _mail-p
151
156
152
157
// Handles UTF-* as well as many legacy encodings
153
158
assert_eq! (
154
- nested_message . get_text_body (0 ). unwrap (). to_string () ,
159
+ nested_message . get_text_body (0 ). unwrap (),
155
160
" ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!"
156
161
);
157
162
assert_eq! (
158
- nested_message . get_html_body (0 ). unwrap (). to_string () ,
163
+ nested_message . get_html_body (0 ). unwrap (),
159
164
" <html><body>ℌ𝔢𝔩𝔭 𝔪𝔢 𝔢𝔵𝔭𝔬𝔯𝔱 𝔪𝔶 𝔟𝔬𝔬𝔨 𝔭𝔩𝔢𝔞𝔰𝔢!</body></html>"
160
165
);
161
166
162
- let nested_attachment = match nested_message . get_attachment (0 ). unwrap () {
163
- MessagePart :: Binary (v ) => v ,
164
- _ => unreachable! (),
165
- };
167
+ let nested_attachment = nested_message . get_attachment (0 ). unwrap (). unwrap_binary ();
166
168
167
169
assert_eq! (nested_attachment . len (), 42 );
168
170
0 commit comments