Merge pull request #4939 from colemanw/CRM-15789
[civicrm-core.git] / CRM / Utils / Mail.php
index 86cdf330a3386f65d1865c4ca0ac93387cac8f86..d076c10732af2ff69d17e84f04bb9878ab02f2f6 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -52,17 +52,17 @@ class CRM_Utils_Mail {
    *   mime_type: mime type of the attachment
    *   cleanName: the user friendly name of the attachmment
    *
-   * @param array $params (by reference)
-   *
-   * @access public
+   * @param array $params
+   *   (by reference).
    *
-   * @return boolean true if a mail was sent, else false
+   * @return boolean
+   *   true if a mail was sent, else false
    */
-  static function send(&$params) {
-    $returnPath       = CRM_Core_BAO_MailSettings::defaultReturnPath();
+  public static function send(&$params) {
+    $returnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
     $includeMessageId = CRM_Core_BAO_MailSettings::includeMessageId();
-    $emailDomain      = CRM_Core_BAO_MailSettings::defaultDomain();
-    $from             = CRM_Utils_Array::value('from', $params);
+    $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
+    $from = CRM_Utils_Array::value('from', $params);
     if (!$returnPath) {
       $returnPath = self::pluckEmailFromHeader($from);
     }
@@ -85,13 +85,13 @@ class CRM_Utils_Mail {
       $htmlMessage = FALSE;
     }
 
-    $headers         = array();
+    $headers = array();
     // CRM-10699 support custom email headers
     if (!empty($params['headers'])) {
       $headers = array_merge($headers, $params['headers']);
     }
     $headers['From'] = $params['from'];
-    $headers['To']   =
+    $headers['To'] =
       self::formatRFC822Email(
         CRM_Utils_Array::value('toName', $params),
         CRM_Utils_Array::value('toEmail', $params),
@@ -160,20 +160,20 @@ class CRM_Utils_Mail {
     $headers = &$msg->headers($headers);
 
     $to = array($params['toEmail']);
-    $result = null;
-    $mailer =& CRM_Core_Config::getMailer( );
+    $result = NULL;
+    $mailer =& CRM_Core_Config::getMailer();
 
     // Mail_smtp and Mail_sendmail mailers require Bcc anc Cc emails
     // be included in both $to and $headers['Cc', 'Bcc']
     if (get_class($mailer) != "Mail_mail") {
-        //get emails from headers, since these are
-        //combination of name and email addresses.
-        if (!empty($headers['Cc'])) {
-            $to[] = CRM_Utils_Array::value( 'Cc', $headers );
-        }
-        if (!empty($headers['Bcc'])) {
-            $to[] = CRM_Utils_Array::value( 'Bcc', $headers );
-        }
+      //get emails from headers, since these are
+      //combination of name and email addresses.
+      if (!empty($headers['Cc'])) {
+        $to[] = CRM_Utils_Array::value('Cc', $headers);
+      }
+      if (!empty($headers['Bcc'])) {
+        $to[] = CRM_Utils_Array::value('Bcc', $headers);
+      }
     }
     if (is_object($mailer)) {
       $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
@@ -198,9 +198,10 @@ class CRM_Utils_Mail {
    *
    * @return string
    */
-  static function errorMessage($mailer, $result) {
+  public static function errorMessage($mailer, $result) {
     $message = '<p>' . ts('An error occurred when CiviCRM attempted to send an email (via %1). If you received this error after submitting on online contribution or event registration - the transaction was completed, but we were unable to send the email receipt.', array(
-      1 => 'SMTP')) . '</p>' . '<p>' . ts('The mail library returned the following error message:') . '<br /><span class="font-red"><strong>' . $result->getMessage() . '</strong></span></p>' . '<p>' . ts('This is probably related to a problem in your Outbound Email Settings (Administer CiviCRM &raquo; System Settings &raquo; Outbound Email), OR the FROM email address specifically configured for your contribution page or event. Possible causes are:') . '</p>';
+        1 => 'SMTP'
+      )) . '</p>' . '<p>' . ts('The mail library returned the following error message:') . '<br /><span class="font-red"><strong>' . $result->getMessage() . '</strong></span></p>' . '<p>' . ts('This is probably related to a problem in your Outbound Email Settings (Administer CiviCRM &raquo; System Settings &raquo; Outbound Email), OR the FROM email address specifically configured for your contribution page or event. Possible causes are:') . '</p>';
 
     if (is_a($mailer, 'Mail_smtp')) {
       $message .= '<ul>' . '<li>' . ts('Your SMTP Username or Password are incorrect.') . '</li>' . '<li>' . ts('Your SMTP Server (machine) name is incorrect.') . '</li>' . '<li>' . ts('You need to use a Port other than the default port 25 in your environment.') . '</li>' . '<li>' . ts('Your SMTP server is just not responding right now (it is down for some reason).') . '</li>';
@@ -210,7 +211,8 @@ class CRM_Utils_Mail {
     }
 
     $message .= '<li>' . ts('The FROM Email Address configured for this feature may not be a valid sender based on your email service provider rules.') . '</li>' . '</ul>' . '<p>' . ts('Check <a href="%1">this page</a> for more information.', array(
-      1 => CRM_Utils_System::docURL2('user/advanced-configuration/email-system-configuration', TRUE))) . '</p>';
+        1 => CRM_Utils_System::docURL2('user/advanced-configuration/email-system-configuration', TRUE)
+      )) . '</p>';
 
     return $message;
   }
@@ -220,7 +222,7 @@ class CRM_Utils_Mail {
    * @param $headers
    * @param $message
    */
-  static function logger(&$to, &$headers, &$message) {
+  public static function logger(&$to, &$headers, &$message) {
     if (is_array($to)) {
       $toString = implode(', ', $to);
       $fileName = $to[0];
@@ -254,12 +256,13 @@ class CRM_Utils_Mail {
    *
    * Ugly but working.
    *
-   * @param  string $header  the full name + email address string
+   * @param string $header
+   *   The full name + email address string.
    *
-   * @return string          the plucked email address
-   * @static
+   * @return string
+   *   the plucked email address
    */
-  static function pluckEmailFromHeader($header) {
+  public static function pluckEmailFromHeader($header) {
     preg_match('/<([^<]*)>$/', $header, $matches);
 
     if (isset($matches[1])) {
@@ -271,11 +274,10 @@ class CRM_Utils_Mail {
   /**
    * Get the Active outBound email
    *
-   * @return boolean true if valid outBound email configuration found, false otherwise
-   * @access public
-   * @static
+   * @return boolean
+   *   true if valid outBound email configuration found, false otherwise
    */
-  static function validOutBoundMail() {
+  public static function validOutBoundMail() {
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
       'mailing_backend'
     );
@@ -309,7 +311,7 @@ class CRM_Utils_Mail {
    *
    * @return mixed
    */
-  static function &setMimeParams(&$message, $params = NULL) {
+  public static function &setMimeParams(&$message, $params = NULL) {
     static $mimeParams = NULL;
     if (!$params) {
       if (!$mimeParams) {
@@ -333,7 +335,7 @@ class CRM_Utils_Mail {
    *
    * @return null|string
    */
-  static function formatRFC822Email($name, $email, $useQuote = FALSE) {
+  public static function formatRFC822Email($name, $email, $useQuote = FALSE) {
     $result = NULL;
 
     $name = trim($name);
@@ -371,7 +373,7 @@ class CRM_Utils_Mail {
    *
    * This code has been copied and adapted from ezc/Mail/src/tools.php
    */
-  static function formatRFC2822Name($name) {
+  public static function formatRFC2822Name($name) {
     $name = trim($name);
     if (!empty($name)) {
       // remove the quotes around the name part if they are already there
@@ -393,9 +395,9 @@ class CRM_Utils_Mail {
    * @param string $html
    * @param string $format
    *
-   * @return array $attachments
+   * @return array
    */
-  static function appendPDF($fileName, $html, $format = NULL) {
+  public static function appendPDF($fileName, $html, $format = NULL) {
     $pdf_filename = CRM_Core_Config::singleton()->templateCompileDir . CRM_Utils_File::makeFileName($fileName);
 
     //FIXME : CRM-7894
@@ -405,9 +407,9 @@ class CRM_Utils_Mail {
     $html = preg_replace('/(<html)(.+?xmlns=["\'].[^\s]+["\'])(.+)?(>)/', '\1\3\4', $html);
 
     file_put_contents($pdf_filename, CRM_Utils_PDF_Utils::html2pdf($html,
-      $fileName,
-      TRUE,
-      $format)
+        $fileName,
+        TRUE,
+        $format)
     );
     return array(
       'fullPath' => $pdf_filename,
@@ -416,4 +418,3 @@ class CRM_Utils_Mail {
     );
   }
 }
-