summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-23 12:51:54 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-23 12:51:54 +0100
commit31193c2bef934d26265673c91cbea0b64a53cd15 (patch)
tree105163b13ed6fcb43e655f233679cc5947cf0b7b
parent71ea078d4eb5d857680a69b01f7427ea43e2f5a2 (diff)
Run cargo-fmt on codebasecargo-fmt
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--core/examples/readme.rs18
-rw-r--r--core/src/compose.rs118
-rw-r--r--core/src/context.rs207
-rw-r--r--core/src/default_impl/cpupool.rs27
-rw-r--r--core/src/default_impl/fs.rs153
-rw-r--r--core/src/default_impl/message_id_gen.rs46
-rw-r--r--core/src/default_impl/mod.rs17
-rw-r--r--core/src/default_impl/simple_context.rs30
-rw-r--r--core/src/encode.rs128
-rw-r--r--core/src/error.rs37
-rw-r--r--core/src/iri.rs75
-rw-r--r--core/src/lib.rs45
-rw-r--r--core/src/macros.rs37
-rw-r--r--core/src/mail.rs300
-rw-r--r--core/src/mime.rs34
-rw-r--r--core/src/resource/data.rs122
-rw-r--r--core/src/resource/loading.rs68
-rw-r--r--core/src/resource/mod.rs22
-rw-r--r--core/src/resource/source.rs25
-rw-r--r--core/src/test_utils.rs10
-rw-r--r--core/src/utils.rs14
-rw-r--r--core/tests/mail.rs2
-rw-r--r--core/tests/resource/load_file.rs40
-rw-r--r--core/tests/resource/mod.rs1
-rw-r--r--headers/src/convert.rs10
-rw-r--r--headers/src/data/inner_item.rs130
-rw-r--r--headers/src/data/input.rs93
-rw-r--r--headers/src/data/mod.rs2
-rw-r--r--headers/src/data/simple_item.rs74
-rw-r--r--headers/src/error.rs61
-rw-r--r--headers/src/header.rs65
-rw-r--r--headers/src/header_components/cfws.rs14
-rw-r--r--headers/src/header_components/date_time.rs52
-rw-r--r--headers/src/header_components/disposition.rs131
-rw-r--r--headers/src/header_components/email.rs210
-rw-r--r--headers/src/header_components/file_meta.rs26
-rw-r--r--headers/src/header_components/mailbox.rs136
-rw-r--r--headers/src/header_components/mailbox_list.rs70
-rw-r--r--headers/src/header_components/media_type.rs152
-rw-r--r--headers/src/header_components/message_id.rs243
-rw-r--r--headers/src/header_components/mod.rs8
-rw-r--r--headers/src/header_components/path.rs31
-rw-r--r--headers/src/header_components/phrase.rs79
-rw-r--r--headers/src/header_components/phrase_list.rs60
-rw-r--r--headers/src/header_components/raw_unstructured.rs29
-rw-r--r--headers/src/header_components/received_token.rs61
-rw-r--r--headers/src/header_components/transfer_encoding.rs49
-rw-r--r--headers/src/header_components/unstructured.rs79
-rw-r--r--headers/src/header_components/utils/mod.rs55
-rw-r--r--headers/src/header_components/utils/text_partition.rs27
-rw-r--r--headers/src/header_components/word.rs204
-rw-r--r--headers/src/header_macro.rs3
-rw-r--r--headers/src/headers.rs39
-rw-r--r--headers/src/lib.rs21
-rw-r--r--headers/src/macros.rs54
-rw-r--r--headers/src/map/into_iter.rs7
-rw-r--r--headers/src/map/mod.rs283
-rw-r--r--headers/src/name.rs76
-rw-r--r--internals/src/bind/base64.rs112
-rw-r--r--internals/src/bind/encoded_word/impls.rs77
-rw-r--r--internals/src/bind/encoded_word/mod.rs47
-rw-r--r--internals/src/bind/idna.rs44
-rw-r--r--internals/src/bind/mime.rs27
-rw-r--r--internals/src/bind/mod.rs6
-rw-r--r--internals/src/bind/quoted_printable.rs143
-rw-r--r--internals/src/bind/quoted_string.rs23
-rw-r--r--internals/src/encoder/encodable.rs59
-rw-r--r--internals/src/encoder/mod.rs751
-rw-r--r--internals/src/encoder/trace.rs30
-rw-r--r--internals/src/error.rs58
-rw-r--r--internals/src/grammar.rs128
-rw-r--r--internals/src/lib.rs18
-rw-r--r--internals/src/macros.rs38
-rw-r--r--internals/src/mail_type.rs7
-rw-r--r--internals/src/utils/mod.rs38
-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
-rw-r--r--smtp/src/error.rs21
-rw-r--r--smtp/src/lib.rs25
-rw-r--r--smtp/src/request.rs176
-rw-r--r--smtp/src/resolve_all.rs40
-rw-r--r--smtp/src/send_mail.rs100
-rw-r--r--template/src/additional_cid.rs37
-rw-r--r--template/src/base_dir.rs46
-rw-r--r--template/src/error.rs2
-rw-r--r--template/src/handlebars.rs70
-rw-r--r--template/src/lib.rs202
-rw-r--r--template/src/path_rebase.rs81
-rw-r--r--template/src/serde_impl.rs197
92 files changed, 3304 insertions, 3701 deletions
diff --git a/core/examples/readme.rs b/core/examples/readme.rs
index 5e0cd42..7f2c0ed 100644
--- a/core/examples/readme.rs
+++ b/core/examples/readme.rs
@@ -6,24 +6,17 @@ extern crate mail_internals;
#[macro_use]
extern crate mail_headers;
-use std::str;
use futures::Future;
+use std::str;
use mail_internals::MailType;
// In the facade this is the `headers` module.
-use mail_headers::{
- headers::*,
- header_components::Domain
-};
+use mail_headers::{header_components::Domain, headers::*};
// In the facade this types (and the default_impl module)
// are also exposed at top level
-use mail_core::{
- Mail,
- default_impl::simple_context,
- error::MailError
-};
+use mail_core::{default_impl::simple_context, error::MailError, Mail};
fn print_some_mail() -> Result<(), MailError> {
// Domain will implement `from_str` in the future,
@@ -43,7 +36,8 @@ fn print_some_mail() -> Result<(), MailError> {
// We don't added any think which needs loading but we could have
// and all of it would have been loaded concurrent and async.
- let encoded = mail.into_encodable_mail(ctx.clone())
+ let encoded = mail
+ .into_encodable_mail(ctx.clone())
.wait()?
.encode_into_bytes(MailType::Ascii)?;
@@ -54,4 +48,4 @@ fn print_some_mail() -> Result<(), MailError> {
fn main() {
print_some_mail().unwrap()
-} \ No newline at end of file
+}
diff --git a/core/src/compose.rs b/core/src/compose.rs
index 1334a22..e69317b 100644
--- a/core/src/compose.rs
+++ b/core/src/compose.rs
@@ -17,23 +17,15 @@
// in the later part of the file for better readability. ||
//-------------------------------------------------------------//
-use media_type::{MULTIPART, ALTERNATIVE, RELATED, MIXED};
+use media_type::{ALTERNATIVE, MIXED, MULTIPART, RELATED};
use vec1::Vec1;
use headers::{
- HeaderKind,
- headers,
- header_components::{
- Disposition,
- DispositionKind,
- MediaType
- }
+ header_components::{Disposition, DispositionKind, MediaType},
+ headers, HeaderKind,
};
-use crate::{
- mail::Mail,
- resource::Resource
-};
+use crate::{mail::Mail, resource::Resource};
/// Parts used to create a mail body (in a multipart mail).
///
@@ -45,7 +37,6 @@ use crate::{
/// by it's content id.
#[derive(Debug)]
pub struct BodyPart {
-
/// A body created by a template.
pub resource: Resource,
@@ -68,8 +59,7 @@ pub struct BodyPart {
/// Attachments of a `BodyPart` instance will be combined with
/// the attachments of other instances and the ones in the
/// `MailParts` instance.
- pub attachments: Vec<Resource>
-
+ pub attachments: Vec<Resource>,
}
/// Parts which can be used to compose a multipart mail.
@@ -116,17 +106,14 @@ pub struct MailParts {
pub inline_embeddings: Vec<Resource>,
/// A number of embeddings which should be treated as attachments
- pub attachments: Vec<Resource>
+ pub attachments: Vec<Resource>,
}
//-------------------------------------------------------\\
// implementations for creating mails are from here on ||
//-------------------------------------------------------//
-
impl MailParts {
-
-
/// Create a `Mail` instance based on this `MailParts` instance.
///
///
@@ -151,57 +138,52 @@ impl MailParts {
/// Each sub-body created for a `BodyPart` will be wrapped
/// inside a `multipart/related` if it has body specific
/// embeddings (with content disposition inline).
- pub fn compose(self)
- -> Mail
- {
+ pub fn compose(self) -> Mail {
let MailParts {
alternative_bodies,
inline_embeddings,
- attachments
+ attachments,
} = self;
- let mut attachments = attachments.into_iter()
+ let mut attachments = attachments
+ .into_iter()
.map(|atta| atta.create_mail_with_disposition(DispositionKind::Attachment))
.collect::<Vec<_>>();
- let mut alternatives = alternative_bodies.into_iter()
+ let mut alternatives = alternative_bodies
+ .into_iter()
.map(|body| body.create_mail(&mut attachments))
.collect::<Vec<_>>();
//UNWRAP_SAFE: bodies is Vec1, i.e. we have at last one
let mail = alternatives.pop().unwrap();
- let mail =
- if alternatives.is_empty() {
- mail
- } else {
- mail.wrap_with_alternatives(alternatives)
- };
+ let mail = if alternatives.is_empty() {
+ mail
+ } else {
+ mail.wrap_with_alternatives(alternatives)
+ };
- let mail =
- if inline_embeddings.is_empty() {
- mail
- } else {
- let related = inline_embeddings.into_iter()
- .map(|embedding| {
- embedding.create_mail_with_disposition(DispositionKind::Inline)
- })
- .collect::<Vec<_>>();
- mail.wrap_with_related(related)
- };
+ let mail = if inline_embeddings.is_empty() {
+ mail
+ } else {
+ let related = inline_embeddings
+ .into_iter()
+ .map(|embedding| embedding.create_mail_with_disposition(DispositionKind::Inline))
+ .collect::<Vec<_>>();
+ mail.wrap_with_related(related)
+ };
- let mail =
- if attachments.is_empty() {
- mail
- } else {
- mail.wrap_with_mixed(attachments)
- };
+ let mail = if attachments.is_empty() {
+ mail
+ } else {
+ mail.wrap_with_mixed(attachments)
+ };
mail
}
}
impl BodyPart {
-
/// Creates a `Mail` instance from this `BodyPart` instance.
///
/// All embeddings in `BodyPart.embeddings` which have a
@@ -215,14 +197,11 @@ impl BodyPart {
/// have a `Inline` disposition that body will be
/// wrapped into a `multipart/related` body containing
/// them.
- pub fn create_mail(
- self,
- attachments_out: &mut Vec<Mail>,
- ) -> Mail {
+ pub fn create_mail(self, attachments_out: &mut Vec<Mail>) -> Mail {
let BodyPart {
resource,
inline_embeddings,
- attachments
+ attachments,
} = self;
let body = resource.create_mail();
@@ -235,10 +214,9 @@ impl BodyPart {
if inline_embeddings.is_empty() {
body
} else {
- let related = inline_embeddings.into_iter()
- .map(|embedding| {
- embedding.create_mail_with_disposition(DispositionKind::Inline)
- })
+ let related = inline_embeddings
+ .into_iter()
+ .map(|embedding| embedding.create_mail_with_disposition(DispositionKind::Inline))
.collect::<Vec<_>>();
body.wrap_with_related(related)
}
@@ -246,7 +224,6 @@ impl BodyPart {
}
impl Resource {
-
/// Create a `Mail` instance representing this `Resource`.
///
/// This is not a complete mail, i.e. it will not contain
@@ -268,15 +245,12 @@ impl Resource {
}
impl Mail {
-
/// Create a `multipart/mixed` `Mail` instance containing this mail as
/// first body and one additional body for each attachment.
///
/// Normally this is used with embeddings having a attachment
/// disposition creating a mail with attachments.
- pub fn wrap_with_mixed(self, other_bodies: Vec<Mail>)
- -> Mail
- {
+ pub fn wrap_with_mixed(self, other_bodies: Vec<Mail>) -> Mail {
let mut bodies = other_bodies;
bodies.push(self);
new_multipart(&MIXED, bodies)
@@ -291,9 +265,7 @@ impl Mail {
/// specified by `multipart/alternative`.
/// This also means that _this_ body will be the last body as it is
/// meant to be the _main_ body.
- pub fn wrap_with_alternatives(self, alternates: Vec<Mail>)
- -> Mail
- {
+ pub fn wrap_with_alternatives(self, alternates: Vec<Mail>) -> Mail {
let mut bodies = alternates;
//TODO[opt] accept iter and prepend instead of insert in vec
bodies.insert(0, self);
@@ -302,14 +274,11 @@ impl Mail {
/// Creates a `multipart/related` `Mail` instance containing this
/// mail first and then all related bodies.
- pub fn wrap_with_related(self, related: Vec<Mail>)
- -> Mail
- {
+ pub fn wrap_with_related(self, related: Vec<Mail>) -> Mail {
let mut bodies = related;
bodies.insert(0, self);
new_multipart(&RELATED, bodies)
}
-
}
/// Creates a `multipart/<sub_type>` mail with given bodies.
@@ -318,10 +287,7 @@ impl Mail {
///
/// If `sub_type` can not be used to create a multipart content
/// type this will panic.
-fn new_multipart(sub_type: &'static str, bodies: Vec<Mail>)
- -> Mail
-{
- let content_type = MediaType::new(MULTIPART, sub_type)
- .unwrap();
+fn new_multipart(sub_type: &'static str, bodies: Vec<Mail>) -> Mail {
+ let content_type = MediaType::new(MULTIPART, sub_type).unwrap();
Mail::new_multipart_mail(content_type, bodies)
-} \ No newline at end of file
+}
diff --git a/core/src/context.rs b/core/src/context.rs
index 88f1045..d776da5 100644
--- a/core/src/context.rs
+++ b/core/src/context.rs
@@ -1,44 +1,46 @@
//! Provides the context needed for building/encoding mails.
-use std::sync::Arc;
use std::fmt::Debug;
+use std::sync::Arc;
-use futures::{ future::{self, Either}, Future, IntoFuture };
+use futures::{
+ future::{self, Either},
+ Future, IntoFuture,
+};
use utils::SendBoxFuture;
-use headers::header_components::{
- MessageId, ContentId
-};
+use headers::header_components::{ContentId, MessageId};
use crate::{
- resource::{Source, Data, EncData, Resource},
- error::ResourceLoadingError
+ error::ResourceLoadingError,
+ resource::{Data, EncData, Resource, Source},
};
-
/// Represents Data which might already have been transfer encoded.
pub enum MaybeEncData {
/// The data is returned normally.
Data(Data),
/// The data is returned in a already transfer encoded variant.
- EncData(EncData)
+ EncData(EncData),
}
impl MaybeEncData {
-
pub fn to_resource(self) -> Resource {
match self {
MaybeEncData::Data(data) => Resource::Data(data),
- MaybeEncData::EncData(enc_data) => Resource::EncData(enc_data)
+ MaybeEncData::EncData(enc_data) => Resource::EncData(enc_data),
}
}
- pub fn encode(self, ctx: &impl Context)
- -> impl Future<Item=EncData,Error=ResourceLoadingError>
- {
+ pub fn encode(
+ self,
+ ctx: &impl Context,
+ ) -> impl Future<Item = EncData, Error = ResourceLoadingError> {
match self {
- MaybeEncData::Data(data) => Either::A(ctx.load_transfer_encoded_resource(&Resource::Data(data))),
- MaybeEncData::EncData(enc) => Either::B(future::ok(enc))
+ MaybeEncData::Data(data) => {
+ Either::A(ctx.load_transfer_encoded_resource(&Resource::Data(data)))
+ }
+ MaybeEncData::EncData(enc) => Either::B(future::ok(enc)),
}
}
}
@@ -76,8 +78,6 @@ impl MaybeEncData {
/// implementor to have a outer+inner type where the inner type is wrapped
/// into a `Arc` e.g. `struct SomeCtx { inner: Arc<InnerSomeCtx> }`.
pub trait Context: Debug + Clone + Send + Sync + 'static {
-
-
/// Loads and transfer encodes a `Data` instance.
///
/// This is called when a `Mail` instance is converted into
@@ -98,8 +98,7 @@ pub trait Context: Debug + Clone + Send + Sync + 'static {
/// This function should not block and schedule the encoding
/// in some other place e.g. by using the contexts offload
/// functionality.
- fn load_resource(&self, source: &Source)
- -> SendBoxFuture<MaybeEncData, ResourceLoadingError>;
+ fn load_resource(&self, source: &Source) -> SendBoxFuture<MaybeEncData, ResourceLoadingError>;
/// Loads and Transfer encodes a `Resource` instance.
///
@@ -124,9 +123,10 @@ pub trait Context: Debug + Clone + Send + Sync + 'static {
/// This function should not block and schedule the encoding
/// in some other place e.g. by using the contexts offload
/// functionality.
- fn load_transfer_encoded_resource(&self, resource: &Resource)
- -> SendBoxFuture<EncData, ResourceLoadingError>
- {
+ fn load_transfer_encoded_resource(
+ &self,
+ resource: &Resource,
+ ) -> SendBoxFuture<EncData, ResourceLoadingError> {
default_impl_for_load_transfer_encoded_resource(self, resource)
}
@@ -161,60 +161,56 @@ pub trait Context: Debug + Clone + Send + Sync + 'static {
//TODO[futures/v>=0.2]: integrate this with Context
/// offloads the execution of the future `fut` to somewhere else e.g. a cpu pool
fn offload<F>(&self, fut: F) -> SendBoxFuture<F::Item, F::Error>
- where F: Future + Send + 'static,
- F::Item: Send + 'static,
- F::Error: Send + 'static;
+ where
+ F: Future + Send + 'static,
+ F::Item: Send + 'static,
+ F::Error: Send + 'static;
//TODO[futures/v>=0.2]: integrate this with Context
/// offloads the execution of the function `func` to somewhere else e.g. a cpu pool
- fn offload_fn<FN, I>(&self, func: FN ) -> SendBoxFuture<I::Item, I::Error>
- where FN: FnOnce() -> I + Send + 'static,
- I: IntoFuture + 'static,
- I::Future: Send + 'static,
- I::Item: Send + 'static,
- I::Error: Send + 'static
+ fn offload_fn<FN, I>(&self, func: FN) -> SendBoxFuture<I::Item, I::Error>
+ where
+ FN: FnOnce() -> I + Send + 'static,
+ I: IntoFuture + 'static,
+ I::Future: Send + 'static,
+ I::Item: Send + 'static,
+ I::Error: Send + 'static,
{
- self.offload( future::lazy( func ) )
+ self.offload(future::lazy(func))