[MERGE] tools.email_send, base: improved spam wizard and email_send w/ plaintext alternative + minor improvements in base menu/views

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

bzr revid: odo@openerp.com-20101222123509-dhxbq3wdzj5w2bei
This commit is contained in:
Olivier Dony 2010-12-22 13:35:09 +01:00
commit 8bf22a19e5
4 changed files with 27 additions and 7 deletions

View File

@ -339,7 +339,7 @@
<field name="name" select="1"/>
<field name="address" select="1"/>
<field name="country" select="1"/>
<field name="category_id" select="1"/>
<field name="category_id" select="1" groups="base.group_extended"/>
<field name="user_id" select="1">
<filter string="My Partners" icon="terp-personal+" domain="[('user_id','=',uid)]"/>
</field>

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,14 +52,22 @@ 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:
name = adr.name or partner.name
to = '%s <%s>' % (name, adr.email)
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_,
openobject_id="res.partner-%s"%partner.id)
nbr += 1
event_pool.create(cr, uid,
{'name': 'Email(s) sent through mass mailing',

View File

@ -52,7 +52,7 @@
</record>
<record id="res_log_act_window" model="ir.actions.act_window">
<field name="name">Logs</field>
<field name="name">Client Logs</field>
<field name="res_model">res.log</field>
<field name="view_type">form</field>
<field name="context">{'search_default_my': 1}</field>

View File

@ -49,6 +49,10 @@ if sys.version_info[:2] < (2, 4):
from threadinglocal import local
else:
from threading import local
try:
from html2text import html2text
except ImportError:
html2text = None
import netsvc
from config import config
@ -499,8 +503,7 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non
email_body = ustr(body).encode('utf-8')
email_text = MIMEText(email_body or '',_subtype=subtype,_charset='utf-8')
if attach: msg = MIMEMultipart()
else: msg = email_text
msg = MIMEMultipart()
msg['Subject'] = Header(ustr(subject), 'utf-8')
msg['From'] = email_from
@ -522,8 +525,16 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non
for key, value in x_headers.iteritems():
msg['%s' % key] = str(value)
if attach:
if html2text and subtype == 'html':
text = html2text(email_body.decode('utf-8')).encode('utf-8')
alternative_part = MIMEMultipart(_subtype="alternative")
alternative_part.attach(MIMEText(text, _charset='utf-8', _subtype='plain'))
alternative_part.attach(email_text)
msg.attach(alternative_part)
else:
msg.attach(email_text)
if attach:
for (fname,fcontent) in attach:
part = MIMEBase('application', "octet-stream")
part.set_payload( fcontent )