Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uhccux!munnari.oz.au!comp.vuw.ac.nz!root From: asjl@comp.vuw.ac.nz (Andy Linton) Newsgroups: comp.mail.sendmail Subject: Re: error handling on mail lists Message-ID: <1989Sep13.012342.20092@comp.vuw.ac.nz> Date: 13 Sep 89 01:23:42 GMT References: <6872@cs.utexas.edu> Reply-To: asjl@cantina.comp.vuw.ac.nz (Andy Linton) Organization: Dept of Comp Sci, Victoria University of Wellington, NZ. Lines: 212 In article <6872@cs.utexas.edu> fletcher@cs.utexas.edu (Fletcher Mattox) writes: >Unless I'm mis-reading the code, it looks to me like the >"owner-" error hack doesn't work when mail to a list of >all local users arrives via SMTP and one of those users >doesn't exist. I use the following to ensure that errors in mail to lists get back to the person who looks after the list locally. This should also work if any of the list expansions go to a non-sendmail host (yes there are some (:-)) since it relies on the Sender: field to return the error a la RFC822 and not on the sendmail hack. -- #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'distribute.c' <<'END_OF_FILE' X/* X * Distribute changes headers of messages to mailing lists so that there is a X * Sender: field for errors in the list etc and a Reply-To: field for errors X * in mailer design. (:-) X * X * It requires the following sort of set up in /usr/lib/aliases:- X * X * listname:"|/usr/local/lib/mail/distribute listname" X * listname-request:asjl@comp.vuw.ac.nz X * listname-xxx::include:/usr/local/lib/aliaslists/listname X * X * The user addresses mail to "listname", "listname-request" is the person X * responsible for the list and "listname-xxx" is a pointer to the list to X * expand for delivery. X * X * All this should be transparent to the user. X * X * $State: Exp $ X * X * $Log: distribute.c,v $ X * Revision 1.3 89/08/31 09:37:16 asjl X * Modified for use at VUW X * X * Revision 1.1 89/08/31 09:34:27 asjl X * Initial revision X * X * Revision 1.2 89/07/27 14:44:58 crr X * Fix non checking of temp file write failure (bug). X * Use temp file in /var/tmp not /tmp to avoid dump removing it. X * X * Revision 1.1 89/05/26 12:21:52 asjl X * Initial revision X * X * Revision 1.2 89/03/22 10:36:09 root X * Added RCS Keywords X * Reduced number of parameters to one. X * Added check on return code of 'system (cmdstring)' call. X * X */ X X X#include X#include X#include X#include X#include X X#define BUF_LINE 500 /* line length buffer */ X#define TRUE 1 /* return(...) codes */ X#define FALSE 0 X#define NULLP(x) ((x*)0) X X#define OWNER_SUFFIX "-request@comp.vuw.ac.nz" X#define DLIST_SUFFIX "-xxx" X Xchar tempfile[] = "/usr/tmp/distrib.XXXXXX"; X X/* X * M A I N P R O G R A M X */ X Xmain (argc, argv) Xint argc; Xchar *argv[]; X{ X register int processing_header, X add_reply_to, X temp_fd; X FILE *new_message; X char *inp, X *outp, X inbuf[BUF_LINE], X reply_tobuf[BUF_LINE], X cmdstring[BUF_LINE]; X X processing_header = TRUE; X add_reply_to = FALSE; X X if ((new_message = fopen (mktemp (tempfile), "w+")) == NULLP(FILE)) X { X exit (EX_CANTCREAT); X } X X while (fgets (inbuf, BUF_LINE, stdin) != NULLP(char)) X { X if (processing_header) X { X if (strncmp (inbuf, "From ", sizeof ("From ") - 1) == 0) X { X /* Discard it */ X continue; X } X if (strncmp (inbuf, "Acknowledge-To: ", X sizeof ("Acknowledge-To: ") - 1) == 0) X { X /* Discard it */ X continue; X } X if (strncmp (inbuf, "Return-Receipt-To: ", X sizeof ("Return-Receipt-To: ") - 1) == 0) X { X /* Discard it */ X continue; X } X if (strncmp (inbuf, "Sender: ", sizeof ("Sender: ") - 1) == 0) X { X fprintf (new_message, "Original-Sender%s", X index (inbuf, ':')); X continue; X } X if (strncmp (inbuf, "Via: ", sizeof ("Via: ") - 1) == 0) X { X fprintf (new_message, "Original-Via%s", index (inbuf, ':')); X continue; X } X if (strncmp (inbuf, "From: ", sizeof ("From: ") - 1) == 0) X { X sprintf (reply_tobuf, "Reply-To%s", index (inbuf, ':')); X add_reply_to = TRUE; X } X if (strncmp (inbuf, "Reply-To: ", sizeof ("Reply-To: ") - 1) == 0) X { X add_reply_to = FALSE; X } X if (strcmp (inbuf, "\n") == 0) X { X fprintf (new_message, "Sender: %s%s\n", argv[1], OWNER_SUFFIX); X if (add_reply_to) X { X if (fputs (reply_tobuf, new_message) == EOF) X { X fclose (new_message); X exit (EX_IOERR); X } X } X processing_header = FALSE; X } X if (fputs (inbuf, new_message) == EOF) X { X fclose (new_message); X exit (EX_IOERR); X } X } X else X { X if (fputs (inbuf, new_message) == EOF) X { X fclose (new_message); X exit (EX_IOERR); X } X } X X } X if ( ferror(new_message) ){ X fclose (new_message); X exit (EX_IOERR); X } X fclose (new_message); X sprintf (cmdstring, "/usr/lib/sendmail -ba -f%s%s %s%s < %s", X argv[1], OWNER_SUFFIX, argv[1], DLIST_SUFFIX, tempfile); X /* Now send the mail as 'daemon' */ X setuid (geteuid ()); X if (system (cmdstring) == 127) /* Couldn't invoke the shell */ X { X X unlink (tempfile); X exit (EX_SOFTWARE); X } X X unlink (tempfile); X exit (EX_OK); X} END_OF_FILE if test 4006 -ne `wc -c <'distribute.c'`; then echo shar: \"'distribute.c'\" unpacked with wrong size! fi # end of 'distribute.c' fi echo shar: End of shell archive. exit 0 -- EMAIL = asjl@comp.vuw.ac.nz FAX = +64 4 712 070 PHONE = +64 4 721 000 x8978 SNAIL = Computer Science Dept, Victoria University, Wellington, NEW ZEALAND