def test_non_ascii_chars_do_not_cause_inf_loop(self): policy = email.policy.default.clone(max_line_length=20) actual = policy.fold('Subject', 'ą' * 12) self.assertEqual( actual, 'Subject: \n' + 12 * ' =?utf-8?q?=C4=85?=\n')
def test_short_maxlen_error(self): # RFC 2047 chrome takes up 7 characters, plus the length of the charset # name, so folding should fail if maxlen is lower than the minimum # required length for a line. # Note: This is only triggered when there is a single word longer than # max_line_length, hence the 1234567890 at the end of this whimsical # subject. This is because when we encounter a word longer than # max_line_length, it is broken down into encoded words to fit # max_line_length. If the max_line_length isn't large enough to even # contain the RFC 2047 chrome (`?=<charset>?q??=`), we fail. subject = "Melt away the pounds with this one simple trick! 1234567890" for maxlen in [3, 7, 9]: with self.subTest(maxlen=maxlen): policy = email.policy.default.clone(max_line_length=maxlen) with self.assertRaises(email.errors.HeaderParseError): policy.fold("Subject", subject)