procmail
[Top] [All Lists]

Re: sorting from IMAP folders

2000-07-05 08:43:27
Jason followed up.

| Thanks for the insight on trying to solve my problem. I thought about doing 
| what you suggested.

You're very welcome.

| Would I use formail to save all the messages (I guess I'll use received 
| date) into separate files and then just dump them back into my system 
| mailbox.

Yes, formail's -s option splits the input into individual messages and
optionally invokes a named command each of them.  That's what worked for me,
using mboxes.  I have no idea of what to do for IMAP folders, having no
experience with them, and still defer to Bart on that aspect.

| Also, in order to get that date, would I grep/awk/cut each message for it 
| and then feed it to the date command?

It's best if you can extract it with procmail's MATCH facility, because that
saves the work of forking another program.  Exactly where to find it depends
on the format of your stored messages.  I used the time in the From_ line, but
IMAP might not use From_ lines.  Let's see if I can take some of the speciali-
zation out.  One shortcoming is that it may cough on messages that arrived
during the repeated hour in October when we revert to Standard Time, though:

#!/path/to/procmail -pYm

MAILDIR=your_working_directory

:0 # if this process hasn't grabbed the lock, grab the lock
* RCFILE ?? ^^^^
{ LOCKFILE=.sequence$LOCKEXT }

# Two invocations can still run simultaneously if they use different
# working directories.  Yes, I have the working directory hard-coded,
# but I always called this script from the shell prompt and never had
# two of it running at the same time.  Change that if it helps you.

:0Ai # clean up files left in this directory from previous uses
* ? rm -f *
{ }

RCFILE = $_
DEFAULT=|
LOGABSTRACT=on

:0cw # clone procmail
{
 :0fi # reduce clone's text to first remaining message
 | formail -1Yes

 :0D: # translate From_ date to seconds since Unix epoch, use as file name
 * ^^From .* \/(Sun|Mon|Tue|Wed|Thu|Fri|Sat) .+
 `date -d "$MATCH" +%s`

 :0e: # if the date command bombed, store in file named "undated"
 undated
}

:0fw # remove message handled by the clone
| formail +1 -Yes

:0B # if there's a message remaining, recurse and reuse this rcfile
* .
{ SWITCHRC = $_ } # use INCLUDERC if your procmail doesn't grok SWITCHRC
:0E # otherwise shut off stderr and write files in date sequence + "undated"
{ LOGABSTRACT=off`cat *; rm -f *` }


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>