Authentication-Results: mail-b.sr.ht; dkim=pass header.d=falsifian.org header.i=@falsifian.org Received: from exoco.falsifian.org (exoco.falsifian.org [168.235.109.198]) by mail-b.sr.ht (Postfix) with ESMTPS id D93B411EEAC for <~rjarry/aerc-devel@lists.sr.ht>; Mon, 11 Jul 2022 03:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=2020-07-31; bh=2wdkbgYjO +JFXx2a3QENBlSrLz/LXCBMCat3PLTh9vU=; h=cc:in-reply-to:references: subject:to:from:date; d=falsifian.org; b=ZZ0PE0i4PZsBXvjCqjB1ke+Xzdu7C K2Ub9eSBRfTv1KV2oRPcpzZTrX52D/ngD0053DgiXGWnT9hEtiruIHCTcikPDXMB9s2SoF Asqvfa8YqAepNpNazRRcKVlM5MLcL0+FbC5IQ6DnHxMFWLZ7CP+iFt25RxqgZVkGQPGo2a QpceFchZV2ZzEuQhUbPZAlaViW8CfghJ1hUMNxnEkNQ0FJE3rbK/L+SblkYDr6FDjxNtpY eIXIu1PZKc/9rdMbilHEMqoAQqLcr1J2m0hr8Cj9ItrGeakSCw43VsIGvU+sDJm/EYs+d1 jYQgHeo9gZvo+nROKHzOInzZPf1n6Y7pw== Received: from moth.falsifian.org (cpef81d0f9cb2f3-cmf81d0f9cb2f0.cpe.net.fido.ca [72.140.58.252]) by exoco.falsifian.org (OpenSMTPD) with ESMTPSA id 45c9bf77 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 11 Jul 2022 03:41:45 +0000 (UTC) Received: from localhost (moth.falsifian.org [local]) by moth.falsifian.org (OpenSMTPD) with ESMTPA id 6c7c19b2; Mon, 11 Jul 2022 03:41:42 +0000 (UTC) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 11 Jul 2022 03:41:41 +0000 Message-Id: From: "James Cook" To: "Koni Marti" Subject: notmuch workflow (Was [PATCH aerc] Allow not marking viewed messages as seen.) X-Mailer: aerc 0.10.0-61-g4240f1f-dirty References: <20220705060618.68685-1-falsifian@falsifian.org> In-Reply-To: Cc: (List to bcc; my reply at bottom. If you're not interested in notmuch workflows you can skip this.) > Sorry for jumping into this conversation but when you use notmuch, you > can already work with custom labels/tags that support your workflow I > believe. > > What I do is use notmuch's post-new hook where I tag new messages with > whatever label I want. In the post-new-hook script I would have a line > like this: > > notmuch tag +mycustomlabel -new -- tag:new > > This will set "mycustomlabel" to all new messages in notmuch.=20 > > In aerc you could then use ":cf tag:mycustomlabel" to see all those > tagged messages (or use the query map).=20 > > With the :modify-labels command you can then remove this label and set > another one depending on your workflow, :modify-labels -mycustomlabel > +seen > > Hope this helps. Thank you. I already know notmuch can do this. The problem is synchronizing the information so it's not just in my one computer's notmuch database. Specifically: 0. I often check my email on my Android phone. I'd like to mark things as "done", and conversely see which messages are not yet "done". 1. I like to keep important information backed up, and that includes the "done" status of my emails. 2. I would like to be able to check my email from other devices (though in practice these days it's only phone and laptop). I may be able to address 1 and 2 by synchronizing notmuch's tag database, but it sounds like a mess, so I'm not doing that. Because of these concerns, I've adopted a policy of only using notmuch tags that are backed in some way by the backend (with limited exceptions for short-lived tags). I do use a "spam" tag, but that's backed by moving things in/out of a Spam folder. (I could do the same thing with an "Inbox" or "Archive" tag, but see earlier in the thread for a couple of reasons I don't do that.) Since I brought it up, in case it's useful to anyone else, here are my notmuch hooks for synchronizing the "spam" tag with being in the "Spam" folder. The same technique could be used for an "Archive" tag. Probably similar things have been posted to the notmuch list and wiki. pre-new: #!/bin/sh set -e mail_root=3D$HOME/var/mbsync/falsifian.org # Copy spam status from spam tag to folder location. We do this in the "pr= e" # rather than "post" hook so that if mbsync moved a message in or out of S= pam, # we don't see it yet, so we don't try to override it. # This hook may fail if a message's spam status was changed both externall= y # (mbsync moved it in or out of Spam) or internally ("spam" tag added or # removed), so don't do that. # Move spam to the Spam folder. notmuch search --output=3Dfiles tag:spam not folder:Spam \ | xargs mv_losing_uid_to -- "$mail_root/Spam/cur" # Move non-spam out of the Spam folder. notmuch search --output=3Dfiles folder:Spam not tag:spam \ | xargs mv_losing_uid_to -- "$mail_root/INBOX/cur" # This is a good time to run mbsync: after we've updated paths to match ta= gs, # but before notmuch scans for changes. Running it at a different time sho= uld # be okay; the advantage of running it here is that everything should get = synced # with just one run of "notmuch new". mbsync falsifian.org post-new: #!/bin/sh set -e # Update the "spam" tag to match file locations. notmuch tag +spam folder:Spam not tag:spam notmuch tag -spam tag:spam not folder:Spam And here's my "mv_losing_uid_to" script; I gather something like this is needed to avoid confusing isync (mbsync): #!/usr/bin/env raku # # Usage: # mv_losing_uid_to [--] dir file... # # Moves the files to dir, removing the ",U=3D..." part from their filename= s if # present. Fails if the filenames don't look like Maildir filenames. # # Inspired by the safeMove function from # https://notmuchmail.org/pipermail/notmuch/2019/028956.html # except I don't want to lose the :info suffix, and I want to be extra-car= eful # by failing if it looks like we're being run on the wrong kind of file. sub die_note(Str $message) { note $message; exit 1; } shift @*ARGS if @*ARGS[0] eq '--'; die_note 'Required first argument is missing.' if @*ARGS.elems =3D=3D 0; my IO::Path $destination_dir :=3D @*ARGS[0].IO; die_note 'Destination does not exist or is not a directory.' unless $destination_dir.d; # Compute all the destination paths first, so that if any of the source pa= ths # don't match our expectations, we abort the whole operation. my Pair @renames =3D ( for @*ARGS[1..*] { my regex filename_pattern { # Make sure the old filename matches our expectation. If it # doesn't, something has gone wrong, and we should not proceed. ^ $ =3D [ <-[,.:]> * '.' <-[,.:]> * '.' <-[,.:]> * ] [ ',U=3D' <[ 0..9 ]> + ]? # UID to discard $ =3D [ ':' <-[:]> * ] ? $ }; die_note "Source $_ does not exist or is not a regular file. " ~ 'No files were moved.' unless .IO.f; my $basename :=3D .IO.basename; my $match :=3D $basename ~~ &filename_pattern or die_note "{$basename.raku} doesn't look like a Maildir filename. " ~ 'No files were moved.'; $_ =3D> $destination_dir.add("$match$match"); }); for @renames { # The destination should not exist already. Pass -i just in case. Even # if this is being run non-interactively, better to fail and have # useless "overwrite x?" messages appear than to overwrite. run , $_.key, $_.value or die_note "Failed to move {.key} to {.value}."; } --=20 James