[release-24.05] python311Packages.imap-tools: backport regression fix (#355108)

This commit is contained in:
Atemu 2024-11-11 03:36:32 +01:00 committed by GitHub
commit f2207998de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,68 @@
From e7ee5f5d93315c48b1193a5d7471cbc0d8d97c41 Mon Sep 17 00:00:00 2001
From: "v.kaukin" <v.kaukin@u6.ru>
Date: Fri, 4 Oct 2024 10:32:50 +0500
Subject: [PATCH] Fixed bug in 3.12.6+ after [CVE-2023-27043]
(cherry picked from commit 017208a87d497aae6fe90f6d250a1c786615e241)
---
imap_tools/utils.py | 7 ++++++-
tests/test_utils.py | 11 ++++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/imap_tools/utils.py b/imap_tools/utils.py
index 18bacee..9c87bbf 100644
--- a/imap_tools/utils.py
+++ b/imap_tools/utils.py
@@ -78,6 +78,11 @@ class EmailAddress:
return all(getattr(self, i) == getattr(other, i) for i in self.__slots__)
+def remove_non_printable(value: str) -> str:
+ """Remove non-printable character from value"""
+ return ''.join(i for i in value if i.isprintable())
+
+
def parse_email_addresses(raw_header: Union[str, Header]) -> Tuple[EmailAddress, ...]:
"""
Parse email addresses from header
@@ -87,7 +92,7 @@ def parse_email_addresses(raw_header: Union[str, Header]) -> Tuple[EmailAddress,
result = []
if type(raw_header) is Header:
raw_header = decode_value(*decode_header(raw_header)[0])
- for raw_name, email in getaddresses([raw_header.replace('\r\n', '').replace('\n', '')]):
+ for raw_name, email in getaddresses([remove_non_printable(raw_header)]):
name = decode_value(*decode_header(raw_name)[0]).strip()
email = email.strip()
if not (name or email):
diff --git a/tests/test_utils.py b/tests/test_utils.py
index abc4b38..f586641 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,14 +1,23 @@
import unittest
import datetime
+import unicodedata
from imap_tools.errors import ImapToolsError, UnexpectedCommandStatusError, MailboxCopyError
from imap_tools.consts import MailMessageFlags
from imap_tools.utils import clean_flags, chunks, quote, pairs_to_dict, decode_value, check_command_status, \
- parse_email_date, parse_email_addresses, EmailAddress, clean_uids, replace_html_ct_charset
+ parse_email_date, parse_email_addresses, EmailAddress, clean_uids, replace_html_ct_charset, remove_non_printable
class UtilsTest(unittest.TestCase):
+ def test_remove_non_printable(self):
+ all_non_printable_chars = []
+ for i in range(0x110000): # Диапазон всех кодовых точек Unicode
+ char = chr(i)
+ if unicodedata.category(char).startswith('C'):
+ all_non_printable_chars.append(char)
+ self.assertEqual(remove_non_printable('123{}'.format(''.join(all_non_printable_chars))), '123')
+
def test_clean_uids(self):
# *clean_uids also implicitly tested in test_query.py
self.assertEqual(clean_uids('11'), '11')
--
2.47.0

View File

@ -21,6 +21,11 @@ buildPythonPackage rec {
hash = "sha256-kY6Y8Uu1HwSkcmlKL5+zPh4n+4mofX2aoPVXAZvInlI=";
};
patches = [
# https://github.com/ikvk/imap_tools/commit/017208a87d497aae6fe90f6d250a1c786615e241
./0001-Fixed-bug-in-3.12.6-after-CVE-2023-27043.patch
];
nativeCheckInputs = [ pytestCheckHook ];
disabledTests = [