/**
  * Build Mandrill compatible message array from email entity
  *
  * Documentation at https://mandrillapp.com/api/docs/messages.php.html
  *
  * @param  EmailEntity  $emails
  * @return array
  */
 protected function buildMessage(EmailEntity $email)
 {
     // Create attachments array
     $attachments = json_decode($email->getAttachments(), true);
     $recipientEmail = $email->getRecipientEmail();
     $to = [['email' => $this->filterThroughWhitelist($recipientEmail), 'name' => $email->getRecipientName(), 'type' => 'to']];
     $message = ['html' => $email->getMessage(), 'subject' => $email->getSubject(), 'from_email' => $email->getSenderEmail(), 'from_name' => $email->getSenderName(), 'to' => $to, 'attachments' => $attachments, 'headers' => json_decode($email->getHeaders(), true), 'important' => false, 'track_opens' => true, 'track_clicks' => true, 'auto_text' => true, 'auto_html' => false, 'inline_css' => true, 'url_strip_qs' => null, 'preserve_recipients' => false, 'bcc_address' => $email->getBcc(), 'merge' => true];
     return $message;
 }
 /**
  * Build Mailgun compatible message array from email entity
  *
  * Documentation at https://mandrillapp.com/api/docs/messages.php.html
  *
  * @param  EmailEntity  $emails
  * @return array
  */
 protected function buildMessage(EmailEntity $email)
 {
     // Create attachments array
     $attachments = json_decode($email->getAttachments(), true) ?: [];
     // Convert Mandrill format to Mailgun format
     $attachments = array_map(function ($attachment) {
         if (isset($attachment['content'])) {
             $attachment['data'] = base64_decode(Arr::remove($attachment, 'content'));
         }
         if (isset($attachment['name'])) {
             $attachment['filename'] = Arr::remove($attachment, 'name');
         }
         if (isset($attachment['type'])) {
             $attachment['contentType'] = Arr::remove($attachment, 'type');
         }
         return attachment;
     }, $attachments);
     if ($email->getSenderName()) {
         $from = "{$email->getSenderName()} <{$email->getSenderEmail()}>";
     } else {
         $from = $email->getSenderEmail();
     }
     if ($email->getTemplateName()) {
         $html = $this->templateService->renderHbsForEmail($email->getTemplateName(), $email->getTemplateData() ? json_decode($email->getTemplateData(), true) : []);
     } else {
         $html = $email->getMessage();
     }
     $message = ['html' => $html, 'subject' => $email->getSubject(), 'from' => $from, 'to' => $this->filterThroughWhitelist($email->getRecipientEmail()), 'attachments' => $attachments];
     if ($email->getHeaders()) {
         $headers = [];
         foreach (json_decode($email->getHeaders(), true) as $key => $value) {
             $headers["h:{$key}"] = $value;
         }
         $message['headers'] = $headers;
     }
     return $message;
 }