Python email.header.make_header() Examples

The following are 30 code examples of email.header.make_header(). 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.header , or try the search function .
Example #1
Source File: test_email_renamed.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_whitespace_eater(self):
        eq = self.assertEqual
        s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
        parts = decode_header(s)
        eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
        hdr = make_header(parts)
        eq(hdr.encode(),
           'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.') 
Example #2
Source File: test_email.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def test_rfc2047_multiline(self):
        eq = self.assertEqual
        s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
        dh = decode_header(s)
        eq(dh, [
            (b'Re: ', None),
            (b'r\x8aksm\x9arg\x8cs', 'mac-iceland'),
            (b' baz foo bar ', None),
            (b'r\x8aksm\x9arg\x8cs', 'mac-iceland')])
        header = make_header(dh)
        eq(str(header),
           'Re: r\xe4ksm\xf6rg\xe5s baz foo bar r\xe4ksm\xf6rg\xe5s')
        self.ndiffAssertEqual(header.encode(maxlinelen=76), """\
Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar =?mac-iceland?q?r=8Aksm?=
 =?mac-iceland?q?=9Arg=8Cs?=""") 
Example #3
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_rfc2047_multiline(self):
        eq = self.assertEqual
        s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
        dh = decode_header(s)
        eq(dh, [
            ('Re:', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
            ('baz foo bar', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
        eq(str(make_header(dh)),
           """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
 =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""") 
Example #4
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode_2(self):
        eq = self.assertEqual
        s = 'The =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?='
        dh = decode_header(s)
        eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
                ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
        hu = make_header(dh).__unicode__()
        eq(hu, u'The quick brown fox jumped over the lazy dog') 
Example #5
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode(self):
        eq = self.assertEqual
        s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
        dh = decode_header(s)
        eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
        hu = unicode(make_header(dh)).encode('latin-1')
        eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>') 
Example #6
Source File: test_email_renamed.py    From datafari with Apache License 2.0 5 votes vote down vote up
def test_us_ascii_header(self):
        eq = self.assertEqual
        s = 'hello'
        x = decode_header(s)
        eq(x, [('hello', None)])
        h = make_header(x)
        eq(s, h.encode()) 
Example #7
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater(self):
        eq = self.assertEqual
        s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
        parts = decode_header(s)
        eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
        hdr = make_header(parts)
        eq(hdr.encode(),
           'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.') 
Example #8
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_encoded_adjacent_nonencoded(self):
        eq = self.assertEqual
        h = Header()
        h.append('hello', 'iso-8859-1')
        h.append('world')
        s = h.encode()
        eq(s, '=?iso-8859-1?q?hello?= world')
        h = make_header(decode_header(s))
        eq(h.encode(), s) 
Example #9
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode_2(self):
        eq = self.assertEqual
        s = 'The =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?='
        dh = decode_header(s)
        eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
                ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
        hu = make_header(dh).__unicode__()
        eq(hu, u'The quick brown fox jumped over the lazy dog') 
Example #10
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_rfc2047_multiline(self):
        eq = self.assertEqual
        s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
        dh = decode_header(s)
        eq(dh, [
            ('Re:', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
            ('baz foo bar', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
        eq(str(make_header(dh)),
           """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
 =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""") 
Example #11
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater(self):
        eq = self.assertEqual
        s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
        parts = decode_header(s)
        eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
        hdr = make_header(parts)
        eq(hdr.encode(),
           'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.') 
Example #12
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_rfc2047_multiline(self):
        eq = self.assertEqual
        s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
        dh = decode_header(s)
        eq(dh, [
            ('Re:', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
            ('baz foo bar', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
        eq(str(make_header(dh)),
           """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
 =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""") 
Example #13
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode(self):
        eq = self.assertEqual
        s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
        dh = decode_header(s)
        eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
        hu = unicode(make_header(dh)).encode('latin-1')
        eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>') 
Example #14
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode_2(self):
        eq = self.assertEqual
        s = 'The =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?='
        dh = decode_header(s)
        eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
                ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
        hu = make_header(dh).__unicode__()
        eq(hu, u'The quick brown fox jumped over the lazy dog') 
Example #15
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_encoded_adjacent_nonencoded(self):
        eq = self.assertEqual
        h = Header()
        h.append('hello', 'iso-8859-1')
        h.append('world')
        s = h.encode()
        eq(s, '=?iso-8859-1?q?hello?= world')
        h = make_header(decode_header(s))
        eq(h.encode(), s) 
Example #16
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater(self):
        eq = self.assertEqual
        s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
        parts = decode_header(s)
        eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
        hdr = make_header(parts)
        eq(hdr.encode(),
           'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.') 
Example #17
Source File: test_email_renamed.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_us_ascii_header(self):
        eq = self.assertEqual
        s = 'hello'
        x = decode_header(s)
        eq(x, [('hello', None)])
        h = make_header(x)
        eq(s, h.encode()) 
Example #18
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode(self):
        eq = self.assertEqual
        s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
        dh = decode_header(s)
        eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
        hu = unicode(make_header(dh)).encode('latin-1')
        eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>') 
Example #19
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater(self):
        eq = self.assertEqual
        s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
        parts = decode_header(s)
        eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
        hdr = make_header(parts)
        eq(hdr.encode(),
           'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.') 
Example #20
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_us_ascii_header(self):
        eq = self.assertEqual
        s = 'hello'
        x = decode_header(s)
        eq(x, [('hello', None)])
        h = make_header(x)
        eq(s, h.encode()) 
Example #21
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode_2(self):
        eq = self.assertEqual
        s = 'The =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?='
        dh = decode_header(s)
        eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
                ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
        hu = make_header(dh).__unicode__()
        eq(hu, u'The quick brown fox jumped over the lazy dog') 
Example #22
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_whitespace_eater_unicode(self):
        eq = self.assertEqual
        s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
        dh = decode_header(s)
        eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
        hu = unicode(make_header(dh)).encode('latin-1')
        eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>') 
Example #23
Source File: test_email_renamed.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_rfc2047_multiline(self):
        eq = self.assertEqual
        s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
        dh = decode_header(s)
        eq(dh, [
            ('Re:', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
            ('baz foo bar', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
        eq(str(make_header(dh)),
           """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
 =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""") 
Example #24
Source File: test_email_renamed.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_whitespace_eater(self):
        eq = self.assertEqual
        s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
        parts = decode_header(s)
        eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
        hdr = make_header(parts)
        eq(hdr.encode(),
           'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.') 
Example #25
Source File: test_email_renamed.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_us_ascii_header(self):
        eq = self.assertEqual
        s = 'hello'
        x = decode_header(s)
        eq(x, [('hello', None)])
        h = make_header(x)
        eq(s, h.encode()) 
Example #26
Source File: test_email_renamed.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_whitespace_eater_unicode_2(self):
        eq = self.assertEqual
        s = 'The =?iso-8859-1?b?cXVpY2sgYnJvd24gZm94?= jumped over the =?iso-8859-1?b?bGF6eSBkb2c=?='
        dh = decode_header(s)
        eq(dh, [('The', None), ('quick brown fox', 'iso-8859-1'),
                ('jumped over the', None), ('lazy dog', 'iso-8859-1')])
        hu = make_header(dh).__unicode__()
        eq(hu, u'The quick brown fox jumped over the lazy dog') 
Example #27
Source File: test_email_renamed.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_whitespace_eater_unicode(self):
        eq = self.assertEqual
        s = '=?ISO-8859-1?Q?Andr=E9?= Pirard <pirard@dom.ain>'
        dh = decode_header(s)
        eq(dh, [('Andr\xe9', 'iso-8859-1'), ('Pirard <pirard@dom.ain>', None)])
        hu = unicode(make_header(dh)).encode('latin-1')
        eq(hu, 'Andr\xe9 Pirard <pirard@dom.ain>') 
Example #28
Source File: test_email_renamed.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_rfc2047_multiline(self):
        eq = self.assertEqual
        s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
        dh = decode_header(s)
        eq(dh, [
            ('Re:', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
            ('baz foo bar', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
        eq(str(make_header(dh)),
           """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
 =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""") 
Example #29
Source File: test_email_renamed.py    From datafari with Apache License 2.0 5 votes vote down vote up
def test_whitespace_eater(self):
        eq = self.assertEqual
        s = 'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztk=?= =?koi8-r?q?=CA?= zz.'
        parts = decode_header(s)
        eq(parts, [('Subject:', None), ('\xf0\xd2\xcf\xd7\xc5\xd2\xcb\xc1 \xce\xc1 \xc6\xc9\xce\xc1\xcc\xd8\xce\xd9\xca', 'koi8-r'), ('zz.', None)])
        hdr = make_header(parts)
        eq(hdr.encode(),
           'Subject: =?koi8-r?b?8NLP18XSy8EgzsEgxsnOwczYztnK?= zz.') 
Example #30
Source File: test_email_renamed.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_rfc2047_multiline(self):
        eq = self.assertEqual
        s = """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz
 foo bar =?mac-iceland?q?r=8Aksm=9Arg=8Cs?="""
        dh = decode_header(s)
        eq(dh, [
            ('Re:', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland'),
            ('baz foo bar', None),
            ('r\x8aksm\x9arg\x8cs', 'mac-iceland')])
        eq(str(make_header(dh)),
           """Re: =?mac-iceland?q?r=8Aksm=9Arg=8Cs?= baz foo bar
 =?mac-iceland?q?r=8Aksm=9Arg=8Cs?=""")