You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Python source code encoding : https://www.python.org/dev/peps/pep-0263/
  3. ##############################################################################
  4. # For copyright and license notices, see __openerp__.py file in root directory
  5. ##############################################################################
  6. import urlparse
  7. import urllib
  8. from openerp import api, models
  9. from openerp.tools.translate import _
  10. class MailMail(models.Model):
  11. _inherit = 'mail.mail'
  12. @api.model
  13. def _get_unsubscribe_url(self, mail, email_to, msg=None):
  14. m_config = self.env['ir.config_parameter']
  15. base_url = m_config.get_param('web.base.url')
  16. config_msg = m_config.get_param('mass_mailing.unsubscribe.label')
  17. params = {
  18. 'db': self.env.cr.dbname,
  19. 'res_id': mail.res_id,
  20. 'email': email_to,
  21. 'token': self.env["mail.mass_mailing"].hash_create(
  22. mail.mailing_id.id,
  23. mail.res_id,
  24. email_to),
  25. }
  26. # Avoid `token=None` in URL
  27. if not params["token"]:
  28. del params["token"]
  29. # Generate URL
  30. url = urlparse.urljoin(
  31. base_url, 'mail/mailing/%(mailing_id)s/unsubscribe?%(params)s' % {
  32. 'mailing_id': mail.mailing_id.id,
  33. 'params': urllib.urlencode(params),
  34. }
  35. )
  36. html = ''
  37. if config_msg is False:
  38. html = '<small><a href="%(url)s">%(label)s</a></small>' % {
  39. 'url': url,
  40. 'label': msg or _('Click to unsubscribe'),
  41. }
  42. elif config_msg.lower() != 'false':
  43. html = config_msg % {
  44. 'url': url,
  45. }
  46. return html