From 20c9504ea9931799b5961609d579b4b30e86b584 Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Tue, 27 Oct 2026 12:59:13 +0100 Subject: [PATCH] Delete empty and whitespace-only notes without sending a mail This also fixes the -v output for such notes, which referred to a mail that was never sent and was logged as a send failure. --- hedgedoc-expire.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py index 405b093..26d3b9d 100644 --- a/hedgedoc-expire.py +++ b/hedgedoc-expire.py @@ -314,8 +314,9 @@ class HedgedocExpire: with db.prepare('DELETE FROM "Notes" WHERE "id" = $1') as delete_statement: for note in self.notes_to_be_expired(db): try: - - if len(note["content"]) > 0: + # notes that are empty or only contain whitespace are deleted without sending a backup + has_content = len((note["content"] or '').strip()) > 0 + if has_content: note_age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt']) attachments, skipped = self.upload_attachments(note["content"]) msg = MIMEMultipart() @@ -351,7 +352,10 @@ class HedgedocExpire: if self.config.verbose: url = self.config.url + '/' + (note["alias"] if note["alias"] is not None else note["shortid"]) - print(f'Note "{note["title"]}" ({url}) emailed to {msg["To"]}') + if has_content: + print(f'Note "{note["title"]}" ({url}) emailed to {self.email_from_email_or_profile(note)}') + else: + print(f'Empty note "{note["title"]}" ({url}) deleted') except Exception as e: print(f'Unable to send email to {self.email_from_email_or_profile(note)}: {e}', file=sys.stderr)