summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Korber <p.korber@1aim.com>2018-08-22 18:59:56 +0200
committerPhilipp Korber <p.korber@1aim.com>2018-08-22 19:39:57 +0200
commit09ec925b58913d41c725a53e611d57e4707d8983 (patch)
tree4ac83af41f37c07af3fe6ea4b13bcdbd67c68b32
parent4df2ded1766a51b2757b50901cc3e70fb142c8ca (diff)
feat(extended-api) hide some parts behind a feature gate
(to expose a more clean interface for the 99% of cases where the now hidden parts are not needed by the api user)
-rw-r--r--Cargo.toml3
-rw-r--r--src/lib.rs10
-rw-r--r--src/request.rs27
3 files changed, 36 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 8ac910a..305a8d0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,4 +20,5 @@ new-tokio-smtp = { git="https://github.com/1aim/new-tokio-smtp" }
[features]
-test-with-traceing = ["mail-common/traceing"] \ No newline at end of file
+test-with-traceing = ["mail-common/traceing"]
+extended-api = [] \ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index 2d49ebf..ef30887 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -70,8 +70,14 @@ pub mod error;
mod request;
mod send_mail;
-pub use self::request::*;
-pub use self::send_mail::*;
+pub use self::request::MailRequest;
+#[cfg(feature="extended-api")]
+pub use self::request::derive_envelop_data_from_mail;
+
+pub use self::send_mail::{send_mails, SendMailResult};
+#[cfg(feature="extended-api")]
+pub use self::send_mail::{encode_mails, send_encoded_mails};
+
pub use new_tokio_smtp::{ConnectionConfig, ConnectionBuilder};
pub use new_tokio_smtp::command::auth;
diff --git a/src/request.rs b/src/request.rs
index a7a1f5d..b5689d6 100644
--- a/src/request.rs
+++ b/src/request.rs
@@ -32,25 +32,50 @@ impl From<Mail> for MailRequest {
impl MailRequest {
+ /// creates a new `MailRequest` from a `Mail` instance
pub fn new(mail: Mail) -> Self {
MailRequest { mail, envelop_data: None }
}
+ /// create a new `MailRequest` and use custom smtp `EnvelopData`
+ ///
+ /// Note that envelop data comes from `new-tokio-smtp::send_mail` and
+ /// is not re-exported so if you happen to run into one of the view
+ /// cases where you need to set it manually just import it from
+ /// `new-tokio-smtp`.
pub fn new_with_envelop(mail: Mail, envelop: EnvelopData) -> Self {
MailRequest { mail, envelop_data: Some(envelop) }
}
+ /// replace the smtp `EnvelopData`
pub fn override_envelop(&mut self, envelop: EnvelopData) -> Option<EnvelopData> {
mem::replace(&mut self.envelop_data, Some(envelop))
}
- pub fn into_mail_with_envelop(self) -> Result<(Mail, EnvelopData), MailError> {
+ pub fn _into_mail_with_envelop(self) -> Result<(Mail, EnvelopData), MailError> {
let envelop =
if let Some(envelop) = self.envelop_data { envelop }
else { derive_envelop_data_from_mail(&self.mail)? };
Ok((self.mail, envelop))
}
+
+ #[cfg(not(feature="extended-api"))]
+ #[inline(always)]
+ pub(crate) fn into_mail_with_envelop(self) -> Result<(Mail, EnvelopData), MailError> {
+ self._into_mail_with_envelop()
+ }
+
+ /// Turns this type into the contained mail an associated envelop data.
+ ///
+ /// If envelop data was explicitly set it is returned.
+ /// If no envelop data was explicitly given it is derived from the
+ /// Mail header fields using `derive_envelop_data_from_mail`.
+ #[cfg(feature="extended-api")]
+ #[inline(always)]
+ pub fn into_mail_with_envelop(self) -> Result<(Mail, EnvelopData), MailError> {
+ self._into_mail_with_envelop()
+ }
}
fn mailaddress_from_mailbox(mailbox: &Mailbox) -> Result<MailAddress, EncodingError> {