procmail
[Top] [All Lists]

dealing with mailing lists

1995-10-02 17:48:29
This post isn't directly relevant to Richard's request, but
this is as good a time as any to get it off my chest.

Read on only if you're really really interested in managing
a whole bunch of mailing lists.  The downside of my approach
is that it's very very complicated, probably unnecessarily
so; the upside is that when i subscribe to a new mailing
list all i need to do is add its name to my .procmailrc.

Is it better to spend a couple hours putting together a
189-line four-program system for that kind of convenience?

     68 /home2/mengwong/.procmailrc-lists
     54 /home2/mengwong/.procmailrc-sed
     25 /usr/local/bin/readlists
     42 /usr/local/bin/listsum
    189 total

Or is it better to deal with each mailing list individually
in a separate recipe?  You be the judge.  Feedback welcome.

cheers
Meng Weng Wong
mengwong(_at_)pobox(_dot_)com

the original message:
| 
| I'm a very unsophisticated (compared to some on this list) user of procmail
| and mailstat. Thankyou Stephen. I monitor some mailing lists and so my
| .procmailrc file with logging which looks something like
| 
|   :0:
|   * ^Sender: list1
|   | formailmunge >> $MAILDIR/list1
|   ...
|   :0:
|   * ^Sender: listn
|   | formailmunge >> $MAILDIR/listn
| 
| formailmunge = usage of formail to strip out most of the headers
| 
| I have a cron job each day which invokes mailstat to tell me 
|   xxxxx yy  formailmunge >> $MAILDIR/list1
|   ...
|   xxxxx yy  formailmunge >> $MAILDIR/listn
| ie. how many messages received for each list.
| 
| Now the procmailrc cries out to be written
| 
|   :0:
|   * ^Sender: \/(list1|...|listn)
|   | formailmunge >> $MAILDIR/$MATCH
| 
| which means the mailstat job becomes less informative. So-ooo...
| 
| option 1 - leave things as they stand
| 
| option 2 - do something like 
|   :0
|   * ^Sender: \/(list1|...|listn)
|   {
|   LOG="filed in $MATCH"
|   | formailmunge >> $MAILDIR/$MATCH
|   }
|   and hack mailstat to pick up the "filed..." records in the log file
|   QUESTION - how do I insert a carriage return in the LOG variable
| 
| option 3 - ... well that's why I'm posting! ... any suggestions
|   
| I know, I know. Option 1 is just fine so why fix it? Well, I'm just
| tinkering and it's my way of understanding more about the plethora of
| ways of using unix boxes.
| 
|  Thanks for any advice, Richard.
| -- 
| %% Richard Brankin, NAG Ltd.  richard(_at_)nag(_dot_)co(_dot_)uk / 
na(_dot_)brankin(_at_)na-net(_dot_)ornl(_dot_)gov %%
| 

my solution is to call .procmailrc-lists after defining
LISTS in .procmailrc:

# ----------------------------------------------------------
#               mailing list initialization
# ----------------------------------------------------------

# mailing lists to which i'm subscribed.  no leading whitespace allowed.
LISTS = "\
interesting-people|\
procmail-announce|\
majordomo-workers|\
announce_stuchap|\
majordomo-users|\
8lgm-advisories|\
internet-index|\
domain-policy|\
list-managers|\
fors-announce|\
namedroppers|\
nic-registry|\
scout-report|\
fors-discuss|\
yellowpages|\
0xdeadbeef|\
pobox-user|\
edisonserv|\
edisonhelp|\
computing|\
new-httpd|\
cix-news|\
fv-users|\
netstuff|\
com-priv|\
procmail|\
sandbox|\
futurec|\
bugtraq|\
edupage|\
english|\
rs-info|\
vpcomp|\
irvc-l|\
stwing|\
chaos|\
ietf|\
swip|\
rre|\
vp|\
ad"

followed by

# ----------------------------------------------------------
#                       include rc's
#                     ----------------
# 
# /home/mengwong/.procmail-lists
#    save mailing lists to ~/Mail/Lists/listname
# ----------------------------------------------------------

INCLUDERC=/home/mengwong/.procmailrc-lists

which calls .procmailrc-lists:

# ----------------------------------------------------------
#                      mailing lists
# 
#             /home/mengwong/.procmailrc-lists
# called by anyone who wants to deal with lists
# 
# messages go to the ~/Mail/Lists directory
# to be read using /usr/local/bin/readlists or this sh script:
#       for i in ~/Mail/Lists/*; do elm -zf $i; done
# note that this will Do The Wrong Thing with lists whose
# real names start with [^a-zA-Z] due to the nature of the
# ^TO expression.
# 
# EXTERNAL VARIABLES
#     MAILDIR should be $HOME/Mail
#     LISTS   should look like "edupage|bugtraq|blahblah"
# ----------------------------------------------------------

:0
* $ ^TO\\/($LISTS)@
* ! $ ^TO$LOGNAME@
{
   MAILDIR=Lists

   # just in case the To: line contains lists to which I'm
   # multiply subscribed, we'll check the Sender: line to
   # see which mailbox this message gets to go to.  also, we
   # have to beware of shellmetas.

   OLDMATCH     = $MATCH
   SENDER       = `formail -zx Sender:`
   :0
   * SENDER ?? [^A-Za-z0-9]?\/[A-Za-z0-9_-]+@
   {
        SENDER = $MATCH

        # clean out shell metacharacters for the echo statement later
        SED_ALPHA    = "&|<>~;?*'["
        SED_BETA     = ""
        SED_RIGHT    = $SENDER
        SED_CONTINUE = "1"
        SED_RCFILE   = "/home/mengwong/.procmailrc-sed"
        INCLUDERC    = $SED_RCFILE
        SENDER       = $SED_RIGHT

        MATCH        = $OLDMATCH

        :0
        * $ SENDER ?? (owner-)?($LISTS)(-owner)?
        {
        MATCH=`echo $SENDER|sed -e 's/-owner.*//; s/.*owner-//; s/@.*/@/;'`
        }
   }

   # in any case, MATCH now contains "listname@".  sed to
   # lowercase, wipe out / and @ symbols ...

   MATCH=`echo $MATCH | sed -e 
'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/; s/@//; s/\///;'`

   :0w:              # undigestify digests
   * ^TO.*digest
   | formail -ds >> $MATCH

   :0:
   $MATCH
}


.procmailrc-sed is called by .procmailrc-lists.

############################################################
#                     .procmailrc-sed
#                           v.02
#                      Meng Weng Wong
#                    mengwong(_at_)pobox(_dot_)com
#               Sat Aug  5 00:10:16 EDT 1995
#
# ACTION: given SED_RIGHT, replaces a character class SED_ALPHA
#         with a string SED_BETA by calling itself recursively.
# 
# USAGE:  define the following (these are just example values)
#          SED_RIGHT    = "a 'line' <with> [[some]] ||special|| &char;acters."
#          SED_ALPHA    = "]&|<~;?*'!|["
#          SED_BETA     = ""
#          SED_CONTINUE = "1"
#          SED_RCFILE   = "$HOME/.procmailrc-sed"
#         and run
#          INCLUDERC=$SED_RCFILE
#
# RAISON D'ETRE: remove shell metacharacters from possibly
#                tainted input before passing to shell.
#
# INSTALLATION: save this file in your home directory as .procmailrc-sed.
#
# AVAILABILITY: http://icg.pobox.com/procmail/procmailrc-sed
#
# $Id: .procmailrc-sed,v 1.1 1995/08/04 09:05:16 mengwong Exp mengwong $
############################################################

:0            # grab everything to the left of SED_ALPHA
* $ SED_RIGHT ?? ^\\/([^$SED_ALPHA]+)?
{ SED_LEFT = $MATCH }

:0            # grab everything to the right of SED_ALPHA
* $ SED_RIGHT ?? ^([^$SED_ALPHA]+)?[$SED_ALPHA]\\/.*\$
{ SED_RIGHT = $MATCH }

SED_OUTPUT = "$SED_OUTPUT$SED_LEFT"

:0 E          # SED_ALPHA not found in SED_RIGHT, done ...
{ 
        SED_CONTINUE = "0"
        SED_COMMENT  = "done.  output is $SED_OUTPUT"
        SED_RIGHT    = $SED_OUTPUT
        SED_OUTPUT   = ""
}

:0           # we've got more SED_ALPHAs to go ...
* SED_CONTINUE ?? 1
{
        SED_OUTPUT = "$SED_OUTPUT$SED_BETA"
        SED_COMMENT = "repeat with SED_RIGHT = $SED_RIGHT"
        INCLUDERC = $SED_RCFILE
}


i read my lists using readlists, a perl script:

#!/usr/bin/perl

############################################################
#                        readlists
# read mailing lists in ~/Mail/Lists/*
############################################################

$listdir = "$ENV{'HOME'}/Mail/Lists";

if (@ARGV) {
    foreach $listname (@ARGV) {
        system("elm","-f","$listdir/$listname");
    }
    exit;
}

system("clear");
require "/usr/local/bin/listsum";
sleep 1;

foreach $folder (<~/Mail/Lists/*>) {
    system("elm -zf $folder");
    print STDERR "^C now to quit.\n";
    sleep 1;
}


and i summarize my lists using listsum:

#!/usr/bin/perl

############################################################
#                         listsum
#                      Meng Weng Wong
#               Fri Sep  1 15:04:16 EDT 1995
# $Id$
# summary of mailing lists in ~/Mail/Lists
############################################################

for (<~/Mail/Lists/*>) {
    ($filename) = /([^\/]+)$/;
    $bytes = -s $_;
    open (IN, $_);
    while (! eof(IN)) {
        $_ = <IN>;
        $froms++ if (/^From /);
        $lines++;
    }
    close (IN);
    write;
    $total_filename ++;
    $total_bytes    += $bytes;  $bytes = 0;
    $total_lines    += $lines;  $lines = 0;
    $total_froms    += $froms;  $froms = 0;
}

$filename = "Total: $total_filename folders";
$bytes    = $total_bytes;
$lines    = $total_lines;
$froms    = $total_froms;
write;

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  @#######     @####  @##########
$filename, $froms, $lines, $bytes
.

format STDOUT_TOP =
list name                            messages     lines        bytes
-----------------------------------  --------     -----  -----------
.

the output of listsum looks like:

list name                            messages     lines        bytes
-----------------------------------  --------     -----  -----------
0xdeadbeef                                  8      1081        53194
big-linux                                 198      6615       265780
bugtraq                                    25      1810       103180
com-priv                                  100      5999       284092
comp.risks                                 30      1163        52348
computing                                  16       892        38075
cronjobs                                   22      3698       163421
edisonhelp                                  1        54         2202
edisonserv                                  4       377        18427
edupage                                     3       779        43235
english                                     7       283        13810
fors-discuss                               14       807        40828
fv-users                                   48      3709       179822
happymail-receipt                          54      1895        92638
harrypurchase                               2        56         2228
idiots                                      2        48         2240
ietf-announce-request                      30      3136       127237
interesting-people                         36      3860       180800
irvc-l                                      6       741        33207
list-managers                              35      1593        82214
majordomo-users                            31      3096       130319
majordomo-workers                          13       737        37092
mkhome                                     52       855        48186
namedroppers                               32      1705        85915
netstuff                                    3       198        10221
new-httpd                                   2       101         4313
payment.to                                  4       146         6845
pobox-killed-processes                     16       259        11732
procmail                                    1        85         3220
returnedmail                              457     11079      7561660
rre                                        15      3056       138010
rs-info                                    14      1184        53366
sandbox                                     4       261        12092
scout-report                                1       370        15797
sltnew                                      5       124         4306
stwing                                      2       120         4202
swip                                       24      1065        47936
tcpwrap                                    63       717        35487
to-pobox                                  193      8771       387694
verify.bad                                  6       337        13960
Total: 41 folders                        1588     17307     10413394

and incidentally, my mailstat output looks just fine:

  Total  Number Folder
  -----  ------ ------
  15731       7  echo "$RCPT$FROM" >> Pobox/user-unknown.at-pobox.log
  20646       1  formail -ds >> $MATCH
 142828      41 /usr/spool/mail/mengwong
  20743       5 0xdeadbeef
   9925       2 Lists/cronjobs
  27144      16 Lists/happymail-receipt
    896       1 Lists/idiots
   4922       6 Lists/mkhome
   4314       6 Lists/pobox-killed-processes
6297362      19 Lists/returnedmail
   1620       3 Lists/tcpwrap
  13580       8 Lists/to-pobox
  26368      11 Pobox/verify.from
   9426       3 Pobox/verify.to
   4510       1 bugtraq
   8526       3 club-singapore
   1961       1 com-priv
   1643       1 computing
   3368       1 edisonserv
  40828      14 fors-discuss
   2465       1 fv-users
  14709       3 ietf-announce-request
   5603       3 list-managers
   4758       2 majordomo-workers

<Prev in Thread] Current Thread [Next in Thread>
  • dealing with mailing lists, Meng Weng Wong <=