Created
September 29, 2017 20:00
-
-
Save emsearcy/fcb6ff3d0eb1c6a89ccd236ebb9d22a5 to your computer and use it in GitHub Desktop.
Export mailman3 subscribers for groups.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Django script to export member lists from Mailman 3 to Groups.io | |
# Includes a suffix "nomail", "digest", or "summary" as needed | |
# | |
# Sample command: | |
# /opt/mailman3-web/virtualenv/bin/python ./manage.py runscript mm3_to_groupsio --script-args lists.example.com | |
import codecs | |
from django.conf import settings | |
from django.core.management.base import BaseCommand, CommandError | |
from postorius import utils | |
from urllib2 import HTTPError | |
digest_map = { | |
'regular': '', | |
'plaintext_digests': ' digest', | |
'mime_digests': ' digest', | |
'summary_digests': ' summary', | |
} | |
def run(*args): | |
if len(args) < 1: | |
print "Please pass '--script-args lists.example.com' to command" | |
return | |
member_export(args[0]) | |
def member_export(domain): | |
client = utils.get_client() | |
for list in client.get_domain(domain).lists: | |
print 'dumping members for '+list.list_id | |
f = codecs.open('/tmp/list_members/'+list.list_id+'.txt', 'w', encoding='utf8') | |
for member in list.members: | |
email = member.email | |
if member.user.display_name is not None and member.user.display_name != 'None': | |
email = "%s <%s>" % (member.user.display_name, member.email) | |
delivery = member.preferences['delivery_status'] | |
if delivery is None: | |
# if no subscription preference, try an email preference | |
for addr in member.user.addresses: | |
if str(addr) == member.email: | |
delivery = addr.preferences['delivery_status'] | |
if delivery is None: | |
# if no subscription or email preference, try a user preference | |
delivery = member.user.preferences['delivery_status'] | |
if delivery == 'by_user': | |
# they have delivery disabled, print record and skip delivery mode checks | |
f.write("%s %s\n" % (email, 'nomail')) | |
else: | |
# determine if they have a regular subscription, digest, or summary | |
delivery = member.preferences['delivery_mode'] | |
if delivery is None: | |
# if no subscription preference, try an email preference | |
for addr in member.user.addresses: | |
if str(addr) == member.email: | |
delivery = addr.preferences['delivery_mode'] | |
if delivery is None: | |
# if no subscription or email preference, try a user preference | |
delivery = member.user.preferences['delivery_mode'] | |
if delivery is None: | |
# fall back to 'regular' | |
delivery = 'regular' | |
# map delivery_mode to a suffix (no suffix for regular) | |
f.write("%s%s\n" % (email, digest_map[delivery])) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment