forked from CCCHH/hedgedoc-expire
only send email when a note actually has content
This commit is contained in:
parent
4abb4d7516
commit
2da0096453
1 changed files with 21 additions and 19 deletions
|
|
@ -215,28 +215,30 @@ class HedgedocExpire:
|
||||||
with db.prepare('DELETE FROM "Notes" WHERE "id" = $1') as delete_statement:
|
with db.prepare('DELETE FROM "Notes" WHERE "id" = $1') as delete_statement:
|
||||||
for note in self.notes_to_be_expired(db):
|
for note in self.notes_to_be_expired(db):
|
||||||
try:
|
try:
|
||||||
note_age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt'])
|
|
||||||
msg = MIMEMultipart()
|
if len(note["content"]) > 0:
|
||||||
msg['From'] = self.email_sender.mail_from
|
note_age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt'])
|
||||||
msg['To'] = self.email_from_email_or_profile(note)
|
msg = MIMEMultipart()
|
||||||
msg['Subject'] = f'Your HedgeDoc Note "{note["title"]}" has expired'
|
msg['From'] = self.email_sender.mail_from
|
||||||
msg.attach(MIMEText(dedent(f'''\
|
msg['To'] = self.email_from_email_or_profile(note)
|
||||||
You created the note titled "{note["title"]}" on {note["createdAt"]}.
|
msg['Subject'] = f'Your HedgeDoc Note "{note["title"]}" has expired'
|
||||||
It was lasted updated {note['updatedAt']}, {humanize.naturaldelta(note_age)} ago. We expire all notes
|
msg.attach(MIMEText(dedent(f'''\
|
||||||
that have not been updated within {humanize.naturaldelta(self.config.note_age)}.
|
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'))
|
'''), 'plain', 'utf-8'))
|
||||||
md = MIMEText(note["content"], 'markdown', 'utf-8')
|
md = MIMEText(note["content"], 'markdown', 'utf-8')
|
||||||
filename = note['title'].encode('ascii', 'ignore').decode('utf-8')
|
filename = note['title'].encode('ascii', 'ignore').decode('utf-8')
|
||||||
if len(filename) == 0:
|
if len(filename) == 0:
|
||||||
filename = 'note'
|
filename = 'note'
|
||||||
md.add_header('Content-Disposition', f'attachment; filename={filename}.md')
|
md.add_header('Content-Disposition', f'attachment; filename={filename}.md')
|
||||||
msg.attach(md)
|
msg.attach(md)
|
||||||
self.email_sender.send(msg)
|
self.email_sender.send(msg)
|
||||||
|
|
||||||
# email backup of the note sent, now we can delete it
|
# email backup of the note sent, now we can delete it
|
||||||
delete_statement(note["id"])
|
delete_statement(note["id"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue