diff --git a/modoboa/webmail/lib/imaputils.py b/modoboa/webmail/lib/imaputils.py index 120de33c8..44435d27d 100644 --- a/modoboa/webmail/lib/imaputils.py +++ b/modoboa/webmail/lib/imaputils.py @@ -1,7 +1,6 @@ """Extra IMAPv4 utilities.""" import email -from functools import wraps import imaplib import re import ssl @@ -19,7 +18,7 @@ from modoboa.parameters import tools as param_tools from ..exceptions import ImapError, WebmailInternalError from .fetch_parser import FetchResponseParser -# imaplib.Debug = 4 +imaplib.Debug = 4 # workaround for the "got more than 10000 bytes" exception. MAXLINE # value set to 1M, as on latest python versions. @@ -28,29 +27,6 @@ if hasattr(imaplib, "_MAXLINE") and imaplib._MAXLINE < MAXLINE: imaplib._MAXLINE = MAXLINE -class capability: - """ - Simple decorator to check if the server presents the required - capability. If not, a fallback method is called instead. - - :param name: the capability name (upper case) - :param fallback_method: a method's name - """ - - def __init__(self, name: str, fallback_method: str): - self.name = name - self.fallback_method = fallback_method - - def __call__(self, method): - @wraps(method) - def wrapped_func(cls, *args, **kwargs): - if self.name in cls.capabilities: - return method(cls, *args, **kwargs) - return getattr(cls, self.fallback_method)(cls, **kwargs) - - return wrapped_func - - class BodyStructure: """ BODYSTRUCTURE response parser. @@ -411,45 +387,6 @@ class IMAPconnector: sdescr["class"] = "subfolders" return True - def _listmboxes_simple( - self, topmailbox: str = "INBOX", mailboxes: Optional[list] = None, **kwargs - ) -> None: - # data = self._cmd("LIST", "", "*") - if not mailboxes: - mailboxes = [] - (status, data) = self.m.list() - newmboxes = [] - for mb in data: - flags, delimiter, name = self.list_response_pattern.match( - mb.decode() - ).groups() - name = bytearray(name.strip('"'), "utf-8").decode("imap4-utf-7") - mdm_found = False - for idx, mdm in enumerate(mailboxes): - if mdm["name"] == name: - mdm_found = True - descr = mailboxes[idx] - break - if not mdm_found: - descr = {"name": name} - newmboxes += [descr] - - if re.search(rf"\{delimiter}", name): - parts = name.split(delimiter) - if "path" not in descr: - descr["path"] = parts[0] - descr["sub"] = [] - if self._parse_mailbox_name( - descr["sub"], parts[0], delimiter, parts[1:] - ): - descr["class"] = "subfolders" - continue - - from operator import itemgetter - - mailboxes += sorted(newmboxes, key=itemgetter("name")) - - @capability("LIST-EXTENDED", "_listmboxes_simple") def _listmboxes(self, topmailbox: str, mailboxes: list, until_mailbox=None) -> None: """Retrieve mailboxes list.""" pattern = ( diff --git a/modoboa/webmail/tests/test_viewsets.py b/modoboa/webmail/tests/test_viewsets.py index 2659fc347..1a724904c 100644 --- a/modoboa/webmail/tests/test_viewsets.py +++ b/modoboa/webmail/tests/test_viewsets.py @@ -49,6 +49,8 @@ class IMAP4Mock: self.untagged_responses["LIST"] = [b'() "." "INBOX"'] elif name == "NAMESPACE": self.untagged_responses["NAMESPACE"] = [b'(("" "/")) NIL NIL'] + elif name == "STATUS": + self.untagged_responses["STATUS"] = [b"STATUS INBOX (UNSEEN 10)"] return "OK", None def append(self, *args, **kwargs):