Information technology tools and resources at the UW
Regular expressions in Mailman
- On This Page
- Regular expressions explained
- Common uses of regular expressions in Mailman
- Settings that use Regular Expressions
Regular expressions explained
Regular expressions are used within the Python programming language (which is what Mailman is written in) and other programming languages to specify rules for matching strings of text. In other words, you can use regular expressions to match text in incoming email messages. The settings in which you use the regular expressions will tell Mailman what to do with messages that have matching text.
The settings in Mailman that will accept regular expressions will also accept non-regular expression text so there needs to be a way for Mailman to know whether the text that is entered is a regular expression or not. To specify that the text is a regular expression, begin the line with ^.
Common uses of regular expressions in Mailman
Specify domains that are allowed to post
The most common use of regular expressions in Mailman is to specify entire domains that can and cannot post messages to your list. For example, to allow all addresses in the washington.edu domain, even those addresses that are not subscribed, to post messages without moderation to your list, go to Privacy Options and then the Sender filters sub-category and enter the following regular expression in the accept_these_nonmembers setting:
The ^ specifies that the string is a regular expression. The .* specifies that any text that comes before the “washington.edu” part of the email address of the sender is acceptable. For example, email@example.com, firstname.lastname@example.org, and email@example.com will all match the regular expression. The \ specifies that the subsequent period is part of the text of the string you want to match and not a special character that can be used in regular expressions. The $ specifies that it is the end of the string.
Please be aware that spammers often forge the headers of spam email. If the forged From header is set to an email address ending in washington.edu, that message will be able to get through to your list. If you are concerned about spam on your list, see the How can I avoid spam on my Mailman list? FAQ.
Specify domains that are not allowed to post
To ban an entire domain from being able to post to your list and have Mailman automatically discard all messages from that domain, enter the following regular expression in the discard_these_nonmembers setting on the Privacy Options category → Sender filters subsection of the admin pages:
where “domain” is the domain you want to block.
Ban non-UW email addresses from subscribing
If you want to ban all non-UW email addresses from subscribing to your list, enter the following regular expression in the ban_list setting on the Privacy Options category → Subscription Rules subsection of the admin pages:
As you can see, this regular expression is a little more complex than the preceding ones. This regular expression is known as a negative lookahead and is telling Mailman to match subscribing email addresses that don’t end in “washington.edu” and to ban those matching email addresses.
There are many more uses of regular expressions. This page was not designed to go into all of the uses; it is only meant to give you a simple overview of how regular expressions are used in Mailman. For more information on specific settings that may use regular expressions, look through the other Mailman help pages on this website, especially the Frequently Asked Questions. While not necessarily mentioning the term “regular expression,” the other pages still contain information on how to accomplish specific tasks by using regular expressions.
Settings that use regular expressions
The following settings in Mailman will accept regular expressions:
- ban_list (Privacy Options category → Subscription Rules subsection)
- accept_these_nonmembers (Privacy Options category → Sender Filters subsection)
- hold_these_nonmembers (Privacy Options category → Sender Filters subsection)
- reject_these_nonmembers (Privacy Options category → Sender Filters subsection)
- discard_these_nonmembers (Privacy Options category → Sender Filters subsection)
- acceptable_aliases (Privacy Options category → Recipient Filters subsection)
- header_filter_rules (Privacy Options category → Spam Filters subsection)
- bounce_matching_headers (Privacy Options category → Spam Filters subsection)