Browse Source

Put messageid in all emails

Daniel Wagner-Hall 8 years ago
parent
commit
c3a71011a6
2 changed files with 11 additions and 7 deletions
  1. 11 0
      sydent/util/emailutils.py
  2. 0 7
      sydent/validators/emailvalidator.py

+ 11 - 0
sydent/util/emailutils.py

@@ -15,21 +15,32 @@
 # limitations under the License.
 
 import logging
+import os
+import random
 import smtplib
 import email.utils
+import string
 import twisted.python.log
 
 import email.utils
 
+from sydent.util import time_msec
+
 logger = logging.getLogger(__name__)
 
 
 def sendEmail(sydent, templateName, mailTo, substitutions):
         mailFrom = sydent.cfg.get('email', 'email.from')
         mailTemplateFile = sydent.cfg.get('email', templateName)
+
+        myHostname = os.uname()[1]
+        midRandom = "".join([random.choice(string.ascii_letters) for _ in range(16)])
+        messageid = "%d%s@%s" % (time_msec(), midRandom, myHostname)
+
         allSubstitutions = {}
         allSubstitutions.update(substitutions)
         allSubstitutions.update({
+            'messageid': messageid,
             'date': email.utils.formatdate(localtime=False),
             'to': mailTo,
             'from': mailFrom,

+ 0 - 7
sydent/validators/emailvalidator.py

@@ -14,10 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import os
 import logging
-import random
-import string
 import urllib
 
 from sydent.db.valsession import ThreePidValSessionStore
@@ -47,13 +44,9 @@ class EmailValidator:
             logger.info("Not mailing code because current send attempt (%d) is not less than given send attempt (%s)", int(sendAttempt), int(valSession.sendAttemptNumber))
             return valSession.id
 
-        myHostname = os.uname()[1]
-        midRandom = "".join([random.choice(string.ascii_letters) for _ in range(16)])
-        messageid = "%d%s@%s" % (time_msec(), midRandom, myHostname)
         ipstring = ipaddress if ipaddress else u"an unknown location"
 
         substitutions = {
-            'messageid': messageid,
             'ipaddress': ipstring,
             'link': self.makeValidateLink(valSession, clientSecret, nextLink),
             'token': valSession.token,