mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Merge pull request #3872 from modoboa/2336-fix-serach-criteria
fix(imap): issue when pattern is empty
This commit is contained in:
@@ -292,16 +292,21 @@ class IMAPconnector:
|
||||
return f"OR {old} {c}"
|
||||
|
||||
if criterion == "both":
|
||||
criterion = "from_addr, subject"
|
||||
criterions = ""
|
||||
for c in criterion.split(","):
|
||||
if c == "from_addr":
|
||||
key = "FROM"
|
||||
elif c == "subject":
|
||||
key = "SUBJECT"
|
||||
else:
|
||||
continue
|
||||
criterions = or_criterion(criterions, f'({key} "{pattern}")')
|
||||
criterion = "from_addr,subject"
|
||||
|
||||
if not pattern:
|
||||
criterions = "ALL"
|
||||
else:
|
||||
criterions = ""
|
||||
for c in criterion.split(","):
|
||||
if c == "from_addr":
|
||||
key = "FROM"
|
||||
elif c == "subject":
|
||||
key = "SUBJECT"
|
||||
else:
|
||||
continue
|
||||
criterions = or_criterion(criterions, f'({key} "{pattern}")')
|
||||
|
||||
self.criterions = [bytearray(criterions, "utf8")]
|
||||
|
||||
def messages_count(self, **kwargs) -> int:
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
"""mailutils tests"""
|
||||
|
||||
import unittest
|
||||
|
||||
from modoboa.webmail.lib.imaputils import IMAPconnector
|
||||
|
||||
|
||||
class ImapUtilsTestCase(unittest.TestCase):
|
||||
"""Test mail utils library"""
|
||||
|
||||
def setUp(self):
|
||||
self.imap_connector = IMAPconnector(user="test", password="test")
|
||||
|
||||
def test_criterions_one_criterion_with_pattern(self):
|
||||
"""Test with Criterion and pattern"""
|
||||
self.imap_connector.criterions = []
|
||||
self.imap_connector.parse_search_parameters("from_addr", "bob")
|
||||
result = [bytearray('(FROM "bob")', "utf8")]
|
||||
self.assertEqual(self.imap_connector.criterions, result)
|
||||
|
||||
def test_criterions_both_criterion_with_pattern(self):
|
||||
"""Test with both Criterion and pattern"""
|
||||
self.imap_connector.criterions = []
|
||||
self.imap_connector.parse_search_parameters("both", "bob")
|
||||
result = [bytearray('OR (FROM "bob") (SUBJECT "bob")', "utf8")]
|
||||
self.assertEqual(self.imap_connector.criterions, result)
|
||||
|
||||
def test_criterions_one_criterion_without_pattern(self):
|
||||
"""Test with Criterion and empty pattern"""
|
||||
self.imap_connector.criterions = []
|
||||
self.imap_connector.parse_search_parameters("SEEN", "")
|
||||
result = [bytearray("ALL", "utf8")]
|
||||
self.assertEqual(self.imap_connector.criterions, result)
|
||||
Reference in New Issue
Block a user