35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import html.parser
|
|
import os
|
|
import textwrap
|
|
from string import Template
|
|
from srht.config import cfg, cfgi
|
|
from srht.email import send_email, lookup_key
|
|
from srht.oauth import current_user
|
|
from todosrht.types import ParticipantType
|
|
|
|
origin = cfg("todo.sr.ht", "origin")
|
|
|
|
def format_lines(text, quote=False):
|
|
wrapped = textwrap.wrap(text, width=72,
|
|
replace_whitespace=False, expand_tabs=False, drop_whitespace=False)
|
|
return "\n".join(wrapped)
|
|
|
|
def notify(sub, template, subject, headers, **kwargs):
|
|
encrypt_key = None
|
|
to = sub.participant
|
|
if to.participant_type == ParticipantType.email:
|
|
to = to.email
|
|
elif to.participant_type == ParticipantType.user:
|
|
user = to.user
|
|
to = user.email
|
|
encrypt_key = lookup_key(user)
|
|
else:
|
|
return
|
|
with open(os.path.join(os.path.dirname(__file__), "emails", template)) as f:
|
|
tmpl = Template(f.read())
|
|
body = tmpl.substitute(**{
|
|
'root': origin,
|
|
**kwargs,
|
|
})
|
|
send_email(body, to, subject, encrypt_key=encrypt_key, **headers)
|