Merge pull request #17 from miquelruiz/master
Add support for "STORE" command
This commit is contained in:
commit
2f73134f64
1 changed files with 38 additions and 0 deletions
|
|
@ -194,6 +194,15 @@ impl<T: Read+Write> Client<T> {
|
||||||
self.run_command_and_check_ok("CLOSE")
|
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<Vec<String>> {
|
||||||
|
self.run_command_and_read_response(&format!("STORE {} {}", sequence_set, query))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uid_store(&mut self, uid_set: &str, query: &str) -> Result<Vec<String>> {
|
||||||
|
self.run_command_and_read_response(&format!("UID STORE {} {}", uid_set, query))
|
||||||
|
}
|
||||||
|
|
||||||
/// Copy copies the specified message to the end of the specified destination mailbox.
|
/// 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<()> {
|
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())
|
self.run_command_and_check_ok(&format!("COPY {} {}", sequence_set, mailbox_name).to_string())
|
||||||
|
|
@ -532,4 +541,33 @@ mod tests {
|
||||||
client.close().unwrap();
|
client.close().unwrap();
|
||||||
assert!(client.stream.written_buf == b"a1 CLOSE\r\n".to_vec(), "Invalid close command");
|
assert!(client.stream.written_buf == b"a1 CLOSE\r\n".to_vec(), "Invalid close command");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn store() {
|
||||||
|
generic_store(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn uid_store() {
|
||||||
|
generic_store(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn generic_store(uid: bool) {
|
||||||
|
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 uid_cmd = if uid { " UID " } else { " " };
|
||||||
|
let command = format!("a1{}STORE {} {}\r\n", uid_cmd, sequence_set, query);
|
||||||
|
let mock_stream = MockStream::new(response);
|
||||||
|
let mut client = Client::new(mock_stream);
|
||||||
|
if uid {
|
||||||
|
client.uid_store(sequence_set, query).unwrap();
|
||||||
|
} else {
|
||||||
|
client.store(sequence_set, query).unwrap();
|
||||||
|
}
|
||||||
|
assert!(client.stream.written_buf == command.as_bytes().to_vec(), "Invalid store command");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue