procmail
[Top] [All Lists]

Re: maintaining list

1998-02-23 09:01:21
Marcus Holmes has a problem with this recipe:

:0cwh
| formail -rtzxTo: | cat - $TMP |
  tr '[A-Z]' '[a-z]' | sort -u >.procaddresses

It's missing a backslash to tell procmail that the action continues on the
next text line of the rcfile; also, transpose tr and cat because all the
addresses already in the file have been lower-cased before and don't need to
be run through tr:

  :0cwh
  | formail -rtzxTo: | tr '[A-Z]' '[a-z]' | \
    cat - $TMP | sort -u >.procaddresses

I still think there are better ways to do this, especially since sort can
sort in place with no user-maintained temporary files.

  :0h
  returnaddress=| formail -rtzxTo:

  :0D # tr only if needed
  * returnaddress ?? [A-Z]
  { returnaddress=`echo "$returnaddress" | tr '[A-Z]' '[a-z]'` }

  LOCKFILE=.procaddresses.lock # will be needed during condition as well 
                               # as during action

  :0ic # if address is not already in file, add it and sort
  * ! ? fgrep -x "$returnaddress" .procaddresses
  | echo "$returnaddress" >> .procaddresses ; \
    sort -o .procaddresses .procaddresses # -u is superfluous

  LOCKFILE

Another consideration is that, if fgrepping prevents duplicate entries, does
the file need to be sorted at all?  If not,

  :0h
  returnaddress=| formail -rtzxTo:

  :0D # tr only if needed
  * returnaddress ?? [A-Z]
  { returnaddress=`echo "$returnaddress" | tr '[A-Z]' '[a-z]'` }

  LOCKFILE=.procaddresses.lock # will be needed during condition as well 
                               # as during action

  :0ic # if address is not already in file, add it
  * ! ? fgrep -x "$returnaddress" .procaddresses
  | echo "$returnaddress" >> .procaddresses

  LOCKFILE

And even if you still want it sorted, you can still leave the sorting out of
.procmailrc and have a cron job sort it every so often (the most recently
added addresses would still be unsorted at the end between cron jobs, but
that makes them easier to find if you want to know who has just been added)
instead of running sort with every incoming letter that fails the fgrep. 
Cron can call a script that looks like this:

 #!/bin/sh
 # cron's default PATH should find rm and sort, but maybe not lockfile

 cd <yourmaildir>
 trap 'rm -f .procaddresses.lock' 0 1 2 3 15
 /path/to/lockfile .procaddresses.lock # same name that .procmailrc uses

 sort -o .procaddresses .procaddresses # add -u if it makes you feel better

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