procmail
[Top] [All Lists]

Re: automated archive filenames

1996-01-21 21:48:49
Dallman Ross has this:

| ## FRIENDS
| ##
| MAILDIR=$HOME/Mail/archive  # change directories
| 
|  # Following recipe stores each writer's files under his or
|  # her respective email name before any "@" sign.
| 
| :0 wc  # c-flag replicates a copy for fall-through to my inbox
| * ^From: \/(afob|alerman|andrys|brenner|brettf|carrollt| \
|             cnorloff|dattier|davidg|elisa|fox|hartland|higa| \
|             jamieson|jcook|jesse(_at_)spine|jgraf|jraphael|kael| \
|             kenji|lbegeman|louie|ltw|luke|margery|miriam(_at_)spi| \
|             mjsilva|mnementh|santra|seligman|southern|speacock| \
|             schwim|teddybur|tgl|tittle|vidgames|zconcept|torin| \
|             tsalagi|tweek|vjl|wb8foz)
| * ! ^TO(cabal|infopro)
| {
|     ARCNAME=`echo "$MATCH" | sed 's/@.*//'`

| But I'm convinced there would be a better way to cut off the remainder of
| each emailer's address than the sed kludge I devised.

Indeed there is.

You're calling a shell and sed for nothing, since there will be no @-sign in
$MATCH.  It's not as if you had ".*" at the end of the condition line that
sets MATCH and saved the rest of the line in it; MATCH saves only that which
matches the right side of the expression in the condition line.

Now, it saves the longest possible right side when there is an ambiguous
match (for example, a trailing ".*" to the right of "\/" would work the same
as a trailing ".*$") but you have no ambiguities of that sort.  So you can
just set

     ARCNAME=$MATCH

If $MATCH possibly *could* contain an @-sign, you could strip the rest
within procmail (no shell and no sed) anyway:

   ARCNAME=$MATCH

   :0
   * ARCNAME ?? ^^\/[^(_at_)]*
   { ARCNAME=$MATCH }

|     :0 w
|     | gzip -fc >> "${ARCNAME}.gz"
| }

There you're fine, of course.  You don't even need the braces around
$ARCNAME, nor, since it won't contain any shell-special characters, the
quotes either.

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