Skip to content

Instantly share code, notes, and snippets.

@natefoo
Created February 23, 2023 21:39
Show Gist options
  • Save natefoo/9f3aa40d8191c71250155b42aada070e to your computer and use it in GitHub Desktop.
Save natefoo/9f3aa40d8191c71250155b42aada070e to your computer and use it in GitHub Desktop.
Re-enable bouncing Mailman3 list members

I upgraded Mailman3 from <3.3.1 to >= 3.3.1 without heeding the instructions and as a result, had a ton of my list members erroneously set to disabled due to bounces.

These scripts scan your bounce log file and re-enable anyone who was disabled. You could also easily modify it to just re-enable everyone, but I didn't want to do it unilaterally just in case.

from mailman.interfaces.member import DeliveryStatus
def unbounce(mlist, bounce_log):
emails = []
with open(bounce_log) as logfh:
for line in logfh:
if line.strip().endswith(", disabling delivery."):
splitline = line.split()
email = splitline[6]
list_id = splitline[9].rstrip(",")
if list_id == mlist.list_id:
emails.append(email)
for member in [mlist.members.get_member(email) for email in emails]:
msg = f"{member.address.email:30} {member.delivery_status} {member.bounce_score}"
if member.delivery_status == DeliveryStatus.by_bounces:
print(f"x {msg}")
member.preferences.delivery_status = DeliveryStatus.enabled
member.bounce_score = None
else:
print(f" {msg}")
#!/bin/bash
set -euo pipefail
BOUNCE_LOG='/var/log/mailman3/bounce.log'
. /opt/mailman3/bin/activate
for list_id in $(grep disabling "$BOUNCE_LOG" | awk '{print $10}' | sed 's/,$//' | sort | uniq); do
echo "[$list_id]"
PYTHONPATH=. mailman withlist -r unbounce.unbounce -l "$list_id" "$BOUNCE_LOG"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment