Support for STORE

This commit is contained in:
Miquel Ruiz 2016-07-10 14:47:46 +01:00
parent ed03acf07d
commit 9e5d5986d0

View file

@ -210,6 +210,11 @@ impl<T: Read+Write> Client<T> {
self.run_command_and_check_ok("CLOSE")
}
/// Store alters data associated with a message in the mailbox.
pub fn store(&mut self, sequence_set: &str, query: &str) -> Result<Vec<String>> {
self.run_command_and_read_response(&format!("STORE {} {}", sequence_set, query))
}
/// Copy copies the specified message to the end of the specified destination mailbox.
pub fn copy(&mut self, sequence_set: &str, mailbox_name: &str) -> Result<()> {
self.run_command_and_check_ok(&format!("COPY {} {}", sequence_set, mailbox_name).to_string())
@ -560,4 +565,19 @@ mod tests {
client.close().unwrap();
assert!(client.stream.written_buf == b"a1 CLOSE\r\n".to_vec(), "Invalid close command");
}
#[test]
fn store() {
let response = b"* 2 FETCH (FLAGS (\\Deleted \\Seen))\r\n\
* 3 FETCH (FLAGS (\\Deleted))\r\n\
* 4 FETCH (FLAGS (\\Deleted \\Flagged \\Seen))\r\n\
a1 OK STORE completed\r\n".to_vec();
let sequence_set = "2:4";
let query = "+FLAGS (\\Deleted)";
let command = format!("a1 STORE {} {}\r\n", sequence_set, query);
let mock_stream = MockStream::new(response);
let mut client = Client::new(mock_stream);
client.store(sequence_set, query).unwrap();
assert!(client.stream.written_buf == command.as_bytes().to_vec(), "Invalid store command");
}
}