Wow, that beats my lazy way of doing it, which is simply a cron job which uses the *add_members* function to import a list of email addresses from a text file, that I have a PHP script <http://www.syjmovie.com> saving the addresses to.

Michael Kubler
*G*rey *P*hoenix *P*roductions <http://www.greyphoenix.biz>



Lynn, Michael (A&E) wrote:
Not sure if this will help anyone - but I had a requirement to enable
remote subscription from a command line.  I wrapped a call to cURL for
this.

--->8---
#!/bin/bash
# mlynn 03/28/2008
# Wrap a call to curl to enable subscription to a mailman list
#
VERSION="0.1"
MAILMANURL="http://lists.yourserver.com/mailman/subscribe";
PROGRAM=`basename $0`

function ERROR
# Spew the wrongness
{
        echo "Error: Code $1"
        echo "${2}?"
        exit $1
}

function SYNTAX
#
# Tell the people how you communicate
#
{
        echo "SYNTAX:"
        echo "$PROGRAM $VERSION"
        echo "  $PROGRAM [[email] [firstname] [lastname] [password]
[listname]]"
        echo "  This handy script will wrap a call to cURL for the
purpose of subscribing"
        echo "  a user to a mailman list.  If you fail to provide
optional arguments, you"
        echo "  will be prompted to enter them at the command line."
        echo "           "
}

function CHECKCURL
#
# Check for commands you depend upon
#
{
        CURL=`which curl`
        if [ $? -ne 0 ]; then
                ERROR 1 "the command curl is missing from the system"
        fi;

}

function GETARGS
#
# Get the arguments - duh.
#
{
        if [ "$1" = "-h" -o "$1" = "--h" ]; then
                SYNTAX
                exit 0
        fi
        if [ -z $1 ]; then
                {
                echo "Enter email for user to be subscribed: "
                read EMAIL
                if [ -z $EMAIL ]; then
                        ERROR 30 "You must enter a valid email address."
                fi
                }
        else
                EMAIL=$1
        fi
        if [ -z $2 ]; then
                {
                echo "Enter the first name of the person to be
subscribed: "
                read FIRSTNAME
                if [ -z $FIRSTNAME ]; then
                        ERROR 30 "You the first name of the subscibee."
                fi
                }
        else
                FIRSTNAME=$2
        fi
        if [ -z $3 ]; then
                {
                echo "Enter the last name of the person to be
subscribed: "
                read LASTNAME
                if [ -z $LASTNAME ]; then
                        ERROR 30 "You the last name of the subscibee."
                fi
                }
        else
                LASTNAME=$3
        fi
        if [ -z $4 ]; then
                {
                echo "Enter the list access password for this user: "
                read PW
                if [ -z $PW ]; then
                        ERROR 30 "You must enter a password for $EMAIL."
                fi
                }
        else
                PW=$4
        fi
        if [ -z $5 ]; then
                {
                echo "Enter the list name to subscribe $EMAIL to: "
                read LIST
                if [ -z $LIST ]; then
                        ERROR 30 "You must enter a valid listname."
                fi
                }
        else
                LIST=$5
        fi
}

function DOCURL
# Build the cURL call
{

        # urlencode the email '@'
        UEMAIL=`echo $EMAIL | sed "s/\@/\%40/g"`
        CMD="curl -s
$MAILMANURL/${LIST}?email=${UEMAIL}&fullname=$FIRSTNAME%20$LASTNAME&pw=$
PW&pw-conf=$PW&digest=0&email-button=Submit"
        OUT=`${CMD}`
        if `echo ${OUT} | grep -i "no such list"` ; then
                {
                        ERROR 30 "List $LIST not found.  Please check
and try again."
                }
        else
                {
                        echo "List subscription for the following user
appears to have worked."
                        echo "Email:     $EMAIL"
                        echo "Full Name: $FIRSTNAME $LASTNAME"
                        echo "The user should recieve an email
requesting confirmation for this subscription."
                        exit 0
                }
        fi

}


CHECKCURL
GETARGS $1 $2 $3 $4 $5
DOCURL
---8<----
------------------------------------------------------
Mailman-Users mailing list
Mailman-Users@python.org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-users/archive%40jab.org

Security Policy: 
http://www.python.org/cgi-bin/faqw-mm.py?req=show&amp;file=faq01.027.htp

Reply via email to