This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: email.utils.make_msgid: specify domain
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: r.david.murray Nosy List: avbidder@fortytwo.ch, eric.araujo, l0nwlf, r.david.murray
Priority: normal Keywords: patch

Created on 2010-06-13 15:15 by avbidder@fortytwo.ch, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
make_msgid-domain.diff avbidder@fortytwo.ch, 2010-06-14 18:51 review
Messages (9)
msg107734 - (view) Author: Adrian von Bidder (avbidder@fortytwo.ch) Date: 2010-06-13 15:15
Using the hostname for the domain part of a Message-Id is probably the right thing usually but users may want to override this.

Please consider this rather trivial patch:

=====
--- utils.py.orig       2010-06-13 16:59:30.533861099 +0200
+++ utils.py    2010-06-13 17:02:18.650697979 +0200
@@ -173,13 +173,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@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.  The domain part of the Message-ID
+    defaults to the locally defined hostname, but can be specified
+    explicitly.
     """
     timeval = time.time()
     utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval))
@@ -189,8 +191,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
 
 
=====

thanks & greetings
-- vbi
msg107735 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-06-13 15:20
Seems straightforward. Any reason not to allow it David?

Adrian, I edited the versions: new features go into 3.2 only. Please make sure your patch applies to this version (branch named py3k). Can you also write unit tests for this new parameter?
msg107736 - (view) Author: Shashwat Anand (l0nwlf) Date: 2010-06-13 15:49
Adrian, Could you generate the diffs from the
top level of the checkout and attach it here?
msg107767 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-06-14 00:52
This does seem like a reasonable (and backward compatible) addition to the API.  I'm only +0 on adding it, though, without at least one specific use case.  I'd want to mention that use case in the docs as an example, and stress that using the default is recommended unless you've got a good reason to do otherwise ("such as....").

Adrian, what use case(s) do you have in mind?
msg107779 - (view) Author: Adrian von Bidder (avbidder@fortytwo.ch) Date: 2010-06-14 11:11
Thanks for the positive feedback. I'll try to do the diff against top of tree and the unit test soon-ish.

Use case: 
 * In my specific case, I'm writing a sort of cross between mailing list and blog system and I'd like to use a static (across all installations) domain for internally generated messages.
 * kmail offers the choice of custom domain for message-id as well, I've set it to my own domain for ages.  It turns out that message-ids are harvested by spammers and so I've got a quite good way to build spamtraps since "nobody" will ever try to send real email to these "adresses". (Or, in the reverse case: if your host's fqdn is a valid email domain you may actually not want to cause this kind of load to your MX.)

(Not sure if this should be added to the documentation, though.  The explanation seems much too long in comparision with the complexity of the feature.)
msg107806 - (view) Author: Adrian von Bidder (avbidder@fortytwo.ch) Date: 2010-06-14 18:51
I'm sure several of you have worked with the Python source code before and know by heart how to run the testsuite.  In other words: I admit that I've only written the code and have not tried it.

Given how trivial the patch is, I have some hope ;-)
msg120993 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-12 00:24
Thanks for the patch, which looks good to me, except for the test: “eq” will raise a NameError, since this does not exist.  Other test methods bind eq to self.assertEqual to save typing, which is not really needed in your case: Just use self.assertEqual :)

To run the tests, ./python -m email.test.test_email
msg123125 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-12-02 21:51
Committed to py3k in r86936 with minor fixups.
msg123223 - (view) Author: Adrian von Bidder (avbidder@fortytwo.ch) Date: 2010-12-03 10:02
On Thursday 02 December 2010 22.51:51 you wrote:

> Committed to py3k in r86936 with minor fixups.

thanks, great!  (Wheee! my first patch to Python ;-)

cheers
-- vbi
History
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53235
2010-12-03 10:02:50avbidder@fortytwo.chsetmessages: + msg123223
2010-12-02 21:51:47r.david.murraysetstatus: open -> closed
resolution: accepted
messages: + msg123125

stage: patch review -> resolved
2010-11-12 00:24:43eric.araujosetmessages: + msg120993
stage: test needed -> patch review
2010-06-14 18:51:08avbidder@fortytwo.chsetfiles: + make_msgid-domain.diff

messages: + msg107806
2010-06-14 11:11:35avbidder@fortytwo.chsetmessages: + msg107779
2010-06-14 00:52:29r.david.murraysetassignee: r.david.murray
2010-06-14 00:52:06r.david.murraysetmessages: + msg107767
2010-06-13 15:49:12l0nwlfsetnosy: + l0nwlf
messages: + msg107736
2010-06-13 15:20:29eric.araujosettype: enhancement
versions: + Python 3.2, - Python 2.6, Python 3.1
keywords: + patch
nosy: + eric.araujo, r.david.murray

messages: + msg107735
stage: test needed
2010-06-13 15:15:36avbidder@fortytwo.chcreate