How can I apply my procmail filters to my maildir inbox?
Solution 1
I believe this will work. You need to run formail
to reformat the mail and send it back through procmail
.
From the Maildir directory:
cat * | formail -s procmail
Solution 2
you might be able to do it in place, like this:
$ for m in Mail/{cur,new}/*; do echo $m; procmail <$m; rm $m; done
You have to remove each original email afterwards, or else procmail will duplicate it.
It will also record everything as new. I'm not sure of a good way to handle that.
Solution 3
If you are using mutt, you can pipe the email through procmail and also delete the original from your inbox with a key command something like this:
muttrc:
macro index y '<enter-command>unset wait_key<enter><tag-prefix><pipe-entry>/usr/bin/procmail /home/user/.procmailrc<enter><tag-prefix><delete-message><enter-command>set wait_key<enter>'
macro pager y '<enter-command>unset wait_key<enter><pipe-entry>/usr/bin/procmail /home/user/.procmailrc<enter><delete-message><enter-command>set wait_key<enter>'
Solution 4
It seems like there is no good solution for this: procmail only seems to accept mail input from stdin
, which limits maildir applications.
I faced a similar situation, and the best solution that fit my needs was simply duplicating what I wanted procmail
to do, but what it most definitely cannot do, with my own little script, which should be sufficient if you only have one or two simple rules that you need to take care of:
cd ~/Maildir/
sh -c 'for i in `egrep -l "^Delivered-To: [email protected]" cur/*`; \
do mv $i .FreeBSD.perforce/$i; done'
This is not optimal, either, but at least it should not suffer from needless IO and potential data loss issues.
Related videos on Youtube
![Cory Klein](https://i.stack.imgur.com/gmL3R.jpg?s=256&g=1)
Cory Klein
Updated on September 18, 2022Comments
-
Cory Klein almost 2 years
Last night I subscribed to a mailing list, and discovered this morning that my procmail filter didn't apply to many of the mailing list messages. Now I have loads of less-important mailing list messages interspersed with my more-important work emails sitting in my inbox.
Is it possible to rerun all the emails in my inbox through my procmail filters again?
Note: I am using the maildir format
-
cnst over 11 yearsThis would seem wasteful on disc io: procmail filtering is usually only done based on headers, but such piping will cause the whole message to be read and written to disc all over again. Besides, should procmail run out of memory or encounter some other issue, you still unconditionally remove the file (ouch!), which seems pretty scary, too. I would say that this is a completely unacceptable solution as far as maildir goes.
-
RANJAN YADAV over 6 yearsThis could be incrementally improved by doing
procmail < $m && rm $m
instead ofprocmail < $m ; rm $m
so at least the message isn't removed if procmail fails. -
Rudolf Adamkovic about 3 yearsExecuting
rm
after;
is extremely unsafe. Why not use&&
instead? That way,rm
will run if and only ifprocmail
processed the message successfully.