From 14a4cd24f1a25a89e16574881869dd6036310930 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 2 Aug 2021 22:31:27 -0400 Subject: add verify command In order to work with older versions of mailmanclient, provide a function to fetch a nonmember from a list --- mm3mod/__init__.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mm3mod/__init__.py b/mm3mod/__init__.py index d18f246..f5f3b86 100644 --- a/mm3mod/__init__.py +++ b/mm3mod/__init__.py @@ -6,6 +6,7 @@ import cmd2 import configparser from pathlib import PurePath from mailmanclient.client import Client +from mailmanclient import Member class ModShell(cmd2.Cmd): intro = 'Type help or ? for a list of commands' @@ -54,6 +55,26 @@ class ModShell(cmd2.Cmd): return False + def complete_verify(self, text, line, begidx, endidx): + return self.matching_request_ids(text) + + def do_verify(self, arg): + ''' + Post held message, and accept further messages from the same + sender. + ''' + try: + n = int(arg) + msg=self.mlist.get_held_message (n) + member=get_nonmember(self.mlist, msg.sender) + member.moderation_action = 'accept' + member.save() + msg.accept() + except ValueError: + print('Illegal request_id: {:s}'.format(arg)) + + return False + def complete_discard(self, text, line, begidx, endidx): candidates = self.matching_request_ids(text) if "page".startswith(text): @@ -86,6 +107,26 @@ class ModShell(cmd2.Cmd): self.print_held() return stop +# in later versions, this exists as a method of MailingList, but not in +# version 3.2.1 + +def get_nonmember(mlist, email): + """Get a nonmember. + + :param address: The email address of the member for this list. + :return: A member proxy object. + """ + # In order to get the member object we query the REST API for + # the member. Incase there is no matching subscription, an + # HTTPError is returned instead. + try: + path = 'lists/{0}/nonmember/{1}'.format(mlist.list_id, email) + response, content = mlist._connection.call(path) + return Member(mlist._connection, content['self_link'], content) + except HTTPError: + raise ValueError('%s is not a known nonmember address of %s' % + (email, mlist.fqdn_listname)) + def main (): home = os.environ.get('HOME') -- cgit v1.2.3