Skip to content

Commit

Permalink
allow , and " in emails
Browse files Browse the repository at this point in the history
  • Loading branch information
ivank committed Feb 10, 2014
1 parent 8f38454 commit 0608a1d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions src/Openbuildings/Postmark/Swift/Transport/PostmarkTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license http://spdx.org/licenses/BSD-3-Clause
*/
class Swift_Transport_PostmarkTransport implements \Swift_Transport {

protected $_api;
protected $_eventDispatcher;

Expand All @@ -29,18 +29,18 @@ public function api(Api $api = NULL)
}
return $this->_api;
}
public function isStarted()

public function isStarted()
{
return FALSE;
return FALSE;
}

public function start()
public function start()
{
return FALSE;
}

public function stop()
public function stop()
{
return FALSE;
}
Expand All @@ -49,23 +49,23 @@ public function convert_email_array(array $emails)
{
$converted = array();

foreach ($emails as $email => $name)
foreach ($emails as $email => $name)
{
$converted []= $name ? "{$name} <{$email}>" : $email;
$converted []= $name ? '"'.str_replace('"', '\\"', $name)." <{$email}>\"" : $email;
}

return $converted;
}

/**
* @param Swift_Mime_Message $message
* @param string $mime_type
* @return Swift_Mime_MimePart
*/
protected function getMIMEPart(\Swift_Mime_Message $message, $mime_type)
protected function getMIMEPart(\Swift_Mime_Message $message, $mime_type)
{
$part_content = NULL;
foreach ($message->getChildren() as $part)
foreach ($message->getChildren() as $part)
{
if (strpos($part->getContentType(), $mime_type) === 0)
{
Expand All @@ -80,22 +80,22 @@ protected function getMIMEPart(\Swift_Mime_Message $message, $mime_type)
* @param array $failed_recipients
* @return int
*/
public function send(\Swift_Mime_Message $message, & $failed_recipients = NULL)
public function send(\Swift_Mime_Message $message, & $failed_recipients = NULL)
{
if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
$this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
if ($evt->bubbleCancelled()) {
return 0;
}
}

$data = array(
'From' => join(',', self::convert_email_array($message->getFrom())),
'To' => join(',', self::convert_email_array($message->getTo())),
'Subject' => $message->getSubject(),
);

if ($cc = $message->getCc())
if ($cc = $message->getCc())
{
$data['Cc'] = join(',', self::convert_email_array($cc));
}
Expand All @@ -110,11 +110,11 @@ public function send(\Swift_Mime_Message $message, & $failed_recipients = NULL)
$data['Bcc'] = join(',', self::convert_email_array($bcc));
}

switch ($message->getContentType())
switch ($message->getContentType())
{
case 'text/html':
$data['HtmlBody'] = $message->getBody();
break;
break;
default:
$data['TextBody'] = $message->getBody();
break;
Expand All @@ -134,7 +134,7 @@ public function send(\Swift_Mime_Message $message, & $failed_recipients = NULL)
{
$data['Attachments'] = array();

foreach ($message->getChildren() as $attachment)
foreach ($message->getChildren() as $attachment)
{
if (is_object($attachment) AND $attachment instanceof \Swift_Mime_Attachment)
{
Expand All @@ -156,9 +156,9 @@ public function send(\Swift_Mime_Message $message, & $failed_recipients = NULL)

return 1;
}
public function registerPlugin(\Swift_Events_EventListener $plugin)

public function registerPlugin(\Swift_Events_EventListener $plugin)
{
$this->_eventDispatcher->bindEventListener($plugin);
}
}
}
16 changes: 8 additions & 8 deletions tests/tests/Swift/PostmarkTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function test_send()
{
$transport = Swift_PostmarkTransport::newInstance('POSTMARK_API_TEST');
$this->assertInstanceOf('Openbuildings\Postmark\Api', $transport->api());

$api = $this->getMock('Openbuildings\Postmark\Api', array(), array('POSTMARK_API_TEST'));
$transport->api($api);
$mailer = Swift_Mailer::newInstance($transport);
Expand All @@ -37,11 +37,11 @@ public function test_send()
$api->expects($this->at(2))
->method('send')
->with($this->equalTo(array(
'From' => 'John Smith <[email protected]>',
'To' => 'Paul Smith <[email protected]>',
'Cc' => 'Jane Smith <[email protected]>,[email protected]',
'Bcc' => 'Gale Smith <[email protected]>,Mark Smith <[email protected]>',
'ReplyTo' => 'Tom Smith <[email protected]>',
'From' => '"John Smith <[email protected]>"',
'To' => '"Paul Smith <[email protected]>"',
'Cc' => '"Jane \"Panny\" Smith <[email protected]>",[email protected]',
'Bcc' => '"Gale Smith <[email protected]>","Mark Smith <[email protected]>"',
'ReplyTo' => '"Tom Smith <[email protected]>"',
'Subject' => 'Test Big',
'TextBody' => 'Text Part',
'HtmlBody' => 'HTML Part',
Expand Down Expand Up @@ -94,7 +94,7 @@ public function test_send()
$message->setTo('[email protected]', 'Paul Smith');
$message->setReplyTo('[email protected]', 'Tom Smith');
$message->setSubject('Test Big');
$message->setCc(array('[email protected]' => 'Jane Smith', '[email protected]'));
$message->setCc(array('[email protected]' => 'Jane "Panny" Smith', '[email protected]'));
$message->setBcc(array('[email protected]' => 'Gale Smith', '[email protected]' => 'Mark Smith'));
$message->addPart('HTML Part', 'text/html');
$message->addPart('Text Part', 'text/plain');
Expand All @@ -113,7 +113,7 @@ public function test_send()
$mailer->send($message);

$transport->stop();

$transport->registerPlugin($this->getMock('Swift_Events_EventListener'));
}
}

0 comments on commit 0608a1d

Please sign in to comment.