From ce5a3815e8c6e7d18e73e899736a0bd9fcd937f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Serman?= Date: Sat, 25 Nov 2017 20:46:40 +0100 Subject: [PATCH] Adds helds messages endpoint --- mailmanapi/apiv1.py | 18 ++++++++++++++++++ mailmanapi/apiv2.py | 19 +++++++++++++++++++ mailmanapi/routes.py | 5 ++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/mailmanapi/apiv1.py b/mailmanapi/apiv1.py index 4fa75d3..b1360bd 100644 --- a/mailmanapi/apiv1.py +++ b/mailmanapi/apiv1.py @@ -132,6 +132,24 @@ def members(listname): return jsonify(mlist.getMembers()) +def helds(listname): + """Lists helds messages for the `listname` list. + + **Method**: GET + + **URI**: //helds + + Returns an array of helds messages.""" + + mlist = get_mailinglist(listname, lock=True) + msgids = mlist.GetHeldMessageIds() + msg = [] + for msgid in msgids: + record = mlist.GetRecord(msgid) + msg.append({'from': record[1], 'subject': record[2], 'reason': record[3]}) + mlist.Unlock() + return jsonify(msg) + def sendmail(listname): """Posts an email to the mailing list. diff --git a/mailmanapi/apiv2.py b/mailmanapi/apiv2.py index 898e0f5..b48bb81 100644 --- a/mailmanapi/apiv2.py +++ b/mailmanapi/apiv2.py @@ -242,3 +242,22 @@ def members(listname): except Errors.MMUnknownListError, e: return jsonify(ERRORS_CODE[e.__class__.__name__]) return jsonify(mlist.getMembers()) + +def helds(listname): + """Lists helds messages for the `listname` list. + + **Method**: GET + + **URI**: /v2//helds + + Returns an array of helds messages.""" + + mlist = get_mailinglist(listname, lock=True) + msgids = mlist.GetHeldMessageIds() + msg = [] + for msgid in msgids: + record = mlist.GetRecord(msgid) + msg.append({'from': record[1], 'subject': record[2], 'reason': record[3]}) + mlist.Unlock() + return jsonify(msg) + diff --git a/mailmanapi/routes.py b/mailmanapi/routes.py index 6fe82d7..99d7064 100644 --- a/mailmanapi/routes.py +++ b/mailmanapi/routes.py @@ -17,6 +17,8 @@ def create_routes(app): callback=apiv1.members) app.route('//sendmail', method='POST', callback=apiv1.sendmail) + app.route('//helds', method='GET', + callback=apiv1.helds) # v2 app.route('/v2/lists/', method='GET', @@ -31,7 +33,8 @@ def create_routes(app): callback=apiv2.members) app.route('/v2/sendmail/', method='POST', callback=apiv2.sendmail) - + app.route('/v2//helds', method='GET', + callback=apiv2.helds) def get_application(allowed_ips): bottle_app = default_app()