~futatuki/mailman/2.1-forbid-subscription

« back to all changes in this revision

Viewing changes to Mailman/Commands/cmd_unsubscribe.py

  • Committer:
  • Date: 2003-01-02 05:25:50 UTC
  • Revision ID: vcs-imports@canonical.com-20030102052550-qqbl1i96tzg3bach
This commit was manufactured by cvs2svn to create branch
'Release_2_1-maint'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2002 by the Free Software Foundation, Inc.
 
2
#
 
3
# This program is free software; you can redistribute it and/or
 
4
# modify it under the terms of the GNU General Public License
 
5
# as published by the Free Software Foundation; either version 2
 
6
# of the License, or (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
16
 
 
17
"""
 
18
    unsubscribe [password] [address=<address>]
 
19
        Unsubscribe from the mailing list.  If given, your password must match
 
20
        your current password.  If omitted, a confirmation email will be sent
 
21
        to the unsubscribing address. If you wish to unsubscribe an address
 
22
        other than the address you sent this request from, you may specify
 
23
        `address=<address>' (no brackets around the email address, and no
 
24
        quotes!)
 
25
"""
 
26
 
 
27
from email.Utils import parseaddr
 
28
 
 
29
from Mailman import Errors
 
30
from Mailman.i18n import _
 
31
 
 
32
STOP = 1
 
33
 
 
34
 
 
35
 
 
36
def gethelp(mlist):
 
37
    return _(__doc__)
 
38
 
 
39
 
 
40
 
 
41
def process(res, args):
 
42
    mlist = res.mlist
 
43
    password = None
 
44
    address = None
 
45
    argnum = 0
 
46
    for arg in args:
 
47
        if arg.startswith('address='):
 
48
            address = arg[8:]
 
49
        elif argnum == 0:
 
50
            password = arg
 
51
        else:
 
52
            res.results.append(_('Usage:'))
 
53
            res.results.append(gethelp(mlist))
 
54
            return STOP
 
55
        argnum += 1
 
56
    # Fill in empty defaults
 
57
    if address is None:
 
58
        realname, address = parseaddr(res.msg['from'])
 
59
    if not mlist.isMember(address):
 
60
        listname = mlist.real_name
 
61
        res.results.append(
 
62
            _('%(address)s is not a member of the %(listname)s mailing list'))
 
63
        return STOP
 
64
    # If we're doing admin-approved unsubs, don't worry about the password
 
65
    if mlist.unsubscribe_policy:
 
66
        try:
 
67
            mlist.DeleteMember(address, 'mailcmd')
 
68
        except Errors.MMNeedApproval:
 
69
            res.results.append(_("""\
 
70
Your unsubscription request has been forwarded to the list administrator for
 
71
approval."""))
 
72
    elif password is None:
 
73
        # No password was given, so we need to do a mailback confirmation
 
74
        # instead of unsubscribing them here.
 
75
        cpaddr = mlist.getMemberCPAddress(address)
 
76
        mlist.ConfirmUnsubscription(cpaddr)
 
77
        # We don't also need to send a confirmation to this command
 
78
        res.respond = 0
 
79
    else:
 
80
        # No admin approval is necessary, so we can just delete them if the
 
81
        # passwords match.
 
82
        oldpw = mlist.getMemberPassword(address)
 
83
        if oldpw <> password:
 
84
            res.results.append(_('You gave the wrong password'))
 
85
            return STOP
 
86
        mlist.ApprovedDeleteMember(address, 'mailcmd')
 
87
        res.results.append(_('Unsubscription request succeeded.'))