Skip to content

Commit

Permalink
Send messages to emails signed as "use_as_bcc" indipendently from "se…
Browse files Browse the repository at this point in the history
…nd" flag.
  • Loading branch information
folix-01 committed Aug 30, 2024
1 parent 32552da commit 68ac175
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
3.1.3 (unreleased)
------------------

- Send messages to emails signed as 'use_as_bcc' indipendently from 'send' flag.
[folix-01]

- Update Italian translations.
[cekk]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def reply(self):

notify(PostEventService(self.context, self.form_data))

if send_action:
if send_action or self.get_bcc():
try:
self.send_data()
except BadRequest as e:
Expand Down Expand Up @@ -366,9 +366,10 @@ def send_data(self):
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix="plone")
charset = registry.get("plone.email_charset", "utf-8")

should_send = self.block.get("send", [])
if should_send:
bcc = self.get_bcc()

if should_send or bcc:
portal_transforms = api.portal.get_tool(name="portal_transforms")
mto = self.block.get("default_to", mail_settings.email_from_address)
message = self.prepare_message()
Expand All @@ -393,11 +394,11 @@ def send_data(self):

self.manage_attachments(msg=msg)

if isinstance(should_send, list):
if should_send and isinstance(should_send, list):
if "recipient" in self.block.get("send", []):
self.send_mail(msg=msg, charset=charset)
# Backwards compatibility for forms before 'acknowledgement' sending
else:
elif should_send:
self.send_mail(msg=msg, charset=charset)

# send a copy also to the fields with bcc flag
Expand Down
17 changes: 8 additions & 9 deletions src/collective/volto/formsupport/tests/test_send_action_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ def test_email_field_used_as_bcc(
"@type": "form",
"default_subject": "block subject",
"default_from": "[email protected]",
"send": ["recipient"],
"send": False,
"store": True,
"subblocks": [
{
"field_id": "contact",
Expand Down Expand Up @@ -683,15 +684,13 @@ def test_email_field_used_as_bcc(
transaction.commit()

self.assertEqual(response.status_code, 200)
self.assertEqual(len(self.mailhost.messages), 2)
msg = self.mailhost.messages[0]
bcc_msg = self.mailhost.messages[1]
if isinstance(msg, bytes) and bytes is not str:
# Python 3 with Products.MailHost 4.10+
msg = msg.decode("utf-8")
self.assertEqual(len(self.mailhost.messages), 1)

bcc_msg = self.mailhost.messages[0]

if isinstance(bcc_msg, bytes) and bytes is not str:
bcc_msg = bcc_msg.decode("utf-8")
self.assertIn("To: [email protected]", msg)
self.assertNotIn("To: [email protected]", msg)

self.assertNotIn("To: [email protected]", bcc_msg)
self.assertIn("To: [email protected]", bcc_msg)

Expand Down

0 comments on commit 68ac175

Please sign in to comment.