Ticket #2503: announcerplugin-internationalized-chars-and-enable-tls.diff

File announcerplugin-internationalized-chars-and-enable-tls.diff, 2.4 kB (added by leorochael, 5 months ago)

Internationalized chars AND actually use the use_tls setting

  • ./distributors/email_distributor.py

    old new  
    1212from email.MIMEMultipart import MIMEMultipart 
    1313from email.MIMEText import MIMEText 
    1414from email.Utils import formatdate 
     15from email.header import Header 
    1516import time, Queue, threading, smtplib 
    1617 
    1718class DeliveryThread(threading.Thread): 
     
    223224        output = formatter.format(transport, event.realm, format, event) 
    224225        subject = formatter.format_subject(transport, event.realm, format, event) 
    225226         
     227        charset = self.env.config.get('trac', 'default_charset') or 'utf-8' 
    226228        alternate_format = formatter.get_format_alternative(transport, event.realm, format) 
    227229        if alternate_format: 
    228230            alternate_output = formatter.format(transport, event.realm, alternate_format, event) 
     
    245247            rootMessage['X-Announcement-%s' % key.capitalize()] = str(provided_headers[key]) 
    246248         
    247249        rootMessage['Date'] = formatdate() 
    248         rootMessage['Subject'] = subject 
     250        rootMessage['Subject'] = Header(subject, charset)  
    249251        rootMessage['From'] = self.smtp_from 
    250252        if to: 
    251253            rootMessage['To'] = '"%s"'%(to) 
     
    261263            parentMessage = rootMessage 
    262264         
    263265        if alternate_output: 
    264             msgText = MIMEText(alternate_output, 'html' in alternate_format and 'html' or 'plain'
     266            msgText = MIMEText(alternate_output, 'html' in alternate_format and 'html' or 'plain', charset
    265267            parentMessage.attach(msgText) 
    266268         
    267         msgText = MIMEText(output, 'html' in format and 'html' or 'plain'
     269        msgText = MIMEText(output, 'html' in format and 'html' or 'plain', charset
    268270        parentMessage.attach(msgText) 
    269271         
    270272        start = time.time() 
     
    281283    def _transmit(self, smtpfrom, addresses, message): 
    282284        smtp = smtplib.SMTP() 
    283285        smtp.connect(self.smtp_server) 
     286        if self.use_tls: 
     287            smtp.ehlo() 
     288            smtp.starttls() 
    284289        if self.smtp_user: 
    285290            smtp.login(self.smtp_user, self.smtp_password) 
    286291        smtp.sendmail(smtpfrom, addresses, message)