예제 #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);
     }
 }
예제 #2
0
 /**
  * Method used to send an email notification when an issue is
  * assigned to an user.
  *
  * @param   array $users The list of users
  * @param   integer $issue_id The issue ID
  */
 public static function notifyNewAssignment($users, $issue_id)
 {
     $prj_id = Issue::getProjectID($issue_id);
     $emails = array();
     foreach ($users as $usr_id) {
         if ($usr_id == Auth::getUserID()) {
             continue;
         }
         $prefs = Prefs::get($usr_id);
         if (!empty($prefs) && isset($prefs['receive_assigned_email'][$prj_id]) && $prefs['receive_assigned_email'][$prj_id] && $usr_id != Auth::getUserID()) {
             $emails[] = User::getFromHeader($usr_id);
         }
     }
     if (!$emails) {
         return;
     }
     // get issue details
     $issue = Issue::getDetails($issue_id);
     // open text template
     $tpl = new Template_Helper();
     $tpl->setTemplate('notifications/assigned.tpl.text');
     $tpl->assign(array('app_title' => Misc::getToolCaption(), 'issue' => $issue, 'current_user' => User::getFullName(Auth::getUserID())));
     foreach ($emails as $email) {
         $text_message = $tpl->getTemplateContents();
         Language::set(User::getLang(User::getUserIDByEmail(Mail_Helper::getEmailAddress($email))));
         $subject = "[#{$issue_id}] New Assignment: " . $issue['iss_summary'];
         $from = self::getFixedFromHeader($issue_id, '', 'issue');
         // send email (use PEAR's classes)
         $mail = new Mail_Helper();
         $mail->setTextBody($text_message);
         $mail->setHeaders(Mail_Helper::getBaseThreadingHeaders($issue_id));
         $mail->send($from, $email, $subject, true, $issue_id, 'assignment');
     }
     Language::restore();
 }