Add transparency for <CRLF>.<CRLF>

This commit is contained in:
Alexis Mousset
2014-11-04 17:50:44 +01:00
parent fefc3e209f
commit 22b2dad57f
4 changed files with 49 additions and 24 deletions

View File

@@ -19,7 +19,7 @@ use response::Response;
use extension;
use command;
use command::Command;
use common::{SMTP_PORT, CRLF};
use common::SMTP_PORT;
use transaction;
use transaction::TransactionState;
use client::connecter::Connecter;
@@ -175,12 +175,12 @@ impl<S: Connecter + ClientStream + Clone> Client<S> {
if !self.state.is_command_possible(command.clone()) {
panic!("Bad command sequence");
}
self.stream.clone().unwrap().send_and_get_response(format!("{}", command).as_slice())
self.stream.clone().unwrap().send_and_get_response(format!("{}", command).as_slice(), false)
}
/// Sends the email content
fn send_message(&mut self, message: String) -> Response {
self.stream.clone().unwrap().send_and_get_response(format!("{}{}.{}", message, CRLF, CRLF).as_slice())
self.stream.clone().unwrap().send_and_get_response(format!("{}", message).as_slice(), true)
}
/// Connects to the configured server

View File

@@ -6,14 +6,14 @@ use std::str::from_utf8;
use std::vec::Vec;
use response::Response;
use common::escape_crlf;
use common::{escape_crlf, escape_dot, CRLF};
static BUFFER_SIZE: uint = 1024;
/// TODO
pub trait ClientStream {
/// TODO
fn send_and_get_response(&mut self, string: &str) -> Response;
fn send_and_get_response(&mut self, string: &str, is_message: bool) -> Response;
/// TODO
fn get_reply(&mut self) -> Option<Response>;
/// TODO
@@ -22,9 +22,13 @@ 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) -> Response {
match self.write_str(format!("{}", string).as_slice()) {
Ok(..) => debug!("Wrote: {}", escape_crlf(string.to_string())),
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)
};
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")
}