Fix bug 481825 - No loading of CalDav Calendar due to errors regarding parsing eTags. r=dbo
authorPhilipp Kewisch <mozilla@kewis.ch>
Fri, 20 Mar 2009 10:54:50 +0100
changeset 2252 2ebb18326ffb5c5acf9e57d8322d36ca11054f93
parent 2251 73e75f355c99e334cbc03fd6dd5349c39bc531bc
child 2253 ab06268403cbd964486cf92032ea5668fbe00114
push idunknown
push userunknown
push dateunknown
reviewersdbo
bugs481825
Fix bug 481825 - No loading of CalDav Calendar due to errors regarding parsing eTags. r=dbo
calendar/providers/caldav/calDavCalendar.js
calendar/providers/caldav/calDavRequestHandlers.js
--- a/calendar/providers/caldav/calDavCalendar.js
+++ b/calendar/providers/caldav/calDavCalendar.js
@@ -883,17 +883,18 @@ calDavCalendar.prototype = {
                 return;
             }
 
             var ctag = multistatus..CS::getctag.toString();
             if (!ctag.length || ctag != thisCalendar.mCtag) {
                 // ctag mismatch, need to fetch calendar-data
                 thisCalendar.mCtag = ctag;
                 thisCalendar.mTargetCalendar.setMetaData("ctag", ctag);
-                thisCalendar.getUpdatedItems(this.calendarUri, aChangeLogListener);
+                thisCalendar.getUpdatedItems(thisCalendar.calendarUri,
+                                             aChangeLogListener);
                 if (thisCalendar.verboseLogging()) {
                     cal.LOG("CalDAV: ctag mismatch on refresh, fetching data for " +
                             "calendar " + thisCalendar.name);
                              
                 }
             } else {
                 if (thisCalendar.verboseLogging()) {
                     cal.LOG("CalDAV: ctag matches, no need to fetch data for " +
@@ -1080,36 +1081,41 @@ calDavCalendar.prototype = {
 
                     var etag = response..D::["getetag"].toString();
                     var href = response..D::["href"].toString();
                     var resourcePath = thisCalendar.ensurePath(href);
                     var calData = response..C::["calendar-data"];
 
                     var parser = Components.classes["@mozilla.org/calendar/ics-parser;1"]
                                            .createInstance(Components.interfaces.calIIcsParser);
-                    parser.parseString(calData, null);
+                    try {
+                        parser.parseString(calData, null);
+                    } catch (e) {
+                        // Warn and continue.
+                        // TODO As soon as we have activity manager integration,
+                        // this should be replace with logic to notify that a
+                        // certain event failed.
+                        cal.WARN("Failed to parse item: " + response.toXMLString());
+                        continue;
+                    }
                     // with CalDAV there really should only be one item here
                     var items = parser.getItems({});
                     var propertiesList = parser.getProperties({});
                     var method;
                     for each (var prop in propertiesList) {
                         if (prop.propertyName == "METHOD") {
                             method = prop.value;
                             break;
                         }
                     }
                     var isReply = (method == "REPLY");
                     var item = items[0];
                     if (!item) {
-                        thisCalendar.notifyOperationComplete(aListener,
-                                                             Components.results.NS_ERROR_FAILURE,
-                                                             Components.interfaces.calIOperationListener.GET,
-                                                             null,
-                                                             "failed to retrieve item");
-                        return;
+                        cal.WARN("Failed to parse item: " + response.toXMLString());
+                        continue;
                     }
 
                     item.calendar = thisCalendar.superCalendar;
                     if (isReply && thisCalendar.isInbox(aUri.spec)) {
                         if (thisCalendar.hasScheduling) {
                             thisCalendar.processItipReply(item, resourcePath);
                         }
                         continue;
--- a/calendar/providers/caldav/calDavRequestHandlers.js
+++ b/calendar/providers/caldav/calDavRequestHandlers.js
@@ -272,19 +272,19 @@ etagsHandler.prototype = {
     endElement: function eH_endElement(aUri, aLocalName, aQName) {
         switch (aLocalName) {
             case "response":
                 this.tag = null;
                 let r = this.currentResponse;
                 if (r.status.indexOf(" 200") > 0 &&
                     r.getetag && r.getetag.length &&
                     r.href && r.href.length &&
-                    !r.getcontenttype || r.getcontenttype.length) {
+                    r.getcontenttype && r.getcontenttype.length) {
                     let href;
-                    if (r.getcontenttype == "message/rfc822") {
+                    if (r.getcontenttype.substr(0, 14) == "message/rfc822") {
                         // workaround for a Scalix bug which causes incorrect
                         // contenttype to be returned.
                         r.getcontenttype = "text/calendar";
                     }
 
                     if (r.getcontenttype.substr(0,13) == "text/calendar") {
                         // Only handle calendar items