Re: [OT-ish] Want command line program to selectively delete emails

2023-08-06 Thread Ed Blackman
On Sun, Aug 06, 2023 at 06:41:30PM +0100, Darac Marjal wrote:
> On 04/08/2023 19:34, Ed Blackman wrote:
> > I could probably port archivemail to Python3 with enough time.
> 
> 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

Any chance you still have it?

> 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").

I'd prefer something that operated on a local mail store, but I am running 
Dovecot so I can access my mail folders from my phone  Hmmm...

-- 
Ed Blackman


Re: [OT-ish] Want command line program to selectively delete emails

2023-08-06 Thread Ed Blackman
On Mon, Aug 07, 2023 at 01:57:04AM +1000, Nemo Thorx wrote:
> Quoting Ed Blackman from 04 Aug (a Friday in 2023) at 1434 hours...
> > 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 could call mutt (see, kinda OT!) with "-e" to tag, delete, sync, and
> > quit, but that seems fiddly and heavyweight.
> 
> But if it's being run from cron overnight or something, are you ever
> going to notice? 

Fair enough for "heavyweight".

I've saved your message in case I change my mind.

-- 
Ed Blackman


Re: [OT-ish] Want command line program to selectively delete emails

2023-08-06 Thread Ed Blackman
On Fri, Aug 04, 2023 at 03:15:41PM -0400, Jon LaBadie wrote:
> On Fri, Aug 04, 2023 at 02:34:44PM -0400, Ed Blackman wrote:
> > I could probably port archivemail to Python3 with enough time.
> 
> I make extensive, but very basic, use of archivemail.  I'm concerned about
> its going away.  Does anyone know of an equivalent, maintained,
> program?  Shame if it is dropped.  Though the last update was what,
> 2011 I think, it has caused no problems, it just works.

The issue is that the Python3 email API is much different from the Python2 API.

Knowing that there's at least one other archivemail user that might be 
interested in a Python3 port, I've put some work in.

Do *not* get your hopes up.  After about 5 hours, I'm down to 36 errors and 
failures in the 99 item test suite, having started from about 68 errors and 
failures after a quick Py2->Py3 syntax port.  I've also noted the absence of a 
lot of test cases.  I'm not close enough for coverage to mean anything, but I'm 
guessing the test suite covered less than half the lines of the existing code.

For now I'll keep working on it as I have time and interest, but I might drop 
it if I find something better.

-- 
Ed Blackman


Re: [OT-ish] Want command line program to selectively delete emails

2023-08-06 Thread Darac Marjal


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").





OpenPGP_signature
Description: OpenPGP digital signature


Re: Want command line program to selectively delete emails

2023-08-06 Thread googly . negotiator862
On Sun, Aug 06, 2023 at 04:04:34PM +0200, Marcus C. Gottwald wrote:

> > I think for a true date received test, you have to look at the
> > timestamp part of the filename.

> Well, it looks like both mtime and timestamp-as-part-of-filename may
> change when copying messages between Maildirs, at least when using
> Mutt and a local filesystem. So if mtimes do not reflect the desired
> timestamp, neither might timestamp-as-part-of-filename.

I was thinking of just using cp and friends, and yes I have done that
to move around my maildirs.

I'm curious if mutt preserves the mtime when doing the mutating
operations I mentioned ie. rethreading or editing after the fact.
Especially in the case of editing, I have serious doubts that mtime
is preserved.  But maybe mutt also creates a fresh message in this
case, my memory is foggy.

I'm also curious what other programs look at the mtime to determine
time delivered. I mean real programs, not your hand written scripts
;-)

Friendly,

-- 
Ian


Re: [OT-ish] Want command line program to selectively delete emails

2023-08-06 Thread Nemo Thorx
Quoting Ed Blackman from 04 Aug (a Friday in 2023) at 1434 hours...
> 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 could call mutt (see, kinda OT!) with "-e" to tag, delete, sync, and
> quit, but that seems fiddly and heavyweight.

But if it's being run from cron overnight or something, are you ever
going to notice? 

> 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".

I'm reasonably confident that all filenames (before the ':') are only
convention (I convert an nntp spool to maildir and name them according
to my own naming convention which everything (well, mutt and dovecot)
then honours), and mtime is unused by anything and/or not to be trusted. 

So honetsly, I'd suggest mutt's -e, since it gives you mutt's pattern
matching which is much more powerful than archivemail (admittedly,
I only used that for trivial stuff and only many years ago) and likely
more than anything else available. 

eg, instead of just "received more than X days ago and not flagged",
mutt can let you select/ignore whole threads based on those parameters,
and others alike. eg, I once had archiving setup on a folder-hook thus: 

folder-hook !(Maildir$|archive|search|mfolder|.r.) 'push 
"t~m 600- !~(~m -600) !~(~r <32d) !~(~N) !~(~F) 
!~D^.archivet"'

To decode that: sort reverse threaded, select all messages after the
first 600, but not if it's part of a thread within the first 600, not if
it's in a thread with messages received in the last 32 days, not if it's
in a thread with messages marked 'New' or 'Flagged', and not if it's
a message already marked delete. Then save to the archive mailbox and
established my desired sorting and thread collapse visibility. 

Basically - I wanted a thread-preserving archiving mechanism, and mutt's
thread-aware pattern matching gave it to me. (I didn't include sync in
that setup, preferring at the time to let that occur with mailbox
closing)

In a delete scenario as you're seeking, I'd suggest a multi-step process
which first archives threads you've contributed to - and only then
deleting old ignorable threads. 

Sure It's fiddly - which is your argument against using mutt.

...But it's powerful - which is my argument for using mutt!

Aside - I used folder-hook before because I didn't know of the "-e"
option, and I stopped using it because I found I was often using mutt as
a mailbox debug tool, and this was just getting in the way. I can see
myself going down the rabbithole and reimplementing my old archiver now
(where "now" is "sometime in the next few months, maybe" :)


.../Nemo

-- 
  - -
earth native