Changeset 11584 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 7 Apr 2014, 15:50:53 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/smtp.py
r10944 r11584 1 1 ## $Id$ 2 2 ## 3 ## Copyright (C) 201 2Uli Fouquet & Henrik Bettermann3 ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann 4 4 ## This program is free software; you can redistribute it and/or modify 5 5 ## it under the terms of the GNU General Public License as published by … … 53 53 from waeup.kofa.interfaces import IMailService 54 54 55 55 56 class DefaultMailService(grok.GlobalUtility): 56 57 """Returns a :class:`zope.sendmail.IMailDelivery`. … … 69 70 name = getattr(config, 'smtp_mailer', name) 70 71 return getUtility(IMailDelivery, name=name) 72 71 73 72 74 class FakeSMTPDelivery(grok.GlobalUtility): … … 92 94 CHARSETS = ('US-ASCII', 'ISO-8859-1', 'UTF-8') 93 95 96 94 97 def encode_header_item(item): 95 98 """Turns `item`, a string into an SMTP header part string. … … 104 107 if not isinstance(item, unicode): 105 108 item = unicode(item, 'utf-8') 106 return str(Header(item, 'iso-8859-1')) # try ascii, then latin1, then utf-8 109 return str(Header(item, 'iso-8859-1')) # try ascii, then latin1, utf-8 110 107 111 108 112 def encode_address(addr, name=u''): … … 127 131 return formataddr((name, addr)) 128 132 133 129 134 def encode_body(text): 130 135 """Build MIME message part from text. … … 139 144 if not isinstance(text, unicode): 140 145 text = unicode(text, 'utf-8') 141 charset = CHARSETS[-1] # fallback146 charset = CHARSETS[-1] # fallback 142 147 for charset in CHARSETS: 143 148 try: 144 149 text = text.encode(charset) 145 150 except UnicodeError: 146 pass # try next encoding151 pass # try next encoding 147 152 else: 148 153 break 149 154 return MIMEText(text, 'plain', charset) 155 150 156 151 157 def send_mail(from_name, from_addr, rcpt_name, rcpt_addrs, … … 154 160 """ 155 161 # format message 156 rcpt_addrs = rcpt_addrs.replace(' ', '').split(',')162 rcpt_addrs = rcpt_addrs.replace(' ', '').split(',') 157 163 body_to = '' 158 164 for email in rcpt_addrs:
Note: See TracChangeset for help on using the changeset viewer.