Fix enum scopes in tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
|
||||
name = "smtp"
|
||||
version = "0.0.1-pre"
|
||||
version = "0.0.1"
|
||||
authors = ["Alexis Mousset <contact@amousset.eu>"]
|
||||
|
||||
@@ -63,26 +63,26 @@ fn main() {
|
||||
optflag("h", "help", "print this help menu"),
|
||||
];
|
||||
|
||||
let matches = match getopts(args_string.tail(), opts) {
|
||||
let matches = match getopts(args_string.tail(), &opts) {
|
||||
Ok(m) => m,
|
||||
Err(f) => panic!("{}", f),
|
||||
};
|
||||
|
||||
if matches.opt_present("h") {
|
||||
print_usage(description, opts);
|
||||
print_usage(description, &opts);
|
||||
return;
|
||||
}
|
||||
|
||||
if !matches.opt_present("r") {
|
||||
println!("The sender option is required");
|
||||
print_usage(program, opts);
|
||||
print_usage(program, &opts);
|
||||
return;
|
||||
}
|
||||
|
||||
let recipients_str: &str = if !matches.free.is_empty() {
|
||||
matches.free[0].as_slice()
|
||||
} else {
|
||||
print_usage(description, opts);
|
||||
print_usage(description, &opts);
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@ use std::io::net::ip::ToSocketAddr;
|
||||
use tools::{get_first_word, unquote_email_address};
|
||||
use common::{CRLF, MESSAGE_ENDING};
|
||||
use response::Response;
|
||||
use extension;
|
||||
use extension::Extension;
|
||||
//use command;
|
||||
use command::Command;
|
||||
use transaction::TransactionState;
|
||||
use error::{SmtpResult, ErrorKind};
|
||||
|
||||
@@ -62,17 +62,17 @@ impl ServerInfo {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::ServerInfo;
|
||||
use extension;
|
||||
use extension::Extension;
|
||||
|
||||
#[test]
|
||||
fn test_fmt() {
|
||||
assert_eq!(format!("{}", ServerInfo{
|
||||
name: "name".to_string(),
|
||||
esmtp_features: Some(vec![extension::EightBitMime])
|
||||
esmtp_features: Some(vec![Extension::EightBitMime])
|
||||
}), "name with [8BITMIME]".to_string());
|
||||
assert_eq!(format!("{}", ServerInfo{
|
||||
name: "name".to_string(),
|
||||
esmtp_features: Some(vec![extension::EightBitMime, extension::Size(42)])
|
||||
esmtp_features: Some(vec![Extension::EightBitMime, Extension::Size(42)])
|
||||
}), "name with [8BITMIME, SIZE=42]".to_string());
|
||||
assert_eq!(format!("{}", ServerInfo{
|
||||
name: "name".to_string(),
|
||||
@@ -84,19 +84,19 @@ mod test {
|
||||
fn test_supports_feature() {
|
||||
assert_eq!(ServerInfo{
|
||||
name: "name".to_string(),
|
||||
esmtp_features: Some(vec![extension::EightBitMime])
|
||||
}.supports_feature(extension::EightBitMime), Some(extension::EightBitMime));
|
||||
esmtp_features: Some(vec![Extension::EightBitMime])
|
||||
}.supports_feature(Extension::EightBitMime), Some(Extension::EightBitMime));
|
||||
assert_eq!(ServerInfo{
|
||||
name: "name".to_string(),
|
||||
esmtp_features: Some(vec![extension::Size(42), extension::EightBitMime])
|
||||
}.supports_feature(extension::EightBitMime), Some(extension::EightBitMime));
|
||||
esmtp_features: Some(vec![Extension::Size(42), Extension::EightBitMime])
|
||||
}.supports_feature(Extension::EightBitMime), Some(Extension::EightBitMime));
|
||||
assert_eq!(ServerInfo{
|
||||
name: "name".to_string(),
|
||||
esmtp_features: Some(vec![extension::Size(42), extension::EightBitMime])
|
||||
}.supports_feature(extension::Size(0)), Some(extension::Size(42)));
|
||||
esmtp_features: Some(vec![Extension::Size(42), Extension::EightBitMime])
|
||||
}.supports_feature(Extension::Size(0)), Some(Extension::Size(42)));
|
||||
assert!(ServerInfo{
|
||||
name: "name".to_string(),
|
||||
esmtp_features: Some(vec![extension::EightBitMime])
|
||||
}.supports_feature(extension::Size(42)).is_none());
|
||||
esmtp_features: Some(vec![Extension::EightBitMime])
|
||||
}.supports_feature(Extension::Size(42)).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
104
src/command.rs
104
src/command.rs
@@ -17,8 +17,6 @@ use std::fmt::{Show, Formatter, Result};
|
||||
use response::Response;
|
||||
use error::SmtpResult;
|
||||
use common::SP;
|
||||
use self::Command::{Connect, StartTls, ExtendedHello, Hello, Mail, Recipient, Data, Message, Reset,
|
||||
Verify, Expand, Help, Quit};
|
||||
|
||||
/// Supported SMTP commands
|
||||
///
|
||||
@@ -59,25 +57,25 @@ pub enum Command {
|
||||
impl Show for Command {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.write( match *self {
|
||||
Connect => "CONNECT".to_string(),
|
||||
StartTls => "STARTTLS".to_string(),
|
||||
ExtendedHello(ref my_hostname) => format!("EHLO {}", my_hostname),
|
||||
Hello(ref my_hostname) => format!("HELO {}", my_hostname),
|
||||
Mail(ref from_address, None) => format!("MAIL FROM:<{}>", from_address),
|
||||
Mail(ref from_address, Some(ref options)) =>
|
||||
Command::Connect => "CONNECT".to_string(),
|
||||
Command::StartTls => "STARTTLS".to_string(),
|
||||
Command::ExtendedHello(ref my_hostname) => format!("EHLO {}", my_hostname),
|
||||
Command::Hello(ref my_hostname) => format!("HELO {}", my_hostname),
|
||||
Command::Mail(ref from_address, None) => format!("MAIL FROM:<{}>", from_address),
|
||||
Command::Mail(ref from_address, Some(ref options)) =>
|
||||
format!("MAIL FROM:<{}> {}", from_address, options.connect(SP)),
|
||||
Recipient(ref to_address, None) => format!("RCPT TO:<{}>", to_address),
|
||||
Recipient(ref to_address, Some(ref options)) =>
|
||||
Command::Recipient(ref to_address, None) => format!("RCPT TO:<{}>", to_address),
|
||||
Command::Recipient(ref to_address, Some(ref options)) =>
|
||||
format!("RCPT TO:<{}> {}", to_address, options.connect(SP)),
|
||||
Data => "DATA".to_string(),
|
||||
Message => "MESSAGE".to_string(),
|
||||
Reset => "RSET".to_string(),
|
||||
Verify(ref address) => format!("VRFY {}", address),
|
||||
Expand(ref address) => format!("EXPN {}", address),
|
||||
Help(None) => "HELP".to_string(),
|
||||
Help(Some(ref argument)) => format!("HELP {}", argument),
|
||||
Noop => "NOOP".to_string(),
|
||||
Quit => "QUIT".to_string(),
|
||||
Command::Data => "DATA".to_string(),
|
||||
Command::Message => "MESSAGE".to_string(),
|
||||
Command::Reset => "RSET".to_string(),
|
||||
Command::Verify(ref address) => format!("VRFY {}", address),
|
||||
Command::Expand(ref address) => format!("EXPN {}", address),
|
||||
Command::Help(None) => "HELP".to_string(),
|
||||
Command::Help(Some(ref argument)) => format!("HELP {}", argument),
|
||||
Command::Noop => "NOOP".to_string(),
|
||||
Command::Quit => "QUIT".to_string(),
|
||||
}.as_bytes())
|
||||
}
|
||||
}
|
||||
@@ -86,17 +84,17 @@ impl Command {
|
||||
/// Tests if the `Command` is ASCII-only
|
||||
pub fn is_ascii(&self) -> bool {
|
||||
match *self {
|
||||
ExtendedHello(ref my_hostname) => my_hostname.is_ascii(),
|
||||
Hello(ref my_hostname) => my_hostname.is_ascii(),
|
||||
Mail(ref from_address, None) => from_address.is_ascii(),
|
||||
Mail(ref from_address, Some(ref options)) => from_address.is_ascii()
|
||||
Command::ExtendedHello(ref my_hostname) => my_hostname.is_ascii(),
|
||||
Command::Hello(ref my_hostname) => my_hostname.is_ascii(),
|
||||
Command::Mail(ref from_address, None) => from_address.is_ascii(),
|
||||
Command::Mail(ref from_address, Some(ref options)) => from_address.is_ascii()
|
||||
&& options.concat().is_ascii(),
|
||||
Recipient(ref to_address, None) => to_address.is_ascii(),
|
||||
Recipient(ref to_address, Some(ref options)) => to_address.is_ascii()
|
||||
Command::Recipient(ref to_address, None) => to_address.is_ascii(),
|
||||
Command::Recipient(ref to_address, Some(ref options)) => to_address.is_ascii()
|
||||
&& options.concat().is_ascii(),
|
||||
Verify(ref address) => address.is_ascii(),
|
||||
Expand(ref address) => address.is_ascii(),
|
||||
Help(Some(ref argument)) => argument.is_ascii(),
|
||||
Command::Verify(ref address) => address.is_ascii(),
|
||||
Command::Expand(ref address) => address.is_ascii(),
|
||||
Command::Help(Some(ref argument)) => argument.is_ascii(),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
@@ -107,20 +105,20 @@ impl Command {
|
||||
/// `Err` otherwise
|
||||
pub fn test_success(&self, response: Response) -> SmtpResult {
|
||||
let success = match *self {
|
||||
Connect => vec![220],
|
||||
StartTls => vec![220],
|
||||
ExtendedHello(..) => vec![250],
|
||||
Hello(..) => vec![250],
|
||||
Mail(..) => vec![250],
|
||||
Recipient(..) => vec![250, 251],
|
||||
Data => vec![354],
|
||||
Message => vec![250],
|
||||
Reset => vec![250],
|
||||
Verify(..) => vec![250, 251, 252],
|
||||
Expand(..) => vec![250, 252],
|
||||
Help(..) => vec![211, 214],
|
||||
Noop => vec![250],
|
||||
Quit => vec![221],
|
||||
Command::Connect => vec![220],
|
||||
Command::StartTls => vec![220],
|
||||
Command::ExtendedHello(..) => vec![250],
|
||||
Command::Hello(..) => vec![250],
|
||||
Command::Mail(..) => vec![250],
|
||||
Command::Recipient(..) => vec![250, 251],
|
||||
Command::Data => vec![354],
|
||||
Command::Message => vec![250],
|
||||
Command::Reset => vec![250],
|
||||
Command::Verify(..) => vec![250, 251, 252],
|
||||
Command::Expand(..) => vec![250, 252],
|
||||
Command::Help(..) => vec![211, 214],
|
||||
Command::Noop => vec![250],
|
||||
Command::Quit => vec![221],
|
||||
}.contains(&response.code);
|
||||
if success {
|
||||
Ok(response)
|
||||
@@ -132,22 +130,24 @@ impl Command {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::Command;
|
||||
|
||||
#[test]
|
||||
fn test_fmt() {
|
||||
assert_eq!(
|
||||
format!("{}", super::Noop),
|
||||
format!("{}", Command::Noop),
|
||||
"NOOP".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", super::ExtendedHello("my_name".to_string())),
|
||||
format!("{}", Command::ExtendedHello("my_name".to_string())),
|
||||
"EHLO my_name".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", super::Mail("test".to_string(), Some(vec!["option".to_string()]))),
|
||||
format!("{}", Command::Mail("test".to_string(), Some(vec!["option".to_string()]))),
|
||||
"MAIL FROM:<test> option".to_string()
|
||||
);
|
||||
assert_eq!(
|
||||
format!("{}", super::Mail("test".to_string(),
|
||||
format!("{}", Command::Mail("test".to_string(),
|
||||
Some(vec!["option".to_string(), "option2".to_string()]))),
|
||||
"MAIL FROM:<test> option option2".to_string()
|
||||
);
|
||||
@@ -155,17 +155,17 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_is_ascii() {
|
||||
assert!(super::Help(None).is_ascii());
|
||||
assert!(super::ExtendedHello("my_name".to_string()).is_ascii());
|
||||
assert!(!super::ExtendedHello("my_namé".to_string()).is_ascii());
|
||||
assert!(Command::Help(None).is_ascii());
|
||||
assert!(Command::ExtendedHello("my_name".to_string()).is_ascii());
|
||||
assert!(!Command::ExtendedHello("my_namé".to_string()).is_ascii());
|
||||
assert!(
|
||||
super::Mail("test".to_string(), Some(vec!["test".to_string(), "test".to_string()]))
|
||||
Command::Mail("test".to_string(), Some(vec!["test".to_string(), "test".to_string()]))
|
||||
.is_ascii());
|
||||
assert!(
|
||||
!super::Mail("test".to_string(), Some(vec!["est".to_string(), "testà".to_string()]))
|
||||
!Command::Mail("test".to_string(), Some(vec!["est".to_string(), "testà".to_string()]))
|
||||
.is_ascii());
|
||||
assert!(
|
||||
!super::Mail("testé".to_string(), Some(vec!["est".to_string(), "test".to_string()]))
|
||||
!Command::Mail("testé".to_string(), Some(vec!["est".to_string(), "test".to_string()]))
|
||||
.is_ascii());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,14 +116,14 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_fmt() {
|
||||
assert_eq!(format!("{}", super::EightBitMime), "8BITMIME".to_string());
|
||||
assert_eq!(format!("{}", super::Size(42)), "SIZE=42".to_string());
|
||||
assert_eq!(format!("{}", Extension::EightBitMime), "8BITMIME".to_string());
|
||||
assert_eq!(format!("{}", Extension::Size(42)), "SIZE=42".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
assert_eq!(from_str::<Extension>("8BITMIME"), Some(super::EightBitMime));
|
||||
assert_eq!(from_str::<Extension>("SIZE 42"), Some(super::Size(42)));
|
||||
assert_eq!(from_str::<Extension>("8BITMIME"), Some(Extension::EightBitMime));
|
||||
assert_eq!(from_str::<Extension>("SIZE 42"), Some(Extension::Size(42)));
|
||||
assert_eq!(from_str::<Extension>("SIZ 42"), None);
|
||||
assert_eq!(from_str::<Extension>("SIZE 4a2"), None);
|
||||
// TODO: accept trailing spaces ?
|
||||
@@ -132,22 +132,22 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_same_extension_as() {
|
||||
assert_eq!(super::EightBitMime.same_extension_as(super::EightBitMime), true);
|
||||
assert_eq!(super::Size(42).same_extension_as(super::Size(42)), true);
|
||||
assert_eq!(super::Size(42).same_extension_as(super::Size(43)), true);
|
||||
assert_eq!(super::Size(42).same_extension_as(super::EightBitMime), false);
|
||||
assert_eq!(Extension::EightBitMime.same_extension_as(Extension::EightBitMime), true);
|
||||
assert_eq!(Extension::Size(42).same_extension_as(Extension::Size(42)), true);
|
||||
assert_eq!(Extension::Size(42).same_extension_as(Extension::Size(43)), true);
|
||||
assert_eq!(Extension::Size(42).same_extension_as(Extension::EightBitMime), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_esmtp_response() {
|
||||
assert_eq!(Extension::parse_esmtp_response("me\r\n250-8BITMIME\r\n250 SIZE 42"),
|
||||
Some(vec![super::EightBitMime, super::Size(42)]));
|
||||
Some(vec![Extension::EightBitMime, Extension::Size(42)]));
|
||||
assert_eq!(Extension::parse_esmtp_response("me\r\n250-8BITMIME\r\n250 UNKNON 42"),
|
||||
Some(vec![super::EightBitMime]));
|
||||
Some(vec![Extension::EightBitMime]));
|
||||
assert_eq!(Extension::parse_esmtp_response("me\r\n250-9BITMIME\r\n250 SIZE a"),
|
||||
Some(vec![]));
|
||||
assert_eq!(Extension::parse_esmtp_response("me\r\n250-SIZE 42\r\n250 SIZE 43"),
|
||||
Some(vec![super::Size(42), super::Size(43)]));
|
||||
Some(vec![Extension::Size(42), Extension::Size(43)]));
|
||||
assert_eq!(Extension::parse_esmtp_response(""),
|
||||
Some(vec![]));
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
//! );
|
||||
//! let result = email_client.send_mail::<TcpStream>(
|
||||
//! "user@example.com", // sender (reverse-path)
|
||||
//! ["user@example.org"], // recipient list
|
||||
//! &["user@example.org"], // recipient list
|
||||
//! "Test email", // email content
|
||||
//! );
|
||||
//! ```
|
||||
|
||||
@@ -114,27 +114,27 @@ impl TransactionState {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use command;
|
||||
use command::Command;
|
||||
use super::TransactionState;
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
||||
assert_eq!(TransactionState::new(), super::Unconnected);
|
||||
assert_eq!(TransactionState::new(), TransactionState::Unconnected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_command_allowed() {
|
||||
assert!(!super::Unconnected.is_command_allowed(&Command::Noop));
|
||||
assert!(!super::DataSent.is_command_allowed(&Command::Noop));
|
||||
assert!(super::HelloSent.is_command_allowed(&Command::Mail("".to_string(), None)));
|
||||
assert!(!super::MailSent.is_command_allowed(&Command::Mail("".to_string(), None)));
|
||||
assert!(!TransactionState::Unconnected.is_command_allowed(&Command::Noop));
|
||||
assert!(!TransactionState::DataSent.is_command_allowed(&Command::Noop));
|
||||
assert!(TransactionState::HelloSent.is_command_allowed(&Command::Mail("".to_string(), None)));
|
||||
assert!(!TransactionState::MailSent.is_command_allowed(&Command::Mail("".to_string(), None)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_next_state() {
|
||||
assert_eq!(super::MailSent.next_state(&Command::Noop), Some(super::MailSent));
|
||||
assert_eq!(super::HelloSent.next_state(&Command::Mail("".to_string(), None)),
|
||||
Some(super::MailSent));
|
||||
assert_eq!(super::MailSent.next_state(&Command::Mail("".to_string(), None)), None);
|
||||
assert_eq!(TransactionState::MailSent.next_state(&Command::Noop), Some(TransactionState::MailSent));
|
||||
assert_eq!(TransactionState::HelloSent.next_state(&Command::Mail("".to_string(), None)),
|
||||
Some(TransactionState::MailSent));
|
||||
assert_eq!(TransactionState::MailSent.next_state(&Command::Mail("".to_string(), None)), None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user