diff --git a/mailman_sync.py b/mailman_sync.py index 18c0113..d9a602f 100755 --- a/mailman_sync.py +++ b/mailman_sync.py @@ -64,7 +64,7 @@ def config_list( # TODO: this will never update someone's display name def diff_roster( - expected_members: list[str], existing_members: list[mailmanclient.Member] + expected_members: set[str], existing_members: set[mailmanclient.Member] ) -> tuple[dict[str, str], list[mailmanclient.Member]]: expected_members_dict = dict( list(reversed(email.utils.parseaddr(member))) for member in expected_members @@ -82,9 +82,9 @@ def diff_roster( def sync_members( - list: mailmanclient.MailingList, dry_run: bool, expected_members: list[str] + list: mailmanclient.MailingList, dry_run: bool, expected_members: set[str] ): - members_to_add, members_to_remove = diff_roster(expected_members, list.members) + members_to_add, members_to_remove = diff_roster(expected_members, set(list.members)) for address, display_name in members_to_add.items(): print(f"Adding '{display_name} <{address}>' to list {list}") @@ -106,9 +106,11 @@ def sync_members( def sync_moderators( - list: mailmanclient.MailingList, dry_run: bool, expected_members: list[str] + list: mailmanclient.MailingList, dry_run: bool, expected_members: set[str] ): - members_to_add, members_to_remove = diff_roster(expected_members, list.moderators) + members_to_add, members_to_remove = diff_roster( + expected_members, set(list.moderators) + ) for address, display_name in members_to_add.items(): print(f"Adding '{display_name} <{address}>' as moderator to list {list}") @@ -197,8 +199,8 @@ def main( config_list(list, dry_run, **props["config"]) if "moderators" in props: - sync_moderators(list, dry_run, props["moderators"]) - sync_members(list, dry_run, props["members"]) + sync_moderators(list, dry_run, set(props["moderators"])) + sync_members(list, dry_run, set(props["members"]) | set(props["moderators"])) lists = [list.list_name.lower() for list in domain.get_lists()] update_cloudflare_lists(