Ticket #3007: messageid.patch

File messageid.patch, 991 bytes (added by Chris Beaven, 18 years ago)

Fallback for Python 2.3 (and caching of server name)

  • django/core/mail.py

     
    88import time
    99import random
    1010
     11# Cache the hostname
     12DNS_NAME = socket.getfqdn()
     13
    1114class BadHeaderError(ValueError):
    1215    pass
    1316
     
    5356        msg['From'] = from_email
    5457        msg['To'] = ', '.join(recipient_list)
    5558        msg['Date'] = rfc822.formatdate()
    56         msg['Message-ID'] = "<%d.%d@%s>" % (time.time(), random.getrandbits(64), socket.getfqdn())
    5759        try:
     60            random_bits = str(random.getrandbits(64))
     61        except AttributeError:  # Python 2.3 fallback
     62            random_bits = ''.join([random.choice('1234567890') for i in range(19)])
     63        msg['Message-ID'] = '<%d.%s@%s>' % (time.time(), random_bits, DNS_NAME)
     64        try:
    5865            server.sendmail(from_email, recipient_list, msg.as_string())
    5966            num_sent += 1
    6067        except:
Back to Top