=== modified file 'bin/addons/base/res/partner/wizard/wizard_spam.py' --- bin/addons/base/res/partner/wizard/wizard_spam.py 2009-06-08 05:55:05 +0000 +++ bin/addons/base/res/partner/wizard/wizard_spam.py 2010-10-29 12:50:24 +0000 @@ -23,6 +23,7 @@ import wizard import pooler import tools +import re email_send_form = '''
@@ -43,6 +44,9 @@ def _mass_mail_send(self, cr, uid, data, context): nbr = 0 partners = pooler.get_pool(cr.dbname).get('res.partner').browse(cr, uid, data['ids'], context) + type_ = 'plain' + if re.search('(<(pre)|[pubi].*>)', data['form']['text']): + type_ = 'html' for partner in partners: for adr in partner.address: if adr.email: @@ -50,7 +54,10 @@ to = '%s <%s>' % (name, adr.email) #TODO: add some tests to check for invalid email addresses #CHECKME: maybe we should use res.partner/email_send - tools.email_send(data['form']['from'], [to], data['form']['subject'], data['form']['text'],subtype='html') + tools.email_send(data['form']['from'], [to], + data['form']['subject'], + data['form']['text'], + subtype=type_, tinycrm=True) nbr += 1 pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid, {'name': 'Email sent through mass mailing', === modified file 'bin/tools/misc.py' --- bin/tools/misc.py 2010-08-10 09:40:06 +0000 +++ bin/tools/misc.py 2010-10-29 12:48:55 +0000 @@ -39,6 +39,10 @@ from threading import local from itertools import izip +try: + from html2text import html2text +except ImportError: + html2text = None # initialize a database with base/base.sql def init_db(cr): @@ -330,13 +334,7 @@ if not email_bcc: email_bcc = [] - if not attach: - try: - msg = MIMEText(body.encode('utf8') or '',_subtype=subtype,_charset='utf-8') - except: - msg = MIMEText(body or '',_subtype=subtype,_charset='utf-8') - else: - msg = MIMEMultipart() + msg = MIMEMultipart() msg['Subject'] = Header(ustr(subject), 'utf-8') msg['From'] = email_from @@ -364,11 +362,16 @@ if tinycrm: msg['Message-Id'] = "<%s-tinycrm-%s@%s>" % (time.time(), tinycrm, socket.gethostname()) + if isinstance(body, unicode): + body = body.encode('utf-8') + msg.attach(MIMEText(body or '', _charset='utf-8', _subtype=subtype)) + + if html2text and subtype == 'html': + text = html2text(body.decode('utf-8')).encode('utf-8') + msg.attach(MIMEText(text, _charset='utf-8', + _subtype='plain')) + if attach: - try: - msg.attach(MIMEText(body.encode('utf8') or '',_subtype=subtype,_charset='utf-8')) - except: - msg.attach(MIMEText(body or '', _charset='utf-8', _subtype=subtype) ) for (fname,fcontent) in attach: part = MIMEBase('application', "octet-stream") part.set_payload( fcontent )