Merge pull request #69 from amousset/rustfmt-2
style(all): run rustfmt 0.5
This commit is contained in:
@@ -349,16 +349,14 @@ impl EmailBuilder {
|
||||
alternate.set_message_type(MimeMultipartType::Alternative);
|
||||
|
||||
let text = PartBuilder::new()
|
||||
.body(body_text)
|
||||
.header(("Content-Type",
|
||||
format!("{}", mime!(Text/Plain; Charset=Utf8)).as_ref()))
|
||||
.build();
|
||||
.body(body_text)
|
||||
.header(("Content-Type", format!("{}", mime!(Text/Plain; Charset=Utf8)).as_ref()))
|
||||
.build();
|
||||
|
||||
let html = PartBuilder::new()
|
||||
.body(body_html)
|
||||
.header(("Content-Type",
|
||||
format!("{}", mime!(Text/Html; Charset=Utf8)).as_ref()))
|
||||
.build();
|
||||
.body(body_html)
|
||||
.header(("Content-Type", format!("{}", mime!(Text/Html; Charset=Utf8)).as_ref()))
|
||||
.build();
|
||||
|
||||
alternate.add_child(text);
|
||||
alternate.add_child(html);
|
||||
@@ -495,12 +493,12 @@ mod test {
|
||||
email.message.headers.insert(Header::new_with_value("Message-ID".to_string(),
|
||||
format!("<{}@rust-smtp>",
|
||||
current_message))
|
||||
.unwrap());
|
||||
.unwrap());
|
||||
|
||||
email.message
|
||||
.headers
|
||||
.insert(Header::new_with_value("To".to_string(), "to@example.com".to_string())
|
||||
.unwrap());
|
||||
.headers
|
||||
.insert(Header::new_with_value("To".to_string(), "to@example.com".to_string())
|
||||
.unwrap());
|
||||
|
||||
email.message.body = "body".to_string();
|
||||
|
||||
@@ -516,16 +514,16 @@ mod test {
|
||||
let date_now = now();
|
||||
|
||||
let email = email_builder.to("user@localhost")
|
||||
.from("user@localhost")
|
||||
.cc(("cc@localhost", "Alias"))
|
||||
.reply_to("reply@localhost")
|
||||
.sender("sender@localhost")
|
||||
.body("Hello World!")
|
||||
.date(&date_now)
|
||||
.subject("Hello")
|
||||
.header(("X-test", "value"))
|
||||
.build()
|
||||
.unwrap();
|
||||
.from("user@localhost")
|
||||
.cc(("cc@localhost", "Alias"))
|
||||
.reply_to("reply@localhost")
|
||||
.sender("sender@localhost")
|
||||
.body("Hello World!")
|
||||
.date(&date_now)
|
||||
.subject("Hello")
|
||||
.header(("X-test", "value"))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(format!("{}", email),
|
||||
format!("To: <user@localhost>\r\nFrom: <user@localhost>\r\nCc: \"Alias\" \
|
||||
@@ -543,16 +541,16 @@ mod test {
|
||||
let date_now = now();
|
||||
|
||||
let email = email_builder.to("user@localhost")
|
||||
.from("user@localhost")
|
||||
.cc(("cc@localhost", "Alias"))
|
||||
.reply_to("reply@localhost")
|
||||
.sender("sender@localhost")
|
||||
.body("Hello World!")
|
||||
.date(&date_now)
|
||||
.subject("Hello")
|
||||
.header(("X-test", "value"))
|
||||
.build()
|
||||
.unwrap();
|
||||
.from("user@localhost")
|
||||
.cc(("cc@localhost", "Alias"))
|
||||
.reply_to("reply@localhost")
|
||||
.sender("sender@localhost")
|
||||
.body("Hello World!")
|
||||
.date(&date_now)
|
||||
.subject("Hello")
|
||||
.header(("X-test", "value"))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(email.from_address(), "sender@localhost".to_string());
|
||||
assert_eq!(email.to_addresses(),
|
||||
|
||||
75
src/transport/sendmail/mod.rs
Normal file
75
src/transport/sendmail/mod.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
//! This transport creates a file for each email, containing the enveloppe information and the email
|
||||
//! itself.
|
||||
|
||||
use transport::EmailTransport;
|
||||
use transport::error::EmailResult;
|
||||
use transport::smtp::response::Response;
|
||||
use transport::smtp::response::{Category, Code, Severity};
|
||||
use email::SendableEmail;
|
||||
|
||||
/// Writes the content and the enveloppe information to a file
|
||||
pub struct SendmailEmailTransport {
|
||||
command: String,
|
||||
}
|
||||
|
||||
impl SendmailEmailTransport {
|
||||
/// Creates a new transport to the default "sendmail" command
|
||||
pub fn new() -> SendmailEmailTransport {
|
||||
SendmailEmailTransport { command: "sendmail".to_string() }
|
||||
}
|
||||
|
||||
/// Creates a new transport with a custom sendmail command
|
||||
pub fn new_with_command(command: &str) -> SendmailEmailTransport {
|
||||
SendmailEmailTransport { command: command.to_string() }
|
||||
}
|
||||
}
|
||||
|
||||
impl EmailTransport for SendmailEmailTransport {
|
||||
fn send<T: SendableEmail>(&mut self, email: T) -> EmailResult {
|
||||
|
||||
|
||||
// Build TO list
|
||||
// Set FROM
|
||||
// Send content
|
||||
|
||||
let sendmail_sh_frist_half = "sendmail ".to_string() + &to_address;
|
||||
let sendmail_sh_second_half = " < email.txt".to_string();
|
||||
let sendmail_sh = sendmail_sh_frist_half + &sendmail_sh_second_half;
|
||||
|
||||
let output = Command::new(self.command)
|
||||
.arg("-c")
|
||||
.arg(sendmail_sh)
|
||||
.output()
|
||||
.unwrap_or_else(|e| panic!("failed to execute process: {}", e));
|
||||
|
||||
println!("status: {}", output.status);
|
||||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
||||
|
||||
|
||||
|
||||
|
||||
let mut file = self.path.clone();
|
||||
file.push(format!("{}.txt", email.message_id()));
|
||||
|
||||
let mut f = try!(File::create(file.as_path()));
|
||||
|
||||
let log_line = format!("{}: from=<{}> to=<{}>\n",
|
||||
email.message_id(),
|
||||
email.from_address(),
|
||||
email.to_addresses().join("> to=<"));
|
||||
|
||||
try!(f.write_all(log_line.as_bytes()));
|
||||
try!(f.write_all(format!("{}", email.message()).as_bytes()));
|
||||
|
||||
info!("{} status=<written>", log_line);
|
||||
|
||||
Ok(Response::new(Code::new(Severity::PositiveCompletion, Category::MailSystem, 0),
|
||||
vec![format!("Ok: email written to {}",
|
||||
file.to_str().unwrap_or("non-UTF-8 path"))]))
|
||||
}
|
||||
|
||||
fn close(&mut self) {
|
||||
()
|
||||
}
|
||||
}
|
||||
@@ -58,8 +58,8 @@ impl Mechanism {
|
||||
}
|
||||
None => {
|
||||
Ok(format!("{}{}{}{}", NUL, username, NUL, password)
|
||||
.as_bytes()
|
||||
.to_base64(base64::STANDARD))
|
||||
.as_bytes()
|
||||
.to_base64(base64::STANDARD))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,8 +80,8 @@ impl Mechanism {
|
||||
hmac.input(&decoded_challenge);
|
||||
|
||||
Ok(format!("{} {}", username, hmac.result().code().to_hex())
|
||||
.as_bytes()
|
||||
.to_base64(base64::STANDARD))
|
||||
.as_bytes()
|
||||
.to_base64(base64::STANDARD))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,10 +105,9 @@ mod test {
|
||||
let mechanism = Mechanism::CramMd5;
|
||||
|
||||
assert_eq!(mechanism.response("alice",
|
||||
"wonderland",
|
||||
Some("PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg=\
|
||||
="))
|
||||
.unwrap(),
|
||||
"wonderland",
|
||||
Some("PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg=="))
|
||||
.unwrap(),
|
||||
"YWxpY2UgNjRiMmE0M2MxZjZlZDY4MDZhOTgwOTE0ZTIzZTc1ZjA=");
|
||||
assert!(mechanism.response("alice", "wonderland", Some("tést")).is_err());
|
||||
assert!(mechanism.response("alice", "wonderland", None).is_err());
|
||||
|
||||
@@ -23,12 +23,12 @@ pub mod net;
|
||||
#[inline]
|
||||
fn escape_dot(string: &str) -> String {
|
||||
if string.starts_with(".") {
|
||||
format!(".{}", string)
|
||||
} else {
|
||||
string.to_string()
|
||||
}
|
||||
.replace("\r.", "\r..")
|
||||
.replace("\n.", "\n..")
|
||||
format!(".{}", string)
|
||||
} else {
|
||||
string.to_string()
|
||||
}
|
||||
.replace("\r.", "\r..")
|
||||
.replace("\n.", "\n..")
|
||||
}
|
||||
|
||||
/// Returns the string replacing all the CRLF with "\<CRLF\>"
|
||||
|
||||
@@ -45,7 +45,7 @@ impl Connector for NetworkStream {
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn is_encrypted(&self) -> bool {
|
||||
match *self {
|
||||
NetworkStream::Plain(_) => false,
|
||||
|
||||
@@ -171,12 +171,9 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_serverinfo() {
|
||||
let response = Response::new(Code::new(Severity::PositiveCompletion,
|
||||
Category::Unspecified4,
|
||||
1),
|
||||
vec!["me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string()]);
|
||||
let response =
|
||||
Response::new(Code::new(Severity::PositiveCompletion, Category::Unspecified4, 1),
|
||||
vec!["me".to_string(), "8BITMIME".to_string(), "SIZE 42".to_string()]);
|
||||
|
||||
let mut features = HashSet::new();
|
||||
assert!(features.insert(Extension::EightBitMime));
|
||||
@@ -192,13 +189,12 @@ mod test {
|
||||
assert!(!server_info.supports_feature(&Extension::StartTls));
|
||||
assert!(!server_info.supports_auth_mechanism(Mechanism::CramMd5));
|
||||
|
||||
let response2 = Response::new(Code::new(Severity::PositiveCompletion,
|
||||
Category::Unspecified4,
|
||||
1),
|
||||
vec!["me".to_string(),
|
||||
"AUTH PLAIN CRAM-MD5 OTHER".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string()]);
|
||||
let response2 =
|
||||
Response::new(Code::new(Severity::PositiveCompletion, Category::Unspecified4, 1),
|
||||
vec!["me".to_string(),
|
||||
"AUTH PLAIN CRAM-MD5 OTHER".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string()]);
|
||||
|
||||
let mut features2 = HashSet::new();
|
||||
assert!(features2.insert(Extension::EightBitMime));
|
||||
|
||||
@@ -330,7 +330,8 @@ impl EmailTransport for SmtpTransport {
|
||||
Some(mechanism) => vec![mechanism],
|
||||
None => {
|
||||
match self.client.is_encrypted() {
|
||||
// If encrypted, allow all mechanisms, with a preference for the simplest
|
||||
// If encrypted, allow all mechanisms, with a preference for the
|
||||
// simplest
|
||||
true => vec![Mechanism::Plain, Mechanism::CramMd5],
|
||||
// If not encrypted, do not all clear-text passwords
|
||||
false => vec![Mechanism::CramMd5],
|
||||
@@ -354,13 +355,13 @@ impl EmailTransport for SmtpTransport {
|
||||
|
||||
// Mail
|
||||
let mail_options = match (self.server_info
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.supports_feature(&Extension::EightBitMime),
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.supports_feature(&Extension::EightBitMime),
|
||||
self.server_info
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.supports_feature(&Extension::SmtpUtfEight)) {
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.supports_feature(&Extension::SmtpUtfEight)) {
|
||||
(true, true) => Some("BODY=8BITMIME SMTPUTF8"),
|
||||
(true, false) => Some("BODY=8BITMIME"),
|
||||
(false, _) => None,
|
||||
|
||||
@@ -410,7 +410,7 @@ mod test {
|
||||
vec!["me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string()])
|
||||
.is_positive());
|
||||
.is_positive());
|
||||
assert!(!Response::new(Code {
|
||||
severity: "5".parse::<Severity>().unwrap(),
|
||||
category: "4".parse::<Category>().unwrap(),
|
||||
@@ -419,7 +419,7 @@ mod test {
|
||||
vec!["me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string()])
|
||||
.is_positive());
|
||||
.is_positive());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -521,7 +521,7 @@ mod test {
|
||||
vec!["me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string()])
|
||||
.has_code(241));
|
||||
.has_code(241));
|
||||
assert!(!Response::new(Code {
|
||||
severity: "2".parse::<Severity>().unwrap(),
|
||||
category: "4".parse::<Category>().unwrap(),
|
||||
@@ -530,7 +530,7 @@ mod test {
|
||||
vec!["me".to_string(),
|
||||
"8BITMIME".to_string(),
|
||||
"SIZE 42".to_string()])
|
||||
.has_code(251));
|
||||
.has_code(251));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user