/**
  * Generate email HTML body using the email template and mailing data
  *
  * @param $params
  *
  * @return string
  */
 protected static function generateEmailHtml($params)
 {
     // Setup paths
     $templateFile = static::getEmailTemplatePath();
     // Setup template variables
     $template = new stdClass();
     $template->title = empty($params['title']) ? NULL : $params['title'];
     $template->replyAddress = static::getMailToLink($params);
     $template->body = empty($params['body']) ? NULL : $params['body'];
     $twoColumn = new CRM_Simplemail_BAO_TwoColumn();
     $template->isTwoColumn = $twoColumn->isTwoColumn($template->body);
     if ($template->isTwoColumn) {
         list($bodyColumn1, $bodyColumn2) = $twoColumn->getColumns($template->body);
         $template->bodyColumn1 = $bodyColumn1;
         $template->bodyColumn2 = $bodyColumn2;
     }
     if (!empty($params['social_link'])) {
         $template->facebookUrl = static::getOptionValue('email_social_facebook_links', $params['social_link']);
         $template->twitterUrl = static::getOptionValue('email_social_twitter_links', $params['social_link']);
     }
     static::updateSignature($template->body);
     $template->contactDetails = isset($params['contact_details']) && $params['contact_details'] ? $params['contact_details'] : NULL;
     // TODO (robin): Make this dynamic as useful when testing on a dev box
     $template->unsubscribeLink = static::getOptOutLink();
     // Retrieve header if the mailing has one, and assign header and logo images in the template accordingly
     if (isset($params['header_id'])) {
         $header = new CRM_Simplemail_BAO_SimpleMailHeader();
         $header->id = (int) $params['header_id'];
         // TODO (robin): Change this to the form if ($header->find(TRUE) { ... } and test
         $header->find();
         if ($header->fetch()) {
             $template->headerImage = $header->image ? CRM_Simplemail_BAO_SimpleMailHeader::getImageUrl($header->image, 'image') : NULL;
             $template->logo = $header->show_logo && $header->logo_image ? CRM_Simplemail_BAO_SimpleMailHeader::getImageUrl($header->logo_image, 'logo_image') : NULL;
         }
     }
     // Retrieve campaign message if the mailing has one, and assign campaign text in the template accordingly
     if (isset($params['message_id'])) {
         $message = new CRM_Simplemail_BAO_SimpleMailMessage();
         $message->id = (int) $params['message_id'];
         // TODO (robin): Change this to the form if ($header->find(TRUE) { ... } and test
         $message->find();
         if ($message->fetch()) {
             $template->campaignMessage = $message->text ?: NULL;
         }
     }
     // Output parsed template
     ob_start();
     require $templateFile;
     $emailBody = ob_get_clean();
     ob_end_clean();
     return $emailBody;
 }
/**
 * SimpleMailHeader.DeleteImage API
 *
 * @param array $params
 *
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_simple_mail_header_deleteimage($params)
{
    try {
        CRM_Simplemail_BAO_SimpleMailHeader::deleteImage($params);
        return civicrm_api3_create_success();
    } catch (CRM_Extension_Exception $e) {
        return civicrm_api3_create_error($e->getMessage());
    }
}