This can be done with a custom handler. See PostLimit.py for an example to be put in Mailman/Handlers/PostLimit.py, and see extend.py for a file that can be edited and put in lists/LISTNAME/extend.py to set parameters and enable this for the LISTNAME list.
See 4.67 How do I implement a custom handler in Mailman, e.g. to mung headers or filter posts based on regex searches of the message body? for more info on custom handlers.