diff --git a/src/client/mod.rs b/src/client/mod.rs index 3675b2a..a7b5a27 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -19,7 +19,7 @@ use response::Response; use extension; use command; use command::Command; -use common::SMTP_PORT; +use common::{CRLF, SMTP_PORT}; use transaction; use transaction::TransactionState; use client::connecter::Connecter; @@ -175,12 +175,14 @@ impl Client { if !self.state.is_command_possible(command.clone()) { panic!("Bad command sequence"); } - self.stream.clone().unwrap().send_and_get_response(format!("{}", command).as_slice(), false) + self.stream.clone().unwrap().send_and_get_response(format!("{}", command).as_slice(), + format!("{}", CRLF).as_slice()) } /// Sends the email content fn send_message(&mut self, message: String) -> Response { - self.stream.clone().unwrap().send_and_get_response(format!("{}", message).as_slice(), true) + self.stream.clone().unwrap().send_and_get_response(format!("{}", message).as_slice(), + format!("{}.{}", CRLF, CRLF).as_slice()) } /// Connects to the configured server diff --git a/src/client/stream.rs b/src/client/stream.rs index ce1ff93..d171ad6 100644 --- a/src/client/stream.rs +++ b/src/client/stream.rs @@ -6,14 +6,14 @@ use std::str::from_utf8; use std::vec::Vec; use response::Response; -use common::{escape_crlf, escape_dot, CRLF}; +use common::{escape_crlf, escape_dot}; static BUFFER_SIZE: uint = 1024; /// TODO pub trait ClientStream { /// TODO - fn send_and_get_response(&mut self, string: &str, is_message: bool) -> Response; + fn send_and_get_response(&mut self, string: &str, end: &str) -> Response; /// TODO fn get_reply(&mut self) -> Option; /// TODO @@ -22,11 +22,7 @@ pub trait ClientStream { impl ClientStream for TcpStream { /// Sends a complete message or a command to the server and get the response - fn send_and_get_response(&mut self, string: &str, is_message: bool) -> Response { - let end = match is_message { - true => format!("{}.{}", CRLF, CRLF), - false => format!("{}", CRLF) - }; + fn send_and_get_response(&mut self, string: &str, end: &str) -> Response { match self.write_str(format!("{}{}", escape_dot(string.to_string()), end).as_slice()) { Ok(..) => debug!("Wrote: {}", escape_crlf(escape_dot(string.to_string()))), Err(..) => panic!("Could not write to stream") diff --git a/src/command.rs b/src/command.rs index a45dd69..da8a316 100644 --- a/src/command.rs +++ b/src/command.rs @@ -7,10 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![unstable] - //! Represents a valid complete SMTP command, ready to be sent to a server +#![unstable] + use std::fmt::{Show, Formatter, Result}; use common::SP; diff --git a/src/transaction.rs b/src/transaction.rs index 5d57145..df8e1f5 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -9,6 +9,8 @@ //! SMTP commands and ESMTP features library +#![unstable] + use std::fmt; use std::fmt::{Show, Formatter}; use command; @@ -47,7 +49,7 @@ impl Show for TransactionState { } impl TransactionState { - /// bla bla + /// TODO pub fn is_command_possible(&self, command: Command) -> bool { match (*self, command) { (Unconnected, command::Connect) => true, @@ -73,7 +75,7 @@ impl TransactionState { } } - /// a method + /// TODO pub fn next_state(&mut self, command: Command) -> Option { match (*self, command) { (Unconnected, command::Connect) => Some(Connected),