Example #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.
  *
  * @access  public
  * @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.
  * @return  void
  */
 function sendDirectEmail($issue_id, $from, $to, $cc, $subject, $body, $message_id, $sender_usr_id = false)
 {
     $recipients = Support::getRecipientsCC($cc);
     $recipients[] = $to;
     // send the emails now, one at a time
     foreach ($recipients as $recipient) {
         $mail = new Mail_API();
         if (!empty($issue_id)) {
             // add the warning message to the current message' body, if needed
             $fixed_body = Mail_API::addWarningMessage($issue_id, $recipient, $body);
             $mail->setHeaders(array("Message-Id" => $message_id));
             // skip users who don't have access to this issue
             $recipient_usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($recipient));
             if (!empty($recipient_usr_id) && !Issue::canAccess($issue_id, $recipient_usr_id) || empty($recipient_usr_id) && Issue::isPrivate($issue_id)) {
                 continue;
             }
         } else {
             $fixed_body = $body;
         }
         if (User::getRoleByUser(User::getUserIDByEmail(Mail_API::getEmailAddress($from)), Issue::getProjectID($issue_id)) == User::getRoleID("Customer")) {
             $type = 'customer_email';
         } else {
             $type = 'other_email';
         }
         $mail->setTextBody($fixed_body);
         $mail->send($from, $recipient, $subject, TRUE, $issue_id, $type, $sender_usr_id);
     }
 }
 /**
  * Method used to send an email notification when an issue is
  * assigned to an user.
  *
  * @access  public
  * @param   array $users The list of users
  * @param   integer $issue_id The issue ID
  * @return  void
  */
 function notifyNewAssignment($users, $issue_id)
 {
     $prj_id = Issue::getProjectID($issue_id);
     $emails = array();
     for ($i = 0; $i < count($users); $i++) {
         $prefs = Prefs::get($users[$i]);
         if (!empty($prefs) && @$prefs["receive_assigned_emails"][$prj_id]) {
             $emails[] = User::getFromHeader($users[$i]);
         }
     }
     if (count($emails) == 0) {
         return false;
     }
     // get issue details
     $issue = Notification::getIssueDetails($issue_id);
     // open text template
     $tpl = new Template_API();
     $tpl->setTemplate('notifications/assigned.tpl.text');
     $tpl->bulkAssign(array("app_title" => Misc::getToolCaption(), "issue" => $issue, "current_user" => User::getFullName(Auth::getUserID())));
     $text_message = $tpl->getTemplateContents();
     for ($i = 0; $i < count($emails); $i++) {
         // send email (use PEAR's classes)
         $mail = new Mail_API();
         $mail->setTextBody($text_message);
         $mail->setHeaders(Mail_API::getBaseThreadingHeaders($issue_id));
         $mail->send(Notification::getFixedFromHeader($issue_id, '', 'issue'), $emails[$i], "[#{$issue_id}] New Assignment: " . $issue['iss_summary'], TRUE, $issue_id, 'assignment');
     }
 }