2024-01-31 01:28:45 +00:00
|
|
|
from django.conf import settings
|
2024-01-26 04:52:38 +00:00
|
|
|
from django.core.mail import EmailMessage
|
2024-01-26 06:49:03 +00:00
|
|
|
from django.shortcuts import reverse
|
|
|
|
|
2024-01-31 01:28:45 +00:00
|
|
|
SENDER = settings.USETHESOURCE['SENDER']
|
|
|
|
LIST_RECIPIENT = settings.USETHESOURCE['LIST_RECIPIENT']
|
2024-01-26 06:49:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def make_candidate_email(candidate, user):
|
|
|
|
"""The initial email announcing the new candidate."""
|
|
|
|
subject = candidate.name
|
|
|
|
signature = user.get_full_name() or user.username
|
|
|
|
sender = f'{signature} <{SENDER}>'
|
|
|
|
to = [LIST_RECIPIENT]
|
|
|
|
body = f'''\
|
|
|
|
We've just published the following new candidate:
|
|
|
|
|
|
|
|
{candidate.name}
|
|
|
|
Vendor: {candidate.vendor}
|
|
|
|
Device: {candidate.device}
|
|
|
|
Released: {candidate.release_date}
|
|
|
|
|
|
|
|
{candidate.description}
|
|
|
|
|
2024-01-31 23:10:05 +00:00
|
|
|
To view this candidate and download the source candidate and firmware image, visit:
|
2024-01-26 06:49:03 +00:00
|
|
|
https://sfconservancy.org{reverse('usethesource:candidate', kwargs={'slug': candidate.slug})}
|
|
|
|
|
|
|
|
--
|
|
|
|
{signature}
|
2024-01-31 01:33:47 +00:00
|
|
|
(Via https://sfconservancy.org{reverse('usethesource:landing')})'''
|
2024-01-26 06:49:03 +00:00
|
|
|
headers = {'Message-ID': candidate.email_message_id}
|
|
|
|
return EmailMessage(subject, body, sender, to, headers=headers)
|
2024-01-26 04:52:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def make_comment_email(comment):
|
2024-01-26 06:49:03 +00:00
|
|
|
"""Email when a comment is added to a candidate."""
|
2024-01-31 01:28:45 +00:00
|
|
|
candidate = comment.candidate
|
|
|
|
subject = f'Re: {candidate.name}'
|
2024-01-26 04:52:38 +00:00
|
|
|
signature = comment.user.get_full_name() or comment.user.username
|
2024-01-26 06:49:03 +00:00
|
|
|
sender = f'{signature} <{SENDER}>'
|
|
|
|
to = [LIST_RECIPIENT]
|
2024-01-31 01:28:45 +00:00
|
|
|
body = f'''\
|
|
|
|
{comment.message}
|
|
|
|
|
2024-01-31 23:10:05 +00:00
|
|
|
To view this candidate and download the source candidate and firmware image, visit:
|
2024-01-31 01:28:45 +00:00
|
|
|
https://sfconservancy.org{reverse('usethesource:candidate', kwargs={'slug': candidate.slug})}
|
|
|
|
|
|
|
|
--
|
|
|
|
{signature}
|
2024-01-31 01:33:47 +00:00
|
|
|
(Via https://sfconservancy.org{reverse('usethesource:landing')})'''
|
2024-01-26 04:52:38 +00:00
|
|
|
headers = {'Message-ID': comment.email_message_id}
|
|
|
|
if in_reply_to := comment.in_reply_to():
|
|
|
|
# From my testing, both "In-Reply-To" and "References" headers trigger
|
|
|
|
# email threading in Thunderbind. Sticking to "In-Reply-To" for now.
|
|
|
|
headers['In-Reply-To'] = in_reply_to
|
|
|
|
return EmailMessage(subject, body, sender, to, headers=headers)
|