Browse Source

Add "List-Unsubscribe" header to alert and report emails

pull/199/head
Pēteris Caune 6 years ago
parent
commit
b9a81ad382
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
7 changed files with 20 additions and 19 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +5
    -2
      hc/accounts/models.py
  3. +1
    -0
      hc/api/tests/test_notify.py
  4. +4
    -1
      hc/api/tests/test_sendreports.py
  5. +7
    -2
      hc/api/transports.py
  6. +2
    -2
      hc/lib/emails.py
  7. +0
    -12
      templates/emails/alert-body-html.html

+ 1
- 0
CHANGELOG.md View File

@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
### Improvements
- Load settings from environment variables
- Add "List-Unsubscribe" header to alert and report emails
## 1.2.0 - 2018-10-20


+ 5
- 2
hc/accounts/models.py View File

@ -150,18 +150,21 @@ class Profile(models.Model):
# rendering the template
checks = list(checks)
unsub_url = self.reports_unsub_url()
headers = {"List-Unsubscribe": unsub_url}
ctx = {
"checks": checks,
"sort": self.sort,
"now": timezone.now(),
"unsub_link": self.reports_unsub_url(),
"unsub_link": unsub_url,
"notifications_url": self.notifications_url(),
"nag": nag,
"nag_period": self.nag_period.total_seconds(),
"num_down": num_down
}
emails.report(self.user.email, ctx)
emails.report(self.user.email, ctx, headers)
return True
def can_invite(self):


+ 1
- 0
hc/api/tests/test_notify.py View File

@ -246,6 +246,7 @@ class NotifyTestCase(BaseTestCase):
email = mail.outbox[0]
self.assertTrue("X-Bounce-Url" in email.extra_headers)
self.assertTrue("List-Unsubscribe" in email.extra_headers)
def test_it_skips_unverified_email(self):
self._setup_data("email", "[email protected]", email_verified=False)


+ 4
- 1
hc/api/tests/test_sendreports.py View File

@ -30,7 +30,7 @@ class SendAlertsTestCase(BaseTestCase):
def test_it_sends_report(self):
cmd = Command()
cmd.stdout = Mock() # silence output to stdout
cmd.stdout = Mock() # silence output to stdout
cmd.pause = Mock() # don't pause for 1s
found = cmd.handle_one_monthly_report()
@ -40,6 +40,9 @@ class SendAlertsTestCase(BaseTestCase):
self.assertTrue(self.profile.next_report_date > now())
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
self.assertTrue("List-Unsubscribe" in email.extra_headers)
def test_it_obeys_next_report_date(self):
self.profile.next_report_date = now() + td(days=1)
self.profile.save()


+ 7
- 2
hc/api/transports.py View File

@ -50,7 +50,12 @@ class Email(Transport):
if not self.channel.email_verified:
return "Email not verified"
headers = {"X-Bounce-Url": bounce_url}
unsub_link = self.channel.get_unsub_link()
headers = {
"X-Bounce-Url": bounce_url,
"List-Unsubscribe": unsub_link
}
try:
# Look up the sorting preference for this email address
@ -67,7 +72,7 @@ class Email(Transport):
"checks": list(self.checks()),
"sort": sort,
"now": timezone.now(),
"unsub_link": self.channel.get_unsub_link()
"unsub_link": unsub_link
}
emails.alert(self.channel.value, ctx, headers)


+ 2
- 2
hc/lib/emails.py View File

@ -56,8 +56,8 @@ def verify_email(to, ctx):
send("verify-email", to, ctx)
def report(to, ctx):
send("report", to, ctx)
def report(to, ctx, headers={}):
send("report", to, ctx, headers)
def invoice(to, ctx, filename, pdf_data):


+ 0
- 12
templates/emails/alert-body-html.html View File

@ -18,18 +18,6 @@ Here is a summary of your checks:
Thanks,<br>
The {% escaped_site_name %} Team
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"url": "{{ check.details_url }}",
"name": "View in {% site_name%}"
},
"description": "View in {% site_name%}"
}
</script>
{% endblock %}
{% block unsub %}


Loading…
Cancel
Save