Пример #1
0
 /**
  * Method used to get the name portion of a given recipient information.
  *
  * @access  public
  * @param   string $address The email address value
  * @param   boolean $multiple If multiple addresses should be returned
  * @return  mixed The name or an array of names if multiple is true
  */
 function getName($address, $multiple = false)
 {
     $info = Mail_API::getAddressInfo($address, true);
     $returns = array();
     foreach ($info as $row) {
         if (!empty($row['sender_name'])) {
             $returns[] = Mime_Helper::fixEncoding($row['sender_name']);
         } else {
             $returns[] = $row['email'];
         }
     }
     if ($multiple) {
         return $returns;
     } else {
         return $returns[0];
     }
 }
Пример #2
0
 /**
  * Method used to build a properly encoded email address that will be
  * used by the email/note routing system.
  *
  * @access  public
  * @param   integer $issue_id The issue ID
  * @param   string $sender The email address of the sender
  * @param   string $type Whether this is a note or email routing message
  * @return  string The properly encoded email address
  */
 function getFixedFromHeader($issue_id, $sender, $type)
 {
     $setup = Setup::load();
     if ($type == 'issue') {
         $routing = 'email_routing';
     } else {
         $routing = 'note_routing';
     }
     $project_id = Issue::getProjectID($issue_id);
     // if sender is empty, get project email address
     if (empty($sender)) {
         $project_info = Project::getOutgoingSenderAddress($project_id);
         $info = array("sender_name" => $project_info['name'], 'email' => $project_info['email']);
         // if no project name, use eventum wide sender name
         if (empty($info['sender_name'])) {
             $setup_sender_info = Mail_API::getAddressInfo($setup['smtp']['from']);
             $info['sender_name'] = $setup_sender_info['sender_name'];
         }
     } else {
         $info = Mail_API::getAddressInfo($sender);
     }
     // allow flags even without routing enabled
     if (!empty($setup[$routing]['recipient_type_flag'])) {
         $flag = '[' . $setup[$routing]['recipient_type_flag'] . '] ';
     } else {
         $flag = '';
     }
     if (@$setup[$routing]['status'] != 'enabled') {
         // let's use the custom outgoing sender address
         $project_info = Project::getOutgoingSenderAddress($project_id);
         if (empty($project_info['email'])) {
             /// no project email, use main email address
             $from_email = $setup['smtp']['from'];
         } else {
             $from_email = $project_info['email'];
         }
     } else {
         $from_email = $setup[$routing]['address_prefix'] . $issue_id . "@" . $setup[$routing]['address_host'];
     }
     if (empty($info['sender_name'])) {
         // no sender name, check if this email address belongs to a user and if so use that
         $usr_id = User::getUserIDByEmail($info['email']);
         if (!empty($usr_id)) {
             $info['sender_name'] = User::getFullName($usr_id);
         } else {
             // no name exists, use email address for name as well
             $info['sender_name'] = $info['email'];
         }
     }
     // also check where we need to append/prepend a special string to the sender name
     if (substr($info['sender_name'], strlen($info['sender_name']) - 1) == '"') {
         if (@$setup[$routing]['flag_location'] == 'before') {
             $info['sender_name'] = '"' . $flag . substr($info['sender_name'], 1);
         } else {
             $info['sender_name'] = substr($info['sender_name'], 0, strlen($info['sender_name']) - 1) . ' ' . trim($flag) . '"';
         }
     } else {
         if (@$setup[$routing]['flag_location'] == 'before') {
             $info['sender_name'] = '"' . $flag . $info['sender_name'] . '"';
         } else {
             $info['sender_name'] = '"' . $info['sender_name'] . ' ' . trim($flag) . '"';
         }
     }
     $from = Mail_API::getFormattedName($info['sender_name'], $from_email);
     return MIME_Helper::encodeAddress(trim($from));
 }