Ticket #67: subject_umlauts.patch

File subject_umlauts.patch, 1.6 kB (added by fs, 8 months ago)

Patch to resolve the issue

  • tests/test_message.py

    diff -r 363a20e4e326 tests/test_message.py
    a b  
    66 
    77import unittest 
    88from turbomail.message import Message 
     9from email.Header import Header 
    910try: 
    1011    from email.mime.text import MIMEText 
    1112except ImportError: 
     
    4748    def test_recipients_collection(self): 
    4849        self.message.cc.append("copied@example.com") 
    4950        self.assertEqual(self.message.recipients.addresses, ["recipient@example.com", "copied@example.com"]) 
     51     
     52    def test_subject_with_umlaut(self): 
     53        subject_string = u"Test with ÀöÌ" 
     54        self.message.subject = subject_string 
     55        self.message.encoding = "UTF-8" 
     56         
     57        msg_string = str(self.message) 
     58        subject_string = "Subject: " + str(Header(subject_string, "UTF-8")) 
     59        self.failUnless(subject_string in msg_string) 
     60     
     61     
  • turbomail/message.py

    diff -r 363a20e4e326 turbomail/message.py
    a b  
    216216            if isinstance(header, (tuple, list)): 
    217217                if header[1] is None or ( isinstance(header[1], list) and not header[1] ): continue 
    218218                header = list(header) 
     219                if isinstance(header[1], unicode): 
     220                    header[1] = Header(header[1], self.encoding) 
    219221                header[1] = str(header[1]) 
    220222                message.add_header(*header) 
    221223            elif isinstance(header, dict):