A while ago I posted a query about sorting incoming mail, which started:
>I want to sort my incoming email using procmail and rcvstore; I've noticed
>a number of things:
>
>(1) rcvstore doesn't lock the .mh_sequences files, or anything else...
The replies were ambiguous, some people said that the lack of locking
was dangerous, others said it wasn't. So I decided to do things the
safe way, and write a little script to do the sorting. I call it "sep",
and run it instead of "inc", when something shows up in my mailbox
It's not the quickest thing in the world; it takes about 1 second to run
on my system (266 mhz pentium) plus about 1/2 second for each folder
with any new mail in it.
Of course, you have to edit the body of the script to pull out the
right things for refiling.
I've been using it for about a month without any trouble (though I just
made a few minor edits (8-). Also, it's only been tested under bash.
Here's a copy of the script:
============================ Cut Here =================================
#!/bin/sh
# Invoke as sep
function re-file()
{
if [ $v != 0 ]
then
return 1
fi
oldlast=`scan -format '%(msg)' last +$1 2> /dev/null`
if [ $? = 1 ]
then
oldlast=0
fi
folder -create +$1 > /dev/null
refile -src +inbox pick +$1
let oldlast=oldlast+1
mark -seq unseen +$1 $oldlast-last
if [ $2 = 0 ]
then
echo "Folder: $1"
scan $oldlast-last
fi
folder +inbox > /dev/null
}
# Execution starts here
inboxLast=`scan -format '%(msg)' last +inbox 2> /dev/null`
if [ $? = 1 ]
then
inboxLast=0
fi
inc >& /dev/null
if [ $? != 0 ]
then
echo 'sep: no mail to incorporate'
exit 1
fi
for i in redhat kde nmh hurd fsb linmodem applix bosnet eefc mackay
do
case $i in
redhat)
pick +inbox --X-Mailing-List redhat unseen >& /dev/null
v=$?
re-file redhat $v
;;
kde)
pick +inbox --X-Mailing-List kde unseen >& /dev/null
v=$?
re-file kde $v
;;
nmh)
pick +inbox --X-Mailing-List nmh unseen >& /dev/null
v=$?
re-file nmh $v
;;
hurd)
pick +inbox --X-Mailing-List hurd unseen >& /dev/null
v=$?
re-file hurd $v
;;
fsb)
pick +inbox --Mailing-List fsb unseen >& /dev/null
v=$?
re-file fsb $v
;;
linmodem)
pick +inbox --Mailing-List linmodem unseen >& /dev/null
v=$?
re-file linmodem $v
;;
applix)
pick +inbox --Sender applix unseen >& /dev/null
v=$?
re-file applix $v
;;
bosnet)
pick +inbox --Sender bosnet unseen >& /dev/null
v=$?
re-file bosnet $v
;;
eefc)
pick +inbox --Sender eefc unseen >& /dev/null
v=$?
re-file eefc $v
;;
esac
done
let inboxLast=inboxLast+1
scan +inbox $inboxLast-last >& /dev/null
if [ $? = 0 ]
then
echo "Folder: inbox"
scan +inbox $inboxLast-last
fi