Hugo Mills wrote:
> On Mon, Jul 16, 2007 at 09:59:02PM +0100, Graeme Hilton wrote:
>> Does anyone have any pointers to a shell scripting tutorial that might
>> be able to help me split out the emails from an mbox?  Googling for
>> various combinations of "shell script mail forward mbox" doesn't give me
>> much to work with.
> 
>    Probably the thing to do is something like this:
> 
> mkdir split && cd split
> csplit -b %04d ${MBOXFILE} '/^From /' '{*}'
> 
>    That will generate a file in the directory "split" (put it in /tmp
> or wherever else you want) for each mail in the mailbox.
> 
Thanks Hugo, I've expanded on this with the following script*:
#!/bin/sh
# A script to report undetected spam to Plusnet
# command line parameters are <username> and <root folder>
cd /tmp && mkdir -p split && cd split
csplit -b %04d /home/$1/mail/$2/JunkSpam '/From /' '{*}' > /dev/null
#following three lines all together.
files="$(/bin/grep -H '^Subject:' /tmp/split/xx???? |
    /bin/grep -v [[][-]SPAM[-] |
    /bin/grep -o '[x]\{2\}[[:digit:]]\{4\}')"
#echo $files
for n in $files
do
    echo `grep '^Subject:' $n`
    mail -s Spam spam@??? < $n
done
rm xx????
cd ..
rm -rd split
#End of file
It should be noted that this is my first attempt at doing anything
remotely complex in a script.  Any suggestions for tidying it up are
more than welcome.
-- 
Graeme Hilton