@param Swift_Mime_Message $message

@return array
436176
public function buildPayload(Swift_Mime_Message $message)
    {
        $payload = [
            'recipients' => $this->buildRecipients($message),
            'content'    => $this->buildContent($message),
        ];

        if ($campaignId = $this->buildCampaignId($message)) {
            $payload['campaign_id'] = $campaignId;
        }

        if ($metadata = $this->buildMetadata($message)) {
            $payload['metadata'] = $metadata;
        }

        if ($substitutionData = $this->buildSubstitutionData($message)) {
            $payload['substitution_data'] = $substitutionData;
        }

        if ($options = $this->buildOptions($message)) {
            $payload['options'] = $options;
        }

        return $payload;
    }
105358
private function parseMessage($message)
    {
        $string = $message;

        if (is_array($message)) {
            $format = '"%s" %s';
            $errors = array();

            foreach ($message as $field => $messages) {
                if (is_array($messages)) {
                    $messages = array_unique($messages);
                    foreach ($messages as $error) {
                        $errors[] = sprintf($format, $field, $error);
                    }
                } elseif (is_integer($field)) {
                    $errors[] = $messages;
                } else {
                    $errors[] = sprintf($format, $field, $messages);
                }
            }

            $string = implode(', ', $errors);
        }

        return $string;
    }
1182391
private function getReversePath(\Swift_Mime_SimpleMessage $message): string
    {
        $returnPath = $message->getReturnPath();
        $sender = $message->getSender();
        $from = $message->getFrom();
        $path = '';
        if (!empty($returnPath)) {
            $path = $returnPath;
        } elseif (!empty($sender)) {
            $path = $sender;
        } elseif (!empty($from)) {
            if (is_array($from)) {
                $keys = array_keys($from);
                $path = array_shift($keys);
            } else {
                $path = $from;
            }
        }
        return $path;
    }
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);
	}
455244
protected function getTo(Swift_Mime_SimpleMessage $message)
    {
        return collect($this->allContacts($message))->map(function ($display, $address) {
            return $display ? $display." <{$address}>" : $address;
        })->values()->implode(',');
    }
1169276
protected function getHTMLPreviewContent(Swift_Mime_SimpleMessage $message)
    {
        $messageInfo = $this->getMessageInfo($message);

        return $messageInfo.$message->getBody();
    }
354891
public static function makeResult($data, $message)
	{
		$result = array();
		$result['flag'] = true;
		$result['message'] = $message;
		$result['data'] = $data;

		return $result;
	}
1140347
protected function getReversePath(Swift_Mime_SimpleMessage $message)
    {
        $return = $message->getReturnPath();
        $sender = $message->getSender();
        $from = $message->getFrom();
        $path = null;
        if (!empty($return)) {
            $path = $return;
        } elseif (!empty($sender)) {
            // Don't use array_keys
            reset($sender); // Reset Pointer to first pos
            $path = key($sender); // Get key
        } elseif (!empty($from)) {
            reset($from); // Reset Pointer to first pos
            $path = key($from); // Get key
        }

        return $path;
    }
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;
    }
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;
    }
942947
public function prepareMessage($message)
    {
        list($text, $level, $category, $timestamp) = $message;

        $result = [
            'category' => $category,
            'level' => Logger::getLevelName($level),
            '@timestamp' => date('c', $timestamp),
        ];

        if (isset($message[4])) {
            $result['trace'] = $message[4];
        }

        //Exceptions get parsed into an array, text and arrays are passed as is, other types are var_dumped
        if ($text instanceof \Exception) {
            //convert exception to array for easier analysis
            $result['message'] = [
                'message' => $text->getMessage(),
                'file' => $text->getFile(),
                'line' => $text->getLine(),
                'trace' => $text->getTraceAsString(),
            ];
        } elseif (is_array($text) || is_string($text)) {
            $result['message'] = $text;
        } else {
            $result['message'] = VarDumper::export($text);
        }

        if ($this->includeContext) {
            $result['context'] = $this->getContextMessage();
        }

        $message = implode("\n", [
            Json::encode([
                'index' => new \stdClass()
            ]),
            Json::encode($result)
        ]);

        return $message;
    }
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;
    }
159120
public function uploadMedias(MediaUploadMessage $message): array
    {
        $message->initBuilder();

        $path    = sprintf('sites/%d/uploads/media', $message->getSiteId());
        $body    = $message->build();
        $headers = $message->buildHeaders();

        $response = $this->getClient()->sendRequest('POST', $path, $body, $headers);

        /** @var Media[] $model */
        $model = $this->getModelFactory()->createMany(Media::class, $response);

        return $model;
    }
937259
protected function getPreviewFilePath(Swift_Mime_SimpleMessage $message)
    {
        $to = str_replace(['@', '.'], ['_at_', '_'], array_keys($message->getTo())[0]);

        $subject = $message->getSubject();

        return $this->previewPath.'/'.str_slug($message->getDate()->getTimestamp().'_'.$to.'_'.$subject, '_');
    }
600425
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
    {
        if ($evt = $this->eventDispatcher->createSendEvent($this, $message)) {
            $this->eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
            if ($evt->bubbleCancelled()) {
                return 0;
            }
        }

        $this->doSend($message, $failedRecipients);

        if ($evt) {
            $evt->setResult(\Swift_Events_SendEvent::RESULT_SUCCESS);
            $this->eventDispatcher->dispatchEvent($evt, 'sendPerformed');
        }

        $count = (
            count((array) $message->getTo())
            + count((array) $message->getCc())
            + count((array) $message->getBcc())
        );

        return $count;
    }
577693
protected function numberOfRecipients(Swift_Mime_Message $message)
    {
        return count(array_merge(
            (array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc()
        ));
    }
333817
public function getTouchDowns(AbstractMessage $message)
    {
        $touchdown = array();
        $messageSegments = $message->getEncryptedSegments();
        /** @var AbstractSegment $msgSeg */
        foreach ($messageSegments as $msgSeg) {
            $segment = $this->findSegmentForReference('HIRMS', $msgSeg);
            if (null != $segment) {
                $parts = $this->splitSegment($segment);
                // remove header
                array_shift($parts);
                foreach ($parts as $p) {
                    $pSplit = $this->splitDeg($p);
                    if ($pSplit[0] == 3040) {
                        $td = $pSplit[3];
                        $touchdown[$msgSeg->getName()] = $td;
                    }
                }
            }
        }

        return $touchdown;
    }