summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chrome/content/synckolab/addressbook.js102
-rw-r--r--src/chrome/content/synckolab/addressbookTools.js41
-rw-r--r--src/install.rdf2
-rw-r--r--test/suite.js4
-rw-r--r--test/synckolab/parser/kolab2/json/list.test.json4
-rw-r--r--test/synckolab/parser/kolab2/raw/list.test.xml6
6 files changed, 116 insertions, 43 deletions
diff --git a/src/chrome/content/synckolab/addressbook.js b/src/chrome/content/synckolab/addressbook.js
index cec3d95..6176b5f 100644
--- a/src/chrome/content/synckolab/addressbook.js
+++ b/src/chrome/content/synckolab/addressbook.js
@@ -64,6 +64,8 @@ synckolab.AddressBook = {
forceServerCopy: false,
forceLocalCopy: false,
+
+ processedIds: [], // remember all processed ids to remove duplicates
/**
* add the address book specific configuration to the config object
@@ -277,7 +279,6 @@ synckolab.AddressBook = {
synckolab.tools.fillMessageLookup(cConfig.msgList, config, synckolab.addressbookTools.parseMessageContent);
}
-
synckolab.global.triggerRunning = true;
// get the dbfile from the local disk
@@ -361,6 +362,8 @@ synckolab.AddressBook = {
// get the sync config
this.gConfig = config;
+ // clear the already processed ids
+ this.processedIds = [];
// clean out cardDb to avoid conflicts with autosync
this.gConfig.cardDb = null;
@@ -476,7 +479,9 @@ synckolab.AddressBook = {
message.config.cardDb.put(cUID, card);
}
}
- message.config.addressBook.addMailList(synckolab.addressbookTools.createTBirdObject(newCard, message.config.cardDb));
+ // add the mailing list: this will also check each entry and link it - if not create it
+ synckolab.addressbookTools.addMailingList(message.config.addressBook, newCard, message.config.cardDb);
+
// also add to the hash-database
//this.gCardDB.put(this.tools.getUID(newCard), newCard);
}
@@ -633,6 +638,7 @@ synckolab.AddressBook = {
// parse the new item
newCard = this.tools.parseMessageContent(fileContent);
+
if (newCard && newCard.isMailList)
{
synckolab.tools.logMessage("got mailing list " + this.tools.getUID(newCard), synckolab.global.LOG_WARNING + synckolab.global.LOG_AB);
@@ -641,7 +647,7 @@ synckolab.AddressBook = {
if (newCard && newCard.isMailList)
{
// skip mailing lists
- this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " " + this.tools.getUID(newCard));
+ this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " <" + newCard.DisplayName + ">");
this.curItemInListId.setAttribute("label", synckolab.global.strBundle.getString("noChange"));
synckolab.tools.logMessage("skipping mailing lists!", synckolab.global.LOG_WARNING + synckolab.global.LOG_AB);
return null;
@@ -662,7 +668,7 @@ synckolab.AddressBook = {
// since we disabled mailing list - wont come here
if (newCard.type === "maillist") {
- this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " " + this.tools.getCardProperty(newCard, "Name"));
+ this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " <" + newCard.DisplayName + ">");
} else if (this.tools.getCardProperty(newCard, "DisplayName") !== "") {
this.curItemInListContent.setAttribute("label", this.tools.getCardProperty(newCard, "DisplayName") +
" <" + this.tools.getCardProperty(newCard, "PrimaryEmail","---") + ">");
@@ -672,6 +678,18 @@ synckolab.AddressBook = {
" <" + this.tools.getCardProperty(newCard, "PrimaryEmail","---") + ">");
}
+ // check if we have this id already
+ var pi;
+ for(pi = 0; pi < this.processedIds.length; pi++) {
+ if(this.processedIds[pi] === this.tools.getUID(newCard)) {
+ synckolab.tools.logMessage("removing duplicate " + this.tools.getUID(newCard), synckolab.global.LOG_DEBUG + synckolab.global.LOG_AB);
+ this.curItemInListStatus.setAttribute("label", synckolab.global.strBundle.getString("deleteOnServer"));
+ return "DELETEME";
+ }
+ }
+ // add the id to the list of processed ids
+ this.processedIds.push(this.tools.getUID(newCard));
+
// ok lets see if we have this one already
var foundCard = this.gCardDB.get(this.gCurUID);
@@ -694,8 +712,10 @@ synckolab.AddressBook = {
if (newCard.type === "maillist")
{
synckolab.tools.logMessage("list is new, add to address book: " + this.tools.getUID(newCard), synckolab.global.LOG_INFO + synckolab.global.LOG_AB);
- // add mailing lists- pass the gCardDB with its nsIAbCard
- this.gConfig.addressBook.addMailList(synckolab.addressbookTools.createTBirdObject(newCard, this.gCardDB));
+
+ // add the mailing list: this will also check each entry and link it - if not create it
+ synckolab.addressbookTools.addMailingList(this.gConfig.addressBook, newCard, this.gCardDB);
+
// also add to the hash-database
this.gCardDB.put(this.tools.getUID(newCard), newCard);
}
@@ -857,28 +877,47 @@ synckolab.AddressBook = {
ulDelList = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray);
ulDelList.appendElement(foundCard, false);
- try
+ // server changed - update local
+ if (foundCard.isMailList)
{
- this.gConfig.addressBook.deleteCards(ulDelList);
-
- // also copy the image
- pName = this.tools.getCardProperty(newCard, "PhotoName");
- if (pName && pName !== "" && pName !== "null")
+
+ try
{
- // in case the copy failed - clear the photoname
- if (this.tools.copyImage(pName) === false) {
- this.tools.setCardProperty(newCard, "PhotoName", "");
- }
+ this.gConfig.addressBook.deleteDirectory(foundCard);
+ // add the mailing list: this will also check each entry and link it - if not create it
+ synckolab.addressbookTools.addMailingList(this.gConfig.addressBook, newCard, this.gCardDB);
+
+ // also add to the hash-database
+ this.gCardDB.put(this.tools.getUID(newCard), newCard);
+ } catch (delMailList)
+ {
+ synckolab.tools.logMessage("problem with local update for - skipping" + this.tools.getUID(foundCard), synckolab.global.LOG_WARNING + synckolab.global.LOG_AB);
}
-
- // add the new one
- this.gConfig.addressBook.addCard(synckolab.addressbookTools.createTBirdObject(newCard));
}
- catch (de)
+ else
{
- synckolab.tools.logMessage("problem with local update for - skipping" + this.tools.getUID(foundCard), synckolab.global.LOG_WARNING + synckolab.global.LOG_AB);
- }
-
+ try
+ {
+ this.gConfig.addressBook.deleteCards(ulDelList);
+
+ // also copy the image
+ pName = this.tools.getCardProperty(newCard, "PhotoName");
+ if (pName && pName !== "" && pName !== "null")
+ {
+ // in case the copy failed - clear the photoname
+ if (this.tools.copyImage(pName) === false) {
+ this.tools.setCardProperty(newCard, "PhotoName", "");
+ }
+ }
+
+ // add the new one
+ this.gConfig.addressBook.addCard(synckolab.addressbookTools.createTBirdObject(newCard));
+ }
+ catch (de)
+ {
+ synckolab.tools.logMessage("problem with local update for - skipping" + this.tools.getUID(foundCard), synckolab.global.LOG_WARNING + synckolab.global.LOG_AB);
+ }
+ }
// write the current content in the sync-db file
synckolab.tools.writeSyncDBFile(idxEntry, newCard);
}
@@ -913,12 +952,13 @@ synckolab.AddressBook = {
try
{
- //var delMailListlist = Components.classes["@mozilla.org/array;1"].createInstance(Components.interfaces.nsIMutableArray);
- //delMailListlist.appendElement(foundCard, false);
- //this.gConfig.addressBook.deleteCards(delMailListlist);
this.gConfig.addressBook.deleteDirectory(foundCard);
- this.gConfig.addressBook.addMailList(synckolab.addressbookTools.createTBirdObject(newCard, this.gCardDB));
- } catch (delMailList)
+ // add the mailing list: this will also check each entry and link it - if not create it
+ synckolab.addressbookTools.addMailingList(this.gConfig.addressBook, newCard, this.gCardDB);
+
+ // also add to the hash-database
+ this.gCardDB.put(this.tools.getUID(newCard), newCard);
+ } catch (delMailList2)
{
synckolab.tools.logMessage("problem with local update for - skipping" + this.tools.getUID(foundCard), synckolab.global.LOG_WARNING + synckolab.global.LOG_AB);
}
@@ -1078,7 +1118,7 @@ synckolab.AddressBook = {
this.curItemInListId.setAttribute("label", this.tools.getUID(curItem));
this.curItemInListStatus.setAttribute("label", synckolab.global.strBundle.getString("addToServer"));
if (curItem.isMailList) {
- this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " " + this.tools.getCardProperty(curItem, "Name"));
+ this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " <" + curItem.DisplayName + ">");
} else {
this.curItemInListContent.setAttribute("label", cur.firstName + " " + curItem.lastName + " <" + curItem.primaryEmail + ">");
}
@@ -1155,7 +1195,7 @@ synckolab.AddressBook = {
this.curItemInListId.setAttribute("label", this.tools.getUID(curItem));
this.curItemInListStatus.setAttribute("label", synckolab.global.strBundle.getString("localDelete"));
if (curItem.isMailList) {
- this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " " + this.tools.getUID(curItem));
+ this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " <" + curItem.DisplayName + ">");
} else {
this.curItemInListContent.setAttribute("label", curItem.firstName + " " + curItem.lastName + " <" + curItem.primaryEmail + ">");
}
@@ -1188,7 +1228,7 @@ synckolab.AddressBook = {
this.curItemInListId.setAttribute("label", this.tools.getUID(curItem));
this.curItemInListStatus.setAttribute("label", synckolab.global.strBundle.getString("addToServer"));
if (curItem.isMailList) {
- this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " " + this.tools.getUID(curItem));
+ this.curItemInListContent.setAttribute("label", synckolab.global.strBundle.getString("mailingList") + " <" + curItem.DisplayName + ">");
} else {
this.curItemInListContent.setAttribute("label", curItem.firstName + " " + curItem.lastName + " <" + curItem.primaryEmail + ">");
}
diff --git a/src/chrome/content/synckolab/addressbookTools.js b/src/chrome/content/synckolab/addressbookTools.js
index 14760db..7c0a837 100644
--- a/src/chrome/content/synckolab/addressbookTools.js
+++ b/src/chrome/content/synckolab/addressbookTools.js
@@ -730,9 +730,11 @@ synckolab.addressbookTools.xml2Card = function (xml, card) {
// kolab 2+3
case "SMTP-ADDRESS":
case "EMAIL":
- //synckolab.tools.logMessage("email: " + email + " - " + cur.getXmlResult("SMTP-ADDRESS", ""), synckolab.global.LOG_DEBUG + synckolab.global.LOG_AB);
- var emailAddress = cur.getXmlResult("SMTP-ADDRESS", "");
- emailAddress += cur.getXmlResult("TEXT", "");
+ var emailAddress = cur.getXmlResult("SMTP-ADDRESS", null);
+ if(emailAddress === null) {
+ emailAddress = cur.getFirstData();
+ }
+ synckolab.tools.logMessage("email: " + email + " - " + emailAddress, synckolab.global.LOG_DEBUG + synckolab.global.LOG_AB);
switch (email) {
case 0:
this.setCardProperty(card, "PrimaryEmail", emailAddress);
@@ -2396,6 +2398,33 @@ synckolab.addressbookTools.parseMessageContent = function (message) {
};
/**
+ * Add a json style mailing list to the address book.
+ * This will check each entry of the mailing list if it exists in thunderbird.
+ * If not, it will create it.
+ * Note: this will NOT update the thunderbird entry of the cards (if they exist!)
+ * @param addressBook the tbird addressbook to add the list to
+ * @param entry the actual list entry to add
+ * @param cardDB the existing card DB with all already added cards
+ */
+synckolab.addressbookTools.addMailingList = function (addressBook, entry, cardDB) {
+ // check each child
+ for ( var i = 0; i < entry.contacts.length; i++) {
+ var listCard = cardDB.get(this.getUID(entry.contacts[i]));
+ if(!listCard) {
+ // add this card - also to the cardDB
+ var abCard = synckolab.addressbookTools.createTBirdObject(entry.contacts[i]);
+ addressBook.addCard(abCard);
+ // also add to the hash-database
+ cardDB.put(this.getUID(entry.contacts[i]), abCard);
+ }
+ }
+
+ // add mailing lists- pass the gCardDB with its nsIAbCard
+ addressBook.addMailList(synckolab.addressbookTools.createTBirdObject(entry, cardDB));
+};
+
+
+/**
* Transform a json object into the real deal.
* @param base the base json object
* @param cards a hashmap with address book objects (key = UID for reference in the list)
@@ -2430,7 +2459,9 @@ synckolab.addressbookTools.createTBirdObject = function (base, cards) {
// fill the list
for ( var i = 0; i < base.contacts.length; i++) {
var listCard = cards.get(this.getUID(base.contacts[i]));
- card.addressLists.appendElement(listCard, false);
+ if(listCard) {
+ card.addressLists.appendElement(listCard, false);
+ }
}
} else {
// go through all elements of base
@@ -2864,6 +2895,8 @@ synckolab.addressbookTools.abListObject = function (card) {
return Components.classes["@mozilla.org/abmanager;1"].getService(Components.interfaces.nsIAbManager).getDirectory(card.mailListURI);
};
+
+
synckolab.addressbookTools.card2Human = function (card) {
var msg = "";
diff --git a/src/install.rdf b/src/install.rdf
index 1d905a3..c019ef6 100644
--- a/src/install.rdf
+++ b/src/install.rdf
@@ -22,7 +22,7 @@
<!-- Front End MetaData -->
<em:id>{571CFACF-0F7D-49b4-BD77-E6FC7B209ADC}</em:id>
<em:name>Sync Kolab</em:name>
- <em:version>2.0.3</em:version>
+ <em:version>2.9.0</em:version>
<em:type>2</em:type>
<em:description>Synchronize the address book and calendar with IMAP folder or Kolab1/2 server</em:description>
<em:creator>Niko Berger</em:creator>
diff --git a/test/suite.js b/test/suite.js
index 0e13548..91d2209 100644
--- a/test/suite.js
+++ b/test/suite.js
@@ -40,9 +40,9 @@ QUnit.log(function(details) {
load("test/synckolab/tools/textTest.js");
load("test/synckolab/tools/toolsTest.js");
-load("test/synckolab/parser/kolab2/calendarTest.js");
+//load("test/synckolab/parser/kolab2/calendarTest.js");
load("test/synckolab/parser/kolab2/contactTest.js");
-load("test/synckolab/parser/kolab3/contactTest.js");
+//load("test/synckolab/parser/kolab3/contactTest.js");
//load("test/synckolab/parser/kolab3/calendarTest.js");
print("========================")
diff --git a/test/synckolab/parser/kolab2/json/list.test.json b/test/synckolab/parser/kolab2/json/list.test.json
index a4dfdd1..6288395 100644
--- a/test/synckolab/parser/kolab2/json/list.test.json
+++ b/test/synckolab/parser/kolab2/json/list.test.json
@@ -14,7 +14,7 @@
"isMailList": false,
"ts": 1349908157831,
"DisplayName": "testöä lastname",
- "PrimaryEmail": "",
+ "PrimaryEmail": "weird@email.com",
"UUID": "urn:uuid:pas-id-1D84CEA337CD1878"
},
{
@@ -24,7 +24,7 @@
"isMailList": false,
"ts": 1349908157832,
"DisplayName": "cont2#öüä&$",
- "PrimaryEmail": "",
+ "PrimaryEmail": "weird@email.com",
"UUID": "urn:uuid:pas-id-A4E937D838A897AD"
}
],
diff --git a/test/synckolab/parser/kolab2/raw/list.test.xml b/test/synckolab/parser/kolab2/raw/list.test.xml
index 8ff9b02..6aece4e 100644
--- a/test/synckolab/parser/kolab2/raw/list.test.xml
+++ b/test/synckolab/parser/kolab2/raw/list.test.xml
@@ -2,15 +2,15 @@
<distribution-list version="1.0" >
<product-id>SyncKolab, Kolab resource</product-id>
<uid>list_name</uid>
- <creation-date>20121010T222052Z</creation-date>
- <last-modification-date>20121010T222052Z</last-modification-date>
+ <creation-date>20121017T214612Z</creation-date>
+ <last-modification-date>20121017T214612Z</last-modification-date>
<sensitivity>public</sensitivity>
<name>list-name</name>
<body>list-description</body>
<nickname>list-nickname</nickname>
<member>
<display-name>testöä lastname</display-name>
- <smtp-address>email@mail.com</smtp-address>
+ <smtp-address>weird@email.com</smtp-address>
<uid>urn:uuid:pas-id-1D84CEA337CD1878</uid>
</member>
<member>