protected function format(MessageInterface $message)
    {
        $personalization = [
            'to'      => $this->formatRecipients($message->getTo()),
            'cc'      => $this->formatRecipients($message->getCc()),
            'bcc'     => $this->formatRecipients($message->getBcc()),
            'subject' => $message->getSubject(),
        ];

        if ($headers = $message->getHeaders()) {
            $personalization['headers'] = $headers;
        }

        if (empty($personalization['cc'])) {
            unset($personalization['cc']);
        }

        if (empty($personalization['bcc'])) {
            unset($personalization['bcc']);
        }

        $content = [
            ['type' => 'text/plain', 'value' => $message->getText()],
            ['type' => 'text/html', 'value' => $message->getHtml()],
        ];

        foreach ($content as $i => $c) {
            if (empty($c['value'])) {
                unset($content[$i]);
            }
        }

        $parameters = [
            'personalizations' => [$personalization],
            'from'             => $this->formatRecipients($message->getFrom())[0],
            'reply_to'         => $this->formatRecipients($message->getReplyTo()),
            'content'          => array_values($content),
        ];

        if (empty($parameters['reply_to'])) {
            unset($parameters['reply_to']);
        } else {
            $parameters['reply_to'] = $parameters['reply_to'][0];
        }

        if ($message instanceof AttachmentsAwareInterface) {
            $attachments = $message->getAttachments();
            if (!empty($attachments)) {
                $parameters['attachments'] = $this->processAttachments($attachments);
            }
        }

        if ($message instanceof TaggableInterface) {
            $parameters['categories'] = (array) $message->getTag();
        }

        if ($message instanceof MetadataAwareInterface) {
            $metadata = array_filter($message->getMetadata());
            if (!empty($metadata)) {
                if (isset($parameters['custom_args'])) {
                    $parameters['custom_args'] = array_merge($parameters['custom_args'], $metadata);
                } else {
                    $parameters['custom_args'] = $metadata;
                }
            }
        }

        return json_encode($parameters);
    }
protected function format(MessageInterface $message)
    {
        $personalization = [
            'to'      => $this->formatRecipients($message->getTo()),
            'cc'      => $this->formatRecipients($message->getCc()),
            'bcc'     => $this->formatRecipients($message->getBcc()),
            'subject' => $message->getSubject(),
        ];

        if ($headers = $message->getHeaders()) {
            $personalization['headers'] = $headers;
        }

        if (empty($personalization['cc'])) {
            unset($personalization['cc']);
        }

        if (empty($personalization['bcc'])) {
            unset($personalization['bcc']);
        }

        $content = [
            ['type' => 'text/plain', 'value' => $message->getText()],
            ['type' => 'text/html', 'value' => $message->getHtml()],
        ];

        foreach ($content as $i => $c) {
            if (empty($c['value'])) {
                unset($content[$i]);
            }
        }

        $parameters = [
            'personalizations' => [$personalization],
            'from'             => $this->formatRecipients($message->getFrom())[0],
            'reply_to'         => $this->formatRecipients($message->getReplyTo()),
            'content'          => array_values($content),
        ];

        if (empty($parameters['reply_to'])) {
            unset($parameters['reply_to']);
        } else {
            $parameters['reply_to'] = $parameters['reply_to'][0];
        }

        if ($message instanceof AttachmentsAwareInterface) {
            $attachments = $message->getAttachments();
            if (!empty($attachments)) {
                $parameters['attachments'] = $this->processAttachments($attachments);
            }
        }

        if ($message instanceof TaggableInterface) {
            $parameters['categories'] = (array) $message->getTag();
        }

        if ($message instanceof MetadataAwareInterface) {
            $metadata = array_filter($message->getMetadata());
            if (!empty($metadata)) {
                if (isset($parameters['custom_args'])) {
                    $parameters['custom_args'] = array_merge($parameters['custom_args'], $metadata);
                } else {
                    $parameters['custom_args'] = $metadata;
                }
            }
        }

        return json_encode($parameters);
    }
{@inheritdoc}