protected static function prepareHeaders(Swift_Mime_Message $message, $mailjetHeaders)
    {
        $messageHeaders = $message->getHeaders();

        $mailjetData = [];

        foreach (array_keys($mailjetHeaders) as $headerName) {
            /** @var \Swift_Mime_Headers_UnstructuredHeader $value */
            if (null !== $value = $messageHeaders->get($headerName)) {
                // Handle custom headers
                if($headerName == "X-MJ-Vars" && is_string($value->getValue())){
                    $mailjetData[$mailjetHeaders[$headerName]] = json_decode($value->getValue());
                } else {
                    $mailjetData[$mailjetHeaders[$headerName]] = $value->getValue();
                }
                // remove Mailjet specific headers
                $messageHeaders->removeAll($headerName);
            }
        }

        return $mailjetData;
    }