skip url from IDS check
[civicrm-core.git] / CRM / Utils / Mail.php
index 7986f84eacdfc50239475a9590269556757f49c7..57453a0ca51c4da1996ceeec9e0b71c952c82f24 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,9 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 class CRM_Utils_Mail {
 
@@ -45,9 +43,7 @@ class CRM_Utils_Mail {
    * @return Mail
    */
   public static function createMailer() {
-    $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
-      'mailing_backend'
-    );
+    $mailingInfo = Civi::settings()->get('mailing_backend');
 
     if ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB ||
       (defined('CIVICRM_MAILER_SPOOL') && CIVICRM_MAILER_SPOOL)
@@ -130,7 +126,7 @@ class CRM_Utils_Mail {
     else {
       $mailer = Mail::factory($driver, $params);
     }
-    CRM_Utils_Hook::alterMail($mailer, $driver, $params);
+    CRM_Utils_Hook::alterMailer($mailer, $driver, $params);
     return $mailer;
   }
 
@@ -159,14 +155,13 @@ class CRM_Utils_Mail {
    *   TRUE if a mail was sent, else FALSE.
    */
   public static function send(&$params) {
-    $returnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
+    $defaultReturnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
     $includeMessageId = CRM_Core_BAO_MailSettings::includeMessageId();
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     $from = CRM_Utils_Array::value('from', $params);
-    if (!$returnPath) {
-      $returnPath = self::pluckEmailFromHeader($from);
+    if (!$defaultReturnPath) {
+      $defaultReturnPath = self::pluckEmailFromHeader($from);
     }
-    $params['returnPath'] = $returnPath;
 
     // first call the mail alter hook
     CRM_Utils_Hook::alterMailParams($params);
@@ -202,10 +197,10 @@ class CRM_Utils_Mail {
     $headers['Content-Type'] = $htmlMessage ? 'multipart/mixed; charset=utf-8' : 'text/plain; charset=utf-8';
     $headers['Content-Disposition'] = 'inline';
     $headers['Content-Transfer-Encoding'] = '8bit';
-    $headers['Return-Path'] = CRM_Utils_Array::value('returnPath', $params);
+    $headers['Return-Path'] = CRM_Utils_Array::value('returnPath', $params, $defaultReturnPath);
 
     // CRM-11295: Omit reply-to headers if empty; this avoids issues with overzealous mailservers
-    $replyTo = CRM_Utils_Array::value('replyTo', $params, $from);
+    $replyTo = CRM_Utils_Array::value('replyTo', $params, CRM_Utils_Array::value('from', $params));
 
     if (!empty($replyTo)) {
       $headers['Reply-To'] = $replyTo;
@@ -218,7 +213,7 @@ class CRM_Utils_Mail {
       $headers['Auto-Submitted'] = "Auto-Generated";
     }
 
-    //make sure we has to have space, CRM-6977
+    // make sure we has to have space, CRM-6977
     foreach (array('From', 'To', 'Cc', 'Bcc', 'Reply-To', 'Return-Path') as $fld) {
       if (isset($headers[$fld])) {
         $headers[$fld] = str_replace('"<', '" <', $headers[$fld]);
@@ -265,8 +260,8 @@ class CRM_Utils_Mail {
     // 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.
+      // get emails from headers, since these are
+      // combination of name and email addresses.
       if (!empty($headers['Cc'])) {
         $to[] = CRM_Utils_Array::value('Cc', $headers);
       }
@@ -377,9 +372,7 @@ class CRM_Utils_Mail {
    *   TRUE if valid outBound email configuration found, false otherwise.
    */
   public static function validOutBoundMail() {
-    $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
-      'mailing_backend'
-    );
+    $mailingInfo = Civi::settings()->get('mailing_backend');
     if ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MAIL) {
       return TRUE;
     }
@@ -471,6 +464,10 @@ class CRM_Utils_Mail {
    * and if so does the needful and return the formatted name
    *
    * This code has been copied and adapted from ezc/Mail/src/tools.php
+   *
+   * @param string $name
+   *
+   * @return string
    */
   public static function formatRFC2822Name($name) {
     $name = trim($name);
@@ -499,10 +496,10 @@ class CRM_Utils_Mail {
   public static function appendPDF($fileName, $html, $format = NULL) {
     $pdf_filename = CRM_Core_Config::singleton()->templateCompileDir . CRM_Utils_File::makeFileName($fileName);
 
-    //FIXME : CRM-7894
-    //xmlns attribute is required in XHTML but it is invalid in HTML,
-    //Also the namespace "xmlns=http://www.w3.org/1999/xhtml" is default,
-    //and will be added to the <html> tag even if you do not include it.
+    // FIXME : CRM-7894
+    // xmlns attribute is required in XHTML but it is invalid in HTML,
+    // Also the namespace "xmlns=http://www.w3.org/1999/xhtml" is default,
+    // and will be added to the <html> tag even if you do not include it.
     $html = preg_replace('/(<html)(.+?xmlns=["\'].[^\s]+["\'])(.+)?(>)/', '\1\3\4', $html);
 
     file_put_contents($pdf_filename, CRM_Utils_PDF_Utils::html2pdf($html,