Merge pull request #88 from mtorromeo/feature-move

client: Add MOVE and UID MOVE support
This commit is contained in:
Jon Gjengset 2018-10-06 12:14:52 -04:00 committed by GitHub
commit a9e993f98b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -564,6 +564,25 @@ impl <T: Read + Write> Session<T> {
self.run_command_and_check_ok(&format!("UID COPY {} {}", uid_set, mailbox_name)) 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 /// 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( 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] #[test]
fn fetch() { fn fetch() {
generic_fetch(" ", |c, seq, query| c.fetch(seq, query)) generic_fetch(" ", |c, seq, query| c.fetch(seq, query))