diff --git a/src/client.rs b/src/client.rs index a5448be..a5fbcc6 100644 --- a/src/client.rs +++ b/src/client.rs @@ -564,6 +564,25 @@ impl Session { self.run_command_and_check_ok(&format!("UID COPY {} {}", uid_set, mailbox_name)) } + /// Moves each message in the sequence into the destination mailbox. This function is + /// named `mv` instead of `move` due to it being a reserved keyword. + /// The MOVE command is defined in [RFC 6851 - "Internet Message Access Protocol (IMAP) + /// - MOVE Extension"](https://tools.ietf.org/html/rfc6851#section-3). + pub fn mv(&mut self, sequence_set: &str, mailbox_name: &str) -> Result<()> { + self.run_command_and_check_ok(&format!("MOVE {} {}", sequence_set, validate_str(mailbox_name)?)) + } + + /// Moves each message in the uid set into the destination mailbox. + /// The UID MOVE command is defined in [RFC 6851 - "Internet Message Access Protocol (IMAP) + /// - MOVE Extension"](https://tools.ietf.org/html/rfc6851#section-3). + pub fn uid_mv(&mut self, uid_set: &str, mailbox_name: &str) -> Result<()> { + self.run_command_and_check_ok(&format!( + "UID MOVE {} {}", + uid_set, + validate_str(mailbox_name)? + )) + } + /// The LIST command returns a subset of names from the complete set /// of all names available to the client. pub fn list( @@ -1220,6 +1239,40 @@ mod tests { ); } + #[test] + fn mv() { + let response = b"* OK [COPYUID 1511554416 142,399 41:42] Moved UIDs.\r\n\ + * 2 EXPUNGE\r\n\ + * 1 EXPUNGE\r\n\ + a1 OK Move completed\r\n".to_vec(); + let mailbox_name = "MEETING"; + let command = format!("a1 MOVE 1:2 {}\r\n", quote!(mailbox_name)); + let mock_stream = MockStream::new(response); + let mut session = mock_session!(mock_stream); + session.mv("1:2", mailbox_name).unwrap(); + assert!( + session.stream.get_ref().written_buf == command.as_bytes().to_vec(), + "Invalid move command" + ); + } + + #[test] + fn uid_mv() { + let response = b"* OK [COPYUID 1511554416 142,399 41:42] Moved UIDs.\r\n\ + * 2 EXPUNGE\r\n\ + * 1 EXPUNGE\r\n\ + a1 OK Move completed\r\n".to_vec(); + let mailbox_name = "MEETING"; + let command = format!("a1 UID MOVE 41:42 {}\r\n", quote!(mailbox_name)); + let mock_stream = MockStream::new(response); + let mut session = mock_session!(mock_stream); + session.uid_mv("41:42", mailbox_name).unwrap(); + assert!( + session.stream.get_ref().written_buf == command.as_bytes().to_vec(), + "Invalid uid move command" + ); + } + #[test] fn fetch() { generic_fetch(" ", |c, seq, query| c.fetch(seq, query))