[wplug] Procmail recipe help
Gentgeen
gentgeen at linuxmail.org
Sun Oct 1 10:04:36 EDT 2006
On Tue, 26 Sep 2006 11:38:44 -0400
"Jonathan S. Billings" <billings at negate.org> wrote:
> WARNING: I believe these examples will work, test it first though. I
> just wrote them off the cuff without testing them first.
>
> On 09/25/2006 06:40 PM, Gentgeen wrote:
> > (1) how do I check for things like "fwd: " or "re: "
>
> * ^Subject: (re:|fwd:|) *$
>
>
> > (2) how could I then add in a subject as noted above.
>
> This can get a little complicated.
>
> You can use procmail's filter with 'formail -i' to add a subject,
> however first you need to extract the information from the message.
>
> Maybe something like this:
> :0:
> * ^Subject: (re:|fwd:|) *$
> {
> # add a new subject. The "rabbit ears" \/ mean
> # put everything after them into $MATCH
>
> :0f
> * ^From: \/.*$
> | formail -i "Subject: From $MATCH"
> }
>
> There are probably a couple other ways of doing this, I can think of
> others too, but I won't bore by being overly pedantic. Grabbing just
> the name, and not the email address would also be complex, and I'll
> leave that to the ingenuity of the reader.
>
Thank you, that really got me rolling. Now I have 1 more question for
anyone who might be able to help me out. I have now come up with the
following (thanks to Billings, and a procmail FAQ at
http://lipas.uwasa.fi/~ts/info/proctips.html)
* 1^0 ^Subject:([ ]$|$) # Blank Subjects
* 1^0 !^Subject: # Missing Subjects
* 1^0 ^Subject: (re:|fwd:|) *$ # Blank fwd/re
{
#Get the subject discarding any leading and trailing blanks
#Note: On some systems -xSubject: has to be -x"Subject: "
SUBJ_=`formail -xSubject: \
| expand | sed -e 's/^[ ]*//g' -e 's/[ ]*$//g'`
# This cuts out the indicated part of the "FROM" field.
# it either does the Name, or the Email address.
SENDER_=`formail -xFrom: \
#name #| cut -f2 -d':' | cut -f1 -d'<' | sed -e 's/"//g' -e 's/ //'`
#email #| cut -f2 -d'<' | cut -f1 -d'>' | sed -e 's/"//g' -e 's/ //'`
# Now reinsert the SENDER and any SUBJECT from above
:0 f
| formail -i "Subject: ${SUBJ_}--NO SUBJECT-- From ${SENDER_}"
}
I used procmail's scoring to combine tests for the same script. (Note
sure
So the first 3 lines check for blank, missing, or blank re/fwd lines in
the Subject field. If any of that exists the the { } will be done.
the SUBJ_= takes any existing subject (in this case an re/fwd) and
stores it in the variable SUBJ_
The SENDER_= takes the either the email or the name from the "From:"
line. It just depends on which one I uncomment. And here is all the
further I can get.
I would like the SENDER_ variable to be something like:
SENDER_ = "name" unless "name" does not exist
then use "email"
If someone could just point me in the right direction, I will be happy
to do the "heavy lifting". I am just stumped at this point. Could it
be done from within the .procmailrc file? Would I have to call an
external script? Can I use:
if [ -f "SENDER_" ]; then
kind of thing in a .procmailrc file?
This originally started out as a simple fix to an issue. Now it has
become an fun little project for me.
Thanks (again) in advance for any help.
--
http://gentgeen.homelinux.org
#############################################################
Associate yourself with men of good quality if you esteem
your own reputation; for 'tis better to be alone then in bad
company. - George Washington, Rules of Civility
More information about the wplug
mailing list