summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_email
Commit message (Collapse)AuthorAgeFilesLines
* gh-124452: Fix header mismatches when folding/unfolding with email message ↵RanKKI2024-11-161-2/+48
| | | | | | | | | | | | | | | | | | (#125919) The header-folder of the new email API has a long standing known buglet where if the first token is longer than max_line_length, it puts that token on the next line. It turns out there is also a *parsing* bug when parsing such a header: the space prefixing that first, non-empty line gets preserved and tacked on to the start of the header value, which is not the expected behavior per the RFCs. The bug arises from the fact that the parser assumed that there would be at least one token on the line with the header, which is going to be true for probably every email producer other than the python email library with its folding buglet. Clearly, though, this is a case that needs to be handled correctly. The fix is simple: strip the blanks off the start of the whole value, not just the first physical line of the value. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-126133: Only use start year in PSF copyright, remove end years (#126236)Hugo van Kemenade2024-11-123-3/+3
|
* Fix typos in comments and test code (#122846)Xie Yanbo2024-08-121-1/+1
|
* gh-121650: Encode newlines in headers, and verify headers are sound (GH-122233)Petr Viktorin2024-07-302-0/+88
| | | | | | | | | | | | | | | | | | | | | | | | | ## Encode header parts that contain newlines Per RFC 2047: > [...] these encoding schemes allow the > encoding of arbitrary octet values, mail readers that implement this > decoding should also ensure that display of the decoded data on the > recipient's terminal will not cause unwanted side-effects It seems that the "quoted-word" scheme is a valid way to include a newline character in a header value, just like we already allow undecodable bytes or control characters. They do need to be properly quoted when serialized to text, though. ## Verify that email headers are well-formed This should fail for custom fold() implementations that aren't careful about newlines. Co-authored-by: Bas Bloemsaat <bas@bloemsaat.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-120930: Remove extra blank occuring in wrapped encoded words in email ↵Matthieu Caneill2024-07-181-0/+13
| | | | headers (GH-121747)
* gh-120417: Remove unused imports in tests (part 2) (#120630)Victor Stinner2024-06-172-4/+1
|
* gh-118643: Fix AttributeError in the email module (GH-119099)Serhiy Storchaka2024-05-221-2/+10
| | | | | | | | Fix regression introduced in gh-100884: AttributeError when re-fold a long address list. Also fix more cases of incorrect encoding of the address separator in the address list missed in gh-100884.
* gh-92081: Fix for email.generator.Generator with whitespace between encoded ↵Toshio Kuratomi2024-05-202-1/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | words. (#92281) * Fix for email.generator.Generator with whitespace between encoded words. email.generator.Generator currently does not handle whitespace between encoded words correctly when the encoded words span multiple lines. The current generator will create an encoded word for each line. If the end of the line happens to correspond with the end real word in the plaintext, the generator will place an unencoded space at the start of the subsequent lines to represent the whitespace between the plaintext words. A compliant decoder will strip all the whitespace from between two encoded words which leads to missing spaces in the round-tripped output. The fix for this is to make sure that whitespace between two encoded words ends up inside of one or the other of the encoded words. This fix places the space inside of the second encoded word. A second problem happens with continuation lines. A continuation line that starts with whitespace and is followed by a non-encoded word is fine because the newline between such continuation lines is defined as condensing to a single space character. When the continuation line starts with whitespace followed by an encoded word, however, the RFCs specify that the word is run together with the encoded word on the previous line. This is because normal words are filded on syntactic breaks by encoded words are not. The solution to this is to add the whitespace to the start of the encoded word on the continuation line. Test cases are from #92081 * Rename a variable so it's not confused with the final variable.
* gh-118798: Remove deprecated isdst parameter from `email.utils.localtime` ↵Hugo van Kemenade2024-05-091-4/+0
| | | | (#118799)
* gh-80361: Fix TypeError in email.Message.get_payload() (GH-117994)Serhiy Storchaka2024-04-171-0/+15
| | | | | It was raised when the charset is rfc2231 encoded, e.g.: Content-Type: text/plain; charset*=ansi-x3.4-1968''utf-8
* bpo-40944: Fix IndexError when parse emails with truncated Message-ID, ↵Ivan Savin2024-04-171-0/+40
| | | | | address, routes, etc (GH-20790) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-117313: Fix re-folding email messages containing non-standard line ↵Serhiy Storchaka2024-04-171-0/+49
| | | | | | | separators (GH-117369) Only treat '\n', '\r' and '\r\n' as line separators in re-folding the email messages. Preserve control characters '\v', '\f', '\x1c', '\x1d' and '\x1e' and Unicode line separators '\x85', '\u2028' and '\u2029' as is.
* gh-86650: Fix IndexError when parse emails with invalid Message-ID (GH-117934)Serhiy Storchaka2024-04-171-0/+25
| | | | | | | In particularly, one-off addresses generated by Microsoft Outlook: https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/one-off-addresses Co-authored-by: fsc-eriker <72394365+fsc-eriker@users.noreply.github.com>
* gh-75171: Fix parsing invalid email address headers starting or ending with ↵tsufeki2024-04-172-0/+46
| | | | | | a dot (GH-15600) Co-authored-by: Tim Bell <timothybell@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-76511: Fix email.Message.as_string() for non-ASCII message with ASCII ↵Serhiy Storchaka2024-03-051-0/+15
| | | | charset (GH-116125)
* gh-100884: email/_header_value_parser: don't encode list separators (GH-100885)Thomas Weißschuh2024-02-171-0/+5
| | | | | ListSeparator should not be encoded. This could happen when a long line pushes its separator to the next line, which would have been encoded.
* gh-77749: Fix inconsistent behavior of non-ASCII handling in ↵Rito Takeuchi2024-01-261-0/+17
| | | | | | | EmailPolicy.fold() (GH-6986) It now always encodes non-ASCII characters in headers if utf8 is false. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-113027: Fix timezone check in test_variable_tzname in test_email (GH-113835)Pablo Galindo Salgado2024-01-121-1/+1
| | | Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-113594: Fix UnicodeEncodeError in TokenList.fold() (GH-113730)Serhiy Storchaka2024-01-101-0/+39
| | | It occurred when try to re-encode an unknown-8bit part combined with non-unknown-8bit part.
* gh-113027: Fix test_variable_tzname in test_email (#113821)Serhiy Storchaka2024-01-081-2/+2
| | | | | Determine the support of the Kyiv timezone by checking the result of astimezone() which uses the system tz database and not the one populated by zoneinfo.
* [CVE-2023-27043] gh-102988: Reject malformed addresses in email.parseaddr() ↵Victor Stinner2023-12-151-8/+179
| | | | | | | | | | (#111116) Detect email address parsing errors and return empty tuple to indicate the parsing error (old API). Add an optional 'strict' parameter to getaddresses() and parseaddr() functions. Patch by Thomas Dwyer. Co-Authored-By: Thomas Dwyer <github@tomd.tel>
* gh-94606: Fix error when message with Unicode surrogate not surrogateescaped ↵Sidney Markowitz2023-12-111-0/+29
| | | | | string (GH-94641) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-109017: Use non alternate name for Kyiv (GH-109251)Jochen Sprickerhof2023-10-241-7/+4
| | | | | | | | | | | | tzdata provides Kiev as an alternative to Kyiv: https://sources.debian.org/src/tzdata/2023c-10/backward/?hl=314#L314 But Debian moved it to the tzdata-legacy package breaking the test: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050530 This patch switches to the name provided by tzdata. Also check that the new name is actually available.
* no-issue: Fix typo TestContentTyopeHeader to TestContentTypeHeader (gh-109069)Jenner2023-09-191-1/+1
|
* gh-108416: Mark slow test methods with @requires_resource('cpu') (GH-108421)Serhiy Storchaka2023-09-021-0/+2
| | | | Only mark tests which spend significant system or user time, by itself or in subprocesses.
* Revert "Use non alternate name for Kyiv (GH-108533)" (GH-108649)Serhiy Storchaka2023-08-291-1/+1
| | | | | This reverts commit 7659128b9d7a30ddbcb063bc12e2ddb0f1f119e0. It broke tests on the Debian and macOS buildbots.
* Use non alternate name for Kyiv (GH-108533)Jochen Sprickerhof2023-08-291-1/+1
| | | | | | | | | | | tzdata provides Kiev as an alternative to Kyiv: https://sources.debian.org/src/tzdata/2023c-10/backward/?hl=314#L314 But Debian moved it to the tzdata-legacy package breaking the test: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050530 This patch switches to the name provided by tzdata.
* gh-106186: Don't report MultipartInvariantViolationDefect for valid ↵htsedebenham2023-07-232-0/+24
| | | | multipart emails when parsing header only (#107016)
* gh-106669: Revert "gh-102988: Detect email address parsing errors ... ↵Gregory P. Smith2023-07-211-77/+19
| | | | | | | | (#105127)" (#106733) This reverts commit 18dfbd035775c15533d13a98e56b1d2bf5c65f00. Adds a regression test from the issue. See https://github.com/python/cpython/issues/106669.
* gh-102988: Detect email address parsing errors and return empty tuple to ↵Thomas Dwyer2023-07-101-3/+78
| | | | | | | | | indicate the parsing error (old API) (#105127) Detect email address parsing errors and return empty tuple to indicate the parsing error (old API). This fixes or at least ameliorates CVE-2023-27043. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-106300: Improve `assertRaises(Exception)` usages in tests (GH-106302)Nikita Sobolev2023-07-071-2/+4
|
* gh-72346: Added isdst deprecation warning to email.utils.localtime (GH-91450)Alan Williams2023-03-201-4/+9
|
* gh-95087: Fix IndexError in parsing invalid date in the email module (GH-95201)Serhiy Storchaka2022-07-252-23/+55
| | | | Co-authored-by: wouter bolsterlee <wouter@bolsterl.ee>
* gh-84623: Remove unused imports in tests (#93772)Victor Stinner2022-06-131-2/+1
|
* gh-93010: InvalidHeaderError used but nonexistent (#93015)oda-gitso2022-05-231-8/+14
| | | | | * fix issue 93010 Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* bpo-43323: Fix UnicodeEncodeError in the email module (GH-32137)Serhiy Storchaka2022-04-303-0/+28
| | | | | It was raised if the charset itself contains characters not encodable in UTF-8 (in particular \udcxx characters representing non-decodable bytes in the source).
* Rewrite audio.py to jive with image.py (#91886)Barry Warsaw2022-04-245-11/+23
| | | | | | | Similar to the rewrite of email/mime/image.py and associated test after the deprecation of imghdr.py, thisrewrites email/mime/audio.py and associated tests after the deprecation of sndhdr.py. Closes #91885
* gh-91520: Rewrite imghdr inlining for clarity and completeness (#91521)Barry Warsaw2022-04-1515-7/+36
| | | | | | | | | | | | | | | | | | | | * Rewrite imghdr inlining for clarity and completeness * Move MIMEImage class back closer to the top of the file since it's the important thing. * Use a decorate to mark a given rule function and simplify the rule function names for clarity. * Copy over all the imghdr test data files into the email package's test data directory. This way when imghdr is actually removed, it won't affect the MIMEImage guessing tests. * Rewrite and extend the MIMEImage tests to test for all supported auto-detected MIME image subtypes. * Remove the now redundant PyBanner048.gif data file. * See https://github.com/python/cpython/pull/91461#discussion_r850313336 Co-authored-by: Oleg Iarygin <dralife@yandex.ru> Co-authored-by: Oleg Iarygin <dralife@yandex.ru>
* gh-91217: deprecate imghdr (#91461)Brett Cannon2022-04-131-1/+1
| | | | | | | | | | | | | | * Deprecate imghdr Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> * Update Doc/whatsnew/3.11.rst Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> * Inline `imghdr` into `email.mime.image` Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Barry Warsaw <barry@python.org>
* bpo-40280: Detect missing threading on WASM platforms (GH-32352)Christian Heimes2022-04-071-0/+1
| | | Co-authored-by: Brett Cannon <brett@python.org>
* bpo-46198: rename duplicate tests and remove unused code (GH-30297)Nikita Sobolev2022-03-101-1/+1
|
* Optimize images by IMGbot (GH-21348)Manish Kumar ⛄2022-02-041-0/+0
| | | Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com>
* bpo-19460: Add test for MIMENonMultipart (GH-29817)1809092021-11-281-0/+14
|
* bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452)Ben Hoyt2021-10-131-0/+1
| | | Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* Fix typos in the Lib directory (GH-28775)Christian Clauss2021-10-061-1/+1
| | | | | Fix typos in the Lib directory as identified by codespell. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-5846: Do not use obsolete unittest functions. (GH-28303)Serhiy Storchaka2021-09-131-16/+10
| | | | Get rid of use of makeSuite() and findTestCases(). Also make test_math and test_threading_local discoverable.
* bpo-45001: Make email date parsing more robust against malformed input ↵wouter bolsterlee2021-08-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (GH-27946) 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. >>> import email.utils >>> email.utils.parsedate('foo') >>> email.utils.parsedate(' ') Traceback (most recent call last): File "<stdin>", line 1, in <module> 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.
* bpo-41402: Fix email ContentManager calling .encode() on bytes (GH-21631)Johannes Reiff2021-08-091-0/+12
|
* bpo-42892: fix email multipart attribute error (GH-26903)andrei kulakov2021-07-301-1/+33
|
* bpo-27513: email.utils.getaddresses() now handles Header objects (#13797)Zackery Spytz2021-07-191-0/+5
| | | | | | getaddresses() should be able to handle a Header object if passed one. Co-authored-by: Łukasz Langa <lukasz@langa.pl>