Merge pull request #172 from amousset/fix-benches

feat(transport): Fix benches
This commit is contained in:
Alexis Mousset
2017-07-17 14:49:12 +02:00
committed by GitHub
2 changed files with 21 additions and 23 deletions

View File

@@ -3,7 +3,7 @@
extern crate lettre;
extern crate test;
use lettre::{EmailTransport, SimpleSendableEmail};
use lettre::{EmailAddress, EmailTransport, SimpleSendableEmail};
use lettre::smtp::SmtpTransportBuilder;
#[bench]
@@ -11,10 +11,10 @@ fn bench_simple_send(b: &mut test::Bencher) {
let mut sender = SmtpTransportBuilder::new("127.0.0.1:2525").unwrap().build();
b.iter(|| {
let email = SimpleSendableEmail::new(
"user@localhost",
vec!["root@localhost"],
"id",
"Hello world",
EmailAddress::new("user@localhost".to_string()),
vec![EmailAddress::new("root@localhost".to_string())],
"id".to_string(),
"Hello world".to_string(),
);
let result = sender.send(email);
assert!(result.is_ok());
@@ -29,10 +29,10 @@ fn bench_reuse_send(b: &mut test::Bencher) {
.build();
b.iter(|| {
let email = SimpleSendableEmail::new(
"user@localhost",
vec!["root@localhost"],
"file_id",
"Hello file",
EmailAddress::new("user@localhost".to_string()),
vec![EmailAddress::new("root@localhost".to_string())],
"id".to_string(),
"Hello world".to_string(),
);
let result = sender.send(email);
assert!(result.is_ok());

View File

@@ -46,20 +46,18 @@ impl EmailTransport<SendmailResult> for SendmailTransport {
fn send<T: SendableEmail>(&mut self, email: T) -> SendmailResult {
// Spawn the sendmail command
let to_addresses: Vec<String> = email.to().iter().map(|x| x.to_string()).collect();
let mut process =
Command::new(&self.command)
.args(
&[
"-i",
"-f",
&email.from().to_string(),
&to_addresses.join(" "),
],
)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
?;
let mut process = Command::new(&self.command)
.args(
&[
"-i",
"-f",
&email.from().to_string(),
&to_addresses.join(" "),
],
)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
match process.stdin.as_mut().unwrap().write_all(
email.message().as_bytes(),