mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
parent
52173d4959
commit
a0b44b5adb
5 changed files with 23 additions and 6 deletions
|
@ -2457,6 +2457,10 @@ multipart/report
|
|||
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
|
||||
|
|
|
@ -148,13 +148,15 @@ def formatdate(timeval=None, localtime=False, usegmt=False):
|
|||
|
||||
|
||||
|
||||
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. 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 @@ def make_msgid(idstring=None):
|
|||
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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue