Skip to content

Commit 505c392

Browse files
committed
Fix error when no cc or bcc are set
1 parent 6a8720b commit 505c392

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/Openbuildings/Swiftmailer/FilterPlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ public function beforeSendPerformed(\Swift_Events_SendEvent $evt)
143143
{
144144
$message = $evt->getMessage();
145145

146-
$message->setTo(FilterPlugin::filterEmailArray($this->getWhitelist(), $this->getBlacklist(), $message->getTo()));
146+
$message->setTo(FilterPlugin::filterEmailArray($this->getWhitelist(), $this->getBlacklist(), (array) $message->getTo()));
147147

148-
$message->setCc(FilterPlugin::filterEmailArray($this->getWhitelist(), $this->getBlacklist(), $message->getCc()));
148+
$message->setCc(FilterPlugin::filterEmailArray($this->getWhitelist(), $this->getBlacklist(), (array) $message->getCc()));
149149

150-
$message->setBcc(FilterPlugin::filterEmailArray($this->getWhitelist(), $this->getBlacklist(), $message->getBcc()));
150+
$message->setBcc(FilterPlugin::filterEmailArray($this->getWhitelist(), $this->getBlacklist(), (array) $message->getBcc()));
151151
}
152152

153153
/**

tests/tests/FilterPluginTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,47 @@ public function test_integration()
2929
$this->assertEquals(array(), $message->getBcc());
3030
}
3131

32+
public function test_integration_with_empty_cc()
33+
{
34+
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance());
35+
36+
$mailer->registerPLugin(new FilterPlugin('example.com', '[email protected]'));
37+
38+
$message = Swift_Message::newInstance();
39+
40+
$message->setFrom('[email protected]');
41+
$message->setTo('[email protected]');
42+
$message->setBcc(array('[email protected]', '[email protected]', '[email protected]'));
43+
$message->setSubject('Test');
44+
$message->setBody('Test Email');
45+
46+
$mailer->send($message);
47+
48+
$this->assertEquals(array('[email protected]' => ''), $message->getTo());
49+
$this->assertEquals(array(), $message->getCc());
50+
$this->assertEquals(array('[email protected]' => ''), $message->getBcc());
51+
}
52+
53+
public function test_integration_with_empty_cc_and_bcc()
54+
{
55+
$mailer = Swift_Mailer::newInstance(Swift_NullTransport::newInstance());
56+
57+
$mailer->registerPLugin(new FilterPlugin('example.com', '[email protected]'));
58+
59+
$message = Swift_Message::newInstance();
60+
61+
$message->setFrom('[email protected]');
62+
$message->setTo('[email protected]');
63+
$message->setSubject('Test');
64+
$message->setBody('Test Email');
65+
66+
$mailer->send($message);
67+
68+
$this->assertEquals(array('[email protected]' => ''), $message->getTo());
69+
$this->assertEquals(array(), $message->getCc());
70+
$this->assertEquals(array(), $message->getBcc());
71+
}
72+
3273
public function data_emailMatches()
3374
{
3475
return array(

0 commit comments

Comments
 (0)