1.12. How do I automatically delete held messages?

Beginning with Mailman 2.1.6, there is a max_days_to_hold setting on the list's General Options page which will cause held messages to be discarded after that many days. If you have so many held messages that the admindb page times out, set max_days_to_hold > 0 and the old messages will be deleted the next time cron/checkdbs runs (default 08:00 daily or you can run it manually).

For Mailman prior to 2.1.6, see the following, but only if you want to discard (un)subscribe requests too. Otherwise see FAQ 4.74 4.74 How do I manually remove held messages from the command-line?.

Did you read the paragraphs above? Everything below here is for pre 2.1.6 Mailman.

There is an alternative solution added at the bottom (by tkikuchi 08/13/2004).

There is a work-around that can be implemented on a per list basis.

On a list where you want all held messages deleted (these include attempts to subscribe, when subscribes must be approved by an admin), you can do the following:

1) Delete all current requests for the list using the web Admin. This will make the file request.db (request.pck for 2.1.5 and above) empty for that list.

2) Change directory to your lists configuration directory

  cd /home/mailman/lists/<list-name>/

3) Copy the file request.db to orig.request.db

  cp request.db orig.request.db

4) Login as the mailman user

  su mailman

5) Create a bash script to delete the held messages for the list and then replace the database file request.db with the blank one we copied in step 3:

  #!/bin/bash
  # This script removes held messages that have accumulated for a list
  # Clear out the heldmessages in ~mailman/data  then
  # Replace request.db in ~mailman/lists/<listname>/ with the original
  #
  # Example using a list named "hr"
  # rm ~/mailman/data/heldmsg-hr-* 2> /dev/null
  # cp ~mailman/lists/hr/orig.request.db ~mailman/lists/hr/request.db
  rm ~mailman/data/heldmsg-<list-name>-* 2> /dev/null
  cp ~mailman/lists/<list-name>/orig.request.db ~mailman/lists/<list-name>/request.db

  # repeat for all lists where you want held messages auto-deleted

6) Make the script executable

  chmod a+x  /home/mailman/bin/rm_held_msgs

7) Edit crontab to have the script run hourly

  crontab -e

  # Run auto-delete script to remove unwanted messages from my lists
  59 * * * *      /home/mailman/bin/rm_held_msgs

Done.

===

The Details:

Held messages are stored in ~mailman/data. You can easily read, edit, or delete them. The messages are stored in files with the name:
heldmsg- <list-name> - <number> .txt.

As an example held messages for hr would have names like this:
heldmsg-hr-97.txt
heldmsg-hr-98.txt
heldmsg-hr-99.txt
heldmsg-hr-100.txt

These files contain individual emails that were sent to your lists. Mailman stores these files here (as a sort of queue) and sends out either an immediate message or a daily message alerting the admin of the waiting messages. Mailman will also load some information from these held messages into a database for your list. The name of this database is request.db.

The amount of information Mailman loads into request.db for every message is determined by various settings in either ~mailman/Mailman/mm_cfg.py or Defaults.py

When you browse via the web-admin and look at the waiting requests, you are accessing the request.db database and not the actual files in
~mailman/data/.. For our purposes, we just want to blank out request.db.

We cannot just delete it. But it is safe to replace request.db with an empty version.

I have my lists set to NOT alert me so that I only get the daily alert from Mailman (in the web-admin under General Options):
"Should administrator get immediate notice of new requests,
as well as daily notices about collected ones" = no

The Mailman alert script then runs at exactly 5:00pm every day, so I could set the script to kick off once a day at 4:59pm and I would never get bugged about held messages (for lists in the script). Instead I like to run the script hourly at 59 minutes past the hour. The effect is the same, I just don't like letting spam hang out on my server longer than an hour.

The first active line in the script uses a redirect to get rid of warnings - just in case there are currently no held messages to be deleted. A redirect with a "2" in front of it specifically catches console warning messages:
.... 2> /dev/null # sends warnings into the bit bucket

ALTERNATIVE SOLUTION:

Apply a patch from sourceforge mailman patch area #790494. http://sourceforge.net/tracker/index.php?func=detail&aid=790494&group_id=103&atid=300103

You can specify how many days to hold the pending message and automatically discard when expires.

Note: this just implements the max_days_to_hold setting that's in 2.1.6 and above.

Converted from the Mailman FAQ Wizard

This is one of many Frequently Asked Questions.

MailmanWiki: DOC/How do I automatically delete held messages? (last edited 2015-01-31 02:36:58 by msapiro)