diff --git a/src/client.rs b/src/client.rs index eeb36b0..728f773 100644 --- a/src/client.rs +++ b/src/client.rs @@ -382,6 +382,18 @@ impl Client { IdleHandle::new(self) } + /// The APPEND command adds a mail to a mailbox. + pub fn append(&mut self, folder: &str, content: &[u8]) -> Result> { + try!(self.run_command(&format!("APPEND \"{}\" {{{}}}", folder, content.len()))); + let line = try!(self.readline()); + if !line.starts_with(b"+") { + return Err(Error::Append); + } + try!(self.stream.write_all(content)); + try!(self.stream.write_all(b"\r\n")); + self.read_response() + } + /// Runs a command and checks if it returns OK. pub fn run_command_and_check_ok(&mut self, command: &str) -> Result<()> { let lines = try!(self.run_command_and_read_response(command)); diff --git a/src/error.rs b/src/error.rs index 28ee761..02df535 100644 --- a/src/error.rs +++ b/src/error.rs @@ -20,7 +20,9 @@ pub enum Error { /// A NO response from the IMAP server. NoResponse(Vec), // Error parsing a server response. - Parse(ParseError) + Parse(ParseError), + // Error appending a mail + Append } impl From for Error { @@ -53,6 +55,7 @@ impl StdError for Error { Error::Parse(ref e) => e.description(), Error::BadResponse(_) => "Bad Response", Error::NoResponse(_) => "No Response", + Error::Append => "Could not append mail to mailbox" } }