]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Chore: Fixes the TO filter chaining so it doesn't reset the messages list + determini...
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 3 Feb 2026 19:31:19 +0000 (11:31 -0800)
committerGitHub <noreply@github.com>
Tue, 3 Feb 2026 19:31:19 +0000 (11:31 -0800)
src/paperless_mail/tests/test_mail.py

index 305c2854c89b17a1c6dee0ee89581969b0543b9c..51a1929ab8dc8a5938797971ab73ace651a5f539 100644 (file)
@@ -1,6 +1,5 @@
 import dataclasses
 import email.contentmanager
-import random
 import time
 import uuid
 from collections import namedtuple
@@ -148,11 +147,7 @@ class BogusMailBox(AbstractContextManager):
 
         if "TO" in criteria:
             to_ = criteria[criteria.index("TO") + 1].strip('"')
-            msg = []
-            for m in self.messages:
-                for to_addrs in m.to:
-                    if to_ in to_addrs:
-                        msg.append(m)
+            msg = filter(lambda m: any(to_ in to_addr for to_addr in m.to), msg)
 
         if "UNFLAGGED" in criteria:
             msg = filter(lambda m: not m.flagged, msg)
@@ -204,7 +199,7 @@ def fake_magic_from_buffer(buffer, *, mime=False):
 
 class MessageBuilder:
     def __init__(self) -> None:
-        self._used_uids = set()
+        self._next_uid = 1
 
     def create_message(
         self,
@@ -257,10 +252,8 @@ class MessageBuilder:
         # TODO: Unsure how to add a uid to the actual EmailMessage. This hacks it in,
         #  based on how imap_tools uses regex to extract it.
         #  This should be a large enough pool
-        uid = random.randint(1, 10000)
-        while uid in self._used_uids:
-            uid = random.randint(1, 10000)
-        self._used_uids.add(uid)
+        uid = self._next_uid
+        self._next_uid += 1
 
         imap_msg._raw_uid_data = f"UID {uid}".encode()