[FIX]partner:Improved wizard spam

lp bug: https://launchpad.net/bugs/668320 fixed

bzr revid: ssi@tinyerp.com-20101104100414-683dfu5i3avtq12z
This commit is contained in:
ssi 2010-11-04 15:34:14 +05:30
parent d41debe92a
commit 462ca11338
2 changed files with 14 additions and 2 deletions

View File

@ -22,6 +22,7 @@
import netsvc
import tools
from osv import fields, osv
import re
class partner_wizard_spam(osv.osv_memory):
""" Mass Mailing """
@ -51,6 +52,9 @@ class partner_wizard_spam(osv.osv_memory):
event_pool = self.pool.get('res.partner.event')
active_ids = context and context.get('active_ids', [])
partners = partner_pool.browse(cr, uid, active_ids, context)
type_ = 'plain'
if re.search('(<(pre)|[pubi].*>)', data.text):
type_ = 'html'
for partner in partners:
for adr in partner.address:
if adr.email:
@ -58,7 +62,7 @@ class partner_wizard_spam(osv.osv_memory):
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.email_from, [to], data.subject, data.text,subtype='html')
tools.email_send(data.email_from, [to], data.subject, data.text,subtype=type_)
nbr += 1
event_pool.create(cr, uid,
{'name': 'Email(s) sent through mass mailing',

View File

@ -38,6 +38,10 @@ import re
from itertools import islice
import threading
from which import which
try:
from html2text import html2text
except ImportError:
html2text = None
import smtplib
from email.MIMEText import MIMEText
@ -532,7 +536,11 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non
# Add dynamic X Header
for key, value in x_headers.iteritems():
msg['%s' % key] = str(value)
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:
msg.attach(email_text)
for (fname,fcontent) in attach: