From 4c002a1dd3518873208693a50d5822d2e14ad492 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 23 Aug 2021 02:50:13 -0500 Subject: [PATCH] i fucking hate email --- imap/src/client/client.rs | 19 +++++++++++++++++-- imap/src/proto/test_rfc3501.rs | 20 ++++++++++++++++++++ mbsync/src/store.rs | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/imap/src/client/client.rs b/imap/src/client/client.rs index 7022aba..0f18bff 100644 --- a/imap/src/client/client.rs +++ b/imap/src/client/client.rs @@ -126,6 +126,16 @@ impl ClientAuthenticated { client_expose!(async execute(cmd: Command) -> Result); client_expose!(async has_capability(cap: impl AsRef) -> Result); + pub async fn search(&mut self) -> Result<()> { + let cmd = Command::Examine; + let res = self.execute(cmd).await?; + let (done, data) = res.wait().await?; + println!("done = {:?}", done); + println!("data = {:?}", data); + + Ok(()) + } + /// Runs the LIST command pub async fn list(&mut self) -> Result> { let cmd = Command::List(CommandList { @@ -168,13 +178,18 @@ impl ClientAuthenticated { code: Some(code), .. }, - ) => match code { + ) + | Response::Condition(Condition { + status: Status::Ok, + code: Some(code), + .. + }) => match code { ResponseCode::Unseen(value) => select.unseen = Some(value), ResponseCode::UidNext(value) => select.uid_next = Some(value), ResponseCode::UidValidity(value) => select.uid_validity = Some(value), _ => {} }, - _ => {} + _ => warn!("unknown response {:?}", resp), } } diff --git a/imap/src/proto/test_rfc3501.rs b/imap/src/proto/test_rfc3501.rs index 209f601..6f097c8 100644 --- a/imap/src/proto/test_rfc3501.rs +++ b/imap/src/proto/test_rfc3501.rs @@ -21,6 +21,26 @@ fn test_literal() { #[test] fn afl() { let _ = response(Bytes::from(b"* 4544444444 444 ")); } +#[test] +fn test_date() {} + +#[test] +fn test_fetch() { + use nom::Err; + use panorama_proto_common::convert_error; + let buf = Bytes::from(b"* 8045 FETCH (UID 8225 ENVELOPE (\"Sun, 21 Mar 2021 18:44:10 -0700\" \"SUBJECT\" ((\"SENDER\" NIL \"sender\" \"example.com\")) ((\"SENDER\" NIL \"sender\" \"example.com\")) ((\"noreply\" NIL \"noreply\" \"example.com\")) ((\"NAME\" NIL \"user\" \"gmail.com\")) NIL NIL NIL \"\") FLAGS () INTERNALDATE \"22-Mar-2021 01:44:12 +0000\" RFC822.SIZE 13503)\r\n".to_vec()); + let res = response(buf.clone()); + let res = match res { + Ok((_, res)) => res, + Err(Err::Error(err)) | Err(Err::Failure(err)) => { + println!("code: {}", convert_error(buf, err)); + panic!() + } + _ => panic!(), + }; + assert!(matches!(res, Response::Expunge(2))); +} + #[test] fn test_capabilities() { assert_eq!( diff --git a/mbsync/src/store.rs b/mbsync/src/store.rs index b2a4672..3594a09 100644 --- a/mbsync/src/store.rs +++ b/mbsync/src/store.rs @@ -55,6 +55,7 @@ pub async fn open(config: &Config, store_name: impl AsRef) -> Result