add debug

This commit is contained in:
Antonio J. Delgado 2024-09-30 23:48:40 +03:00
parent 6040eb17cc
commit 7b86e093e8

View file

@ -141,6 +141,10 @@ class ImapFilter:
else:
content = '# Managed by imap_filter. Some lines might get replaced if the match with rule name from imap_filter'
for mfilter in filters:
self._log.debug(
'Adding filter %s to sieve script',
mfilter['name']
)
if 'field' in mfilter:
field = mfilter['field']
else:
@ -153,10 +157,22 @@ class ImapFilter:
replacement = f'if {condition} {{ fileinto "{mfilter['destination']}"; stop;}} # imap_filter: rule name \'imap_filter_INBOX_{mfilter['name']}\''
match = re.search(search, content)
if match:
self._log.debug(
"Line '%s' found in current file",
search
)
new_content = re.sub(search, replacement, content)
if content != new_content:
self._log.debug(
"It's different, so replacing it with '%s'",
replacement
)
content = f"{new_content}\n"
else:
self._log.debug(
"Line '%s' not found in current file, adding it",
search
)
content += f"{replacement}\n"
with open(self.config['sieve_scripts_path'], 'w', encoding='UTF-8') as sieve_script:
sieve_script.write(content)