"""Creation/deletion hooks for manual /etc/aliases files."""
import sys
import email.Utils
from cStringIO import StringIO
from Mailman import mm_cfg
from Mailman import Message
from Mailman import Utils
from Mailman.Queue.sbcache import get_switchboard
from Mailman.i18n import _
from Mailman.MTA.Utils import makealiases
try:
True, False
except NameError:
True = 1
False = 0
def makelock():
class Dummy:
def lock(self):
pass
def unlock(self, unconditionally=False):
pass
return Dummy()
def clear():
pass
def create(mlist, cgi=False, nolock=False, quiet=False):
if mlist is None:
return
listname = mlist.internal_name()
fieldsz = len(listname) + len('-unsubscribe')
if cgi:
sfp = StringIO()
if not quiet:
print >> sfp, _("""\
The mailing list `%(listname)s' has been created via the through-the-web
interface. In order to complete the activation of this mailing list, the
proper /etc/aliases (or equivalent) file must be updated. The program
`newaliases' may also have to be run.
Here are the entries for the /etc/aliases file:
""")
outfp = sfp
else:
if not quiet:
print _("""\
To finish creating your mailing list, you must edit your /etc/aliases (or
equivalent) file by adding the following lines, and possibly running the
`newaliases' program:
""")
print _("""\
## %(listname)s mailing list""")
outfp = sys.stdout
for k, v in makealiases(listname):
print >> outfp, k + ':', ((fieldsz - len(k)) * ' '), v
if not cgi:
print >> outfp
return
siteowner = Utils.get_site_email(extra='owner')
msg = Message.UserNotification(
siteowner, siteowner,
_('Mailing list creation request for list %(listname)s'),
sfp.getvalue(), mm_cfg.DEFAULT_SERVER_LANGUAGE)
msg.send(mlist)
def remove(mlist, cgi=False):
listname = mlist.internal_name()
fieldsz = len(listname) + len('-unsubscribe')
if cgi:
sfp = StringIO()
print >> sfp, _("""\
The mailing list `%(listname)s' has been removed via the through-the-web
interface. In order to complete the de-activation of this mailing list, the
appropriate /etc/aliases (or equivalent) file must be updated. The program
`newaliases' may also have to be run.
Here are the entries in the /etc/aliases file that should be removed:
""")
outfp = sfp
else:
print _("""
To finish removing your mailing list, you must edit your /etc/aliases (or
equivalent) file by removing the following lines, and possibly running the
`newaliases' program:
## %(listname)s mailing list""")
outfp = sys.stdout
for k, v in makealiases(listname):
print >> outfp, k + ':', ((fieldsz - len(k)) * ' '), v
if not cgi:
print >> outfp
return
siteowner = Utils.get_site_email(extra='owner')
msg = Message.UserNotification(
siteowner, siteowner,
_('Mailing list removal request for list %(listname)s'),
sfp.getvalue(), mm_cfg.DEFAULT_SERVER_LANGUAGE)
msg['Date'] = email.Utils.formatdate(localtime=1)
outq = get_switchboard(mm_cfg.OUTQUEUE_DIR)
outq.enqueue(msg, recips=[siteowner], nodecorate=1)