[vox-tech] program to move message from inbox to folder
Ken Herron
Kherron+lugod at fmailbox.com
Wed Sep 29 12:30:17 PDT 2004
--On Wednesday, September 29, 2004 11:29:16 -0700 Charles McLaughlin
<cmclaughlin at ucdavis.edu> wrote:
> I want to write a shell script to move messages from a mail spool inbox
> to a number of folders. So if there are messages in the inbox, the
> first message should go to folder1, second message should go to
> folder2, etc.
Your first hurdle is that the mail spool is most likely a single file
with all of the messages concatenated together; you'll need to split it
into separate messages. There are a few ways to do this:
1) Don't deliver the mail into the spool file in the first place. Set up
a .forward file which causes the mail to be piped into some other
program, such as procmail.
2) Use the formail utility (which comes with procmail) to split the spool
file into separate messages, which are similarly piped into another
program.
3) Write a completely custom utility, in perl or python perhaps, which
can parse the spool into separate messages. I assume this isn't an option
for you.
Using method 1 or 2, a simple way to get what you want is to pipe the
messages into procmail and have procmail deliver them into an MH-format
mailbox. An MH mailbox is a directory where the messages are files with
sequential numbers for names; this is different from the maildir format.
Basically, you'd deliver the mail into the MH directory using procmail
(or formail + procmail), then sweep the directory using a simple shell
script that moves each file to a mailbox based on the file's number.
So, one way to accomplish this is as follows. First you'd create a
.forward file in the home directory of the spool file's owner, containing
the following:
|procmail
This pipes the user's messages into procmail instead of delivering them
to the spool file.
You'd also create a directory such as "/home/user/mhinbox" to serve as
the inbox, and a .procmailrc containing something like this:
:0
/home/user/mhinbox/.
This writes each message to a file in the directory, using a sequential
numeric filename.
Finally, you'd run a script like the following from cron every fifteen
minutes or whatever:
#!/bin/bash
cd /home/user/mhinbox || exit 1
mbox[0]=/path/to/mbox1
mbox[1]=/path/to/mbox2
...
mboxcount=5
for file in *
do
box=${mbox[$file % mboxcount]}
# deliver $file into $box
done
--
"Grand Funk Railroad paved the way for Jefferson Airplane, which cleared
the way for Jefferson Starship. The stage was now set for the Alan Parsons
Project, which I believe was some sort of hovercraft." - Homer Simpson
Kenneth Herron Kenneth.Herron at mci.com v658-5894 916-569-5894
More information about the vox-tech
mailing list