about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAtemu2024-11-11 03:36:32 +0100
committerGitHub2024-11-11 03:36:32 +0100
commitf2207998de8a250de7f550d9cba7e3ce4c01c63c (patch)
treedbf126f193a6445d78943434e8cb35e56712173e
parent634700d1c8e9edfb0da4dd8192f8aee490069e26 (diff)
parentabe8e044d36ba7f744aa2976baaf25e1c93b433b (diff)
[release-24.05] python311Packages.imap-tools: backport regression fix (#355108)
-rw-r--r--pkgs/development/python-modules/imap-tools/0001-Fixed-bug-in-3.12.6-after-CVE-2023-27043.patch68
-rw-r--r--pkgs/development/python-modules/imap-tools/default.nix5
2 files changed, 73 insertions, 0 deletions
diff --git a/pkgs/development/python-modules/imap-tools/0001-Fixed-bug-in-3.12.6-after-CVE-2023-27043.patch b/pkgs/development/python-modules/imap-tools/0001-Fixed-bug-in-3.12.6-after-CVE-2023-27043.patch
new file mode 100644
index 000000000000..d22bbf35a387
--- /dev/null
+++ b/pkgs/development/python-modules/imap-tools/0001-Fixed-bug-in-3.12.6-after-CVE-2023-27043.patch
@@ -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
+
diff --git a/pkgs/development/python-modules/imap-tools/default.nix b/pkgs/development/python-modules/imap-tools/default.nix
index ce6a88040fad..02b0f147847e 100644
--- a/pkgs/development/python-modules/imap-tools/default.nix
+++ b/pkgs/development/python-modules/imap-tools/default.nix
@@ -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 = [