def full_spec(self): """ Returns an ASCII-compatable encoding of an email address or raises a ValueError. Display name and domain parts will be converted to ASCII-compatable encoding. The transformed address will be ASCII-only and RFC-2822 compliant. >>> EmailAddress("Ev K", "*****@*****.**").full_spec() 'Ev K <*****@*****.**>' >>> EmailAddress("Жека", "*****@*****.**").full_spec() '=?utf-8?b?0JbQtdC60LA=?= <*****@*****.**>' """ if not is_pure_ascii(self.mailbox): raise ValueError( 'address {} has no ASCII-compatable encoding'.format( self.address.encode('utf-8'))) if not is_pure_ascii(self.hostname): try: ace_hostname = idna.encode(self.hostname) except idna.IDNAError: raise ValueError( 'address {} has no ASCII-compatable encoding'.format( self.address.encode('utf-8'))) else: ace_hostname = self.hostname if self.display_name: ace_display_name = smart_quote( encode_string(None, self.display_name, maxlinelen=MAX_ADDRESS_LENGTH)) return u'{} <{}@{}>'.format(ace_display_name, self.mailbox, ace_hostname) return u'{}@{}'.format(self.mailbox, ace_hostname)
def test_quote__spaces(): eq_('foo bar', smart_quote('foo bar')) eq_('" foo bar"', smart_quote(' foo bar')) eq_('"foo bar "', smart_quote('foo bar ')) eq_('" foo bar "', smart_quote(' foo bar ')) eq_('foo\tbar', smart_quote('foo\tbar')) eq_('"\tfoo\tbar"', smart_quote('\tfoo\tbar')) eq_('"foo\tbar\t"', smart_quote('foo\tbar\t')) eq_('"\tfoo\tbar\t"', smart_quote('\tfoo\tbar\t'))
def test_quote(): eq_('"foo, bar"', smart_quote('foo, bar')) eq_('"foo; bar"', smart_quote('foo; bar')) eq_('"foo< bar"', smart_quote('foo< bar')) eq_('"foo> bar"', smart_quote('foo> bar')) eq_('"foo\\" bar"', smart_quote('foo" bar')) eq_('"foo. bar"', smart_quote('foo. bar')) eq_('"foo: bar"', smart_quote('foo: bar'))
def _get_full_spec_without_validation(name, email): """ This function is the same as calling full_spec() on a Flanker address.EmailAddress object. This function exists because you can't construct a Flanker EmailAddress object with an invalid email address. """ if name: encoded_name = smart_quote( encode_string(None, name, maxlinelen=MAX_ADDRESS_LENGTH)) return '{0} <{1}>'.format(encoded_name, email) return u'{0}'.format(email)
def _get_full_spec_without_validation(name, email): """ This function is the same as calling full_spec() on a Flanker address.EmailAddress object. This function exists because you can't construct a Flanker EmailAddress object with an invalid email address. """ if name: encoded_name = smart_quote(encode_string( None, name, maxlinelen=MAX_ADDRESS_LENGTH)) return '{0} <{1}>'.format(encoded_name, email) return u'{0}'.format(email)
def full_spec(self): """ Returns a full spec of an email address. Always in ASCII, RFC-2822 compliant, safe to be included into MIME: >>> EmailAddress("Ev K", "*****@*****.**").full_spec() 'Ev K <*****@*****.**>' >>> EmailAddress("Жека", "*****@*****.**").full_spec() '=?utf-8?b?0JbQtdC60LA=?= <*****@*****.**>' """ if self.display_name: encoded_display_name = smart_quote(encode_string( None, self.display_name, maxlinelen=MAX_ADDRESS_LENGTH)) return '{0} <{1}>'.format(encoded_display_name, self.address) return '{0}'.format(self.address)
def full_spec(self): """ Returns a full spec of an email address. Always in ASCII, RFC-2822 compliant, safe to be included into MIME: >>> EmailAddress("Ev K", "*****@*****.**").full_spec() 'Ev K <*****@*****.**>' >>> EmailAddress("Жека", "*****@*****.**").full_spec() '=?utf-8?b?0JbQtdC60LA=?= <*****@*****.**>' """ if self.display_name: encoded_display_name = smart_quote(encode_string( None, self.display_name, maxlinelen=MAX_ADDRESS_LENGTH)) return '{0} <{1}>'.format(encoded_display_name, self.address) return u'{0}'.format(self.address)
def __unicode__(self): if self.display_name: return u'{} <{}@{}>'.format(smart_quote(self.display_name), self.mailbox, self.hostname) return u'{}@{}'.format(self.mailbox, self.hostname)
def ace_display_name(self): return smart_quote( encode_string(None, self.display_name, maxlinelen=MAX_ADDRESS_LENGTH))
def test_quote__nothing_to_quote(): eq_('', smart_quote('')) eq_('foo bar', smart_quote('foo bar')) eq_("!#$%&'*+-/=?^_`{|}~", smart_quote("!#$%&'*+-/=?^_`{|}~"))
def test_quote__escaping(): eq_('"f\\\\o\\"o \\"bar\\""', smart_quote('f\\o"o "bar"')) eq_('"\\"foo\\""', smart_quote('"foo"')) eq_('"\\"foo\\"bar\\""', smart_quote('"foo"bar"'))
def test_quote__periods(): eq_('foo. bar', smart_quote('foo. bar'))
def to_unicode(self): if self._display_name: return u'{} <{}@{}>'.format(smart_quote(self._display_name), self._mailbox, self._hostname) return u'{}@{}'.format(self._mailbox, self._hostname)
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): return encode_string(None, smart_quote(self.display_name), maxlinelen=MAX_ADDRESS_LENGTH)