def _encode_unstructured(name, value): try: return _email.encode_header(name, value.encode('ascii'), 'ascii') except (UnicodeEncodeError, UnicodeDecodeError): if _is_address_header(name, value): return _encode_address_header(name, value) return _email.encode_header(name, to_utf8(value), 'utf-8')
def test_encode_header_maxlinelen(): """ If the encoded string is longer then the maximum line length, which is 76, by default then it is broken down into lines. But a maximum line length value can be provided in the `maxlinelen` parameter. """ eq_('very\r\n l' + ('o' * 70) + 'ng', _email.encode_header(None, 'very l' + ('o' * 70) + 'ng')) eq_('very l' + ('o' * 70) + 'ng', _email.encode_header(None, 'very l' + ('o' * 70) + 'ng', max_line_len=78))
def test_encode_header_maxlinelen(): """ If the encoded string is longer then the maximum line length, which is 76, by default then it is broken down into lines. But a maximum line length value can be provided in the `maxlinelen` parameter. """ eq_('very\r\n l' + ('o' * 70) + 'ng', _email.encode_header(None, 'very l' + ('o' * 70) + 'ng')) eq_( 'very l' + ('o' * 70) + 'ng', _email.encode_header(None, 'very l' + ('o' * 70) + 'ng', max_line_len=78))
def _encode_param(key, name, value): try: if six.PY2: value = value.encode('ascii') return _email.format_param(name, value) except Exception: value = value.encode('utf-8') encoded_param = _email.encode_header(key, value, 'utf-8') return _email.format_param(name, encoded_param)
def ace_display_name(self): quoted_display_name = smart_quote(self._display_name) encoded_display_name = _email.encode_header(None, quoted_display_name, 'ascii', MAX_ADDRESS_LENGTH) return _to_str(encoded_display_name)
def ace_display_name(self): quoted_display_name = smart_quote(self._display_name) encoded_display_name = _email.encode_header(None, quoted_display_name, 'ascii', MAX_ADDRESS_LENGTH) return _to_str(encoded_display_name)