Set command ending in the client

This commit is contained in:
Alexis Mousset
2014-11-04 18:51:08 +01:00
parent 22b2dad57f
commit ba6c879be1
4 changed files with 14 additions and 14 deletions

View File

@@ -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<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(), 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

View File

@@ -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<Response>;
/// 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")

View File

@@ -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;

View File

@@ -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<TransactionState> {
match (*self, command) {
(Unconnected, command::Connect) => Some(Connected),