Archive, destroy, measure, or otherwise mangle your Maildir, using this simple /bin/sh script

IMAP is great, until you have to lasso 4000 messages in a GUI client, so that you can move them to a new folder that's been organized by date. For that, shell tools are necessary, that can work directly on Maildir. And there are some great Maildir archiving utilities out there, but they each make assumptions about what I want to do. What I really want is a Maildir system that works like MH, but until then, there's takes either one argument (a 4-digit year) or two arguments (two 8-digit YYYYMMDD values) and computes the start and end time, in unix-epoch seconds, of that interval. If you run it with -d as its first argument it will inform you as to its date-related calculations. (Which may be FreeBSD-specific, I don't know.) will then process its output, assumed to be a set of Maildir filenames. It cracks the timestamp encoded in each filename, and if that timestamp is in range, that filename is sent to the output.


Assuming that you have login access to your IMAP server, which is speaking Maildir on the back end, then your Inbox is stored, more or less, in ~/Maildir/cur. Whereas the OldMail/2016 folder would be stored, for the most part, if it's mostly static, in ~/Maildir/.OldMail.2016/cur. You get the idea. Anyway, CD to some "cur" subdirectory and run "ls" to make sure you're seeing files that look like this:,S=4220,W=4316:2,Sb

That first number before the first dot (".") is the unix-epoch time when the file was first written, which generally means when it was received or created. Let's say you want to count the files whose timestamps occurred in 2016:

ls | 2015 | wc -l

The variations are endless. I pipe to xargs, with -P %, and a command like "mv % ~/Maildir/.OldMail.2016/cur", but clearly there are a lot of opportunities for "rm" here. Just as clearly, I miss MH.

File maildirfind.sh1.33 KB


User login