Comment 5 for bug 921442

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi there,

First thank you to review this one. I came back to you as I just face it again on the last trunk version. PLEASE, FIX ALSO THE SECOND PART IN BOTH 6.1 AND 6.0 :

Second part: Fetching mail when some character are broken in the body_html part. It could happend that you receive an email with broking characters in it, you should not block everything because of that. Currently, if it happend, no other mail are fetched, and you got an PostgreSQL error when trying to write it in DB : invalid byte sequence for encoding "UTF8": 0xe96ce9

=> We really need this fix here. I just tested my patch and it also work on v6.1 (first part as well as second one).

To reproduce, you'll need to send a mail to the fecthmail of openerp with a broken char in it like in this script:

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.mime.text import MIMEText

# Create a text/plain message
msg = MIMEText('abcdef' + chr(255))

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The broken mail'
msg['From'] = 'YOUR_EMAIL'
msg['To'] = 'TO_FETCHMAIL_OPENERP'

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('YOUR_SMTP_SERVER')
s.sendmail('YOUR_EMAIL', ['TO_FETCHMAIL_OPENERP'], msg.as_string())
s.quit()

Don't forget to replace those variable : YOUR_EMAIL, TO_FETCHMAIL_OPENERP, YOUR_SMTP_SERVER.

Or just type this in a Python console to have the proof:

a = 'abcdef' + chr(255)
a
>>>> 'abcdef\xff'
str(a)
>>>'abcdef\xff'
unicode(a)
>>>>Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 6: ordinal not in range(128)

You see that unicode can't make it. This is exactly what happen when PostgreSQL try to record the mail, and this stop everything !

Thanks for your review,

Best regards,

Joël