From 2f1af34b2d77a542d4c7962765f0c0a96ead90aa Mon Sep 17 00:00:00 2001 From: Miquel Ruiz Date: Mon, 11 Jul 2016 22:44:46 +0100 Subject: [PATCH] Support for UID COPY & tests --- src/client.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 915ab5d..2a1e8ce 100644 --- a/src/client.rs +++ b/src/client.rs @@ -208,8 +208,12 @@ impl Client { self.run_command_and_check_ok(&format!("COPY {} {}", sequence_set, mailbox_name).to_string()) } + pub fn uid_copy(&mut self, uid_set: &str, mailbox_name: &str) -> Result<()> { + self.run_command_and_check_ok(&format!("UID COPY {} {}", uid_set, mailbox_name)) + } + /// The LIST command returns a subset of names from the complete set - /// of all names available to the client. + /// of all names available to the client. pub fn list(&mut self, reference_name: &str, mailbox_search_pattern: &str) -> Result> { self.run_command_and_parse(&format!("LIST {} {}", reference_name, mailbox_search_pattern)) } @@ -570,4 +574,30 @@ mod tests { } assert!(client.stream.written_buf == command.as_bytes().to_vec(), "Invalid store command"); } + + #[test] + fn copy() { + generic_copy(false) + } + + #[test] + fn uid_copy() { + generic_copy(true) + } + + fn generic_copy(uid: bool) { + let response = b"a1 OK COPY completed\r\n".to_vec(); + let sequence_set = "2:4"; + let mailbox = "MEETING"; + let uid_cmd = if uid { " UID " } else { " " }; + let command = format!("a1{}COPY {} {}\r\n", uid_cmd, sequence_set, mailbox); + let mock_stream = MockStream::new(response); + let mut client = Client::new(mock_stream); + if uid { + client.uid_copy(sequence_set, mailbox).unwrap(); + } else { + client.copy(sequence_set, mailbox).unwrap(); + } + assert!(client.stream.written_buf == command.as_bytes().to_vec(), "Invalid copy command"); + } }