[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kolab-users
Subject:    [PATCH] for improved calendar sync in SyncKolab 0.4.28
From:       Andreas Gungl <Andreas.Gungl () osp-dd ! de>
Date:       2007-01-19 13:44:49
Message-ID: 200701191444.49687 () osp-dd ! de
[Download RAW message or body]

Hello all,

In the attached patch there are significant improvements for the calendar 
synchronization (compared to version 0.4.28):

1) fix for a problem when a message has been removed from the server and 
the message has already been in the internal hash database
(In this case the entry in the database hasn't been deleted which lead to 
problems if the same events have been uploaded again to the server by 
another client. Because then the events would be deleted again and again by 
the first client.)

2) fix for dealing with more than one calendar sync settings
(some typos or copy&paste errors prevented the settings dialog to be updated 
correctly)

3) allow parsing of most of the events generated by Toltec Connector
(the XML attachments in the message are base64-encoded, so the detection of 
that encoding and the decoding of base64 is needed)

There are still minor problems with the calendar sync, but most of them are 
hard to reproduce. If anyone has a reproducible test case, please let me 
know.

Best Regards,
Andreas

["synckolab-28-improved.diff" (text/x-diff)]

diff -U 3 -b -d -r -N -- synckolab/addressbook.js my-synckolab/addressbook.js
--- synckolab/addressbook.js	2006-11-03 16:43:40.000000000 +0100
+++ my-synckolab/addressbook.js	2006-12-28 09:47:11.000000000 +0100
@@ -149,7 +149,7 @@
 			// a new card or locally deleted 
 			if (acard == null)
 			{
-				var cEntry = getDbEntry (newCard.custom4, this.db);
+				var cEntry = getDbEntryIdx (newCard.custom4, this.db);
 				if (cEntry == -1)
 				{
 					var curEntry = new Array();
@@ -174,7 +174,7 @@
 			}
 			else
 			{
-				var cdb = getDbEntry (newCard.custom4, this.db);
+				var cdb = getDbEntryIdx (newCard.custom4, this.db);
 				var lastSyncEntry = cdb!=-1?this.db[cdb][1]:null;
 				var newSyncEntry = genConSha1 (newCard);
 				var curSyncEntry = genConSha1 (acard);
@@ -389,7 +389,7 @@
 			if (writeCur)
 			{
 				var curSyncEntry = genConSha1 (cur);
-				var cdb = getDbEntry (cur.custom4, this.db);
+				var cdb = getDbEntryIdx (cur.custom4, this.db);
 				if (cdb != -1)
 				{
 					writeCur = false;
diff -U 3 -b -d -r -N -- synckolab/calTools.js my-synckolab/calTools.js
--- synckolab/calTools.js	2006-11-03 16:43:40.000000000 +0100
+++ my-synckolab/calTools.js	2007-01-18 16:08:39.000000000 +0100
@@ -109,8 +109,7 @@
     // to switch back to something faster if needed.
     var aString = cnv_event2xml( event, true);
     hashValue = hex_sha1(aString);
-    if (debugKolabXML)
-        consoleService.logStringMessage("Parsed event in XML:\n" + aString + "\nHash \
Value: " + hashValue); +    condLogMsg(debugKolabXML, "Parsed event in XML:\n" + \
aString + "\nHash Value: " + hashValue);  
     return hashValue;
 }
@@ -205,8 +204,7 @@
  */
 function xml2Event (xml, event)
 {
-    if (debugKolabXML)
-        consoleService.logStringMessage("Parsing an XML \
event:\n====================\n" + xml); +    condLogMsg(debugKolabXML, "Parsing an \
XML event:\n====================\n" + xml);  // TODO improve recurrence settings
 	//      not working ATM:
 	//          - yearly recurrence
@@ -222,11 +220,46 @@
 	var boundary = xml.substring(xml.indexOf('boundary="')+10, xml.indexOf('"', \
xml.indexOf('boundary="')+12));  
 	// get the start of the xml
-	xml = xml.substring(xml.indexOf("<?xml"));
-	
+	contTypeIdx = xml.indexOf('Content-Type: application/x-vnd.kolab.event');
+	if (contTypeIdx == -1)
+	{
+		// so this message has no part of content type application/x-vnd.kolab.event
+		consoleService.logStringMessage("Error parsing this message: no \
application/x-vnd.kolab.event"); +		return false;
+	}
+	xml = xml.substring(contTypeIdx); // cut everything before this part
+	xmlIdx = xml.indexOf("<?xml")
+	if (xmlIdx == -1)
+	{
+		// FIXME try to decode if transfer-encoding is set to base64
+		if (xml.indexOf("Content-Transfer-Encoding: base64") != -1)
+		{
+			startPos = xml.indexOf("\r\n\r\n");
+			endPos = xml.indexOf("--"+boundary)
+			xml = xml.substring(startPos, endPos).replace(/\r\n/g, "")
+			try {
+				xml = atob(xml)
+			} catch (e) {
+				dump("Error decoding base64: " + e + "\n");
+				consoleService.logStringMessage("Error decoding base64: " + xml);
+				return false;
+			}
+		}
+		else
+		{
+			// so this message has no <xml>something</xml> area
+			consoleService.logStringMessage("Error parsing this message: no xml segment \
found"); +			return false;
+		}
+	}
+	else
+	{
+		xml = xml.substring(xmlIdx);
 	// until the boundary = end of xml
 	if (xml.indexOf(boundary) != -1)
 		xml = xml.substring(0, xml.indexOf("--"+boundary));
+	}
+	xml = decode_utf8(DecodeQuoted(xml))
 
 	// convert the string to xml
 	var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"].getService(Components.interfaces.nsIDOMParser); \
 @@ -330,7 +363,11 @@
 					break;
 					
 				case "LOCATION":
+				    // sometimes we have <location></location> in the XML
+				    if (cur.firstChild)
+				    {
 			  		event.setProperty("LOCATION", cur.firstChild.data);
+				    }
 					break;
 
 				case "CATEGORIES":
@@ -355,7 +392,7 @@
 					break;
 
 				case "RECURRENCE":
-					consoleService.logStringMessage("Parsing this event: " + event.id);
+					consoleService.logStringMessage("Parsing recurring event: " + event.id);
                     recInfo = \
                Components.classes["@mozilla.org/calendar/recurrence-info;1"] 
                                       \
.createInstance(Components.interfaces.calIRecurrenceInfo);  recInfo.item = event;
@@ -620,8 +657,7 @@
 		} // end if
 		cur = cur.nextSibling;
 	} // end while
-	if (debugKolabXML)
-	   consoleService.logStringMessage("Parsed event in ICAL:\n=====================\n" \
+ event.icalString); +	condLogMsg(debugKolabXML, "Parsed event in \
ICAL:\n=====================\n" + event.icalString);  return true;
 }
 
@@ -846,7 +882,7 @@
         // account specified in the synckolab settings
         xml += " <organizer>\n";
         xml += "  <display-name>" + "Synckolab" + "</display-name>\n";
-        xml += "  <smtp-address>" + "Synckolab@Post" + "</smtp-address>\n";
+        xml += "  <smtp-address>" + "synckolab@no.tld" + "</smtp-address>\n";
         xml += " </organizer>\n";
     }
 
@@ -865,8 +901,7 @@
     xml += " <revision>0</revision>\n";
     xml += "</event>\n"
 
-	if (debugKolabXML)
-		consoleService.logStringMessage("Event in ICAL:\n=============\n" + \
event.icalString + "\n"  +	condLogMsg(debugKolabXML, "Event in \
ICAL:\n=============\n" + event.icalString + "\n"   + "Created XML event \
structure:\n=============================\n" + xml);  return xml;
 }
diff -U 3 -b -d -r -N -- synckolab/calendar.js my-synckolab/calendar.js
--- synckolab/calendar.js	2006-11-03 16:43:38.000000000 +0100
+++ my-synckolab/calendar.js	2007-01-18 15:59:30.000000000 +0100
@@ -47,7 +47,6 @@
 	serverKey: '', // the incoming server
 	gSaveImap: true, // write back to folder
 
-//	gEvents: '', - now a listener
 	gToDo: '',
 	gCurTodo: 0,
 	gCurEvent: 0,
@@ -72,7 +71,6 @@
 		if (!isCalendarAvailable ())
 			return;
 			
-		var calFile;
 		// initialize the configuration
 		try {
 	    var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
 @@ -147,8 +145,6 @@
 	 * new message content is returned otherwise null
 	 */	
 	parseMessage: function(fileContent) {
-		fileContent = decode_utf8(DecodeQuoted(fileContent));
-		
 		// create a new item in the itemList for display
 		this.curItemInList = document.createElement("listitem");
 		this.curItemInListId = document.createElement("listcell");
@@ -165,12 +161,12 @@
 		
 		this.itemList.appendChild(this.curItemInList);
 		
-		var newEvent;
+		var parsedEvent;
 		if (this.format == "Xml")
 		{
-			newEvent = Components.classes["@mozilla.org/calendar/event;1"]
+			parsedEvent = Components.classes["@mozilla.org/calendar/event;1"]
 				.createInstance(Components.interfaces.calIEvent);
-			if (xml2Event(fileContent, newEvent) == false)
+			if (xml2Event(fileContent, parsedEvent) == false)
 			{
 				// update list item
 				this.curItemInListId.setAttribute("label", "unparseable");
@@ -179,90 +175,82 @@
 		}
 		else
 		{
+		    fileContent = decode_utf8(DecodeQuoted(fileContent));
             // this.format == 'iCal'
-		    newEvent = ical2event(fileContent);
+		    parsedEvent = ical2event(fileContent);
 		}
 
 		// update list item
-		this.curItemInListId.setAttribute("label", newEvent.id);
+		this.curItemInListId.setAttribute("label", parsedEvent.id);
 		this.curItemInListStatus.setAttribute("label", "checking");
-		this.curItemInListContent.setAttribute("label", newEvent.title);
+		this.curItemInListContent.setAttribute("label", parsedEvent.title);
 		
 		// remember that we did this uid already
-		this.folderMessageUids.push(newEvent.id);
+		this.folderMessageUids.push(parsedEvent.id);
 		// ok lets see if we have this one already 
-		var foundEvent = findEvent (this.gEvents, newEvent.id);
+		var foundEvent = findEvent (this.gEvents, parsedEvent.id);
+		var idxEntry = getDbEntryIdx (parsedEvent.id, this.db);
 	
 		if (foundEvent == null)
 		{
 			// a new event
-			if (debugCalendarSync)
-				consoleService.logStringMessage("a new event, locally unknown:" + newEvent.id);
-			var cEntry = getDbEntry (newEvent.id, this.db);
-			if (cEntry == -1)
+			condLogMsg(debugCalendarSync, "a new event, locally unknown:" + parsedEvent.id);
+			if (idxEntry == -1)
 			{
 				var curEntry = new Array();
-				curEntry.push(newEvent.id);
-				curEntry.push(genCalSha1(newEvent));
+				curEntry.push(parsedEvent.id);
+				curEntry.push(genCalSha1(parsedEvent));
 				this.db.push(curEntry);
 				this.curItemInListStatus.setAttribute("label", "add local");
 
-				if (debugCalendarSync)
-				    consoleService.logStringMessage("added locally:" + newEvent.id);				
+    			// add the new event
+    			this.gCalendar.addItem(parsedEvent, this.gEvents);
+
+				condLogMsg(debugCalendarSync, "added locally:" + parsedEvent.id);				
 			}
 			else
 			{
-				this.curItemInListStatus.setAttribute("label", "server delete");
-				if (debugCalendarSync)
-				    consoleService.logStringMessage("server delete - DELETEME returned:" + \
newEvent.id); +				condLogMsg(debugCalendarSync, "event is still in db:" + \
parsedEvent.id);				 +				this.curItemInListStatus.setAttribute("label", "delete on \
server"); +				condLogMsg(debugCalendarSync, "event deleted locally: " + \
parsedEvent.id); +				this.db[idxEntry][0] = ""; // mark for delete
 				return "DELETEME";
 			}
-
-			// add the new event
-			this.gCalendar.addItem(newEvent, this.gEvents);
 		}
 		else
 		{
 			// event exists in local calendar
-			if (debugCalendarSync)
-				consoleService.logStringMessage("event exists locally:" + newEvent.id);
+			condLogMsg(debugCalendarSync, "event exists locally:" + parsedEvent.id);
 
-			var cdb = getDbEntry (newEvent.id, this.db);
-			var lastSyncEntry = cdb!=-1?this.db[cdb][1]:null;
-			var newSyncEntry = genCalSha1 (newEvent);
-			var curSyncEntry = genCalSha1 (foundEvent);
+			var lastSyncEntry = idxEntry!=-1?this.db[idxEntry][1]:null;
+			var parsedSyncEntry = genCalSha1 (parsedEvent);
+			var foundSyncEntry = genCalSha1 (foundEvent);
 
 			// where did changes happen?
-			if (lastSyncEntry != null && lastSyncEntry != curSyncEntry && lastSyncEntry != \
newSyncEntry) +			if (lastSyncEntry != null && lastSyncEntry != foundSyncEntry && \
lastSyncEntry != parsedSyncEntry)  {
 				// changed locally and on server side
-				if (debugCalendarSync)
-					consoleService.logStringMessage("changed both on server and client:" + \
newEvent.id); +				condLogMsg(debugCalendarSync, "changed both on server and client:" \
                + parsedEvent.id);
 				if (window.confirm("Changes were made on the server and local. Click ok to use \
                the server version.\nClient Event: " + 
-					foundEvent.title + "<"+ foundEvent.id + ">\nServer Event: " + newEvent.title + \
"<"+ newEvent.id + ">")) +					foundEvent.title + "<"+ foundEvent.id + ">\nServer \
Event: " + parsedEvent.title + "<"+ parsedEvent.id + ">"))  {
 					// take event from server
-					if (debugCalendarSync)
-						consoleService.logStringMessage("take event from server:" + newEvent.id);
+					condLogMsg(debugCalendarSync, "take event from server:" + parsedEvent.id);
 
 					var newdb = new Array();
-					newdb.push(newEvent.id);
-					newdb.push(newSyncEntry);
-					if (lastSyncEntry != null) this.db[cdb][0] = ""; // mark for delete
-					
+					newdb.push(parsedEvent.id);
+					newdb.push(parsedSyncEntry);
 					this.db.push(newdb);
+					if (lastSyncEntry != null) this.db[idxEntry][0] = ""; // mark for delete
 	
 					for (var i = 0; i < this.gEvents.events.length; i++)
 					{
-						if (this.gEvents.events[i].id == newEvent.id)
+						if (this.gEvents.events[i].id == parsedEvent.id)
 						{
 							// modify the item
-							this.gCalendar.modifyItem(newEvent, foundEvent, this.gEvents);
-							//this.gEvents.events[i] = newEvent;
-							
+							this.gCalendar.modifyItem(parsedEvent, foundEvent, this.gEvents);
 							//update list item
 							this.curItemInListStatus.setAttribute("label", "update local");
-							
 							return null;
 						}
 					}
@@ -270,15 +258,13 @@
 				else
 				{
 					// put local change to server
-					if (debugCalendarSync)
-					   consoleService.logStringMessage("put event on server:" + newEvent.id);
+					condLogMsg(debugCalendarSync, "put event on server:" + parsedEvent.id);
 
 					var newdb = new Array();
 					newdb.push(foundEvent.id);
-					newdb.push(curSyncEntry);
-					if (lastSyncEntry != null) this.db[cdb][0] = ""; // mark for delete
-
+					newdb.push(foundSyncEntry);
 					this.db.push(newdb);
+					if (lastSyncEntry != null) this.db[idxEntry][0] = ""; // mark for delete
 	
 					var msg = null;
 					if (this.format == "Xml")
@@ -293,7 +279,7 @@
 					}
 
 						// update list item
-						this.curItemInListStatus.setAttribute("label", "update server");
+					this.curItemInListStatus.setAttribute("label", "update on server");
 					
 					// remember this message for update
 					return msg;
@@ -301,52 +287,43 @@
 			}
 			else
 			{
-				if (debugCalendarSync)
-					consoleService.logStringMessage("changed only on one side (if at all):" + \
newEvent.id); +				condLogMsg(debugCalendarSync, "changed only on one side (if at \
                all):" + parsedEvent.id);
 	 			// we got that already, see which is newer and update the message or the event
 				// the sync database might be out-of-date, so we handle a non-existent entry as \
                well
-	 			if (lastSyncEntry == null || (lastSyncEntry == curSyncEntry && lastSyncEntry != \
newSyncEntry)) +	 			if (lastSyncEntry == null || (lastSyncEntry == foundSyncEntry && \
lastSyncEntry != parsedSyncEntry))  {
 					// event has been changed on the server
-					if (debugCalendarSync)
-					   consoleService.logStringMessage("event changed on server:" + newEvent.id);
+					condLogMsg(debugCalendarSync, "event changed on server:" + parsedEvent.id);
 			    
 					var newdb = new Array();
-					newdb.push(newEvent.id);
-					newdb.push(newSyncEntry);
-					if (lastSyncEntry != null) this.db[cdb][0] = ""; // mark for delete
+					newdb.push(parsedEvent.id);
+					newdb.push(parsedSyncEntry);
 					this.db.push(newdb);
+					this.db[idxEntry][0] = ""; // mark for delete
 
 					for (var i = 0; i < this.gEvents.events.length; i++)
 					{
-						if (this.gEvents.events[i].id == newEvent.id)
+						if (this.gEvents.events[i].id == parsedEvent.id)
 						{
 							// modify the item
-							this.gCalendar.modifyItem(newEvent, foundEvent, this.gEvents);
-							//this.gEvents.events[i] = newEvent;
-
+							this.gCalendar.modifyItem(parsedEvent, foundEvent, this.gEvents);
 							// update list item
 							this.curItemInListStatus.setAttribute("label", "update local");
-							 
 							return null;
 						}
 					}
 				}
 				else
 				{
-					if (lastSyncEntry != curSyncEntry && lastSyncEntry == newSyncEntry)
+					if (lastSyncEntry != foundSyncEntry && lastSyncEntry == parsedSyncEntry)
 					{
 						// event has been changed on the client
-						if (debugCalendarSync)
-							consoleService.logStringMessage("event changed on client:" + newEvent.id);
+						condLogMsg(debugCalendarSync, "event changed on client:" + parsedEvent.id);
 						var newdb = new Array();
 						newdb.push(foundEvent.id);
-						newdb.push(curSyncEntry);
-						if (lastSyncEntry != null)
-						{
-							this.db[cdb][0] = ""; // mark for delete
-						}
+						newdb.push(foundSyncEntry);
 						this.db.push(newdb);
+						this.db[idxEntry][0] = ""; // mark for delete
 
 				                var msg = null;
 				                if (this.format == "Xml")
@@ -368,14 +345,13 @@
 				                }
 				
 						// update list item
-						this.curItemInListStatus.setAttribute("label", "update server");
+						this.curItemInListStatus.setAttribute("label", "update on server");
 						
 						// remember this message for update
 						return msg;
 					}
 				}
-				if (debugCalendarSync)
-					consoleService.logStringMessage("no change for event:" + newEvent.id);
+				condLogMsg(debugCalendarSync, "no change for event:" + parsedEvent.id);
  	
 				this.curItemInListStatus.setAttribute("label", "no change");
 			}
@@ -394,15 +370,15 @@
 	 * read the next todo/event and return the content if update needed
 	 */
 	nextUpdate: function () {
-		consoleService.logStringMessage("next update...");
+		condLogMsg(debugCalendarSync, "next update...");
 		// if there happens an exception, we are done
 		if ((this.gEvents == null || this.gCurEvent >= this.gEvents.events.length) && \
(this.gTodo == null || this.gCurTodo >= this.gTodo.length))  {
-			consoleService.logStringMessage("done update...");
+			condLogMsg(debugCalendarSync, "done update...");
 			// we are done
 			return "done";
 		}
-		consoleService.logStringMessage("get event");
+		condLogMsg(debugCalendarSync, "get event");
 		
 		if (this.gEvents != null && this.gCurEvent <= this.gEvents.events.length )
 		{
@@ -410,16 +386,15 @@
 			var msg = null;
 			var writeCur = true;
 		    
-			if (debugCalendarSync)
-				consoleService.logStringMessage("nextUpdate for event:" + cur.id);
-			// check if we have this uid in the messages
+			condLogMsg(debugCalendarSync, "nextUpdate for event:" + cur.id);
+			// check if we have this uid in the messages, skip it if it
+			// has been processed already when reading the IMAP msgs
 			var i;
 			for (i = 0; i < this.folderMessageUids.length; i++)
 			{
 				if (cur.id == this.folderMessageUids[i])
 				{
-					if (debugCalendarSync)
-						consoleService.logStringMessage("event is know from IMAP lookup:" + cur.id);
+					condLogMsg(debugCalendarSync, "event is known from IMAP lookup:" + cur.id);
 					writeCur = false;
 					break;
 				}
@@ -430,16 +405,14 @@
 			// it has been deleted on the server and we dont know about it yet
 			if (writeCur)
 			{
-				if (debugCalendarSync)
-					consoleService.logStringMessage("nextUpdate decided to write event:" + cur.id);
+				condLogMsg(debugCalendarSync, "nextUpdate decided to write event:" + cur.id);
 
 				var curSyncEntry = genCalSha1 (cur);
-				var cdb = getDbEntry (cur.id, this.db);
+				var cdb = getDbEntryIdx (cur.id, this.db);
 				if (cdb != -1)
 				{
-					// we have it in our database
-					if (debugCalendarSync)
-						consoleService.logStringMessage("nextUpdate found -1, better don't write \
event:" + cur.id); +					// we have it in our database - don't write back to server \
but delete locally +					condLogMsg(debugCalendarSync, "nextUpdate assumes 'delete on \
server', better don't write event:" + cur.id);  writeCur = false;
 					this.db[cdb][0] = ""; // mark for delete
 					this.gCalendar.deleteItem(cur, this.gEvents);
@@ -450,25 +423,23 @@
 					this.curItemInListStatus = document.createElement("listcell");
 					this.curItemInListContent = document.createElement("listcell");
 					this.curItemInListId.setAttribute("label", cur.id);
-					this.curItemInListStatus.setAttribute("label", "local delete");
+					this.curItemInListStatus.setAttribute("label", "delete local");
 					this.curItemInListContent.setAttribute("label", cur.title);
 					
-			
 					this.curItemInList.appendChild(this.curItemInListId);
 					this.curItemInList.appendChild(this.curItemInListStatus);
 					this.curItemInList.appendChild(this.curItemInListContent);
 					
 					this.itemList.appendChild(this.curItemInList);
 				}
-				// ok its NOT in our internal db... add it
 				else
 				{
+    				// ok its NOT in our internal db... add it
 					var newdb = new Array();
 					newdb.push(cur.id);
 					newdb.push(curSyncEntry);
 					this.db.push(newdb);
 					
-					
 					// create a new item in the itemList for display
 					this.curItemInList = document.createElement("listitem");
 					this.curItemInListId = document.createElement("listcell");
@@ -490,10 +461,8 @@
 		
 			if (writeCur)
 			{
-				if (debugCalendarSync)
-					consoleService.logStringMessage("nextUpdate really writes event:" + cur.id);
-
-				// and write the message
+				condLogMsg(debugCalendarSync, "nextUpdate really writes event:" + cur.id);
+				// and now really write the message
 		                var msg = null;
 		                if (this.format == "Xml")
 		                {
@@ -512,9 +481,8 @@
 					msg += encodeQuoted(encode_utf8(calComp.serializeToICS()));
 					msg += "\n\n";
 				}
-				consoleService.logStringMessage("New event:\n" + msg);
-				if (debugCalendarSync)
-					consoleService.logStringMessage("nextUpdate puts event into db (2):" + cur.id);
+				condLogMsg(debugCalendarSync, "New event:\n" + msg);
+				condLogMsg(debugCalendarSync, "nextUpdate puts event into db (2):" + cur.id);
 				// add the new event into the db
 				var curSyncEntry = genCalSha1 (cur);
 				var newdb = new Array();
@@ -538,7 +506,7 @@
 			{
 				if (cur.id == this.folderMessageUids[i])
 				{
-					consoleService.logStringMessage("we got this todo: " + cur.id);
+					condLogMsg(debugCalendarSync, "we got this todo: " + cur.id);
 					writeCur = false;
 					break;
 				}
@@ -551,7 +519,7 @@
 				msg += encodeQuoted(encode_utf8(cur.getIcalString()));
 				msg += "\n\n";
 				
-		    consoleService.logStringMessage("New event [" + msg + "]");
+    		    condLogMsg(debugCalendarSync, "New event [" + msg + "]");
 			}
 		}
 		
diff -U 3 -b -d -r -N -- synckolab/settings.js my-synckolab/settings.js
--- synckolab/settings.js	2006-11-03 16:43:40.000000000 +0100
+++ my-synckolab/settings.js	2007-01-16 12:12:16.000000000 +0100
@@ -470,7 +470,7 @@
 			cur = cur.nextSibling;
 		}
 						
-		// the address book
+		// the calendar
 		var ab = pref.getCharPref("SyncKolab."+selectedCalConfig+".Calendar");
 		actList = document.getElementById("calURL");
 		// go through the items
@@ -487,7 +487,7 @@
 			cur = cur.nextSibling;
 		}
 
-		var calFormat = pref.getCharPref("SyncKolab."+selectedConConfig+".CalendarFormat");
 +		var calFormat = pref.getCharPref("SyncKolab."+selectedCalConfig+".CalendarFormat");
  actList = document.getElementById("calFormat");
 		// go through the items
 		var cur = actList.firstChild.firstChild;
@@ -509,7 +509,7 @@
 		updateCalFolder (act);
 		updateCalFolder (act);
 		var tree= document.getElementById ("calImapFolder");
-		var treei = tree.view.getIndexOfItem(document.getElementById(sCurFolder));
+		var treei = tree.view.getIndexOfItem(document.getElementById(sCurFolder+"c"));
 		tree.view.selection.select(treei); 
 		tree.boxObject.scrollToRow(treei);
 
@@ -656,6 +656,8 @@
 	var gAccountManager = \
Components.classes['@mozilla.org/messenger/account-manager;1'].getService(Components.interfaces.nsIMsgAccountManager);
  for (var i = 0; i < gAccountManager.allServers.Count(); i++)
 	{
+		try
+		{
 		var account = gAccountManager.allServers.GetElementAt(i).QueryInterface(Components.interfaces.nsIMsgIncomingServer);
  if (account.rootMsgFolder.baseMessageURI == act)
 		{
@@ -672,15 +674,17 @@
 				cnode = cnode.nextSibling;
 			}
 
+	
 			// ok show some folders:
 			var tChildren = document.createElement("treechildren");
 			cfold.appendChild(tChildren);
-
 			updateFolderElements (account.rootFolder, tChildren, "c");
 			return;			
 			
 		}
 	}
+		catch (ex){}
+	}
 }
 
 function saveCalPrefs () {
diff -U 3 -b -d -r -N -- synckolab/synckolab.js my-synckolab/synckolab.js
--- synckolab/synckolab.js	2006-11-03 16:43:40.000000000 +0100
+++ my-synckolab/synckolab.js	2007-01-18 12:44:16.000000000 +0100
@@ -33,6 +33,7 @@
  */
 // global variables 
 
+var debugSync = false;
 
 // print debug information out to console
 var consoleService = \
Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
 @@ -349,7 +350,7 @@
  */
 function parseMessageRunner ()
 {
-   	consoleService.logStringMessage("parsing message...");
+   	condLogMsg(debugSync, "parsing message...");
 	
 	// fix the message for line truncs (last char in line is =)
 	fileContent = fileContent.replace(/=\n/g, "");
@@ -360,12 +361,12 @@
 	if (content != null)
 	{
 		if (content == "DELETEME")
-			consoleService.logStringMessage("updating and deleting [" + gSync.folderMsgURI \
+"#"+gCurMessageKey + "]"); +			condLogMsg(debugSync, "updating and deleting [" + \
gSync.folderMsgURI +"#"+gCurMessageKey + "]");  else
-			consoleService.logStringMessage("updating [" + gSync.folderMsgURI \
+"#"+gCurMessageKey + "]"); +			condLogMsg(debugSync, "updating [" + \
gSync.folderMsgURI +"#"+gCurMessageKey + "]");  \
updateMessages.push(gSync.folderMsgURI +"#"+gCurMessageKey);   \
                updateMessagesContent.push(content); 
-		consoleService.logStringMessage("changed msg #" + updateMessages.length);
+		condLogMsg(debugSync, "changed msg #" + updateMessages.length);
 	}
 	
 	
@@ -393,7 +394,7 @@
 	// do step 5
 	curStep = 5;
 	writeDone = false;
-    consoleService.logStringMessage("parseFolderToAddressFinish");
+    condLogMsg(debugSync, "parseFolderToAddressFinish");
 
 	meter.setAttribute("value", "60%");
 	statusMsg.value = "Writing changed cards...";
@@ -403,23 +404,23 @@
 
 function updateContent()
 {
-    consoleService.logStringMessage("updating content:");
+    condLogMsg(debugSync, "updating content:");
 	// first lets delete the old messages
 	if (gSync.gSaveImap && updateMessages.length > 0) 
 	{
 		try
 		{
-			consoleService.logStringMessage("deleting changed messages..");
+			condLogMsg(debugSync, "deleting changed messages..");
 			var list = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
  for (var i = 0; i < updateMessages.length; i++)
 			{
-				consoleService.logStringMessage("deleting [" + updateMessages[i] + "]");
+				condLogMsg(debugSync, "deleting [" + updateMessages[i] + "]");
 				var hdr = gMessageService.messageURIToMsgHdr(updateMessages[i]);
 				list.AppendElement(hdr);		
 		    
 			}
 			gSync.folder.deleteMessages (list, msgWindow, true, false, null, true);		
-			consoleService.logStringMessage("done..");
+			condLogMsg(debugSync, "done..");
 		}
 		catch (ex)
 		{
@@ -445,7 +446,7 @@
 		{
 			// write the message in the temp file
 			var sfile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
                
-			consoleService.logStringMessage("adding [" + content + "] to messages");
+			condLogMsg(debugSync, "adding [" + content + "] to messages");
 			// temp path
 			sfile.initWithPath(gTmpFile);
 			if (sfile.exists()) 
@@ -475,13 +476,13 @@
 
 function updateContentAfterSave ()
 {
-	consoleService.logStringMessage("starting update content...");
+	condLogMsg(debugSync, "starting update content...");
 	curStep = 6;
 	writeDone = false;
 	
 	if (!gSync.initUpdate())
 	{
-		consoleService.logStringMessage("Nothing there to update...");
+		condLogMsg(debugSync, "Nothing there to update...");
 		writeContentAfterSave ();
 	}
 
@@ -529,7 +530,7 @@
 		stream.close();
 		
 		// write the temp file back to the original directory
-		consoleService.logStringMessage("WriteContent Writing...");
+		condLogMsg(debugSync, "WriteContent Writing...");
 		copyToFolder (gTmpFile, gSync.folder.folderURL);
 	}
 	else
diff -U 3 -b -d -r -N -- synckolab/tools.js my-synckolab/tools.js
--- synckolab/tools.js	2006-11-03 16:43:39.000000000 +0100
+++ my-synckolab/tools.js	2006-12-28 10:44:10.000000000 +0100
@@ -101,7 +101,7 @@
 /**
  * returns the position of this entry in the db
  */
-function getDbEntry (key, db)
+function getDbEntryIdx (key, db)
 {
  	for (var i = 0; i < db.length; i++)
 		if (db[i][0] == key)
@@ -130,7 +130,6 @@
 	s = "\n\n";
 	stream.write(s, s.length);
 	stream.close();
-
 }
 
 
@@ -971,3 +970,12 @@
 	
 	return msg;
 }
+
+/**
+ *
+ */
+function condLogMsg (condition, msg)
+{
+	if (condition)
+		consoleService.logStringMessage(msg);
+}
\ No newline at end of file



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic