Skip to content

Commit

Permalink
[IMP] mail.mail: simplify: no default for headers field
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odony committed Aug 11, 2014
1 parent f985c0b commit 34cc064
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions addons/mail/mail_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ def get_suggested_thread(self, cr, uid, removed_suggested_threads=None, context=
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 = {}
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
Expand All @@ -236,5 +238,5 @@ def message_get_email_values(self, cr, uid, id, notif_mail=None, context=None):
# 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
1 change: 0 additions & 1 deletion addons/mail/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class mail_mail(osv.Model):

_defaults = {
'state': 'outgoing',
'headers': '{}',
}

def default_get(self, cr, uid, fields, context=None):
Expand Down
12 changes: 7 additions & 5 deletions addons/website_mail_group/models/mail_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ def message_get_email_values(self, cr, uid, id, notif_mail=None, context=None):
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 = {}
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


Expand Down

0 comments on commit 34cc064

Please sign in to comment.