From 36d3cd63475ed63cd78c9328cc0fbed310b481f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sun, 9 May 2021 21:40:37 +0200 Subject: [PATCH] bump imap-rust v3.0.0-alpha.3 --- Cargo.lock | 48 ++++++----------------------------------------- Cargo.toml | 2 +- src/flag/model.rs | 3 ++- src/imap/model.rs | 18 ++++++++++++++---- src/msg/cli.rs | 22 +++++++++++----------- src/msg/model.rs | 4 ++++ 6 files changed, 38 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce8c59d..9dbd5e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,12 +33,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "atty" version = "0.2.14" @@ -408,9 +402,9 @@ dependencies = [ [[package]] name = "imap" -version = "2.4.0" +version = "3.0.0-alpha.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45e5e8d7783a68f2a0e2451bd19446412202fe21c24d34f4b282a510b91ede3" +checksum = "e6db7782d7160066e0293d32c31b06b443f6da58a86594629554582d8a006097" dependencies = [ "base64 0.13.0", "bufstream", @@ -418,17 +412,17 @@ dependencies = [ "imap-proto", "lazy_static", "native-tls", - "nom 5.1.2", + "nom 6.1.2", "regex", ] [[package]] name = "imap-proto" -version = "0.10.2" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a6def1d5ac8975d70b3fd101d57953fe3278ef2ee5d7816cba54b1d1dfc22f" +checksum = "06045f4bd4770f83a263cf85c5be0187e8f646dfa31507ee302019145405f0b6" dependencies = [ - "nom 5.1.2", + "nom 6.1.2", ] [[package]] @@ -489,19 +483,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "lexical-core" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db65c6da02e61f55dae90a0ae427b2a5f6b3e8db09f58d10efab23af92592616" -dependencies = [ - "arrayvec", - "bitflags", - "cfg-if 0.1.10", - "ryu", - "static_assertions", -] - [[package]] name = "libc" version = "0.2.88" @@ -616,17 +597,6 @@ dependencies = [ "memchr 1.0.2", ] -[[package]] -name = "nom" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" -dependencies = [ - "lexical-core", - "memchr 2.3.4", - "version_check", -] - [[package]] name = "nom" version = "6.1.2" @@ -1043,12 +1013,6 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0" -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strsim" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index 4003b45..0dafef2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ chrono = "0.4.19" clap = {version = "2.33.3", default-features = false, features = ["suggestions", "color"]} env_logger = "0.8.3" error-chain = "0.12.4" -imap = "2.4.0" +imap = "3.0.0-alpha.3" lettre = "0.10.0-beta.3" log = "0.4.14" mailparse = "0.13.1" diff --git a/src/flag/model.rs b/src/flag/model.rs index 74d0eb4..4b1efb7 100644 --- a/src/flag/model.rs +++ b/src/flag/model.rs @@ -12,7 +12,7 @@ impl<'f> Serialize for SerializableFlag<'f> { where S: Serializer, { - serializer.serialize_str(match &self.0 { + serializer.serialize_str(match self.0 { Flag::Seen => "Seen", Flag::Answered => "Answered", Flag::Flagged => "Flagged", @@ -21,6 +21,7 @@ impl<'f> Serialize for SerializableFlag<'f> { Flag::Recent => "Recent", Flag::MayCreate => "MayCreate", Flag::Custom(cow) => cow, + _ => "Unknown", }) } } diff --git a/src/imap/model.rs b/src/imap/model.rs index e3984f4..6e1e238 100644 --- a/src/imap/model.rs +++ b/src/imap/model.rs @@ -119,7 +119,11 @@ impl<'a> ImapConnector<'a> { .idle() .and_then(|mut idle| { idle.set_keepalive(std::time::Duration::new(keepalive, 0)); - idle.wait_keepalive() + idle.wait_keepalive_while(|res| { + // TODO: handle response + trace!("idle response: {:?}", res); + false + }) }) .chain_err(|| "Could not start the idle mode")?; @@ -173,7 +177,11 @@ impl<'a> ImapConnector<'a> { .idle() .and_then(|mut idle| { idle.set_keepalive(std::time::Duration::new(keepalive, 0)); - idle.wait_keepalive() + idle.wait_keepalive_while(|res| { + // TODO: handle response + trace!("idle response: {:?}", res); + false + }) }) .chain_err(|| "Could not start the idle mode")?; app.config.exec_watch_cmds(&app.account)?; @@ -274,9 +282,11 @@ impl<'a> ImapConnector<'a> { } } - pub fn append_msg(&mut self, mbox: &str, msg: &[u8], flags: &[Flag]) -> Result<()> { + pub fn append_msg(&mut self, mbox: &str, msg: &[u8], flags: Vec) -> Result<()> { self.sess - .append_with_flags(mbox, msg, flags) + .append(mbox, msg) + .flags(flags) + .finish() .chain_err(|| format!("Could not append message to `{}`", mbox))?; Ok(()) diff --git a/src/msg/cli.rs b/src/msg/cli.rs index 3c5e225..ceaa823 100644 --- a/src/msg/cli.rs +++ b/src/msg/cli.rs @@ -340,7 +340,7 @@ pub fn msg_matches(app: &App) -> Result { debug!("sending message…"); let msg = msg.to_sendable_msg()?; smtp::send(&app.account, &msg)?; - imap_conn.append_msg("Sent", &msg.formatted(), &[Flag::Seen])?; + imap_conn.append_msg("Sent", &msg.formatted(), vec![Flag::Seen])?; input::remove_draft()?; app.output.print("Message successfully sent"); break; @@ -352,7 +352,7 @@ pub fn msg_matches(app: &App) -> Result { input::PostEditChoice::LocalDraft => break, input::PostEditChoice::RemoteDraft => { debug!("saving to draft…"); - imap_conn.append_msg("Drafts", &msg.to_vec()?, &[Flag::Seen])?; + imap_conn.append_msg("Drafts", &msg.to_vec()?, vec![Flag::Seen])?; input::remove_draft()?; app.output.print("Message successfully saved to Drafts"); break; @@ -401,7 +401,7 @@ pub fn msg_matches(app: &App) -> Result { debug!("sending message…"); let msg = msg.to_sendable_msg()?; smtp::send(&app.account, &msg)?; - imap_conn.append_msg("Sent", &msg.formatted(), &[Flag::Seen])?; + imap_conn.append_msg("Sent", &msg.formatted(), vec![Flag::Seen])?; imap_conn.add_flags(&app.mbox, uid, "\\Answered")?; input::remove_draft()?; app.output.print("Message successfully sent"); @@ -414,7 +414,7 @@ pub fn msg_matches(app: &App) -> Result { input::PostEditChoice::LocalDraft => break, input::PostEditChoice::RemoteDraft => { debug!("saving to draft…"); - imap_conn.append_msg("Drafts", &msg.to_vec()?, &[Flag::Seen])?; + imap_conn.append_msg("Drafts", &msg.to_vec()?, vec![Flag::Seen])?; input::remove_draft()?; app.output.print("Message successfully saved to Drafts"); break; @@ -459,7 +459,7 @@ pub fn msg_matches(app: &App) -> Result { debug!("sending message…"); let msg = msg.to_sendable_msg()?; smtp::send(&app.account, &msg)?; - imap_conn.append_msg("Sent", &msg.formatted(), &[Flag::Seen])?; + imap_conn.append_msg("Sent", &msg.formatted(), vec![Flag::Seen])?; input::remove_draft()?; app.output.print("Message successfully sent"); break; @@ -471,7 +471,7 @@ pub fn msg_matches(app: &App) -> Result { input::PostEditChoice::LocalDraft => break, input::PostEditChoice::RemoteDraft => { debug!("saving to draft…"); - imap_conn.append_msg("Drafts", &msg.to_vec()?, &[Flag::Seen])?; + imap_conn.append_msg("Drafts", &msg.to_vec()?, vec![Flag::Seen])?; input::remove_draft()?; app.output.print("Message successfully saved to Drafts"); break; @@ -548,7 +548,7 @@ pub fn msg_matches(app: &App) -> Result { let msg = Msg::from(imap_conn.read_msg(&app.mbox, &uid)?); let mut flags = msg.flags.deref().to_vec(); flags.push(Flag::Seen); - imap_conn.append_msg(target, &msg.raw, &flags)?; + imap_conn.append_msg(target, &msg.raw, flags)?; debug!("message {} successfully copied to folder `{}`", uid, target); app.output.print(format!( "Message {} successfully copied to folder `{}`", @@ -569,9 +569,9 @@ pub fn msg_matches(app: &App) -> Result { let mut imap_conn = ImapConnector::new(&app.account)?; let msg = Msg::from(imap_conn.read_msg(&app.mbox, &uid)?); - let mut flags = msg.flags.deref().to_vec(); + let mut flags = msg.flags.to_vec(); flags.push(Flag::Seen); - imap_conn.append_msg(target, &msg.raw, &flags)?; + imap_conn.append_msg(target, &msg.raw, flags)?; imap_conn.add_flags(&app.mbox, uid, "\\Seen \\Deleted")?; debug!("message {} successfully moved to folder `{}`", uid, target); app.output.print(format!( @@ -624,7 +624,7 @@ pub fn msg_matches(app: &App) -> Result { let msg = Msg::from(msg.to_string()); let msg = msg.to_sendable_msg()?; smtp::send(&app.account, &msg)?; - imap_conn.append_msg("Sent", &msg.formatted(), &[Flag::Seen])?; + imap_conn.append_msg("Sent", &msg.formatted(), vec![Flag::Seen])?; imap_conn.logout(); return Ok(true); @@ -636,7 +636,7 @@ pub fn msg_matches(app: &App) -> Result { let mut imap_conn = ImapConnector::new(&app.account)?; let msg = matches.value_of("message").unwrap(); let msg = Msg::from(msg.to_string()); - imap_conn.append_msg(&app.mbox, &msg.to_vec()?, &[Flag::Seen])?; + imap_conn.append_msg(&app.mbox, &msg.to_vec()?, vec![Flag::Seen])?; imap_conn.logout(); return Ok(true); diff --git a/src/msg/model.rs b/src/msg/model.rs index 568b7e3..685d21f 100644 --- a/src/msg/model.rs +++ b/src/msg/model.rs @@ -235,6 +235,7 @@ impl<'m> From<&'m imap::types::Fetch> for Msg<'m> { flags: Flags::new(fetch.flags()), subject: envelope .subject + .as_ref() .and_then(|subj| rfc2047_decoder::decode(subj).ok()) .unwrap_or_default(), sender: envelope @@ -243,14 +244,17 @@ impl<'m> From<&'m imap::types::Fetch> for Msg<'m> { .and_then(|addrs| addrs.first()) .and_then(|addr| { addr.name + .as_ref() .and_then(|name| rfc2047_decoder::decode(name).ok()) .or_else(|| { let mbox = addr .mailbox + .as_ref() .and_then(|mbox| String::from_utf8(mbox.to_vec()).ok()) .unwrap_or(String::from("unknown")); let host = addr .host + .as_ref() .and_then(|host| String::from_utf8(host.to_vec()).ok()) .unwrap_or(String::from("unknown")); Some(format!("{}@{}", mbox, host))