if (!$this->templates) {
$this->getHeaderFooter();
$this->templates = array();
- if ($this->body_text) {
+ if ($this->body_text || !empty($this->header)) {
$template = array();
if (!empty($this->header->body_text)) {
$template[] = $this->header->body_text;
$template[] = CRM_Utils_String::htmlToText($this->header->body_html);
}
- $template[] = $this->body_text;
+ if ($this->body_text) {
+ $template[] = $this->body_text;
+ }
+ else {
+ $template[] = CRM_Utils_String::htmlToText($this->body_html);
+ }
if (!empty($this->footer->body_text)) {
$template[] = $this->footer->body_text;
$this->templates['html'] = implode("\n", $template);
+ // this is where we create a text template from the html template if the text template did not exist
+ // this way we ensure that every recipient will receive an email even if the pref is set to text and the
+ // user uploads an html email only
+ if (empty($this->templates['text'])) {
+ $this->templates['text'] = CRM_Utils_String::htmlToText($this->templates['html']);
+ }
}
if ($this->subject) {
array_push($pEmail, $template[($idx + 1)]);
}
}
+
$html = NULL;
if (isset($pEmails['html']) && is_array($pEmails['html']) && count($pEmails['html'])) {
$html = &$pEmails['html'];
}
$mailParams = $headers;
-
- // If we should be sending a text version of the email
- if (($test || $contact['preferred_mail_format'] == 'Text' ||
+ if ($text && ($test || $contact['preferred_mail_format'] == 'Text' ||
$contact['preferred_mail_format'] == 'Both' ||
($contact['preferred_mail_format'] == 'HTML' && !array_key_exists('html', $pEmails))
)
) {
-
- // The following if elseif allows us to ensure that people who have a
- // preference for text emails will get one even when the person composing
- // the email has not uploaded a text version.
-
- if ($text) {
- // If the text version exists, use it
- $textBody = implode('', $text);
- }
- elseif ($html) {
- // Else if it doesn't exist and the html version exists, use it
- $textBody = implode('', $html);
- $textBody = htmlspecialchars_decode(htmlspecialchars_decode($textBody)); // Some &s have become 'really encoded'
- $textBody = CRM_Utils_String::htmlToText($textBody);
- }
-
+ $textBody = implode('', $text);
if ($useSmarty) {
$textBody = $smarty->fetch("string:$textBody");
}
-
$mailParams['text'] = $textBody;
}
$res = NULL;
return $res;
}
+
$mailParams['attachments'] = $attachments;
$mailParams['Subject'] = CRM_Utils_Array::value('subject', $pEmails);
";" .
"Sample Header for TEXT formatted content.\n" . // Default header
"BEWARE children need regular infusions of toys. Santa knows your .*\\. There is no http.*civicrm/mailing/optout.*\\.\n" .
- "Unsubscribe: http.*civicrm/mailing/optout" . // Default footer
+ "to unsubscribe: http.*civicrm/mailing/optout" . // Default footer
";",
$message->body->text
);
$this->assertEquals('html', $htmlPart->subType);
$this->assertRegExp(
";" .
- "<p>Sample Header for HTML formatted content\.</p>.*" . // Default header
+ "Sample Header for HTML formatted content.\n" . // Default header
// FIXME: CiviMail puts double " after hyperlink!
- "<p>You can go to <a href=\"http://example.net/first\\?cs=[0-9a-f_]+\"\"?>Google</a> or <a href=\"http.*civicrm/mailing/optout.*\">opt out</a>.</p>.*" . // body_html
- "<p>Sample Footer for HTML formatted content\.</p>.*" . // Default footer
+ "<p>You can go to <a href=\"http://example.net/first\\?cs=[0-9a-f_]+\"\"?>Google</a> or <a href=\"http.*civicrm/mailing/optout.*\">opt out</a>.</p>\n" . // body_html
+ "Sample Footer for HTML formatted content" . // Default footer
+ ".*\n" .
"<img src=\".*extern/open.php.*\"" .
- ";s",
+ ";",
$htmlPart->text
);
+
$this->assertEquals('plain', $textPart->subType);
$this->assertRegExp(
";" .
- "Sample Header for HTML formatted content\\..*" . // Default header (converted from HTML as it was not supplied)
- "You can go to Google \\[1\\] or opt out \\[2\\]\\..*" . // Text body (converted from HTML as it was not supplied)
- "Sample Footer for HTML formatted content\..*" . // Footer footer (converted from HTML as it was not supplied)
- "Unsubscribe \\[2\\]\\..*" . // Text body (converted from HTML as it was not supplied)
- "Links:.*" .
- "------.*" .
- "\\[1\\] http://example.net/first\\?cs=[0-9a-f_]+.*" .
- "\\[2\\] http.*civicrm/mailing/optout.*" .
- ";s",
+ "Sample Header for TEXT formatted content.\n" . // Default header
+ "You can go to Google \\[1\\] or opt out \\[2\\]\\.\n" . // body_html, filtered
+ "\n" .
+ "Links:\n" .
+ "------\n" .
+ "\\[1\\] http://example.net/first\\?cs=[0-9a-f_]+\n" .
+ "\\[2\\] http.*civicrm/mailing/optout.*\n" .
+ "\n" .
+ "to unsubscribe: http.*civicrm/mailing/optout" . // Default footer
+ ";",
$textPart->text
);
}
"<p>You can go to <a href=['\"].*extern/url\.php\?u=\d+&\\;qid=\d+['\"]>Google</a>" .
" or <a href=\"http.*civicrm/mailing/optout.*\">opt out</a>.</p>\n" .
// Default footer
- "<p>Sample Footer for HTML formatted content\.</p>" .
+ "Sample Footer for HTML formatted content" .
".*\n" .
// Open-tracking code
"<img src=\".*extern/open.php.*\"" .
";",
$htmlPart->text
);
+
$this->assertEquals('plain', $textPart->subType);
$this->assertRegExp(
";" .
- "You can go to Google \\[1\\] or opt out \\[2\\]\\..*" .
- "Unsubscribe \\[2\\].*" .
+ // body_html, filtered
+ "You can go to Google \\[1\\] or opt out \\[2\\]\\.\n" .
+ "\n" .
"Links:\n" .
"------\n" .
- "\\[1\\] .*extern/url\.php\?u=\d+&qid=\d+.*" .
- "\\[2\\] http.*civicrm/mailing/optout.*" .
- ";s",
+ "\\[1\\] .*extern/url\.php\?u=\d+&qid=\d+\n" .
+ "\\[2\\] http.*civicrm/mailing/optout.*\n" .
+ "\n" .
+ // Default footer
+ "to unsubscribe: http.*civicrm/mailing/optout" .
+ ";",
$textPart->text
);
}
array('url_tracking' => 1),
);
$cases[] = array(
- // Plain-text URLs are not tracked.
+ // Plain-text URL's are tracked in plain-text emails...
+ // but not in HTML emails.
"<p>Please go to: http://example.net/</p>",
";<p>Please go to: http://example\.net/</p>;",
- ';Please go to: http://example\.net/;',
+ ';Please go to: .*extern/url.php\?u=\d+&qid=\d+;',
array('url_tracking' => 1),
);
INSERT INTO civicrm_mailing_component
(name,component_type,subject,body_html,body_text,is_default,is_active)
VALUES
- ('{ts escape="sql"}Mailing Header{/ts}','Header','{ts escape="sql"}Descriptive Title for this Header{/ts}','{ts escape="sql"}<p>Sample Header for HTML formatted content.</p>{/ts}','{ts escape="sql"}Sample Header for TEXT formatted content.{/ts}',1,1),
- ('{ts escape="sql"}Mailing Footer{/ts}','Footer','{ts escape="sql"}Descriptive Title for this Footer.{/ts}','{ts escape="sql"}<p>Sample Footer for HTML formatted content.</p><p><a href="{ldelim}action.optOutUrl{rdelim}">Unsubscribe</a>.</p><p>{ldelim}domain.address{rdelim}</p>{/ts}','{ts escape="sql"}Unsubscribe: {ldelim}action.optOutUrl{rdelim}{"\n"}{ldelim}domain.address{rdelim}.{/ts}',1,1),
+ ('{ts escape="sql"}Mailing Header{/ts}','Header','{ts escape="sql"}Descriptive Title for this Header{/ts}','{ts escape="sql"}Sample Header for HTML formatted content.{/ts}','{ts escape="sql"}Sample Header for TEXT formatted content.{/ts}',1,1),
+ ('{ts escape="sql"}Mailing Footer{/ts}','Footer','{ts escape="sql"}Descriptive Title for this Footer.{/ts}','{ts escape="sql"}Sample Footer for HTML formatted content<br/><a href="{ldelim}action.optOutUrl{rdelim}">Unsubscribe</a> <br/> {ldelim}domain.address{rdelim}{/ts}','{ts escape="sql"}to unsubscribe: {ldelim}action.optOutUrl{rdelim}
+{ldelim}domain.address{rdelim}{/ts}',1,1),
('{ts escape="sql"}Subscribe Message{/ts}','Subscribe','{ts escape="sql"}Subscription Confirmation Request{/ts}','{ts escape="sql" 1=$subgroup 2=$suburl}You have a pending subscription to the %1 mailing list. To confirm this subscription, reply to this email or click <a href="%2">here</a>.{/ts}','{ts escape="sql" 1=$subgroup 2=$suburl}You have a pending subscription to the %1 mailing list. To confirm this subscription, reply to this email or click on this link: %2{/ts}',1,1),
('{ts escape="sql"}Welcome Message{/ts}','Welcome','{ts escape="sql"}Your Subscription has been Activated{/ts}','{ts escape="sql" 1=$welgroup}Welcome. Your subscription to the %1 mailing list has been activated.{/ts}','{ts escape="sql" 1=$welgroup}Welcome. Your subscription to the %1 mailing list has been activated.{/ts}',1,1),
('{ts escape="sql"}Unsubscribe Message{/ts}','Unsubscribe','{ts escape="sql"}Un-subscribe Confirmation{/ts}','{ts escape="sql" 1=$unsubgroup 2=$actresub 3=$actresuburl}You have been un-subscribed from the following groups: %1. You can re-subscribe by mailing %2 or clicking <a href="%3">here</a>.{/ts}','{ts escape="sql" 1=$unsubgroup 2=$actresub}You have been un-subscribed from the following groups: %1. You can re-subscribe by mailing %2 or clicking %3{/ts}',1,1),