aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-08-02 22:31:27 -0400
committerDavid Bremner <david@tethera.net>2021-08-03 08:24:03 -0400
commit14a4cd24f1a25a89e16574881869dd6036310930 (patch)
tree4d3caa2bccc5ca1a4d20b364eab590d6511e4a19
parent3186fb29fe63e6ed61942b642da1e89ba14f97cf (diff)
add verify command
In order to work with older versions of mailmanclient, provide a function to fetch a nonmember from a list
-rw-r--r--mm3mod/__init__.py41
1 files changed, 41 insertions, 0 deletions
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')