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:
parent
6a0d4365ca
commit
20c9504ea9
1 changed files with 7 additions and 3 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue