Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Email notification workflow now ignores recipients with invalid email addresses #370

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions src/Actions/NotifyUsersWorkflowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use SilverStripe\Security\Security;
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
use Swift_RfcComplianceException;
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction;
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;

Expand Down Expand Up @@ -96,7 +97,7 @@ public function execute(WorkflowInstance $workflow)
$memberFields = $this->getMemberFields($member);
$initiatorFields = $this->getMemberFields($initiator);

$variables = array();
$variables = [];

foreach ($contextFields as $field => $val) {
$variables["\$Context.$field"] = $val;
Expand All @@ -109,28 +110,28 @@ public function execute(WorkflowInstance $workflow)
}

$pastActions = $workflow->Actions()->sort('Created DESC');
$variables["\$CommentHistory"] = $this->customise(array(
'PastActions'=>$pastActions,
'Now'=>DBDatetime::now()
))->renderWith('Includes/CommentHistory');
$variables["\$CommentHistory"] = $this->customise([
'PastActions' => $pastActions,
'Now' => DBDatetime::now()
])->renderWith('Includes/CommentHistory');

$from = str_replace(array_keys($variables), array_values($variables), $this->EmailFrom);
$subject = str_replace(array_keys($variables), array_values($variables), $this->EmailSubject);

if ($this->config()->whitelist_template_variables) {
$item = new ArrayData(array(
'Initiator' => new ArrayData($initiatorFields),
'Member' => new ArrayData($memberFields),
'Context' => new ArrayData($contextFields),
if ($this->config()->get('whitelist_template_variables')) {
$item = ArrayData::create([
'Initiator' => ArrayData::create($initiatorFields),
'Member' => ArrayData::create($memberFields),
'Context' => ArrayData::create($contextFields),
'CommentHistory' => $variables["\$CommentHistory"]
));
]);
} else {
$item = $workflow->customise(array(
$item = $workflow->customise([
'Items' => $workflow->Actions(),
'Member' => $member,
'Context' => new ArrayData($contextFields),
'Context' => ArrayData::create($contextFields),
'CommentHistory' => $variables["\$CommentHistory"]
));
]);
}


Expand All @@ -141,8 +142,14 @@ public function execute(WorkflowInstance $workflow)

foreach ($members as $member) {
if ($member->Email) {
$email = new Email;
$email->setTo($member->Email);
$email = Email::create();
try {
$email->setTo($member->Email);
} catch (Swift_RfcComplianceException $exception) {
// If the email address isn't valid we should skip it rather than break
// the rest of the processing
continue;
}
$email->setSubject($subject);
$email->setFrom($from);
$email->setBody($body);
Expand Down