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.
This commit is contained in:
Stefan Bethke 2026-10-27 12:59:13 +01:00
commit 20c9504ea9

View file

@ -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)