Projet

Général

Profil

0001-include-filename-only-for-attached-inline-images-128.patch

Serghei Mihai (congés, retour 15/05), 27 septembre 2016 16:29

Télécharger (2,79 ko)

Voir les différences:

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(-)
corbo/models.py
1
import os
1 2
from datetime import datetime
2 3
import logging
3 4
import urlparse
......
89 90
        storage = DefaultStorage()
90 91
        for img in html_tree.xpath('//img/@src'):
91 92
            img_path = img.lstrip(storage.base_url)
92
            m.attach(filename=img, data=storage.open(img_path))
93
            m.attachments[img].is_inline = True
93
            img_name = os.path.basename(img_path)
94
            m.attach(filename=img_name, data=storage.open(img_path))
94 95
        for s in subscriptions:
95 96
            if not s.identifier:
96 97
                continue
......
101 102
            message = template.render(Context({'unsubscribe_link': unsubscribe_link,
102 103
                                               'content': self.announce.text}))
103 104
            m.html = message
104
            m.transformer.load_and_transform()
105
            m.transformer.synchronize_inline_images()
105
            m.transformer.apply_to_images(func=lambda src, **kw: os.path.basename(src))
106
            m.transformer.load_and_transform(load_images=False)
107
            m.transformer.make_all_images_inline()
106 108
            m.transformer.save()
107 109
            handler.body_width = 0
108 110
            m.text = handler.handle(message)
tests/test_emailing.py
82 82
    storage = DefaultStorage()
83 83
    media_path = os.path.join(os.path.dirname(__file__), 'media')
84 84
    image_name = 'logo.png'
85
    storage.save(image_name, file(os.path.join(media_path, image_name)))
85
    image_name = storage.save(image_name, file(os.path.join(media_path, image_name)))
86 86
    for announce in announces:
87 87
        announce.text = announce.text + '<img src="/media/%s" />' % image_name
88 88
        announce.save()
......
93 93
        broadcast.send()
94 94
        assert broadcast.result
95 95
        assert mail.outbox
96
        assert storage.url(image_name) in mail.outbox[0].attachments.keys()
96
        assert image_name in mail.outbox[0].attachments.keys()
97
        assert 'cid:%s' % image_name in mail.outbox[0].html_body
97 98
        mail.outbox = []
98 99
    storage.delete(image_name)
99 100

  
100
-