summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-01-19 12:58:19 -0500
committerGitHub <noreply@github.com>2017-01-19 12:58:19 -0500
commit9e917cc29181ad32abc21488ee70e739ce805f3a (patch)
tree3fa734463f36924e2f77e187855fc4fcaf2c839c
parentd4bb37593ed1cc0831404b6c5e8581e628d00f3b (diff)
Fixed #23905, refs #23919 -- Used make_msgid() from stdlib.
-rw-r--r--django/core/mail/message.py33
1 files changed, 1 insertions, 32 deletions
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index f8fd6c2d25..228084f2d1 100644
--- a/django/core/mail/message.py
+++ b/django/core/mail/message.py
@@ -1,7 +1,5 @@
import mimetypes
import os
-import random
-import time
from email import (
charset as Charset, encoders as Encoders, generator, message_from_string,
)
@@ -13,7 +11,7 @@ from email.mime.base import MIMEBase
from email.mime.message import MIMEMessage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
-from email.utils import formatdate, getaddresses, parseaddr
+from email.utils import formatdate, getaddresses, make_msgid, parseaddr
from io import BytesIO, StringIO
from django.conf import settings
@@ -38,35 +36,6 @@ class BadHeaderError(ValueError):
pass
-# Copied from Python 3.2+ standard library, with the following modifications:
-# * Used cached hostname for performance.
-# TODO: replace with email.utils.make_msgid(.., domain=DNS_NAME) when dropping
-# 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 5322 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. 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))
- pid = os.getpid()
- randint = random.randrange(100000)
- if idstring is None:
- idstring = ''
- else:
- idstring = '.' + idstring
- if domain is None:
- # stdlib uses socket.getfqdn() here instead
- domain = DNS_NAME
- msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, domain)
- return msgid
-
-
# Header names that contain structured address data (RFC #5322)
ADDRESS_HEADERS = {
'from',