bump imap-rust v3.0.0-alpha.3

This commit is contained in:
Clément DOUIN 2021-05-09 21:40:37 +02:00
parent d41df7d1a4
commit 36d3cd6347
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
6 changed files with 38 additions and 59 deletions

48
Cargo.lock generated
View file

@ -33,12 +33,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -408,9 +402,9 @@ dependencies = [
[[package]] [[package]]
name = "imap" name = "imap"
version = "2.4.0" version = "3.0.0-alpha.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b45e5e8d7783a68f2a0e2451bd19446412202fe21c24d34f4b282a510b91ede3" checksum = "e6db7782d7160066e0293d32c31b06b443f6da58a86594629554582d8a006097"
dependencies = [ dependencies = [
"base64 0.13.0", "base64 0.13.0",
"bufstream", "bufstream",
@ -418,17 +412,17 @@ dependencies = [
"imap-proto", "imap-proto",
"lazy_static", "lazy_static",
"native-tls", "native-tls",
"nom 5.1.2", "nom 6.1.2",
"regex", "regex",
] ]
[[package]] [[package]]
name = "imap-proto" name = "imap-proto"
version = "0.10.2" version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16a6def1d5ac8975d70b3fd101d57953fe3278ef2ee5d7816cba54b1d1dfc22f" checksum = "06045f4bd4770f83a263cf85c5be0187e8f646dfa31507ee302019145405f0b6"
dependencies = [ dependencies = [
"nom 5.1.2", "nom 6.1.2",
] ]
[[package]] [[package]]
@ -489,19 +483,6 @@ dependencies = [
"uuid", "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]] [[package]]
name = "libc" name = "libc"
version = "0.2.88" version = "0.2.88"
@ -616,17 +597,6 @@ dependencies = [
"memchr 1.0.2", "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]] [[package]]
name = "nom" name = "nom"
version = "6.1.2" version = "6.1.2"
@ -1043,12 +1013,6 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0" checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.8.0" version = "0.8.0"

View file

@ -10,7 +10,7 @@ chrono = "0.4.19"
clap = {version = "2.33.3", default-features = false, features = ["suggestions", "color"]} clap = {version = "2.33.3", default-features = false, features = ["suggestions", "color"]}
env_logger = "0.8.3" env_logger = "0.8.3"
error-chain = "0.12.4" error-chain = "0.12.4"
imap = "2.4.0" imap = "3.0.0-alpha.3"
lettre = "0.10.0-beta.3" lettre = "0.10.0-beta.3"
log = "0.4.14" log = "0.4.14"
mailparse = "0.13.1" mailparse = "0.13.1"

View file

@ -12,7 +12,7 @@ impl<'f> Serialize for SerializableFlag<'f> {
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_str(match &self.0 { serializer.serialize_str(match self.0 {
Flag::Seen => "Seen", Flag::Seen => "Seen",
Flag::Answered => "Answered", Flag::Answered => "Answered",
Flag::Flagged => "Flagged", Flag::Flagged => "Flagged",
@ -21,6 +21,7 @@ impl<'f> Serialize for SerializableFlag<'f> {
Flag::Recent => "Recent", Flag::Recent => "Recent",
Flag::MayCreate => "MayCreate", Flag::MayCreate => "MayCreate",
Flag::Custom(cow) => cow, Flag::Custom(cow) => cow,
_ => "Unknown",
}) })
} }
} }

View file

@ -119,7 +119,11 @@ impl<'a> ImapConnector<'a> {
.idle() .idle()
.and_then(|mut idle| { .and_then(|mut idle| {
idle.set_keepalive(std::time::Duration::new(keepalive, 0)); 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")?; .chain_err(|| "Could not start the idle mode")?;
@ -173,7 +177,11 @@ impl<'a> ImapConnector<'a> {
.idle() .idle()
.and_then(|mut idle| { .and_then(|mut idle| {
idle.set_keepalive(std::time::Duration::new(keepalive, 0)); 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")?; .chain_err(|| "Could not start the idle mode")?;
app.config.exec_watch_cmds(&app.account)?; 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<Flag>) -> Result<()> {
self.sess self.sess
.append_with_flags(mbox, msg, flags) .append(mbox, msg)
.flags(flags)
.finish()
.chain_err(|| format!("Could not append message to `{}`", mbox))?; .chain_err(|| format!("Could not append message to `{}`", mbox))?;
Ok(()) Ok(())

View file

@ -340,7 +340,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
debug!("sending message…"); debug!("sending message…");
let msg = msg.to_sendable_msg()?; let msg = msg.to_sendable_msg()?;
smtp::send(&app.account, &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()?; input::remove_draft()?;
app.output.print("Message successfully sent"); app.output.print("Message successfully sent");
break; break;
@ -352,7 +352,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
input::PostEditChoice::LocalDraft => break, input::PostEditChoice::LocalDraft => break,
input::PostEditChoice::RemoteDraft => { input::PostEditChoice::RemoteDraft => {
debug!("saving to draft…"); 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()?; input::remove_draft()?;
app.output.print("Message successfully saved to Drafts"); app.output.print("Message successfully saved to Drafts");
break; break;
@ -401,7 +401,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
debug!("sending message…"); debug!("sending message…");
let msg = msg.to_sendable_msg()?; let msg = msg.to_sendable_msg()?;
smtp::send(&app.account, &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")?; imap_conn.add_flags(&app.mbox, uid, "\\Answered")?;
input::remove_draft()?; input::remove_draft()?;
app.output.print("Message successfully sent"); app.output.print("Message successfully sent");
@ -414,7 +414,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
input::PostEditChoice::LocalDraft => break, input::PostEditChoice::LocalDraft => break,
input::PostEditChoice::RemoteDraft => { input::PostEditChoice::RemoteDraft => {
debug!("saving to draft…"); 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()?; input::remove_draft()?;
app.output.print("Message successfully saved to Drafts"); app.output.print("Message successfully saved to Drafts");
break; break;
@ -459,7 +459,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
debug!("sending message…"); debug!("sending message…");
let msg = msg.to_sendable_msg()?; let msg = msg.to_sendable_msg()?;
smtp::send(&app.account, &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()?; input::remove_draft()?;
app.output.print("Message successfully sent"); app.output.print("Message successfully sent");
break; break;
@ -471,7 +471,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
input::PostEditChoice::LocalDraft => break, input::PostEditChoice::LocalDraft => break,
input::PostEditChoice::RemoteDraft => { input::PostEditChoice::RemoteDraft => {
debug!("saving to draft…"); 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()?; input::remove_draft()?;
app.output.print("Message successfully saved to Drafts"); app.output.print("Message successfully saved to Drafts");
break; break;
@ -548,7 +548,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
let msg = Msg::from(imap_conn.read_msg(&app.mbox, &uid)?); let msg = Msg::from(imap_conn.read_msg(&app.mbox, &uid)?);
let mut flags = msg.flags.deref().to_vec(); let mut flags = msg.flags.deref().to_vec();
flags.push(Flag::Seen); 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); debug!("message {} successfully copied to folder `{}`", uid, target);
app.output.print(format!( app.output.print(format!(
"Message {} successfully copied to folder `{}`", "Message {} successfully copied to folder `{}`",
@ -569,9 +569,9 @@ pub fn msg_matches(app: &App) -> Result<bool> {
let mut imap_conn = ImapConnector::new(&app.account)?; let mut imap_conn = ImapConnector::new(&app.account)?;
let msg = Msg::from(imap_conn.read_msg(&app.mbox, &uid)?); 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); 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")?; imap_conn.add_flags(&app.mbox, uid, "\\Seen \\Deleted")?;
debug!("message {} successfully moved to folder `{}`", uid, target); debug!("message {} successfully moved to folder `{}`", uid, target);
app.output.print(format!( app.output.print(format!(
@ -624,7 +624,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
let msg = Msg::from(msg.to_string()); let msg = Msg::from(msg.to_string());
let msg = msg.to_sendable_msg()?; let msg = msg.to_sendable_msg()?;
smtp::send(&app.account, &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(); imap_conn.logout();
return Ok(true); return Ok(true);
@ -636,7 +636,7 @@ pub fn msg_matches(app: &App) -> Result<bool> {
let mut imap_conn = ImapConnector::new(&app.account)?; let mut imap_conn = ImapConnector::new(&app.account)?;
let msg = matches.value_of("message").unwrap(); let msg = matches.value_of("message").unwrap();
let msg = Msg::from(msg.to_string()); 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(); imap_conn.logout();
return Ok(true); return Ok(true);

View file

@ -235,6 +235,7 @@ impl<'m> From<&'m imap::types::Fetch> for Msg<'m> {
flags: Flags::new(fetch.flags()), flags: Flags::new(fetch.flags()),
subject: envelope subject: envelope
.subject .subject
.as_ref()
.and_then(|subj| rfc2047_decoder::decode(subj).ok()) .and_then(|subj| rfc2047_decoder::decode(subj).ok())
.unwrap_or_default(), .unwrap_or_default(),
sender: envelope sender: envelope
@ -243,14 +244,17 @@ impl<'m> From<&'m imap::types::Fetch> for Msg<'m> {
.and_then(|addrs| addrs.first()) .and_then(|addrs| addrs.first())
.and_then(|addr| { .and_then(|addr| {
addr.name addr.name
.as_ref()
.and_then(|name| rfc2047_decoder::decode(name).ok()) .and_then(|name| rfc2047_decoder::decode(name).ok())
.or_else(|| { .or_else(|| {
let mbox = addr let mbox = addr
.mailbox .mailbox
.as_ref()
.and_then(|mbox| String::from_utf8(mbox.to_vec()).ok()) .and_then(|mbox| String::from_utf8(mbox.to_vec()).ok())
.unwrap_or(String::from("unknown")); .unwrap_or(String::from("unknown"));
let host = addr let host = addr
.host .host
.as_ref()
.and_then(|host| String::from_utf8(host.to_vec()).ok()) .and_then(|host| String::from_utf8(host.to_vec()).ok())
.unwrap_or(String::from("unknown")); .unwrap_or(String::from("unknown"));
Some(format!("{}@{}", mbox, host)) Some(format!("{}@{}", mbox, host))