procmail
[Top] [All Lists]

Re: search for keyword/delete paragraphs

1999-06-17 20:40:54
| First, I would like to forward a copy of e-mails that contain a certain
| keyword within the message body to an alphanumeric pager.  I subscribe to a
| weather warning notification service and wish to forward only messages that
| contain, within the body, the name of my county.

No problem at all.  Use the capital-B flag on the recipe, or if it has other
conditions that must search the head or the entirety, use the B ?? modifier
on the condition that searches for the county name.

This is the current recipe that I wish to improve upon.  It sends ALL weather
warnings in my region to my pager:

:0c
*^From:(_dot_)*weather(_at_)service(_dot_)com
!mypager(_at_)pagercompany(_dot_)net

Is this how I would add/nest the additional condition of checking the body of 
the
message for my county name?

:0c
*^From:(_dot_)*weather(_at_)service(_dot_)com
:0B
*county
!mypager(_at_)pagercompany(_dot_)net


| Second, after identifying such a message, I want to delete from the 
forwarded
| copy any paragraphs that do not begin with an asterisk.  These paragraphs 
are
| the ones containing the pertinent info, and since my pager is limited to
| about 200 characters I need to remove the extraneous stuff.

A lot depends on the specifics; are the paragarphs separated by blank lines?
Is the asterisk at the start of a pargraph flush against the left margin or is
it indented?  Are there other asterisks in the text?

If the asterisks are flush left and there is an empty line between each two
paragraphs,

 :0bfw
 | sed '/^\*/,/^$/!d' # or, sed -n '/^\*/,/^$/p'

The format appears to be that the asterisk is used as the "bullet" character of 
the
paragraph, with all subsequent paragraph text indented.  Perhaps your second 
method
below would be better because of this?  All of the text I want to delete is
consistently ahead of the first occurence of an asterisk.

 :0bfw
 | sed '/\*/,$ !d' # or, sed -n '/\*/,$ p'


So, would my completely modified recipe look like this?

:0c
*^From:(_dot_)*weather(_at_)service(_dot_)com
:0B
*county
:0bfw
 | sed '/\*/,$ !d'
!mypager(_at_)pagercompany(_dot_)net

Unfortunately, I will have to wait for severe weather to see if it works!

Tom