Merge lp:~openerp-dev/openobject-addons/7.0-inline-images-in-mail into lp:openobject-addons/7.0

Proposed by Paramjit Singh Sahota(OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-inline-images-in-mail
Merge into: lp:openobject-addons/7.0
Diff against target: 27 lines (+10/-0)
1 file modified
mail/mail_thread.py (+10/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-inline-images-in-mail
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+206433@code.launchpad.net

Description of the change

Hello,

Fixed the issue of mail where the image is not visible on mail wall if the images coming in email as inline image.
Related branch of server: https://code.launchpad.net/~openerp-dev/openobject-server/7.0-inline-images-in-mail

Thankz You.

To post a comment you must log in.
9841. By Paramjit Singh Sahota(OpenERP)

[IMP] Improved code.

Unmerged revisions

9841. By Paramjit Singh Sahota(OpenERP)

[IMP] Improved code.

9840. By Paramjit Singh Sahota(OpenERP)

[FIX] Fixed the issue of email in which the images coming inline in email are not visible.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mail/mail_thread.py'
2--- mail/mail_thread.py 2014-02-13 09:57:17 +0000
3+++ mail/mail_thread.py 2014-02-18 08:50:43 +0000
4@@ -29,6 +29,7 @@
5 import time
6 import xmlrpclib
7 from email.message import Message
8+from lxml import etree
9
10 from openerp import tools
11 from openerp import SUPERUSER_ID
12@@ -801,6 +802,15 @@
13 else:
14 filename=decode(filename)
15 encoding = part.get_content_charset() # None if attachment
16+ # For inline attachement
17+ content_type = re.split(r"\s*[,;]\s*", part.get('Content-Type').strip())
18+ if part.get('content-disposition', '').strip().startswith('inline') or content_type[0] == 'image/png':
19+ content_id = str(part.get('Content-ID'))
20+ content_id = email.utils.collapse_rfc2231_value(content_id).strip()
21+ doc = etree.HTML(str(body))
22+ for node in doc.xpath("//img[@src='cid:%s']" %(content_id)):
23+ node.set('src', 'data:%s;%s,%s' %(content_type[0], part.get('Content-Transfer-Encoding'), part.get_payload()))
24+ body = etree.tostring(doc)
25 # 1) Explicit Attachments -> attachments
26 if filename or part.get('content-disposition', '').strip().startswith('attachment'):
27 attachments.append((filename or 'attachment', part.get_payload(decode=True)))