protected function format(MessageInterface $message)
    {
        $headers = array_filter(array_merge(
            $message->getHeaders(),
            ['Reply-To' => $message->getReplyTo()]
        ));

        $from = $this->normalizeIdentity($message->getFrom());

        $to = [];
        foreach ($this->normalizeIdentities($message->getTo()) as $recipient) {
            $to[] = ['email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'to'];
        }

        foreach ($this->normalizeIdentities($message->getCc()) as $recipient) {
            $to[] = ['email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'cc'];
        }

        foreach ($this->normalizeIdentities($message->getBcc()) as $recipient) {
            $to[] = ['email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'bcc'];
        }

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

        $metadata = [];
        if ($message instanceof MetadataAwareInterface) {
            $metadata = array_filter($message->getMetadata());
        }

        $images = [];
        $attachments = [];
        if ($message instanceof AttachmentsAwareInterface) {
            list($attachments, $images) = $this->processAttachments($message->getAttachments());
        }

        $parameters = [
            'key'     => $this->getServerToken(),
            'message' => array_filter([
                'from_email'  => $from->getEmail(),
                'from_name'   => $from->getName(),
                'to'          => $to,
                'subject'     => $message->getSubject(),
                'headers'     => $headers,
                'text'        => $message->getText(),
                'html'        => $message->getHtml(),
                'tags'        => $tags,
                'metadata'    => $metadata,
                'attachments' => $attachments,
                'images'      => $images,
            ]),
        ];

        if ($this->subaccount) {
            $parameters['message']['subaccount'] = $this->subaccount;
        }

        return json_encode($parameters);
    }
protected function format(MessageInterface $message)
    {
        $headers = array_filter(array_merge(
            $message->getHeaders(),
            ['Reply-To' => $message->getReplyTo()]
        ));

        $from = $this->normalizeIdentity($message->getFrom());

        $to = [];
        foreach ($this->normalizeIdentities($message->getTo()) as $recipient) {
            $to[] = ['email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'to'];
        }

        foreach ($this->normalizeIdentities($message->getCc()) as $recipient) {
            $to[] = ['email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'cc'];
        }

        foreach ($this->normalizeIdentities($message->getBcc()) as $recipient) {
            $to[] = ['email' => $recipient->getEmail(), 'name' => $recipient->getName(), 'type' => 'bcc'];
        }

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

        $metadata = [];
        if ($message instanceof MetadataAwareInterface) {
            $metadata = array_filter($message->getMetadata());
        }

        $images = [];
        $attachments = [];
        if ($message instanceof AttachmentsAwareInterface) {
            list($attachments, $images) = $this->processAttachments($message->getAttachments());
        }

        $parameters = [
            'key'     => $this->getServerToken(),
            'message' => array_filter([
                'from_email'  => $from->getEmail(),
                'from_name'   => $from->getName(),
                'to'          => $to,
                'subject'     => $message->getSubject(),
                'headers'     => $headers,
                'text'        => $message->getText(),
                'html'        => $message->getHtml(),
                'tags'        => $tags,
                'metadata'    => $metadata,
                'attachments' => $attachments,
                'images'      => $images,
            ]),
        ];

        if ($this->subaccount) {
            $parameters['message']['subaccount'] = $this->subaccount;
        }

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