From a282ccd5b4cf82375439f6ceb82c23d2c04ff78d Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Mon, 22 Aug 2016 13:51:07 +0200 Subject: [PATCH] include filename only for attached inline images (#12872) --- corbo/models.py | 10 ++++++---- tests/test_emailing.py | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/corbo/models.py b/corbo/models.py index c6d1787..e2a4064 100644 --- a/corbo/models.py +++ b/corbo/models.py @@ -1,3 +1,4 @@ +import os from datetime import datetime import logging import urlparse @@ -89,8 +90,8 @@ class Broadcast(models.Model): storage = DefaultStorage() for img in html_tree.xpath('//img/@src'): img_path = img.lstrip(storage.base_url) - m.attach(filename=img, data=storage.open(img_path)) - m.attachments[img].is_inline = True + img_name = os.path.basename(img_path) + m.attach(filename=img_name, data=storage.open(img_path)) for s in subscriptions: if not s.identifier: continue @@ -101,8 +102,9 @@ class Broadcast(models.Model): message = template.render(Context({'unsubscribe_link': unsubscribe_link, 'content': self.announce.text})) m.html = message - m.transformer.load_and_transform() - m.transformer.synchronize_inline_images() + m.transformer.apply_to_images(func=lambda src, **kw: os.path.basename(src)) + m.transformer.load_and_transform(load_images=False) + m.transformer.make_all_images_inline() m.transformer.save() handler.body_width = 0 m.text = handler.handle(message) diff --git a/tests/test_emailing.py b/tests/test_emailing.py index 8447e5a..aa6b358 100644 --- a/tests/test_emailing.py +++ b/tests/test_emailing.py @@ -82,7 +82,7 @@ def test_check_inline_images(app, categories, announces): storage = DefaultStorage() media_path = os.path.join(os.path.dirname(__file__), 'media') image_name = 'logo.png' - storage.save(image_name, file(os.path.join(media_path, image_name))) + image_name = storage.save(image_name, file(os.path.join(media_path, image_name))) for announce in announces: announce.text = announce.text + '' % image_name announce.save() @@ -93,7 +93,8 @@ def test_check_inline_images(app, categories, announces): broadcast.send() assert broadcast.result assert mail.outbox - assert storage.url(image_name) in mail.outbox[0].attachments.keys() + assert image_name in mail.outbox[0].attachments.keys() + assert 'cid:%s' % image_name in mail.outbox[0].html_body mail.outbox = [] storage.delete(image_name) -- 2.9.3