On 11/16/23 01:07, Thomas Ward via Mailman-users wrote:
When people are communicating on Mailman3 lists, some set up automatic responders for out-of-office, etc. and get let through the system to list recipients.
Unfortunately, this is bad behavior and appears to not be caught by default. I'd like to set up some kind of rule globally rather than per-list that would check if a message is an automatic reply (based on a set of criteria we've come up with programmatically on our previous custom implementation of lists) and then default-discard those messages.
Is there a way with custom rules to implement this? We're looking for certain strings on the subject line or other headers to determine "Discard" cases in our custom list implementations, but we are hoping we can implement this with customized rules in Mailman3 to achieve this goal. How would we structure that type of rule, and do we check the message object or the msgdata instead?
You can implement a custom rule and a custom chain to do this, but you'd
need to set that as the default chain on every existing list. Setting
the default chain can be scripted using mailman shell
pretty easily
though.
For any new lists, you can setup a custom style(s) and ensure that your new chain is the default chain for new lists.
https://gitlab.com/mailman/example-mailman-plugin/-/blob/master/example_mail...
^ is an example plugin you can use as a starting point for your plugin
and you will also see example rule at rules/rules.py
.
https://gitlab.com/mailman/mailman/-/tree/master/src/mailman/rules
The above existing rules in Mailman's source code should serve as examples on how you can look at a header or body of the email. For example, approved.py looks for certain headers (var HEADERS in the file) or iterates through the body to look for something that looks like a header too ("Approved: <password>").
Once you have the rule, you can insert it in the right place in the chain. You can use the default-posting-chain
https://gitlab.com/mailman/mailman/-/blob/master/src/mailman/chains/builtin....
as your starting point (example plugin doesn't have an example chain yet, but it would look similar to inbuilt chains, under a "chains/" directory in the plugin).
In the chain, you can also define what happens if rule matches. Rules
only return True/False, based on whether the rule matched and chain can
define if that should put the message into a separate queue (e.g.
('my-new-rule', LinkAction.jump , 'hold'), etc. or do nothing
('my-new-rule', LinkAction.defer
, None).
There are also example styles defined in the plugin
https://gitlab.com/mailman/example-mailman-plugin/-/blob/master/example_mail...
You mostly want to update posting_chain
property on the 'mlist' object
for the style.
You can find examples again in the source tree under
src/mailman/styles
directory.
To configure the default style for new lists, you can add the following to your mailman.cfg:
[styles] default: my-new-style
ref: https://docs.mailman3.org/projects/mailman/en/latest/src/mailman/config/docs...
Let us know if you have any questions on the same.
-- thanks, Abhilash Raj (maxking)