procmail
[Top] [All Lists]

Re: questions about ^TO_ and MATCH

1999-12-04 10:51:33
Nancy asked,

M> I'm thinking about adding an @ sign at the end of the condition
M> so it would look like this:
M> 
M>  :0:
M>  * 
^TO_\/(procmail|pine-info|vim|copyediting-l|techwr-l|cygwin|framers|veg-nyc|faq-maintainers|pine-alpha)@
M>  in-l-$MATCH
M> 
M> so that it's more likely that it will actually match on an email
M> address rather than a comment. But I don't really want my file
M> names to end with an @ so I'm wondering what's the best way to
M> truncate the last letter of the $MATCH and does that defeat some
M> of the speed-saving I'm getting by processing all my mailing
M> lists with this one recipe.

In more recent versions of procmail,

   :0:
   * 
^TO_\/(procmail|pine-info|vim|copyediting-l|techwr-l|cygwin|framers|veg-nyc|faq-maintainers|pine-alpha)@
   * MATCH ?? ()\/[^(_at_)]+
   in-l-$MATCH

In older versions, you couldn't match on $MATCH, so you had to save the first
value in another variable as Stan Ryckman illustrated:

R>  :0
R>  * MATCH ?? ()\/[^(_at_)]+
R>  { }
R>  DUMMY = $MATCH
R>  :0
R>  * DUMMY ?? ()\/[^(_at_)]+
R>  { }

However, since we'd care about $DUMMY only if the first condition matched,
I'd nest them or at least link them:

   :0
   * 
^TO_\/(procmail|pine-info|vim|copyediting-l|techwr-l|cygwin|framers|veg-nyc|faq-maintainers|pine-alpha)@
   { DUMMY=$MATCH }
   :0A:
   * DUMMY ?? ()\/[^(_at_)]+
   in-l-$MATCH

M> Another problem with the above recipe is that some of the mailing
M> lists use ALL CAPS, ...

Stan answered that,

R> That was very recently posted here; I'd like to give credit but
R> unfortunately I've deleted my copy.  It was something like:
    # where VAR contains the mixed-case string
    :0D
    * VAR ?? [A-Z]
    { VAR=` (something which properly invokes tr goes here) ` }
R> This only runs the tr process when there is an upper case character
R> needing conversion to lower case.

The credit is mine, thanks, and the backquoted command was

    VAR=`echo "$VAR" | tr [A-Z] [a-z]`

Ruud also commented,

vT> If you have a limited number of 'down-casings',
vT> you better use the same 'trick'
vT> that one uses to translate numbers into monthnames or vv.

I'm not sure what "vv" is/are, but I'm also guilty of that trick.  It is
not always practical, as sometimes the variety of text to downcase is too
great, but in a case like this, it works well, and I use it myself:

  listnames="framers%framers!techwr-l%techwr!copyediting-l%copyediting"

  :0:
  * $ listnames ?? ()$LISTNAME%\/[^!]+
  $MATCH

Because the matching is case-insensitive but the extraction is case-sensitive,
all varieties of casing "framers" will be saved to $MAILDIR/framers.  I use
this technique myself where subscribers post to an assortment of casings or
where the list canonicalizes it but the listowner's choice includes some an-
noying gratuitous capitals.

So to combine them,

   :0
   * 
^TO_\/(procmail|pine-info|vim|copyediting-l|techwr-l|cygwin|framers|veg-nyc|faq-maintainers|pine-alpha)@
   * MATCH ?? ()\/[^(_at_)]+
   { 
    LISTNAME=$MATCH

    listnames="framers%framers!techwr-l%techwr!copyediting-l%copyediting"

    :0:
    * $ listnames ?? ()$LISTNAME%\/[^!]+
    $MATCH
    :0E:
    $LISTNAME
   }

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