From eaa83b71efb605a8bfed5e09fffae5b396dae115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 23 Oct 2021 00:46:21 +0200 Subject: [PATCH] notify cannot get body (#233) * imap: fix notify cmd * doc: update changelog --- CHANGELOG.md | 7 ++++++- src/config/config_entity.rs | 2 +- src/domain/imap/imap_service.rs | 27 +++++++++++---------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f732a8d..78cfd2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Error on empty subject [#229] +- Error when receiving notification from `notify` command [#228] + +### Change + +- Remove error when empty subject [#229] ## [0.5.0] - 2021-10-10 @@ -337,4 +341,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#199]: https://github.com/soywod/himalaya/issues/199 [#205]: https://github.com/soywod/himalaya/issues/205 [#215]: https://github.com/soywod/himalaya/issues/215 +[#228]: https://github.com/soywod/himalaya/issues/228 [#229]: https://github.com/soywod/himalaya/issues/229 diff --git a/src/config/config_entity.rs b/src/config/config_entity.rs index b4ce176..68016e0 100644 --- a/src/config/config_entity.rs +++ b/src/config/config_entity.rs @@ -111,7 +111,7 @@ impl Config { let subject = subject.as_ref(); let sender = sender.as_ref(); - let default_cmd = format!(r#"notify-send "📫 {}" "{}""#, sender, subject); + let default_cmd = format!(r#"notify-send "New message from {}" "{}""#, sender, subject); let cmd = self .notify_cmd .as_ref() diff --git a/src/domain/imap/imap_service.rs b/src/domain/imap/imap_service.rs index 7db842a..d51bb21 100644 --- a/src/domain/imap/imap_service.rs +++ b/src/domain/imap/imap_service.rs @@ -14,7 +14,7 @@ use std::{ use crate::{ config::{Account, Config}, - domain::{Envelopes, Flags, Mbox, Mboxes, Msg, RawEnvelopes, RawMboxes}, + domain::{Envelope, Envelopes, Flags, Mbox, Mboxes, Msg, RawEnvelopes, RawMboxes}, }; type ImapSession = imap::Session>; @@ -284,21 +284,16 @@ impl<'a> ImapServiceInterface<'a> for ImapService<'a> { .join(","); let fetches = self .sess()? - .uid_fetch(uids, "(ENVELOPE)") + .uid_fetch(uids, "(UID ENVELOPE)") .context("cannot fetch new messages enveloppe")?; for fetch in fetches.iter() { - let msg = Msg::try_from(fetch)?; + let msg = Envelope::try_from(fetch)?; let uid = fetch.uid.ok_or_else(|| { anyhow!("cannot retrieve message {}'s UID", fetch.message) })?; - let from = msg - .from - .as_ref() - .and_then(|addrs| addrs.iter().next()) - .map(|addr| addr.to_string()) - .unwrap_or(String::from("unknown")); + let from = msg.sender.to_owned().into(); config.run_notify_cmd(&msg.subject, &from)?; debug!("notify message: {}", uid); @@ -350,7 +345,7 @@ impl<'a> ImapServiceInterface<'a> for ImapService<'a> { } fn add_flags(&mut self, seq_range: &str, flags: &Flags) -> Result<()> { - let mbox = self.mbox.to_owned(); + let mbox = self.mbox; let flags: String = flags.to_string(); self.sess()? .select(&mbox.name) @@ -361,25 +356,25 @@ impl<'a> ImapServiceInterface<'a> for ImapService<'a> { Ok(()) } - fn set_flags(&mut self, uid_seq: &str, flags: &Flags) -> Result<()> { - let mbox = self.mbox.to_owned(); + fn set_flags(&mut self, seq_range: &str, flags: &Flags) -> Result<()> { + let mbox = self.mbox; self.sess()? .select(&mbox.name) .context(format!(r#"cannot select mailbox "{}""#, self.mbox.name))?; self.sess()? - .store(uid_seq, format!("FLAGS ({})", flags)) + .store(seq_range, format!("FLAGS ({})", flags)) .context(format!(r#"cannot set flags "{}""#, &flags))?; Ok(()) } - fn remove_flags(&mut self, uid_seq: &str, flags: &Flags) -> Result<()> { - let mbox = self.mbox.to_owned(); + fn remove_flags(&mut self, seq_range: &str, flags: &Flags) -> Result<()> { + let mbox = self.mbox; let flags = flags.to_string(); self.sess()? .select(&mbox.name) .context(format!(r#"cannot select mailbox "{}""#, self.mbox.name))?; self.sess()? - .store(uid_seq, format!("-FLAGS ({})", flags)) + .store(seq_range, format!("-FLAGS ({})", flags)) .context(format!(r#"cannot remove flags "{}""#, &flags))?; Ok(()) }