[IMP] mail.mail: simplify: no default for `headers` field
This avoids storing useless "{}" values in the database when there are no headers, and avoids having to update all existing entries when this column is added. Just requires simple tests before evaluating the headers contents.
This commit is contained in:
parent
f985c0bc11
commit
34cc064400
|
@ -221,10 +221,12 @@ 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)
|
||||
try:
|
||||
headers = eval(res.get('headers', '{}'))
|
||||
except Exception:
|
||||
headers = {}
|
||||
if res.get('headers'):
|
||||
try:
|
||||
headers.update(eval(res['headers']))
|
||||
except Exception:
|
||||
pass
|
||||
headers['Precedence'] = 'list'
|
||||
# avoid out-of-office replies from MS Exchange
|
||||
# http://blogs.technet.com/b/exchange/archive/2006/10/06/3395024.aspx
|
||||
|
@ -236,5 +238,5 @@ class mail_group(osv.Model):
|
|||
# X-Forge-To: will replace To: after SMTP envelope is determined by ir.mail.server
|
||||
list_to = '"%s" <%s@%s>' % (group.name, group.alias_name, group.alias_domain)
|
||||
headers['X-Forge-To'] = list_to
|
||||
res['headers'] = '%s' % headers
|
||||
res['headers'] = repr(headers)
|
||||
return res
|
||||
|
|
|
@ -67,7 +67,6 @@ class mail_mail(osv.Model):
|
|||
|
||||
_defaults = {
|
||||
'state': 'outgoing',
|
||||
'headers': '{}',
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
|
|
|
@ -13,16 +13,18 @@ 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')
|
||||
try:
|
||||
headers = eval(res.get('headers', '{}'))
|
||||
except Exception:
|
||||
headers = {}
|
||||
if res.get('headers'):
|
||||
try:
|
||||
headers = eval(res['headers'])
|
||||
except Exception:
|
||||
pass
|
||||
headers.update({
|
||||
'List-Archive': '<%s/groups/%s>' % (base_url, slug(group)),
|
||||
'List-Subscribe': '<%s/groups>' % (base_url),
|
||||
'List-Unsubscribe': '<%s/groups?unsubscribe>' % (base_url,),
|
||||
})
|
||||
res['headers'] = '%s' % headers
|
||||
res['headers'] = repr(headers)
|
||||
return res
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue