From 1035983f4bd56f4dca43649ff569c4d254697d04 Mon Sep 17 00:00:00 2001 From: Sean Whalen Date: Sat, 21 Mar 2026 15:08:27 -0400 Subject: [PATCH] Rename 'should_reload' parameter to 'config_reloading' in mailbox connection methods for clarity --- CHANGELOG.md | 2 +- parsedmarc/__init__.py | 8 ++++---- parsedmarc/cli.py | 2 +- parsedmarc/mail/gmail.py | 6 +++--- parsedmarc/mail/graph.py | 6 +++--- parsedmarc/mail/imap.py | 6 +++--- parsedmarc/mail/mailbox_connection.py | 2 +- parsedmarc/mail/maildir.py | 6 +++--- tests.py | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e96a67..1504dfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - On a successful reload, old output clients are closed and recreated. - On a failed reload, the previous configuration remains fully active. - `close()` methods on `GelfClient`, `KafkaClient`, `SyslogClient`, `WebhookClient`, HECClient, and `S3Client` for clean resource teardown on reload. -- `should_reload` parameter on all `MailboxConnection.watch()` implementations and `watch_inbox()` to ensure SIGHUP never triggers a new email batch mid-reload. +- `config_reloading` parameter on all `MailboxConnection.watch()` implementations and `watch_inbox()` to ensure SIGHUP never triggers a new email batch mid-reload. - Elasticsearch and OpenSearch connections are now tracked and cleaned up on reload via `_close_output_clients()`. - Extracted `_parse_config_file()` and `_init_output_clients()` from `_main()` in `cli.py` to support config reload and reduce code duplication. diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index 9d439b2..1b9ddfc 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -2195,7 +2195,7 @@ def watch_inbox( batch_size: int = 10, since: Optional[Union[datetime, date, str]] = None, normalize_timespan_threshold_hours: float = 24, - should_reload: Optional[Callable] = None, + config_reloading: Optional[Callable] = None, ): """ Watches the mailbox for new messages and @@ -2223,7 +2223,7 @@ def watch_inbox( batch_size (int): Number of messages to read and process before saving since: Search for messages since certain time normalize_timespan_threshold_hours (float): Normalize timespans beyond this - should_reload: Optional callable that returns True when a config + config_reloading: Optional callable that returns True when a config reload has been requested (e.g. via SIGHUP) """ @@ -2253,8 +2253,8 @@ def watch_inbox( "check_callback": check_callback, "check_timeout": check_timeout, } - if should_reload is not None: - watch_kwargs["should_reload"] = should_reload + if config_reloading is not None: + watch_kwargs["config_reloading"] = config_reloading mailbox_connection.watch(**watch_kwargs) diff --git a/parsedmarc/cli.py b/parsedmarc/cli.py index c813012..110e24a 100644 --- a/parsedmarc/cli.py +++ b/parsedmarc/cli.py @@ -2025,7 +2025,7 @@ def _main(): reverse_dns_map_url=opts.reverse_dns_map_url, offline=opts.offline, normalize_timespan_threshold_hours=normalize_timespan_threshold_hours_value, - should_reload=lambda: _reload_requested, + config_reloading=lambda: _reload_requested, ) except FileExistsError as error: logger.error("{0}".format(error.__str__())) diff --git a/parsedmarc/mail/gmail.py b/parsedmarc/mail/gmail.py index 6eec937..924ba7e 100644 --- a/parsedmarc/mail/gmail.py +++ b/parsedmarc/mail/gmail.py @@ -175,13 +175,13 @@ class GmailConnection(MailboxConnection): # Not needed pass - def watch(self, check_callback, check_timeout, should_reload=None): + def watch(self, check_callback, check_timeout, config_reloading=None): """Checks the mailbox for new messages every n seconds""" while True: - if should_reload and should_reload(): + if config_reloading and config_reloading(): return sleep(check_timeout) - if should_reload and should_reload(): + if config_reloading and config_reloading(): return check_callback(self) diff --git a/parsedmarc/mail/graph.py b/parsedmarc/mail/graph.py index a2f5c0e..7df039c 100644 --- a/parsedmarc/mail/graph.py +++ b/parsedmarc/mail/graph.py @@ -278,13 +278,13 @@ class MSGraphConnection(MailboxConnection): # Not needed pass - def watch(self, check_callback, check_timeout, should_reload=None): + def watch(self, check_callback, check_timeout, config_reloading=None): """Checks the mailbox for new messages every n seconds""" while True: - if should_reload and should_reload(): + if config_reloading and config_reloading(): return sleep(check_timeout) - if should_reload and should_reload(): + if config_reloading and config_reloading(): return check_callback(self) diff --git a/parsedmarc/mail/imap.py b/parsedmarc/mail/imap.py index b084bd9..5201fa7 100644 --- a/parsedmarc/mail/imap.py +++ b/parsedmarc/mail/imap.py @@ -81,7 +81,7 @@ class IMAPConnection(MailboxConnection): def keepalive(self): self._client.noop() - def watch(self, check_callback, check_timeout, should_reload=None): + def watch(self, check_callback, check_timeout, config_reloading=None): """ Use an IDLE IMAP connection to parse incoming emails, and pass the results to a callback function @@ -94,7 +94,7 @@ class IMAPConnection(MailboxConnection): check_callback(self) while True: - if should_reload and should_reload(): + if config_reloading and config_reloading(): return try: IMAPClient( @@ -113,5 +113,5 @@ class IMAPConnection(MailboxConnection): except Exception as e: logger.warning("IMAP connection error. {0}. Reconnecting...".format(e)) sleep(check_timeout) - if should_reload and should_reload(): + if config_reloading and config_reloading(): return diff --git a/parsedmarc/mail/mailbox_connection.py b/parsedmarc/mail/mailbox_connection.py index 670af28..6c94336 100644 --- a/parsedmarc/mail/mailbox_connection.py +++ b/parsedmarc/mail/mailbox_connection.py @@ -28,5 +28,5 @@ class MailboxConnection(ABC): def keepalive(self): raise NotImplementedError - def watch(self, check_callback, check_timeout, should_reload=None): + def watch(self, check_callback, check_timeout, config_reloading=None): raise NotImplementedError diff --git a/parsedmarc/mail/maildir.py b/parsedmarc/mail/maildir.py index 20b08a0..fa23dd3 100644 --- a/parsedmarc/mail/maildir.py +++ b/parsedmarc/mail/maildir.py @@ -63,14 +63,14 @@ class MaildirConnection(MailboxConnection): def keepalive(self): return - def watch(self, check_callback, check_timeout, should_reload=None): + def watch(self, check_callback, check_timeout, config_reloading=None): while True: - if should_reload and should_reload(): + if config_reloading and config_reloading(): return try: check_callback(self) except Exception as e: logger.warning("Maildir init error. {0}".format(e)) - if should_reload and should_reload(): + if config_reloading and config_reloading(): return sleep(check_timeout) diff --git a/tests.py b/tests.py index faf18fa..739cf5c 100755 --- a/tests.py +++ b/tests.py @@ -1278,7 +1278,7 @@ class TestMailboxWatchSince(unittest.TestCase): def testWatchInboxPassesSinceToMailboxFetch(self): mailbox_connection = SimpleNamespace() - def fake_watch(check_callback, check_timeout, should_reload=None): + def fake_watch(check_callback, check_timeout, config_reloading=None): check_callback(mailbox_connection) raise _BreakLoop()