summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniko <niko>2012-10-28 12:56:03 (GMT)
committerniko <niko>2012-10-28 12:56:03 (GMT)
commitcd63dc9b7e9a9adb384781d3707b75cdfdf311e3 (patch)
treeec53824ad43ce8d3bd857dfe27432bd79fc08994
parentf793711f7edba878e077ddc1ec5d00a10df4f31a (diff)
downloadsynckolab-cd63dc9b7e9a9adb384781d3707b75cdfdf311e3.tar.gz
fix autosync again
-rw-r--r--src/chrome/content/synckolab/calendar.js4
-rw-r--r--src/chrome/content/synckolab/calendarTools.js40
-rw-r--r--src/chrome/content/synckolab/synckolab.js12
-rw-r--r--src/chrome/content/synckolab/tools/text.js68
-rw-r--r--test/synckolab/parser/kolab2/calendarTest.js3
-rw-r--r--test/synckolab/parser/kolab2/json/event-recurr.json28
-rw-r--r--test/synckolab/parser/kolab2/raw/event-recurr.eml48
-rw-r--r--test/synckolab/parser/kolab2/xml/event-recurr.xml19
8 files changed, 179 insertions, 43 deletions
diff --git a/src/chrome/content/synckolab/calendar.js b/src/chrome/content/synckolab/calendar.js
index 7e9a0ba..4c9685d 100644
--- a/src/chrome/content/synckolab/calendar.js
+++ b/src/chrome/content/synckolab/calendar.js
@@ -449,6 +449,8 @@ synckolab.Calendar = {
return;
}
+ synckolab.tools.logMessage("triggered add message for " + message.config.name, synckolab.global.LOG_DEBUG + synckolab.global.LOG_CAL);
+
// parse the content
var newEvent = synckolab.calendarTools.message2json(message.fileContent, message.config.type === "task");
@@ -493,6 +495,8 @@ synckolab.Calendar = {
return;
}
+ synckolab.tools.logMessage("triggered delete message for " + message.config.name, synckolab.global.LOG_DEBUG + synckolab.global.LOG_CAL);
+
var messageFields = new synckolab.dataBase();
// parse the content
diff --git a/src/chrome/content/synckolab/calendarTools.js b/src/chrome/content/synckolab/calendarTools.js
index d1a55b2..fc56eb0 100644
--- a/src/chrome/content/synckolab/calendarTools.js
+++ b/src/chrome/content/synckolab/calendarTools.js
@@ -126,14 +126,14 @@ synckolab.calendarTools = {
getEndDate: function (cur, tasks)
{
if (tasks === true && cur.dueDate){
- return cur.dueDate.jsDate;
+ return synckolab.tools.text.getJSDateFromICalDateTime(cur.dueDate);
}
if (tasks === false && cur.untilDate) {
- return cur.untilDate.jsDate;
+ return synckolab.tools.text.getJSDateFromICalDateTime(cur.untilDate);
}
if (tasks === false && cur.endDate) {
- return cur.endDate.jsDate;
+ return synckolab.tools.text.getJSDateFromICalDateTime(cur.endDate);
}
return null;
@@ -351,7 +351,7 @@ synckolab.calendarTools = {
* This functions checks if two event json objects are equals
*/
synckolab.calendarTools.equalsEvent = function (a, b) {
- return synckolab.tools.equalsObject(a, b);
+ return synckolab.tools.equalsObject(a, b, {revision:true});
};
/**
@@ -432,7 +432,8 @@ synckolab.calendarTools.event2json = function (event, syncTasks) {
}
var jobj = {
synckolab : synckolab.config.version, // synckolab version
- type : "calendar"
+ type : "calendar",
+ revision: 0
};
if(syncTasks === true) {
@@ -693,7 +694,7 @@ synckolab.calendarTools.event2json = function (event, syncTasks) {
}
if (endDate) {
- jobj.recurrence.untilDate = synckolab.tools.text.date2String(endDate.jsDate);
+ jobj.recurrence.untilDate = synckolab.tools.text.calDateTime2String(endDate, false);
}
}
@@ -704,7 +705,7 @@ synckolab.calendarTools.event2json = function (event, syncTasks) {
{
var item = items[i];
if (item.isNegative) {
- jobj.recurrence.exclusion.push(synckolab.tools.text.calDateTime2String(item.date, true));
+ jobj.recurrence.exclusion.push(synckolab.tools.text.calDateTime2String(item.date, false));
}
}
}
@@ -2001,16 +2002,24 @@ synckolab.calendarTools.json2kolab3 = function (jobj, syncTasks, email) {
// tasks have a status
xml += synckolab.tools.text.nodeContainerWithContent("status", "text", jobj.status, false);
xml += synckolab.tools.text.nodeContainerWithContent("completed", "text", jobj.completed, false);
- xml += synckolab.tools.text.nodeContainerWithContent("dtstart", "date-time", jobj.startDate.dateTime, false);
- xml += synckolab.tools.text.nodeContainerWithContent("dtdue", "date-time", jobj.endDate.dateTime, false);
+ if (jobj.startDate.dateTime) {
+ xml += synckolab.tools.text.nodeContainerWithContent("dtstart", "date-time", jobj.startDate.dateTime.replace(/[\-:]/g, ""), false);
+ }
+ if (jobj.endDate.dateTime) {
+ xml += synckolab.tools.text.nodeContainerWithContent("dtdue", "date-time", jobj.endDate.dateTime.replace(/[\-:]/g, ""), false);
+ }
xml += synckolab.tools.text.nodeContainerWithContent("priority", "text", jobj.priority, false);
// xml += " <completed-date>" + synckolab.tools.text.calDateTime2String(completedDate, true) + "</completed-date>\n";
}
else
{
- xml += synckolab.tools.text.nodeContainerWithContent("dtstart", "date-time", jobj.startDate.dateTime, false);
- xml += synckolab.tools.text.nodeContainerWithContent("dtend", "date-time", jobj.endDate.dateTime, false);
+ if (jobj.startDate.dateTime) {
+ xml += synckolab.tools.text.nodeContainerWithContent("dtstart", "date-time", jobj.startDate.dateTime.replace(/[\-:]/g, ""), false);
+ }
+ if (jobj.endDate.dateTime) {
+ xml += synckolab.tools.text.nodeContainerWithContent("dtend", "date-time", jobj.endDate.dateTime.replace(/[\-:]/g, ""), false);
+ }
}
@@ -2095,7 +2104,8 @@ synckolab.calendarTools.json2kolab3 = function (jobj, syncTasks, email) {
if(jobj.recurrence.exclusion) {
xml+= " <exdate>\n";
for(i=0; i < jobj.recurrence.exclusion.length; i++) {
- xml += synckolab.tools.text.nodeWithContent("date", jobj.recurrence.exclusion[i], true);
+ // convert longdate to compact one: 2005-03-30T15:28:52Z -> 20050330T152852Z
+ xml += synckolab.tools.text.nodeWithContent("date", jobj.recurrence.exclusion[i].replace(/[\-:]/g, ""), true);
}
xml+= " </exdate>\n";
}
@@ -2265,12 +2275,10 @@ synckolab.calendarTools.ical2event = function (content, todo)
var subComp = event.getFirstSubcomponent("ANY");
while (subComp) {
if (subComp.componentType === "VEVENT") {
- event = Components.classes["@mozilla.org/calendar/event;1"]
- .createInstance(Components.interfaces.calIEvent);
+ event = Components.classes["@mozilla.org/calendar/event;1"].createInstance(Components.interfaces.calIEvent);
break;
} else if (subComp.componentType === "VTODO") {
- event = Components.classes["@mozilla.org/calendar/todo;1"]
- .createInstance(Components.interfaces.calITodo);
+ event = Components.classes["@mozilla.org/calendar/todo;1"].createInstance(Components.interfaces.calITodo);
break;
} else if (subComp.componentType !== "VTIMEZONE") {
synckolab.tools.logMessage("unable to parse event 2: " + content, synckolab.global.LOG_CAL + synckolab.global.LOG_ERROR);
diff --git a/src/chrome/content/synckolab/synckolab.js b/src/chrome/content/synckolab/synckolab.js
index fda94f6..28fa53f 100644
--- a/src/chrome/content/synckolab/synckolab.js
+++ b/src/chrome/content/synckolab/synckolab.js
@@ -888,7 +888,7 @@ synckolab.main.getMessage = function()
/**
*
- * @param content the content structure contianing the message key and the buffer for the content
+ * @param content the content structure containing the message key and the buffer for the content
*/
synckolab.main.getMessageIntoContent = function(content) {
var aurl = {};
@@ -911,15 +911,13 @@ synckolab.main.getMessageIntoContent = function(content) {
onStartRequest: function (request, context) {
},
onStopRequest: function (aRequest, aContext, aStatusCode) {
- synckolab.tools.logMessage("got Message [" + content.message + "]:\n" + content.fileContent, synckolab.global.LOG_DEBUG);
-
+ synckolab.tools.logMessage("synckolab.main.getMessageIntoContent [" + content.message + "]:\n" + content.fileContent, synckolab.global.LOG_DEBUG);
+
// parse the mail
- synckolab.main.currentMessage.fileContent = synckolab.tools.parseMail(content.fileContent);
+ content.fileContent = synckolab.tools.parseMail(content.fileContent);
// make sure we dont come into an endless loop here
- synckolab.global.triggerRunning = true;
- content.nextFunc(synckolab.main.currentMessage.fileContent);
- synckolab.global.triggerRunning = false;
+ content.nextFunc(content);
}
}, false, null, msgWindow, aurl
);
diff --git a/src/chrome/content/synckolab/tools/text.js b/src/chrome/content/synckolab/tools/text.js
index 522cfb2..e75bfd5 100644
--- a/src/chrome/content/synckolab/tools/text.js
+++ b/src/chrome/content/synckolab/tools/text.js
@@ -353,33 +353,66 @@ synckolab.tools.text = {
},
+ /**
+ * convert iCalDateTime to js: http://doxygen.db48x.net/mozilla-full/html/d0/d83/interfacecalIDateTime.html
+ */
+ getJSDateFromICalDateTime: function (cal) {
+ var dt;
+
+ if (this.isDate) {
+ dt = new Date(cal.year,
+ cal.month,
+ cal.day);
+ } else {
+ dt = new Date(cal.jsDate);
+ //dt.setTime(dt.getTime() + cal.timezoneOffset);
+ }
+ synckolab.tools.logMessage("CONVERTING: " + cal.hour + "/"+ dt.getUTCHours() +" - " + cal.timezoneOffset + " - " + cal.jsDate + " vs. " + dt, synckolab.global.LOG_CAL + synckolab.global.LOG_WARNING);
+ return dt;
+ },
+
// produces: 2005-03-30
date2String : function (datetime, normal, compact) {
if (!datetime) {
return '';
}
+
+ // if we do not have a javascript date
+ if(!datetime.getTime) {
+ // calIDateTime - http://doxygen.db48x.net/mozilla-full/html/d0/d83/interfacecalIDateTime.html
+ datetime = this.getJSDateFromICalDateTime(datetime);
+ }
- if (compact) {
- if (normal) {
- return datetime.getFullYear() + (datetime.getMonth() + 1 < 10 ? "0" : "") + (datetime.getMonth() + 1) + (datetime.getDate() < 10 ? "0" : "") + datetime.getDate();
- } else {
- return datetime.getUTCFullYear() + (datetime.getUTCMonth() + 1 < 10 ? "0" : "") + (datetime.getUTCMonth() + 1) + (datetime.getUTCDate() < 10 ? "0" : "") + datetime.getUTCDate();
- }
- } else {
- if (normal) {
- return datetime.getFullYear() + "-" + (datetime.getMonth() + 1 < 10 ? "0" : "") + (datetime.getMonth() + 1) + "-" + (datetime.getDate() < 10 ? "0" : "") + datetime.getDate();
- } else {
- return datetime.getUTCFullYear() + "-" + (datetime.getUTCMonth() + 1 < 10 ? "0" : "") + (datetime.getUTCMonth() + 1) + "-" + (datetime.getUTCDate() < 10 ? "0" : "") + datetime.getUTCDate();
- }
+ var strDate;
+ if (normal) {
+ strDate = datetime.getFullYear() + "-" + (datetime.getMonth() + 1 < 10 ? "0" : "") + (datetime.getMonth() + 1) + "-" + (datetime.getDate() < 10 ? "0" : "") + datetime.getDate();
+ } else {
+ strDate = datetime.getUTCFullYear() + "-" + (datetime.getUTCMonth() + 1 < 10 ? "0" : "") + (datetime.getUTCMonth() + 1) + "-" + (datetime.getUTCDate() < 10 ? "0" : "") + datetime.getUTCDate();
+ }
+
+ if(compact) {
+ // compact: remove seperators
+ return strDate.replace(/[\-:]/g, "");
}
+ return strDate;
},
// produces 15:28:52
time2String : function (datetime, compact) {
+ // if we do not have a javascript date
+ if(!datetime.getTime) {
+ // calIDateTime - http://doxygen.db48x.net/mozilla-full/html/d0/d83/interfacecalIDateTime.html
+ datetime = this.getJSDateFromICalDateTime(datetime);
+ }
+
+ var strDate= (datetime.getUTCHours() < 10 ? "0" : "") + datetime.getUTCHours() + ":" + (datetime.getUTCMinutes() < 10 ? "0" : "") + datetime.getUTCMinutes() + ":" + (datetime.getUTCSeconds() < 10 ? "0" : "") + datetime.getUTCSeconds();
+
if(compact) {
- return (datetime.getUTCHours() < 10 ? "0" : "") + datetime.getUTCHours() + (datetime.getUTCMinutes() < 10 ? "0" : "") + datetime.getUTCMinutes() + (datetime.getUTCSeconds() < 10 ? "0" : "") + datetime.getUTCSeconds();
+ // compact: remove seperators
+ return strDate.replace(/[:]/g, "");
}
- return (datetime.getUTCHours() < 10 ? "0" : "") + datetime.getUTCHours() + ":" + (datetime.getUTCMinutes() < 10 ? "0" : "") + datetime.getUTCMinutes() + ":" + (datetime.getUTCSeconds() < 10 ? "0" : "") + datetime.getUTCSeconds();
+
+ return strDate;
},
// produces: 2005-03-30T15:28:52Z for allday = false,
@@ -389,14 +422,11 @@ synckolab.tools.text = {
return "";
}
- var datetime = val.jsDate ? val.jsDate: val;
- //alert("EVENT TIME: " + datetime);
-
// make sure not to use UTC for all-day events
- var resultstring = this.date2String(datetime, false, compact);
+ var resultstring = this.date2String(val, true, compact);
//if (!allday) {
resultstring += 'T';
- resultstring += this.time2String(datetime, compact);
+ resultstring += this.time2String(val, compact);
resultstring += 'Z';
//}
return resultstring;
diff --git a/test/synckolab/parser/kolab2/calendarTest.js b/test/synckolab/parser/kolab2/calendarTest.js
index c4fcffc..3208bbc 100644
--- a/test/synckolab/parser/kolab2/calendarTest.js
+++ b/test/synckolab/parser/kolab2/calendarTest.js
@@ -12,10 +12,11 @@ load("test/lib/testOverride.js");
test("kolab3 synckolab.addressbookTools.parseMessageContent", function(){
equal(null, synckolab.calendarTools.message2json(null), "parsing a null message");
- var testFiles = [{name:"task-alarm",task:true},{name:"task-due",task:true},{name:"task-progress",task:true},{name:"task-recurr",task:true}
+ var testFiles = [{name:"event-recurr",task:false},{name:"task-alarm",task:true},{name:"task-due",task:true},{name:"task-progress",task:true},{name:"task-recurr",task:true}
];
var content, entry, jsonEntry;
+ synckolab.config.DEBUG_SYNCKOLAB_LEVEL = synckolab.global.LOG_ALL + synckolab.global.LOG_DEBUG;
for(var i = 0; i < testFiles.length; i++) {
var src = testFiles[i];
diff --git a/test/synckolab/parser/kolab2/json/event-recurr.json b/test/synckolab/parser/kolab2/json/event-recurr.json
new file mode 100644
index 0000000..ce09a2a
--- /dev/null
+++ b/test/synckolab/parser/kolab2/json/event-recurr.json
@@ -0,0 +1,28 @@
+{
+ "synckolab": "2.9.0",
+ "type": "calendar",
+ "startDate": {
+ "dateTime": "2012-03-12T10:00:00Z",
+ "tz": null
+ },
+ "endDate": {
+ "dateTime": "2012-03-12T11:00:00Z",
+ "tz": null
+ },
+ "uid": "ec80aeec-1030-4ba4-bac5-8352b2845e55",
+ "title": "Jour Fixe Administration",
+ "body": "Event is CONFIDENTIAL!",
+ "sensitivity": "confidential",
+ "location": "Büro Boris, 3.OG",
+ "showTimeAs": "busy",
+ "recurrence": {
+ "cycle": "weekly",
+ "days": [
+ "sunday"
+ ],
+ "interval": 2,
+ "count": 0,
+ "untilDate": "2013-02-26",
+ "exclusion": []
+ }
+} \ No newline at end of file
diff --git a/test/synckolab/parser/kolab2/raw/event-recurr.eml b/test/synckolab/parser/kolab2/raw/event-recurr.eml
new file mode 100644
index 0000000..6d95e04
--- /dev/null
+++ b/test/synckolab/parser/kolab2/raw/event-recurr.eml
@@ -0,0 +1,48 @@
+From: email@no.tld
+Reply-To:
+Bcc:
+To: synckolab@no.tld
+Subject: ec80aeec-1030-4ba4-bac5-8352b2845e55
+Date: Sun, 28 Oct 2012 11:45:53 +0100
+Content-Type: Multipart/Mixed;boundary="Boundary-00=6301B888B4E27B4C"
+User-Agent: SyncKolab 2.9.0
+X-Kolab-Type: application/x-vnd.kolab.event
+
+--Boundary-00=6301B888B4E27B4C
+Content-Type: Text/Plain;
+ charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+This is a Kolab Groupware object.
+To view this object you will need an email client that can understand the Kolab Groupware format.
+For a list of such email clients please visit
+http://kolab.org/content/kolab-clients
+---
+Summary: Jour Fixe Administration
+Event is CONFIDENTIAL!
+B�ro Boris, 3.OG
+---
+
+Notice:
+The information above is only valid, if no other client than synckolab updated this message. (ie. a client that updates the attachment but not the message)
+
+--Boundary-00=6301B888B4E27B4C
+Content-Type: application/x-vnd.kolab.event;
+ name="kolab.xml"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment;
+ filename="kolab.xml"
+
+PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPGV2ZW50IHZlcnNpb249
+IjEuMCIgPgogPHByb2R1Y3QtaWQ+U3luY2tvbGFiIDIuOS4wLCBDYWxlbmRhciBTeW5jPC9w
+cm9kdWN0LWlkPgogIDx1aWQ+ZWM4MGFlZWMtMTAzMC00YmE0LWJhYzUtODM1MmIyODQ1ZTU1
+PC91aWQ+CiAgPHN0YXJ0LWRhdGU+MjAxMi0wMy0xMlQxMDowMDowMFo8L3N0YXJ0LWRhdGU+
+CiAgPGVuZC1kYXRlPjIwMTItMDMtMTJUMTE6MDA6MDBaPC9lbmQtZGF0ZT4KICA8c3VtbWFy
+eT5Kb3VyIEZpeGUgQWRtaW5pc3RyYXRpb248L3N1bW1hcnk+CiAgPGJvZHk+RXZlbnQgaXMg
+Q09ORklERU5USUFMITwvYm9keT4KICA8c2Vuc2l0aXZpdHk+Y29uZmlkZW50aWFsPC9zZW5z
+aXRpdml0eT4KICA8bG9jYXRpb24+QsO8cm8gQm9yaXMsIDMuT0c8L2xvY2F0aW9uPgogIDxz
+aG93LXRpbWUtYXM+YnVzeTwvc2hvdy10aW1lLWFzPgogPHJlY3VycmVuY2UgY3ljbGU9Indl
+ZWtseSI+CiAgPGRheT5zdW5kYXk8L2RheT4KICA8aW50ZXJ2YWw+MjwvaW50ZXJ2YWw+CiAg
+PHJhbmdlIHR5cGU9ImRhdGUiPjIwMTMtMDItMjY8L3JhbmdlPgogPC9yZWN1cnJlbmNlPgog
+PHJldmlzaW9uPjA8L3JldmlzaW9uPgo8L2V2ZW50Pgo=
+--Boundary-00=6301B888B4E27B4C--
diff --git a/test/synckolab/parser/kolab2/xml/event-recurr.xml b/test/synckolab/parser/kolab2/xml/event-recurr.xml
new file mode 100644
index 0000000..c4a8b41
--- /dev/null
+++ b/test/synckolab/parser/kolab2/xml/event-recurr.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<event version="1.0" >
+ <product-id>Synckolab 2.9.0, Calendar Sync</product-id>
+ <uid>ec80aeec-1030-4ba4-bac5-8352b2845e55</uid>
+ <revision>0</revision>
+ <start-date>2012-03-12T10:00:00Z</start-date>
+ <end-date>2012-03-12T11:00:00Z</end-date>
+ <summary>Jour Fixe Administration</summary>
+ <body>Event is CONFIDENTIAL!</body>
+ <sensitivity>confidential</sensitivity>
+ <location>Büro Boris, 3.OG</location>
+ <show-time-as>busy</show-time-as>
+ <recurrence cycle="weekly">
+ <day>sunday</day>
+ <interval>2</interval>
+ <range type="date">2013-02-26</range>
+ </recurrence>
+ <revision>0</revision>
+</event>