Merge pull request #69 from amousset/rustfmt-2

style(all): run rustfmt 0.5
This commit is contained in:
Alexis Mousset
2016-05-14 12:25:13 +02:00
8 changed files with 140 additions and 71 deletions

View File

@@ -350,14 +350,12 @@ impl EmailBuilder {
let text = PartBuilder::new()
.body(body_text)
.header(("Content-Type",
format!("{}", mime!(Text/Plain; Charset=Utf8)).as_ref()))
.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()))
.header(("Content-Type", format!("{}", mime!(Text/Html; Charset=Utf8)).as_ref()))
.build();
alternate.add_child(text);

View 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) {
()
}
}

View File

@@ -106,8 +106,7 @@ mod test {
assert_eq!(mechanism.response("alice",
"wonderland",
Some("PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg=\
="))
Some("PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg=="))
.unwrap(),
"YWxpY2UgNjRiMmE0M2MxZjZlZDY4MDZhOTgwOTE0ZTIzZTc1ZjA=");
assert!(mechanism.response("alice", "wonderland", Some("tést")).is_err());

View File

@@ -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,9 +189,8 @@ 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),
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(),

View File

@@ -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],