procmail
[Top] [All Lists]

Re: How to parse and resent info embeeded in an email

2001-07-25 07:28:14
On 25 Jul, Errol Casey wrote:
| I'm interested in parsing out some summary weather info,
| and then put it into a "subject" line to be emailed.
| 
| 
| WEATHER-----------
| TODAY:
|   High 88F; Low 72F. Humid; breezy later.
|   Ozone -
| TOMORROW:
|   High 87F; Low 70F. A few t-storms and humid.
| 
| Is the sample text. I've pulled subjects out of emails, etc
| with formail -- but this is the first time I want to pull something
| out of a body, and then resend it as a subject in an email
| 
| i.e. get weather info, put into a one line string, send email with subject of 
parsed info.
| 

Here's a possible start:

:0
* ^From: Errol Casey
* B ?? TODAY:[  ]*\>[   ]*\/High\>.*Low.*
{
   :0 fhw
   | formail -I "Subject: $MATCH"
   :0:
   $TESTDIR/ztestmbox   # $TESTDIR is *my* variable
}

Running your message through this filter delivered it exactly as sent
(headers and body), except:

$ diff testmsg ztestmbox 
48d47
< Subject: How to parse and resent info embeeded in an email
77a77
Subject: High 88F; Low 72F. Humid; breezy later.

Obviously, the first From: condition would need to be changed to
something suitable. This serves two purposes -- lessen the risk of
filtering the wrong messages, and preempt unnecessary body searches in
the next condition.  And the final action needs to be whatever suits
your needs. If you're intending to strip or otherwise munge the body,
or want to include the string "TODAY:", or want tomorrow's weather, etc.
there's more work left as an exercise.

[While doing this, Matt already got back with one. I offer this anyway
because it's pure procmail.]

-- 
                   /"\
Don Hammond        \ /     ASCII Ribbon Campaign
Raleigh, NC US      X        Against HTML Mail,
                   / \      and News Too

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