Changeset - d95ef6587bca
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 13 years ago 2012-06-13 23:44:32
marcin@python-works.com
fixes #481 rhodecode emails are sent without Date header
- small code cleanup in mailing
4 files changed with 17 insertions and 7 deletions:
0 comments (0 inline, 0 general)
docs/changelog.rst
Show inline comments
 
@@ -47,12 +47,13 @@ fixes
 
- fix for issue #417, git execution was broken on windows for certain
 
  commands.
 
- fixed #413. Don't disable .git directory for bare repos on deleting
 
- 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**)
 
----------------------
 

	
 
news
 
++++
rhodecode/lib/rcmail/message.py
Show inline comments
 
from rhodecode.lib.rcmail.response import MailResponse
 

	
 
from rhodecode.lib.rcmail.exceptions import BadHeaders
 
from rhodecode.lib.rcmail.exceptions import InvalidMessage
 

	
 

	
 
class Attachment(object):
 
    """
 
    Encapsulates file attachment information.
 

	
 
    :param filename: filename of attachment
 
    :param content_type: file mimetype
 
@@ -131,19 +132,19 @@ class Message(object):
 
    def validate(self):
 
        """
 
        Checks if message is valid and raises appropriate exception.
 
        """
 

	
 
        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
 

	
 
    def add_recipient(self, recipient):
 
        """
rhodecode/lib/rcmail/response.py
Show inline comments
 
@@ -361,12 +361,13 @@ def to_message(mail, separator="; "):
 
    # go through the children
 
    for part in mail.parts:
 
        out.attach(to_message(part))
 

	
 
    return out
 

	
 

	
 
class MIMEPart(MIMEBase):
 
    """
 
    A reimplementation of nearly everything in email.mime to be more useful
 
    for actually attaching things.  Rather than one class for every type of
 
    thing you'd encode, there's just this one, and it figures out how to
 
    encode what you ask it.
 
@@ -384,13 +385,14 @@ class MIMEPart(MIMEBase):
 
            encoded = content.encode('utf-8')
 
            charset = 'utf-8'
 

	
 
        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']
 

	
 
        assert ctype, ("Extract payload requires that mail.content_encoding "
 
                       "have a valid Content-Type.")
 
@@ -412,21 +414,23 @@ class MIMEPart(MIMEBase):
 
            self['Content-Type'],
 
            self['Content-Disposition'],
 
            self.is_multipart())
 

	
 

	
 
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:
 
        return separator.join(properly_encode_header(
 
            v, encoder, not_email) for v in value)
 
    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
 
    to do a fast check to see if the header value has an email address in
 
    it.  Since random headers could have an email address, and email addresses
 
    have weird special formatting rules, we have to check for it.
rhodecode/lib/rcmail/smtp_mailer.py
Show inline comments
 
@@ -18,16 +18,17 @@
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import time
 
import logging
 
import smtplib
 
from socket import sslerror
 
from email.utils import formatdate
 
from rhodecode.lib.rcmail.message import Message
 

	
 

	
 
class SmtpMailer(object):
 
    """SMTP mailer class
 

	
 
@@ -56,14 +57,17 @@ class SmtpMailer(object):
 

	
 
    def send(self, recipients=[], subject='', body='', html='',
 
             attachment_files=None):
 

	
 
        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:
 
            smtp_serv = smtplib.SMTP_SSL(self.mail_server, self.mail_port)
 
        else:
 
            smtp_serv = smtplib.SMTP(self.mail_server, self.mail_port)
0 comments (0 inline, 0 general)