-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmail_thread.py
61 lines (53 loc) · 2.31 KB
/
mail_thread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of email_separator,
# an Odoo module.
#
# Authors: ACSONE SA/NV (<http://acsone.eu>)
#
# email_separator is free software:
# you can redistribute it and/or modify it under the terms of the GNU
# Affero General Public License as published by the Free Software
# Foundation,either version 3 of the License, or (at your option) any
# later version.
#
# email_separator is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with email_separator.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import re
from openerp.osv import orm
from openerp.addons.mail.mail_thread import decode_header
class MailThread(orm.AbstractModel):
_inherit = 'mail.thread'
def message_route_check_bounce(self, cr, uid, message, context=None):
"""
Check bounce with a '+' case of any match then
replace it with '-' before and call before
"""
bounce_alias = self.pool['ir.config_parameter'].get_param(
cr, uid, 'mail.bounce.alias', context=context)
email_to = decode_header(message, 'To')
if bounce_alias in email_to:
# Is a bounce ? Reuse the same technic as in super method in
# mass_mailing/models/mail_thread.py
bounce_re = re.compile(
r'%s\+(\d+)-?([\w.]+)?-?(\d+)?' % re.escape(bounce_alias),
re.UNICODE)
if bounce_re.search(email_to):
# Replace the first occurrence of a plus sign in the
# recipient address by a dash, e.g.:
# catchall-bounces+543-kremlin@vladimir-putin.ru
# => catchall-bounces-543-kremlin@vladimir-putin.ru
del message['To']
message['To'] = email_to.replace(
'%s+' % bounce_alias, '%s-' % bounce_alias, 1)
return super(MailThread, self).message_route_check_bounce(
cr, uid, message, context=context)