Exemplo n.º 1
0
 /**
  * Method used to send emails directly from the sender to the
  * recipient. This will not re-write the sender's email address
  * to issue-xxxx@ or whatever.
  *
  * @param   integer $issue_id The issue ID
  * @param   string $from The sender of this message
  * @param   string $to The primary recipient of this message
  * @param   string $cc The extra recipients of this message
  * @param   string $subject The subject of this message
  * @param   string $body The message body
  * @param   string $message_id The message-id
  * @param   integer $sender_usr_id The ID of the user sending this message.
  * @param   array $attachment An array with attachment information.
  * @return  void
  */
 public function sendDirectEmail($issue_id, $from, $to, $cc, $subject, $body, $attachment, $message_id, $sender_usr_id = false)
 {
     $prj_id = Issue::getProjectID($issue_id);
     $subject = Mail_Helper::formatSubject($issue_id, $subject);
     $recipients = self::getRecipientsCC($cc);
     $recipients[] = $to;
     // send the emails now, one at a time
     foreach ($recipients as $recipient) {
         $mail = new Mail_Helper();
         if (!empty($issue_id)) {
             // add the warning message to the current message' body, if needed
             $fixed_body = Mail_Helper::addWarningMessage($issue_id, $recipient, $body, array());
             $mail->setHeaders(array('Message-Id' => $message_id));
             // skip users who don't have access to this issue (but allow non-users and users without access to this project) to get emails
             $recipient_usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($recipient), true);
             if (!empty($recipient_usr_id) && (!Issue::canAccess($issue_id, $recipient_usr_id) && User::getRoleByUser($recipient_usr_id, $prj_id) != null) || empty($recipient_usr_id) && Issue::isPrivate($issue_id)) {
                 continue;
             }
         } else {
             $fixed_body = $body;
         }
         if (User::getRoleByUser(User::getUserIDByEmail(Mail_Helper::getEmailAddress($from)), Issue::getProjectID($issue_id)) == User::getRoleID('Customer')) {
             $type = 'customer_email';
         } else {
             $type = 'other_email';
         }
         if ($attachment && !empty($attachment['name'][0])) {
             $mail->addAttachment($attachment['name'][0], file_get_contents($attachment['tmp_name'][0]), $attachment['type'][0]);
         }
         $mail->setTextBody($fixed_body);
         $mail->send($from, $recipient, $subject, true, $issue_id, $type, $sender_usr_id);
     }
 }