mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-19 22:51:13 +00:00
add message deletion integration test
This commit is contained in:
parent
3a7dd4051c
commit
df39d5b364
|
@ -44,26 +44,71 @@ fn mbox() {
|
||||||
fn msg() {
|
fn msg() {
|
||||||
let account = get_account("inbox@localhost");
|
let account = get_account("inbox@localhost");
|
||||||
|
|
||||||
// Let's add message
|
// Add messages
|
||||||
smtp::send(
|
smtp::send(
|
||||||
&account,
|
&account,
|
||||||
&lettre::Message::builder()
|
&lettre::Message::builder()
|
||||||
.from("sender@localhost".parse().unwrap())
|
.from("sender-a@localhost".parse().unwrap())
|
||||||
.to("inbox@localhost".parse().unwrap())
|
.to("inbox@localhost".parse().unwrap())
|
||||||
.subject("Very important message")
|
.subject("Subject A")
|
||||||
.singlepart(
|
.singlepart(lettre::message::SinglePart::builder().body("Body A".as_bytes().to_vec()))
|
||||||
lettre::message::SinglePart::builder().body("Hello, world!".as_bytes().to_vec()),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
.unwrap();
|
||||||
|
smtp::send(
|
||||||
|
&account,
|
||||||
|
&lettre::Message::builder()
|
||||||
|
.from("\"Sender B\" <sender-b@localhost>".parse().unwrap())
|
||||||
|
.to("inbox@localhost".parse().unwrap())
|
||||||
|
.subject("Subject B")
|
||||||
|
.singlepart(lettre::message::SinglePart::builder().body("Body B".as_bytes().to_vec()))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// We should see the message
|
// Login
|
||||||
let mut imap_conn = ImapConnector::new(&account).unwrap();
|
let mut imap_conn = ImapConnector::new(&account).unwrap();
|
||||||
|
|
||||||
|
// List messages
|
||||||
|
// TODO: check non-existance of \Seen flag
|
||||||
let msgs = imap_conn.list_msgs("INBOX", &10, &0).unwrap();
|
let msgs = imap_conn.list_msgs("INBOX", &10, &0).unwrap();
|
||||||
let msgs = Msgs::from(&msgs);
|
let msgs = Msgs::from(&msgs);
|
||||||
assert_eq!(msgs.0.len(), 1);
|
assert_eq!(msgs.0.len(), 2);
|
||||||
let msg = msgs.0.first().unwrap();
|
|
||||||
assert_eq!("Very important message", msg.subject.as_str());
|
let msg_a = msgs
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.find(|msg| msg.subject == "Subject A")
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(msg_a.subject, "Subject A");
|
||||||
|
assert_eq!(msg_a.sender, "sender-a@localhost");
|
||||||
|
|
||||||
|
let msg_b = msgs
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.find(|msg| msg.subject == "Subject B")
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(msg_b.subject, "Subject B");
|
||||||
|
assert_eq!(msg_b.sender, "Sender B");
|
||||||
|
|
||||||
|
// TODO: search messages
|
||||||
|
// TODO: read message (+ \Seen flag)
|
||||||
|
// TODO: list message attachments
|
||||||
|
// TODO: add/set/remove flags
|
||||||
|
|
||||||
|
// Delete messages
|
||||||
|
imap_conn
|
||||||
|
.add_flags("INBOX", &msg_a.uid.to_string(), "\\Deleted")
|
||||||
|
.unwrap();
|
||||||
|
imap_conn
|
||||||
|
.add_flags("INBOX", &msg_b.uid.to_string(), "\\Deleted")
|
||||||
|
.unwrap();
|
||||||
|
imap_conn.expunge("INBOX").unwrap();
|
||||||
|
assert!(match imap_conn.list_msgs("INBOX", &10, &0) {
|
||||||
|
Err(err) => err.to_string() == "The `INBOX` mailbox is empty",
|
||||||
|
Ok(_) => false,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Logout
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue