From b28ae3efbe1f8c055641afde1355d46bae9971a5 Mon Sep 17 00:00:00 2001 From: Massimiliano Torromeo Date: Thu, 4 Oct 2018 13:03:58 +0200 Subject: [PATCH 1/4] client: Add MOVE and UID MOVE support --- src/client.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/client.rs b/src/client.rs index 43f0c5d..ff76723 100644 --- a/src/client.rs +++ b/src/client.rs @@ -563,6 +563,20 @@ 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. + pub fn imap_move(&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. + pub fn uid_move(&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( @@ -1173,6 +1187,40 @@ mod tests { ); } + #[test] + fn imap_move() { + 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.imap_move("1:2", mailbox_name).unwrap(); + assert!( + session.stream.get_ref().written_buf == command.as_bytes().to_vec(), + "Invalid move command" + ); + } + + #[test] + fn uid_move() { + 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_move("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)) From 23449e203ef991fbe178a38574a51767995e2ee7 Mon Sep 17 00:00:00 2001 From: Massimiliano Torromeo Date: Fri, 5 Oct 2018 17:29:34 +0200 Subject: [PATCH 2/4] Added links to the RFC for the functions mv and uid_move --- src/client.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index ff76723..a67e64e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -563,12 +563,17 @@ 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. - pub fn imap_move(&mut self, sequence_set: &str, mailbox_name: &str) -> Result<()> { + /// 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_move(&mut self, uid_set: &str, mailbox_name: &str) -> Result<()> { self.run_command_and_check_ok(&format!( "UID MOVE {} {}", From a6f0240f949eea791aa14f2cb3aff69d0644e08a Mon Sep 17 00:00:00 2001 From: Massimiliano Torromeo Date: Fri, 5 Oct 2018 17:29:43 +0200 Subject: [PATCH 3/4] Renamed imap_move to mv --- src/client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index a67e64e..fa55b62 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1193,7 +1193,7 @@ mod tests { } #[test] - fn imap_move() { + fn mv() { let response = b"* OK [COPYUID 1511554416 142,399 41:42] Moved UIDs.\r\n\ * 2 EXPUNGE\r\n\ * 1 EXPUNGE\r\n\ @@ -1202,7 +1202,7 @@ mod tests { 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.imap_move("1:2", mailbox_name).unwrap(); + session.mv("1:2", mailbox_name).unwrap(); assert!( session.stream.get_ref().written_buf == command.as_bytes().to_vec(), "Invalid move command" From 201269423dfcc89fa64584348021333503ee261e Mon Sep 17 00:00:00 2001 From: Massimiliano Torromeo Date: Sat, 6 Oct 2018 10:02:10 +0200 Subject: [PATCH 4/4] Renamed uid_move to uid_mv --- src/client.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index fa55b62..5248729 100644 --- a/src/client.rs +++ b/src/client.rs @@ -574,7 +574,7 @@ impl Session { /// 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_move(&mut self, uid_set: &str, mailbox_name: &str) -> Result<()> { + pub fn uid_mv(&mut self, uid_set: &str, mailbox_name: &str) -> Result<()> { self.run_command_and_check_ok(&format!( "UID MOVE {} {}", uid_set, @@ -1210,7 +1210,7 @@ mod tests { } #[test] - fn uid_move() { + 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\ @@ -1219,7 +1219,7 @@ mod tests { 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_move("41:42", mailbox_name).unwrap(); + session.uid_mv("41:42", mailbox_name).unwrap(); assert!( session.stream.get_ref().written_buf == command.as_bytes().to_vec(), "Invalid uid move command"