Fix silent failures and false success pings

- Collapse folded Message-ID headers before IMAP SEARCH; embedded
  CRLF was breaking the command and crashing every run
- Set Type=oneshot so the success ping only fires on clean exit
  instead of on every spawn, letting OnFailure report real failures

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeena 2026-06-05 22:38:10 +00:00
parent c39abe0509
commit 136db55905
2 changed files with 4 additions and 0 deletions

View file

@ -3,6 +3,7 @@ Description=Email Forwarder
OnFailure=email_forwarder-fail-notify.service
[Service]
Type=oneshot
WorkingDirectory=${PROJECT_DIR}
ExecStart=${PROJECT_DIR}/venv/bin/python -m email_forwarder
EnvironmentFile=${PROJECT_DIR}/.env

View file

@ -197,6 +197,9 @@ class EmailForwarder:
msg_id = msg.get("Message-ID")
if not msg_id:
continue
# Collapse folded headers (embedded CRLF/whitespace) so the
# Message-ID is safe to embed in an IMAP SEARCH command.
msg_id = "".join(msg_id.split())
if msg_id in self.processed_ids:
continue
self.dest.ensure_folder_exists(folder)