From dfd46afae4624384da18be6c54af6f0b7d7d1a0b Mon Sep 17 00:00:00 2001
From: Stephen Frost
Date: Mon, 18 Dec 2017 15:59:18 +0100
Subject: [PATCH] Send -bugs and -docs emails from noreply address
Sending from the submitters address runs afoul to DMARC and other
restrictions. Instead, send the email from a defined noreply address.
Instead, add the original submitter to both the Cc and the Reply-To
header, to make sure they receive followups.
Patch by Stephen, minor changes by Magnus
---
pgweb/docs/views.py | 4 +++-
pgweb/mailqueue/util.py | 4 +++-
pgweb/misc/views.py | 3 ++-
pgweb/settings.py | 2 ++
pgweb/util/misc.py | 4 ++--
templates/docs/docsbug_completed.html | 1 +
templates/misc/bug_completed.html | 3 ++-
7 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/pgweb/docs/views.py b/pgweb/docs/views.py
index a2c0c914..c961e26e 100644
--- a/pgweb/docs/views.py
+++ b/pgweb/docs/views.py
@@ -133,7 +133,7 @@ def commentform(request, itemid, version, filename):
form = DocCommentForm(request.POST)
if form.is_valid():
send_template_mail(
- form.cleaned_data['email'],
+ settings.DOCSREPORT_NOREPLY_EMAIL,
settings.DOCSREPORT_EMAIL,
'%s' % form.cleaned_data['shortdesc'],
'docs/docsbugmail.txt', {
@@ -142,6 +142,8 @@ def commentform(request, itemid, version, filename):
'details': form.cleaned_data['details'],
},
usergenerated=True,
+ cc=form.cleaned_data['email'],
+ replyto='%s, %s' % (form.cleaned_data['email'], settings.DOCSREPORT_NOREPLY_EMAIL),
)
return render_to_response('docs/docsbug_completed.html', {
}, NavContext(request, 'docs'))
diff --git a/pgweb/mailqueue/util.py b/pgweb/mailqueue/util.py
index aac28be7..1c3879cb 100644
--- a/pgweb/mailqueue/util.py
+++ b/pgweb/mailqueue/util.py
@@ -7,7 +7,7 @@ from email import encoders
from models import QueuedMail
-def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, usergenerated=False, cc=None):
+def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, usergenerated=False, cc=None, replyto=None):
# attachment format, each is a tuple of (name, mimetype,contents)
# content should be *binary* and not base64 encoded, since we need to
# use the base64 routines from the email library to get a properly
@@ -18,6 +18,8 @@ def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, userge
msg['From'] = sender
if cc:
msg['Cc'] = cc
+ if replyto:
+ msg['Reply-To'] = replyto
msg['Date'] = formatdate(localtime=True)
msg['Message-ID'] = make_msgid()
diff --git a/pgweb/misc/views.py b/pgweb/misc/views.py
index 261f195a..f340e778 100644
--- a/pgweb/misc/views.py
+++ b/pgweb/misc/views.py
@@ -24,7 +24,7 @@ def submitbug(request):
bugid = c.fetchall()[0][0]
send_template_mail(
- form.cleaned_data['email'],
+ settings.BUGREPORT_NOREPLY_EMAIL,
settings.BUGREPORT_EMAIL,
'BUG #%s: %s' % (bugid, form.cleaned_data['shortdesc']),
'misc/bugmail.txt',
@@ -34,6 +34,7 @@ def submitbug(request):
},
usergenerated=True,
cc=form.cleaned_data['email'],
+ replyto='%s, %s' % (form.cleaned_data['email'], settings.BUGREPORT_EMAIL),
)
return render_to_response('misc/bug_completed.html', {
diff --git a/pgweb/settings.py b/pgweb/settings.py
index 7deba10b..2fd6a106 100644
--- a/pgweb/settings.py
+++ b/pgweb/settings.py
@@ -148,7 +148,9 @@ NOTIFICATION_FROM="someone@example.com" # Address to send notific
NOREPLY_FROM="someone@example.com" # Address to send unverified messages from
LISTSERVER_EMAIL="someone@example.com" # Address to majordomo
BUGREPORT_EMAIL="someone@example.com" # Address to pgsql-bugs list
+BUGREPORT_NOREPLY_EMAIL="someone-noreply@example.com" # Address to no-reply pgsql-bugs address
DOCSREPORT_EMAIL="someone@example.com" # Address to pgsql-docs list
+DOCSREPORT_NOREPLY_EMAIL="someone-noreply@example.com" # Address to no-reply pgsql-docs address
FRONTEND_SERVERS=() # A tuple containing the *IP addresses* of all the
# varnish frontend servers in use.
FTP_MASTERS=() # A tuple containing the *IP addresses* of all machines
diff --git a/pgweb/util/misc.py b/pgweb/util/misc.py
index 3f436c85..b9f1bf16 100644
--- a/pgweb/util/misc.py
+++ b/pgweb/util/misc.py
@@ -8,10 +8,10 @@ from pgweb.mailqueue.util import send_simple_mail
from pgweb.util.helpers import template_to_string
import re
-def send_template_mail(sender, receiver, subject, templatename, templateattr={}, usergenerated=False, cc=None):
+def send_template_mail(sender, receiver, subject, templatename, templateattr={}, usergenerated=False, cc=None, replyto=None):
send_simple_mail(sender, receiver, subject,
template_to_string(templatename, templateattr),
- usergenerated=usergenerated, cc=cc)
+ usergenerated=usergenerated, cc=cc, replyto=replyto)
def get_client_ip(request):
"""
diff --git a/templates/docs/docsbug_completed.html b/templates/docs/docsbug_completed.html
index b1a910fd..f967600c 100644
--- a/templates/docs/docsbug_completed.html
+++ b/templates/docs/docsbug_completed.html
@@ -6,5 +6,6 @@
Your documentation comment has been received, and been posted to
the pgsql-docs mailinglist. It will
show up there as soon as it has cleared the moderator queue.
+A copy of the comment has also been sent to your mailbox.
{%endblock%}
diff --git a/templates/misc/bug_completed.html b/templates/misc/bug_completed.html
index 2f9f86bd..b36c58d5 100644
--- a/templates/misc/bug_completed.html
+++ b/templates/misc/bug_completed.html
@@ -6,6 +6,7 @@
Your bug report has been received, and given id #{{bugid}}. It has been posted
to the pgsql-bugs
mailinglist and will show up there as soon as it has cleared the moderator
-queue.
+queue. A copy of the report has also been sent to your mailbox. If you need
+to add any further information to the report, please reply to that mail.
{%endblock%}