aboutsummaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-12 15:02:02 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-12 15:02:02 +0100
commit22cd0764d810e94e8ea9258b71d4dc25085585bd (patch)
tree34327ab72cddf3fec1aeb4bb68f293a676540a49 /tests/common
parentc1e7f7264a68533262bfe1d181061e577e508030 (diff)
downloadaerogramme-22cd0764d810e94e8ea9258b71d4dc25085585bd.tar.gz
aerogramme-22cd0764d810e94e8ea9258b71d4dc25085585bd.zip
rewrite store testing logicfeat/condstore-try-2
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/fragments.rs67
1 files changed, 55 insertions, 12 deletions
diff --git a/tests/common/fragments.rs b/tests/common/fragments.rs
index 0fd1c45..e07413e 100644
--- a/tests/common/fragments.rs
+++ b/tests/common/fragments.rs
@@ -63,6 +63,7 @@ pub enum Email {
pub enum Selection {
FirstId,
SecondId,
+ All,
}
pub enum SelectMod {
@@ -70,6 +71,20 @@ pub enum SelectMod {
Condstore,
}
+pub enum StoreAction {
+ AddFlags,
+ DelFlags,
+ SetFlags,
+ AddFlagsSilent,
+ DelFlagsSilent,
+ SetFlagsSilent,
+}
+
+pub enum StoreMod {
+ None,
+ UnchangedSince(u64),
+}
+
pub fn capability(imap: &mut TcpStream, ext: Extension) -> Result<()> {
imap.write(&b"5 capability\r\n"[..])?;
@@ -308,18 +323,6 @@ pub fn append_email(imap: &mut TcpStream, content: Email) -> Result<()> {
Ok(())
}
-pub fn add_flags_email(imap: &mut TcpStream, selection: Selection, flag: Flag) -> Result<()> {
- let mut buffer: [u8; 1500] = [0; 1500];
- assert!(matches!(selection, Selection::FirstId));
- assert!(matches!(flag, Flag::Deleted));
- imap.write(&b"50 store 1 +FLAGS (\\Deleted)\r\n"[..])?;
- let _read = read_lines(imap, &mut buffer, Some(&b"50 OK"[..]))?;
-
- Ok(())
-}
-
-#[allow(dead_code)]
-/// Not yet implemented
pub fn search(imap: &mut TcpStream) -> Result<()> {
imap.write(&b"55 search text \"OoOoO\"\r\n"[..])?;
let mut buffer: [u8; 1500] = [0; 1500];
@@ -327,6 +330,46 @@ pub fn search(imap: &mut TcpStream) -> Result<()> {
Ok(())
}
+pub fn store(
+ imap: &mut TcpStream,
+ sel: Selection,
+ flag: Flag,
+ action: StoreAction,
+ modifier: StoreMod
+) -> Result<String> {
+ let mut buffer: [u8; 6000] = [0; 6000];
+
+ let seq = match sel {
+ Selection::FirstId => "1",
+ Selection::SecondId => "2",
+ Selection::All => "1:*",
+ };
+
+ let modif = match modifier {
+ StoreMod::None => "".into(),
+ StoreMod::UnchangedSince(val) => format!(" (UNCHANGEDSINCE {})", val),
+ };
+
+ let flags_str = match flag {
+ Flag::Deleted => "(\\Deleted)",
+ Flag::Important => "(\\Important)",
+ };
+
+ let action_str = match action {
+ StoreAction::AddFlags => "+FLAGS",
+ StoreAction::DelFlags => "-FLAGS",
+ StoreAction::SetFlags => "FLAGS",
+ StoreAction::AddFlagsSilent => "+FLAGS.SILENT",
+ StoreAction::DelFlagsSilent => "-FLAGS.SILENT",
+ StoreAction::SetFlagsSilent => "FLAGS.SILENT",
+ };
+
+ imap.write(format!("57 STORE {}{} {} {}\r\n", seq, modif, action_str, flags_str).as_bytes())?;
+ let read = read_lines(imap, &mut buffer, Some(&b"57 OK"[..]))?;
+ let srv_msg = std::str::from_utf8(read)?;
+ Ok(srv_msg.to_string())
+}
+
pub fn expunge(imap: &mut TcpStream) -> Result<()> {
imap.write(&b"60 expunge\r\n"[..])?;
let mut buffer: [u8; 1500] = [0; 1500];