From 9d51b6bd525784bc108959519c8dd21d30a8b020 Mon Sep 17 00:00:00 2001 From: Damian Poddebniak Date: Tue, 4 Jul 2023 20:40:51 +0200 Subject: [PATCH] chore: Update `imap-codec`. --- Cargo.lock | 128 +++++++------------------- melib/Cargo.toml | 2 +- melib/src/backends/imap.rs | 2 +- melib/src/backends/imap/cache/sync.rs | 10 +- melib/src/backends/imap/connection.rs | 39 ++++---- melib/src/backends/imap/operations.rs | 12 ++- melib/src/email.rs | 18 ++-- 7 files changed, 76 insertions(+), 135 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 379e9e5c..c45098ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "abnf-core" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c44e09c43ae1c368fb91a03a566472d0087c26cf7e1b9e8e289c14ede681dd7d" +checksum = "ec182d1f071b906a9f59269c89af101515a5cbe58f723eb6717e7fe7445c0dea" dependencies = [ "nom", ] @@ -151,7 +151,7 @@ dependencies = [ "futures-lite", "rustix", "signal-hook", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -586,7 +586,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ "errno-dragonfly", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -635,7 +635,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall 0.2.16", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -873,9 +873,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "home" @@ -883,7 +883,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -933,23 +933,24 @@ dependencies = [ [[package]] name = "imap-codec" version = "1.0.0-dev" -source = "git+https://github.com/duesee/imap-codec?rev=95acd5186dacc6c6892603954e3f28d18a9f1193#95acd5186dacc6c6892603954e3f28d18a9f1193" +source = "git+https://github.com/duesee/imap-codec?rev=2c5c1cafc3b342714273ea506447157fee2bc8d1#2c5c1cafc3b342714273ea506447157fee2bc8d1" dependencies = [ "abnf-core", "base64 0.21.2", "chrono", "imap-types", + "log", "nom", + "thiserror", ] [[package]] name = "imap-types" version = "1.0.0-dev" -source = "git+https://github.com/duesee/imap-codec?rev=95acd5186dacc6c6892603954e3f28d18a9f1193#95acd5186dacc6c6892603954e3f28d18a9f1193" +source = "git+https://github.com/duesee/imap-codec?rev=2c5c1cafc3b342714273ea506447157fee2bc8d1#2c5c1cafc3b342714273ea506447157fee2bc8d1" dependencies = [ "base64 0.21.2", "chrono", - "subtle", "thiserror", ] @@ -999,9 +1000,9 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1044,9 +1045,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0aa48fab2893d8a49caa94082ae8488f4e1050d73b367881dcd2198f4199fd8" +checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" [[package]] name = "jobserver" @@ -1474,7 +1475,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi 0.3.2", "libc", ] @@ -1649,7 +1650,7 @@ dependencies = [ "libc", "log", "pin-project-lite", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1798,7 +1799,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1824,9 +1825,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" [[package]] name = "same-file" @@ -1839,11 +1840,11 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -1893,15 +1894,15 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.164" +version = "1.0.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8" [[package]] name = "serde_derive" -version = "1.0.164" +version = "1.0.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6" dependencies = [ "proc-macro2", "quote", @@ -2043,12 +2044,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "svg" version = "0.13.1" @@ -2098,7 +2093,7 @@ dependencies = [ "fastrand", "redox_syscall 0.3.5", "rustix", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -2271,9 +2266,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" [[package]] name = "unicode-normalization" @@ -2497,21 +2492,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -2527,21 +2507,15 @@ version = "0.48.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_gnullvm", "windows_aarch64_msvc 0.48.0", "windows_i686_gnu 0.48.0", "windows_i686_msvc 0.48.0", "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_gnullvm", "windows_x86_64_msvc 0.48.0", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" @@ -2554,12 +2528,6 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.48.0" @@ -2572,12 +2540,6 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.48.0" @@ -2590,12 +2552,6 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.48.0" @@ -2608,24 +2564,12 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" @@ -2638,12 +2582,6 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.48.0" diff --git a/melib/Cargo.toml b/melib/Cargo.toml index f848d141..b025d971 100644 --- a/melib/Cargo.toml +++ b/melib/Cargo.toml @@ -55,7 +55,7 @@ xdg-utils = "^0.4.0" [dependencies.imap-codec] # TODO(#222): Replace `git` and `rev` with `version`. git = "https://github.com/duesee/imap-codec" -rev = "95acd5186dacc6c6892603954e3f28d18a9f1193" +rev = "2c5c1cafc3b342714273ea506447157fee2bc8d1" features = [ "ext_condstore_qresync", "ext_enable", diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index 37c5ef06..4c1f9ce0 100644 --- a/melib/src/backends/imap.rs +++ b/melib/src/backends/imap.rs @@ -1765,7 +1765,7 @@ async fn fetch_hlpr(state: &mut FetchState) -> Result> { }; conn.send_command(CommandBody::Fetch { sequence_set, - attributes: common_attributes(), + macro_or_item_names: common_attributes(), uid: true, }) .await?; diff --git a/melib/src/backends/imap/cache/sync.rs b/melib/src/backends/imap/cache/sync.rs index 84d1ff90..4b2647a9 100644 --- a/melib/src/backends/imap/cache/sync.rs +++ b/melib/src/backends/imap/cache/sync.rs @@ -20,10 +20,10 @@ */ use imap_codec::{ - fetch::{FetchAttribute, MacroOrFetchAttributes}, + fetch::{MacroOrMessageDataItemNames, MessageDataItemName}, search::SearchKey, sequence::SequenceSet, - status::StatusAttribute, + status::StatusDataItemName, }; use super::*; @@ -238,7 +238,9 @@ impl ImapConnection { }; self.send_command(CommandBody::Fetch { sequence_set, - attributes: MacroOrFetchAttributes::FetchAttributes(vec![FetchAttribute::Flags]), + macro_or_item_names: MacroOrMessageDataItemNames::MessageDataItemNames(vec![ + MessageDataItemName::Flags, + ]), uid: true, }) .await?; @@ -690,7 +692,7 @@ impl ImapConnection { /* UIDNEXT shouldn't be 0, since exists != 0 at this point */ self.send_command(CommandBody::status( mailbox_path, - [StatusAttribute::UidNext].as_slice(), + [StatusDataItemName::UidNext].as_slice(), )?) .await?; self.read_response(&mut response, RequiredResponses::STATUS) diff --git a/melib/src/backends/imap/connection.rs b/melib/src/backends/imap/connection.rs index e311d4c3..148b35dc 100644 --- a/melib/src/backends/imap/connection.rs +++ b/melib/src/backends/imap/connection.rs @@ -47,16 +47,16 @@ use futures::io::{AsyncReadExt, AsyncWriteExt}; #[cfg(feature = "deflate_compression")] use imap_codec::extensions::compress::CompressionAlgorithm; use imap_codec::{ - auth::{AuthMechanism, AuthMechanismOther}, + auth::AuthMechanism, codec::{Encode, Fragment}, command::{Command, CommandBody}, - core::{AString, Atom, NonEmptyVec, Tag}, + core::{AString, LiteralMode, NonEmptyVec, Tag}, extensions::enable::CapabilityEnable, mailbox::Mailbox, search::SearchKey, secret::Secret, sequence::SequenceSet, - status::StatusAttribute, + status::StatusDataItemName, }; use native_tls::TlsConnector; pub use smol::Async as AsyncWrapper; @@ -308,9 +308,9 @@ impl ImapStream { "\0{}\0{}", &server_conf.server_username, &server_conf.server_password ); - ret.send_command(CommandBody::authenticate( - AuthMechanism::Plain, - Some(credentials.as_bytes()), + ret.send_command(CommandBody::authenticate_with_ir( + AuthMechanism::PLAIN, + credentials.as_bytes(), )) .await?; ret.read_response(&mut res).await?; @@ -396,12 +396,9 @@ impl ImapStream { "Could not decode `server_password` from base64. Is the value correct?" }) .chain_err_kind(ErrorKind::Configuration)?; - // TODO(#222): Improve this as soon as imap-codec supports XOAUTH2. - ret.send_command(CommandBody::authenticate( - AuthMechanism::Other( - AuthMechanismOther::try_from(Atom::unchecked("XOAUTH2")).unwrap(), - ), - Some(&xoauth2), + ret.send_command(CommandBody::authenticate_with_ir( + AuthMechanism::XOAUTH2, + &xoauth2, )) .await?; } @@ -530,7 +527,7 @@ impl ImapStream { pub async fn send_command(&mut self, body: CommandBody<'_>) -> Result<()> { timeout(self.timeout, async { let command = { - let tag = Tag::unchecked(format!("M{}", self.cmd_id)); + let tag = Tag::unvalidated(format!("M{}", self.cmd_id)); Command { tag, body } }; @@ -550,10 +547,10 @@ impl ImapStream { Fragment::Line { data } => { self.stream.write_all(&data).await?; } - Fragment::Literal { data, sync } => { + Fragment::Literal { data, mode } => { // We only need to wait for a continuation request when we are about to // send a synchronizing literal, i.e., when not using LITERAL+. - if sync { + if mode == LiteralMode::Sync { self.wait_for_continuation_request().await?; } self.stream.write_all(&data).await?; @@ -721,12 +718,12 @@ impl ImapConnection { } else { self.send_command(CommandBody::Status { mailbox: Mailbox::Inbox, - attributes: vec![ - StatusAttribute::UidNext, - StatusAttribute::UidValidity, - StatusAttribute::Unseen, - StatusAttribute::Messages, - StatusAttribute::HighestModSeq, + item_names: vec![ + StatusDataItemName::UidNext, + StatusDataItemName::UidValidity, + StatusDataItemName::Unseen, + StatusDataItemName::Messages, + StatusDataItemName::HighestModSeq, ] .into(), }) diff --git a/melib/src/backends/imap/operations.rs b/melib/src/backends/imap/operations.rs index eba1513f..06855b20 100644 --- a/melib/src/backends/imap/operations.rs +++ b/melib/src/backends/imap/operations.rs @@ -21,7 +21,7 @@ use std::sync::Arc; -use imap_codec::fetch::FetchAttribute; +use imap_codec::fetch::MessageDataItemName; use super::*; use crate::{backends::*, email::*, error::Error}; @@ -72,7 +72,7 @@ impl BackendOp for ImapOp { .await?; conn.send_command(CommandBody::fetch( uid, - vec![FetchAttribute::Flags, FetchAttribute::Rfc822], + vec![MessageDataItemName::Flags, MessageDataItemName::Rfc822], true, )?) .await?; @@ -133,8 +133,12 @@ impl BackendOp for ImapOp { conn.connect().await?; conn.examine_mailbox(mailbox_hash, &mut response, false) .await?; - conn.send_command(CommandBody::fetch(uid, vec![FetchAttribute::Flags], true)?) - .await?; + conn.send_command(CommandBody::fetch( + uid, + vec![MessageDataItemName::Flags], + true, + )?) + .await?; conn.read_response(&mut response, RequiredResponses::FETCH_REQUIRED) .await?; debug!( diff --git a/melib/src/email.rs b/melib/src/email.rs index ffe879b4..6fc61217 100644 --- a/melib/src/email.rs +++ b/melib/src/email.rs @@ -113,7 +113,7 @@ pub use headers::*; #[cfg(feature = "imap_backend")] use imap_codec::{ core::{AString, Atom, NonEmptyVec}, - fetch::{FetchAttribute, MacroOrFetchAttributes}, + fetch::{MacroOrMessageDataItemNames, MessageDataItemName}, flag::Flag as ImapCodecFlag, section::Section, }; @@ -128,20 +128,20 @@ use crate::{ #[cfg(feature = "imap_backend")] // TODO(#222): Make this `const` as soon as it is possible. -pub(crate) fn common_attributes() -> MacroOrFetchAttributes<'static> { - MacroOrFetchAttributes::FetchAttributes(vec![ - FetchAttribute::Uid, - FetchAttribute::Flags, - FetchAttribute::Envelope, - FetchAttribute::BodyExt { +pub(crate) fn common_attributes() -> MacroOrMessageDataItemNames<'static> { + MacroOrMessageDataItemNames::MessageDataItemNames(vec![ + MessageDataItemName::Uid, + MessageDataItemName::Flags, + MessageDataItemName::Envelope, + MessageDataItemName::BodyExt { section: Some(Section::HeaderFields( None, - NonEmptyVec::from(AString::from(Atom::unchecked("REFERENCES"))), + NonEmptyVec::from(AString::from(Atom::unvalidated("REFERENCES"))), )), partial: None, peek: true, }, - FetchAttribute::BodyStructure, + MessageDataItemName::BodyStructure, ]) }