------------------------------------------------------------
revno: 1281
committer: Mark Sapiro <m...@msapiro.net>
branch nick: 2.2
timestamp: Fri 2013-09-27 16:34:42 -0700
message:
  Made author_is_list a 3-way with an option to wrap the message.
added:
  Mailman/Handlers/WrapMessage.py
modified:
  Mailman/Defaults.py.in
  Mailman/Gui/General.py
  Mailman/Handlers/AvoidDuplicates.py
  Mailman/Handlers/Cleanse.py
  Mailman/Handlers/CleanseDKIM.py
  Mailman/Handlers/CookHeaders.py
  Mailman/Handlers/Tagger.py
  NEWS


--
lp:mailman/2.2
https://code.launchpad.net/~mailman-coders/mailman/2.2

Your team Mailman Checkins is subscribed to branch lp:mailman/2.2.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mailman-coders/mailman/2.2/+edit-subscription
=== modified file 'Mailman/Defaults.py.in'
--- Mailman/Defaults.py.in	2013-07-19 21:40:31 +0000
+++ Mailman/Defaults.py.in	2013-09-27 23:34:42 +0000
@@ -561,7 +561,7 @@
 # broken and even if the outgoing message is resigned.  However, some sites
 # may wish to remove these headers.  Possible values and meanings are:
 # No, 0, False -> do not remove headers.
-# 1 -> remove headers only if the list's author_is_list setting is Yes.
+# 1 -> remove headers only if the list's author_is_list setting is 1.
 # Yes, 2, True -> always remove headers.
 REMOVE_DKIM_HEADERS = No
 
@@ -594,6 +594,7 @@
     # (outgoing) path, finally leaving the message in the outgoing queue.
     'AfterDelivery',
     'Acknowledge',
+    'WrapMessage',
     'ToOutgoing',
     ]
 
@@ -1079,9 +1080,13 @@
 # Send goodbye messages to unsubscribed members?
 DEFAULT_SEND_GOODBYE_MSG = Yes
 
-# Rewrite the From: header of posts replacing the posters address with
-# that of the list.  Also see REMOVE_DKIM_HEADERS above.
-DEFAULT_AUTHOR_IS_LIST = No
+# The following is a three way setting.
+# 0 -> Do not rewrite the From: or wrap the message.
+# 1 -> Rewrite the From: header of posts replacing the posters address with
+#      that of the list.  Also see REMOVE_DKIM_HEADERS above.
+# 2 -> Do not modify the From: of the message, but wrap the message in an outer
+#      message From the list address.
+DEFAULT_AUTHOR_IS_LIST = 0
 
 # Wipe sender information, and make it look like the list-admin
 # address sends all messages

=== modified file 'Mailman/Gui/General.py'
--- Mailman/Gui/General.py	2013-07-19 19:39:28 +0000
+++ Mailman/Gui/General.py	2013-09-27 23:34:42 +0000
@@ -157,14 +157,18 @@
 
         if mm_cfg.ALLOW_AUTHOR_IS_LIST:
             rtn.append(
-                ('author_is_list', mm_cfg.Radio, (_('No'), _('Yes')), 0,
+                ('author_is_list', mm_cfg.Radio,
+                 (_('No'), _('Mung From'), _('Wrap Message')), 0,
                  _("""Replace the sender with the list address to conform with
                  policies like ADSP and DMARC.  It replaces the poster's
                  address in the From: header with the list address and adds the
                  poster to the Reply-To: header, but the anonymous_list and
                  Reply-To: header munging settings below take priority.  If
                  setting this to Yes, it is advised to set the MTA to DKIM sign
-                 all emails."""))
+                 all emails.""") +
+                 _("""<br>If this is set to Wrap Message, just wrap the message
+                 in an outer message From: the list with Content-Type:
+                 message/rfc822."""))
               )
 
         rtn.extend([

=== modified file 'Mailman/Handlers/AvoidDuplicates.py'
--- Mailman/Handlers/AvoidDuplicates.py	2008-12-03 01:11:33 +0000
+++ Mailman/Handlers/AvoidDuplicates.py	2013-09-27 23:34:42 +0000
@@ -24,6 +24,7 @@
 
 from email.Utils import getaddresses, formataddr
 from Mailman import mm_cfg
+from Mailman.Handlers.CookHeaders import change_header
 
 COMMASPACE = ', '
 
@@ -95,6 +96,10 @@
     # Set the new list of recipients
     msgdata['recips'] = newrecips
     # RFC 2822 specifies zero or one CC header
-    del msg['cc']
     if ccaddrs:
-        msg['Cc'] = COMMASPACE.join([formataddr(i) for i in ccaddrs.values()])
+        change_header('Cc',
+        COMMASPACE.join([formataddr(i) for i in ccaddrs.values()]),
+        mlist, msg, msgdata)
+    else:
+        del msg['cc']
+

=== modified file 'Mailman/Handlers/Cleanse.py'
--- Mailman/Handlers/Cleanse.py	2013-07-19 19:39:28 +0000
+++ Mailman/Handlers/Cleanse.py	2013-09-27 23:34:42 +0000
@@ -39,26 +39,6 @@
     del msg['x-approve']
     # Also remove this header since it can contain a password
     del msg['urgent']
-    # Do we change the from so the list takes ownership of the email
-    # This really belongs in CookHeaders.
-    if mm_cfg.ALLOW_AUTHOR_IS_LIST and mlist.author_is_list:
-        realname, email = parseaddr(msg['from'])
-        replies = getaddresses(msg.get('reply-to', ''))
-        reply_addrs = [x[1].lower() for x in replies]
-        if reply_addrs:
-            if email.lower() not in reply_addrs:
-                rt = msg['reply-to'] + ', ' + msg['from']
-            else:
-                rt = msg['reply-to']
-        else:
-            rt = msg['from']
-        del msg['reply-to']
-        msg['Reply-To'] = rt
-        del msg['from']
-        msg['From'] = formataddr(('%s via %s' % (realname, mlist.real_name),
-                                 mlist.GetListEmail()))
-        del msg['sender']
-        #MAS mlist.include_sender_header = 0
     # We remove other headers from anonymous lists
     if mlist.anonymous_list:
         syslog('post', 'post to %s from %s anonymized',

=== modified file 'Mailman/Handlers/CleanseDKIM.py'
--- Mailman/Handlers/CleanseDKIM.py	2013-07-19 19:39:28 +0000
+++ Mailman/Handlers/CleanseDKIM.py	2013-09-27 23:34:42 +0000
@@ -33,7 +33,7 @@
         return
     if (mm_cfg.ALLOW_AUTHOR_IS_LIST and
             mm_cfg.REMOVE_DKIM_HEADERS == 1 and
-            not mlist.author_is_list):
+            mlist.author_is_list != 1):
         return
     del msg['domainkey-signature']
     del msg['dkim-signature']

=== modified file 'Mailman/Handlers/CookHeaders.py'
--- Mailman/Handlers/CookHeaders.py	2013-07-19 19:39:28 +0000
+++ Mailman/Handlers/CookHeaders.py	2013-09-27 23:34:42 +0000
@@ -64,13 +64,20 @@
         charset = 'us-ascii'
     return Header(s, charset, maxlinelen, header_name, continuation_ws)
 
+def change_header(name, value, mlist, msg, msgdata, delete=True, repl=True):
+    if mm_cfg.ALLOW_AUTHOR_IS_LIST and mlist.author_is_list == 2:
+        msgdata.setdefault('add_header', {})[name] = value
+    elif repl or not msg.has_key(name):
+        if delete:
+            del msg[name]
+        msg[name] = value
+
 
 
 def process(mlist, msg, msgdata):
     # Set the "X-Ack: no" header if noack flag is set.
     if msgdata.get('noack'):
-        del msg['x-ack']
-        msg['X-Ack'] = 'no'
+        change_header('X-Ack', 'no', mlist, msg, msgdata)
     # Because we're going to modify various important headers in the email
     # message, we want to save some of the information in the msgdata
     # dictionary for later.  Specifically, the sender header will get waxed,
@@ -87,7 +94,8 @@
             pass
     # Mark message so we know we've been here, but leave any existing
     # X-BeenThere's intact.
-    msg['X-BeenThere'] = mlist.GetListEmail()
+    change_header('X-BeenThere', mlist.GetListEmail(),
+                  mlist, msg, msgdata, delete=False)
     # Add Precedence: and other useful headers.  None of these are standard
     # and finding information on some of them are fairly difficult.  Some are
     # just common practice, and we'll add more here as they become necessary.
@@ -101,12 +109,32 @@
     # known exploits in a particular version of Mailman and we know a site is
     # using such an old version, they may be vulnerable.  It's too easy to
     # edit the code to add a configuration variable to handle this.
-    if not msg.has_key('x-mailman-version'):
-        msg['X-Mailman-Version'] = mm_cfg.VERSION
+    change_header('X-Mailman-Version', mm_cfg.VERSION,
+                  mlist, msg, msgdata, repl=False)
     # We set "Precedence: list" because this is the recommendation from the
     # sendmail docs, the most authoritative source of this header's semantics.
-    if not msg.has_key('precedence'):
-        msg['Precedence'] = 'list'
+    change_header('Precedence', 'list',
+                  mlist, msg, msgdata, repl=False)
+    # Do we change the from so the list takes ownership of the email
+    if mm_cfg.ALLOW_AUTHOR_IS_LIST and mlist.author_is_list:
+        realname, email = parseaddr(msg['from'])
+        replies = getaddresses(msg.get('reply-to', ''))
+        reply_addrs = [x[1].lower() for x in replies]
+        if reply_addrs:
+            if email.lower() not in reply_addrs:
+                rt = msg['reply-to'] + ', ' + msg['from']
+            else:
+                rt = msg['reply-to']
+        else:
+            rt = msg['from']
+        change_header('Reply-To', rt, mlist, msg, msgdata)
+        change_header('From',
+                      formataddr(('%s via %s' % (realname, mlist.real_name),
+                                 mlist.GetListEmail())),
+                      mlist, msg, msgdata)
+        if mlist.author_is_list != 2:
+            del msg['sender']
+        #MAS ?? mlist.include_sender_header = 0
     # Reply-To: munging.  Do not do this if the message is "fast tracked",
     # meaning it is internally crafted and delivered to a specific user.  BAW:
     # Yuck, I really hate this feature but I've caved under the sheer pressure
@@ -142,12 +170,14 @@
         if mlist.reply_goes_to_list == 1:
             i18ndesc = uheader(mlist, mlist.description, 'Reply-To')
             add((str(i18ndesc), mlist.GetListEmail()))
-        del msg['reply-to']
         # Don't put Reply-To: back if there's nothing to add!
         if new:
             # Preserve order
-            msg['Reply-To'] = COMMASPACE.join(
-                [formataddr(pair) for pair in new])
+            change_header('Reply-To', 
+                          COMMASPACE.join([formataddr(pair) for pair in new]),
+                          mlist, msg, msgdata)
+        else:
+            del msg['reply-to']
         # The To field normally contains the list posting address.  However
         # when messages are fully personalized, that header will get
         # overwritten with the address of the recipient.  We need to get the
@@ -170,6 +200,9 @@
                 add(pair)
             i18ndesc = uheader(mlist, mlist.description, 'Cc')
             add((str(i18ndesc), mlist.GetListEmail()))
+            # We don't worry about what AvoidDuplicates may have done with a
+            # Cc: header or using change_header here since we never get here
+            # if author_is_list is allowed and True.
             del msg['Cc']
             msg['Cc'] = COMMASPACE.join([formataddr(pair) for pair in new])
     # Add list-specific headers as defined in RFC 2369 and RFC 2919, but only
@@ -193,8 +226,7 @@
         # without desc we need to ensure the MUST brackets
         listid_h = '<%s>' % listid
     # We always add a List-ID: header.
-    del msg['list-id']
-    msg['List-Id'] = listid_h
+    change_header('List-Id', listid_h, mlist, msg, msgdata)
     # For internally crafted messages, we also add a (nonstandard),
     # "X-List-Administrivia: yes" header.  For all others (i.e. those coming
     # from list posts), we add a bunch of other RFC 2369 headers.
@@ -221,13 +253,12 @@
     # First we delete any pre-existing headers because the RFC permits only
     # one copy of each, and we want to be sure it's ours.
     for h, v in headers.items():
-        del msg[h]
         # Wrap these lines if they are too long.  78 character width probably
         # shouldn't be hardcoded, but is at least text-MUA friendly.  The
         # adding of 2 is for the colon-space separator.
         if len(h) + 2 + len(v) > 78:
             v = CONTINUATION.join(v.split(', '))
-        msg[h] = v
+        change_header(h, v, mlist, msg, msgdata)
 
 
 
@@ -304,8 +335,7 @@
                     h = u' '.join([prefix, subject])
             h = h.encode('us-ascii')
             h = uheader(mlist, h, 'Subject', continuation_ws=ws)
-            del msg['subject']
-            msg['Subject'] = h
+            change_header('Subject', h, mlist, msg, msgdata)
             ss = u' '.join([recolon, subject])
             ss = ss.encode('us-ascii')
             ss = uheader(mlist, ss, 'Subject', continuation_ws=ws)
@@ -323,8 +353,7 @@
     # TK: Subject is concatenated and unicode string.
     subject = subject.encode(cset, 'replace')
     h.append(subject, cset)
-    del msg['subject']
-    msg['Subject'] = h
+    change_header('Subject', h, mlist, msg, msgdata)
     ss = uheader(mlist, recolon, 'Subject', continuation_ws=ws)
     ss.append(subject, cset)
     msgdata['stripped_subject'] = ss

=== modified file 'Mailman/Handlers/Tagger.py'
--- Mailman/Handlers/Tagger.py	2011-11-17 21:00:25 +0000
+++ Mailman/Handlers/Tagger.py	2013-09-27 23:34:42 +0000
@@ -27,6 +27,7 @@
 
 from Mailman import Utils
 from Mailman.Logging.Syslog import syslog
+from Mailman.Handlers.CookHeaders import change_header
 
 OR = '|'
 CRNL = '\r\n'
@@ -71,8 +72,9 @@
                 break
     if hits:
         msgdata['topichits'] = hits.keys()
-        msg['X-Topics'] = NLTAB.join(hits.keys())
-    
+        change_header('X-Topics', NLTAB.join(hits.keys()),
+                      mlist, msg, msgdata, Delete=False)
+
 
 
 def scanbody(msg, numlines=None):

=== added file 'Mailman/Handlers/WrapMessage.py'
--- Mailman/Handlers/WrapMessage.py	1970-01-01 00:00:00 +0000
+++ Mailman/Handlers/WrapMessage.py	2013-09-27 23:34:42 +0000
@@ -0,0 +1,57 @@
+# Copyright (C) 2013 by the Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+"""Wrap the message in an outer message/rfc822 part and transfer/add
+some headers from the original.
+"""
+
+import copy
+
+from Mailman import mm_cfg
+from Mailman.Utils import unique_message_id
+from Mailman.Message import Message
+
+# Headers from the original that we want to keep in the wrapper.
+KEEPERS = ('to',
+           'in-reply-to',
+           'references',
+           'x-mailman-approved-at',
+          )
+
+
+
+def process(mlist, msg, msgdata):
+    if not mm_cfg.ALLOW_AUTHOR_IS_LIST or mlist.author_is_list != 2:
+        return
+
+    # There are various headers in msg that we don't want, so we basically
+    # make a copy of the msg, then delete almost everything and set/copy
+    # what we want.
+    omsg = copy.deepcopy(msg)
+    for key in msg.keys():
+        if key.lower() not in KEEPERS:
+            del msg[key]
+    msg['MIME-Version'] = '1.0'
+    msg['Content-Type'] = 'message/rfc822'
+    msg['Content-Disposition'] = 'inline'
+    msg['Message-ID'] = unique_message_id(mlist)
+    # Add the headers from CookHeaders.
+    for k, v in msgdata['add_header'].items():
+        msg[k] = v
+    # And set the payload.
+    msg.set_payload(omsg.as_string())
+

=== modified file 'NEWS'
--- NEWS	2013-08-11 18:21:38 +0000
+++ NEWS	2013-09-27 23:34:42 +0000
@@ -53,13 +53,19 @@
  
   New Features
  
-    - There is a new list attribute author_is_list to rewrite the From: header
-      of posts replacing the posters address with that of the list for
-      compatability with DMARC and or ADSP.  There is a new mm_cfg.py setting
+    - There is a new list attribute author_is_list to either rewrite the From:
+      header of posts replacing the posters address with that of the list or
+      wrap the message in an outer message From: the list for compatability
+      with DMARC and or ADSP.  There is a new mm_cfg.py setting
       DEFAULT_AUTHOR_IS_LIST to control the default for new lists, and the
       existing REMOVE_DKIM_HEADERS setting has been extended to allow removing
-      those headers only for author_is_list = Yes lists.  This feature must be
-      enabled by setting ALLOW_AUTHOR_IS_LIST to Yes in mm_cfg.py.
+      those headers only for certain author_is_list lists.  This feature must
+      be enabled by setting ALLOW_AUTHOR_IS_LIST to Yes in mm_cfg.py.  See the 
+      description of these settings in Defaults.py for more detail.  This
+      feature is experimental in 2.1.16, and it is subject to change or to
+      become just one of the two methods in a subsequent release. People 
+      interested in this feature are encouraged to try it and report their
+      experiences to the mailman-us...@python.org list.
 
     - There is a new DISPLAY_HELD_SUMMARY_SORT_BUTTONS setting which if set
       in mm_cfg.py will display a set of radio buttons in the admindb held

_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to