Thank you, that's perfect! For anyone that might stumble upon this, I had to make two minor adjustments to automate it.
import os
msg_ids = {}
lm = getUtility(IListManager)
ms = getUtility(IMessageStore)
for mlistin lm.mailing_lists:
requestdb = IListRequests(mlist)
for rqin requestdb.held_requests:
key, msgdata = requestdb.get_request(rq.id)
if msgdata['_request_type'] !='held_message':
continue msg = ms.get_message_by_id(key)
msg_ids[(msg['Message-ID-Hash'])] =True for root, dirs, filesin os.walk('/docker/var/messages'):
for filein files:
if not msg_ids.get(file, False):
msg = ms.get_message_by_hash(file)
# It happened to me that msg was 'None'
if msg:
ms.delete_message(msg['Message-ID'])
# I couldn't run it with '--run' and if you pipe it into 'mailman
shell' # I needed this or the loop above wouldn't execute. pass
On 5/27/19 6:22 AM, Mark Sapiro wrote:
You could modify the above to write the list to a file and then wrap the whole thing in a shell script which would make the list and then do something like
for f in
find var/messages -type f
;do n=cut -d / -f5 <<<$f
for keep incat list
;do k=0 if [ $n == $keep ] ;then k=1 break fi done if [ $k -eq 0 ]; then rm $f fi done Actually, I thought about it a bit more, and I decided that arcane shellOn 5/26/19 3:07 PM, Mark Sapiro wrote: script was a bit obscure and it would be easier to just do it in Python. Plus, you can properly delete the message that way.
A complete script for
mailman shell
is likeimport os msg_ids = {} lm = getUtility(IListManager) ms = getUtility(IMessageStore) for mlist in lm.mailing_lists: requestdb = IListRequests(mlist) for rq in requestdb.held_requests: key, msgdata = requestdb.get_request(rq.id) if msgdata['_request_type'] != 'held_message': continue msg = ms.get_message_by_id(key) msg_ids[(msg['Message-ID-Hash'])] = True
for root, dirs, files in os.walk('path/to/var/messages'): for file in files: if not msg_ids.get(file, False): msg = ms.get_message_by_hash(file) ms.delete_message(msg['Message-ID'])