mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
Removed workaround for lack of os.getpid() in Jython.
The Jython bug was fixed in http://bugs.jython.org/issue1518 (tested on Jython 2.7b3); also updated make_msgid() to be more like the version in Python 3.2+; refs #23905. Thanks Simon Charette for testing and review.
This commit is contained in:
parent
a5bd7f2cb2
commit
ebb927c4c9
@ -35,31 +35,32 @@ class BadHeaderError(ValueError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Copied from Python standard library, with the following modifications:
|
# Copied from Python 3.2+ standard library, with the following modifications:
|
||||||
# * Used cached hostname for performance.
|
# * Used cached hostname for performance.
|
||||||
# * Added try/except to support lack of getpid() in Jython (#5496).
|
# TODO: replace with email.utils.make_msgid(.., domain=DNS_NAME) when dropping
|
||||||
def make_msgid(idstring=None):
|
# Python 2 (Python 2's version doesn't have domain parameter) (#23905).
|
||||||
|
def make_msgid(idstring=None, domain=None):
|
||||||
"""Returns a string suitable for RFC 2822 compliant Message-ID, e.g:
|
"""Returns a string suitable for RFC 2822 compliant Message-ID, e.g:
|
||||||
|
|
||||||
<20020201195627.33539.96671@nightshade.la.mastaler.com>
|
<20020201195627.33539.96671@nightshade.la.mastaler.com>
|
||||||
|
|
||||||
Optional idstring if given is a string used to strengthen the
|
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()
|
timeval = time.time()
|
||||||
utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval))
|
utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval))
|
||||||
try:
|
pid = os.getpid()
|
||||||
pid = os.getpid()
|
|
||||||
except AttributeError:
|
|
||||||
# No getpid() in Jython, for example.
|
|
||||||
pid = 1
|
|
||||||
randint = random.randrange(100000)
|
randint = random.randrange(100000)
|
||||||
if idstring is None:
|
if idstring is None:
|
||||||
idstring = ''
|
idstring = ''
|
||||||
else:
|
else:
|
||||||
idstring = '.' + idstring
|
idstring = '.' + idstring
|
||||||
idhost = DNS_NAME
|
if domain is None:
|
||||||
msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, idhost)
|
# stdlib uses socket.getfqdn() here instead
|
||||||
|
domain = DNS_NAME
|
||||||
|
msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, domain)
|
||||||
return msgid
|
return msgid
|
||||||
|
|
||||||
|
|
||||||
@ -266,7 +267,8 @@ class EmailMessage(object):
|
|||||||
if 'date' not in header_names:
|
if 'date' not in header_names:
|
||||||
msg['Date'] = formatdate()
|
msg['Date'] = formatdate()
|
||||||
if 'message-id' not in header_names:
|
if 'message-id' not in header_names:
|
||||||
msg['Message-ID'] = make_msgid()
|
# Use cached DNS_NAME for performance
|
||||||
|
msg['Message-ID'] = make_msgid(domain=DNS_NAME)
|
||||||
for name, value in self.extra_headers.items():
|
for name, value in self.extra_headers.items():
|
||||||
if name.lower() in ('from', 'to'): # From and To are already handled
|
if name.lower() in ('from', 'to'): # From and To are already handled
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user