Exemplo n.º 1
0
    def __init__(self, display_name="", username="", domain="", addr_spec=None):
        """Create an object represeting a full email address.

        An address can have a 'display_name', a 'username', and a 'domain'.  In
        addition to specifying the username and domain separately, they may be
        specified together by using the addr_spec keyword *instead of* the
        username and domain keywords.  If an addr_spec string is specified it
        must be properly quoted according to RFC 5322 rules; an error will be
        raised if it is not.

        An Address object has display_name, username, domain, and addr_spec
        attributes, all of which are read-only.  The addr_spec and the string
        value of the object are both quoted according to RFC5322 rules, but
        without any Content Transfer Encoding.

        """
        # This clause with its potential 'raise' may only happen when an
        # application program creates an Address object using an addr_spec
        # keyword.  The email library code itself must always supply username
        # and domain.
        if addr_spec is not None:
            if username or domain:
                raise TypeError("addrspec specified when username and/or " "domain also specified")
            a_s, rest = parser.get_addr_spec(addr_spec)
            if rest:
                raise ValueError("Invalid addr_spec; only '{}' " "could be parsed from '{}'".format(a_s, addr_spec))
            if a_s.all_defects:
                raise a_s.all_defects[0]
            username = a_s.local_part
            domain = a_s.domain
        self._display_name = display_name
        self._username = username
        self._domain = domain
Exemplo n.º 2
0
 def _getaddr(self, arg):
     if not arg:
         return '', ''
     if arg.lstrip().startswith('<'):
         address, rest = get_angle_addr(arg)
     else:
         address, rest = get_addr_spec(arg)
     return address.addr_spec, rest
Exemplo n.º 3
0
 def _getaddr(self, arg):
     if not arg:
         return '', ''
     if arg.lstrip().startswith('<'):
         address, rest = get_angle_addr(arg)
     else:
         address, rest = get_addr_spec(arg)
     return address.addr_spec, rest
Exemplo n.º 4
0
 def _getaddr(self, arg):
     if not arg:
         return ('', '')
     if arg.lstrip().startswith('<'):
         (address, rest) = get_angle_addr(arg)
     else:
         (address, rest) = get_addr_spec(arg)
     if not address:
         return (address, rest)
     return (address.addr_spec, rest)
 def _getaddr(self, arg: str):
     if arg.lstrip().startswith('<'):
         addr, value = get_angle_addr(arg)
     else:
         addr, value = get_addr_spec(arg)
     try:
         addr = addr.addr_spec
     except:
         addr = None
     return addr, value
Exemplo n.º 6
0
 def _getaddr(self, arg):
     if not arg:
         return ('', '')
     if arg.lstrip().startswith('<'):
         (address, rest) = get_angle_addr(arg)
     else:
         (address, rest) = get_addr_spec(arg)
     if not address:
         return (address, rest)
     return (address.addr_spec, rest)
Exemplo n.º 7
0
    def parse_addr(self, maybe_addr):
        if not maybe_addr:
            return b'', b''
        if maybe_addr.lstrip().startswith(b'<'):
            address, rest = get_angle_addr(str(maybe_addr, 'ascii'))
        else:
            address, rest = get_addr_spec(str(maybe_addr, 'ascii'))

        if not address:
            return None, rest

        return address.addr_spec.encode('ascii'), rest.encode('ascii')
Exemplo n.º 8
0
    def parse_addr(self, maybe_addr):
        if not maybe_addr:
            return b'', b''
        if maybe_addr.lstrip().startswith(b'<'):
            address, rest = get_angle_addr(str(maybe_addr, 'ascii'))
        else:
            address, rest = get_addr_spec(str(maybe_addr, 'ascii'))

        if not address:
            return None, rest

        return address.addr_spec.encode('ascii'), rest.encode('ascii')
Exemplo n.º 9
0
 def _getaddr(self, arg):
     if not arg:
         return '', ''
     if arg.lstrip().startswith('<'):
         address, rest = get_angle_addr(arg)
     else:
         address, rest = get_addr_spec(arg)
     try:
         address = address.addr_spec
     except IndexError:
         # Workaround http://bugs.python.org/issue27931
         address = None
     return address, rest
Exemplo n.º 10
0
 def _getaddr(self, arg):
     if not arg:
         return '', ''
     if arg.lstrip().startswith('<'):
         address, rest = get_angle_addr(arg)
     else:
         address, rest = get_addr_spec(arg)
     try:
         address = address.addr_spec
     except IndexError:
         # Workaround http://bugs.python.org/issue27931
         address = None
     return address, rest
Exemplo n.º 11
0
 def __init__(self, display_name='', username='', domain='', addr_spec=None):
     if addr_spec is not None:
         if username or domain:
             raise TypeError('addrspec specified when username and/or domain also specified')
         (a_s, rest) = parser.get_addr_spec(addr_spec)
         if rest:
             raise ValueError("Invalid addr_spec; only '{}' could be parsed from '{}'".format(a_s, addr_spec))
         if a_s.all_defects:
             raise a_s.all_defects[0]
         username = a_s.local_part
         domain = a_s.domain
     self._display_name = display_name
     self._username = username
     self._domain = domain
Exemplo n.º 12
0
    def __init__(self,
                 display_name='',
                 username='',
                 domain='',
                 addr_spec=None):
        """Create an object representing a full email address.

        An address can have a 'display_name', a 'username', and a 'domain'.  In
        addition to specifying the username and domain separately, they may be
        specified together by using the addr_spec keyword *instead of* the
        username and domain keywords.  If an addr_spec string is specified it
        must be properly quoted according to RFC 5322 rules; an error will be
        raised if it is not.

        An Address object has display_name, username, domain, and addr_spec
        attributes, all of which are read-only.  The addr_spec and the string
        value of the object are both quoted according to RFC5322 rules, but
        without any Content Transfer Encoding.

        """

        inputs = ''.join(
            filter(None, (display_name, username, domain, addr_spec)))
        if '\r' in inputs or '\n' in inputs:
            raise ValueError(
                "invalid arguments; address parts cannot contain CR or LF")

        # This clause with its potential 'raise' may only happen when an
        # application program creates an Address object using an addr_spec
        # keyword.  The email library code itself must always supply username
        # and domain.
        if addr_spec is not None:
            if username or domain:
                raise TypeError("addrspec specified when username and/or "
                                "domain also specified")
            a_s, rest = parser.get_addr_spec(addr_spec)
            if rest:
                raise ValueError("Invalid addr_spec; only '{}' "
                                 "could be parsed from '{}'".format(
                                     a_s, addr_spec))
            if a_s.all_defects:
                raise a_s.all_defects[0]
            username = a_s.local_part
            domain = a_s.domain
        self._display_name = display_name
        self._username = username
        self._domain = domain
Exemplo n.º 13
0
 def __init__(self,
              display_name='',
              username='',
              domain='',
              addr_spec=None):
     if addr_spec is not None:
         if username or domain:
             raise TypeError(
                 'addrspec specified when username and/or domain also specified'
             )
         (a_s, rest) = parser.get_addr_spec(addr_spec)
         if rest:
             raise ValueError(
                 "Invalid addr_spec; only '{}' could be parsed from '{}'".
                 format(a_s, addr_spec))
         if a_s.all_defects:
             raise a_s.all_defects[0]
         username = a_s.local_part
         domain = a_s.domain
     self._display_name = display_name
     self._username = username
     self._domain = domain
Exemplo n.º 14
0
    def __init__(self,
                 display_name='',
                 username='',
                 domain='',
                 addr_spec=None):
        """Create an object representing a full email address.

        An address can have a 'display_name', a 'username', and a 'domain'.  In
        addition to specifying the username and domain separately, they may be
        specified together by using the addr_spec keyword *instead of* the
        username and domain keywords.  If an addr_spec string is specified it
        must be properly quoted according to RFC 5322 rules; an error will be
        raised if it is not.

        An Address object has display_name, username, domain, and addr_spec
        attributes, all of which are read-only.  The addr_spec and the string
        value of the object are both quoted according to RFC5322 rules, but
        without any Content Transfer Encoding.

        """
        if addr_spec is not None:
            if username or domain:
                raise TypeError(
                    'addrspec specified when username and/or domain also specified'
                )
            a_s, rest = parser.get_addr_spec(addr_spec)
            if rest:
                raise ValueError(
                    "Invalid addr_spec; only '{}' could be parsed from '{}'".
                    format(a_s, addr_spec))
            if a_s.all_defects:
                raise a_s.all_defects[0]
            username = a_s.local_part
            domain = a_s.domain
        self._display_name = display_name
        self._username = username
        self._domain = domain