[Mailman-Users] Auto Subscribe

Andrew Witt witt at tux.org
Mon Sep 9 19:42:48 CEST 2002


On Mon, 9 Sep 2002, Angel Gabriel wrote:

> Is it possible to have users automatically subscribed to my lists?  I
> found that a lot of people do not understand how to send commands via
> email, and it is not possible for people to access my webservers at
> the moment. Basically, I would like to create the following scenario.
>
> User sends email to a address I set up.
> User gets subscribed to mailing list.

I see two options for you.  Both involve hooking up a program to a mail
alias, (e.g., a "|/path/program" alias under sendmail) which I am going to
assume you know how to do for the MTA you are running.  Both also involve
having the program extract the From: address out of the incoming message.
The first option is to have the program kick off Mailman's own add_members
tool and supply the extracted address; the second is to have the program
generate a new e-mail containing the appropriate subscription command.

The first option could be tricky, depending on what kind of system you are
running, and how permissions and privileges are controlled.  And, no
matter what, it may be ill-advised.  The user that runs mail-enabled
programs is supposed to be relatively un-privileged, since mail is a
service that is exposed to the outside; the ability to run the Mailman
tools is supposed to be relatively privileged, since they are used to
access Mailman databases in an administrative role.  Bridging the gap is
asking for trouble.

The second option is much safer ... but will require that the end users be
able to understand and respond appropriately to a confirmation message at
least.  (Which maybe they can do, even if they cannot understand the
Mailman e-mail commands, since they just need to reply to the confirmation
message.)  Below is a Perl program that, when hooked up to a mail alias,
will do this.  Please be sure to edit the first few lines for your
location of Perl, appropriate e-mail addresses, your MTA's command line,
and the path to the log file.

(Note that the program exits with "0" even when there is an error; you
want to return "0" to the MTA that calls this program, so that it believes
that all went well; otherwise it will return an NDR that the end user is
likely to think of as completely arcane.  Its your responsibility to keep
tabs on the log file.  Also note that the program does not conform
perfectly to RFC-2822; among other things, it assumes a single mailbox in
the From: field.  But it should work for all typical situations.)

> I'm not worried about spoofed addresses, or bouncing addresses, or
> abuse. The people this list are for, can just about work thier mobile
> phones. Any help would be appreciated.

Are you -sure- you want to do this?  If you are not worried about spoofing
or abuse, you either have a small number of interested parties, or you
will personally be in touch with everyone who would sign up.  (In other
words, if you are not worried about attacks, it must also be that you are
not expecting or allowing word to spread among the public in general that
your mailing list is available).  Either way, you might just be better of
having the people send mail to -your- address, and -you- add them to the
list.  Same effect; fewer worries.

If the reason you want an automated process is because you expect a large
or wide-spread number of sign-ups, you -need- to worry about spoofing,
bounced e-mails, and abuses.

(Then again, it occurs to me that this might be for internal use at a
large company, in which case, the auto-subscribe alias does not need to be
exposed to the general public.  Still ... most attacks (speaking of
computer attacks in general) come from the inside, and its not like
hackers and vandals are never hired by established corporations ...)

Hope all of that helps; the code is below

Regards,
- Andrew

    ----------------------------------------------------------------
                 Automation does not happen by itself.


#!/usr/bin/perl

$mailCmnd     = '/usr/sbin/sendmail -t';
$addrCmndFrom = 'USER at DOMAIN';
$addrCmndTo   = 'LISTNAME-request at DOMAIN';

$dateLog = `date "+%Y-%m"`; chomp( $dateLog );
$fileLog = "/tmp/auto-subscribe.log.$dateLog";

# Pull in message; keep certain header lines; keep message body.
$msgBody = "";
$msgHeaders = "";
$flagStartBody = 0;
while ($lineIn = <STDIN>)
    {
    chomp( $lineIn );

    if ($flagStartBody == 1)
        { $msgBody .= "$lineIn\n"; next; }

    if ($lineIn =~ /^$/)
        { $flagStartBody = 1; next; }

    if ($lineIn =~ /^From: +.*?\b(\S+\@\S+)\b/)
        { $addrFrom = "\L$1"; }

    $msgHeaders .= "$lineIn\n";
    }

if (! defined( $addrFrom ))
    {
    &LogEvent( "could not determine From: address" );
    exit( 0 );
    }

&LogEvent( "message from : $addrFrom" );

# Build a message to send.
$msgHeadNew  = "From: $addrCmndFrom\n";
$msgHeadNew .= "To: $addrCmndTo\n";
$msgHeadNew .= "Subject: auto-subscribe\n";
$msgHeadNew .= "\n";

$msgBodyNew  = "subscribe address=$addrFrom\n";
$msgBodyNew .= "end\n";

# Mail out the message.
open( MAILER, "| $mailCmnd" );
print( MAILER $msgHeadNew );
print( MAILER $msgBodyNew );
close( MAILER );

exit( 0 );

sub LogEvent
    {
    local $strEvent = $_[0];

    if (open( FILELOG, ">> $fileLog" ))
        {
        $datetime = `date "+%Y %m %d %T"`;
        chomp( $datetime );
        print( FILELOG "$datetime - $strEvent\n" );
        close( FILELOG );
        }
    }





More information about the Mailman-Users mailing list