Exemplo n.º 1
0
 /**
  * Method used to build the headers of a web-based message.
  *
  * @param   integer $issue_id The issue ID
  * @param   string $message_id The message-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 $body The message body
  * @param   string $in_reply_to The message-id that we are replying to
  * @param   array $iaf_ids Array with attachment file id-s
  * @return  string The full email
  */
 public static function buildFullHeaders($issue_id, $message_id, $from, $to, $cc, $subject, $body, $in_reply_to, $iaf_ids = null)
 {
     // hack needed to get the full headers of this web-based email
     $mail = new Mail_Helper();
     $mail->setTextBody($body);
     // FIXME: $body unused, but does mime->get() have side effects?
     $body = $mail->mime->get(array('text_charset' => APP_CHARSET, 'head_charset' => APP_CHARSET, 'text_encoding' => APP_EMAIL_ENCODING));
     if (!empty($issue_id)) {
         $mail->setHeaders(array('Message-Id' => $message_id));
     } else {
         $issue_id = 0;
     }
     // if there is no existing in-reply-to header, get the root message for the issue
     if ($in_reply_to == false && !empty($issue_id)) {
         $in_reply_to = Issue::getRootMessageID($issue_id);
     }
     if ($in_reply_to) {
         $mail->setHeaders(array('In-Reply-To' => $in_reply_to));
     }
     if ($iaf_ids) {
         foreach ($iaf_ids as $iaf_id) {
             $attachment = Attachment::getDetails($iaf_id);
             $mail->addAttachment($attachment['iaf_filename'], $attachment['iaf_file'], $attachment['iaf_filetype']);
         }
     }
     $cc = trim($cc);
     if (!empty($cc)) {
         $cc = str_replace(',', ';', $cc);
         $ccs = explode(';', $cc);
         foreach ($ccs as $address) {
             if (!empty($address)) {
                 $mail->addCc($address);
             }
         }
     }
     return $mail->getFullHeaders($from, $to, $subject);
 }