# Copyright (C) 1998,1999,2000 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""Produce user options form, from options.html template.
Takes listname/userid in PATH_INFO, expecting an `obscured' userid. Depending
on the Utils.{O,Uno}bscureEmail utilities tolerance, will work fine with an
unobscured ids as well.
"""
# We don't need to lock in this script, because we're never going to change
# data.
import os
import string
from Mailman import mm_cfg
from Mailman import Utils
from Mailman import MailList
from Mailman import Errors
from Mailman.htmlformat import *
from Mailman.Logging.Syslog import syslog
def main():
doc = HeadlessDocument()
try:
path = os.environ['PATH_INFO']
except KeyError:
path = ''
parts = Utils.GetPathPieces(path)
# sanity check options
if len(parts) < 2:
doc.AddItem(Header(2, "Error"))
doc.AddItem(Bold("Invalid options to CGI script."))
print doc.Format()
return
# get the list and user's name
listname = string.lower(parts[0])
user = Utils.UnobscureEmail(string.join(parts[1:], '/'))
# open list
try:
mlist = MailList.MailList(listname, lock=0)
except Errors.MMListError, e:
doc.AddItem(Header(2, "Error"))
doc.AddItem(Bold('No such list %s' % listname))
print doc.Format()
syslog('error', 'No such list "%s": %s\n' % (listname, e))
return
# Sanity check the user
user = Utils.LCDomain(user)
if not mlist.members.has_key(user) and \
not mlist.digest_members.has_key(user):
# then
doc.AddItem(Header(2, "Error"))
doc.AddItem(Bold("%s: No such member %s." % (listname, `user`)))
doc.AddItem(mlist.GetMailmanFooter())
print doc.Format()
return
# find the case preserved email address (the one the user subscribed with)
lcuser = mlist.FindUser(user)
cpuser = mlist.GetUserSubscribedAddress(lcuser)
if lcuser == cpuser:
cpuser = None
if mlist.obscure_addresses:
presentable_user = Utils.ObscureEmail(user, for_text=1)
if cpuser is not None:
cpuser = Utils.ObscureEmail(cpuser, for_text=1)
else:
presentable_user = user
# Do replacements
replacements = mlist.GetStandardReplacements()
replacements[''] = mlist.FormatOptionButton(
mm_cfg.Digests, 1, user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.Digests, 0, user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.DisableMime, 1, user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.DisableMime, 0, user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.DisableDelivery, 0, user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.DisableDelivery, 1, user)
replacements[''] = mlist.FormatDisabledNotice(user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.AcknowledgePosts, 0, user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.AcknowledgePosts, 1, user)
replacements[''] = mlist.FormatOptionButton(
mm_cfg.DontReceiveOwnPosts, 0, user)
replacements[''] = (
mlist.FormatOptionButton(mm_cfg.DontReceiveOwnPosts, 1, user))
replacements[''] = (
mlist.FormatOptionButton(mm_cfg.ConcealSubscription, 0, user))
replacements[''] = mlist.FormatOptionButton(
mm_cfg.ConcealSubscription, 1, user)
replacements[''] = mlist.FormatButton(
'setdigest', 'Submit My Changes')
replacements[''] = (
mlist.FormatButton('unsub', 'Unsubscribe'))
replacements[''] = mlist.FormatSecureBox('digpw')
replacements[''] = mlist.FormatSecureBox('upw')
replacements[''] = mlist.FormatSecureBox('opw')
replacements[''] = mlist.FormatSecureBox('newpw')
replacements[''] = mlist.FormatSecureBox('confpw')
replacements[''] = (
mlist.FormatSecureBox('othersubspw'))
replacements[''] = (
mlist.FormatButton('othersubs',
'List my other subscriptions'))
replacements[''] = (
mlist.FormatButton('changepw', "Change My Password"))
replacements[''] = (
mlist.FormatFormStart('handle_opts', user))
replacements[''] = user
replacements[''] = presentable_user
replacements[''] = mlist.FormatButton('emailpw',
('Email My Password'
' To Me'))
replacements[''] = (
mlist.FormatUmbrellaNotice(user, "password"))
if cpuser is not None:
replacements[''] = '''
You are subscribed to this list with the case-preserved address
%s.''' % cpuser
else:
replacements[''] = ''
doc.AddItem(mlist.ParseTags('options.html', replacements))
print doc.Format()