summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Korber <p.korber@1aim.com>2018-11-16 18:12:33 +0100
committerPhilipp Korber <p.korber@1aim.com>2018-11-16 19:15:51 +0100
commit1f75ff41886350cd153fe1a675f6420befdda2fd (patch)
treed28a9c92f1cf1f07f77a5c93766338cb74230bb4
parent2a640a90d455cf7c380a591b5ab1fcd36641b212 (diff)
chore(deps) applied api changes to examples
-rw-r--r--mail/Cargo.toml11
-rw-r--r--mail/examples/mail_by_hand.rs12
-rw-r--r--mail/examples/send_mail/main.rs11
-rw-r--r--smtp/src/lib.rs4
4 files changed, 26 insertions, 12 deletions
diff --git a/mail/Cargo.toml b/mail/Cargo.toml
index b1db32f..2a3a25f 100644
--- a/mail/Cargo.toml
+++ b/mail/Cargo.toml
@@ -9,6 +9,7 @@ description = "mail, facade for a number of mail related crates for creating and
license = "MIT OR Apache-2.0"
readme = "./README.md"
repository = "https://github.com/1aim/mail"
+autoexamples = false
[features]
smtp = ["mail-smtp"]
@@ -20,6 +21,16 @@ smtp = ["mail-smtp"]
traceing = ["mail-internals/traceing", "mail-headers/traceing"]
test-utils = ["mail-core/test-utils"]
+# [[example]]
+# name = "mail-from_template"
+# crate-type = ["bin"]
+# path = "examples/mail_from_template/main.rs"
+# required-feature = ["render-template-engine", "tera-engine"]
+
+[[example]]
+name = "send_mail"
+crate-type = ["bin"]
+path = "examples/send_mail/main.rs"
[dependencies]
mail-internals = { path="../internals" }
diff --git a/mail/examples/mail_by_hand.rs b/mail/examples/mail_by_hand.rs
index c5414b8..d52a735 100644
--- a/mail/examples/mail_by_hand.rs
+++ b/mail/examples/mail_by_hand.rs
@@ -30,14 +30,14 @@ With regards,\r
The Tree Movie Consortium\r
";
-fn create_text_body() -> Resource {
- Resource::sourceless_from_string(MSG.to_owned())
+fn create_text_body(ctx: &impl Context) -> Resource {
+ Resource::plain_text(MSG, ctx)
}
-fn build_mail() -> Result<Mail, MailError> {
+fn build_mail(ctx: &impl Context) -> Result<Mail, MailError> {
use mail::headers::*;
- let mut mail = Mail::new_singlepart_mail(create_text_body());
+ let mut mail = Mail::new_singlepart_mail(create_text_body(ctx));
mail.insert_headers(headers! {
// `From` can have more than one mailbox.
_From: [("Tree Movie Consortium", "datmail@dat.test")],
@@ -53,7 +53,7 @@ fn build_mail() -> Result<Mail, MailError> {
fn encode_mail_to_stdout(mail: Mail, ctx: impl Context) -> Result<(), MailError> {
let bytes = mail
// This loads lazy resources, e.g. attachments/embeddings.
- .into_encodeable_mail(ctx)
+ .into_encodable_mail(ctx)
// It's a future, but we will just block here.
.wait()?
// Encodes mail and returns a `Vec<u8>` representing the
@@ -78,7 +78,7 @@ fn main() {
let unique_part = SoftAsciiString::from_string("c207n521cec").unwrap();
let ctx = simple_context::new(msg_id_domain, unique_part).unwrap();
- let mail = build_mail().unwrap();
+ let mail = build_mail(&ctx).unwrap();
encode_mail_to_stdout(mail, ctx).unwrap();
println!("---------------- END ---------------- ");
}
diff --git a/mail/examples/send_mail/main.rs b/mail/examples/send_mail/main.rs
index f00a982..bccfde9 100644
--- a/mail/examples/send_mail/main.rs
+++ b/mail/examples/send_mail/main.rs
@@ -28,7 +28,8 @@ use mail::{
},
error::MailError,
default_impl::simple_context,
- header_components::Domain
+ header_components::Domain,
+ Context
};
mod cli;
@@ -39,7 +40,7 @@ fn main() {
let ctx = simple_context::new(msg_id_domain, unique_part).unwrap();
let (msa_info, mails) = read_data().unwrap();
let connection_config = create_connection_config(msa_info);
- let mail_requests = create_mail_requests(mails).unwrap();
+ let mail_requests = create_mail_requests(mails, &ctx).unwrap();
println!("[starting sending mails]");
@@ -71,14 +72,16 @@ fn create_connection_config(msa_info: cli::MsaInfo) -> ConnectionConfig<AuthPlai
.build()
}
-fn create_mail_requests(mails: Vec<cli::SimpleMail>) -> 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 mut mail = Mail::plain_text(text_body);
+ let mut mail = Mail::plain_text(text_body, ctx);
mail.insert_headers(headers! {
_From: [from],
_To: [to],
diff --git a/smtp/src/lib.rs b/smtp/src/lib.rs
index 271fa46..f6c2cbb 100644
--- a/smtp/src/lib.rs
+++ b/smtp/src/lib.rs
@@ -41,7 +41,7 @@
//! let ctx = simple_context::new(Domain::from_unchecked("example.com".to_owned()), "asdkds".parse().unwrap())
//! .unwrap();
//!
-//! let mut mail = Mail::plain_text("Some body");
+//! let mut mail = Mail::plain_text("Some body", &ctx);
//! mail.insert_headers(headers! {
//! _From: ["bla@example.com"],
//! _To: ["blub@example.com"],
@@ -50,7 +50,7 @@
//!
//! // don't use unencrypted con for anything but testing and
//! // simplified examples
-//! let con_config = ConnectionConfig::build_local_unencrypted().build();
+//! let con_config = ConnectionConfig::builder_local_unencrypted().build();
//!
//! let fut = smtp::send(mail.into(), con_config, ctx);
//! let results = fut.wait();