Skip to content

Commit

Permalink
Revert Sparkpost changes, back to "email_rfc822" (#13780)
Browse files Browse the repository at this point in the history
  • Loading branch information
billmn authored and taylorotwell committed May 30, 2016
1 parent 5f27a73 commit 52d7c2a
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions src/Illuminate/Mail/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Mail\Transport;

use Swift_Encoding;
use Swift_Mime_Message;
use GuzzleHttp\ClientInterface;

Expand Down Expand Up @@ -53,24 +52,11 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
'json' => [
'recipients' => $recipients,
'content' => [
'html' => $message->getBody(),
'from' => $this->getFrom($message),
'reply_to' => $this->getReplyTo($message),
'subject' => $message->getSubject(),
'email_rfc822' => $message->toString(),
],
],
];

if ($attachments = $message->getChildren()) {
$options['json']['content']['attachments'] = array_map(function ($attachment) {
return [
'type' => $attachment->getContentType(),
'name' => $attachment->getFileName(),
'data' => Swift_Encoding::getBase64Encoding()->encodeString($attachment->getBody()),
];
}, $attachments);
}

return $this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);
}

Expand Down Expand Up @@ -99,38 +85,12 @@ protected function getRecipients(Swift_Mime_Message $message)
}

$recipients = array_map(function ($address) {
return ['address' => ['email' => $address, 'header_to' => $address]];
return compact('address');
}, $to);

return $recipients;
}

/**
* Get the "from" contacts in the format required by SparkPost.
*
* @param Swift_Mime_Message $message
* @return array
*/
protected function getFrom(Swift_Mime_Message $message)
{
return array_map(function ($email, $name) {
return compact('name', 'email');
}, array_keys($message->getFrom()), $message->getFrom())[0];
}

/**
* Get the 'reply_to' headers and format as required by SparkPost.
*
* @param Swift_Mime_Message $message
* @return string
*/
protected function getReplyTo(Swift_Mime_Message $message)
{
if (is_array($message->getReplyTo())) {
return current($message->getReplyTo()).' <'.key($message->getReplyTo()).'>';
}
}

/**
* Get the API key being used by the transport.
*
Expand Down

0 comments on commit 52d7c2a

Please sign in to comment.