|
Included on this page:
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 ohio.edu domain to post
messages without moderation to your list, even those addresses that are
not subscribed, enter the following regular expression in the
accept_these_nonmembers setting on the Privacy Options
category → Sender filters subsection of the admin pages:
^.*ohiou?\.edu$
The "^" specifies that the string is a regular expression. The ".*"
specifies that any text that comes before the "ohio.edu" part of the
email address of the sender is acceptable. For example,
bob@u.ohio.edu, joe@cac.ohio.edu, and
sally@ocean.ohio.edu will all match the regular expression.
The "u?" accepts from the ohiou.edu domain. The "\"
specifies that the subsequent period is part of the text of the string you
want to match and not the "." 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
ohio.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:
^.*domain$
where "domain" is the domain you want to block.
Ban non-Ohio University email addresses from subscribing
If you want to ban all non-Ohio University 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:
^(?!.*ohiou?\.edu$)
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 either "ohio.edu" or "ohiou.edu" and to ban those matching email addresses.
Other uses
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 Web site, especially the FAQs. While not necessarily mentioning
the term "regular expression," the other pages still contain information
on how to accomplish specific tasks by using regular expressions.
For more general information on regular expressions within Python, see
Python's Regular
Expression Operations and the Regular Expression HOWTO.
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)
|