From 6c6f440f84dc69e8ab710c093984b96445de20a5 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 14 Oct 2016 17:50:43 +0200 Subject: [PATCH] Catch LookupError exception. fix #944 --- modoboa/lib/u2u_decode.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/modoboa/lib/u2u_decode.py b/modoboa/lib/u2u_decode.py index 7ff7c8fee..085e714e8 100644 --- a/modoboa/lib/u2u_decode.py +++ b/modoboa/lib/u2u_decode.py @@ -1,12 +1,9 @@ -#!/usr/bin/env python # coding: utf-8 -""" -u2u_decode.py -unstructured rfc2047 header to unicode -""" -import re +"""Unstructured rfc2047 header to unicode.""" + from email.header import decode_header, make_header +import re # check spaces between encoded_words (and strip them) sre = re.compile(r'\?=[ \t]+=\?') @@ -15,7 +12,7 @@ mre = re.compile(r'=\?[^?]*?\?[bq]\?[^?\t]*?\?=', re.I) def clean_spaces(m): - """Replace unencoded spaces in string + """Replace unencoded spaces in string. :param str m: a match object :return: the cleaned string @@ -24,12 +21,11 @@ def clean_spaces(m): def decode_mime(m): - """substitute matching encoded_word with unicode equiv. - """ + """Substitute matching encoded_word with unicode equiv.""" h = decode_header(clean_spaces(m)) try: u = unicode(make_header(h)) - except UnicodeDecodeError: + except (LookupError, UnicodeDecodeError): return m.group(0) return u