mirror of
https://github.com/domainaware/parsedmarc.git
synced 2026-07-05 16:25:09 +00:00
maildir fixes
This commit is contained in:
+5
-5
@@ -20,8 +20,8 @@ from parsedmarc import get_dmarc_reports_from_mailbox, watch_inbox, \
|
||||
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
|
||||
@@ -505,8 +505,8 @@ def _main():
|
||||
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,
|
||||
@@ -1016,7 +1016,7 @@ def _main():
|
||||
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"]
|
||||
|
||||
+13
-13
@@ -1,15 +1,11 @@
|
||||
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,
|
||||
@@ -17,18 +13,22 @@ class MaildirConnection(MailboxConnection):
|
||||
):
|
||||
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):
|
||||
@@ -41,9 +41,10 @@ class MaildirConnection(MailboxConnection):
|
||||
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)
|
||||
|
||||
@@ -57,4 +58,3 @@ class MaildirConnection(MailboxConnection):
|
||||
except Exception as e:
|
||||
logger.warning("Maildir init error. {0}".format(e))
|
||||
sleep(check_timeout)
|
||||
|
||||
Reference in New Issue
Block a user