procmail
[Top] [All Lists]

Re: automated archive filenames

1996-03-24 03:20:30
From dattier(_at_)wwa(_dot_)com  Sun Jan 21 20:45:07 1996
From: dattier(_at_)wwa(_dot_)com (David W. Tamkin)
Subject: Re: automated archive filenames
To: dman(_at_)netcom(_dot_)com (Dallman Ross)
Date: Sun, 21 Jan 1996 22:45:29 -0600 (CST)
Cc: procmail(_at_)Informatik(_dot_)RWTH-Aachen(_dot_)DE


Believe it or not, I only just yesterday finally had time to read and
digest your reply to me of 2 months ago:


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.


I have now updated my recipe, and it seems to be working fine.  Thank
you very much for the input, David.  Here is what I have now:


 # 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|hal|hartland|higa| \
            jamieson|jcook|jesse(_at_)spine|jgraf|jprusky|jraphael|kael| \
            kenji|lbegeman|louie|ltw|luke|margery|miriam| \
            mjsilva|mnementh|santra|seligman|southern|speacock| \
            schwim|teddybur|tgl|tittle|vidgames|zconcept|torin| \
            tsalagi|tweek|vjl|wb8foz|wotan)
* ! ^TO(cabal|infopro|procmail)
{
    :0 w
    | gzip -fc >> $MATCH.gz
}


Couple of questions remain.  Any reason not to delete the assigning of
$MATCH to another name?  Up above I assigned $ARCNAME to the value of
MATCH.  I decided there was no reason for the extra step here.  Or is it
just good form?

Another question is, suppose I leave more of the address (@whatever)
in on a couple that might otherwise be ambiguous.  See, e.g., "jesse(_at_)spine"
in the above recipe.  Okay, so I get that $MATCH will parse out anything
after the @, inclusive.  But will procmail first match on the full
espression I use?  In other words, suppose "jesse(_at_)wherever(_dot_)com" (not
"spine.com" writes me.  Will this recipe distinguish him before
assigning the value to $MATCH?

I was having trouble before where some mail got saved in my archive
directory and some did not (but did show up in my inbox, courtesy of the
c-flag).  I realized yesterday, when I finally had a chance to look at
this again, that it was because not all incoming email starts with the
username.  That is, mail from "David Tamkin <dattier(_at_)wwa(_dot_)com>" would
not have matched up above.  That is why I now added the ".*" after
"From".  It seems to work.  Don't know if I'm being efficient, though.

David, your help was immensely appreciated, even if I'm 2 months late in
writing my thanks.

 
-- 
  __                               ___               dman(_at_)netcom(_dot_)com 
 (/ \  _   /) /) _ _ _  _    _    (/__) _   _   _    1 (510) 645-1883 
 /`  )(_(_( _(__/|/|/(_(_(_/| (   / (  (_)_/_)_/_)_  350 Perkins St., #108 
(___/                          ` (   \               Oakland, CA 94610-3422

<Prev in Thread] Current Thread [Next in Thread>
  • Re: automated archive filenames, Dallman Ross <=