only send email when a note actually has content
Some checks failed
docker-image / docker (push) Has been cancelled

This commit is contained in:
lilly 2026-02-09 14:33:22 +01:00
commit 2da0096453
Signed by: lilly
SSH key fingerprint: SHA256:y9T5GFw2A20WVklhetIxG1+kcg/Ce0shnQmbu1LQ37g

View file

@ -215,28 +215,30 @@ class HedgedocExpire:
with db.prepare('DELETE FROM "Notes" WHERE "id" = $1') as delete_statement:
for note in self.notes_to_be_expired(db):
try:
note_age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt'])
msg = MIMEMultipart()
msg['From'] = self.email_sender.mail_from
msg['To'] = self.email_from_email_or_profile(note)
msg['Subject'] = f'Your HedgeDoc Note "{note["title"]}" has expired'
msg.attach(MIMEText(dedent(f'''\
You created the note titled "{note["title"]}" on {note["createdAt"]}.
It was lasted updated {note['updatedAt']}, {humanize.naturaldelta(note_age)} ago. We expire all notes
that have not been updated within {humanize.naturaldelta(self.config.note_age)}.
if len(note["content"]) > 0:
note_age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt'])
msg = MIMEMultipart()
msg['From'] = self.email_sender.mail_from
msg['To'] = self.email_from_email_or_profile(note)
msg['Subject'] = f'Your HedgeDoc Note "{note["title"]}" has expired'
msg.attach(MIMEText(dedent(f'''\
You created the note titled "{note["title"]}" on {note["createdAt"]}.
It was lasted updated {note['updatedAt']}, {humanize.naturaldelta(note_age)} ago. We expire all notes
that have not been updated within {humanize.naturaldelta(self.config.note_age)}.
Please find attached the contents of the latest revision of your note.
Please find attached the contents of the latest revision of your note.
The admin team for {self.config.url}
The admin team for {self.config.url}
'''), 'plain', 'utf-8'))
md = MIMEText(note["content"], 'markdown', 'utf-8')
filename = note['title'].encode('ascii', 'ignore').decode('utf-8')
if len(filename) == 0:
filename = 'note'
md.add_header('Content-Disposition', f'attachment; filename={filename}.md')
msg.attach(md)
self.email_sender.send(msg)
'''), 'plain', 'utf-8'))
md = MIMEText(note["content"], 'markdown', 'utf-8')
filename = note['title'].encode('ascii', 'ignore').decode('utf-8')
if len(filename) == 0:
filename = 'note'
md.add_header('Content-Disposition', f'attachment; filename={filename}.md')
msg.attach(md)
self.email_sender.send(msg)
# email backup of the note sent, now we can delete it
delete_statement(note["id"])