#[macro_use]
extern crate mail;
extern crate futures;
extern crate soft_ascii_string;
use futures::Future;
use soft_ascii_string::SoftAsciiString;
use std::str;
use mail::{
HeaderTryFrom,
Mail, MailType,
Resource,
Context, Domain,
error::MailError,
default_impl::simple_context,
};
const MSG: &str =
"Dear Tree Apes,\r
\r
the next grate block buster is here 🎉\r
\r
With regards,\r
The Tree Movie Consortium\r
";
fn create_text_body(ctx: &impl Context) -> Resource {
Resource::plain_text(MSG, ctx)
}
fn build_mail(ctx: &impl Context) -> Result<Mail, MailError> {
use mail::headers::*;
let mut mail = Mail::new_singlepart_mail(create_text_body(ctx));
mail.insert_headers(headers! {
_From: [("Tree Movie Consortium", "datmail@dat.test")],
_To: [("Tree Ape Chief", "datothermail@dat.test")],
Subject: "Rise of the Type Lord: The 🙈 Emoji Plight"
}?);
Ok(mail)
}
fn encode_mail_to_stdout(mail: Mail, ctx: impl Context) -> Result<(), MailError> {
let bytes = mail
.into_encodable_mail(ctx)
.wait()?
.encode_into_bytes(MailType::Ascii)?;
println!("{}", str::from_utf8(bytes.as_slice())
.expect("[BUG] MailType::Ascii can't have non utf8 bytes"));
Ok(())
}
fn main() {
println!("---------------- START ---------------- ");
let msg_id_domain = Domain::try_from("company_a.test").unwrap();
let unique_part = SoftAsciiString::from_string("c207n521cec").unwrap();
let ctx = simple_context::new(msg_id_domain, unique_part).unwrap();
let mail = build_mail(&ctx).unwrap();
encode_mail_to_stdout(mail, ctx).unwrap();
println!("---------------- END ---------------- ");
}