[IMP] mail: added headers field on mail.mail, allowing to store headers data when sending notification emails.
This commit is contained in:
parent
e862ff7033
commit
f62f58174b
|
@ -175,6 +175,11 @@ class mail_notification(osv.Model):
|
|||
# compute email references
|
||||
references = message.parent_id.message_id if message.parent_id else False
|
||||
|
||||
# custom values
|
||||
custom_values = dict()
|
||||
if message.model and message.res_id and self.pool.get(message.model) and hasattr(self.pool[message.model], 'message_get_email_values'):
|
||||
custom_values = self.pool[message.model].message_get_email_values(cr, uid, message.res_id, message, context=context)
|
||||
|
||||
# create email values
|
||||
max_recipients = 50
|
||||
chunks = [email_pids[x:x + max_recipients] for x in xrange(0, len(email_pids), max_recipients)]
|
||||
|
@ -187,6 +192,7 @@ class mail_notification(osv.Model):
|
|||
'recipient_ids': [(4, id) for id in chunk],
|
||||
'references': references,
|
||||
}
|
||||
mail_values.update(custom_values)
|
||||
email_ids.append(self.pool.get('mail.mail').create(cr, uid, mail_values, context=context))
|
||||
if force_send and len(chunks) < 2: # for more than 50 followers, use the queue system
|
||||
self.pool.get('mail.mail').send(cr, uid, email_ids, context=context)
|
||||
|
|
|
@ -23,6 +23,7 @@ import openerp
|
|||
import openerp.tools as tools
|
||||
from openerp.osv import osv
|
||||
from openerp.osv import fields
|
||||
from openerp.tools.safe_eval import safe_eval as eval
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
|
||||
|
@ -215,12 +216,13 @@ class mail_group(osv.Model):
|
|||
def message_get_email_values(self, cr, uid, id, notif_mail=None, context=None):
|
||||
res = super(mail_group, self).message_get_email_values(cr, uid, id, notif_mail=notif_mail, context=context)
|
||||
group = self.browse(cr, uid, id, context=context)
|
||||
res.update({
|
||||
'headers': {
|
||||
'Precedence': 'list',
|
||||
}
|
||||
})
|
||||
if group.alias_domain:
|
||||
res['headers']['List-Id'] = '%s.%s' % (group.alias_name, group.alias_domain)
|
||||
res['headers']['List-Post'] = '<mailto:%s@%s>' % (group.alias_name, group.alias_domain)
|
||||
try:
|
||||
headers = eval(res.get('headers', '{}'))
|
||||
except Exception:
|
||||
headers = {}
|
||||
headers['Precedence'] = 'list'
|
||||
if group.alias_domain and group.alias_name:
|
||||
headers['List-Id'] = '%s.%s' % (group.alias_name, group.alias_domain)
|
||||
headers['List-Post'] = '<mailto:%s@%s>' % (group.alias_name, group.alias_domain)
|
||||
res['headers'] = '%s' % headers
|
||||
return res
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
import base64
|
||||
import logging
|
||||
import re
|
||||
from urllib import urlencode
|
||||
from urlparse import urljoin
|
||||
|
||||
from openerp import tools
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.addons.base.ir.ir_mail_server import MailDeliveryException
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.safe_eval import safe_eval as eval
|
||||
from openerp.tools.translate import _
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
@ -59,6 +59,7 @@ class mail_mail(osv.Model):
|
|||
'recipient_ids': fields.many2many('res.partner', string='To (Partners)'),
|
||||
'email_cc': fields.char('Cc', help='Carbon copy message recipients'),
|
||||
'body_html': fields.text('Rich-text Contents', help="Rich-text/HTML message"),
|
||||
'headers': fields.text('Headers'),
|
||||
# Auto-detected based on create() - if 'mail_message_id' was passed then this mail is a notification
|
||||
# and during unlink() we will not cascade delete the parent and its attachments
|
||||
'notification': fields.boolean('Is Notification',
|
||||
|
@ -67,6 +68,7 @@ class mail_mail(osv.Model):
|
|||
|
||||
_defaults = {
|
||||
'state': 'outgoing',
|
||||
'headers': '{}',
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
|
@ -210,8 +212,6 @@ class mail_mail(osv.Model):
|
|||
'subject': self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context),
|
||||
'email_to': self.send_get_mail_to(cr, uid, mail, partner=partner, context=context),
|
||||
}
|
||||
if mail.model and mail.res_id and self.pool.get(mail.model) and hasattr(self.pool[mail.model], 'message_get_email_values'):
|
||||
res.update(self.pool[mail.model].message_get_email_values(cr, uid, mail.res_id, mail, context=context))
|
||||
return res
|
||||
|
||||
def send(self, cr, uid, ids, auto_commit=False, raise_exception=False, context=None):
|
||||
|
@ -267,13 +267,15 @@ class mail_mail(osv.Model):
|
|||
headers['Return-Path'] = '%s-%d-%s-%d@%s' % (bounce_alias, mail.id, mail.model, mail.res_id, catchall_domain)
|
||||
else:
|
||||
headers['Return-Path'] = '%s-%d@%s' % (bounce_alias, mail.id, catchall_domain)
|
||||
if mail.headers:
|
||||
try:
|
||||
headers.update(eval(mail.headers))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# build an RFC2822 email.message.Message object and send it without queuing
|
||||
res = None
|
||||
for email in email_list:
|
||||
email_headers = dict(headers)
|
||||
if email.get('headers'):
|
||||
email_headers.update(email['headers'])
|
||||
msg = ir_mail_server.build_email(
|
||||
email_from=mail.email_from,
|
||||
email_to=email.get('email_to'),
|
||||
|
@ -288,7 +290,7 @@ class mail_mail(osv.Model):
|
|||
object_id=mail.res_id and ('%s-%s' % (mail.res_id, mail.model)),
|
||||
subtype='html',
|
||||
subtype_alternative='plain',
|
||||
headers=email_headers)
|
||||
headers=headers)
|
||||
res = ir_mail_server.send_email(cr, uid, msg,
|
||||
mail_server_id=mail.mail_server_id.id,
|
||||
context=context)
|
||||
|
|
|
@ -34,26 +34,19 @@
|
|||
</page>
|
||||
<page string="Advanced" groups="base.group_no_one">
|
||||
<group>
|
||||
<div>
|
||||
<group string="Status">
|
||||
<field name="auto_delete"/>
|
||||
<field name="notification"/>
|
||||
<field name="type"/>
|
||||
<field name="mail_server_id"/>
|
||||
<field name="model"/>
|
||||
<field name="res_id"/>
|
||||
</group>
|
||||
</div>
|
||||
<div>
|
||||
<group string="Headers">
|
||||
<field name="message_id"/>
|
||||
<field name="references"/>
|
||||
</group>
|
||||
<group string="Recipients">
|
||||
<field name="partner_ids" widget="many2many_tags"/>
|
||||
<field name="notified_partner_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
</div>
|
||||
<group string="Status">
|
||||
<field name="auto_delete"/>
|
||||
<field name="notification"/>
|
||||
<field name="type"/>
|
||||
<field name="mail_server_id"/>
|
||||
<field name="model"/>
|
||||
<field name="res_id"/>
|
||||
</group>
|
||||
<group string="Headers">
|
||||
<field name="message_id"/>
|
||||
<field name="references"/>
|
||||
<field name="headers"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Attachments">
|
||||
|
|
|
@ -698,12 +698,8 @@ class mail_thread(osv.AbstractModel):
|
|||
for record in self.browse(cr, SUPERUSER_ID, ids, context=context)]
|
||||
|
||||
def message_get_email_values(self, cr, uid, id, notif_mail=None, context=None):
|
||||
""" Temporary method to create custom notification email values for a given
|
||||
model and document. This should be better to have a headers field on
|
||||
the mail.mail model, computed when creating the notification email, but
|
||||
this cannot be done in a stable version.
|
||||
|
||||
TDE FIXME: rethink this ulgy thing. """
|
||||
""" Get specific notification email values to store on the notification
|
||||
mail_mail. Void method, inherit it to add custom values. """
|
||||
res = dict()
|
||||
return res
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from openerp.osv import osv
|
||||
from openerp.tools.safe_eval import safe_eval as eval
|
||||
|
||||
|
||||
class MailGroup(osv.Model):
|
||||
|
@ -10,9 +11,14 @@ class MailGroup(osv.Model):
|
|||
res = super(MailGroup, self).message_get_email_values(cr, uid, id, notif_mail=notif_mail, context=context)
|
||||
group = self.browse(cr, uid, id, context=context)
|
||||
base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url')
|
||||
res['headers'].update({
|
||||
try:
|
||||
headers = eval(res.get('headers', '{}'))
|
||||
except Exception:
|
||||
headers = {}
|
||||
headers.update({
|
||||
'List-Archive': '<%s/groups/%s>' % (base_url, group.id),
|
||||
'List-Subscribe': '<%s/groups>' % (base_url),
|
||||
'List-Unsubscribe': '<%s/groups>' % (base_url),
|
||||
})
|
||||
res['headers'] = '%s' % headers
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue