def get_encoded_subject(subject): try: subject.encode('ascii') except UnicodeEncodeError: return encode(subject, encoding='b') else: return subject
def test_auto_b_if_long_unsafe(self): self.assertEqual(_ew.encode('vi.vi.vi.vi.vi.', 'utf-8'), '=?utf-8?b?dmkudmkudmkudmkudmku?=')
def test_auto_b_if_enough_unsafe(self): self.assertEqual(_ew.encode('.....', 'utf-8'), '=?utf-8?b?Li4uLi4=?=')
def test_auto_q_if_short_mostly_safe(self): self.assertEqual(_ew.encode('vi.', 'utf-8'), '=?utf-8?q?vi=2E?=')
def test_auto_q(self): self.assertEqual(_ew.encode('foo', 'utf-8'), '=?utf-8?q?foo?=')
def test_b(self): self.assertEqual(_ew.encode('foo', 'utf-8', 'b'), '=?utf-8?b?Zm9v?=')
def test_lang(self): self.assertEqual(_ew.encode('foo', lang='jive'), '=?utf-8*jive?q?foo?=')
def test_utf8_default(self): self.assertEqual(_ew.encode('foo'), '=?utf-8?q?foo?=')
def test_auto_q_if_long_mostly_safe(self): self.assertEqual(_ew.encode('vi vi vi.vi ', 'utf-8'), '=?utf-8?q?vi_vi_vi=2Evi_?=')
def test_unknown_8bit(self): self.assertEqual(_ew.encode('foo\uDCACbar', charset='unknown-8bit'), '=?unknown-8bit?q?foo=ACbar?=')