Additional tweaks to the mailman listinfo importer.

- Legacy-Id: 13710
This commit is contained in:
Henrik Levkowetz 2017-06-22 16:41:27 +00:00
parent ce1b655fa2
commit 9f44b9a65d

View file

@ -7,6 +7,7 @@ import debug # pyflakes:ignore
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.exceptions import MultipleObjectsReturned
sys.path.append(settings.MAILMAN_LIB_DIR) sys.path.append(settings.MAILMAN_LIB_DIR)
@ -31,12 +32,14 @@ def import_mailman_listinfo(verbosity=0):
note("Could not import mailman modules -- skipping import of mailman list info") note("Could not import mailman modules -- skipping import of mailman list info")
return return
for name in Utils.list_names(): names = list(Utils.list_names())
names.sort()
for name in names:
mlist = MailList.MailList(name, lock=False) mlist = MailList.MailList(name, lock=False)
note("List: %s" % mlist.internal_name()) note("List: %s" % mlist.internal_name())
if mlist.advertised: if mlist.advertised:
description = mlist.description.decode('latin1')[:256] description = mlist.description.decode('latin1')[:256]
list, created = List.objects.get_or_create(name=mlist.real_name, description=description, advertised=mlist.advertised) mmlist, created = List.objects.get_or_create(name=mlist.real_name, description=description, advertised=mlist.advertised)
# The following calls return lowercased addresses # The following calls return lowercased addresses
members = mlist.getRegularMemberKeys() + mlist.getDigestMemberKeys() members = mlist.getRegularMemberKeys() + mlist.getDigestMemberKeys()
members = [ m for m in members if mlist.getDeliveryStatus(m) == MemberAdaptor.ENABLED ] members = [ m for m in members if mlist.getDeliveryStatus(m) == MemberAdaptor.ENABLED ]
@ -45,18 +48,22 @@ def import_mailman_listinfo(verbosity=0):
if not addr in members: if not addr in members:
note(" Removing subscription: %s" % (addr)) note(" Removing subscription: %s" % (addr))
old = Subscribed.objects.get(email=addr) old = Subscribed.objects.get(email=addr)
old.lists.remove(list) old.lists.remove(mmlist)
if old.lists.count() == 0: if old.lists.count() == 0:
note(" Removing address with no subscriptions: %s" % (addr)) note(" Removing address with no subscriptions: %s" % (addr))
old.delete() old.delete()
for addr in members: for addr in members:
if len(addr) > 64: if len(addr) > 64:
sys.stderr.write("Email address subscribed to '%s' too long for table: <%s>" % (name, addr)) sys.stderr.write(" ** Email address subscribed to '%s' too long for table: <%s>\n" % (name, addr))
continue continue
if not addr in known: if not addr in known:
note(" Adding subscription: %s" % (addr)) note(" Adding subscription: %s" % (addr))
new, created = Subscribed.objects.get_or_create(email=addr) try:
new.lists.add(list) new, created = Subscribed.objects.get_or_create(email=addr)
except MultipleObjectsReturned as e:
sys.stderr.write(" ** Error handling %s in %s: %s\n" % (addr, name, e))
continue
new.lists.add(mmlist)
class Command(BaseCommand): class Command(BaseCommand):