Changeset 052c6e


Ignore:
Timestamp:
Oct 24, 2007, 5:02:31 PM (14 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
0bc2a7
Parents:
fb8f82
Message:

added recognition of secondary emails and Full Names

File:
1 edited

Legend:

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

    rfb8f82 r052c6e  
    109109        var parentDir = rdfService.GetResource("moz-abdirectory://").QueryInterface(Components.interfaces.nsIAbDirectory);
    110110        var enumerator = parentDir.childNodes;
     111        if (!enumerator) return null; // uups, no addressbooks?
    111112       
    112113        var splitted = { number : 0, emails : {}, fullNames : {}, combinedNames : {} };
     
    114115            splitted.fullNames, splitted.combinedNames);
    115116        var recipient_email = splitted.emails.value[0]
     117        var recipient_fullName = splitted.fullNames.value[0]
    116118        if (!recipient_email) return null;
    117119   
    118120        vI_notificationBar.dump("## vI_addressBook: Search '" + recipient_email + "' in addressbooks.\n")
    119121       
    120         var matches = { number : 0, cards : {} }
     122        var matchingEmailCards = { number : 0, cards : {} }
     123        var matchingFullNameCards = { number : 0, cards : {} }
    121124        while (enumerator && enumerator.hasMoreElements()) {
    122125            var addrbook = enumerator.getNext();  // an addressbook directory
    123126            addrbook.QueryInterface(Components.interfaces.nsIAbDirectory);
    124             var searchUri = addrbook.directoryProperties.URI + "?(or(PrimaryEmail,c," + recipient_email + "))";  // search for the address in this book
     127            var searchUri = addrbook.directoryProperties.URI + "?(or(PrimaryEmail,c," + recipient_email + ")(SecondEmail,c," + recipient_email + "))";  // search for the address in this book
    125128            //~ vI_notificationBar.dump("## vI_addressBook: searchUri '" + searchUri + "'\n");
    126129            var directory = rdfService.GetResource(searchUri).QueryInterface(Components.interfaces.nsIAbDirectory);
    127130            // directory will now be a subset of the addressbook containing only those cards that match the searchstring 'address'
     131            if (!directory) break;
    128132            var childCards = directory.childCards;
    129133           
     
    134138                currentCard = childCards.currentItem();
    135139                currentCard.QueryInterface(Components.interfaces.nsIAbCard);
    136                 if (currentCard.primaryEmail.toLowerCase() == recipient_email.toLowerCase()) {
     140                if (currentCard.primaryEmail.toLowerCase() == recipient_email.toLowerCase() ||
     141                    currentCard.secondEmail.toLowerCase() == recipient_email.toLowerCase()) {
    137142                    vI_notificationBar.dump("## vI_addressBook: card found, primaryEmail '" + currentCard.primaryEmail.toLowerCase() + "'.\n")
    138                     matches.cards[matches.number++] = currentCard;
     143                    if (currentCard.displayName == recipient_fullName) {
     144                        vI_notificationBar.dump("## vI_addressBook:             matching full Name '" + currentCard.displayName + "'.\n")
     145                        matchingFullNameCards.cards[matchingFullNameCards.number++] = currentCard;
     146                    }
     147                    else matchingEmailCards.cards[matchingEmailCards.number++] = currentCard;
    139148                }
    140149                try { childCards.next(); } catch (ex) { keepGoing = 0; }
     
    142151        }
    143152       
     153        vI_notificationBar.dump("## vI_addressBook: found " + matchingEmailCards.number + " card(s) with matching email.\n")
     154        vI_notificationBar.dump("## vI_addressBook: found " + matchingFullNameCards.number + " card(s) with matching email and Full Name.\n")
     155        // prefer matchingFullNameCards over matchingEmailCards
     156        var matchingCards = matchingEmailCards
     157        if (matchingFullNameCards.number > 0) matchingCards = matchingFullNameCards
     158       
    144159        // usual cases, found or not
    145         switch (matches.number) {
     160        switch (matchingCards.number) {
    146161            case 0:
    147162                vI_notificationBar.dump("## vI_addressBook: " + recipient_email + " not found.\n")
    148163                return null;
    149164            case 1:
    150                 return matches.cards[0];
     165                return matchingCards.cards[0];
    151166        }
    152167       
    153168        // upps, more than one matching address found
    154         vI_notificationBar.dump("## vI_addressBook WARNING: " + matches.number + " matching entries found.\n")
    155         for (index = 0; index < matches.number; index++) {
     169        vI_notificationBar.dump("## vI_addressBook WARNING: " + matchingEmailCards.number + " matching entries found.\n")
     170               
     171        for (index = 0; index < matchingCards.number; index++) {
    156172            for each (var prop in vI_addressBook.CardFields) {
    157                 if (matches.cards[index][prop.toLowerCase()].indexOf("vIdentity: ") == 0) {
     173                if (matchingCards.cards[index][prop.toLowerCase()].indexOf("vIdentity: ") == 0) {
    158174                    vI_notificationBar.dump("## vI_addressBook WARNING: use first one with a stored Virtual Identity.\n")
    159                     return matches.cards[index];
     175                    return matchingCards.cards[index];
    160176                }
    161177            }
    162178        }
    163179        vI_notificationBar.dump("## vI_addressBook WARNING: none has a stored Virtual Identity, use first in set.\n")
    164         return matches.cards[0];
     180        return matchingCards.cards[0];
    165181    },
    166182               
Note: See TracChangeset for help on using the changeset viewer.