Changeset d28e78
- Timestamp:
- Jul 21, 2011, 4:02:42 PM (11 years ago)
- Branches:
- ng_0.8, ng_0.9
- Children:
- 9a44e8
- Parents:
- f88f6c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
chrome/content/v_identity/vI_storage.js
rf88f6c rd28e78 211 211 __getDescriptionAndType : function (recipient, recipientType) { 212 212 if (recipientType == "addr_newsgroups") return { recDesc : recipient, recType : "newsgroup" } 213 else if (vI_storage.isMailingList(recipient)) 214 return { recDesc : vI_storage.getMailListName(recipient), recType : "maillist" } 213 else if (vI_storage.__isMailingList(recipient)) { 214 vI_notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is MailList\n"); 215 return { recDesc : vI_storage.__getMailListName(recipient), recType : "maillist" } 216 } 215 217 else { 218 vI_notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is no MailList\n"); 216 219 var localIdentityData = new vI_identityData(recipient, null, null, null, null, null, null); 217 220 return { recDesc : localIdentityData.combinedName, recType : "email" } … … 321 324 }, 322 325 323 324 // --------------------------------------------------------------------325 // the following function gets a queryString, a callFunction to call for every found Card related to the queryString326 // and a returnVar, which is passed to the callFunction and returned at the end.327 // this way the Storage-search is unified for all tasks328 _walkTroughCards : function (queryString, callFunction, returnVar) {329 var parentDir = vI_storage.rdfService.GetResource("moz-abdirectory://").QueryInterface(Components.interfaces.nsIAbDirectory);330 var enumerator = parentDir.childNodes;331 if (!enumerator) {vI_notificationBar.dump("## vI_storage: no addressbooks?\n"); return null;} // uups, no addressbooks?332 while (enumerator && enumerator.hasMoreElements()) {333 var addrbook = enumerator.getNext(); // an addressbook directory334 addrbook.QueryInterface(Components.interfaces.nsIAbDirectory);335 var searchUri = (addrbook.directoryProperties?addrbook.directoryProperties.URI:addrbook.URI) + queryString;336 vI_notificationBar.dump("## vI_storage: _walkTroughCards searchUri='" + searchUri + "'\n")337 // just try the following steps, they might fail if addressbook wasn't configured the right way338 // not completely reproducible, but caused bug https://www.absorb.it/virtual-id/ticket/41339 try {340 var AbView = Components.classes["@mozilla.org/addressbook/abview;1"].createInstance(Components.interfaces.nsIAbView);341 var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);342 AbView.setView(rdf.GetResource(searchUri).QueryInterface(Components.interfaces.nsIAbDirectory), null, "GeneratedName", "ascending");343 } catch (ex) { break; };344 var directory = AbView.directory;345 // directory will now be a subset of the addressbook containing only those cards that match the searchstring346 if (!directory) break;347 try { var childCards = directory.childCards; } catch (ex) { break; };348 349 if (typeof(childCards.first)=="function") { // old versions don't use enumerator350 var keepGoing = 1;351 try { childCards.first(); } catch (ex) { keepGoing = 0; }352 while (keepGoing == 1) {353 var currentCard = childCards.currentItem();354 currentCard.QueryInterface(Components.interfaces.nsIAbCard);355 callFunction(addrbook, currentCard, returnVar);356 try { childCards.next(); } catch (ex) { keepGoing = 0; }357 }358 }359 else {360 while (childCards.hasMoreElements()) {361 vI_notificationBar.dump("## vI_storage: _walkTroughCards found card\n")362 var currentCard = childCards.getNext();363 currentCard.QueryInterface(Components.interfaces.nsIAbCard);364 callFunction(addrbook, currentCard, returnVar);365 }366 }367 }368 return returnVar;369 },370 371 326 // -------------------------------------------------------------------- 372 327 // check if recipient is a mailing list. 373 328 // Similiar to Thunderbird, if there are muliple cards with the same displayName the mailinglist is preferred 374 329 // see also https://bugzilla.mozilla.org/show_bug.cgi?id=408575 375 isMailingList: function(recipient) { 376 var queryString = "?(or(DisplayName,c," + encodeURIComponent(vI_storage.getMailListName(recipient)) + "))" 377 var returnVar = vI_storage._walkTroughCards(queryString, vI_storage._isMailingListCard, 378 { mailListName : vI_storage.getMailListName(recipient), isMailList : false } ) 379 vI_notificationBar.dump("## vI_storage: isMailingList " + returnVar.isMailList + "\n") 380 return returnVar.isMailList; 330 __isMailingList: function(recipient) { 331 let abManager = Components.classes["@mozilla.org/abmanager;1"] 332 .getService(Components.interfaces.nsIAbManager); 333 let allAddressBooks = abManager.directories; 334 while (allAddressBooks.hasMoreElements()) { 335 let ab = allAddressBooks.getNext(); 336 if (ab instanceof Components.interfaces.nsIAbDirectory && !ab.isRemote) { 337 let cards = abManager.getDirectory(ab.URI + 338 "?(and(DisplayName,=," + encodeURIComponent(vI_storage.__getMailListName(recipient)) + ")(IsMailList,=,TRUE))").childCards; 339 if (cards.hasMoreElements()) return true; // only interested if there is at least one element... 340 } 341 } 342 return false; 381 343 }, 382 344 383 _isMailingListCard : function (addrbook, Card, returnVar) {384 // returnVar = { mailListName : mailListName, isMailList : false }385 returnVar.isMailList = (returnVar.isMailList ||386 Card.isMailList && Card.displayName.toLowerCase() == returnVar.mailListName.toLowerCase() )387 },388 389 345 // -------------------------------------------------------------------- 390 346 391 getMailListName : function(recipient) {347 __getMailListName : function(recipient) { 392 348 if (recipient.match(/<[^>]*>/) || recipient.match(/$/)) { 393 349 var mailListName = RegExp.leftContext + RegExp.rightContext
Note: See TracChangeset
for help on using the changeset viewer.