gunnar: server/php-kolab/Kolab_Filter/Filter Outlook.php, NONE, 1.1 Resource.php, NONE, 1.1
cvs at kolab.org
cvs at kolab.org
Tue Nov 27 08:35:47 CET 2007
- Previous message: gunnar: server/php-kolab/Kolab_Filter/Filter Incoming.php, 1.1, 1.2 Outgoing.php, 1.1, 1.2 olhacks.php, 1.3, NONE resmgr.php, 1.6, NONE
- Next message: gunnar: server/php-kolab/Kolab_Filter/tests/_data tiny.eml,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: gunnar
Update of /kolabrepository/server/php-kolab/Kolab_Filter/Filter
In directory doto:/tmp/cvs-serv5656
Added Files:
Outlook.php Resource.php
Log Message:
Renamed resmgr.php and olhacks.php
--- NEW FILE: Outlook.php ---
<?php
/*
* COPYRIGHT
* ---------
*
* See ../AUTHORS file
*
*
* LICENSE
* -------
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Revision: 1.1 $
*
* ABOUT
* -----
*
* FIXME
*
*/
require_once 'Kolab/Filter/misc.php';
require_once 'Horde/iCalendar.php';
require_once 'Horde/MIME.php';
require_once 'Horde/MIME/Message.php';
require_once 'Horde/MIME/Headers.php';
require_once 'Horde/MIME/Part.php';
require_once 'Horde/MIME/Structure.php';
$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";
/*static*/ function olhacks_mime_parse( &$text ) {
/* Taken from Horde's MIME/Structure.php */
require_once 'Mail/mimeDecode.php';
/* Set up the options for the mimeDecode class. */
$decode_args = array();
$decode_args['include_bodies'] = true;
$decode_args['decode_bodies'] = false;
$decode_args['decode_headers'] = false;
$mimeDecode = &new Mail_mimeDecode($text, MIME_PART_EOL);
if (!($structure = $mimeDecode->decode($decode_args))) {
return false;
}
/* Put the object into imap_parsestructure() form. */
MIME_Structure::_convertMimeDecodeData($structure);
return array($structure->headers, $ret = &MIME_Structure::parse($structure));
}
/* static */ function copy_header( $name, &$msg_headers, &$headerarray ) {
$lname = strtolower($name);
if( array_key_exists($lname, $headerarray)) {
if( is_array( $headerarray[$lname] ) ) {
foreach( $headerarray[$lname] as $h ) {
$msg_headers->addHeader($name, $h );
}
} else {
$msg_headers->addHeader($name, $headerarray[$lname] );
}
}
}
/*
* Yet another problem: Outlook seems to remove the organizer
* from the iCal when forwarding -- we put the original sender
* back in as organizer.
*/
function add_organizer(&$icaltxt, $from)
{
global $conf;
if (!empty($conf['filter']['email_domain'])) {
$email_domain = $conf['filter']['email_domain'];
} else {
$email_domain = 'localhost';
}
$iCal = &new Horde_iCalendar();
$iCal->parsevCalendar($icaltxt);
$vevent =& $iCal->findComponent('VEVENT');
if( $vevent ) {
if( !$vevent->organizerName() ) {
$adrs = imap_rfc822_parse_adrlist($from, $email_domain);
if( count($adrs) > 0 ) {
$org_email = 'mailto:'.$adrs[0]->mailbox.'@'.$adrs[0]->host;
$org_name = $adrs[0]->personal;
if( $org_name ) $vevent->setAttribute( 'ORGANIZER', $org_email,
array( 'CN' => $org_name), false );
else $vevent->setAttribute( 'ORGANIZER', $org_email,
array(), false );
Horde::logMessage(sprintf(_("Adding missing organizer '%s <%s>' to iCal."),
$org_name, $org_email),
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$icaltxt = $iCal->exportvCalendar();
}
}
}
}
/* Yet another Outlook problem: Some versions of Outlook seems to be incapable
* of handling non-ascii characters properly in text/calendar parts of
* a multi-part/mixed mail which we use for forwarding.
* As a solution, we encode common characters as humanreadable
* two-letter ascii.
*/
/* static */ function olhacks_recode_to_ascii( $text ) {
$text = str_replace( ('æ'), 'ae', $text );
$text = str_replace( ('ø'), 'oe', $text );
$text = str_replace( ('Ã¥'), 'aa', $text );
$text = str_replace( ('ä'), 'ae', $text );
$text = str_replace( ('ö'), 'oe', $text );
$text = str_replace( ('ü'), 'ue', $text );
$text = str_replace( ('Ã'), 'ss', $text );
$text = str_replace( ('Ã'), 'Ae', $text );
$text = str_replace( ('Ã'), 'Oe', $text );
$text = str_replace( ('Ã
'), 'Aa', $text );
$text = str_replace( ('Ã'), 'Ae', $text );
$text = str_replace( ('Ã'), 'Oe', $text );
$text = str_replace( ('Ã'), 'Ue', $text );
return $text;
}
/* main entry point */
function olhacks_embedical($fqhostname, $sender, $recipients, $origfrom, $subject, $tmpfname)
{
Horde::logMessage(sprintf(_("Encapsulating iCal message forwarded by %s"), $sender),
__FILE__, __LINE__, PEAR_LOG_DEBUG);
global $forwardtext;
// 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 || ERR_TEMPFAIL);
}
while (!feof($handle)) {
$requestText .= fread($handle, 8192);
}
fclose($handle);
// Parse existing message
list( $headers, $mime) = olhacks_mime_parse($requestText);
$parts = $mime->contentTypeMap();
if (count($parts) != 1 || $parts[1] != 'text/calendar') {
Horde::logMessage(_("Message does not contain exactly one toplevel text/calendar part, passing through."),
__FILE__, __LINE__, PEAR_LOG_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();
add_organizer($ical_txt, $dorigfrom);
$msgpart = &new MIME_Part($basepart->getType(), olhacks_recode_to_ascii($ical_txt),
$basepart->getCharset() );
$toppart->addPart($textpart);
$toppart->addPart($msgpart);
// Build the reply headers.
$msg_headers = &new MIME_Headers();
copy_header( 'Received', $msg_headers, $headers );
//$msg_headers->addReceivedHeader();
$msg_headers->addMessageIdHeader();
copy_header( 'Date', $msg_headers, $headers );
copy_header( 'Resent-Date', $msg_headers, $headers );
copy_header( '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);
copy_header( '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());
}
// Inject message back into postfix
require_once 'Mail.php';
$mailer = &Mail::factory('SMTP', array('auth' => false, 'port' => 10026 ));
$msg = $toppart->toString();
/* Make sure the message has a trailing newline. */
if (substr($msg, -1) != "\n") {
$msg .= "\n";
}
$result = $mailer->send($recipients, $headerArray, $msg);
if (is_a($result, 'PEAR_Error')) {
$append = sprintf(_(", original code %s"), $result->getCode());
$result->message = $result->getMessage() . $append;
$result->code = OUT_LOG || OUT_STDOUT || ERR_TEMPFAIL;
return $result;
}
return true;
}
?>
--- NEW FILE: Resource.php ---
<?php
/*
* COPYRIGHT
* ---------
*
* See ../AUTHORS file
*
*
* LICENSE
* -------
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[...1476 lines suppressed...]
unset($imap);
// Get the resource's free/busy list
// once more so it is up to date
if( !triggerFreeBusy($resource,false) ) {
myLog("Error updating fblist", RM_LOG_SUPER );
}
return false;;
default:
// We either don't currently handle these iTip methods, or they do not
// apply to what we're trying to accomplish here
myLog("Ignoring $method method and passing message through to $resource");
return true;
}
// Pass the message through to the group's mailbox
myLog("Passing through $method method to $resource");
return true;
}
?>
- Previous message: gunnar: server/php-kolab/Kolab_Filter/Filter Incoming.php, 1.1, 1.2 Outgoing.php, 1.1, 1.2 olhacks.php, 1.3, NONE resmgr.php, 1.6, NONE
- Next message: gunnar: server/php-kolab/Kolab_Filter/tests/_data tiny.eml,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the commits
mailing list