[Mailman-Developers] RFC 2822 complicance (was Re: 2.0.x qrunner bug (bad one))

Jason R. Mastaler jason-list-mailman-developers@mastaler.com
Thu, 04 Apr 2002 11:10:51 -0700


--=-=-=

Norbert Bollow <nb@thinkcoach.com> writes:

> With other words, given that the Message-ID: header is a SHOULD, if
> you want to choose a diffferent course, you (as maintainer of
> Mailman) have a responsibility to understand and carefully consider
> the full implications of not adding a Message-ID: header to messages
> that are _originated_ by Mailman.

[...]

> I think it's probably much less work to just add the header than to
> "understand" and "carefully weigh" all these implications.

The attached patch (for MM 2.0.x) adds a Message-ID header to messages
which lack one.  Utils.make_msgid() is just a Python 1.x compatible
rendition of the same function that is part of the latest email
package.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=mm209.diff

Index: Mailman/Message.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Message.py,v
retrieving revision 1.40.2.2
diff -u -u -r1.40.2.2 Message.py
--- Mailman/Message.py	3 Apr 2002 22:40:41 -0000	1.40.2.2
+++ Mailman/Message.py	4 Apr 2002 18:05:34 -0000
@@ -196,10 +196,14 @@
         # make sure that the first line does NOT contain a colon!
         Message.__init__(self, StringIO(text))
         # RFC 2822 requires a Date: header, and while most MTAs add one if
-        # it's missing, Qmail does not.
+        # it's missing, qmail does not.
         if not self.get('date'):
             self['Date'] = Utils.formatdate(localtime=1)
-
+        # RFC 2822 recommends a Message-ID: header, and while most
+        # MTAs add one if it's missing, qmail does not.
+        if not self.get('message-id'):
+            self['Message-ID'] = Utils.make_msgid(idstring='Mailman')
+        
 
 
 class UserNotification(OutgoingMessage):
Index: Mailman/Utils.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Utils.py,v
retrieving revision 1.104.2.5
diff -u -u -r1.104.2.5 Utils.py
--- Mailman/Utils.py	3 Apr 2002 22:47:12 -0000	1.104.2.5
+++ Mailman/Utils.py	4 Apr 2002 18:05:34 -0000
@@ -28,6 +28,8 @@
 import string
 import re
 import time
+import socket
+import random
 from UserDict import UserDict
 from types import StringType
 import random
@@ -737,3 +739,28 @@
          'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now[1] - 1],
         now[0], now[3], now[4], now[5],
         zone)
+
+
+
+def make_msgid(idstring=None):
+    """Returns a string suitable for RFC 2822 compliant Message-ID:, e.g:
+
+    <20020201195627.33539.96671@nightshade.la.mastaler.com>
+
+    Optional idstring if given is a string used to strengthen the
+    uniqueness of the Message-ID, otherwise an empty string is used.
+    """
+    timeval = time.time()
+    utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval))
+    pid = os.getpid()
+    randint = random.randrange(100000)
+    if idstring is None:
+        idstring = ''
+    else:
+        idstring = '.' + idstring
+    try:
+        idhost = socket.getfqdn()
+    except AttributeError:
+        idhost = socket.gethostbyaddr(socket.gethostname())[0]
+    msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, idhost)
+    return msgid

--=-=-=--