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

[5.2] Revert Sparkpost changes #13780

Merged
merged 1 commit into from
May 30, 2016
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
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