<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/cpython-git.git/Lib/test/test_email, branch enum-private-310</title>
<subtitle>github.com: python/cpython.git
</subtitle>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/'/>
<entry>
<title>[3.10] bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452) (GH-28930)</title>
<updated>2021-10-13T17:12:22+00:00</updated>
<author>
<name>Łukasz Langa</name>
<email>lukasz@langa.pl</email>
</author>
<published>2021-10-13T17:12:22+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=f8473f6f7603f8cccccc3307d4cb853587be41b3'/>
<id>f8473f6f7603f8cccccc3307d4cb853587be41b3</id>
<content type='text'>
Co-authored-by: Łukasz Langa &lt;lukasz@langa.pl&gt;
(cherry picked from commit b9e687618d3489944f29adbd2be50b46940c9e70)

Co-authored-by: Ben Hoyt &lt;benhoyt@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Co-authored-by: Łukasz Langa &lt;lukasz@langa.pl&gt;
(cherry picked from commit b9e687618d3489944f29adbd2be50b46940c9e70)

Co-authored-by: Ben Hoyt &lt;benhoyt@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>[3.10] Fix typos in the Lib directory (GH-28775) (GH-28804)</title>
<updated>2021-10-07T15:49:47+00:00</updated>
<author>
<name>Christian Clauss</name>
<email>cclauss@me.com</email>
</author>
<published>2021-10-07T15:49:47+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=cfca4a67745cb9ed040fade3fd54f5002a6e75a6'/>
<id>cfca4a67745cb9ed040fade3fd54f5002a6e75a6</id>
<content type='text'>
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy &lt;tjreedy@udel.edu&gt;.
(cherry picked from commit 745c9d9dfc1ad6fdfdf1d07420c6273ff67fa5be)

Co-authored-by: Christian Clauss &lt;cclauss@me.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy &lt;tjreedy@udel.edu&gt;.
(cherry picked from commit 745c9d9dfc1ad6fdfdf1d07420c6273ff67fa5be)

Co-authored-by: Christian Clauss &lt;cclauss@me.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-45001: Make email date parsing more robust against malformed input (GH-27946)</title>
<updated>2021-08-26T15:47:27+00:00</updated>
<author>
<name>Miss Islington (bot)</name>
<email>31488909+miss-islington@users.noreply.github.com</email>
</author>
<published>2021-08-26T15:47:27+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=9a79242567d79f42ad1a953cce2b1c4a94df23ea'/>
<id>9a79242567d79f42ad1a953cce2b1c4a94df23ea</id>
<content type='text'>
Various date parsing utilities in the email module, such as
email.utils.parsedate(), are supposed to gracefully handle invalid
input, typically by raising an appropriate exception or by returning
None.

The internal email._parseaddr._parsedate_tz() helper used by some of
these date parsing routines tries to be robust against malformed input,
but unfortunately it can still crash ungracefully when a non-empty but
whitespace-only input is passed. This manifests as an unexpected
IndexError.

In practice, this can happen when parsing an email with only a newline
inside a ‘Date:’ header, which unfortunately happens occasionally in the
real world.

Here's a minimal example:

    $ python
    Python 3.9.6 (default, Jun 30 2021, 10:22:16)
    [GCC 11.1.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    &gt;&gt;&gt; import email.utils
    &gt;&gt;&gt; email.utils.parsedate('foo')
    &gt;&gt;&gt; email.utils.parsedate(' ')
    Traceback (most recent call last):
      File "&lt;stdin&gt;", line 1, in &lt;module&gt;
      File "/usr/lib/python3.9/email/_parseaddr.py", line 176, in parsedate
        t = parsedate_tz(data)
      File "/usr/lib/python3.9/email/_parseaddr.py", line 50, in parsedate_tz
        res = _parsedate_tz(data)
      File "/usr/lib/python3.9/email/_parseaddr.py", line 72, in _parsedate_tz
        if data[0].endswith(',') or data[0].lower() in _daynames:
    IndexError: list index out of range

The fix is rather straight-forward: guard against empty lists, after
splitting on whitespace, but before accessing the first element.
(cherry picked from commit 989f6a3800f06b2bd31cfef7c3269a443ad94fac)

Co-authored-by: wouter bolsterlee &lt;wouter@bolsterl.ee&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Various date parsing utilities in the email module, such as
email.utils.parsedate(), are supposed to gracefully handle invalid
input, typically by raising an appropriate exception or by returning
None.

The internal email._parseaddr._parsedate_tz() helper used by some of
these date parsing routines tries to be robust against malformed input,
but unfortunately it can still crash ungracefully when a non-empty but
whitespace-only input is passed. This manifests as an unexpected
IndexError.

In practice, this can happen when parsing an email with only a newline
inside a ‘Date:’ header, which unfortunately happens occasionally in the
real world.

Here's a minimal example:

    $ python
    Python 3.9.6 (default, Jun 30 2021, 10:22:16)
    [GCC 11.1.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    &gt;&gt;&gt; import email.utils
    &gt;&gt;&gt; email.utils.parsedate('foo')
    &gt;&gt;&gt; email.utils.parsedate(' ')
    Traceback (most recent call last):
      File "&lt;stdin&gt;", line 1, in &lt;module&gt;
      File "/usr/lib/python3.9/email/_parseaddr.py", line 176, in parsedate
        t = parsedate_tz(data)
      File "/usr/lib/python3.9/email/_parseaddr.py", line 50, in parsedate_tz
        res = _parsedate_tz(data)
      File "/usr/lib/python3.9/email/_parseaddr.py", line 72, in _parsedate_tz
        if data[0].endswith(',') or data[0].lower() in _daynames:
    IndexError: list index out of range

The fix is rather straight-forward: guard against empty lists, after
splitting on whitespace, but before accessing the first element.
(cherry picked from commit 989f6a3800f06b2bd31cfef7c3269a443ad94fac)

Co-authored-by: wouter bolsterlee &lt;wouter@bolsterl.ee&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-41402: Fix email ContentManager calling .encode() on bytes (GH-21631)</title>
<updated>2021-08-09T23:44:17+00:00</updated>
<author>
<name>Miss Islington (bot)</name>
<email>31488909+miss-islington@users.noreply.github.com</email>
</author>
<published>2021-08-09T23:44:17+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=a3185da26f8c818907c297d92c533deaa96f40fd'/>
<id>a3185da26f8c818907c297d92c533deaa96f40fd</id>
<content type='text'>
(cherry picked from commit b33186bc43bb5aaf652dd9d093a08fdde796d499)

Co-authored-by: Johannes Reiff &lt;mail@jreiff.de&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
(cherry picked from commit b33186bc43bb5aaf652dd9d093a08fdde796d499)

Co-authored-by: Johannes Reiff &lt;mail@jreiff.de&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-42892: fix email multipart attribute error (GH-26903) (GH-27492)</title>
<updated>2021-07-30T17:27:06+00:00</updated>
<author>
<name>Miss Islington (bot)</name>
<email>31488909+miss-islington@users.noreply.github.com</email>
</author>
<published>2021-07-30T17:27:06+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=6f950023c6a2168b229363d75f59a24ecdd66d19'/>
<id>6f950023c6a2168b229363d75f59a24ecdd66d19</id>
<content type='text'>
(cherry picked from commit e3f877c32d7cccb734f45310f26beeec793364ce)

Co-authored-by: andrei kulakov &lt;andrei.avk@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
(cherry picked from commit e3f877c32d7cccb734f45310f26beeec793364ce)

Co-authored-by: andrei kulakov &lt;andrei.avk@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-27513: email.utils.getaddresses() now handles Header objects (GH-13797) (GH-27242)</title>
<updated>2021-07-19T16:54:45+00:00</updated>
<author>
<name>Miss Islington (bot)</name>
<email>31488909+miss-islington@users.noreply.github.com</email>
</author>
<published>2021-07-19T16:54:45+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=8c43bf1a923754fa6d97772151c6ac23c48759d3'/>
<id>8c43bf1a923754fa6d97772151c6ac23c48759d3</id>
<content type='text'>
getaddresses() should be able to handle a Header object if passed
one.

Co-authored-by: Łukasz Langa &lt;lukasz@langa.pl&gt;
(cherry picked from commit 89f4c34797de2f0e5045da2b97c1c8cbbb42fbb2)

Co-authored-by: Zackery Spytz &lt;zspytz@gmail.com&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
getaddresses() should be able to handle a Header object if passed
one.

Co-authored-by: Łukasz Langa &lt;lukasz@langa.pl&gt;
(cherry picked from commit 89f4c34797de2f0e5045da2b97c1c8cbbb42fbb2)

Co-authored-by: Zackery Spytz &lt;zspytz@gmail.com&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-44395: Fix MIMEPart.as_string to pass unixfrom properly (GH-26685)</title>
<updated>2021-06-21T14:27:26+00:00</updated>
<author>
<name>Miss Islington (bot)</name>
<email>31488909+miss-islington@users.noreply.github.com</email>
</author>
<published>2021-06-21T14:27:26+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=20a1495b8a93596b322ea19bb09008db036eb7e6'/>
<id>20a1495b8a93596b322ea19bb09008db036eb7e6</id>
<content type='text'>
(cherry picked from commit 30f7a77f359a0fc6e37988b0f317a77a15d66b7b)

Co-authored-by: Dong-hee Na &lt;donghee.na@python.org&gt;</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
(cherry picked from commit 30f7a77f359a0fc6e37988b0f317a77a15d66b7b)

Co-authored-by: Dong-hee Na &lt;donghee.na@python.org&gt;</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-43651: PEP 597: Fix test_email (GH-25158)</title>
<updated>2021-04-05T03:30:12+00:00</updated>
<author>
<name>Inada Naoki</name>
<email>songofacandy@gmail.com</email>
</author>
<published>2021-04-05T03:30:12+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=de522a89e42a35da9275169b113460c3581e32d7'/>
<id>de522a89e42a35da9275169b113460c3581e32d7</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-43125: Fix: return expected type (str), not original value (bytes) in email/base64mime.py::body_encode (GH-24476)</title>
<updated>2021-03-30T08:37:37+00:00</updated>
<author>
<name>Grégory Starck</name>
<email>g.starck@gmail.com</email>
</author>
<published>2021-03-30T08:37:37+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=cf35e05f89bb008d6f4553f9875e0fe87fc02406'/>
<id>cf35e05f89bb008d6f4553f9875e0fe87fc02406</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>bpo-30681: Support invalid date format or value in email Date header (GH-22090)</title>
<updated>2020-10-27T00:31:06+00:00</updated>
<author>
<name>Georges Toth</name>
<email>georges@trypill.org</email>
</author>
<published>2020-10-27T00:31:06+00:00</published>
<link rel='alternate' type='text/html' href='http://91.123.203.49/cgit/delta/cpython-git.git/commit/?id=303aac8c56609290e122eecc14c038e9b1e4174a'/>
<id>303aac8c56609290e122eecc14c038e9b1e4174a</id>
<content type='text'>
I am re-submitting an older PR which was abandoned but is still relevant, #10783 by @timb07.

The issue being solved () is still relevant. The original PR #10783 was closed as
the final request changes were not applied and since abandoned.

In this new PR I have re-used the original patch plus applied both comments from the review, by @maxking and @pganssle.


For reference, here is the original PR description:
In email.utils.parsedate_to_datetime(), a failure to parse the date, or invalid date components (such as hour outside 0..23) raises an exception. Document this behaviour, and add tests to test_email/test_utils.py to confirm this behaviour.

In email.headerregistry.DateHeader.parse(), check when parsedate_to_datetime() raises an exception and add a new defect InvalidDateDefect; preserve the invalid value as the string value of the header, but set the datetime attribute to None.

Add tests to test_email/test_headerregistry.py to confirm this behaviour; also added test to test_email/test_inversion.py to confirm emails with such defective date headers round trip successfully.

This pull request incorporates feedback gratefully received from @bitdancer, @brettcannon, @Mariatta and @warsaw, and replaces the earlier PR #2254.

Automerge-Triggered-By: GH:warsaw</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
I am re-submitting an older PR which was abandoned but is still relevant, #10783 by @timb07.

The issue being solved () is still relevant. The original PR #10783 was closed as
the final request changes were not applied and since abandoned.

In this new PR I have re-used the original patch plus applied both comments from the review, by @maxking and @pganssle.


For reference, here is the original PR description:
In email.utils.parsedate_to_datetime(), a failure to parse the date, or invalid date components (such as hour outside 0..23) raises an exception. Document this behaviour, and add tests to test_email/test_utils.py to confirm this behaviour.

In email.headerregistry.DateHeader.parse(), check when parsedate_to_datetime() raises an exception and add a new defect InvalidDateDefect; preserve the invalid value as the string value of the header, but set the datetime attribute to None.

Add tests to test_email/test_headerregistry.py to confirm this behaviour; also added test to test_email/test_inversion.py to confirm emails with such defective date headers round trip successfully.

This pull request incorporates feedback gratefully received from @bitdancer, @brettcannon, @Mariatta and @warsaw, and replaces the earlier PR #2254.

Automerge-Triggered-By: GH:warsaw</pre>
</div>
</content>
</entry>
</feed>
