Merge lp:~openerp-dev/openobject-addons/trunk-bug-921442-nco into lp:openobject-addons

Proposed by Nimesh Contractor(Open ERP)
Status: Rejected
Rejected by: Olivier Dony (Odoo)
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-921442-nco
Merge into: lp:openobject-addons
Diff against target: 60 lines (+9/-4)
3 files modified
base_action_rule/base_action_rule.py (+3/-2)
crm/crm_action_rule.py (+3/-2)
mail/mail_message.py (+3/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-921442-nco
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Disapprove
Raphael Collet (OpenERP) (community) Needs Information
Review via email: mp+93940@code.launchpad.net

Description of the change

Hello,

     For encoding trouble: encode the string in unicode, I have applied patch of Joël Grand-Guillaume @ CampToCamp (jgrandguillaume-c2c) and its working fine.

Thanks,
 NCO.

To post a comment you must log in.
Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

Thanks!
Raphael

review: Approve
Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

Oh, I just noticed that you changed history.name into history.subject.
Why?

review: Needs Information
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

The fix with the missing ustr() call is fine, but it was already correct in the branch from kjo, so I'll merge that in the 6.1 branch separately.

The other fix from Joel is unfortunately not correct for multiple reasons:

1. There is still no proper way to reproduce it that does not involve injecting the error directly in the OpenERP code. We need a way to reproduce this by passing an email message to the parse_message() method, anything else is flawed: when you directly patch the code to produce an error you can do anything that is impossible to trigger in real cases.

2. This is not a proper way to avoid unicode errors. When you call unicode(txt, errors='ignore') you *explicitly* drop anything that is not ASCII within `txt` in the process, because anything else is considered invalid in the default ASCII encoding! e.g.:
  >>> unicode('abcdé', errors='ignore')
  u'abcd'
A cleaner way to do it would be to use errors='replace' and pass the original encoding so only invalid bytes *in the specified encoding* will be replaced. i.e.
  >>> unicode('abcdé' + chr(255), 'utf8', errors='replace')
  u'abcd\xe9\ufffd''

3. This patch is attempting to spot-patch just one out of the dozens of many conversions that are performed in the parse_message() method, which makes little sense. If the code is supposed to be tolerant to malformed email parts, it should not do it for only of the possible places that can be malformed.

review: Disapprove

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_action_rule/base_action_rule.py'
2--- base_action_rule/base_action_rule.py 2011-12-27 09:27:00 +0000
3+++ base_action_rule/base_action_rule.py 2012-02-21 09:12:25 +0000
4@@ -28,6 +28,7 @@
5 import re
6 import time
7 import tools
8+from openerp.loglevels import ustr
9
10
11 def get_datetime(date_field):
12@@ -369,8 +370,8 @@
13 reg_name = action.regex_name
14 result_name = True
15 if reg_name:
16- ptrn = re.compile(str(reg_name))
17- _result = ptrn.search(str(obj.name))
18+ ptrn = re.compile(ustr(reg_name))
19+ _result = ptrn.search(ustr(obj.name))
20 if not _result:
21 result_name = False
22 regex_n = not reg_name or result_name
23
24=== modified file 'crm/crm_action_rule.py'
25--- crm/crm_action_rule.py 2011-12-20 15:29:31 +0000
26+++ crm/crm_action_rule.py 2012-02-21 09:12:25 +0000
27@@ -27,6 +27,7 @@
28 from osv import osv
29
30 import crm
31+from openerp.loglevels import ustr
32
33 class base_action_rule(osv.osv):
34 """ Base Action Rule """
35@@ -73,9 +74,9 @@
36 regex = action.regex_history
37 if regex:
38 res = False
39- ptrn = re.compile(str(regex))
40+ ptrn = re.compile(ustr(regex))
41 for history in obj.message_ids:
42- _result = ptrn.search(str(history.name))
43+ _result = ptrn.search(ustr(history.subject))
44 if _result:
45 res = True
46 break
47
48=== modified file 'mail/mail_message.py'
49--- mail/mail_message.py 2012-01-31 13:36:57 +0000
50+++ mail/mail_message.py 2012-02-21 09:12:25 +0000
51@@ -453,6 +453,9 @@
52
53 msg['body_text'] = body
54 msg['attachments'] = attachments
55+ # For encoding trouble: encode the string in unicode, ignoring unkown byte
56+ if 'body_html' in msg and isinstance(msg['body_html'],str):
57+ msg['body_html'] = unicode(msg['body_html'], errors='ignore')
58
59 # for backwards compatibility:
60 msg['body'] = msg['body_text']

Subscribers

People subscribed via source and target branches

to all changes: