From 9e5d5986d05a85e00b252f6781fac338ec41a938 Mon Sep 17 00:00:00 2001 From: Miquel Ruiz Date: Sun, 10 Jul 2016 14:47:46 +0100 Subject: [PATCH] Support for STORE --- src/client.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/client.rs b/src/client.rs index 24e857e..53c590e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -210,6 +210,11 @@ impl Client { 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> { + 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"); + } }