afewmail / afew

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

Moving mails tagged as deleted #309

Open vikasrawal opened 3 years ago

vikasrawal commented 3 years ago

I use mbsync to sync emails, and afew is used to move mails tagged as "deleted" to the Trash folders. But this seems to create the problem that mbsync does not correctly identify mails and propagate mail deletion.

Is this a known problem? Should I not use afew to deal with deleted mails?

mjg commented 3 years ago

Can you describe in more detail what you expect to happen and what in fact does happen when you move your (per tag) deleted mail with afew and sync it with mbsync?

GuillaumeSeren commented 3 years ago

Hey, what I do is a custom query with xarg like this (probably stolen from arch wiki https://wiki.archlinux.org/title/Notmuch#Permanently_delete_emails)

notmuch search --output=files --format=text0 --limit=1 date:..1Y and not tag:unread and not tag:inbox and not tag:to-me and not tag:flagged and not tag:replied | xargs -0 rm
mjg commented 3 years ago

@GuillaumeSeren sure, that's how you delete locally in a notmuch set-up. Alternatively, have "afew" move those files to a folder where the server deletes them after some time.

I understood @vikasrawal 's question differently, as if afew's move would clear a trash flag or such. notmuch syncs some maildir flags with tags but explicitely excludes the trash flag. mbsync syncs the flags, but the exact handling depends on a couple of mbsync config choices.

anarcat commented 2 years ago

I use mbsync to sync emails, and afew is used to move mails tagged as "deleted" to the Trash folders. But this seems to create the problem that mbsync does not correctly identify mails and propagate mail deletion.

is it possible that you forgot the "rename" option to the move plugin?

ecocode commented 2 years ago

Is it even possible to move all mail tagged "deleted" to a Trash folder? As I understand from the docs, you would need to setup a rule for every single maildir.. I happen to have 1000+ maildirs, so that is kind of unusable ;)

GuillaumeSeren commented 2 years ago

Hello, sorry for the delay.

In afew, you can tag / move mails (see https://afew.readthedocs.io/en/latest/move_mode.html?highlight=mailmover#configuration-section), but afew does talk directly to the imap server this usually done with mbsync or other sync tool.

So here to propagate a mail deletion, you just delete the file and then sync again (mbsync).

mjg commented 2 years ago

Hello, sorry for the delay.

In afew, you can tag / move mails (see https://afew.readthedocs.io/en/latest/move_mode.html?highlight=mailmover#configuration-section), but afew does talk directly to the imap server this usually done with mbsync or other sync tool.

So here to propagate a mail deletion, you just delete the file and then sync again (mbsync).

Yes, that's when you delete them locally using notmuch/xarg/rm.

An alternative would be moving them to a trash/30dtrash folder and let the imap server do the purging. And this is where @ecocode 's question comes in: Is it possible to move all mail tagged trash to a trash folder, using afew? And the answer is "no" (unless you set up config for all folders).

But I think for this and similar purposes it would be beneficial to have a "slow/manual" mode of the mover, something like:

afew -M <folder> <query>

which moves all mail matching <query> to <folder>. afew has all the logic already (searching, file renaming, moving). This mode can be slow depending on the scope of the query but would cover the mentioned use case as well as all cases where you do a one-off reorganisation of your local mail store (to be synced up in a follow-up step).

ecocode commented 2 years ago

Michael J Gruber @.***> writes:

But I think for this and similar purposes it would be beneficial to have a "slow/manual" mode of the mover, something like:

afew -M <folder> <query>

which moves all mail matching <query> to <folder>. afew has all the logic already (searching, file renaming, moving). This mode can be slow depending on the scope of the query but would cover the mentioned use case as well as all cases where you do a one-off reorganisation of your local mail store (to be synced up in a follow-up step).

that would be exactly what I'd need ;) for now I wrote a (quick & dirty) fish script handling this

best -- erik colson

GuillaumeSeren commented 2 years ago

Hey,

Is it possible to move all mail tagged trash to a trash folder, using afew? And the answer is "no" (unless you set up config for all folders).

Yes but that would be a nice optimisation of the move filter.

if you consider a small config like:

MyMail/INBOX = 'tag:spam':MyMail/spam 'tag:sent':MyMail/sent 'not tag:inbox':MyMail/archive 'tag:trash':MyMail/trash
MyMail/archive = 'tag:inbox':MyMail/INBOX 'tag:spam':MyMail/spam 'tag:sent':MyMail/sent 'tag:trash':MyMail/trash
MyMail/spam = 'NOT tag:spam':MyMail/INBOX 'tag:sent':MyMail/sent 'tag:trash':MyMail/trash
MyMail/sent = 'NOT tag:sent':MyMail/INBOX 'tag:spam':MyMail/spam 'tag:trash':MyMail/trash
MyMail/trash = 'tag:inbox':MyMail/INBOX 'tag:spam and not tag:trash':MyMail/spam 'tag:sent and not tag:trash':MyMail/sent

Would become

MyMail/* = 'tag:spam':MyMail/spam 'tag:sent':MyMail/sent 'not tag:inbox':MyMail/archive 'tag:trash':MyMail/trash
MyMail/archive = 'tag:inbox':MyMail/INBOX
MyMail/spam = 'NOT tag:spam':MyMail/INBOX
MyMail/sent = 'NOT tag:sent':MyMail/INBOX
MyMail/trash = 'tag:spam and not tag:trash':MyMail/spam 'tag:sent and not tag:trash':MyMail/sent