Get all the addresses this message should be sent to.

@param Swift_Mime_Message $message

@return array
515072
protected function getRecipients(Swift_Mime_Message $message) {
        $to = [];
        if ($message->getTo()) {
            $to = array_merge($to, $message->getTo());
        }
        if ($message->getCc()) {
            $to = array_merge($to, $message->getCc());
        }
        if ($message->getBcc()) {
            $to = array_merge($to, $message->getBcc());
        }
        $recipients = [];
        foreach ($to as $address => $name) {
            if (!is_null($name)) {
                $recipients[] = ['Email' => $address, 'Name' => $name];
            } else {
                $recipients[] = ['Email' => $address];
            }
        }
        return $recipients;
    }
864319
public function getMandrillMessage(Swift_Mime_SimpleMessage $message)
    {
        $contentType = $this->getMessagePrimaryContentType($message);

        $fromAddresses = $message->getFrom();
        $fromEmails = array_keys($fromAddresses);

        $toAddresses = $message->getTo();
        $ccAddresses = $message->getCc() ? $message->getCc() : [];
        $bccAddresses = $message->getBcc() ? $message->getBcc() : [];
        $replyToAddresses = $message->getReplyTo() ? $message->getReplyTo() : [];

        $to = array();
        $attachments = array();
        $images = array();
        $headers = array();
        $tags = array();

        foreach ($toAddresses as $toEmail => $toName) {
            $to[] = array(
                'email' => $toEmail,
                'name'  => $toName,
                'type'  => 'to'
            );
        }

        foreach ($replyToAddresses as $replyToEmail => $replyToName) {
            if ($replyToName) {
                $headers['Reply-To'] = sprintf('%s <%s>', $replyToEmail, $replyToName);
            } else {
                $headers['Reply-To'] = $replyToEmail;
            }
        }

        foreach ($ccAddresses as $ccEmail => $ccName) {
            $to[] = array(
                'email' => $ccEmail,
                'name'  => $ccName,
                'type'  => 'cc'
            );
        }

        foreach ($bccAddresses as $bccEmail => $bccName) {
            $to[] = array(
                'email' => $bccEmail,
                'name'  => $bccName,
                'type'  => 'bcc'
            );
        }

        $bodyHtml = $bodyText = null;

        if ($contentType === 'text/plain') {
            $bodyText = $message->getBody();
        } elseif ($contentType === 'text/html') {
            $bodyHtml = $message->getBody();
        } else {
            $bodyHtml = $message->getBody();
        }

        foreach ($message->getChildren() as $child) {
            if ($child instanceof \Swift_Image) {
                $images[] = array(
                    'type'    => $child->getContentType(),
                    'name'    => $child->getId(),
                    'content' => base64_encode($child->getBody()),
                );
            } elseif ($child instanceof Swift_Attachment && ! ($child instanceof \Swift_Image)) {
                $attachments[] = array(
                    'type'    => $child->getContentType(),
                    'name'    => $child->getFilename(),
                    'content' => base64_encode($child->getBody())
                );
            } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) {
                if ($child->getContentType() == "text/html") {
                    $bodyHtml = $child->getBody();
                } elseif ($child->getContentType() == "text/plain") {
                    $bodyText = $child->getBody();
                }
            }
        }

        $mandrillMessage = array(
            'html'       => $bodyHtml,
            'text'       => $bodyText,
            'subject'    => $message->getSubject(),
            'from_email' => $fromEmails[0],
            'from_name'  => $fromAddresses[$fromEmails[0]],
            'to'         => $to,
            'headers'    => $headers,
            'tags'       => $tags,
            'inline_css' => null
        );

        if (count($attachments) > 0) {
            $mandrillMessage['attachments'] = $attachments;
        }

        if (count($images) > 0) {
            $mandrillMessage['images'] = $images;
        }

        foreach ($message->getHeaders()->getAll() as $header) {
            if ($header->getFieldType() === \Swift_Mime_Header::TYPE_TEXT) {
                switch ($header->getFieldName()) {
                    case 'List-Unsubscribe':
                        $headers['List-Unsubscribe'] = $header->getValue();
                        $mandrillMessage['headers'] = $headers;
                        break;
                    case 'X-MC-InlineCSS':
                        $mandrillMessage['inline_css'] = $header->getValue();
                        break;
                    case 'X-MC-Tags':
                        $tags = $header->getValue();
                        if (!is_array($tags)) {
                            $tags = explode(',', $tags);
                        }
                        $mandrillMessage['tags'] = $tags;
                        break;
                    case 'X-MC-Autotext':
                        $autoText = $header->getValue();
                        if (in_array($autoText, array('true','on','yes','y', true), true)) {
                            $mandrillMessage['auto_text'] = true;
                        }
                        if (in_array($autoText, array('false','off','no','n', false), true)) {
                            $mandrillMessage['auto_text'] = false;
                        }
                        break;
                    case 'X-MC-GoogleAnalytics':
                        $analyticsDomains = explode(',', $header->getValue());
                        if(is_array($analyticsDomains)) {
                            $mandrillMessage['google_analytics_domains'] = $analyticsDomains;
                        }
                        break;
                    case 'X-MC-GoogleAnalyticsCampaign':
                        $mandrillMessage['google_analytics_campaign'] = $header->getValue();
                        break;
                    case 'X-MC-TrackingDomain':
                        $mandrillMessage['tracking_domain'] = $header->getValue();
                        break;
                    default:
                        if (strncmp($header->getFieldName(), 'X-', 2) === 0) {
                            $headers[$header->getFieldName()] = $header->getValue();
                            $mandrillMessage['headers'] = $headers;
                        }
                        break;
                }
            }
        }

        if ($this->getSubaccount()) {
            $mandrillMessage['subaccount'] = $this->getSubaccount();
        }

        return $mandrillMessage;
    }
657465
public function send(OutgoingMessage $message)
    {
        $from = $message->getFrom();
        $composeMessage = $message->composeMessage();

        //Convert to callfire format.
        $numbers = implode(',', $message->getTo());

        $data = [
            'from'       => $from,
            'to'         => $numbers,
            'text'       => $composeMessage,
            'api_key'    => $this->apiKey,
            'api_secret' => $this->apiSecret,
        ];

        $this->buildCall('/sms/json');
        $this->buildBody($data);

        $response = $this->postRequest();
        $body = json_decode($response->getBody(), true);
        if ($this->hasError($body)) {
            $this->handleError($body);
        }

        return $response;
    }
483369
private function buildRecipients(Swift_Mime_Message $message)
    {
        $tos = array_merge((array) $message->getTo(), (array) $message->getCc());
        $bcc = (array) $message->getBcc();

        if (count($tos) === 0) {
            throw new Exception('Cannot send message without a recipient address');
        }

        $tags             = [];
        $metadata         = [];
        $substitutionData = [];

        if ($message instanceof Message) {
            $tags             = $message->getPerRecipientTags();
            $metadata         = $message->getPerRecipientMetadata();
            $substitutionData = $message->getPerRecipientSubstitutionData();
        }

        $recipients = [];

        foreach ($tos as $email => $name) {
            $recipients[] = $this->buildRecipient($email, $name, $tags, $metadata, $substitutionData);
        }

        $originalEmail = current($recipients)['address']['email'];

        foreach ($bcc as $email => $name) {
            $recipients[] = $this->buildRecipient($email, $name, $tags, $metadata, $substitutionData, $originalEmail);
        }

        return $recipients;
    }
850264
private function buildFrom(Swift_Mime_Message $message)
    {
        $from = $message->getFrom();

        if (current($from)) {
            return ['email' => key($from), 'name' => current($from)];
        }

        return key($from);
    }
592059
protected function beforeSendPerformed(Swift_Mime_Message $message)
    {
        $event = new Swift_Events_SendEvent($this, $message);

        foreach ($this->plugins as $plugin) {

            if (method_exists($plugin, 'beforeSendPerformed')) {

                $plugin->beforeSendPerformed($event);

            }
        }
    }
467017
public function getExceptionByMessage($message)
    {
        $exceptions = array();
        foreach ($this->_exceptions as $e) {
            if ($message == $e->getMessage()) {
                $exceptions[] = $e;
            }
        }

        if (empty($exceptions)) {
            $exceptions = false;
        }

        return $exceptions;
    }
397940
protected function clearAllHeaders(Swift_Message $message)
    {
        $headers = $message->getHeaders();
        foreach ($headers->listAll() as $header) {
            $headers->removeAll($header);
        }
    }
18722
public function transformTextCard(AbstractMessage $message)
    {
        return [
            'msgtype'  => 'textcard',
            'textcard' => [
                'title'       => $message->get('title'),
                'description' => $message->get('description'),
                'url'         => $message->get('url'),
                'btntxt'      => $message->get('btntxt'),
            ],
        ];
    }
144399
protected function parseMessage($message)
    {
        $headerAndBody = explode("\r\n\r\n", $message, 2);
        $headers = explode("\r\n", $headerAndBody[0]);

        return [$this->parseHeader($headers), $headerAndBody[1]];

    }
545933
protected function getEmailAddresses()
    {
        $addresses = array();
        $committer = $this->build->getCommitterEmail();

        if (isset($this->options['committer']) && !empty($committer)) {
            $addresses[] = $committer;
        }

        if (isset($this->options['addresses'])) {
            foreach ($this->options['addresses'] as $address) {
                $addresses[] = $address;
            }
        }

        if (empty($addresses) && isset($this->options['default_mailto_address'])) {
            $addresses[] = $this->options['default_mailto_address'];
        }

        return array_unique($addresses);
    }
987324
private function buildOptions(Swift_Mime_Message $message)
    {
        $options = $this->config->getOptions();

        if (!$this->configuredIpPoolShouldBeUsed()) {
            unset($options[Option::IP_POOL]);
        }

        if ($message instanceof Message) {
            $options = array_merge($options, $message->getOptions());
        }

        return $options;
    }
579600
protected function attachments(SlackMessage $message)
    {
        return collect($message->attachments)->map(function ($attachment) use ($message) {
            return array_filter([
                'actions' => $attachment->actions,
                'author_icon' => $attachment->authorIcon,
                'author_link' => $attachment->authorLink,
                'author_name' => $attachment->authorName,
                'color' => $attachment->color ?: $message->color(),
                'fallback' => $attachment->fallback,
                'fields' => $this->fields($attachment),
                'footer' => $attachment->footer,
                'footer_icon' => $attachment->footerIcon,
                'image_url' => $attachment->imageUrl,
                'mrkdwn_in' => $attachment->markdown,
                'pretext' => $attachment->pretext,
                'text' => $attachment->content,
                'thumb_url' => $attachment->thumbUrl,
                'title' => $attachment->title,
                'title_link' => $attachment->url,
                'ts' => $attachment->timestamp,
            ]);
        })->all();
    }
1346500
public function transformVariables($message)
    {
        $patterns = [];
        $replacements = [];

        preg_match_all(static::VARIABLE_REGEX, $message, $matches);
        foreach ($matches[0] as $variable) {
            $replacements[] = $this->values[$variable];
            $patterns[] = '#' . preg_quote($variable) . '#';
        }
        $message = preg_replace($patterns, $replacements, $message);

        return $message;
    }
1179795
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);
	}
957255
protected function buildData($message)
    {
        $data = [];

        if ($message->getHeaders()) {
            $headers = $message->getHeaders()->getAll();

            foreach( $headers as $header) {
                if( $header instanceof Swift_Mime_Headers_UnstructuredHeader ) {
                    $data['headers'][$header->getFieldName()] = $header->getValue();
                }
            }
        }

        if ($message->getTo()) {
            $data['to'] = $message->getTo();
        }

        if ($message->getSubject()) {
            $data['subject'] = $message->getSubject();
        }

        if ($message->getFrom()) {
            $from = $message->getFrom();
            reset($from);
            $key = key($from);
            $data['from'] = [$key, $from[$key]];
        }

        // set content
        if ($message->getContentType() == 'text/plain') {
            $data['text'] = $message->getBody();
        } else {
            $data['html'] = $message->getBody();
        }

        $children = $message->getChildren();
        foreach ($children as $child) {
            if ($child instanceof Swift_MimePart && $child->getContentType() == 'text/plain') {
                $data['text'] = $child->getBody();
            }
        }

        if (! isset($data['text'])) {
            $data['text'] = strip_tags($message->getBody());
        }
        // end set content

        if ($message->getCc()) {
            $data['cc'] = $message->getCc();
        }

        if ($message->getBcc()) {
            $data['bcc'] = $message->getBcc();
        }

        if ($message->getReplyTo()) {
            $replyTo = $message->getReplyTo();
            reset($replyTo);
            $key = key($replyTo);
            $data['replyto'] = [$key, $replyTo[$key]];
        }

        // attachment
        $attachment = [];
        foreach ($children as $child) {
            if ($child instanceof Swift_Attachment) {
                $filename = $child->getFilename();
                $content = chunk_split(base64_encode($child->getBody()));
                $attachment[$filename] = $content;
            }
        }

        if (count($attachment)) {
            $data['attachment'] = $attachment;
        }

        return $data;
    }
1245129
public function getMailjetMessage(Swift_Mime_Message $message) {
        $contentType = $this->getMessagePrimaryContentType($message);
        $fromAddresses = $message->getFrom();
        $fromEmails = array_keys($fromAddresses);
        $toAddresses = $message->getTo();
        $ccAddresses = $message->getCc() ? $message->getCc() : [];
        $bccAddresses = $message->getBcc() ? $message->getBcc() : [];

        $attachments = array();
        $inline_attachments = array();

        // Process Headers
        $customHeaders = $this->prepareHeaders($message, $this->getMailjetHeaders());
        $userDefinedHeaders = $this->findUserDefinedHeaders($message);


        // @TODO only Format To, Cc, Bcc
        //@TODO array_push is not recommended
        $to = array();
        foreach ($toAddresses as $toEmail => $toName) {
            if (!is_null($toName)) {
                array_push($to, ['Email' => $toEmail, 'Name' => $toName]);
            } else {
                array_push($to, ['Email' => $toEmail]);
            }
        }
        $cc = array();
        foreach ($ccAddresses as $ccEmail => $ccName) {
            if (!is_null($ccName)) {
                array_push($cc, ['Email' => $ccEmail, 'Name' => $ccName]);
            } else {
                array_push($cc, ['Email' => $ccEmail]);
            }
        }
        $bcc = array();
        foreach ($bccAddresses as $bccEmail => $bccName) {
            if (!is_null($bccName)) {
                array_push($bcc, ['Email' => $bccEmail, 'Name' => $bccName]);
            } else {
                array_push($bcc, ['Email' => $bccEmail]);
            }
        }

        // Handle content
        $bodyHtml = $bodyText = null;
        if ($contentType === 'text/plain') {
            $bodyText = $message->getBody();
        } else {
            $bodyHtml = $message->getBody();
        }


        // Handle attachments
        foreach ($message->getChildren() as $child) {
            if ($child instanceof Swift_Attachment) {
                //Handle regular attachments
                if ($child->getDisposition() === "attachment") {
                    $attachments[] = array(
                        'ContentType' => $child->getContentType(),
                        'Filename' => $child->getFilename(),
                        'Base64Content' => base64_encode($child->getBody())
                    );
                }
                //Handle inline attachments
                elseif ($child->getDisposition() === "inline") {
                    $inline_attachments[] = array(
                        'ContentType' => $child->getContentType(),
                        'Filename' => $child->getFilename(),
                        'ContentID' => $child->getId(),
                        'Base64Content' => base64_encode($child->getBody())
                    );
                }
            } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) {
                if ($child->getContentType() == "text/html") {
                    $bodyHtml = $child->getBody();
                } elseif ($child->getContentType() == "text/plain") {
                    $bodyText = $child->getBody();
                }
            }
        }
        $mailjetMessage = array();
        $from = array(
            'Email' => $fromEmails[0],
            'Name' => $fromAddresses[$fromEmails[0]]
        );

        if (!empty($from)) {
            if (is_null($from['Name'])) {
                unset($from['Name']);
            }
            $mailjetMessage['From'] = $from;
        }
        if (!empty($to)) {
            $mailjetMessage['To'] = $to;
        }
        if (!empty($cc)) {
            $mailjetMessage['Cc'] = $cc;
        }
        if (!empty($bcc)) {
            $mailjetMessage['Bcc'] = $bcc;
        }
        if (!is_null($message->getSubject())) {
            $mailjetMessage['Subject'] = $message->getSubject();
        }
        if (!is_null($bodyHtml)) {
            $mailjetMessage['HTMLPart'] = $bodyHtml;
        }
        if (!is_null($bodyText)) {
            $mailjetMessage['TextPart'] = $bodyText;
        }
        if ($replyTo = $this->getReplyTo($message)) {
            $mailjetMessage['ReplyTo'] = $replyTo;
        }

        if (count($userDefinedHeaders) > 0) {
            $mailjetMessage['Headers'] = $userDefinedHeaders;
        }

        if (count($customHeaders) > 0) {
            $mailjetMessage = array_merge($mailjetMessage, $customHeaders);
        }

        if (count($attachments) > 0) {
            $mailjetMessage['Attachments'] = $attachments;
        }
        if (count($inline_attachments) > 0) {
            $mailjetMessage['InlinedAttachments'] = $inline_attachments;
        }


        return array('Messages' => array($mailjetMessage));
    }