diff options
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 60 |
1 files changed, 60 insertions, 0 deletions
@@ -4,6 +4,7 @@ import config import web from random import Random +from Mailman import MailList, Errors, UserDesc rng = Random() @@ -32,3 +33,62 @@ def validate_listname(name): return True +def create_list(listname, listadmin, passwd=None): + if passwd == None: + passwd = generate_password() + + try: + # create list + p = subprocess.Popen(['sudo', '-n', os.path.join(config.mailman_path, 'bin', 'neueliste.bash'), + listname, listadmin, passwd], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + (progress, junk) = p.communicate() + return (p.returncode == 0, progress) + except Exception as e: + progress = e + + return (False, progress) + + +def notify_admins(listname, listadmin, success, progress): + # send mail to admins + web.sendmail('mailman@list.spline.inf.fu-berlin.de', + config.admin_emails, + u'Mailingliste "%s" für %s %serzeugt' % (listname, listadmin, 'NICHT ' if not success else ''), + u'''Die Mailingliste "%s" wurde am %s für %s von %s aus %serzeugt. + + Log: + %s''' % (listname, time.strftime('%Y-%m-%d um %H:%M:%S', time.gmtime()), + listadmin, ctx.ip, 'NICHT ' if not success else '', progress) + ) + + +def add_to_list(listname, listadmin): + try: + mlist = MailList.MailList(listname) + except Errors.MMUnknownListError: + return 'Could not add %s to %s: List not found.' % (listadmin, listname) + + userdesc = UserDesc(address = listadmin, + fullname = '', + digest = 0) + + try: + mlist.ApprovedAddMember(userdesc, 0, 0) + success = True + progress = 'Successfully added %s to %s list.' + + except Errors.MMAlreadyAMember: + success = True + progress = '%s was already member of %s list.' + except Errors.MembershipIsBanned: + success = False + progress = 'Could not add %s to %s: Address ist banned.' + except Errors.MMBadEmailError: + success = False + progress = 'Could not add %s to %s: Bad email address.' + except Errors.MMHostileAddress: + success = False + progress = 'Could not add %s to %s: Illegal characters in email address.' + + return (success, progress % (listadmin, listname)) |