Commit 2b2ded40 authored by Martin Mareš's avatar Martin Mareš
Browse files

Mail notifications have a Reply-To to course teachers

Closes #38.
parent a7b870a0
......@@ -1682,14 +1682,24 @@ def send_notify_post(post):
""", (topic.cid, post.target_uid, post.target_uid, topic.tid))
dests = db.fetchall()
db_query("""
SELECT u.email, u.first_name, u.last_name
FROM owl_enroll e
JOIN owl_users u ON u.uid = e.uid
WHERE e.cid=%s
AND e.is_teacher
AND u.email IS NOT NULL
""", (topic.cid,))
reply_to = db.fetchall()
for dest in dests:
if dest.uid != author.uid or dest.notify_self:
send_notify_to_dest(post, topic, course, author, target, dest)
send_notify_to_dest(post, topic, course, author, target, dest, reply_to)
else:
app.logger.info(f"E-mail: not sending self-notify to uid={dest.uid}")
def send_notify_to_dest(post, topic, course, author, target, dest):
def send_notify_to_dest(post, topic, course, author, target, dest, reply_to):
if 'MAIL_FROM' not in app.config:
app.logger.info('Not sending: MAIL_FROM not defined')
return
......@@ -1709,6 +1719,9 @@ def send_notify_to_dest(post, topic, course, author, target, dest):
# Everybody gets his own view of the thread, so the target is the observer's uid
msg['References'] = '<' + app.config['MAIL_REFERENCES'].format(tid=post.tid, target=dest.uid) + '>'
if reply_to:
msg['Reply-To'] = [email.headerregistry.Address(display_name=full_name(r), addr_spec=r.email) for r in reply_to]
if dest.is_teacher and target:
target_uid = target.uid
title = f"{topic.title} / {full_name(target)}"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment