General discussion on installation and configuration of SOGo

Text archives Help


Re: [SOGo] ActiveSync for SOGo


Chronological Thread 
  • From: Albrecht Gebhardt < >
  • To:
  • Subject: Re: [SOGo] ActiveSync for SOGo
  • Date: Mon, 31 Jan 2011 21:09:53 +0100

Hi

I just want to tell that I recently did some experiments with z-push based on the work of Bo and Fabrice.

It's still not working correctly but nevertheless I want to share it here, a patch is attached and should be applied to Fabrices z-push.zip file from http://oeufdure.free.fr/download/sogo/

I did some succesful tests with Windows Mobile 6.0/6.1 devices with a rather empty test account,
but when I tried to switch to my real life account with ~150 contacts, ~50 events and a rather full IMAP tree things stopped working reliably.

Success was also varying for different devices (WebOS, iOS4, Symbian, Maemo5, Android 2.1). But my first tests were not systematically enough to report them here (errors are doubled events, time-shifted events, removed reminders and so on, contacts are ok, but sometimes need several syncs before everything is synced, ...)

So meanwhile I have to stay with Zarafa (because there is no reliable sync between WebOS or Maemo5 and SOGo that I know of) before I can switch back to SOGo, Funambol and hopefully some future working version of z-push for SOGo.

For details of my changes please look through the attached patch file.

The files are also available at http://www.algepop.net/users/alge/sogo/z-push/


Best wishes
Albrecht


Fabrice Durand schrieb:
Hi Bo,

It seems that i have got a problem with reminders, but it doesn't broken sync. ...

diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/autodiscover.php z-push/autodiscover.php
--- z-push-free.fr/autodiscover.php	1970-01-01 01:00:00.000000000 +0100
+++ z-push/autodiscover.php	2011-01-31 17:20:07.000000000 +0100
@@ -0,0 +1,30 @@
+<?php
+   //get raw POST data so we can extract the email address
+   $data = file_get_contents("php://input");
+   preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $data, $matches);
+   //set Content-Typeheader("Content-Type: application/xml");?>
+<?php echo '<?xml version="1.0" encoding="utf-8" ?>'; ?>
+<Autodiscover xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006";>
+<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006";>
+<Culture>en:en</Culture>
+<User>
+<DisplayName><?php echo $matches[1]; ?></DisplayName>
+<EMailAddress><?php echo $matches[1]; ?></EMailAddress>
+</User>
+<Action>
+<Settings>
+<Server>
+<Type>MobileSync</Type>
+<Url>http://YOUR_SERVER_NAME/Microsoft-Server-ActiveSync </Url>
+<Name>http://YOUR_SERVER_NAME/Microsoft-Server-ActiveSync </Name>
+</Server>
+</Settings>
+</Action>
+</Response>
+</Autodiscover>
+<?php
+# needs the followinglines in apache config (of course uncommented):
+# Alias /Autodiscover/Autodiscover.xml "/opt/z-push/autodiscover.php"
+# Alias /autodiscover/autodiscover.xml "/opt/z-push/autodiscover.php"
+# Alias /AutoDiscover/AutoDiscover.xml "/opt/z-push/autodiscover.php"
+?>
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/backend/caldav.php z-push/backend/caldav.php
--- z-push-free.fr/backend/caldav.php	2010-12-26 11:09:12.000000000 +0100
+++ z-push/backend/caldav.php	2011-01-31 17:22:29.000000000 +0100
@@ -18,6 +18,8 @@
     var $_devid;
     var $_protocolversion;
 	var $_path;
+    var $_dir;
+    var $_messages=array();
 
 
 	
@@ -53,6 +55,12 @@
 			return false;
 		}	
 		$this->_path = $caldav_path;
+                // alge: cache wdc->ls output in $this->_dir to reduce system load
+                $this->_dir = $this->wdc->ls($this->_path);
+                if(!($this->_dir)) {
+                    debugLog('CalDAV::Logon: '.$this->_path.' contains no dir');
+                    return false;
+                }
 
 		debugLog('CalDAV::Successful Logon To WebDAV Server');
         return true;
@@ -97,20 +105,19 @@
      */  
     function GetMessageList($folderid, $cutoffdate) {
         debugLog('CalDAV::GetMessageList('.$folderid.')');
+        // alge: cche output in $this->_messages to reduce system load
+        if(count($this->_messages)==0){
 		if ($folderid != "calendar" && $folderid != "tasks")
             return false;
 
         $messages = array();
 
-        $dir = $this->wdc->ls($this->_path);
-        if(!$dir) {
-            debugLog('CalDAV::GetMessageList '.$this->_path.' not dir');
+        if(!($this->_dir))
             return false;
-        }
 
-        foreach($dir as $e) {
+        foreach($this->_dir as $e) {
             $e['href'] = substr($e['href'], strlen($this->_path));
-			$test = split('/', $e['href']);
+			$test = preg_split('/\//', $e['href']);
 			$last=array_pop($test);
 			if (trim($last) != "") {
 				$message = $this->StatMessage($folderid, $last);
@@ -118,7 +125,11 @@
 			}
         }
         debugLog('CalDAV::GetMessageList length'.count($messages));
+        $this->_messages=$messages;
         return $messages;
+        } else {
+        return $this->_messages;
+        }
     }
 
     function GetFolderList() {
@@ -180,20 +191,22 @@
         if(trim($id == ""))
             return false;
 
-        $dir = $this->wdc->ls($this->_path);
-        if(!$dir)
+        if(!($this->_dir)){
+            debugLog("CalDAV::StatMessage: !_dir " );
             return false;
+        }
 
-        foreach($dir as $e) {
+        foreach($this->_dir as $e) {
 			debugLog('CalDAV::href '.$e['href']);
-			$test = split('/', $e['href']);
+			$test = preg_split('/\//', $e['href']);
 			$last=array_pop($test);
 			$e['href'] = substr($e['href'], strlen($this->_path));
 			debugLog('CalDAV::href2 '.$last);
 			debugLog('CalDAV::href3 '.$this->_path.$last);
 			if ($last == $id) {
 				$event = $this->isevent($this->_path.$last);
-				debugLog('CalDAV::StatMessage('.$folderid.', '.$id.') is '.print_r($event));
+//				debugLog('CalDAV::StatMessage('.$folderid.', '.$id.') is '.print_r($event));
+# alge: why does this stop working when uncommented:
 //				if ($event)  {
 					if ($folderid == "calendar") {
 						$message = array();
@@ -207,6 +220,7 @@
 						$message["flags"] = 1; // always 'read'
 						return $message;
 					}
+# alge??? see above:
 //				}
 				if (!$event && $folderid == "tasks") {
 					$message = array();
@@ -239,7 +253,9 @@
 			$v->sort();
 
 			$vevent = $v->getComponent( 'vevent' );
-			debugLog('CalDAV::VEVENT '.print_r($vevent));
+                        // alge: this print_r goes to stdout and breaks the communication
+                        // !!! why?
+			//debugLog('CalDAV::VEVENT '.print_r($vevent));
 			if ($vevent = $v->getComponent( 'vevent' )) {
 				return true;
 			} else {
@@ -257,7 +273,7 @@
 
         if(trim($id == ""))
             return;
-		$test = split('/', $id);
+		$test = preg_split('/\//', $id);
 		$last=array_pop($test);
         debugLog("CalDAV::Getting123 ".$this->_path.$last);
 		$stat = $this->wdc->get($this->_path.$last, $output); 
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/backend/carddav.php z-push/backend/carddav.php
--- z-push-free.fr/backend/carddav.php	2010-12-26 21:08:58.000000000 +0100
+++ z-push/backend/carddav.php	2011-01-31 17:17:49.000000000 +0100
@@ -32,6 +32,8 @@
     var $_protocolversion;
     var $_config;
     var $_path;
+    var $_dir;
+    var $_messages=array();
 
     
 	
@@ -68,6 +70,12 @@
 			return false;
 		}	
 		$this->_path = $cardav_path;
+                // alge: cache wdc->ls output in $this->_dir to reduce system load
+                $this->_dir = $this->wdc->ls($this->_path);
+                if(!($this->_dir)) {
+                    debugLog('CardDAV::Logon: '.$this->_path.' contains no dir');
+                    return false;
+                }
 
 		debugLog('CardDAV::Successful Logon To WebDAV Server');
         return true;
@@ -101,28 +109,31 @@
 
     function GetMessageList($folderid, $cutoffdate) {
         debugLog('CardDAV::GetMessageList('.$this->_path.')');
+        // alge: cche output in $this->_messages to reduce system load
+        if(count($this->_messages)==0){
         if ($folderid != "contacts")
             return false;
 
         $messages = array();
 
-        $dir = $this->wdc->ls($this->_path);
-        if(!$dir) {
-            debugLog('CardDAV::GetMessageList '.$this->_path.' not dir');
+        if(!($this->_dir))
             return false;
-        }
 
-        foreach($dir as $e) {
+        foreach($this->_dir as $e) {
 			$e['href'] = substr($e['href'], strlen($this->_path));
-			$test = split('/', $e['href']);
+			$test = preg_split('/\//', $e['href']);
 			$last=array_pop($test);
             if (trim($last) != "") {
                 $message = $this->StatMessage($folderid, $last);
                 $messages[] = $message;
             }
         }
-        debugLog('CardDAV::GetMessageList length'.count($messages));
+        debugLog('CardDAV::GetMessageList length: '.count($messages));
+        $this->_messages=$messages;
         return $messages;
+        } else {
+        return $this->_messages;
+        }
     }
 
     function GetFolderList() {
@@ -171,12 +182,13 @@
         if(trim($id == ""))
             return false;
 
-        $dir = $this->wdc->ls($this->_path);
-        if(!$dir)
+        if(!($this->_dir)){
+            debugLog("CardDAV::StatMessage: !_dir " );
             return false;
+        }
 
-        foreach($dir as $e) {
-			$test = split('/', $e['href']);
+        foreach($this->_dir as $e) {
+			$test = preg_split('/\//', $e['href']);
 			$last=array_pop($test);
 			if ($last == $id) {
 		        debugLog('CardDAV::StatMessage('.$folderid.', '.$id.')');
@@ -201,9 +213,8 @@
 
     function GetMessage($folderid, $id, $truncsize, $mimesupport = 0) {
         debugLog('CardDAV::GetMessage('.$folderid.', '.$id.', ..)');
-		$test = split('/', $id);
+		$test = preg_split('/\//', $id);
 		$last=array_pop($test);
-        debugLog("CarDAV::Getting123 ".$id);
 		$stat = $this->wdc->get($this->_path.$last, $output); 
 	//$stat = $this->wdc->get($this->_path.$id, $output); 
 	if ($stat != 200) {
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/backend/diffbackend.php z-push/backend/diffbackend.php
--- z-push-free.fr/backend/diffbackend.php	2010-12-22 10:16:02.000000000 +0100
+++ z-push/backend/diffbackend.php	2011-01-30 10:18:17.000000000 +0100
@@ -488,10 +488,12 @@
                         // calls. This may cause our algorithm to 'double see' changes.
 
                         $stat = $this->_backend->StatMessage($this->_folderid, $change["id"]);
+//print("stat:");print_r($stat);
                         $message = $this->_backend->GetMessage($this->_folderid, $change["id"], $truncsize,(isset($this->_bodypreference) ? $this->_bodypreference : false));
+//print("message:");print_r($message);
 
                         // copy the flag to the message
-                        if (!$message || !$stat) error_log(__METHOD__."() FATAL !message || !stat");
+                        if (!$message || !$stat) debugLog(__METHOD__."() FATAL !message || !stat");
                         $message->flags = (isset($change["flags"])) ? $change["flags"] : 0;
 
                         if($stat && $message) {
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/backend/imap.php z-push/backend/imap.php
--- z-push-free.fr/backend/imap.php	2010-12-24 12:07:00.000000000 +0100
+++ z-push/backend/imap.php	2011-01-31 16:58:04.000000000 +0100
@@ -34,6 +34,8 @@
 
         $this->_wasteID = false;
         $this->_sentID = false;
+        $this->_username=$username;
+        $this->_password=$password;
         $this->_server = "{" . IMAP_SERVER . ":" . IMAP_PORT . "/imap" . IMAP_OPTIONS . "}";
 
         if (!function_exists("imap_open"))
@@ -139,7 +141,11 @@
         $Mail_RFC822 = new Mail_RFC822();
         $toaddr = $ccaddr = $bccaddr = "";
         if(isset($message->headers["to"]))
-            $toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["to"]));
+            //$toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["to"]));
+            // alge: dont strip the To address:
+            $toaddr = $message->headers["to"];
+            //debugLog("IMAP-SendMail: header is:".print_r($message->headers));
+            //debugLog("IMAP-SendMail: to is:".$toaddr);
         if(isset($message->headers["cc"]))
             $ccaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["cc"]));
         if(isset($message->headers["bcc"]))
@@ -251,6 +257,8 @@
             if ($headers) $headers .= "\n";
             $headers .= 'From: '.$v;
         }
+        if ($headers) $headers .= "\n";
+        $headers .= 'X-Mailer: Z-Push / SOGo ActiveSync interface';
 
         // set "Return-Path" header if not set on the device
         if(IMAP_DEFAULTFROM && !$returnPathSet){
@@ -1435,7 +1443,14 @@
 
     // adds a message as seen to a specified folder (used for saving sent mails)
     function addSentMessage($folderid, $header, $body) {
-        return @imap_append($this->_mbox,$this->_server . $folderid, $header . "\n\n" . $body ,"\\Seen");
+        // alge:
+        // temporarily log in a second time because $this->_mbox is 
+        // logged in with OP_HALFOPEN option which is not enough for imap_append() 
+        // at least for my cyrus imap installation
+           
 ($this->_server . $folderid, $this->_user, $this->_password);
+           
 ($tmp_mbox,$this->_server . $folderid, str_replace("\n", "\r\n", $header) . "\r\n\r\n" . $body ,"\\Seen");
+           @imap_close($tmp_mbox);
+           return $r;
     }
 
 
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/config.php z-push/config.php
--- z-push-free.fr/config.php	2010-12-26 15:41:16.000000000 +0100
+++ z-push/config.php	2011-01-31 17:23:10.000000000 +0100
@@ -82,20 +82,21 @@
 
     // Defines the server to which we want to connect
     // recommended to use local servers only
-    define('IMAP_SERVER', 'imap.free.fr');
+    define('IMAP_SERVER', 'localhost');
     // connecting to default port (143)
-    define('IMAP_PORT', 143);
+    define('IMAP_PORT', 993);
     // best cross-platform compatibility (see http://php.net/imap_open for options)
-    define('IMAP_OPTIONS', '/notls/norsh');
+    // dont forget /novalidate-cert whith  self-segnied certificates!
+    define('IMAP_OPTIONS', '/notls/norsh/ssl/novalidate-cert');
     // overwrite the "from" header if it isn't set when sending emails
     // options: 'username'    - the username will be set (usefull if your login is equal to your emailaddress)
     //        'domain'    - the value of the "domain" field is used
     //        '@mydomain.com' - the username is used and the given string will be appended
-    define('IMAP_DEFAULTFROM', '');
+    define('IMAP_DEFAULTFROM', 'username');
     // copy outgoing mail to this folder. If not set z-push will try the default folders
-    define('IMAP_SENTFOLDER', '');
-    define('IMAP_DELETEDITEMSFOLDER', '');
-    define('IMAP_DRAFTSFOLDER', '');
+    define('IMAP_SENTFOLDER', 'INBOX.Sent');
+    define('IMAP_DELETEDITEMSFOLDER', 'INBOX.Trash');
+    define('IMAP_DRAFTSFOLDER', 'INBOX.Drafts');
     // forward messages inline (default off - as attachment)
     define('IMAP_INLINE_FORWARD', false);
     // use imap_mail() to send emails (default) - off uses mail()
@@ -129,12 +130,12 @@
 	// %u is replaced by the username
 	// Not yet implemented
 
-	define('CALDAV_SERVER', 'localhost');
+	define('CALDAV_SERVER', 'YOUR_SERVER_NAME');
 	define('CALDAV_PORT', '80');
 	define('CALDAV_PATH', '/SOGo/dav/%u/Calendar/personal/');
 
 
-	define('CARDDAV_SERVER', 'localhost');
+	define('CARDDAV_SERVER', 'YOUR_SERVER_NAME');
 	define('CARDDAV_PORT', '80');
 	define('CARDDAV_PATH', '/SOGo/dav/%u/Contacts/personal/');
 
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/_htaccess z-push/_htaccess
--- z-push-free.fr/_htaccess	1970-01-01 01:00:00.000000000 +0100
+++ z-push/_htaccess	2011-01-28 20:34:04.000000000 +0100
@@ -0,0 +1,31 @@
+<files .htaccess>
+    order allow,deny
+    deny from all
+</files>
+
+<files debug.txt>
+    order allow,deny
+    deny from all
+</files>
+            
+# some apache settings
+Options -Indexes
+
+# register globals must be off
+php_flag register_globals off
+
+# magic quotes must be off
+php_flag magic_quotes_gpc off
+php_flag magic_quotes_runtime off
+
+# The maximum POST limit. To upload large files, this value must be larger than upload_max_filesize.
+php_value post_max_size 31M
+php_value upload_max_filesize 30M
+
+# we need short-open-tags
+php_flag short_open_tag on
+
+# For debugging only
+# make sure apache/php can write this file, or else no errors are logged!
+php_flag  log_errors on
+php_value error_log /var/log/httpd/errors.txt
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/.htaccess z-push/.htaccess
--- z-push-free.fr/.htaccess	2010-12-22 10:16:02.000000000 +0100
+++ z-push/.htaccess	1970-01-01 01:00:00.000000000 +0100
@@ -1,31 +0,0 @@
-<files .htaccess>
-    order allow,deny
-    deny from all
-</files>
-
-<files debug.txt>
-    order allow,deny
-    deny from all
-</files>
-            
-# some apache settings
-Options -Indexes
-
-# register globals must be off
-php_flag register_globals off
-
-# magic quotes must be off
-php_flag magic_quotes_gpc off
-php_flag magic_quotes_runtime off
-
-# The maximum POST limit. To upload large files, this value must be larger than upload_max_filesize.
-php_value post_max_size 31M
-php_value upload_max_filesize 30M
-
-# we need short-open-tags
-php_flag short_open_tag on
-
-# For debugging only
-# make sure apache/php can write this file, or else no errors are logged!
-php_flag  log_errors on
-php_value error_log /var/log/httpd/errors.txt
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/include/class_ical_client.php z-push/include/class_ical_client.php
--- z-push-free.fr/include/class_ical_client.php	2010-12-25 22:42:32.000000000 +0100
+++ z-push/include/class_ical_client.php	2011-01-31 16:56:29.000000000 +0100
@@ -48,6 +48,8 @@
   //date_default_timezone_set( 'Europe/London' );
             /* version string, do NOT remove!! */
 define( 'ICALCREATOR_VERSION', 'iCalcreator 2.6' );
+
+
 /*********************************************************************************/
 /*********************************************************************************/
 /**
@@ -6707,6 +6709,10 @@
  */
   function setComponent( $component, $arg1=FALSE, $arg2=FALSE  ) {
     if( !isset( $this->components )) return FALSE;
+    // alge:
+    // sometimes this is called with a wrong $component, so avoid that 
+    // the next line throws an error:
+    if( !isset( $this->getConfig )) return FALSE;
     if( '' >= $component->getConfig( 'language'))
       $component->setConfig( 'language',  $this->getConfig( 'language' ));
     $component->setConfig( 'allowEmpty',  $this->getConfig( 'allowEmpty' ));
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/include/class_webdav_client.php z-push/include/class_webdav_client.php
--- z-push-free.fr/include/class_webdav_client.php	2010-12-26 09:46:56.000000000 +0100
+++ z-push/include/class_webdav_client.php	2011-01-31 17:27:50.000000000 +0100
@@ -1524,7 +1524,8 @@
 		// print 'string len of response_body:'. strlen($response_body);
 		// print '[' . htmlentities($response_body) . ']';
 		$ret_struct['body'] = $this->_body;
-		debugLog('CalDAV::OUTPUT3_process_respond: ' . var_export($ret_struct,true));
+		// alge: is this another print_r which goes to stdout?
+                //debugLog('CalDAV::OUTPUT3_process_respond: ' . var_export($ret_struct,true));
 		return $ret_struct;
 		
 	}
diff -uNrw --exclude='*RCS*' --exclude='*state*' z-push-free.fr/index.php z-push/index.php
--- z-push-free.fr/index.php	2010-12-22 10:16:02.000000000 +0100
+++ z-push/index.php	2011-01-31 17:26:01.000000000 +0100
@@ -338,6 +338,10 @@
 $len = ob_get_length();
 $data = ob_get_contents();
 ob_end_clean();
+#alge:
+# brute force logging!! spits out the complete data transfered to the client
+# dont forget to disable as the log file explodes otherwise :-)
+#debugLog("data: " . $data);
 
 // Unfortunately, even though zpush can stream the data to the client
 // with a chunked encoding, using chunked encoding also breaks the progress bar


  • Re: [SOGo] ActiveSync for SOGo, Albrecht Gebhardt, 01/31/2011

Archive powered by MHonArc 2.6.16.

Top of page