You are here

function simplenews_build_combined_mail in Simplenews 7.2

Same name and namespace in other branches
  1. 7 includes/simplenews.mail.inc \simplenews_build_combined_mail()

Build subject and body of the subscribe confirmation email.

Parameters

array $message: Message array as used by hook_mail().

array $params: Parameter array as used by hook_mail().

1 call to simplenews_build_combined_mail()
simplenews_mail in ./simplenews.module
Implements hook_mail().

File

includes/simplenews.mail.inc, line 857
Simplenews email send and spool handling

Code

function simplenews_build_combined_mail(&$message, $params) {
  $context = $params['context'];
  $subscriber = $context['simplenews_subscriber'];
  $langcode = $message['language'];

  // Use formatted from address "name" <mail_address>
  $message['headers']['From'] = $params['from']['formatted'];
  $message['subject'] = simplenews_subscription_confirmation_text('combined_subject', $langcode);
  $message['subject'] = token_replace($message['subject'], $context, array(
    'sanitize' => FALSE,
  ));
  $changes_list = '';
  $actual_changes = 0;
  foreach (simplenews_confirmation_get_changes_list($context['simplenews_subscriber'], $subscriber->changes, $langcode) as $newsletter_id => $change) {
    $changes_list .= ' - ' . $change . "\n";

    // Count the actual changes.
    $subscribed = simplenews_user_is_subscribed($context['simplenews_subscriber']->mail, $newsletter_id);
    if ($subscriber->changes[$newsletter_id] == 'subscribe' && !$subscribed || $subscriber->changes[$newsletter_id] == 'unsubscribe' && $subscribed) {
      $actual_changes++;
    }
  }

  // If there are actual changes, use the combined_body key otherwise use the
  // one without a confirmation link.
  $body_key = $actual_changes ? 'combined_body' : 'combined_body_unchanged';
  $body = simplenews_subscription_confirmation_text($body_key, $langcode);

  // The changes list is not an actual token.
  $body = str_replace('[changes-list]', $changes_list, $body);
  $message['body'][] = token_replace($body, $context, array(
    'sanitize' => FALSE,
  ));
}