Updated the timeout to 500ms.
[civicrm-core.git] / CRM / Utils / Mail.php
index 1328521d738119ff92f49898ef3f4764e12501bf..32a55757078d4388cf684d1d59ca7289f83e25e5 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  */
 class CRM_Utils_Mail {
 
@@ -577,4 +577,26 @@ class CRM_Utils_Mail {
     return $formattedEmail;
   }
 
+  /**
+   * When passed a value, returns the value if it's non-numeric.
+   * If it's numeric, look up the display name and email of the corresponding
+   * contact ID in RFC822 format.
+   *
+   * @param string $from
+   *   contact ID or formatted "From address", eg. 12 or "Fred Bloggs" <fred@example.org>
+   * @return string
+   *   The RFC822-formatted email header (display name + address)
+   */
+  public static function formatFromAddress($from) {
+    if (is_numeric($from)) {
+      $result = civicrm_api3('Email', 'get', [
+        'id' => $from,
+        'return' => ['contact_id.display_name', 'email'],
+        'sequential' => 1,
+      ])['values'][0];
+      $from = '"' . $result['contact_id.display_name'] . '" <' . $result['email'] . '>';
+    }
+    return $from;
+  }
+
 }