From 7bfef154d9eeca5c745402b46d10f726d422c430 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sun, 19 Mar 2023 20:42:35 -0700 Subject: [PATCH] Add rule to preserve unread tag when run with --remove-all. --- procmail2notmuch/src/main.rs | 43 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/procmail2notmuch/src/main.rs b/procmail2notmuch/src/main.rs index fd178e8..f818cbc 100644 --- a/procmail2notmuch/src/main.rs +++ b/procmail2notmuch/src/main.rs @@ -155,29 +155,34 @@ fn notmuch_from_rules(mut w: W, rules: &[Rule]) -> anyhow::Result<()> eprintln!("rule has unknown match {:?}", r); continue; } + + let rule = match m.match_type { + MatchType::From => "from:", + // TODO(wathiede): something more specific? + MatchType::Sender => "from:", + MatchType::To => "to:", + MatchType::Subject => "subject:", + MatchType::List => "List-ID:", + MatchType::Body => "", + // TODO(wathiede): these will probably require adding fields to notmuch + // index. Handle them later. + MatchType::DeliveredTo + | MatchType::XForwardedTo + | MatchType::ReplyTo + | MatchType::XOriginalTo + | MatchType::XSpam => continue, + MatchType::Unknown => unreachable!(), + }; + // Preserve unread status if run with --remove-all + lines.push(format!( + r#"-unprocessed +{} +unread -- is:unread tag:unprocessed {}"{}""#, + t, rule, m.needle + )); lines.push(format!( // TODO(wathiede): this assumes `notmuch new` is configured to add // `tag:unprocessed` to all new mail. r#"-unprocessed +{} -- tag:unprocessed {}"{}""#, - t, - match m.match_type { - MatchType::From => "from:", - // TODO(wathiede): something more specific? - MatchType::Sender => "from:", - MatchType::To => "to:", - MatchType::Subject => "subject:", - MatchType::List => "List-ID:", - MatchType::Body => "", - // TODO(wathiede): these will probably require adding fields to notmuch - // index. Handle them later. - MatchType::DeliveredTo - | MatchType::XForwardedTo - | MatchType::ReplyTo - | MatchType::XOriginalTo - | MatchType::XSpam => continue, - MatchType::Unknown => unreachable!(), - }, - m.needle + t, rule, m.needle )); } }