Changeset 63fe91


Ignore:
Timestamp:
Dec 9, 2007, 9:11:37 PM (14 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
f8f8ea
Parents:
f94d32
Message:

virtual identites for newsgroups now stored in addressbook. major rewrite of vI_addressBook mechanism, requieres cleaning and testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_addressBook.js

    rf94d32 r63fe91  
    3030vI_addressBook = {
    3131    CardFields : Array("Custom1", "Custom2", "Custom3", "Custom4", "Notes"),
     32    addNote : "## added by Virtual Identity extension",
    3233   
    3334    VIdentityString : null,
     
    162163    },
    163164
    164     getCardForAddress: function(email) {
     165    getCardForAddress: function(recipient) {
    165166        // enumerate all of the address books on this system
    166         if (!email.match(/@/)) {
    167             vI_notificationBar.dump("## vI_addressBook: getCardForAddress got no email, aborting.\n")
    168             return null;
    169         }
    170167        var parentDir = vI_addressBook.rdfService.GetResource("moz-abdirectory://").QueryInterface(Components.interfaces.nsIAbDirectory);
    171168        var enumerator = parentDir.childNodes;
    172169        if (!enumerator) {vI_notificationBar.dump("## vI_addressBook: no addressbooks?\n"); return null;} // uups, no addressbooks?
    173170       
    174         var splitted = { number : 0, emails : {}, fullNames : {}, combinedNames : {} };
    175         vI.headerParser.parseHeadersWithArray(email, splitted.emails,
    176             splitted.fullNames, splitted.combinedNames);
    177         var recipient_email = splitted.emails.value[0]
    178         var recipient_fullName = splitted.fullNames.value[0]
    179         if (!recipient_email) {vI_notificationBar.dump("## vI_addressBook: no recipient_email?\n"); return null;}
    180        
    181         vI_notificationBar.dump("## vI_addressBook: Search '" + recipient_email + "' in addressbooks.\n")
    182        
     171        var splittedRecipient = vI.helper.parseAddress(recipient);
     172        var queryString;
     173        if (splittedRecipient.email) {
     174            queryString = "?(or(PrimaryEmail,c," + encodeURIComponent(splittedRecipient.email) + ")(SecondEmail,c," +
     175                encodeURIComponent(splittedRecipient.email) + "))";
     176            vI_notificationBar.dump("## vI_addressBook: Search '" + splittedRecipient.email + "' in addressbook emails.\n")
     177        }
     178        else {
     179            queryString = "?(or(DisplayName,c," +
     180                encodeURIComponent(splittedRecipient.name) + "))";
     181            vI_notificationBar.dump("## vI_addressBook: Search '" + splittedRecipient.name + "' in addressbook displayed names.\n")
     182        }
    183183        var matchingEmailCards = { number : 0, cards : {} }
    184184        var matchingFullNameCards = { number : 0, cards : {} }
     
    186186            var addrbook = enumerator.getNext();  // an addressbook directory
    187187            addrbook.QueryInterface(Components.interfaces.nsIAbDirectory);
    188             var searchUri = (addrbook.directoryProperties?addrbook.directoryProperties.URI:addrbook.URI) + "?(or(PrimaryEmail,c," + encodeURIComponent(recipient_email) + ")(SecondEmail,c," + encodeURIComponent(recipient_email) + "))";  // search for the address in this book
    189             //~ vI_notificationBar.dump("## vI_addressBook: searchUri '" + searchUri + "'\n");
     188            var searchUri = (addrbook.directoryProperties?addrbook.directoryProperties.URI:addrbook.URI) + queryString;  // search for the address in this book
     189            vI_notificationBar.dump("## vI_addressBook: searchUri '" + searchUri + "'\n");
    190190            var directory = vI_addressBook.rdfService.GetResource(searchUri).QueryInterface(Components.interfaces.nsIAbDirectory);
     191           
     192            //~ var AbView = Components.classes["@mozilla.org/addressbook/abview;1"].createInstance(Components.interfaces.nsIAbView);
     193            //~ AbView.init(searchUri, true, null, "GeneratedName", "ascending");
     194            //~ var directory = AbView.directory;
     195           
    191196            // directory will now be a subset of the addressbook containing only those cards that match the searchstring 'address'
    192197            if (!directory) break;
     
    196201            while (keepGoing == 1) {
    197202                currentCard = childCards.currentItem();
     203            //~ while (directory.childNodes && directory.childNodes.hasMoreElements()) {
     204                //~ currentCard = directory.childNodes.getNext();
    198205                currentCard.QueryInterface(Components.interfaces.nsIAbCard);
    199                 if (currentCard.primaryEmail.toLowerCase() == recipient_email.toLowerCase() ||
    200                     currentCard.secondEmail.toLowerCase() == recipient_email.toLowerCase()) {
    201                     vI_notificationBar.dump("## vI_addressBook: card found, primaryEmail '" + currentCard.primaryEmail.toLowerCase() + "'.\n")
    202                     if (recipient_fullName != "" && currentCard.displayName == recipient_fullName) {
    203                         vI_notificationBar.dump("## vI_addressBook:             matching full Name '" + currentCard.displayName + "'.\n")
     206                vI_notificationBar.dump("## vI_addressBook:             checking '" + currentCard.displayName + "'.\n")
     207                if (splittedRecipient.email) {
     208                    if (currentCard.primaryEmail.toLowerCase() == splittedRecipient.email.toLowerCase() ||
     209                        currentCard.secondEmail.toLowerCase() == splittedRecipient.email.toLowerCase()) {
     210                        vI_notificationBar.dump("## vI_addressBook: card found, primaryEmail '" + currentCard.primaryEmail.toLowerCase() + "'.\n")
     211                        if (splittedRecipient.name != "" && currentCard.displayName == splittedRecipient.name) {
     212                            vI_notificationBar.dump("## vI_addressBook:             matching displayed Name '" + currentCard.displayName + "'.\n")
     213                            matchingFullNameCards.cards[matchingFullNameCards.number++] = currentCard;
     214                        }
     215                        else matchingEmailCards.cards[matchingEmailCards.number++] = currentCard;
     216                    }
     217                }
     218                else {
     219                    if (splittedRecipient.name != "" && currentCard.displayName == splittedRecipient.name) {
     220                        vI_notificationBar.dump("## vI_addressBook:             matching displayed Name '" + currentCard.displayName + "'.\n")
    204221                        matchingFullNameCards.cards[matchingFullNameCards.number++] = currentCard;
    205222                    }
    206                     else matchingEmailCards.cards[matchingEmailCards.number++] = currentCard;
    207223                }
    208224                try { childCards.next(); } catch (ex) { keepGoing = 0; }
     
    211227       
    212228        vI_notificationBar.dump("## vI_addressBook: found " + matchingEmailCards.number + " card(s) with matching email.\n")
    213         vI_notificationBar.dump("## vI_addressBook: found " + matchingFullNameCards.number + " card(s) with matching email and Full Name.\n")
     229        vI_notificationBar.dump("## vI_addressBook: found " + matchingFullNameCards.number + " card(s) with matching displayed Name.\n")
    214230        // prefer matchingFullNameCards over matchingEmailCards
    215231        var matchingCards = matchingEmailCards
     
    219235        switch (matchingCards.number) {
    220236            case 0:
    221                 vI_notificationBar.dump("## vI_addressBook: " + recipient_email + " not found.\n")
     237                vI_notificationBar.dump("## vI_addressBook: " + recipient + " not found.\n")
    222238                return null;
    223239            case 1:
     
    449465            if (recipientType == "addr_reply" || recipientType == "addr_followup" ||
    450466                awGetInputElement(row).value.match(/^\s*$/) ) continue;
     467            if (recipientType == "addr_newsgroups" && vI_addressBook.prefroot.getBoolPref("mail.collect_email_address_outgoing") &&
     468                (!vI_addressBook.getCardForAddress(awGetInputElement(row).value))) {
     469               
     470                newCard = Components.classes["@mozilla.org/addressbook/cardproperty;1"]
     471                    .createInstance(Components.interfaces.nsIAbCard);
     472                newCard.displayName = awGetInputElement(row).value;
     473                newCard.notes = vI_addressBook.addNote
     474               
     475                var aBook = vI_addressBook.rdfService.GetResource(vI_addressBook.prefroot.getCharPref("mail.collect_addressbook"))
     476                    .QueryInterface(Components.interfaces.nsIAbDirectory);
     477                aBook.addCard(newCard)
     478            }
    451479            window.setTimeout(vI_addressBook.updateABookFromVIdentity, 50, awGetInputElement(row).value)
    452480        }
Note: See TracChangeset for help on using the changeset viewer.