Browse Source

fixup! fixup! fixup! [ADD] mail_embed_image module

pull/404/head
George Daramouskas 6 years ago
parent
commit
49eb4bdac3
No known key found for this signature in database GPG Key ID: 5B4EF742F8CD859C
  1. 6
      mail_embed_image/models/ir_mail_server.py

6
mail_embed_image/models/ir_mail_server.py

@ -7,6 +7,7 @@ from odoo import models
from odoo.addons.base.ir.ir_mail_server import encode_header_param from odoo.addons.base.ir.ir_mail_server import encode_header_param
from lxml.html.soupparser import fromstring from lxml.html.soupparser import fromstring
from lxml import etree from lxml import etree
from lxml.etree import tostring
from base64 import b64encode from base64 import b64encode
from email.mime.image import MIMEImage from email.mime.image import MIMEImage
from email import Encoders from email import Encoders
@ -69,14 +70,13 @@ class IrMailServer(models.Model):
'web.base.url') 'web.base.url')
src = base_url + img.get('src') src = base_url + img.get('src')
response = requests.get(src) response = requests.get(src)
#content_base64 = b64encode(response.content)
cid = uuid.uuid4().hex cid = uuid.uuid4().hex
filename_rfc2047 = encode_header_param(cid) filename_rfc2047 = encode_header_param(cid)
part = MIMEImage(response.content) part = MIMEImage(response.content)
part.set_param('name', filename_rfc2047) part.set_param('name', filename_rfc2047)
part.add_header( part.add_header(
'Content-Disposition', 'Content-Disposition',
'attachment',
'inline',
cid=cid, cid=cid,
filename=filename_rfc2047, filename=filename_rfc2047,
) )
@ -84,6 +84,6 @@ class IrMailServer(models.Model):
Encoders.encode_base64(part) Encoders.encode_base64(part)
result.attach(part) result.attach(part)
img.set('src', 'cid:%s' % (cid)) img.set('src', 'cid:%s' % (cid))
msg.set_payload(etree.tostring(root))
msg.set_payload(b64encode(tostring(root)))
_build_email_replace_img_src(result, attachments) _build_email_replace_img_src(result, attachments)
return result return result
Loading…
Cancel
Save