[Mailman-Developers] Re: trimming Cc with mailman on reply to all

Barry A. Warsaw barry@python.org
Fri, 13 Sep 2002 19:22:57 -0400


>>>>> "MM" == Marc MERLIN <marc_news@merlins.org> writes:

    MM> Correct, so for one list member a reply to all will generate
    MM> multiple messages, but receipients will only get one if they
    MM> have nodupes enabled (which is a default) The idea is that for
    MM> everyone else on the list side, the Cc doesn't keep growing.

I'm nearly convinced. :)

    >> that the (noduped) cc'd member will get a message with a
    >> different recipient list than what the rest of the list
    >> membership gets?

    MM> I think it's acceptable.  In order not to make mailman look
    MM> more complex than it already is and add yet another option,
    MM> I'd be tempted to just remove from the Cc line every member
    MM> that is subscribed to the list and that has nodupes enabled.

+1

    MM> I think that would take care of it, it should be up to the
    MM> people in the Cc to decide whether they want their address
    MM> stripped from the Cc line, not from the member who receives
    MM> the Email.

    MM> Would you agree?

Yes.  Note that the dup avoidance logic suppresses dups for members in
the To, CC, Resent-To, and Resent-Cc headers, but I think I only want
to remove addresses from the Cc headers.  For one thing, it makes the
code simpler and for another I think the Cc headers are the biggest
culprit.

Attached is a patch to AvoidDuplicates.py that seems to accomplish
this.  Any objections if I just check this in?

-Barry

-------------------- snip snip --------------------
Index: AvoidDuplicates.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Handlers/AvoidDuplicates.py,v
retrieving revision 2.0
diff -u -r2.0 AvoidDuplicates.py
--- AvoidDuplicates.py	5 Mar 2002 05:08:45 -0000	2.0
+++ AvoidDuplicates.py	13 Sep 2002 23:22:37 -0000
@@ -24,7 +24,7 @@
 
 from Mailman import mm_cfg
 
-from email.Utils import getaddresses
+from email.Utils import getaddresses, formataddr
 
 
 
@@ -33,15 +33,29 @@
     # Short circuit
     if not recips:
         return
-    # Figure out the set of explicit recipients
+    # Seed this set with addresses we don't care about dup avoiding
     explicit_recips = {}
+    listaddrs = [mlist.GetListEmail(), mlist.GetBouncesEmail(),
+                 mlist.GetOwnerEmail(), mlist.GetRequestEmail()]
+    for addr in listaddrs:
+        explicit_recips[addr] = 1
+    # Figure out the set of explicit recipients
+    ccaddrs = {}
     for header in ('to', 'cc', 'resent-to', 'resent-cc'):
-        for name, addr in getaddresses(msg.get_all(header, [])):
+        addrs = getaddresses(msg.get_all(header, []))
+        if header == 'cc':
+            for name, addr in addrs:
+                ccaddrs[addr] = name, addr
+        for name, addr in addrs:
             if not addr:
                 continue
+            # Ignore the list addresses for purposes of dup avoidance
             explicit_recips[addr] = 1
+    # Now strip out the list addresses
+    for addr in listaddrs:
+        del explicit_recips[addr]
     if not explicit_recips:
-        # No one was explicitly addressed, so we can do any dup collapsing
+        # No one was explicitly addressed, so we can't do any dup collapsing
         return
     newrecips = []
     for r in recips:
@@ -60,6 +74,8 @@
             if send_duplicate:
                 msgdata.setdefault('add-dup-header', {})[r] = 1
                 newrecips.append(r)
+            elif ccaddrs.has_key(r):
+                del ccaddrs[r]
         else:
             # Otherwise, this is the first time they've been in the recips
             # list.  Add them to the newrecips list and flag them as having
@@ -67,3 +83,6 @@
             newrecips.append(r)
     # Set the new list of recipients
     msgdata['recips'] = newrecips
+    del msg['cc']
+    for item in ccaddrs.values():
+        msg['cc'] = formataddr(item)