Skip to content

Commit

Permalink
maildir fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seanthegeek committed Sep 12, 2024
1 parent 266d57e commit 7633a30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions parsedmarc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
parse_report_file, get_dmarc_reports_from_mbox, elastic, opensearch, \
kafkaclient, splunk, save_output, email_results, ParserError, \
__version__, InvalidDMARCReport, s3, syslog, loganalytics, gelf
from parsedmarc.mail import IMAPConnection, MSGraphConnection, GmailConnection, \
MaildirConnection
from parsedmarc.mail import IMAPConnection, MSGraphConnection, \
GmailConnection, MaildirConnection
from parsedmarc.mail.graph import AuthMethod

from parsedmarc.log import logger
Expand Down Expand Up @@ -505,8 +505,8 @@ def process_reports(reports_):
gmail_api_paginate_messages=True,
gmail_api_scopes=[],
gmail_api_oauth2_port=8080,
maildir_path = None,
maildir_create = False,
maildir_path=None,
maildir_create=False,
log_file=args.log_file,
n_procs=1,
ip_db_path=None,
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def process_reports(reports_):
opts.maildir_path = \
maildir_api_config.get("maildir_path")
opts.maildir_create = \
maildir_api_config.get("maildir_create")
maildir_api_config.get("maildir_create")

if "log_analytics" in config.sections():
log_analytics_config = config["log_analytics"]
Expand Down
26 changes: 13 additions & 13 deletions parsedmarc/mail/maildir.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from time import sleep

#from imapclient.exceptions import IMAPClientError
#from mailsuite.imap import IMAPClient
from socket import timeout

from parsedmarc.log import logger
from parsedmarc.mail.mailbox_connection import MailboxConnection
#import email
import mailbox
import os


class MaildirConnection(MailboxConnection):
def __init__(self,
maildir_path=None,
maildir_create=False,
):
self._maildir_path = maildir_path
self._maildir_create = maildir_create
maildir_owner=os.stat(maildir_path).st_uid
maildir_owner = os.stat(maildir_path).st_uid
if os.getuid() != maildir_owner:
if os.getuid() == 0:
logger.warning("Switching uid to {} to access Maildir".format(maildir_owner))
logger.warning("Switching uid to {} to access Maildir".format(
maildir_owner))
os.setuid(maildir_owner)
else:
raise Exception('runtime uid {} differ from maildir {} owner {}'.format(os.getuid().maildir_path,maildir_owner))
ex = 'runtime uid {} differ from maildir {} owner {}'.format(
os.getuid(), maildir_path, maildir_owner)
raise Exception(ex)
self._client = mailbox.Maildir(maildir_path, create=maildir_create)
self._subfolder_client={}
self._subfolder_client = {}

def create_folder(self, folder_name: str):
self._subfolder_client[folder_name]=self._client.add_folder(folder_name)
self._subfolder_client[folder_name] = self._client.add_folder(
folder_name)
self._client.add_folder(folder_name)

def fetch_messages(self, reports_folder: str, **kwargs):
Expand All @@ -41,9 +41,10 @@ def delete_message(self, message_id: str):
self._client.remove(message_id)

def move_message(self, message_id: str, folder_name: str):
message_data=self._client.get(message_id)
message_data = self._client.get(message_id)
if folder_name not in self._subfolder_client.keys():
self._subfolder_client = mailbox.Maildir(os.join(maildir_path,folder_name), create=maildir_create)
self._subfolder_client = mailbox.Maildir(os.join(
self.maildir_path, folder_name), create=self.maildir_create)
self._subfolder_client[folder_name].add(message_data)
self._client.remove(message_id)

Expand All @@ -57,4 +58,3 @@ def watch(self, check_callback, check_timeout):
except Exception as e:
logger.warning("Maildir init error. {0}".format(e))
sleep(check_timeout)

0 comments on commit 7633a30

Please sign in to comment.