Coding question.
A bit of context:
Goal is to develop a custom handler to perform:
* detach all attachments
* post detached content somewhere available on http
* modify the content of the original email, keeping original html,
adding an html link to the moved document
* adding a small clip image as an attachment symbol as an embed object
Le 16/04/2014 16:01, Mark Sapiro a écrit :
<https://docs.python.org/2/library/email.mime.html> to create new
sub-parts and use the Message.attach() method to attach them.
How can I replace the part which contain the html part, by a new one
which will become :
>> Content-Type: multipart/related
>>>>Content-Type: text/html;
>>>> Content-Type: image/png; name="clip-24.png"
The text/html is the old one.
Adding a part is ok, but replacing it with a new one which embed the
previous one… I dont see.
part of the code I've produced:
if msg.is_multipart():
syslog('debug', 'multipart message rewriting')
related = None
for part in msg.walk():
ctype = part.get_content_type()
if ctype == 'text/plain' and not part['X-Mailman-Part']:
new_footer = txt_attacht_replace + footer_attach
part.set_payload(part.get_payload() + new_footer)
continue
elif ctype == 'text/html':
related = MIMEMultipart('related')
clip = MIMEText(attach_clip)
clip.add_header('Content-Disposition', 'inline')
clip.add_header('Content-ID', '<part1.%d>' % 123412)
clip['Content-Transfer-Encoding'] = 'base64'
del clip['Content-type']
del clip['Content-transfer-encoding']
clip['Content-type'] = 'image/png;
name="attachment-24.png"'
clip['Content-transfer-encoding'] = 'base64'
html_footer = html_attachment_holder %
{'html_attachment_clip_tpl': html_footer_attach}
html_footer += '</body>'
old_content = part.get_payload()
new_content = re.sub(r'</body>', html_footer, old_content)
part.set_payload(new_content)
related.attach(part)
related.attach(clip)
# WRONG
del part
msg.attach(related)
continue
_______________________________________________
Mailman-Developers mailing list
Mailman-Developers@python.org
https://mail.python.org/mailman/listinfo/mailman-developers
Mailman FAQ: http://wiki.list.org/x/AgA3
Searchable Archives:
http://www.mail-archive.com/mailman-developers%40python.org/
Unsubscribe:
https://mail.python.org/mailman/options/mailman-developers/archive%40jab.org
Security Policy: http://wiki.list.org/x/QIA9