On 04/08/2023 19:34, Ed Blackman wrote:
Any suggestions for a command line program to select emails for deletion based on command 
line options?  I specifically want one that can remove emails that were received more 
than X days ago, but can also express "but don't delete if they're flagged".

I had been using archivemail 
(https://manpages.debian.org/buster/archivemail/archivemail.1.en.html) from 
cron to delete emails in certain folders. It saves me from having to manually 
go in and purge folders for lists that I want to have available, but don't ever 
read old messages.

It allows commands like:
  archivemail --quiet --delete --days=30 ~/mail/folder1/
  archivemail --quiet --delete --days=30 --include-flagged ~/mail/folder2/

It supports reading Maildir, IMAP, mbox, MH, but the mailboxes I need to purge 
are all maildir.

When I recently upgraded to Debian 12, I found that archivemail has been 
removed from Debian because it's an unmaintained Python 2 program.

I could probably port archivemail to Python3 with enough time.

I could compile Python2 from source, but don't want to.

I could call mutt (see, kinda OT!) with "-e" to tag, delete, sync, and quit, 
but that seems fiddly and heavyweight.

I could extract the interesting parts of archivemail into my own script (most 
of the script is about *archiving* email, which I'm not interested in).

I could give up on using the message headers to determine the message date, learn how 
filenames are constructed in Maildir (to read the flags) and use a shell script built 
around "find".

None of those options are great, so I thought I'd see if there's something that 
I could just install.

I had a go at rewriting archivemail into python3 (partly because I wanted to pipe messages into spam learning as I archived things), but I've now settled on using imapfilter (https://github.com/lefcha/imapfilter) as a good toolkit. You can basically use it as a Lua library for IMAP handling - that is, imapfilter will do the heavy lifting of connecting, authenticating, listing etc, you just need to provide it a filter file which tells it what to do. (For example, you can say "Get all the messages in box 'Foo' and, for each one if the received date is greater than X days and AND the message is not flagged, then delete this message").


Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to