afewmail / afew

an initial tagging script for notmuch mail
ISC License
325 stars 97 forks source link

Maintaining a folder/tag parity #313

Open ploum opened 2 years ago

ploum commented 2 years ago

As I still also access mail through my webmail, I’m trying to configure notmuch/afew in order to maintain a tag/folder parity.

-> If a mail is moved in a folder on the webmail, it should have the old folder tag removed and a the new folder tag added in notmuch.

-> If a mail is taggued with "archive", it should be moved to the archive folder (yes, my folders are really simples : inbox, sent and archives).

I thought that, with afew, this would be quite easy to implement. But, after spending several days on it, I still don’t make a lot of progress. I’ve settled so far with only one FolderNameFilter to make debugging easy.

If a folder is seen as "inbox" by notmuch then archived on the webmail, it will keep its inbox tag forever. (same happen for any folder)

Is there a way to achieve that with afew?

I’ve the feeling that this might be a common usecase and thus should be advertised more clearly in the documentation

benmezger commented 2 years ago

@ploum I believe you might need a few more steps. I solved this with Gmail by using the following approach:

  1. run afew with -m flag before running mbsync
  2. Run mbsync, then tag all your email
  3. Run afew with the -m flag again, and ideally, before that, tag all your emails again.

See: https://github.com/benmezger/dotfiles/blob/main/dot_config/afew/config

Ideally, you need to filter for the folder instead. If the email is in the deleted folder, for example, remove all other tags and keep the +deleted flag.

GuillaumeSeren commented 2 years ago

Hey, sorry to be late.

I do the same, so yes it can be done, it is not synchronous so new mails are not tagged / sorted etc, but it is good to have the imap storage to be close that the notmuch state.

Before each sync I use the MailMover to move the according to some rules like:

# Perso
Perso/INBOX = 'tag:spam':Perso/spam 'tag:sent':Perso/sent 'not tag:inbox':Perso/archive 'tag:trash':Perso/trash
Perso/archive = 'tag:inbox':Perso/INBOX 'tag:spam':Perso/spam 'tag:sent':Perso/sent 'tag:trash':Perso/trash
Perso/spam = 'NOT tag:spam':Perso/INBOX 'tag:sent':Perso/sent 'tag:trash':Perso/trash
Perso/sent = 'NOT tag:sent':Perso/INBOX 'tag:spam':Perso/spam 'tag:trash':Perso/trash
Perso/trash = 'tag:inbox':Perso/INBOX 'tag:spam and not tag:trash':Perso/spam 'tag:sent and not tag:trash':Perso/sent
agenbite commented 2 years ago

As I said in #317 for those of us that do have an intricate folder tree, it'd be nice to have an afew solution which does not involve listing all the folders. Thanks for contributing, though.