l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2004 Sep 29 12:44

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] program to move message from inbox to folder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] program to move message from inbox to folder



--On Wednesday, September 29, 2004 11:29:16 -0700 Charles McLaughlin <cmclaughlin@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@mci.com v658-5894 916-569-5894
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.