From 7b86e093e823f1efa17df47c4ddf6060124f26d6 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 30 Sep 2024 23:48:40 +0300 Subject: [PATCH] add debug --- imap_filter/imap_filter.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/imap_filter/imap_filter.py b/imap_filter/imap_filter.py index 4382943..911197b 100644 --- a/imap_filter/imap_filter.py +++ b/imap_filter/imap_filter.py @@ -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)