use super::super::defs::*;
use crate::account::model::Flag;
use crate::support::error::Error;
#[test]
fn basic_success() {
let setup = set_up();
let mut client = setup.connect("3501sebs");
quick_log_in(&mut client);
quick_create(&mut client, "3501sebs");
quick_append_enron(&mut client, "3501sebs", 3);
command!(mut responses = client, c("EXAMINE 3501sebs"));
unpack_cond_response! {
(Some(_), s::RespCondType::Ok, Some(s::RespTextCode::ReadOnly(_)), _) =
responses.pop().unwrap() => ()
};
has_untagged_response_matching! {
s::Response::Flags(ref flags) in responses => {
assert_eq!(5, flags.len());
}
};
has_untagged_response_matching! {
s::Response::Exists(3) in responses
};
has_untagged_response_matching! {
s::Response::Recent(3) in responses
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::Unseen(1)),
..
}) in responses
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::PermanentFlags(ref flags)),
..
}) in responses => {
assert_eq!(5, flags.len());
}
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::UidValidity(_)),
..
}) in responses
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::UidNext(4)),
..
}) in responses
};
command!(mut responses = client, c("SELECT 3501sebs"));
unpack_cond_response! {
(Some(_), s::RespCondType::Ok, Some(s::RespTextCode::ReadWrite(_)), _) =
responses.pop().unwrap() => ()
};
has_untagged_response_matching! {
s::Response::Flags(ref flags) in responses => {
assert_eq!(5, flags.len());
}
};
has_untagged_response_matching! {
s::Response::Exists(3) in responses
};
has_untagged_response_matching! {
s::Response::Recent(3) in responses
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::Unseen(1)),
..
}) in responses
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::PermanentFlags(ref flags)),
..
}) in responses => {
assert_eq!(5, flags.len());
}
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::UidValidity(_)),
..
}) in responses
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::UidNext(4)),
..
}) in responses
};
command!(responses = client, c("SELECT 3501sebs"));
has_untagged_response_matching! {
s::Response::Recent(0) in responses
};
ok_command!(client, c("STORE 1:* +FLAGS (\\Seen)"));
command!(responses = client, c("SELECT 3501sebs"));
for response in responses {
if matches!(
response.response,
s::Response::Cond(s::CondResponse {
code: Some(s::RespTextCode::Unseen(_)),
..
})
) {
panic!("Unexpected UNSEEN response: {:?}", response);
}
}
ok_command!(client, c("EXAMINE 3501sebs"));
quick_append_enron(&mut client, "3501sebs", 1);
command!(responses = client, c("EXAMINE 3501sebs"));
has_untagged_response_matching! {
s::Response::Recent(1) in responses
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::Unseen(4)),
..
}) in responses
};
}
#[test]
fn close_and_expunge() {
let setup = set_up();
let mut client = setup.connect("3501sece");
quick_log_in(&mut client);
quick_create(&mut client, "3501sece");
quick_append_enron(&mut client, "3501sece", 3);
ok_command!(client, c("SELECT 3501sece"));
ok_command!(client, c("STORE 1:2 +FLAGS (\\Deleted)"));
command!(responses = client, c("EXAMINE 3501sece"));
has_untagged_response_matching! {
s::Response::Exists(3) in responses
};
command!([response] = client, c("CLOSE"));
assert_tagged_ok(response);
command!(responses = client, c("SELECT 3501sece"));
has_untagged_response_matching! {
s::Response::Exists(3) in responses
};
command!([response] = client, c("CLOSE"));
assert_tagged_ok(response);
command!(responses = client, c("EXAMINE 3501sece"));
has_untagged_response_matching! {
s::Response::Exists(1) in responses
};
}
#[test]
fn error_conditions() {
let setup = set_up();
let mut client = setup.connect("3501seec");
quick_log_in(&mut client);
quick_create(&mut client, "3501seec/noselect/child");
ok_command!(client, c("DELETE 3501seec/noselect"));
ok_command!(client, c("SELECT 3501seec"));
command!(_responses = client, c("EXAMINE \"&#-&#/#\""));
command!([response] = client, c("EXPUNGE"));
unpack_cond_response! {
(Some(_), s::RespCondType::Bad, _, _) = response => ()
};
command!([response] = client, c("SELECT nonexistent"));
assert_error_response(
response,
Some(s::RespTextCode::Nonexistent(())),
Error::NxMailbox,
);
command!([response] = client, c("SELECT 3501seec/noselect"));
assert_error_response(
response,
Some(s::RespTextCode::Nonexistent(())),
Error::MailboxUnselectable,
);
command!([response] = client, c("SELECT ../foo"));
assert_error_response(
response,
Some(s::RespTextCode::Cannot(())),
Error::UnsafeName,
);
command!([response] = client, c("SELECT \"\""));
assert_error_response(
response,
Some(s::RespTextCode::Nonexistent(())),
Error::NxMailbox,
);
command!([response] = client, c("CLOSE"));
unpack_cond_response! {
(Some(_), s::RespCondType::Bad, _, _) = response => ()
};
}
#[test]
fn keywords_included_in_flags() {
let setup = set_up();
let mut client = setup.connect("3501sekf");
quick_log_in(&mut client);
quick_create(&mut client, "3501sekf");
quick_append_enron(&mut client, "3501sekf", 1);
ok_command!(client, c("SELECT 3501sekf"));
ok_command!(client, c("STORE 1 +FLAGS ($Important)"));
command!(responses = client, c("EXAMINE 3501sekf"));
has_untagged_response_matching! {
s::Response::Flags(ref flags) in responses => {
assert!(flags.contains(&Flag::Keyword("$Important".to_owned())));
}
};
has_untagged_response_matching! {
s::Response::Cond(s::CondResponse {
cond: s::RespCondType::Ok,
code: Some(s::RespTextCode::PermanentFlags(ref flags)),
..
}) in responses => {
assert!(flags.contains(&Flag::Keyword("$Important".to_owned())));
}
};
}