SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 933e4729 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Accept multiple bcc_to entries in mails construct

parent b8dbe20f
No related branches found
No related tags found
No related merge requests found
...@@ -137,27 +137,41 @@ class MailUtilsMixin: ...@@ -137,27 +137,41 @@ class MailUtilsMixin:
self.subject = self.mail_data['subject'] self.subject = self.mail_data['subject']
def validate_bcc_list(self): def _validate_single_entry(self, entry):
# Get recipients list. Try to send through BCC to prevent privacy issues! """
self.bcc_list = [] entry -- raw email string or path or properties leading to email mail field
if self.mail_data.get('bcc_to', False) and self.object:
if re.match("[^@]+@[^@]+\.[^@]+", self.mail_data.get('bcc_to')): Returns a list of email addresses found.
self.bcc_list = [self.mail_data.get('bcc_to')] """
if entry and self.object:
if re.match("[^@]+@[^@]+\.[^@]+", entry):
# Email string
return [entry]
else: else:
bcc_to = self.object bcc_to = self.object
for attr in self.mail_data.get('bcc_to').split('.'): for attr in entry.split('.'):
try: try:
bcc_to = getattr(bcc_to, attr) bcc_to = getattr(bcc_to, attr)
except AttributeError: except AttributeError:
# Invalid property, don't use bcc # Invalid property, don't use bcc
return return []
if not isinstance(bcc_to, list): if not isinstance(bcc_to, list):
self.bcc_list = [bcc_to] return [bcc_to]
else: else:
self.bcc_list = bcc_to return bcc_to
elif re.match("[^@]+@[^@]+\.[^@]+", self.mail_data.get('bcc_to', '')): elif re.match("[^@]+@[^@]+\.[^@]+", entry):
self.bcc_list = [self.mail_data.get('bcc_to')] return [entry]
def validate_bcc_list(self):
"""
bcc_to in the .json file may contain multiple raw email addreses or property paths to
an email field. The different entries need to be comma separated.
"""
# Get recipients list. Try to send through BCC to prevent privacy issues!
self.bcc_list = []
for bcc_entry in self.mail_data.get('bcc_to', '').split(','):
self.bcc_list += self._validate_single_entry(bcc_entry)
def validate_recipients(self): def validate_recipients(self):
# Check the send list # Check the send list
......
{ {
"subject": "SciPost: invitation", "subject": "SciPost: invitation",
"to_address": "email", "to_address": "email",
"bcc_to": "invited_by.email", "bcc_to": "invited_by.email,admin@scipost.org",
"from_address_name": "SciPost Registration", "from_address_name": "SciPost Registration",
"from_address": "registration@scipost.org", "from_address": "registration@scipost.org",
"context_object": "invitation" "context_object": "invitation"
......
{ {
"subject": "RE: SciPost: invitation", "subject": "RE: SciPost: invitation",
"to_address": "email", "to_address": "email",
"bcc_to": "invited_by.email", "bcc_to": "invited_by.email,admin@scipost.org",
"from_address_name": "SciPost Registration", "from_address_name": "SciPost Registration",
"from_address": "registration@scipost.org", "from_address": "registration@scipost.org",
"context_object": "invitation" "context_object": "invitation"
......
{ {
"subject": "SciPost: refereeing request", "subject": "SciPost: refereeing request",
"to_address": "referee.user.email", "to_address": "referee.user.email",
"bcc_to": "submission.editor_in_charge.user.email", "bcc_to": "submission.editor_in_charge.user.email,admin@scipost.org",
"from_address_name": "SciPost Refereeing", "from_address_name": "SciPost Refereeing",
"from_address": "refereeing@scipost.org", "from_address": "refereeing@scipost.org",
"context_object": "invitation" "context_object": "invitation"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment