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(
"
Hello, world!
".into(),
),
).singlepart(
SinglePart::base64()
.header(header::ContentType("image/png".parse().unwrap()))
.header(header::ContentDisposition {
disposition: header::DispositionType::Inline,
parameters: vec![],
}).body("".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 ".parse().unwrap())
.reply_to("Yuin ".parse().unwrap())
.to("Hei ".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);
}