summaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/examples/mail_by_hand.rs17
-rw-r--r--mail/examples/mail_from_template/main.rs29
-rw-r--r--mail/examples/send_mail/cli.rs48
-rw-r--r--mail/examples/send_mail/main.rs50
-rw-r--r--mail/src/lib.rs48
5 files changed, 75 insertions, 117 deletions
diff --git a/mail/examples/mail_by_hand.rs b/mail/examples/mail_by_hand.rs
index d52a735..58b1500 100644
--- a/mail/examples/mail_by_hand.rs
+++ b/mail/examples/mail_by_hand.rs
@@ -12,17 +12,12 @@ use soft_ascii_string::SoftAsciiString;
use std::str;
use mail::{
- HeaderTryFrom,
- Mail, MailType,
+ default_impl::simple_context, error::MailError, Context, Domain, HeaderTryFrom, Mail, MailType,
Resource,
- Context, Domain,
- error::MailError,
- default_impl::simple_context,
};
// Mail uses \r\n newlines!!
-const MSG: &str =
-"Dear Tree Apes,\r
+const MSG: &str = "Dear Tree Apes,\r
\r
the next grate block buster is here 🎉\r
\r
@@ -66,9 +61,11 @@ fn encode_mail_to_stdout(mail: Mail, ctx: impl Context) -> Result<(), MailError>
.encode_into_bytes(MailType::Ascii)?;
// Note how the 🙈 utf8 char will be automatically encoded (it would not be
- // specially encoded if MailType would be Internationalized).
- println!("{}", str::from_utf8(bytes.as_slice())
- .expect("[BUG] MailType::Ascii can't have non utf8 bytes"));
+ // specially encoded if MailType would be Internationalized).
+ println!(
+ "{}",
+ str::from_utf8(bytes.as_slice()).expect("[BUG] MailType::Ascii can't have non utf8 bytes")
+ );
Ok(())
}
diff --git a/mail/examples/mail_from_template/main.rs b/mail/examples/mail_from_template/main.rs
index deeda80..0ff2c42 100644
--- a/mail/examples/mail_from_template/main.rs
+++ b/mail/examples/mail_from_template/main.rs
@@ -2,15 +2,13 @@
//! (and then printed)
//!
-extern crate mail;
+extern crate failure;
extern crate futures;
-extern crate soft_ascii_string;
+extern crate mail;
extern crate serde;
-extern crate failure;
+extern crate soft_ascii_string;
-use std::{
- path::Path
-};
+use std::path::Path;
use failure::Error;
use futures::Future;
@@ -19,22 +17,15 @@ use soft_ascii_string::SoftAsciiString;
use serde::Serialize;
use mail::{
- Domain,
- MailType,
default_impl::simple_context,
- template::{
- load_toml_template_from_path,
- handlebars::Handlebars,
- TemplateExt
- },
headers,
- HeaderTryFrom,
- HeaderKind
+ template::{handlebars::Handlebars, load_toml_template_from_path, TemplateExt},
+ Domain, HeaderKind, HeaderTryFrom, MailType,
};
#[derive(Debug, Serialize)]
struct UserData {
- name: &'static str
+ name: &'static str,
}
fn main() {
@@ -49,7 +40,8 @@ fn main() {
let ctx = simple_context::new(msg_id_domain, unique_part).unwrap();
let engine = Handlebars::new();
- let template_path = Path::new("example_resources/templates/template_a/template.toml").to_owned();
+ let template_path =
+ Path::new("example_resources/templates/template_a/template.toml").to_owned();
let fut = load_toml_template_from_path(engine, template_path, &ctx)
.and_then(|template| -> Result<_, Error> {
// If our "user data" would contain additional inline_emebeddings/attachments
@@ -61,7 +53,8 @@ fn main() {
mail.insert_header(headers::_From::auto_body(["a@b.example"])?);
mail.insert_header(headers::_To::auto_body(["d@e.example"])?);
Ok(mail)
- }).and_then(|mail| mail.into_encodable_mail(ctx.clone()).map_err(Into::into));
+ })
+ .and_then(|mail| mail.into_encodable_mail(ctx.clone()).map_err(Into::into));
let enc_mail = fut.wait().unwrap();
let bytes = enc_mail.encode_into_bytes(MailType::Ascii).unwrap();
diff --git a/mail/examples/send_mail/cli.rs b/mail/examples/send_mail/cli.rs
index e2c14d6..535cfe9 100644
--- a/mail/examples/send_mail/cli.rs
+++ b/mail/examples/send_mail/cli.rs
@@ -1,28 +1,22 @@
-use std::io::{
- self,
- StdinLock, StdoutLock,
- BufReader, BufRead,
- Write
-};
+use std::io::{self, BufRead, BufReader, StdinLock, StdoutLock, Write};
use std::str::FromStr;
use rpassword::read_password_with_reader;
-
use mail::{
- Mailbox, Email, HeaderTryFrom,
+ header_components::{Phrase, Unstructured},
smtp::misc::Domain,
- header_components::{Phrase, Unstructured}
+ Email, HeaderTryFrom, Mailbox,
};
-
pub struct ClDialog<'a> {
stdin: BufReader<StdinLock<'a>>,
- stdout: StdoutLock<'a>
+ stdout: StdoutLock<'a>,
}
pub fn with_dialog<FN, R>(func: FN) -> R
- where FN: for<'a> FnOnce(ClDialog<'a>) -> R
+where
+ FN: for<'a> FnOnce(ClDialog<'a>) -> R,
{
let stdin = io::stdin();
let stdout = io::stdout();
@@ -31,9 +25,11 @@ pub fn with_dialog<FN, R>(func: FN) -> R
}
impl<'a> ClDialog<'a> {
-
pub fn new(stdin: StdinLock<'a>, stdout: StdoutLock<'a>) -> Self {
- ClDialog { stdin: BufReader::new(stdin), stdout }
+ ClDialog {
+ stdin: BufReader::new(stdin),
+ stdout,
+ }
}
pub fn stdout(&mut self) -> &mut StdoutLock<'a> {
@@ -84,7 +80,7 @@ impl<'a> ClDialog<'a> {
self.prompt("- Email Address")?;
let email = self.read_email()?;
self.prompt("- Display Name")?;
- let display_name = self.read_opt_phrase()?;
+ let display_name = self.read_opt_phrase()?;
Ok(Mailbox::from((display_name, email)))
}
@@ -92,7 +88,6 @@ impl<'a> ClDialog<'a> {
read_password_with_reader(Some(&mut self.stdin))
}
-
pub fn read_mail_text_body(&mut self) -> Result<String, io::Error> {
let mut buf = String::new();
while self.stdin.read_line(&mut buf)? != 0 {
@@ -156,9 +151,7 @@ impl<'a> ClDialog<'a> {
writeln!(self.stdout, "To/Recipient")?;
let to = self.read_mailbox()?;
self.prompt("Subject")?;
- let subject = Unstructured
- ::try_from(self.read_line()?.trim())
- .unwrap();
+ let subject = Unstructured::try_from(self.read_line()?.trim()).unwrap();
writeln!(self.stdout, "Utf-8 text body [end with Ctrl-D]:")?;
self.stdout.flush()?;
@@ -167,7 +160,7 @@ impl<'a> ClDialog<'a> {
from,
to,
subject,
- text_body
+ text_body,
})
}
@@ -175,18 +168,16 @@ impl<'a> ClDialog<'a> {
loop {
let line = self.read_line()?;
let line = line.trim();
- let valid =
- match line {
- "y" => true,
- "n" => false,
- _ => continue
- };
+ let valid = match line {
+ "y" => true,
+ "n" => false,
+ _ => continue,
+ };
return Ok(valid);
}
}
}
-
/// POD
#[derive(Debug)]
pub struct AuthData {
@@ -198,7 +189,7 @@ pub struct AuthData {
#[derive(Debug)]
pub struct MsaInfo {
pub domain: Domain,
- pub auth: AuthData
+ pub auth: AuthData,
}
/// POD
@@ -209,4 +200,3 @@ pub struct SimpleMail {
pub subject: Unstructured,
pub text_body: String,
}
-
diff --git a/mail/examples/send_mail/main.rs b/mail/examples/send_mail/main.rs
index bccfde9..a9303ec 100644
--- a/mail/examples/send_mail/main.rs
+++ b/mail/examples/send_mail/main.rs
@@ -6,30 +6,25 @@ compile_error!("example `send_mail` requires feature `smtp`");
#[macro_use]
extern crate mail;
-extern crate rpassword;
extern crate futures;
-extern crate tokio;
+extern crate rpassword;
extern crate soft_ascii_string;
+extern crate tokio;
use std::io::{self, Write};
-use futures::{Stream, future};
+use futures::{future, Stream};
use soft_ascii_string::SoftAsciiString;
use mail::{
- Mail,
- HeaderTryFrom,
- smtp::{
- send_batch as send_mail_batch,
- MailRequest,
- ConnectionConfig,
- ConnectionBuilder,
- auth::{Plain as AuthPlain}
- },
- error::MailError,
default_impl::simple_context,
+ error::MailError,
header_components::Domain,
- Context
+ smtp::{
+ auth::Plain as AuthPlain, send_batch as send_mail_batch, ConnectionBuilder,
+ ConnectionConfig, MailRequest,
+ },
+ Context, HeaderTryFrom, Mail,
};
mod cli;
@@ -53,7 +48,7 @@ fn main() {
.for_each(|res| {
match res {
Ok(_) => println!("[mail send]"),
- Err(err) => println!("[sending mail failed] {:?}", err)
+ Err(err) => println!("[sending mail failed] {:?}", err),
}
Ok(())
})
@@ -67,20 +62,28 @@ fn create_connection_config(msa_info: cli::MsaInfo) -> ConnectionConfig<AuthPlai
ConnectionBuilder::new(domain)
.expect("could not resolve domain/host name of MSA")
- .auth(AuthPlain::from_username(auth.username, auth.password)
- .expect("used \\0 in username or password"))
+ .auth(
+ AuthPlain::from_username(auth.username, auth.password)
+ .expect("used \\0 in username or password"),
+ )
.build()
}
-fn create_mail_requests(mails: Vec<cli::SimpleMail>, ctx: &impl Context)
- -> Result<Vec<MailRequest>, MailError>
-{
+fn create_mail_requests(
+ mails: Vec<cli::SimpleMail>,
+ ctx: &impl Context,
+) -> Result<Vec<MailRequest>, MailError> {
use mail::headers::*;
let requests = mails
.into_iter()
.map(|simple_mail| {
- let cli::SimpleMail { from, to, subject, text_body } = simple_mail;
+ let cli::SimpleMail {
+ from,
+ to,
+ subject,
+ text_body,
+ } = simple_mail;
let mut mail = Mail::plain_text(text_body, ctx);
mail.insert_headers(headers! {
_From: [from],
@@ -90,13 +93,11 @@ fn create_mail_requests(mails: Vec<cli::SimpleMail>, ctx: &impl Context)
Ok(MailRequest::from(mail))
})
- .collect::<Result<Vec<_>,_>>();
+ .collect::<Result<Vec<_>, _>>();
requests
}
-
-
fn read_data() -> Result<(cli::MsaInfo, Vec<cli::SimpleMail>), io::Error> {
cli::with_dialog(|mut dialog| {
let msa_info = dialog.read_msa_info()?;
@@ -114,4 +115,3 @@ fn read_data() -> Result<(cli::MsaInfo, Vec<cli::SimpleMail>), io::Error> {
Ok((msa_info, mails))
})
}
-
diff --git a/mail/src/lib.rs b/mail/src/lib.rs
index d9b5904..9712891 100644
--- a/mail/src/lib.rs
+++ b/mail/src/lib.rs
@@ -88,16 +88,16 @@
//! re-exported as it can be seen as an internal part of the implementation
//! which normally doesn't need to be accessed directly.
+extern crate mail_core;
+extern crate mail_headers;
#[doc(hidden)]
pub extern crate mail_internals as internals;
-extern crate mail_headers;
-extern crate mail_core;
pub extern crate mail_template as template;
use self::template as mail_template;
-#[cfg(feature="smtp")]
+#[cfg(feature = "smtp")]
pub extern crate mail_smtp as smtp;
-#[cfg(all(feature="serde", not(feature="serde-impl")))]
+#[cfg(all(feature = "serde", not(feature = "serde-impl")))]
compile_error! {"use feature `serde-impl` instead of pseudo-feature `serde`"}
/// Re-export of all parts of the `mail_core` crate.
@@ -115,11 +115,11 @@ pub use mail_core::*;
/// - `mail-smtp` (feature: `smtp`)
pub mod error {
pub use crate::internals::error::*;
+ pub use mail_core::error::*;
pub use mail_headers::error::*;
pub use mail_headers::InvalidHeaderName;
- pub use mail_core::error::*;
pub use mail_template::error::*;
- #[cfg(feature="smtp")]
+ #[cfg(feature = "smtp")]
pub use smtp::error::*;
}
@@ -127,40 +127,18 @@ pub use self::internals::MailType;
/// Re-export of headers from `mail-headers`.
pub use mail_headers::{
- headers,
- header_components,
-
- HasHeaderName,
- HeaderKind,
- HeaderObj,
- HeaderObjTrait,
- HeaderObjTraitBoxExt,
- HeaderTryFrom,
- HeaderTryInto,
- MaxOneMarker,
-
- map as header_map,
-
- Header,
- HeaderName,
- HeaderMap,
-
- def_headers,
+ def_headers, header_components, headers, map as header_map, HasHeaderName, Header, HeaderKind,
+ HeaderMap, HeaderName, HeaderObj, HeaderObjTrait, HeaderObjTraitBoxExt, HeaderTryFrom,
+ HeaderTryInto, MaxOneMarker,
};
#[doc(hidden)]
pub use mail_headers::data;
-pub use self::header_components::{
- MediaType,
- Mailbox,
- Email,
- Domain
-};
-
+pub use self::header_components::{Domain, Email, Mailbox, MediaType};
// Re-export some parts of mail-internals useful for writing custom header.
-pub use crate::internals::{encoder as header_encoding};
+pub use crate::internals::encoder as header_encoding;
/// Re-export of the default_impl parts from `mail-core`.
///
@@ -170,7 +148,7 @@ pub mod default_impl {
pub use mail_core::default_impl::*;
}
-#[cfg(feature="test-utils")]
+#[cfg(feature = "test-utils")]
pub mod test_utils {
pub use mail_core::test_utils::*;
-} \ No newline at end of file
+}