From c4c4342a80d120c85238315a611a4a85fead79f1 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Wed, 2 Dec 2015 11:02:41 +0200 Subject: Ignore images in incoming emails --- servo/models/note.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'servo/models/note.py') diff --git a/servo/models/note.py b/servo/models/note.py index f5b8c15..ed8b944 100644 --- a/servo/models/note.py +++ b/servo/models/note.py @@ -231,7 +231,9 @@ class Note(MPTTModel): return ' '.join(classes) def find_parent(self, txt): - """Finds the parent of this note""" + """ + Finds the parent of this note + """ cookie = re.search(r'\(SRO#([\w/]+)\)', txt) if not cookie: @@ -250,7 +252,9 @@ class Note(MPTTModel): @classmethod def from_email(cls, msg, user): - """Creates a new Note from an email message""" + """ + Creates a new Note from an email message + """ sender = decode_header(msg['From']) detected = chardet.detect(sender[0][0]).get('encoding') sender = [i[0].decode(i[1] or detected) for i in sender] @@ -276,7 +280,9 @@ class Note(MPTTModel): payload = part.get_payload(decode=True) note.body = unicode(payload, str(charset), "ignore") if s == "html": - note.body = html2text.html2text(note.body) + h = html2text.HTML2Text() + h.ignore_images = True + note.body = h.handle(note.body) else: note.save() if part.get_filename(): -- cgit v1.2.3