procmail
[Top] [All Lists]

Re: save message on autoreply

1996-05-12 23:27:59
Steven J Lewis <nepolon(_at_)gladstone(_dot_)uoregon(_dot_)edu> writes:
OK, so I have a question.  I want to attempt to match a from with a 
variable and a subject:

      # Found attachment submited by $Person1
      * ^From.*$Person1
      * ^Subject.*submiting.attachment
      { 
         # do something in here
      }

Try the following ("submitted" and "submitting" have two 't's, don't
forget the ":0" to start the recipe, and variables are expanded in
condition lines only if the leading '$' 'condition flag' is used):

# Found attachment submitted by $Person1
:0
* $ ^From.*$Person1
*   ^Subject:.*submitting.attachment
{
    # whatever...
}



where would I define these variables if I want them always available to 
me in the shell (I use csh) so I can, for instance:

      mail $Person1 < person1.attachment

and I would REALLY like to have it stored in one place, not two or more, so
I can easily change the definition of $Person1.  This is more of a shell 
question but I guess I am asking if putting this info in my .cshrc will 
carry into procmail processing or not or if there is some other way to 
achieve this.


Well, this is ugly, but...

Put all the variable definitions to be shared in a separate file in
procmail format:

Person1 = someone
Another = some value

Use the INCLUDERC procmail 'directive' to get these into procmail.
Then in your .cshrc put the following:

eval `sed -n "/^#/d\
/=/{\
s:^[    ]*:setenv :\
s:[     ]*=[    ]: ':\
s:[     ]*"\$":':\
p\
}" .name-of-the-file-with-the-vars`


Each of the square brackets contains a space and a tab.  You *might*
need two more backwhacks in front of each one there because of the
eval.  I'm not sure, and it's too late at night to check.  %$*(&%#( csh
quoting rules...

What this does is a) ignore lines beginning with a hash; and b) replace
all remaining lines that contain an equal sign, changing

   foo   =    bar baz quux

to

setenv foo 'bar baz quux'


All leading and trailing whitespace is removed from the value of each
variable, but internal whitespace is preserved (by the single quotes).
If you want to put literal single quotes in variables, add the line:

s:':'\'':g\

after the "setenv" line.  That might need another half-dozen '\'s, of
course...

Some versions of sed allow you to separate internal commands with ';'s,
as well as newlines.  This would make the above much nicer, as then you
could put it on one long line:

eval `sed -n '/^#/d;/=/{........`


You could also do this in perl or awk, but my brain hurts after
fighting with csh's broken quoting rules, so...


Philip Guenther

----------------------------------------------------------------
Philip Guenther                 UNIX Systems and Network Administrator
Internet: guenther(_at_)gac(_dot_)edu   Voicenet: (507) 933-7596
Gustavus Adolphus College       St. Peter, MN 56082-1498
Source code never lies (it just misleads).  (Programming by Purloined Letter?)

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