steffen: server/kolab-resource-handlers/kolab-resource-handlers/resmgr resmgr.php, 1.11, 1.12
cvs at intevation.de
cvs at intevation.de
Fri Aug 20 01:28:54 CEST 2004
Author: steffen
Update of /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr
In directory doto:/tmp/cvs-serv19866/kolab-resource-handlers/kolab-resource-handlers/resmgr
Modified Files:
resmgr.php
Log Message:
Allow group accounts to receive regular mail (Issue319)
Index: resmgr.php
===================================================================
RCS file: /kolabrepository/server/kolab-resource-handlers/kolab-resource-handlers/resmgr/resmgr.php,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- resmgr.php 12 Aug 2004 13:42:48 -0000 1.11
+++ resmgr.php 19 Aug 2004 23:28:52 -0000 1.12
@@ -135,7 +135,7 @@
$is_shutting_down = false;
-function shutdown($return = 1)
+function shutdown($return = 1, $errormsg = "" )
{
global $is_shutting_down;
@@ -150,6 +150,7 @@
imapClose();
logClose();
+ print $errormsg;
exit($return);
}
@@ -220,13 +221,13 @@
// Connect to the LDAP server and retrieve the users' password
$ldap = ldap_connect($params['ldap_uri']);
if (!ldap_bind($ldap, $params['bind_dn'], $params['bind_pw'])) {
- myLog('Unable to contact LDAP server: ' . $ldap_error($ldap));
+ myLog('Unable to contact LDAP server: ' . ldap_error($ldap));
return false;
}
- $result = ldap_search($ldap, $params['base_dn'], "(mail=$resource)", array("kolabEncryptedPassword"));
+ $result = ldap_search($ldap, $params['base_dn'], "(&(objectClass=kolabInetOrgPerson)(mail=$resource))", array("kolabEncryptedPassword"));
if (!$result) {
- myLog('Unable to perform LDAP search: ' . $ldap_error($ldap));
+ myLog('Unable to perform LDAP search: ' . ldap_error($ldap));
return false;
}
@@ -270,9 +271,61 @@
$requestText = preg_replace("/\r\n|\n|\r/s", "\r\n", $requestText);
}
+function check_lmtp_response( &$lmtp, $code )
+{
+ $resp = $lmtp->getResponse();
+ if( $resp[0] != $code ) {
+ myLog( $resp[1], RM_LOG_ERROR );
+ shutdown( 1, $resp[1] );
+ } else return true;
+}
+
+function send_lmtp( $sender, $recip, &$data )
+{
+ static $lmtp;
+ if (!isset($lmtp)) {
+ require_once 'Net/LMTP.php';
+ $lmtp = new Net_LMTP();
+ if( !$lmtp ) {
+ $msg = 'Could not create LMTP object';
+ myLog($msg, RM_LOG_ERROR );
+ shutdown(1, $msg );
+ }
+ if( PEAR::isError( $error = $lmtp->connect() ) ) {
+ $msg = 'Failed to connect to LMTP: '.$error->getMessage();
+ myLog( $msg, RM_LOG_ERROR );
+ shutdown( 1, $msg );
+ }
+ check_lmtp_response( $lmtp, 250 );
+
+ if( PEAR::isError( $error = $lmtp->mailFrom($sender) ) ) {
+ $msg = 'Failed to set sender: '.$error->getMessage();
+ myLog( $msg, RM_LOG_ERROR );
+ shutdown( 1, $msg );
+ }
+ check_lmtp_response( $lmtp, 250 );
+ if( PEAR::isError( $error = $lmtp->rcptTo($recip) ) ) {
+ $msg = 'Failed to set recipient: '.$error->getMessage();
+ myLog( $msg, RM_LOG_ERROR );
+ shutdown( 1, $msg );
+ }
+ check_lmtp_response( $lmtp, 250 );
+ if( PEAR::isError( $error = $lmtp->data($data) ) ) {
+ $msg = 'Failed to send data: '.$error->getMessage();
+ myLog( $msg, RM_LOG_ERROR );
+ shutdown( 1, $msg );
+ }
+ check_lmtp_response( $lmtp, 250 );
+ $lmtp->disconnect();
+ }
+}
+
function &getITip()
{
global $requestText;
+ global $resource;
+ global $sender;
+ global $params;
$mime = &MIME_Structure::parseTextMIMEMessage($requestText);
@@ -287,15 +340,20 @@
$event = &$iCalendar->findComponent('VEVENT');
if ($event === false) {
myLog('No VFREEBUSY found in iCalendar data', RM_LOG_ERROR);
- shutdown();
+ shutdown(1, 'No VFREEBUSY found in iCalendar data' );
}
return $event;
}
}
- myLog('No iCalendar data found in message', RM_LOG_ERROR);
- shutdown();
+ if( $params['group'] ) {
+ send_lmtp( $sender, $resource, $requestText );
+ shutdown(0);
+ } else {
+ myLog('No iCalendar data found in message', RM_LOG_ERROR);
+ shutdown(1, 'No iCalendar data found in message' );
+ }
}
/** Helper function */
@@ -340,8 +398,8 @@
$text = @file_get_contents($url);
if ($text == false || empty($text)) {
- myLog("Unable to retrieve free/busy information for $resource", RM_LOG_ERROR);
- shutdown();
+ myLog("Unable to retrieve free/busy information for $resource", RM_LOG_ERROR);
+ //shutdown(1, "Unable to retrieve free/busy information for $resource");
}
$iCalendar = &new Horde_iCalendar();
@@ -414,7 +472,7 @@
default:
myLog("Unknown iTip method ($type) passed to sendITipReply()", RM_LOG_ERROR);
- shutdown();
+ shutdown(1, "Unknown iTip method ($type) passed to sendITipReply()");
}
$itip_reply->setAttribute('ATTENDEE', 'MAILTO:' . $resource, $params);
@@ -466,7 +524,7 @@
//$status = $mime->send($organiser, $msg_headers);
if (is_a($status, 'PEAR_Error')) {
myLog("Unable to send iTip reply: " . $status->getMessage(), RM_LOG_ERROR);
- shutdown();
+ shutdown(1, "Unable to send iTip reply: " . $status->getMessage());
} else {
myLog("Successfully sent iTip reply");
}
@@ -609,15 +667,16 @@
-$options = getopt("r:gm:");
+$options = getopt("s:r:gm:");
if (!array_key_exists('r', $options)) {
- print("Usage is $argv[0] -r resource at domain [-g] [-m mode]");
+ print("Usage is $argv[0] -s sender at domain -r resource at domain [-g] [-m mode]");
shutdown(1);
}
$params['group'] = array_key_exists('g', $options);
$resource = $options['r'];
+$sender = $options['s'];
if (array_key_exists('m', $options)) {
if (is_array($options['m'])) {
More information about the commits
mailing list