[Python-checkins] r86936 - in python/branches/py3k: Doc/library/email.util.rst Lib/email/test/test_email.py Lib/email/utils.py Misc/ACKS Misc/NEWS

r.david.murray python-checkins at python.org
Thu Dec 2 22:47:19 CET 2010


Author: r.david.murray
Date: Thu Dec  2 22:47:19 2010
New Revision: 86936

Log:
#8989: add 'domain' keyword to make_msgid.

Patch by Adrian von Bidder.


Modified:
   python/branches/py3k/Doc/library/email.util.rst
   python/branches/py3k/Lib/email/test/test_email.py
   python/branches/py3k/Lib/email/utils.py
   python/branches/py3k/Misc/ACKS
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Doc/library/email.util.rst
==============================================================================
--- python/branches/py3k/Doc/library/email.util.rst	(original)
+++ python/branches/py3k/Doc/library/email.util.rst	Thu Dec  2 22:47:19 2010
@@ -105,11 +105,17 @@
    ``False``.  The default is ``False``.
 
 
-.. function:: make_msgid(idstring=None)
+.. function:: make_msgid(idstring=None, domain=None)
 
    Returns a string suitable for an :rfc:`2822`\ -compliant
    :mailheader:`Message-ID` header.  Optional *idstring* if given, is a string
-   used to strengthen the uniqueness of the message id.
+   used to strengthen the uniqueness of the message id.  Optional *domain* if
+   given provides the portion of the msgid after the '@'.  The default is the
+   local hostname.  It is not normally necessary to override this default, but
+   may be useful certain cases, such as a constructing distributed system that
+   uses a consistent domain name across multiple hosts.
+
+   .. versionchanged:: 3.2 domain keyword added
 
 
 .. function:: decode_rfc2231(s)

Modified: python/branches/py3k/Lib/email/test/test_email.py
==============================================================================
--- python/branches/py3k/Lib/email/test/test_email.py	(original)
+++ python/branches/py3k/Lib/email/test/test_email.py	Thu Dec  2 22:47:19 2010
@@ -2457,6 +2457,10 @@
     text/rfc822-headers
 """)
 
+    def test_make_msgid_domain(self):
+        self.assertEqual(
+            email.utils.make_msgid(domain='testdomain-string')[-19:],
+            '@testdomain-string>')
 
 
 # Test the iterator/generators

Modified: python/branches/py3k/Lib/email/utils.py
==============================================================================
--- python/branches/py3k/Lib/email/utils.py	(original)
+++ python/branches/py3k/Lib/email/utils.py	Thu Dec  2 22:47:19 2010
@@ -148,13 +148,15 @@
 
 
 
-def make_msgid(idstring=None):
+def make_msgid(idstring=None, domain=None):
     """Returns a string suitable for RFC 2822 compliant Message-ID, e.g:
 
     <20020201195627.33539.96671 at nightshade.la.mastaler.com>
 
     Optional idstring if given is a string used to strengthen the
-    uniqueness of the message id.
+    uniqueness of the message id.  Optional domain if given provides the
+    portion of the message id after the '@'.  It defaults to the locally
+    defined hostname.
     """
     timeval = time.time()
     utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval))
@@ -164,8 +166,9 @@
         idstring = ''
     else:
         idstring = '.' + idstring
-    idhost = socket.getfqdn()
-    msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, idhost)
+    if domain is None:
+        domain = socket.getfqdn()
+    msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, domain)
     return msgid
 
 

Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS	(original)
+++ python/branches/py3k/Misc/ACKS	Thu Dec  2 22:47:19 2010
@@ -77,6 +77,7 @@
 Steven Bethard
 Stephen Bevan
 Ron Bickers
+Adrian von Bidder
 David Binger
 Dominic Binks
 Philippe Biondi

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Dec  2 22:47:19 2010
@@ -53,6 +53,9 @@
 Library
 -------
 
+- Issue #8989: email.utils.make_msgid now has a domain parameter that can
+  override the domain name used in the generated msgid.
+
 - Issue #9299: Add exist_ok parameter to os.makedirs to suppress the
   'File exists' exception when a target directory already exists with the
   specified mode. Patch by Ray Allen.


More information about the Python-checkins mailing list