From 86f00a6cec71753952d1290bdadd836fdba5fdc1 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Sat, 29 Dec 2007 19:53:23 -0500 Subject: Port the maximum message size check to a rule. Add doctest. Rename the implicit.txt doctest. specialized_message_from_string(): Mimic the way the text->message parser will include the size of the original text as an attribute on the message object. The maximum message size rule will use this information. --- Mailman/docs/hold.txt | 22 ------------ Mailman/docs/implicit-dest.txt | 77 ++++++++++++++++++++++++++++++++++++++++++ Mailman/docs/implicit.txt | 77 ------------------------------------------ Mailman/docs/max-size.txt | 41 ++++++++++++++++++++++ 4 files changed, 118 insertions(+), 99 deletions(-) create mode 100644 Mailman/docs/implicit-dest.txt delete mode 100644 Mailman/docs/implicit.txt create mode 100644 Mailman/docs/max-size.txt (limited to 'Mailman/docs') diff --git a/Mailman/docs/hold.txt b/Mailman/docs/hold.txt index ed3fabdf0..16948331f 100644 --- a/Mailman/docs/hold.txt +++ b/Mailman/docs/hold.txt @@ -96,28 +96,6 @@ Just a bit of clean up. >>> mlist.bounce_matching_headers = None -Message size ------------- - -Mailman can hold messages that are bigger than a given size. Generally this -is used to prevent huge attachments from getting posted to the list. This -value is calculated in terms of KB (1024 bytes). - - >>> mlist.max_message_size = 1 - >>> one_line = 'x' * 79 - >>> big_body = '\n'.join([one_line] * 15) - >>> msg = message_from_string("""\ - ... From: aperson@example.com - ... To: _xtest@example.com - ... - ... """ + big_body) - >>> process(mlist, msg, {}) - Traceback (most recent call last): - ... - MessageTooBig - >>> clear() - - X Hold Notifications X ------------------ X diff --git a/Mailman/docs/implicit-dest.txt b/Mailman/docs/implicit-dest.txt new file mode 100644 index 000000000..b6fed2769 --- /dev/null +++ b/Mailman/docs/implicit-dest.txt @@ -0,0 +1,77 @@ +Implicit destination +==================== + +The 'implicit-dest' rule matches when the mailing list's posting address is +not explicitly mentioned in the set of message recipients. + + >>> from Mailman.configuration import config + >>> mlist = config.db.list_manager.create(u'_xtest@example.com') + >>> from Mailman.app.rules import find_rule + >>> rule = find_rule('implicit-dest') + >>> rule.name + 'implicit-dest' + +This rule matches messages that have implicit destination, meaning that the +mailing list's posting address isn't included in the explicit recipients. + + >>> mlist.require_explicit_destination = True + >>> mlist.acceptable_aliases = u'' + >>> msg = message_from_string(u"""\ + ... From: aperson@example.org + ... Subject: An implicit message + ... + ... """) + >>> rule.check(mlist, msg, {}) + True + +You can disable implicit destination checks for the mailing list. + + >>> mlist.require_explicit_destination = False + >>> rule.check(mlist, msg, {}) + False + +Even with some recipients, if the posting address is not included, the rule +will match. + + >>> mlist.require_explicit_destination = True + >>> msg['To'] = 'myfriend@example.com' + >>> rule.check(mlist, msg, {}) + True + +Add the posting address as a recipient and the rule will no longer match. + + >>> msg['Cc'] = '_xtest@example.com' + >>> rule.check(mlist, msg, {}) + False + +Alternatively, if one of the acceptable aliases is in the recipients list, +then the rule will not match. + + >>> del msg['cc'] + >>> rule.check(mlist, msg, {}) + True + >>> mlist.acceptable_aliases = u'myfriend@example.com' + >>> rule.check(mlist, msg, {}) + False + +A message gated from NNTP will obviously have an implicit destination. Such +gated messages will not be held for implicit destination because it's assumed +that Mailman pulled it from the appropriate news group. + + >>> rule.check(mlist, msg, dict(fromusenet=True)) + False + + +Alias patterns +-------------- + +It's also possible to specify an alias pattern, i.e. a regular expression to +match against the recipients. For example, we can say that if there is a +recipient in the example.net domain, then the rule does not match. + + >>> mlist.acceptable_aliases = u'^.*@example.net' + >>> rule.check(mlist, msg, {}) + True + >>> msg['To'] = 'you@example.net' + >>> rule.check(mlist, msg, {}) + False diff --git a/Mailman/docs/implicit.txt b/Mailman/docs/implicit.txt deleted file mode 100644 index 967ddc8c7..000000000 --- a/Mailman/docs/implicit.txt +++ /dev/null @@ -1,77 +0,0 @@ -Implicit destination -==================== - -The 'implicit-dest' rule matches when the mailing list's posting address is -not explicitly mentioned in the set of message recipients. - - >>> from Mailman.configuration import config - >>> mlist = config.db.list_manager.create(u'_xtest@example.com') - >>> from Mailman.app.rules import find_rule - >>> rule = find_rule('implicit-dest') - >>> rule.name - 'implicit-dest' - -Mailman will hold messages that have implicit destination, meaning that the -mailing list's posting address isn't included in the explicit recipients. - - >>> mlist.require_explicit_destination = True - >>> mlist.acceptable_aliases = u'' - >>> msg = message_from_string(u"""\ - ... From: aperson@example.org - ... Subject: An implicit message - ... - ... """) - >>> rule.check(mlist, msg, {}) - True - -You can disable implicit destination checks for the mailing list. - - >>> mlist.require_explicit_destination = False - >>> rule.check(mlist, msg, {}) - False - -Even with some recipients, if the posting address is not included, the rule -will match. - - >>> mlist.require_explicit_destination = True - >>> msg['To'] = 'myfriend@example.com' - >>> rule.check(mlist, msg, {}) - True - -Add the posting address as a recipient and the rule will no longer match. - - >>> msg['Cc'] = '_xtest@example.com' - >>> rule.check(mlist, msg, {}) - False - -Alternatively, if one of the acceptable aliases is in the recipients list, -then the rule will not match. - - >>> del msg['cc'] - >>> rule.check(mlist, msg, {}) - True - >>> mlist.acceptable_aliases = u'myfriend@example.com' - >>> rule.check(mlist, msg, {}) - False - -A message gated from NNTP will obviously have an implicit destination. Such -gated messages will not be held for implicit destination because it's assumed -that Mailman pulled it from the appropriate news group. - - >>> rule.check(mlist, msg, dict(fromusenet=True)) - False - - -Alias patterns --------------- - -It's also possible to specify an alias pattern, i.e. a regular expression to -match against the recipients. For example, we can say that if there is a -recipient in the example.net domain, then the rule does not match. - - >>> mlist.acceptable_aliases = u'^.*@example.net' - >>> rule.check(mlist, msg, {}) - True - >>> msg['To'] = 'you@example.net' - >>> rule.check(mlist, msg, {}) - False diff --git a/Mailman/docs/max-size.txt b/Mailman/docs/max-size.txt new file mode 100644 index 000000000..b477ecd2b --- /dev/null +++ b/Mailman/docs/max-size.txt @@ -0,0 +1,41 @@ +Message size +============ + +The 'message-size' rule matches when the posted message is bigger than a +specified maximum. Generally this is used to prevent huge attachments from +getting posted to the list. This value is calculated in terms of KB (1024 +bytes). + + >>> from Mailman.configuration import config + >>> mlist = config.db.list_manager.create(u'_xtest@example.com') + >>> from Mailman.app.rules import find_rule + >>> rule = find_rule('max-size') + >>> rule.name + 'max-size' + +For example, setting the maximum message size to 1 means that any message +bigger than that will match the rule. + + >>> mlist.max_message_size = 1 # 1024 bytes + >>> one_line = u'x' * 79 + >>> big_body = u'\n'.join([one_line] * 15) + >>> msg = message_from_string(u"""\ + ... From: aperson@example.com + ... To: _xtest@example.com + ... + ... """ + big_body) + >>> rule.check(mlist, msg, {}) + True + +Setting the maximum message size to zero means no size check is performed. + + >>> mlist.max_message_size = 0 + >>> rule.check(mlist, msg, {}) + False + +Of course, if the maximum size is larger than the message's size, then it's +still okay. + + >>> mlist.max_message_size = msg.original_size/1024.0 + 1 + >>> rule.check(mlist, msg, {}) + False -- cgit v1.3.1