feat(transport): Fix benches
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user