mailing-list demon

Gary Weimer 588-0953 weimer at garden.kodak.COM
Wed Feb 13 08:59:54 AEST 1991


I tried to reply, but my mailer couldn't find the host.

In article <ANDREAS.91Feb12091903 at newsigi.us>, andreas at newsigi.us
(Andreas C. Lemke) writes:
|> Hi,
|> 
|> I would like to create a mailing list with as little administrative
|> effort for myself as possible.  To that end *everybody* should be able
|> to add, update, or remove people from the list, as well as obtain a
|> listing of the current mail addresses on the list.  This should be
|> doable by mail, e.g., if a new person wanted to be added to the alias
|> he/she would simply send a mail-message containing a command such as
|> "add joe at abc.edu" and some sort of demon should carry out the command.
|> 
|> Do you guys know of some software that filters incoming mail messages
|> for commands and executes them?  I'm thinking of something like a perl
|> script to be installed as the alias for mailing-list-request.

I don't know if this will help at all or not. It's not exactly what you
asked for. This is something I wrote to sort my incomming mail. You can
setup a special login id that this can be installed under, or use your
own and require that a specific subject line be used. You'll need to
understand grep and maybe awk to understand what I'm doing in the sort
section of mailsort.csh. To tell the mail server to use mailsort.csh, I
had to create a .forward file in my home directory (I'm using Unix,
specifically SunOS):

-------------- .forward file ------------------
"|/u/users1/weimer/bin/mailsort.csh weimer ~/MAIL"
-------------- end .forward file ------------------

The mailsort.csh program follows. If you would like more explanation,
write back and ask (My .sig has a mail address which should work).

------------ mailsort.csh file ------------------
#!/bin/csh -fb

# login id of person using this script
# environment vars take precidence over defaults
if (!($?USER)) set USER=weimer

# mail directory of person using this script
# environment vars take precidence over defaults
#    NOTE: USER will not be set when prog called by mail daemon
if (!($?MAILDIR)) then
  if (-e ~$USER/MAIL) then
    set MAILDIR=~$USER/MAIL
  else
    set MAILDIR=~$USER/mail
  endif
endif

###################################################################
# NOTE: mail message will be saved in the file $MSG,
#       the mail header only will be saved in the file $HEADER
#       the mail body only will be saved in the file $BODY
###################################################################

# mail header lines to skip when saving message
#    $MSG will still have these, $HEADER will not
set HDRSKIP='$1=="Received:" || $1=="id" || $1=="Message-Id:"'
#set HDRSKIP=""

# arguments take precidence over defaults and environmen vars
#    NOTE: this is not important part of code logic (you can skip it)
set PARAMS=($*)
if ($#PARAMS > 1) then
  set USER=$PARAMS[1]
  set MAILDIR=$PARAMS[2]
  set TMP=`echo $MAILDIR|awk '{print index($1,"//")}'`
  if ($TMP == 1) set MAILDIR=~$USER`echo $MAILDIR|awk '{print substr($1,2)}'`
else if ("$PARAMS" != "") then
  set $USER=$PARAMS
  if (-e ~$USER/MAIL) then
    set MAILDIR=~$USER/MAIL
  else
    set MAILDIR=~$USER/mail
  endif
endif

#######################################################################
#
# generic setup stuff
#
#######################################################################
# date in case I want it for file names
set DATE    = `date +"%y-%m-%d"`

# awk script for separating mail header from mail body
set PARSER=('{if (b) {print $0>>bf;next}};{if (NF==0) {b=1;next}};{if
(""'$HDRSKIP'){next}};{print $0>>hf};END{print>>bf;print>>hf}')

# files for msg, header, & body
set MSG="/tmp/$USER.mail.$$"
set HEADER=$MSG.head
set BODY=$MSG.body
/bin/rm -f $HEADER $BODY $MSG    # just in case we've found a duplicate name...

# our mail server uses /usr/spool/mail, other machines mount this in /var
if (-e /usr/spool/mail) then
  set MAILBOX=/usr/spool/mail/$USER
else
  set MAILBOX=/var/spool/mail/$USER
endif

# stdin is the mail message being sent, put it in $MSG
cat > $MSG
# separate header and body
awk "$PARSER" hf=$HEADER bf=$BODY $MSG

while (1)	#we really only go through loop once
                # this allows us to use break instead of goto

#######################################################################
#
# BEGIN SORTING
#
#######################################################################

#######################################################################
# if you do not want a message to be sent to yourself, and you do not
# want it to match any other conditions, 'break' after sending message--
# DO NOT 'exit'--temporary files will not get removed
#######################################################################
# when concatinating to a mailbox, you should always add a blank line
# to the end of what you are concatinating (hence all the 'echo ""'s
# below)
#######################################################################

#
# extra stuff just for me :-)
#
# intro to prepend to forwarded msg's (stating this has been auto-forwarded)
set AUTOHDR=$MAILDIR/auto.header
# flag for who a copy was sent to (put at end my copy of files auto-forwarded)
set COPYHDR=$MAILDIR/copy.header

#
# template
#
#set SUBJECT=`grep '^Subject:.<subj to check for>' $HEADER`
#set TO=`grep '^To:.<id you expect forwarded mail from>' $HEADER`
#set OTHER=`grep '<text to look for in body of msg>' $BODY`
#if ("$<SUBJECT, TO, or OTHER>" != "") then # we found a match
#    # do any other calculations/parsing here
#
#    # save to a file
#    (cat $<MSG, HEADER, and/or BODY>; echo "") >> $MAILDIR/<file>
#    # put in your own mailbox (as if we never did this script)
#    (cat $MSG; echo "") >> $MAILBOX
#    # forward to someone else
#    cat $<MSG, HEADER, and/or BODY> | /usr/ucb/Mail -s "<subject>" <userid>
#
#    # run any programs, edit files, etc. that you want to here
#    break
#endif


#
# Budtool Report
#
#    simply write $MSG to appropriate file
#
set SUBJECT=`grep '^Subject:.Budtool.Report$' $HEADER`
if ("$SUBJECT" != "") then
    # body of msg has machine name on line starting with 'rsh'
    set MACH=`grep '^rsh' $BODY | awk '{print $2; exit}'`
    # write mail to file
    (cat $MSG; echo "") >> $MAILDIR/backups/$MACH/$DATE
    break
endif

#
# warehouse submissions -- cc: edj
#
set SUBJECT=`grep '^Subject:.wh.submission$' $HEADER`
if ("$SUBJECT" != "") then
    (cat $AUTOHDR $HEADER $BODY) | /usr/ucb/Mail -s "wh submission" edj
    (cat $MSG $COPYHDR;echo "edj";echo "") >> $MAILBOX
    break
endif

#
# test (see if any of this works...)
#
#set SUBJECT=`grep '^Subject:.test$' $HEADER`
#if ("$SUBJECT" != "" ) then
#    (cat $HEADER; echo "test successful"; echo "") >> $MAILBOX
#    break
#endif

#######################################################################
#
# No matches--Put in mailbox
#
#######################################################################

cat $MSG >> $MAILBOX
echo "" >> $MAILBOX
break  #don't repeat while loop
end
/bin/rm -f $HEADER $BODY $MSG
exit
------------ end mailsort.csh file ------------------

weimer at ssd.kodak.com ( Gary Weimer )



More information about the Comp.unix.wizards mailing list