add more debug

This commit is contained in:
Antonio J. Delgado 2025-02-05 10:55:38 +02:00
parent 0d6aff6821
commit 3245bd0e2f

View file

@ -47,10 +47,21 @@ class ImapFilter:
self._init_log()
signal(SIGINT, self._signal_handler)
with open(self.config['filters_file'], 'r', encoding='UTF-8') as filters_file:
self._log.debug(
"Reading filters file '%s'...",
self.config['filters_file']
)
if '.json' in self.config['filters_file'].lower():
self.config['mailboxes'] = json.load(filters_file)
elif '.yaml' in self.config['filters_file'].lower() or '.yml' in self.config['filters_file'].lower():
elif (
'.yaml' in self.config['filters_file'].lower() or
'.yml' in self.config['filters_file'].lower()
):
self.config['mailboxes'] = load(filters_file, Loader=Loader)
self._log.debug(
'Total of %s mailboxes read',
len(self.config['mailboxes'])
)
if len(self.config['mailboxes']) == 0:
self._log.error(
"Filters file is empty. Use --help to see more details."
@ -74,6 +85,11 @@ class ImapFilter:
break
if mailbox['mailbox'] == 'INBOX' and self.config['sieve_scripts_path']:
self._create_sieve_script(mailbox['filters'])
else:
self._log.debug(
"Mailbox '%s' won't be processed to create Sieve scripts",
mailbox['mailbox']
)
self._log.debug(
"Processing mailbox '%s'...",
mailbox['mailbox']
@ -144,6 +160,10 @@ class ImapFilter:
def _create_sieve_script(self, filters):
if os.path.exists(self.config['sieve_scripts_path']):
self._log.debug(
"Updating Sieve script in '%s'...",
self.config['sieve_scripts_path']
)
if os.geteuid() == 0:
file_path = Path(self.config['sieve_scripts_path'])
owner = file_path.owner()
@ -151,6 +171,10 @@ class ImapFilter:
with open(self.config['sieve_scripts_path'], 'r', encoding='UTF-8') as sieve_script:
content = sieve_script.read()
else:
self._log.debug(
"Will create Sieve script in '%s'...",
self.config['sieve_scripts_path']
)
content = '# Managed by imap_filter. Some lines might get replaced if the match with rule name from imap_filter'
content += 'require ["fileinto"];'
for mfilter in filters: