# HG changeset patch # User Marcin Kuzminski # Date 2012-06-13 21:44:32 # Node ID d95ef6587bca261341994a512742d0bd3a344c8c # Parent 402a96fcfa22f990c77e0d08c31c4bf2ca95f72b fixes #481 rhodecode emails are sent without Date header - small code cleanup in mailing diff --git a/docs/changelog.rst b/docs/changelog.rst --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -50,6 +50,7 @@ fixes - fixed issue #459. Changed the way of obtaining logger in reindex task. - fixed #453 added ID field in whoosh SCHEMA that solves the issue of reindexing modified files +- fixes #481 rhodecode emails are sent without Date header 1.3.6 (**2012-05-17**) ---------------------- diff --git a/rhodecode/lib/rcmail/message.py b/rhodecode/lib/rcmail/message.py --- a/rhodecode/lib/rcmail/message.py +++ b/rhodecode/lib/rcmail/message.py @@ -3,6 +3,7 @@ from rhodecode.lib.rcmail.response impor from rhodecode.lib.rcmail.exceptions import BadHeaders from rhodecode.lib.rcmail.exceptions import InvalidMessage + class Attachment(object): """ Encapsulates file attachment information. @@ -134,13 +135,13 @@ class Message(object): """ if not self.recipients: - raise InvalidMessage, "No recipients have been added" + raise InvalidMessage("No recipients have been added") if not self.body and not self.html: - raise InvalidMessage, "No body has been set" + raise InvalidMessage("No body has been set") if not self.sender: - raise InvalidMessage, "No sender address has been set" + raise InvalidMessage("No sender address has been set") if self.is_bad_headers(): raise BadHeaders diff --git a/rhodecode/lib/rcmail/response.py b/rhodecode/lib/rcmail/response.py --- a/rhodecode/lib/rcmail/response.py +++ b/rhodecode/lib/rcmail/response.py @@ -364,6 +364,7 @@ def to_message(mail, separator="; "): return out + class MIMEPart(MIMEBase): """ A reimplementation of nearly everything in email.mime to be more useful @@ -387,7 +388,8 @@ class MIMEPart(MIMEBase): self.set_payload(encoded, charset=charset) def extract_payload(self, mail): - if mail.body == None: return # only None, '' is still ok + if mail.body == None: + return # only None, '' is still ok ctype, ctype_params = mail.content_encoding['Content-Type'] cdisp, cdisp_params = mail.content_encoding['Content-Disposition'] @@ -415,7 +417,8 @@ class MIMEPart(MIMEBase): def header_to_mime_encoding(value, not_email=False, separator=", "): - if not value: return "" + if not value: + return "" encoder = Charset(DEFAULT_ENCODING) if type(value) == list: @@ -424,6 +427,7 @@ def header_to_mime_encoding(value, not_e else: return properly_encode_header(value, encoder, not_email) + def properly_encode_header(value, encoder, not_email): """ The only thing special (weird) about this function is that it tries diff --git a/rhodecode/lib/rcmail/smtp_mailer.py b/rhodecode/lib/rcmail/smtp_mailer.py --- a/rhodecode/lib/rcmail/smtp_mailer.py +++ b/rhodecode/lib/rcmail/smtp_mailer.py @@ -21,10 +21,11 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - +import time import logging import smtplib from socket import sslerror +from email.utils import formatdate from rhodecode.lib.rcmail.message import Message @@ -59,8 +60,11 @@ class SmtpMailer(object): if isinstance(recipients, basestring): recipients = [recipients] + headers = { + 'Date': formatdate(time.time()) + } msg = Message(subject, recipients, body, html, self.mail_from, - recipients_separator=", ") + recipients_separator=", ", extra_headers=headers) raw_msg = msg.to_message() if self.ssl: