コード例 #1
0
ファイル: Outlook.php プロジェクト: raz0rsdge/horde
 /**
  * Clean up iCal messages from Outlook.
  *
  * @param string  $fqhostname  The name of this host.
  * @param string  $sender      The mail address of the sender.
  * @param array   $recipients  The recipients of the message.
  * @param string  $origfrom    The mail address of the original sender.
  * @param string  $subject     The mail subject.
  * @param string  $tmpfname    Path to the temporary message store.
  *
  * @return boolena|PEAR_Error True if the message was successfully rewritten.
  */
 function embedICal($fqhostname, $sender, $recipients, $origfrom, $subject, $tmpfname, $transport)
 {
     Horde::log(sprintf("Encapsulating iCal message forwarded by %s", $sender), 'DEBUG');
     $forwardtext = "This is an invitation forwarded by outlook and\n" . "was rectified by the Kolab server.\n" . "The invitation was originally sent by\n%s.\n\n" . "Diese Einladung wurde von Outlook weitergeleitet\n" . "und vom Kolab-Server in gute Form gebracht.\n" . "Die Einladung wurde ursprünglich von\n%s geschickt.\n";
     // Read in message text
     $requestText = '';
     $handle = @fopen($tmpfname, "r");
     if ($handle === false) {
         $msg = $php_errormsg;
         return PEAR::raiseError(sprintf("Error: Could not open %s for writing: %s", $tmpfname, $msg), OUT_LOG | EX_IOERR);
     }
     while (!feof($handle)) {
         $requestText .= fread($handle, 8192);
     }
     fclose($handle);
     // Parse existing message
     list($headers, $mime) = Kolab_Filter_Outlook::_mimeParse($requestText);
     $parts = $mime->contentTypeMap();
     if (count($parts) != 1 || $parts[1] != 'text/calendar') {
         Horde::log("Message does not contain exactly one toplevel text/calendar part, passing through.", 'DEBUG');
         return false;
     }
     $basepart = $mime->getBasePart();
     // Construct new MIME message with original message attached
     $toppart = new MIME_Message();
     $dorigfrom = Mail_mimeDecode::_decodeHeader($origfrom);
     $textpart = new MIME_Part('text/plain', sprintf($forwardtext, $dorigfrom, $dorigfrom), 'UTF-8');
     $ical_txt = $basepart->transferDecode();
     Kolab_Filter_Outlook::_addOrganizer($ical_txt, $dorigfrom);
     $msgpart = new MIME_Part($basepart->getType(), Kolab_Filter_Outlook::_recodeToAscii($ical_txt), $basepart->getCharset());
     $toppart->addPart($textpart);
     $toppart->addPart($msgpart);
     // Build the reply headers.
     $msg_headers = new MIME_Headers();
     Kolab_Filter_Outlook::_copyHeader('Received', $msg_headers, $headers);
     //$msg_headers->addReceivedHeader();
     $msg_headers->addMessageIdHeader();
     Kolab_Filter_Outlook::_copyHeader('Date', $msg_headers, $headers);
     Kolab_Filter_Outlook::_copyHeader('Resent-Date', $msg_headers, $headers);
     Kolab_Filter_Outlook::_copyHeader('Subject', $msg_headers, $headers);
     $msg_headers->addHeader('From', $sender);
     $msg_headers->addHeader('To', join(', ', $recipients));
     $msg_headers->addHeader('X-Kolab-Forwarded', 'TRUE');
     $msg_headers->addMIMEHeaders($toppart);
     Kolab_Filter_Outlook::_copyHeader('Content-Transfer-Encoding', $msg_headers, $headers);
     if (is_object($msg_headers)) {
         $headerArray = $toppart->encode($msg_headers->toArray(), $toppart->getCharset());
     } else {
         $headerArray = $toppart->encode($msg_headers, $toppart->getCharset());
     }
     return Kolab_Filter_Outlook::_inject($toppart, $recipients, $msg_headers, $sender, $transport);
 }