Set command ending in the client
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user