Hello Mark,
Thanks for the quick reply!
Based on your instructions and reading a bit more in the manual, I made a couple of quick-and-dirty helping functions:
from mailman.app.moderator import handle_message list_manager = getUtility(IListManager) msg_db = getUtility(IMessageStore)
def get_lists(): for name in sorted(list_manager.names): print(name)
def get_held_messages(listname): m = list_manager.get(listname) req_db = IListRequests(m) reqs = list(req_db.held_requests) for req in reqs: print(req.key) for line in str(msg_db.get_message_by_id(req.key)).split("\n"): if any(x in line for x in ['From:', 'Subject:']): print(line) print('\n')
def export_held_messages(listname): m = list_manager.get(listname) req_db = IListRequests(m) reqs = list(req_db.held_requests) for req in reqs: with open('/tmp/' + listname, 'a+') as f: f.write(str(msg_db.get_message_by_id(req.key))) f.write('\n\n\n\n\n\n') f.close()
def discard_held_messages(listname): m = list_manager.get(listname) req_db = IListRequests(m) reqs = list(req_db.held_requests) for req in reqs: handle_message(m, req.id, Action.discard) commit()
However, while I was testing this happily on a list that was not affected with the JSON error, I finally tested discard_held_messages() on one of the problematic list, and I get the exact same problem as when trying to view the moderation queue API:
discard_held_messages_queue('xxx@xxx.xxx') Traceback (most recent call last): File "<console>", line 1, in <module> File "<console>", line 6, in discard_held_messages_queue File "/usr/local/lib/python3.5/dist-packages/mailman/app/moderator.py", line 97, in handle_message key, msgdata = requestdb.get_request(id) File "/usr/local/lib/python3.5/dist-packages/mailman/database/transaction.py", line 85, in wrapper return function(args[0], config.db.store, *args[1:], **kws) File "/usr/local/lib/python3.5/dist-packages/mailman/model/requests.py", line 120, in get_request result.data_hash, expunge=False) File "/usr/local/lib/python3.5/dist-packages/mailman/database/transaction.py", line 85, in wrapper return function(args[0], config.db.store, *args[1:], **kws) File "/usr/local/lib/python3.5/dist-packages/mailman/model/pending.py", line 138, in confirm value = json.loads(keyvalue.value) File "/usr/lib/python3.5/json/__init__.py", line 319, in loads return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Unterminated string starting at: line 1 column 1 (char 0)
With that said, even though I cannot pass the discard action, I can export the queue without problem, so I will send you off-list a sample, because I am not sure what I should be looking for.
Finally, is there another way to get rid of these messages? Are there consequences if I would use message_store.delete_message(message_id) instead of handle_message(m, req.id, Action.discard)?
Thanks! a.