[Mailman-Users] Newlist from a webpage?

Dave Klingler davek at mail.commercedata.com
Sun Dec 24 19:56:51 CET 2000

Happy holidays, everybody.  I wrote:

> > Essentially the problem here is just to pass a piece of
> > information from a program with no privileges running as
> > nobody to a program with the ability to update the aliases
> > file and run newlist.  The 15-minute solution is to
> > use what's there already (sendmail and perl) to send the
> > information through the mail system via cgi.
Still grasping his sanity, Scott Brown wrote:
> Thats only a "15-minute solution" if you're versant in sendmail and perl.  I
> can hack away at a perl script until it works (generally with a few trips to
> the man pages ;-), but sendmail... well, I know how to update the necessary
> files for new virt domains, and I can restart it when it's confused... but
> past that.... ;-)

Whups!  My apologies.  I'm not that great with sendmail either, but I know 
how to do a few things with it related to CGI apps.

For sending mail, I usually use metasend, since it's easy to use.  I chose it
once because it does MIME and I needed MIME, so keep in mind that there might
be easier ways to do it.  For what we're talking about, I'd be happy with 
sendmail because you can just pipe it a bunch of text and send it on its way
very easily.  But most any MTA will take a command line and zing mail off for

Here's a piece of perl from a CGI mail gateway that I stole from an O'Reilly
CGI book long ago and modified.   It assumes you've built an array named 
MAIL containing your FROM and TO addresses and the message you want to send.
You could just as easily call sendmail with a command line, too.

sub send_mail {
   # Get a sendmail process ready...
   open (SENDMAIL, "| $sendmail");

   # ...and send it a mail header...
   print SENDMAIL <<Mail_Header;
From: $MAIL{'from} <$MAIL{'email'}>
To: $MAIL{'to'}
Reply-To: $MAIL{'email'}
Subject: $MAIL{'subject'}
X-Mailer: $gateway
X-Remote-Host: $ENV{'REMOTE_ADDR'}

   # I threw in a cc line just so you'd know you could cc each newlist request
   # to someone, maybe the sysadmin or the company mail person.
   if ($MAIL{'cc'}) {
      print SENDMAIL "Cc: ", $MAIL{'cc'}, "\n";

   # And now we throw in the message, maybe just the names of the list and
   # the email and password for the list admin.
   print SENDMAIL "\n", $MAIL{'message'}, "\n";

   # Go home, drink a beer, contemplate life, pass out on the sofa.
   close (SENDMAIL);

Here's another way of doing it with metasend and a JPEG file, which of course
isn't what you want but I'm pasting and you can get the gist of it *lazy 

   system(qq/metasend -b -z -e base64 -f $preview -F PrintForge -m 
   IMAGE\/JPEG -s "PrintForge Preview" -S 1000000 -t 
   $options{'previewmailto'} /);

The truth is I don't remember what metasend's various options are, but I think
you could skip most of what I pasted because you're just sending text.  But if
you always wanted to send yourself a picture, now you can.
> > Since the message never leaves the machine, it's just like
> > using a file semaphore; a POST calls the MTA, which then leaves
> > the information in a file, which then gets picked up by the
> > MTA and passed to a little script that makes the necessary updates.
> It's the hand-off from sendmail to the perl program that has me scratching
> my head right now.  Obviously, it would need to be done in the way that
> Mailman does it now - but I've not fully disected the WRAPPER program as of
> yet...  My background is in mainframe business application programming - so
> I dont have a lot of experience with OO code ...

OHHHHHHHH!!!!  Good grief, I'm so bamboozled by wrapper and its minions right
now that I wouldn't dare use it either.  I just meant call the program in 
the same way that mailman calls wrapper:

newlist:                    "|/home/mailman/myprogramdir/mylistprog"

That just pipes the incoming mail to your list program.  I've been using
wrapper (and you can try this at home) with

su mail
mail/wrapper mailcmd test < help_test

where "test" is the name of a list and "help_test" is a piece of mail I cc'd
to myself with the word "help" in the subject field.  Unfortunately, although
this works fine I still get "operating system error" in my mail logs, AND my
gid is set fine AND I can't figure it out.   *^#$@#$(!!!

So you can see how that wrapper call works with stdin and argv, and how a
call like I've written above should work just as well.  

> Of course, once the sendmail part is happy and functioning, it should be a
> simple job to parse out the required fields, run newlist, update the domain
> info, update /etc/aliases and the virt domain user file, and then send off a
> confirmation message...

Thar ya go.  Don't forget to parse it for metacharacters, just in case some
smarmy customer puts a shell command in for the name of the new list.
> Well, it would seem there's as many ways as there are people looking at the
> problem.
> >  Better yet, I wish someone would shoot me.
> Thats not the answer.  Chocolate is the answer.  Chocolate, cold pizza and a
> beer or two works wonders for me when I'm running into a deadline ;-)

*sniff* I was a human being, once!  If only those things could help me!  No,
only bullet could help me now...

I discovered last night, while implementing another "this has to work!" 
solution (a separate installation of apache, an idea which I'd actually started
to like because I can do all kinds of cool security and backup things that 
way), that apache neatly bypasses my chroot and zooms up the directory tree,
skipping my mailman installation in the process.  So many people have told me 
that's impossible!  Bla ha!  Bla ha ha ha ha ha ha!  Bla ha haha...how do they
do that???!!!  Must look at the Apache code.

I then fell back on another forehead-slappin' solution (two separate mailman 
installations, with the cgi version using links to the other's data 
directories).  That's when I realized that all this time I've been using 
wrapper to find out when things were working, but I seem to have another 
problem when mailman runs in a virtual machine.  It could be just that I've 
tried so many solutions that I'm skipping some installation step, so I'm going 
to try from scratch today.

I'm really happy with my virtual machines, happy enough that I've put myself 
through the living hell of hard-coded directory names in Mailman in an attempt
to keep them.  I can have separate email names on separate machines this way,
and the MTA's never have to meet.  Python looks pretty easy, actually.  Maybe
I'll modify Mailman to have a single configuration file where all the directory
names are kept...

Dave Klingler

More information about the Mailman-Users mailing list