Skip to content

Commit

Permalink
Merge 1404cc8 into edc22e8
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Apr 29, 2020
2 parents edc22e8 + 1404cc8 commit 3ca0cca
Show file tree
Hide file tree
Showing 23 changed files with 278 additions and 513 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ maintenance = { status = "actively-developed" }
[dependencies]
base64 = { version = "0.12", optional = true }
bufstream = { version = "0.1", optional = true }
# TODO to 0.5
bytes = { version = "0.4", optional = true }
hostname = { version = "0.3", optional = true }
hyperx = { version = "1", optional = true, features = ["headers"] }
idna = "0.2"
line-wrap = "0.1"
log = "0.4"
uuid = { version = "0.8", features = ["v4"] }
mime = { version = "0.3", optional = true }
Expand All @@ -50,7 +49,7 @@ harness = false
name = "transport_smtp"

[features]
builder = ["mime", "base64", "hyperx", "textnonce", "quoted_printable", "bytes"]
builder = ["mime", "base64", "hyperx", "textnonce", "quoted_printable"]
connection-pool = ["r2d2"]
default = ["file-transport", "smtp-transport", "hostname", "sendmail-transport", "native-tls", "builder"]
file-transport = ["serde", "serde_json"]
Expand Down
4 changes: 2 additions & 2 deletions benches/transport_smtp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn bench_simple_send(c: &mut Criterion) {
.subject("Happy new year")
.body("Be happy!")
.unwrap();
let result = black_box(sender.send(email));
let result = black_box(sender.send(&email));
assert!(result.is_ok());
})
});
Expand All @@ -37,7 +37,7 @@ fn bench_reuse_send(c: &mut Criterion) {
.subject("Happy new year")
.body("Be happy!")
.unwrap();
let result = black_box(sender.send(email));
let result = black_box(sender.send(&email));
assert!(result.is_ok());
})
});
Expand Down
2 changes: 1 addition & 1 deletion examples/smtp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
// Open a local connection on port 25
let mut mailer = SmtpClient::new_unencrypted_localhost().unwrap().transport();
// Send the email
let result = mailer.send(email);
let result = mailer.send(&email);

if result.is_ok() {
println!("Email sent");
Expand Down
2 changes: 1 addition & 1 deletion examples/smtp_gmail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
.transport();

// Send the email
let result = mailer.send(email);
let result = mailer.send(&email);

if result.is_ok() {
println!("Email sent");
Expand Down
1 change: 0 additions & 1 deletion src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static LITERAL_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)\[([A-f0-9:\.]+)\

impl Address {
/// Create email address from parts
#[inline]
pub fn new<U: Into<String>, D: Into<String>>(user: U, domain: D) -> Result<Self, AddressError> {
(user, domain).try_into()
}
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum Error {
CannotParseFilename,
/// IO error
Io(std::io::Error),
/// Non-ASCII chars
NonAsciiChars,
}

impl Display for Error {
Expand All @@ -35,6 +37,7 @@ impl Display for Error {
Error::EmailMissingLocalPart => "missing local part in email address".to_string(),
Error::EmailMissingDomain => "missing domain in email address".to_string(),
Error::CannotParseFilename => "could not parse attachment filename".to_string(),
Error::NonAsciiChars => "contains non-ASCII chars".to_string(),
Error::Io(e) => e.to_string(),
})
}
Expand Down
21 changes: 7 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
trivial_casts,
trivial_numeric_casts,
unstable_features,
unused_import_braces
unused_import_braces,
unsafe_code
)]

pub mod address;
Expand All @@ -23,7 +24,7 @@ use crate::error::Error;
#[cfg(feature = "builder")]
pub use crate::message::{
header::{self, Headers},
Mailboxes, Message,
EmailFormat, Mailboxes, Message,
};
#[cfg(feature = "file-transport")]
pub use crate::transport::file::FileTransport;
Expand All @@ -37,7 +38,6 @@ pub use crate::transport::smtp::r2d2::SmtpConnectionManager;
pub use crate::transport::smtp::{ClientSecurity, SmtpClient, SmtpTransport};
#[cfg(feature = "builder")]
use std::convert::TryFrom;
use std::fmt::Display;

/// Simple email envelope representation
///
Expand Down Expand Up @@ -109,27 +109,20 @@ impl TryFrom<&Headers> for Envelope {
}
}

// FIXME generate random log id

/// Transport method for emails
pub trait Transport<'a, B> {
pub trait Transport<'a> {
/// Result type for the transport
type Result;

/// Sends the email
/// FIXME not mut

// email = message (bytes) + envelope
fn send(&mut self, message: Message<B>) -> Self::Result
where
B: Display,
{
self.send_raw(message.envelope(), message.to_string().as_bytes())
fn send(&mut self, message: &Message) -> Self::Result {
let raw = message.formatted();
self.send_raw(message.envelope(), &raw)
}

fn send_raw(&mut self, envelope: &Envelope, email: &[u8]) -> Self::Result;

// TODO allow sending generic data
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 3ca0cca

Please sign in to comment.