Revert "My first commit of codes"

This reverts commit a6e5a69348.
This commit is contained in:
sujitprasad
2015-05-01 13:27:00 +05:30
parent 6f37d10de3
commit 16ea6e1984
8487 changed files with 0 additions and 1317246 deletions

View File

@@ -1,119 +0,0 @@
<?php namespace Illuminate\Mail;
use Swift_Mailer;
use Illuminate\Support\ServiceProvider;
class MailServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('mailer', function($app)
{
$this->registerSwiftMailer();
// Once we have create the mailer instance, we will set a container instance
// on the mailer. This allows us to resolve mailer classes via containers
// for maximum testability on said classes instead of passing Closures.
$mailer = new Mailer(
$app['view'], $app['swift.mailer'], $app['events']
);
$this->setMailerDependencies($mailer, $app);
// If a "from" address is set, we will set it on the mailer so that all mail
// messages sent by the applications will utilize the same "from" address
// on each one, which makes the developer's life a lot more convenient.
$from = $app['config']['mail.from'];
if (is_array($from) && isset($from['address']))
{
$mailer->alwaysFrom($from['address'], $from['name']);
}
// Here we will determine if the mailer should be in "pretend" mode for this
// environment, which will simply write out e-mail to the logs instead of
// sending it over the web, which is useful for local dev environments.
$pretend = $app['config']->get('mail.pretend', false);
$mailer->pretend($pretend);
return $mailer;
});
}
/**
* Set a few dependencies on the mailer instance.
*
* @param \Illuminate\Mail\Mailer $mailer
* @param \Illuminate\Foundation\Application $app
* @return void
*/
protected function setMailerDependencies($mailer, $app)
{
$mailer->setContainer($app);
if ($app->bound('Psr\Log\LoggerInterface'))
{
$mailer->setLogger($app->make('Psr\Log\LoggerInterface'));
}
if ($app->bound('queue'))
{
$mailer->setQueue($app['queue.connection']);
}
}
/**
* Register the Swift Mailer instance.
*
* @return void
*/
public function registerSwiftMailer()
{
$this->registerSwiftTransport();
// Once we have the transporter registered, we will register the actual Swift
// mailer instance, passing in the transport instances, which allows us to
// override this transporter instances during app start-up if necessary.
$this->app['swift.mailer'] = $this->app->share(function($app)
{
return new Swift_Mailer($app['swift.transport']->driver());
});
}
/**
* Register the Swift Transport instance.
*
* @return void
*/
protected function registerSwiftTransport()
{
$this->app['swift.transport'] = $this->app->share(function($app)
{
return new TransportManager($app);
});
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return ['mailer', 'swift.mailer', 'swift.transport'];
}
}

View File

@@ -1,527 +0,0 @@
<?php namespace Illuminate\Mail;
use Closure;
use Swift_Mailer;
use Swift_Message;
use SuperClosure\Serializer;
use Psr\Log\LoggerInterface;
use InvalidArgumentException;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Queue\Queue as QueueContract;
use Illuminate\Contracts\Mail\Mailer as MailerContract;
use Illuminate\Contracts\Mail\MailQueue as MailQueueContract;
class Mailer implements MailerContract, MailQueueContract {
/**
* The view factory instance.
*
* @var \Illuminate\Contracts\View\Factory
*/
protected $views;
/**
* The Swift Mailer instance.
*
* @var \Swift_Mailer
*/
protected $swift;
/**
* The event dispatcher instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* The global from address and name.
*
* @var array
*/
protected $from;
/**
* The log writer instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The IoC container instance.
*
* @var \Illuminate\Contracts\Container\Container
*/
protected $container;
/**
* The queue implementation.
*
* @var \Illuminate\Contracts\Queue\Queue
*/
protected $queue;
/**
* Indicates if the actual sending is disabled.
*
* @var bool
*/
protected $pretending = false;
/**
* Array of failed recipients.
*
* @var array
*/
protected $failedRecipients = array();
/**
* Array of parsed views containing html and text view name.
*
* @var array
*/
protected $parsedViews = array();
/**
* Create a new Mailer instance.
*
* @param \Illuminate\Contracts\View\Factory $views
* @param \Swift_Mailer $swift
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function __construct(Factory $views, Swift_Mailer $swift, Dispatcher $events = null)
{
$this->views = $views;
$this->swift = $swift;
$this->events = $events;
}
/**
* Set the global from address and name.
*
* @param string $address
* @param string $name
* @return void
*/
public function alwaysFrom($address, $name = null)
{
$this->from = compact('address', 'name');
}
/**
* Send a new message when only a raw text part.
*
* @param string $text
* @param mixed $callback
* @return int
*/
public function raw($text, $callback)
{
return $this->send(array('raw' => $text), [], $callback);
}
/**
* Send a new message when only a plain part.
*
* @param string $view
* @param array $data
* @param mixed $callback
* @return int
*/
public function plain($view, array $data, $callback)
{
return $this->send(array('text' => $view), $data, $callback);
}
/**
* Send a new message using a view.
*
* @param string|array $view
* @param array $data
* @param \Closure|string $callback
* @return mixed
*/
public function send($view, array $data, $callback)
{
// First we need to parse the view, which could either be a string or an array
// containing both an HTML and plain text versions of the view which should
// be used when sending an e-mail. We will extract both of them out here.
list($view, $plain, $raw) = $this->parseView($view);
$data['message'] = $message = $this->createMessage();
$this->callMessageBuilder($callback, $message);
// Once we have retrieved the view content for the e-mail we will set the body
// of this message using the HTML type, which will provide a simple wrapper
// to creating view based emails that are able to receive arrays of data.
$this->addContent($message, $view, $plain, $raw, $data);
$message = $message->getSwiftMessage();
return $this->sendSwiftMessage($message);
}
/**
* Queue a new e-mail message for sending.
*
* @param string|array $view
* @param array $data
* @param \Closure|string $callback
* @param string $queue
* @return mixed
*/
public function queue($view, array $data, $callback, $queue = null)
{
$callback = $this->buildQueueCallable($callback);
return $this->queue->push('mailer@handleQueuedMessage', compact('view', 'data', 'callback'), $queue);
}
/**
* Queue a new e-mail message for sending on the given queue.
*
* @param string $queue
* @param string|array $view
* @param array $data
* @param \Closure|string $callback
* @return mixed
*/
public function queueOn($queue, $view, array $data, $callback)
{
return $this->queue($view, $data, $callback, $queue);
}
/**
* Queue a new e-mail message for sending after (n) seconds.
*
* @param int $delay
* @param string|array $view
* @param array $data
* @param \Closure|string $callback
* @param string $queue
* @return mixed
*/
public function later($delay, $view, array $data, $callback, $queue = null)
{
$callback = $this->buildQueueCallable($callback);
return $this->queue->later($delay, 'mailer@handleQueuedMessage', compact('view', 'data', 'callback'), $queue);
}
/**
* Queue a new e-mail message for sending after (n) seconds on the given queue.
*
* @param string $queue
* @param int $delay
* @param string|array $view
* @param array $data
* @param \Closure|string $callback
* @return mixed
*/
public function laterOn($queue, $delay, $view, array $data, $callback)
{
return $this->later($delay, $view, $data, $callback, $queue);
}
/**
* Build the callable for a queued e-mail job.
*
* @param mixed $callback
* @return mixed
*/
protected function buildQueueCallable($callback)
{
if ( ! $callback instanceof Closure) return $callback;
return (new Serializer)->serialize($callback);
}
/**
* Handle a queued e-mail message job.
*
* @param \Illuminate\Contracts\Queue\Job $job
* @param array $data
* @return void
*/
public function handleQueuedMessage($job, $data)
{
$this->send($data['view'], $data['data'], $this->getQueuedCallable($data));
$job->delete();
}
/**
* Get the true callable for a queued e-mail message.
*
* @param array $data
* @return mixed
*/
protected function getQueuedCallable(array $data)
{
if (str_contains($data['callback'], 'SerializableClosure'))
{
return unserialize($data['callback'])->getClosure();
}
return $data['callback'];
}
/**
* Add the content to a given message.
*
* @param \Illuminate\Mail\Message $message
* @param string $view
* @param string $plain
* @param string $raw
* @param array $data
* @return void
*/
protected function addContent($message, $view, $plain, $raw, $data)
{
if (isset($view))
{
$message->setBody($this->getView($view, $data), 'text/html');
}
if (isset($plain))
{
$message->addPart($this->getView($plain, $data), 'text/plain');
}
if (isset($raw))
{
$message->addPart($raw, 'text/plain');
}
}
/**
* Parse the given view name or array.
*
* @param string|array $view
* @return array
*
* @throws \InvalidArgumentException
*/
protected function parseView($view)
{
if (is_string($view)) return [$view, null, null];
// If the given view is an array with numeric keys, we will just assume that
// both a "pretty" and "plain" view were provided, so we will return this
// array as is, since must should contain both views with numeric keys.
if (is_array($view) && isset($view[0]))
{
return [$view[0], $view[1], null];
}
// If the view is an array, but doesn't contain numeric keys, we will assume
// the the views are being explicitly specified and will extract them via
// named keys instead, allowing the developers to use one or the other.
elseif (is_array($view))
{
return [
array_get($view, 'html'),
array_get($view, 'text'),
array_get($view, 'raw'),
];
}
throw new InvalidArgumentException("Invalid view.");
}
/**
* Send a Swift Message instance.
*
* @param \Swift_Message $message
* @return void
*/
protected function sendSwiftMessage($message)
{
if ($this->events)
{
$this->events->fire('mailer.sending', array($message));
}
if ( ! $this->pretending)
{
return $this->swift->send($message, $this->failedRecipients);
}
elseif (isset($this->logger))
{
$this->logMessage($message);
}
}
/**
* Log that a message was sent.
*
* @param \Swift_Message $message
* @return void
*/
protected function logMessage($message)
{
$emails = implode(', ', array_keys((array) $message->getTo()));
$this->logger->info("Pretending to mail message to: {$emails}");
}
/**
* Call the provided message builder.
*
* @param \Closure|string $callback
* @param \Illuminate\Mail\Message $message
* @return mixed
*
* @throws \InvalidArgumentException
*/
protected function callMessageBuilder($callback, $message)
{
if ($callback instanceof Closure)
{
return call_user_func($callback, $message);
}
elseif (is_string($callback))
{
return $this->container->make($callback)->mail($message);
}
throw new InvalidArgumentException("Callback is not valid.");
}
/**
* Create a new message instance.
*
* @return \Illuminate\Mail\Message
*/
protected function createMessage()
{
$message = new Message(new Swift_Message);
// If a global from address has been specified we will set it on every message
// instances so the developer does not have to repeat themselves every time
// they create a new message. We will just go ahead and push the address.
if (isset($this->from['address']))
{
$message->from($this->from['address'], $this->from['name']);
}
return $message;
}
/**
* Render the given view.
*
* @param string $view
* @param array $data
* @return \Illuminate\View\View
*/
protected function getView($view, $data)
{
return $this->views->make($view, $data)->render();
}
/**
* Tell the mailer to not really send messages.
*
* @param bool $value
* @return void
*/
public function pretend($value = true)
{
$this->pretending = $value;
}
/**
* Check if the mailer is pretending to send messages.
*
* @return bool
*/
public function isPretending()
{
return $this->pretending;
}
/**
* Get the view factory instance.
*
* @return \Illuminate\Contracts\View\Factory
*/
public function getViewFactory()
{
return $this->views;
}
/**
* Get the Swift Mailer instance.
*
* @return \Swift_Mailer
*/
public function getSwiftMailer()
{
return $this->swift;
}
/**
* Get the array of failed recipients.
*
* @return array
*/
public function failures()
{
return $this->failedRecipients;
}
/**
* Set the Swift Mailer instance.
*
* @param \Swift_Mailer $swift
* @return void
*/
public function setSwiftMailer($swift)
{
$this->swift = $swift;
}
/**
* Set the log writer instance.
*
* @param \Psr\Log\LoggerInterface $logger
* @return $this
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
return $this;
}
/**
* Set the queue manager instance.
*
* @param \Illuminate\Contracts\Queue\Queue $queue
* @return $this
*/
public function setQueue(QueueContract $queue)
{
$this->queue = $queue;
return $this;
}
/**
* Set the IoC container instance.
*
* @param \Illuminate\Contracts\Container\Container $container
* @return void
*/
public function setContainer(Container $container)
{
$this->container = $container;
}
}

View File

@@ -1,295 +0,0 @@
<?php namespace Illuminate\Mail;
use Swift_Image;
use Swift_Attachment;
class Message {
/**
* The Swift Message instance.
*
* @var \Swift_Message
*/
protected $swift;
/**
* Create a new message instance.
*
* @param \Swift_Message $swift
* @return void
*/
public function __construct($swift)
{
$this->swift = $swift;
}
/**
* Add a "from" address to the message.
*
* @param string $address
* @param string $name
* @return $this
*/
public function from($address, $name = null)
{
$this->swift->setFrom($address, $name);
return $this;
}
/**
* Set the "sender" of the message.
*
* @param string $address
* @param string $name
* @return $this
*/
public function sender($address, $name = null)
{
$this->swift->setSender($address, $name);
return $this;
}
/**
* Set the "return path" of the message.
*
* @param string $address
* @return $this
*/
public function returnPath($address)
{
$this->swift->setReturnPath($address);
return $this;
}
/**
* Add a recipient to the message.
*
* @param string|array $address
* @param string $name
* @return $this
*/
public function to($address, $name = null)
{
return $this->addAddresses($address, $name, 'To');
}
/**
* Add a carbon copy to the message.
*
* @param string $address
* @param string $name
* @return $this
*/
public function cc($address, $name = null)
{
return $this->addAddresses($address, $name, 'Cc');
}
/**
* Add a blind carbon copy to the message.
*
* @param string $address
* @param string $name
* @return $this
*/
public function bcc($address, $name = null)
{
return $this->addAddresses($address, $name, 'Bcc');
}
/**
* Add a reply to address to the message.
*
* @param string $address
* @param string $name
* @return $this
*/
public function replyTo($address, $name = null)
{
return $this->addAddresses($address, $name, 'ReplyTo');
}
/**
* Add a recipient to the message.
*
* @param string|array $address
* @param string $name
* @param string $type
* @return $this
*/
protected function addAddresses($address, $name, $type)
{
if (is_array($address))
{
$this->swift->{"set{$type}"}($address, $name);
}
else
{
$this->swift->{"add{$type}"}($address, $name);
}
return $this;
}
/**
* Set the subject of the message.
*
* @param string $subject
* @return $this
*/
public function subject($subject)
{
$this->swift->setSubject($subject);
return $this;
}
/**
* Set the message priority level.
*
* @param int $level
* @return $this
*/
public function priority($level)
{
$this->swift->setPriority($level);
return $this;
}
/**
* Attach a file to the message.
*
* @param string $file
* @param array $options
* @return $this
*/
public function attach($file, array $options = array())
{
$attachment = $this->createAttachmentFromPath($file);
return $this->prepAttachment($attachment, $options);
}
/**
* Create a Swift Attachment instance.
*
* @param string $file
* @return \Swift_Attachment
*/
protected function createAttachmentFromPath($file)
{
return Swift_Attachment::fromPath($file);
}
/**
* Attach in-memory data as an attachment.
*
* @param string $data
* @param string $name
* @param array $options
* @return $this
*/
public function attachData($data, $name, array $options = array())
{
$attachment = $this->createAttachmentFromData($data, $name);
return $this->prepAttachment($attachment, $options);
}
/**
* Create a Swift Attachment instance from data.
*
* @param string $data
* @param string $name
* @return \Swift_Attachment
*/
protected function createAttachmentFromData($data, $name)
{
return Swift_Attachment::newInstance($data, $name);
}
/**
* Embed a file in the message and get the CID.
*
* @param string $file
* @return string
*/
public function embed($file)
{
return $this->swift->embed(Swift_Image::fromPath($file));
}
/**
* Embed in-memory data in the message and get the CID.
*
* @param string $data
* @param string $name
* @param string $contentType
* @return string
*/
public function embedData($data, $name, $contentType = null)
{
$image = Swift_Image::newInstance($data, $name, $contentType);
return $this->swift->embed($image);
}
/**
* Prepare and attach the given attachment.
*
* @param \Swift_Attachment $attachment
* @param array $options
* @return $this
*/
protected function prepAttachment($attachment, $options = array())
{
// First we will check for a MIME type on the message, which instructs the
// mail client on what type of attachment the file is so that it may be
// downloaded correctly by the user. The MIME option is not required.
if (isset($options['mime']))
{
$attachment->setContentType($options['mime']);
}
// If an alternative name was given as an option, we will set that on this
// attachment so that it will be downloaded with the desired names from
// the developer, otherwise the default file names will get assigned.
if (isset($options['as']))
{
$attachment->setFilename($options['as']);
}
$this->swift->attach($attachment);
return $this;
}
/**
* Get the underlying Swift Message instance.
*
* @return \Swift_Message
*/
public function getSwiftMessage()
{
return $this->swift;
}
/**
* Dynamically pass missing methods to the Swift instance.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function __call($method, $parameters)
{
$callable = array($this->swift, $method);
return call_user_func_array($callable, $parameters);
}
}

View File

@@ -1,87 +0,0 @@
<?php namespace Illuminate\Mail\Transport;
use Swift_Transport;
use Swift_Mime_Message;
use Swift_Mime_MimeEntity;
use Psr\Log\LoggerInterface;
use Swift_Events_EventListener;
class LogTransport implements Swift_Transport {
/**
* The Logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Create a new log transport instance.
*
* @param \Psr\Log\LoggerInterface $logger
* @return void
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function isStarted()
{
return true;
}
/**
* {@inheritdoc}
*/
public function start()
{
return true;
}
/**
* {@inheritdoc}
*/
public function stop()
{
return true;
}
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$this->logger->debug($this->getMimeEntityString($message));
}
/**
* Get a loggable string out of a Swiftmailer entity.
*
* @param \Swift_Mime_MimeEntity $entity
* @return string
*/
protected function getMimeEntityString(Swift_Mime_MimeEntity $entity)
{
$string = (string) $entity->getHeaders().PHP_EOL.$entity->getBody();
foreach ($entity->getChildren() as $children)
{
$string .= PHP_EOL.PHP_EOL.$this->getMimeEntityString($children);
}
return $string;
}
/**
* {@inheritdoc}
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
//
}
}

View File

@@ -1,168 +0,0 @@
<?php namespace Illuminate\Mail\Transport;
use Swift_Transport;
use GuzzleHttp\Client;
use Swift_Mime_Message;
use GuzzleHttp\Post\PostFile;
use Swift_Events_EventListener;
class MailgunTransport implements Swift_Transport {
/**
* The Mailgun API key.
*
* @var string
*/
protected $key;
/**
* The Mailgun domain.
*
* @var string
*/
protected $domain;
/**
* THe Mailgun API end-point.
*
* @var string
*/
protected $url;
/**
* Create a new Mailgun transport instance.
*
* @param string $key
* @param string $domain
* @return void
*/
public function __construct($key, $domain)
{
$this->key = $key;
$this->setDomain($domain);
}
/**
* {@inheritdoc}
*/
public function isStarted()
{
return true;
}
/**
* {@inheritdoc}
*/
public function start()
{
return true;
}
/**
* {@inheritdoc}
*/
public function stop()
{
return true;
}
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$client = $this->getHttpClient();
return $client->post($this->url, ['auth' => ['api', $this->key],
'body' => [
'to' => $this->getTo($message),
'message' => new PostFile('message', (string) $message),
],
]);
}
/**
* {@inheritdoc}
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
//
}
/**
* Get the "to" payload field for the API request.
*
* @param \Swift_Mime_Message $message
* @return array
*/
protected function getTo(Swift_Mime_Message $message)
{
$formatted = [];
$contacts = array_merge(
(array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc()
);
foreach ($contacts as $address => $display)
{
$formatted[] = $display ? $display." <$address>" : $address;
}
return implode(',', $formatted);
}
/**
* Get a new HTTP client instance.
*
* @return \GuzzleHttp\Client
*/
protected function getHttpClient()
{
return new Client;
}
/**
* Get the API key being used by the transport.
*
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* Set the API key being used by the transport.
*
* @param string $key
* @return void
*/
public function setKey($key)
{
return $this->key = $key;
}
/**
* Get the domain being used by the transport.
*
* @return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* Set the domain being used by the transport.
*
* @param string $domain
* @return void
*/
public function setDomain($domain)
{
$this->url = 'https://api.mailgun.net/v2/'.$domain.'/messages.mime';
return $this->domain = $domain;
}
}

View File

@@ -1,138 +0,0 @@
<?php namespace Illuminate\Mail\Transport;
use Swift_Transport;
use GuzzleHttp\Client;
use Swift_Mime_Message;
use Swift_Events_EventListener;
class MandrillTransport implements Swift_Transport {
/**
* The Mandrill API key.
*
* @var string
*/
protected $key;
/**
* Create a new Mandrill transport instance.
*
* @param string $key
* @return void
*/
public function __construct($key)
{
$this->key = $key;
}
/**
* {@inheritdoc}
*/
public function isStarted()
{
return true;
}
/**
* {@inheritdoc}
*/
public function start()
{
return true;
}
/**
* {@inheritdoc}
*/
public function stop()
{
return true;
}
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$client = $this->getHttpClient();
return $client->post('https://mandrillapp.com/api/1.0/messages/send-raw.json', [
'body' => [
'key' => $this->key,
'to' => $this->getToAddresses($message),
'raw_message' => (string) $message,
'async' => false,
],
]);
}
/**
* Get all the addresses this message should be sent to.
*
* Note that Mandrill still respects CC, BCC headers in raw message itself.
*
* @param Swift_Mime_Message $message
* @return array
*/
protected function getToAddresses(Swift_Mime_Message $message)
{
$to = [];
if ($message->getTo())
{
$to = array_merge($to, array_keys($message->getTo()));
}
if ($message->getCc())
{
$to = array_merge($to, array_keys($message->getCc()));
}
if ($message->getBcc())
{
$to = array_merge($to, array_keys($message->getBcc()));
}
return $to;
}
/**
* {@inheritdoc}
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
//
}
/**
* Get a new HTTP client instance.
*
* @return \GuzzleHttp\Client
*/
protected function getHttpClient()
{
return new Client;
}
/**
* Get the API key being used by the transport.
*
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* Set the API key being used by the transport.
*
* @param string $key
* @return void
*/
public function setKey($key)
{
return $this->key = $key;
}
}

View File

@@ -1,96 +0,0 @@
<?php namespace Illuminate\Mail\Transport;
use Swift_Transport;
use Aws\Ses\SesClient;
use Swift_Mime_Message;
use Swift_Events_EventListener;
class SesTransport implements Swift_Transport {
/**
* The Amazon SES instance.
*
* @var \Aws\Ses\SesClient
*/
protected $ses;
/**
* Create a new SES transport instance.
*
* @param \Aws\Ses\SesClient $ses
* @return void
*/
public function __construct(SesClient $ses)
{
$this->ses = $ses;
}
/**
* {@inheritdoc}
*/
public function isStarted()
{
return true;
}
/**
* {@inheritdoc}
*/
public function start()
{
return true;
}
/**
* {@inheritdoc}
*/
public function stop()
{
return true;
}
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
return $this->ses->sendRawEmail([
'Source' => $message->getSender(),
'Destinations' => $this->getTo($message),
'RawMessage' => [
'Data' => base64_encode((string) $message),
],
]);
}
/**
* {@inheritdoc}
*/
public function registerPlugin(Swift_Events_EventListener $plugin)
{
//
}
/**
* Get the "to" payload field for the API request.
*
* @param \Swift_Mime_Message $message
* @return array
*/
protected function getTo(Swift_Mime_Message $message)
{
$destinations = [];
$contacts = array_merge(
(array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc()
);
foreach ($contacts as $address => $display)
{
$destinations[] = $address;
}
return $destinations;
}
}

View File

@@ -1,138 +0,0 @@
<?php namespace Illuminate\Mail;
use Aws\Ses\SesClient;
use Illuminate\Support\Manager;
use Swift_SmtpTransport as SmtpTransport;
use Swift_MailTransport as MailTransport;
use Illuminate\Mail\Transport\LogTransport;
use Illuminate\Mail\Transport\MailgunTransport;
use Illuminate\Mail\Transport\MandrillTransport;
use Illuminate\Mail\Transport\SesTransport;
use Swift_SendmailTransport as SendmailTransport;
class TransportManager extends Manager {
/**
* Create an instance of the SMTP Swift Transport driver.
*
* @return \Swift_SmtpTransport
*/
protected function createSmtpDriver()
{
$config = $this->app['config']['mail'];
// The Swift SMTP transport instance will allow us to use any SMTP backend
// for delivering mail such as Sendgrid, Amazon SES, or a custom server
// a developer has available. We will just pass this configured host.
$transport = SmtpTransport::newInstance(
$config['host'], $config['port']
);
if (isset($config['encryption']))
{
$transport->setEncryption($config['encryption']);
}
// Once we have the transport we will check for the presence of a username
// and password. If we have it we will set the credentials on the Swift
// transporter instance so that we'll properly authenticate delivery.
if (isset($config['username']))
{
$transport->setUsername($config['username']);
$transport->setPassword($config['password']);
}
return $transport;
}
/**
* Create an instance of the Sendmail Swift Transport driver.
*
* @return \Swift_SendmailTransport
*/
protected function createSendmailDriver()
{
$command = $this->app['config']['mail']['sendmail'];
return SendmailTransport::newInstance($command);
}
/**
* Create an instance of the Amazon SES Swift Transport driver.
*
* @return \Swift_SendmailTransport
*/
protected function createSesDriver()
{
$sesClient = SesClient::factory($this->app['config']->get('services.ses', []));
return new SesTransport($sesClient);
}
/**
* Create an instance of the Mail Swift Transport driver.
*
* @return \Swift_MailTransport
*/
protected function createMailDriver()
{
return MailTransport::newInstance();
}
/**
* Create an instance of the Mailgun Swift Transport driver.
*
* @return \Illuminate\Mail\Transport\MailgunTransport
*/
protected function createMailgunDriver()
{
$config = $this->app['config']->get('services.mailgun', array());
return new MailgunTransport($config['secret'], $config['domain']);
}
/**
* Create an instance of the Mandrill Swift Transport driver.
*
* @return \Illuminate\Mail\Transport\MandrillTransport
*/
protected function createMandrillDriver()
{
$config = $this->app['config']->get('services.mandrill', array());
return new MandrillTransport($config['secret']);
}
/**
* Create an instance of the Log Swift Transport driver.
*
* @return \Illuminate\Mail\Transport\LogTransport
*/
protected function createLogDriver()
{
return new LogTransport($this->app->make('Psr\Log\LoggerInterface'));
}
/**
* Get the default cache driver name.
*
* @return string
*/
public function getDefaultDriver()
{
return $this->app['config']['mail.driver'];
}
/**
* Set the default cache driver name.
*
* @param string $name
* @return void
*/
public function setDefaultDriver($name)
{
$this->app['config']['mail.driver'] = $name;
}
}

View File

@@ -1,39 +0,0 @@
{
"name": "illuminate/mail",
"description": "The Illuminate Mail package.",
"license": "MIT",
"homepage": "http://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"authors": [
{
"name": "Taylor Otwell",
"email": "taylorotwell@gmail.com"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/container": "5.0.*",
"illuminate/contracts": "5.0.*",
"illuminate/support": "5.0.*",
"psr/log": "~1.0",
"swiftmailer/swiftmailer": "~5.1"
},
"autoload": {
"psr-4": {
"Illuminate\\Mail\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
}
},
"suggest": {
"aws/aws-sdk-php": "Required to use the SES mail driver (~2.4).",
"guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers (~5.0)."
},
"minimum-stability": "dev"
}