-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathformat_stream_multipart.rs
71 lines (66 loc) · 2.75 KB
/
format_stream_multipart.rs
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
extern crate emailmessage;
extern crate futures;
extern crate tokio;
use emailmessage::{header, Message, MultiPart, SinglePart};
use futures::{Future, Stream};
use std::str::from_utf8;
use tokio::run;
fn main() {
let b: MultiPart = MultiPart::mixed()
.multipart(
MultiPart::alternative()
.singlepart(
SinglePart::quoted_printable()
.header(header::ContentType(
"text/plain; charset=utf8".parse().unwrap(),
)).body("Привет, мир!".into()),
).multipart(
MultiPart::related()
.singlepart(
SinglePart::eight_bit()
.header(header::ContentType(
"text/html; charset=utf8".parse().unwrap(),
)).body(
"<p><b>Hello</b>, <i>world</i>! <img src=smile.png></p>".into(),
),
).singlepart(
SinglePart::base64()
.header(header::ContentType("image/png".parse().unwrap()))
.header(header::ContentDisposition {
disposition: header::DispositionType::Inline,
parameters: vec![],
}).body("<smile-raw-image-data>".into()),
),
),
).singlepart(
SinglePart::seven_bit()
.header(header::ContentType(
"text/plain; charset=utf8".parse().unwrap(),
)).header(header::ContentDisposition {
disposition: header::DispositionType::Attachment,
parameters: vec![header::DispositionParam::Filename(
header::Charset::Ext("utf-8".into()),
None,
"example.c".as_bytes().into(),
)],
}).body("int main() { return 0; }".into()),
);
let m = Message::builder()
.from("NoBody <[email protected]>".parse().unwrap())
.reply_to("Yuin <[email protected]>".parse().unwrap())
.to("Hei <[email protected]>".parse().unwrap())
.subject("Happy new year")
.mime_body(b.into_stream());
let f = m
.into_stream()
.map(|chunk| {
println!("CHUNK[[\n{}]]", from_utf8(&chunk).unwrap());
chunk
}).concat2()
.map(|message| {
println!("MESSSAGE[[\n{}]]", from_utf8(&message).unwrap());
}).map_err(|error| {
eprintln!("ERROR: {:?}", error);
});
run(f);
}