diff --git a/src/smtp/client.rs b/src/smtp/client.rs index 43f0dcd..f8bfff9 100644 --- a/src/smtp/client.rs +++ b/src/smtp/client.rs @@ -66,7 +66,7 @@ impl FromStr for SmtpResponse { match ( from_str::(s.slice_to(3)), vec!(" ", "-").contains(&s.slice(3,4)), - remove_trailing_crlf(StrBuf::from_str(s.slice_from(4))) + StrBuf::from_str(remove_trailing_crlf(s.slice_from(4).to_owned())) ) { (Some(code), true, message) => Some(SmtpResponse{ code: code, @@ -390,7 +390,7 @@ impl SmtpClient { Ok(response) => { self.server_info = Some( SmtpServerInfo{ - name: get_first_word(response.message.clone().unwrap()), + name: StrBuf::from_str(get_first_word(response.message.clone().unwrap().into_owned())), esmtp_features: None } ); @@ -409,7 +409,7 @@ impl SmtpClient { Ok(response) => { self.server_info = Some( SmtpServerInfo{ - name: get_first_word(response.message.clone().unwrap()), + name: StrBuf::from_str(get_first_word(response.message.clone().unwrap().to_owned())), esmtp_features: SmtpServerInfo::parse_esmtp_response(response.message.clone().unwrap()) } ); @@ -424,7 +424,7 @@ impl SmtpClient { pub fn mail(&mut self, from_address: StrBuf, options: Option>) -> Result, SmtpResponse> { check_state_in!(vec!(HeloSent)); - match self.send_command(commands::Mail(unquote_email_address(from_address), options)).with_code(vec!(250)) { + match self.send_command(commands::Mail(StrBuf::from_str(unquote_email_address(from_address.to_owned())), options)).with_code(vec!(250)) { Ok(response) => { self.state = MailSent; Ok(response) @@ -439,7 +439,7 @@ impl SmtpClient { pub fn rcpt(&mut self, to_address: StrBuf, options: Option>) -> Result, SmtpResponse> { check_state_in!(vec!(MailSent, RcptSent)); - match self.send_command(commands::Recipient(unquote_email_address(to_address), options)).with_code(vec!(250)) { + match self.send_command(commands::Recipient(StrBuf::from_str(unquote_email_address(to_address.to_owned())), options)).with_code(vec!(250)) { Ok(response) => { self.state = RcptSent; Ok(response) diff --git a/src/smtp/common.rs b/src/smtp/common.rs index 2582388..459f52a 100644 --- a/src/smtp/common.rs +++ b/src/smtp/common.rs @@ -11,70 +11,68 @@ //! //! Needs to be organized later -use std::strbuf::StrBuf; - pub static SP: &'static str = " "; pub static CRLF: &'static str = "\r\n"; /// Adds quotes to emails if needed -pub fn quote_email_address(address: StrBuf) -> StrBuf { +pub fn quote_email_address(address: ~str) -> ~str { match (address.as_slice().slice_to(1), address.as_slice().slice_from(address.as_slice().len()-1)) { - ("<", ">") => address.into_strbuf(), - _ => StrBuf::from_str(format!("<{:s}>", address)) + ("<", ">") => address, + _ => format!("<{:s}>", address) } } /// Removes quotes from emails if needed -pub fn unquote_email_address(address: StrBuf) -> StrBuf { +pub fn unquote_email_address(address: ~str) -> ~str { match (address.as_slice().slice_to(1), address.as_slice().slice_from(address.as_slice().len() - 1)) { - ("<", ">") => address.as_slice().slice(1, address.as_slice().len() - 1).into_strbuf(), - _ => address.into_strbuf() + ("<", ">") => address.as_slice().slice(1, address.as_slice().len() - 1).to_owned(), + _ => address } } /// Removes the trailing line return at the end of a string -pub fn remove_trailing_crlf(string: StrBuf) -> StrBuf { +pub fn remove_trailing_crlf(string: ~str) -> ~str { if string.as_slice().slice_from(string.as_slice().len() - 2) == CRLF { - StrBuf::from_str(string.as_slice().slice_to(string.as_slice().len() - 2)) + string.as_slice().slice_to(string.as_slice().len() - 2).to_owned() } else if string.as_slice().slice_from(string.as_slice().len() - 1) == "\r" { - StrBuf::from_str(string.as_slice().slice_to(string.as_slice().len() - 1)) + string.as_slice().slice_to(string.as_slice().len() - 1).to_owned() } else { - StrBuf::from_str(string.as_slice()) + string } } /// Returns the first word of a string, or the string if it contains no space -pub fn get_first_word(string: StrBuf) -> StrBuf { - StrBuf::from_str(string.into_owned().split_str(CRLF).next().unwrap().splitn(' ', 1).next().unwrap()) +pub fn get_first_word(string: ~str) -> ~str { + string.split_str(CRLF).next().unwrap().splitn(' ', 1).next().unwrap().to_owned() } #[cfg(test)] mod test { #[test] fn test_quote_email_address() { - assert_eq!(super::quote_email_address(StrBuf::from_str("address")), StrBuf::from_str("
")); - assert_eq!(super::quote_email_address(StrBuf::from_str("
")), StrBuf::from_str("
")); + assert_eq!(super::quote_email_address("address".to_owned()), "
".to_owned()); + assert_eq!(super::quote_email_address("
".to_owned()), "
".to_owned()); } #[test] fn test_unquote_email_address() { - assert_eq!(super::unquote_email_address(StrBuf::from_str("
")), StrBuf::from_str("address")); - assert_eq!(super::unquote_email_address(StrBuf::from_str("address")), StrBuf::from_str("address")); - assert_eq!(super::unquote_email_address(StrBuf::from_str("".to_owned()), "address".to_owned()); + assert_eq!(super::unquote_email_address("address".to_owned()), "address".to_owned()); + assert_eq!(super::unquote_email_address("