From 06d8578c47e632f69765f3ed93a31f4f1dcf7cb8 Mon Sep 17 00:00:00 2001 From: Gaige B Paulsen Date: Mon, 2 Sep 2024 17:27:28 -0400 Subject: [PATCH] fix: use namespace for separator (#552) --- parsedmarc/__init__.py | 13 +++++++++---- parsedmarc/mail/imap.py | 8 ++++++++ parsedmarc/mail/mailbox_connection.py | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index d054b35..98a29a1 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -1423,10 +1423,15 @@ def get_dmarc_reports_from_mailbox(connection: MailboxConnection, aggregate_report_msg_uids = [] forensic_report_msg_uids = [] smtp_tls_msg_uids = [] - aggregate_reports_folder = "{0}/Aggregate".format(archive_folder) - forensic_reports_folder = "{0}/Forensic".format(archive_folder) - smtp_tls_reports_folder = "{0}/SMTP-TLS".format(archive_folder) - invalid_reports_folder = "{0}/Invalid".format(archive_folder) + folder_separator = connection.get_folder_separator() + aggregate_reports_folder = "{0}{1}Aggregate".format(archive_folder, + folder_separator) + forensic_reports_folder = "{0}{1}Forensic".format(archive_folder, + folder_separator) + smtp_tls_reports_folder = "{0}{1}SMTP-TLS".format(archive_folder, + folder_separator) + invalid_reports_folder = "{0}{1}Invalid".format(archive_folder, + folder_separator) if results: aggregate_reports = results["aggregate_reports"].copy() diff --git a/parsedmarc/mail/imap.py b/parsedmarc/mail/imap.py index 150185e..4ffa55f 100644 --- a/parsedmarc/mail/imap.py +++ b/parsedmarc/mail/imap.py @@ -26,6 +26,14 @@ class IMAPConnection(MailboxConnection): timeout=timeout, max_retries=max_retries) + def get_folder_separator(self): + try: + namespaces = self._client.namespace() + personal = namespaces.personal[0] + return personal[1] + except (IndexError, NameError): + return '/' + def create_folder(self, folder_name: str): self._client.create_folder(folder_name) diff --git a/parsedmarc/mail/mailbox_connection.py b/parsedmarc/mail/mailbox_connection.py index ecaa2cb..ba7c2cf 100644 --- a/parsedmarc/mail/mailbox_connection.py +++ b/parsedmarc/mail/mailbox_connection.py @@ -6,6 +6,9 @@ class MailboxConnection(ABC): """ Interface for a mailbox connection """ + def get_folder_separator(self): + return "/" + def create_folder(self, folder_name: str): raise NotImplementedError