Python email.Utils.parseaddr() Examples

The following are 30 code examples of email.Utils.parseaddr(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module email.Utils , or try the search function .
Example #1
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
Example #2
Source File: message.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def sanitize_address(addr, encoding):
    if isinstance(addr, basestring):
        addr = parseaddr(force_unicode(addr))
    nm, addr = addr
    nm = str(Header(nm, encoding))
    try:
        addr = addr.encode('ascii')
    except UnicodeEncodeError:  # IDN
        if u'@' in addr:
            localpart, domain = addr.split(u'@', 1)
            localpart = str(Header(localpart, encoding))
            domain = domain.encode('idna')
            addr = '@'.join([localpart, domain])
        else:
            addr = str(Header(addr, encoding))
    return formataddr((nm, addr)) 
Example #3
Source File: test_email.py    From datafari with Apache License 2.0 6 votes vote down vote up
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
Example #4
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
Example #5
Source File: test_email.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
Example #6
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
Example #7
Source File: test_email.py    From BinderFilter with MIT License 6 votes vote down vote up
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
Example #8
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_parseaddr_preserves_quoted_pairs_in_addresses(self):
        # issue 10005.  Note that in the third test the second pair of
        # backslashes is not actually a quoted pair because it is not inside a
        # comment or quoted string: the address being parsed has a quoted
        # string containing a quoted backslash, followed by 'example' and two
        # backslashes, followed by another quoted string containing a space and
        # the word 'example'.  parseaddr copies those two backslashes
        # literally.  Per rfc5322 this is not technically correct since a \ may
        # not appear in an address outside of a quoted string.  It is probably
        # a sensible Postel interpretation, though.
        eq = self.assertEqual
        eq(Utils.parseaddr('""example" example"@example.com'),
          ('', '""example" example"@example.com'))
        eq(Utils.parseaddr('"\\"example\\" example"@example.com'),
          ('', '"\\"example\\" example"@example.com'))
        eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'),
          ('', '"\\\\"example\\\\" example"@example.com')) 
Example #9
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #10
Source File: test_email.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_multiline_from_comment(self):
        x = """\
Foo
\tBar <foo@example.com>"""
        self.assertEqual(Utils.parseaddr(x), ('Foo Bar', 'foo@example.com')) 
Example #11
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_parseaddr_empty(self):
        self.assertEqual(Utils.parseaddr('<>'), ('', ''))
        self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '') 
Example #12
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #13
Source File: test_email.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #14
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_name_with_dot(self):
        x = 'John X. Doe <jxd@example.com>'
        y = '"John X. Doe" <jxd@example.com>'
        a, b = ('John X. Doe', 'jxd@example.com')
        self.assertEqual(Utils.parseaddr(x), (a, b))
        self.assertEqual(Utils.parseaddr(y), (a, b))
        # formataddr() quotes the name if there's a dot in it
        self.assertEqual(Utils.formataddr((a, b)), y) 
Example #15
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_backslashes(self):
        self.assertEqual(
            Utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
            r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
        a = r'Arthur \Backslash\ Foobar'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #16
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_name_with_dot(self):
        x = 'John X. Doe <jxd@example.com>'
        y = '"John X. Doe" <jxd@example.com>'
        a, b = ('John X. Doe', 'jxd@example.com')
        self.assertEqual(Utils.parseaddr(x), (a, b))
        self.assertEqual(Utils.parseaddr(y), (a, b))
        # formataddr() quotes the name if there's a dot in it
        self.assertEqual(Utils.formataddr((a, b)), y) 
Example #17
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_backslashes(self):
        self.assertEqual(
            Utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
            r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
        a = r'Arthur \Backslash\ Foobar'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #18
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_parseaddr_empty(self):
        self.assertEqual(Utils.parseaddr('<>'), ('', ''))
        self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '') 
Example #19
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_name_with_dot(self):
        x = 'John X. Doe <jxd@example.com>'
        y = '"John X. Doe" <jxd@example.com>'
        a, b = ('John X. Doe', 'jxd@example.com')
        self.assertEqual(Utils.parseaddr(x), (a, b))
        self.assertEqual(Utils.parseaddr(y), (a, b))
        # formataddr() quotes the name if there's a dot in it
        self.assertEqual(Utils.formataddr((a, b)), y) 
Example #20
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #21
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_backslashes(self):
        self.assertEqual(
            Utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
            r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
        a = r'Arthur \Backslash\ Foobar'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #22
Source File: test_email.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_name_with_dot(self):
        x = 'John X. Doe <jxd@example.com>'
        y = '"John X. Doe" <jxd@example.com>'
        a, b = ('John X. Doe', 'jxd@example.com')
        self.assertEqual(Utils.parseaddr(x), (a, b))
        self.assertEqual(Utils.parseaddr(y), (a, b))
        # formataddr() quotes the name if there's a dot in it
        self.assertEqual(Utils.formataddr((a, b)), y) 
Example #23
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_parseaddr_empty(self):
        self.assertEqual(Utils.parseaddr('<>'), ('', ''))
        self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '') 
Example #24
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def ParseAddress(item):
    parseAddr = parseaddr(item)
    if parseAddr[0] == '':
        return parseAddr[1]
    decAddr = decode_header(parseAddr[0])[0]
    if not decAddr[1]:
        return parseAddr[0]
    else:
        return DecodeSection(decAddr[0], decAddr[1])
#=============================================================================== 
Example #25
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_parseaddr_empty(self):
        self.assertEqual(Utils.parseaddr('<>'), ('', ''))
        self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '') 
Example #26
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #27
Source File: test_email.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_escape_backslashes(self):
        self.assertEqual(
            Utils.formataddr(('Arthur \Backslash\ Foobar', 'person@dom.ain')),
            r'"Arthur \\Backslash\\ Foobar" <person@dom.ain>')
        a = r'Arthur \Backslash\ Foobar'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #28
Source File: test_email.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b)) 
Example #29
Source File: test_email.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_parseaddr_multiple_domains(self):
        self.assertEqual(
            Utils.parseaddr('a@b@c'),
            ('', '')
        )
        self.assertEqual(
            Utils.parseaddr('a@b.c@c'),
            ('', '')
        )
        self.assertEqual(
            Utils.parseaddr('a@172.17.0.1@c'),
            ('', '')
        ) 
Example #30
Source File: test_email.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_escape_dump(self):
        self.assertEqual(
            Utils.formataddr(('A (Very) Silly Person', 'person@dom.ain')),
            r'"A \(Very\) Silly Person" <person@dom.ain>')
        a = r'A \(Special\) Person'
        b = 'person@dom.ain'
        self.assertEqual(Utils.parseaddr(Utils.formataddr((a, b))), (a, b))