Changeset fb8f82


Ignore:
Timestamp:
Oct 24, 2007, 3:21:26 PM (14 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
052c6e
Parents:
c4a2c2
Message:

problem with similar adresses in addressbook solved
also added mechanism to work with double addresses

File:
1 edited

Legend:

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

    rc4a2c2 rfb8f82  
    116116        if (!recipient_email) return null;
    117117   
    118         vI_notificationBar.dump("## vI_addressBook: Search " + recipient_email + " in addressbooks.\n")
    119        
     118        vI_notificationBar.dump("## vI_addressBook: Search '" + recipient_email + "' in addressbooks.\n")
     119       
     120        var matches = { number : 0, cards : {} }
    120121        while (enumerator && enumerator.hasMoreElements()) {
    121122            var addrbook = enumerator.getNext();  // an addressbook directory
    122123            addrbook.QueryInterface(Components.interfaces.nsIAbDirectory);
    123124            var searchUri = addrbook.directoryProperties.URI + "?(or(PrimaryEmail,c," + recipient_email + "))";  // search for the address in this book
     125            //~ vI_notificationBar.dump("## vI_addressBook: searchUri '" + searchUri + "'\n");
    124126            var directory = rdfService.GetResource(searchUri).QueryInterface(Components.interfaces.nsIAbDirectory);
    125127            // directory will now be a subset of the addressbook containing only those cards that match the searchstring 'address'
    126             try {
    127                 var ChildCards = directory.childCards;
    128                 ChildCards.first();
    129                 var CurrentItem = ChildCards.currentItem();
    130             } catch(e) {
    131                 var ChildCards = directory.childNodes;
    132                 if (ChildCards.hasMoreElements()) var CurrentItem = ChildCards.getNext();
    133             }
    134             try {
    135                 var Card = CurrentItem.QueryInterface(Components.interfaces.nsIAbCard);
    136                 vI_notificationBar.dump("## vI_addressBook: card found.\n")
    137                 // current card is now the addressbook card of a contact that has 'address'
    138                 if (Card.primaryEmail.toLowerCase() == recipient_email.toLowerCase()) return Card;
    139             }  catch (e)  {
    140                 // we would be here if the directory contained no items
    141             }
     128            var childCards = directory.childCards;
    142129           
    143         }
    144         vI_notificationBar.dump("## vI_addressBook: " + recipient_email + " not found.\n")
    145         return null;
     130            var keepGoing = 1;
     131            try { childCards.first(); } catch (ex) { keepGoing = 0; }
     132           
     133            while (keepGoing == 1) {
     134                currentCard = childCards.currentItem();
     135                currentCard.QueryInterface(Components.interfaces.nsIAbCard);
     136                if (currentCard.primaryEmail.toLowerCase() == recipient_email.toLowerCase()) {
     137                    vI_notificationBar.dump("## vI_addressBook: card found, primaryEmail '" + currentCard.primaryEmail.toLowerCase() + "'.\n")
     138                    matches.cards[matches.number++] = currentCard;
     139                }
     140                try { childCards.next(); } catch (ex) { keepGoing = 0; }
     141            }
     142        }
     143       
     144        // usual cases, found or not
     145        switch (matches.number) {
     146            case 0:
     147                vI_notificationBar.dump("## vI_addressBook: " + recipient_email + " not found.\n")
     148                return null;
     149            case 1:
     150                return matches.cards[0];
     151        }
     152       
     153        // 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++) {
     156            for each (var prop in vI_addressBook.CardFields) {
     157                if (matches.cards[index][prop.toLowerCase()].indexOf("vIdentity: ") == 0) {
     158                    vI_notificationBar.dump("## vI_addressBook WARNING: use first one with a stored Virtual Identity.\n")
     159                    return matches.cards[index];
     160                }
     161            }
     162        }
     163        vI_notificationBar.dump("## vI_addressBook WARNING: none has a stored Virtual Identity, use first in set.\n")
     164        return matches.cards[0];
    146165    },
    147166               
Note: See TracChangeset for help on using the changeset viewer.