value = ''.join(remainder)
try:
text, charset, lang, defects = _ew.decode('=?' + tok + '?=')
- except ValueError:
+ except (ValueError, KeyError):
raise _InvalidEwError(
"encoded word format invalid: '{}'".format(ew.cte))
ew.charset = charset
_ew.decode('=?')
with self.assertRaises(ValueError):
_ew.decode('')
+ with self.assertRaises(KeyError):
+ _ew.decode('=?utf-8?X?somevalue?=')
def _test(self, source, result, charset='us-ascii', lang='', defects=[]):
res, char, l, d = _ew.decode(source)
with self.assertRaises(errors.HeaderParseError):
parser.get_encoded_word('=?abc?=')
+ def test_get_encoded_word_invalid_cte(self):
+ with self.assertRaises(errors.HeaderParseError):
+ parser.get_encoded_word('=?utf-8?X?somevalue?=')
+
def test_get_encoded_word_valid_ew(self):
self._test_get_x(parser.get_encoded_word,
'=?us-ascii?q?this_is_a_test?= bird',
[],
'')
+ def test_get_unstructured_invalid_ew_cte(self):
+ self._test_get_x(self._get_unst,
+ '=?utf-8?X?=somevalue?=',
+ '=?utf-8?X?=somevalue?=',
+ '=?utf-8?X?=somevalue?=',
+ [],
+ '')
+
# get_qp_ctext
def test_get_qp_ctext_only(self):