Changeset 6a7d00


Ignore:
Timestamp:
Apr 23, 2008, 7:38:09 PM (14 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
adf85d
Parents:
d3c905
Message:

bugfix: smartReply filter was broken. Major Cleanup done.

Location:
chrome/content/v_identity
Files:
2 edited

Legend:

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

    rd3c905 r6a7d00  
    3939        vI_notificationBar.dump("## vI_smartIdentity: msgComposeType = " + type + "\n");
    4040       
    41         //~ if (vI.preferences.getBoolPref("autoTimestamp") &&
    42             //~ ((type == msgComposeType.New) || (type == msgComposeType.NewsPost) || (type == msgComposeType.MailToUrl)))
    43                     //~ vI_smartIdentity.SmartTimestamp(hdr);
    44                    
    45         // if there is no ID of the original Message  (Why?) leave the function
     41        // if there is no ID of the original Message (Why? maybe new mail) dumpa notice
    4642        var uri = gMsgCompose.originalMsgURI;
    4743        if (!uri) vI_notificationBar.dump("## vI_smartIdentity: can't get URI of former Message\n");
     
    7369       
    7470    // this function adds a timestamp to the current sender
    75     SmartTimestamp : function() {
    76         vI_notificationBar.dump("## vI_smartIdentity: SmartTimestamp()\n");
     71    __autoTimestamp : function() {
     72        vI_notificationBar.dump("## vI_smartIdentity: __autoTimestamp()\n");
    7773        if (vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("value") == "vid") {
    7874            vI_notificationBar.dump("## vI_smartIdentity: Virtual Identity in use, aborting\n");
     
    9389   
    9490    NewMail : function() {
    95         var storage_addresses = new identityCollection();
    96         vI_storage.getVIdentityFromAllRecipients(storage_addresses);
    97        
    98         if (storage_addresses.number > 0) vI_smartIdentity.smartIdentitySelection(storage_addresses, false)
    99         else if (vI.preferences.getBoolPref("autoTimestamp")) vI_smartIdentity.SmartTimestamp();   
     91        var storageIdentities = new identityCollection();
     92        vI_storage.getVIdentityFromAllRecipients(storageIdentities);
     93       
     94        if (storageIdentities.number > 0) vI_smartIdentity.__smartIdentitySelection(storageIdentities, false)
     95        else if (vI.preferences.getBoolPref("autoTimestamp")) vI_smartIdentity.__autoTimestamp();   
    10096    },
    10197   
     
    10399        vI_notificationBar.dump("## vI_smartIdentity: Draft()\n");
    104100       
    105         var all_addresses = new identityCollection();
    106         vI_smartIdentity.SmartDraft(hdr, all_addresses);
    107         var storage_addresses = new identityCollection();
    108         vI_storage.getVIdentityFromAllRecipients(storage_addresses);
    109        
    110         all_addresses = vI_smartIdentity.mergeWithoutDuplicates(all_addresses, storage_addresses);
    111            
    112         vI_smartIdentity.smartIdentitySelection(all_addresses, true);
     101        var allIdentities = new identityCollection();
     102        vI_smartIdentity.__SmartDraft(hdr, allIdentities);
     103        var storageIdentities = new identityCollection();
     104        vI_storage.getVIdentityFromAllRecipients(storageIdentities);
     105       
     106        allIdentities.mergeWithoutDuplicates(storageIdentities);
     107           
     108        vI_smartIdentity.__smartIdentitySelection(allIdentities, true);
    113109   
    114110    },
    115111   
    116112    // this function checks if we have a draft-case and Smart-Draft should replace the Identity
    117     SmartDraft : function(hdr, all_addresses) {
     113    __SmartDraft : function(hdr, allIdentities) {
    118114        if (!vI.preferences.getBoolPref("smart_draft"))
    119115            { vI_notificationBar.dump("## vI_smartIdentity: SmartDraft deactivated\n"); return; }
    120         vI_notificationBar.dump("## vI_smartIdentity: SmartDraft()\n");
     116        vI_notificationBar.dump("## vI_smartIdentity: __SmartDraft()\n");
    121117           
    122118        if (hdr) {
    123             vI.headerParser.parseHeadersWithArray(hdr.author, all_addresses.emails,
    124                 all_addresses.fullNames, all_addresses.combinedNames);
    125             all_addresses.number = 1
    126             all_addresses.emails[0] = all_addresses.emails.value[0]
    127             all_addresses.fullNames[0] = all_addresses.fullNames.value[0]
    128             all_addresses.combinedNames[0] = all_addresses.combinedNames.value[0]
    129            
    130             vI_notificationBar.dump("## vI_smartIdentity: sender '" + all_addresses.combinedNames[0] + "'\n");
    131         }
    132         else vI_notificationBar.dump("## vI_smartIdentity: SmartDraft: No Header found, shouldn't happen\n");
    133     },
    134    
    135     //~ // check if recent email-address (pre-choosen identity) is found in at least one address
    136     //~ matchSelectedIdentity : function(all_addresses) {
    137         //~ vI_notificationBar.dump("## vI_smartIdentity: search for preselected Identity\n");
    138         //~ current_email = getCurrentIdentity().email.toLowerCase();
    139         //~ vI_notificationBar.dump("## vI_smartIdentity: preselected email: " + current_email + "\n");
    140         //~ current_name =  getCurrentIdentity().fullName.toLowerCase();
    141         //~ vI_notificationBar.dump("## vI_smartIdentity: preselected name: " + current_name + "\n");
    142         //~ for (index = 0; index < all_addresses.number; index++) {
    143             //~ if (current_email == all_addresses.emails[index].toLowerCase()
    144                 //~ && (vI.preferences.getBoolPref("smart_reply_ignoreFullName") ||
    145                 //~ current_name == all_addresses.fullNames[index].toLowerCase())) {
    146                     //~ vI_notificationBar.dump("## vI_smartIdentity:   found preselected Identity in address sets, aborting\n");
    147                     //~ return true; // direct hit
    148                 //~ }
    149         //~ }
    150         //~ vI_notificationBar.dump("## vI_smartIdentity:   collected address(es) doesn't contain preselected Identity, continuing\n");
    151         //~ return false;
    152     //~ },
    153    
    154     //~ // checks if any Identity in the collected address-set is already available as
    155     //~ // a stored identity. If so, use the stored one.
    156     //~ matchAnyIdentity : function(all_addresses) {
    157         //~ vI_notificationBar.dump("## vI_smartIdentity: check if any collected address is stored as a (usual) Identity\n");
    158         //~ var accounts = queryISupportsArray(gAccountManager.accounts, Components.interfaces.nsIMsgAccount);
    159         //~ for (var i in accounts) {
    160             //~ // check for VirtualIdentity Account
    161             //~ try {   vI_account.prefroot.getBoolPref("mail.account." + accounts[i].key + ".vIdentity");
    162                 //~ continue; } catch (e) { };
    163            
    164             //~ var server = accounts[i].incomingServer;
    165             //~ // ignore newsgroup accounts if not selected in preferences
    166             //~ if (server && server.type == "nntp" &&
    167                 //~ !vI.preferences.getBoolPref("smart_reply_for_newsgroups")) continue;
    168            
    169             //~ var identities = queryISupportsArray(accounts[i].identities, Components.interfaces.nsIMsgIdentity);
    170             //~ for (var j in identities) {
    171                 //~ for (index = 0; index < all_addresses.number; index++) {
    172                     //~ if (identities[j].getUnicharAttribute("useremail").toLowerCase() ==
    173                         //~ all_addresses.emails[index].toLowerCase() &&
    174                         //~ (vI.preferences.getBoolPref("smart_reply_ignoreFullName") ||
    175                         //~ identities[j].getUnicharAttribute("fullName").toLowerCase() ==
    176                         //~ all_addresses.fullNames[index].toLowerCase())) {
    177                             //~ vI_notificationBar.dump("## vI_smartIdentity:   found existing Identity in address sets, aborting\n");
    178                             //~ return identities[j];
    179                         //~ }
    180                     //~ }
    181                 //~ }
    182             //~ }
    183         //~ vI_notificationBar.dump("## vI_smartIdentity:   no collected address found stored, continuing\n");
    184         //~ return null;
    185     //~ },
    186 
    187    
    188     filterAddresses : function(all_addresses) {
    189         var return_addresses = new identityCollection();
    190        
    191         var filter_list = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("smart_reply_filter")).split(/\n/)
    192         if (filter_list.length == 0) filter_list[0] == ""
    193        
    194         for (i = 0; i < filter_list.length; i++) {
     119            vI.headerParser.parseHeadersWithArray(hdr.author, allIdentities.emails,
     120                allIdentities.fullNames, allIdentities.combinedNames);
     121            allIdentities.number = 1
     122            allIdentities.emails[0] = allIdentities.emails.value[0]
     123            allIdentities.fullNames[0] = allIdentities.fullNames.value[0]
     124            allIdentities.combinedNames[0] = allIdentities.combinedNames.value[0]
     125           
     126            vI_notificationBar.dump("## vI_smartIdentity: sender '" + allIdentities.combinedNames[0] + "'\n");
     127        }
     128        else vI_notificationBar.dump("## vI_smartIdentity: __SmartDraft: No Header found, shouldn't happen\n");
     129    },
     130   
     131    __filterAddresses : function(smartIdentities) {
     132        var returnIdentities = new identityCollection();
     133       
     134        var filterList  =
     135            vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("smart_reply_filter")).split(/\n/)
     136        if (filterList.length == 0) filterList[0] == ""
     137       
     138        for (i = 0; i < filterList.length; i++) {
    195139            const filterType = { None : 0, RegExp : 1, StrCmp : 2 }
    196140            var recentfilterType; var skipRegExp = false;
    197             if (filter_list.length <= 1 && filter_list[0] == "")
    198                 { vI_notificationBar.dump("## vI_smartIdentity: no filters configured\n"); recentfilterType = filterType.None; }
    199             else if (/^\/(.*)\/$/.exec(filter_list[i]))
    200                 { vI_notificationBar.dump("## vI_smartIdentity: filter emails with RegExp '"
    201                     + filter_list[i].replace(/\\/g,"\\\\") + "'\n"); recentfilterType = filterType.RegExp; }
    202             else    { vI_notificationBar.dump("## vI_smartIdentity: filter emails, compare with '"
    203                     + filter_list[i] + "'\n"); recentfilterType = filterType.StrCmp; }
    204             for (j = 0; j < all_addresses.number; j++) { // check if recent email-address (pre-choosen identity) is found in
     141            if (filterList.length <= 1 && filterList[0] == "")
     142                { vI_notificationBar.dump("## identityCollection: no filters configured\n"); recentfilterType = filterType.None; }
     143            else if (/^\/(.*)\/$/.exec(filterList[i]))
     144                { vI_notificationBar.dump("## identityCollection: filter emails with RegExp '"
     145                    + filterList[i].replace(/\\/g,"\\\\") + "'\n"); recentfilterType = filterType.RegExp; }
     146            else    { vI_notificationBar.dump("## identityCollection: filter emails, compare with '"
     147                    + filterList[i] + "'\n"); recentfilterType = filterType.StrCmp; }
     148            for (j = 0; j < smartIdentities.number; j++) { // check if recent email-address (pre-choosen identity) is found in
    205149            // copied and adapted from correctIdentity, thank you for the RegExp-idea!
    206150                var add_addr = false;
     
    210154                    case filterType.RegExp:
    211155                        if (skipRegExp) break;
    212                         try {   /^\/(.*)\/$/.exec(filter_list[i]);
    213                             add_addr =  (all_addresses.emails[j].match(new RegExp(RegExp.$1,"i")))
     156                        try {   /^\/(.*)\/$/.exec(filterList[i]);
     157                            add_addr =  (smartIdentities.emails[j].match(new RegExp(RegExp.$1,"i")))
    214158                        }
    215159                        catch(vErr) {
    216160                            vI_notificationBar.addNote(
    217161                                vI.elements.strings.getString("vident.smartIdentity.ignoreRegExp") +
    218                                 +filter_list[i].replace(/\\/g,"\\\\") + " .",
     162                                +filterList[i].replace(/\\/g,"\\\\") + " .",
    219163                                "smart_reply_notification");
    220164                                skipRegExp = true; }
    221165                        break;
    222166                    case filterType.StrCmp:
    223                         add_addr = (filter_list[i] == all_addresses.emails[j])
     167                        add_addr = (filterList[i] == smartIdentities.emails[j])
    224168                        break;
    225169                }
    226                 if (add_addr)   return_addresses = vI_smartIdentity.addWithoutDuplicates(return_addresses,
    227                         all_addresses.emails[j],
    228                         all_addresses.fullNames[j],
    229                         all_addresses.combinedNames[j], null, null)
    230             }
    231         }
    232         return return_addresses;
    233     },
    234    
    235     mergeWithoutDuplicates : function(all_addresses, add_addresses) {
    236         for (index = 0; index < add_addresses.number; index++)
    237             vI_smartIdentity.addWithoutDuplicates(all_addresses,
    238                 add_addresses.emails[index],
    239                 add_addresses.fullNames[index],
    240                 add_addresses.combinedNames[index],
    241                 add_addresses.id_keys[index],
    242                 add_addresses.smtp_keys[index],
    243                 add_addresses.extras[index])
    244         return all_addresses
    245     },
    246    
    247     addWithoutDuplicates : function(all_addresses, email, fullName, combinedName, id_key, smtp_key, extra) {
    248         for (index = 0; index < all_addresses.number; index++) {
    249             if (all_addresses.emails[index] == email &&
    250                 (!all_addresses.id_keys[index] || !id_key ||
    251                     (all_addresses.id_keys[index] == id_key && all_addresses.smtp_keys[index] == smtp_key))) {
    252                 // found, so check if we can use the Name of the new field
    253                 if (all_addresses.fullNames[index] == "" && fullName != "") {
    254                     all_addresses.fullNames[index] = fullName
    255                     all_addresses.combinedNames[index] = combinedName
    256                     vI_notificationBar.dump("## vI_smartIdentity:   added fullName '" + fullName
    257                         + "' to stored email '" + email +"'\n")
    258                 }
    259                 // check if id_key, smtp_key or extras can be used
    260                 // only try this once, for the first Identity where id is set)
    261                 if (!all_addresses.id_keys[index] && id_key) {
    262                     all_addresses.id_keys[index] = id_key;
    263                     all_addresses.smtp_keys[index] = smtp_key;
    264                     all_addresses.extras[index] = extra;
    265                     vI_notificationBar.dump("## vI_smartIdentity:   added id '" + id_key
    266                         + "' smtp '" + smtp_key + "' (+extra) to stored email '" + email +"'\n")
    267                 }
    268                 return all_addresses;
    269             }
    270         }
    271         vI_notificationBar.dump("## vI_smartIdentity:   add new address to result:" + combinedName + "\n")
    272         all_addresses.emails[index] = email;
    273         all_addresses.fullNames[index] = fullName;
    274         all_addresses.combinedNames[index] = combinedName;
    275         all_addresses.id_keys[index] = id_key;
    276         all_addresses.smtp_keys[index] = smtp_key;
    277         all_addresses.number = index + 1;
    278         return all_addresses;
    279     },
    280    
    281     collectAddresses : function(hdr, all_addresses) {
     170                if (add_addr)   returnIdentities.addWithoutDuplicates(
     171                            smartIdentities.emails[j],
     172                            smartIdentities.fullNames[j],
     173                            smartIdentities.combinedNames[j], null, null)
     174            }
     175        }
     176        smartIdentities.takeOver(returnIdentities);
     177    },
     178   
     179    __smartReplyCollectAddresses : function(hdr, allIdentities) {
    282180        // add emails from selected headers (stored by vI_getHeader.xul/js)
    283181        var reply_headers = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("smart_reply_headers")).split(/\n/)
     
    309207                splitted.fullNames, splitted.combinedNames);
    310208           
    311             // move found addresses step by step to all_addresses, and change values if requested
     209            // move found addresses step by step to allIdentities, and change values if requested
    312210            for (i = 0; i < splitted.number; i++) {
    313                 all_addresses.emails[all_addresses.number] = splitted.emails.value[i]
     211                allIdentities.emails[allIdentities.number] = splitted.emails.value[i]
    314212               
    315213                // empty FullName if requested
    316                 if (replyHeaderEmptyFullNames) splitted.fullNames.value[i] = ""
    317                 all_addresses.fullNames[all_addresses.number] = splitted.fullNames.value[i]
     214                if (replyHeaderEmptyFullNames) allIdentities.fullNames[allIdentities.number] = ""
     215                else allIdentities.fullNames[allIdentities.number] = splitted.fullNames.value[i]   
    318216               
    319217                // set CombinedName related to new values
    320                 if (all_addresses.fullNames[all_addresses.number] != "")
    321                     all_addresses.combinedNames[all_addresses.number] =
    322                         all_addresses.fullNames[all_addresses.number] + " <" +
    323                         all_addresses.emails[all_addresses.number] + ">"
    324                 else all_addresses.combinedNames[all_addresses.number] =
    325                     all_addresses.emails[all_addresses.number]
     218                allIdentities.combinedNames[allIdentities.number] = vI_helper.combineNames(
     219                    allIdentities.fullNames[allIdentities.number],
     220                    allIdentities.emails[allIdentities.number])                 
    326221                   
    327222                // mark id, smtp and extra fields as empty
    328                 all_addresses.id_keys[all_addresses.number] = null;
    329                 all_addresses.smtp_keys[all_addresses.number] = null;
    330                 all_addresses.extras[all_addresses.number] = null;
     223                allIdentities.id_keys[allIdentities.number] = null;
     224                allIdentities.smtp_keys[allIdentities.number] = null;
     225                allIdentities.extras[allIdentities.number] = null;
    331226               
    332227                vI_notificationBar.dump("## vI_smartIdentity:   found '" +
    333                     all_addresses.combinedNames[all_addresses.number++] + "'\n")
     228                    allIdentities.combinedNames[allIdentities.number++] + "'\n")
    334229            }
    335230        }
     
    339234        vI_notificationBar.dump("## vI_smartIdentity: Reply()\n");
    340235               
    341         var storage_addresses = new identityCollection();
    342         vI_storage.getVIdentityFromAllRecipients(storage_addresses);
    343        
    344         var all_addresses = new identityCollection();
    345         if (storage_addresses.number == 0 || !vI.preferences.getBoolPref("idSelection_storage_ignore_smart_reply"))
    346             vI_smartIdentity.SmartReply(hdr, all_addresses);
     236        var storageIdentities = new identityCollection();
     237        vI_storage.getVIdentityFromAllRecipients(storageIdentities);
     238       
     239        var smartIdentities = new identityCollection();
     240        if (storageIdentities.number == 0 || !vI.preferences.getBoolPref("idSelection_storage_ignore_smart_reply"))
     241            vI_smartIdentity.__SmartReply(hdr, smartIdentities);
    347242        else vI_notificationBar.dump("## vI_smartIdentity: SmartReply skipped, Identities in Storage found.\n");
    348243
    349244        // merge SmartReply-Identities and Storage-Identites
    350245        if (vI.preferences.getBoolPref("idSelection_storage_prefer_smart_reply"))
    351             all_addresses = vI_smartIdentity.mergeWithoutDuplicates(all_addresses, storage_addresses)
     246            { smartIdentities.mergeWithoutDuplicates(storageIdentities); allIdentities = smartIdentities; }
    352247        else
    353             all_addresses = vI_smartIdentity.mergeWithoutDuplicates(storage_addresses, all_addresses)
    354        
    355         vI_notificationBar.dump("## vI_smartIdentity: merged SmartReply & Storage, " + all_addresses.number + " address(es) left\n")
    356        
    357         if (all_addresses.number == 0) return;
    358        
    359         //~ if (vI_smartIdentity.matchSelectedIdentity(all_addresses)) return;
    360        
    361         //~ if (vI_smartIdentity.smartIdentity_BaseIdentity = vI_smartIdentity.matchAnyIdentity(all_addresses)) {
    362             //~ vI_notificationBar.dump("## vI_smartIdentity:  existing Identity key: " + vI_smartIdentity.smartIdentity_BaseIdentity.key + "\n")
    363             //~ vI_notificationBar.addNote(
    364                 //~ vI.elements.strings.getString("vident.smartIdentity.matchExisting"),
    365                 //~ "smart_reply_notification");
    366             //~ window.setTimeout(vI_smartIdentity.updateMsgComposeDialog, 0);
    367             //~ return;
    368         //~ }
    369 
    370         vI_smartIdentity.smartIdentitySelection(all_addresses, false);
     248            { storageIdentities.mergeWithoutDuplicates(smartIdentities); allIdentities = storageIdentities; }
     249       
     250        vI_notificationBar.dump("## vI_smartIdentity: merged SmartReply & Storage, " + allIdentities.number + " address(es) left\n")
     251       
     252        if (allIdentities.number == 0) return;
     253       
     254        vI_smartIdentity.__smartIdentitySelection(allIdentities, false);
    371255    },
    372256   
    373257    // this function checks if we have a reply-case and Smart-Reply should replace the Identity
    374     SmartReply : function(hdr, all_addresses) {
     258    __SmartReply : function(hdr, smartIdentities) {
    375259        if (!vI.preferences.getBoolPref("smart_reply"))
    376260            { vI_notificationBar.dump("## vI_smartIdentity: SmartReply deactivated\n"); return; }
     
    380264        }
    381265
    382         vI_notificationBar.dump("## vI_smartIdentity: SmartReply()\n");
     266        vI_notificationBar.dump("## vI_smartIdentity: __SmartReply()\n");
    383267        vI_notificationBar.dump("## vI_smartIdentity: ----------------------------------------------------------\n")
    384268        if (hdr) {
    385269            /* first step: collect addresses */
    386             vI_smartIdentity.collectAddresses(hdr, all_addresses);
    387             vI_notificationBar.dump("## vI_smartIdentity: " + all_addresses.number + " address(es) after parsing, before filtering\n")
     270            vI_smartIdentity.__smartReplyCollectAddresses(hdr, smartIdentities);
     271            vI_notificationBar.dump("## vI_smartIdentity: " + smartIdentities.number + " address(es) after parsing, before filtering\n")
    388272           
    389273            /* second step: filter (and sort) addresses */
    390             vI_smartIdentity.filterAddresses(all_addresses);
    391            
    392             vI_notificationBar.dump("## vI_smartIdentity: filtering done, " + all_addresses.number + " address(es) left\n")
     274            vI_smartIdentity.__filterAddresses(smartIdentities);
     275           
     276            vI_notificationBar.dump("## vI_smartIdentity: filtering done, " + smartIdentities.number + " address(es) left\n")
    393277           
    394278            /* set default FullName */
    395279            var smart_reply_defaultFullName = vI.unicodeConverter.ConvertToUnicode(vI.preferences.getCharPref("smart_reply_defaultFullName"))
    396280            if (smart_reply_defaultFullName != "") {
    397                 for (index = 0; index < all_addresses.number; index++) {
    398                     if (all_addresses.fullNames[index] == "") {
    399                         all_addresses.fullNames[index] = smart_reply_defaultFullName
    400                         all_addresses.combinedNames[index] =
    401                             smart_reply_defaultFullName + " <" + all_addresses.emails[index] + ">"
     281                for (index = 0; index < smartIdentities.number; index++) {
     282                    if (smartIdentities.fullNames[index] == "") {
     283                        smartIdentities.fullNames[index] = smart_reply_defaultFullName
     284                        smartIdentities.combinedNames[index] =
     285                            smart_reply_defaultFullName + " <" + smartIdentities.emails[index] + ">"
    402286                        vI_notificationBar.dump("## vI_smartIdentity: added default FullName '" +
    403                             smart_reply_defaultFullName + "' to '" + all_addresses.emails[index] + "'\n")
     287                            smart_reply_defaultFullName + "' to '" + smartIdentities.emails[index] + "'\n")
    404288                    }
    405289                }
     
    411295    },
    412296   
    413     smartIdentitySelection : function(all_addresses, autocreate) {
    414         vI_msgIdentityClone.addIdentitiesToCloneMenu(all_addresses);
     297    __smartIdentitySelection : function(allIdentities, autocreate) {
     298        vI_msgIdentityClone.addIdentitiesToCloneMenu(allIdentities);
    415299       
    416300        if (!autocreate && vI.preferences.getBoolPref("idSelection_ask") &&
    417             ((all_addresses.number == 1 && vI.preferences.getBoolPref("idSelection_ask_always"))
    418                 || all_addresses.number > 1))
     301            ((allIdentities.number == 1 && vI.preferences.getBoolPref("idSelection_ask_always"))
     302                || allIdentities.number > 1))
    419303            window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0, // give the Dialog a unique id
    420304                    "chrome, dialog, modal, alwaysRaised, resizable=yes",
    421                      all_addresses,
     305                     allIdentities,
    422306                    /* callback: */ vI_smartIdentity.changeIdentityToSmartIdentity).focus();
    423307        else if (autocreate || vI.preferences.getBoolPref("idSelection_autocreate")) {
    424             vI_smartIdentity.changeIdentityToSmartIdentity(all_addresses, 0);
     308            vI_smartIdentity.changeIdentityToSmartIdentity(allIdentities, 0);
    425309        }   
    426310    },
    427311   
    428     changeIdentityToSmartIdentity : function(all_addresses, selectedValue) {
    429         if (all_addresses.id_keys[selectedValue]) {
    430             vI_msgIdentityClone.setMenuToIdentity(all_addresses.id_keys[selectedValue])
    431             vI_smtpSelector.setMenuToKey(all_addresses.smtp_keys[selectedValue])
    432         }
    433         vI_msgIdentityClone.setIdentity(all_addresses.combinedNames[selectedValue], null);
     312    changeIdentityToSmartIdentity : function(allIdentities, selectedValue) {
     313        if (allIdentities.id_keys[selectedValue]) {
     314            vI_msgIdentityClone.setMenuToIdentity(allIdentities.id_keys[selectedValue])
     315            vI_smtpSelector.setMenuToKey(allIdentities.smtp_keys[selectedValue])
     316        }
     317        vI_msgIdentityClone.setIdentity(allIdentities.combinedNames[selectedValue], null);
    434318        if (vI_msgIdentityClone.elements.Obj_MsgIdentity_clone.getAttribute("value") == "vid") {
    435319            var label=vI.elements.strings.getString("vident.smartIdentity.vIUsage");
    436             if (all_addresses.number > 1) label += " "
     320            if (allIdentities.number > 1) label += " "
    437321                + vI.elements.strings.getString("vident.smartIdentity.moreThanOne");
    438322            vI_notificationBar.addNote(label + ".", "smart_reply_notification");
    439323        }
    440         vI_smartIdentity.removeSmartIdentityFromRecipients(all_addresses, selectedValue);
    441     },
    442    
    443     removeSmartIdentityFromRecipients : function(all_addresses, index) {
     324        vI_smartIdentity.__removeSmartIdentityFromRecipients(allIdentities, selectedValue);
     325    },
     326   
     327    __removeSmartIdentityFromRecipients : function(allIdentities, index) {
    444328        var bcc_addresses = { number : 1, emails : {}, fullNames : {}, combinedNames : {} };
    445329        var skip_bcc = false;
     
    450334           
    451335            for (index = 0; index < bcc_addresses.number; index++) {
    452                 if (all_addresses.emails[index] == bcc_addresses.emails.value[index]) {
     336                if (allIdentities.emails[index] == bcc_addresses.emails.value[index]) {
    453337                    skip_bcc = true; break;
    454338                }
     
    462346            if ((awGetPopupElement(row).selectedItem.getAttribute("value") == "addr_bcc") && skip_bcc) continue;
    463347            // check if entry is matching senders address, if so, remove it
    464             if (input.value == all_addresses.emails[index] ||
    465                 input.value == all_addresses.combinedNames[index]) {
     348            if (input.value == allIdentities.emails[index] ||
     349                input.value == allIdentities.combinedNames[index]) {
    466350                    awSetInputAndPopupValue(input, "", popup, "addr_to", -1);
    467351                    awCleanupRows()
     
    472356            }
    473357        }
    474     },
    475    
    476     //~ updateMsgComposeDialog : function() {
    477         //~ vI_msgIdentityClone.setMenuToIdentity(vI_smartIdentity.smartIdentity_BaseIdentity.key);
    478         //~ // after inserting a new signature (as part of the new identity) the cursor is not at the right place.
    479         //~ // there is no easy way to set the cursor at the end, before the signature, so set it at the beginning.
    480         //~ if (vI_smartIdentity.smartIdentity_BaseIdentity.attachSignature)
    481             //~ gMsgCompose.editor.beginningOfDocument();
    482     //~ },
     358    }
    483359}
  • chrome/content/v_identity/vI_storage.js

    rd3c905 r6a7d00  
    9696    smtp_keys : {},
    9797    extras : {},
     98   
     99    mergeWithoutDuplicates : function(addIdentityCollection) {
     100        for (index = 0; index < addIdentityCollection.number; index++)
     101            this.addWithoutDuplicates(
     102                addIdentityCollection.emails[index],
     103                addIdentityCollection.fullNames[index],
     104                addIdentityCollection.combinedNames[index],
     105                addIdentityCollection.id_keys[index],
     106                addIdentityCollection.smtp_keys[index],
     107                addIdentityCollection.extras[index])
     108    },
     109
     110    addWithoutDuplicates : function(email, fullName, combinedName, id_key, smtp_key, extra) {
     111        for (index = 0; index < this.number; index++) {
     112            if (this.emails[index] == email &&
     113                (!this.id_keys[index] || !id_key ||
     114                    (this.id_keys[index] == id_key && this.smtp_keys[index] == smtp_key))) {
     115                // found, so check if we can use the Name of the new field
     116                if (this.fullNames[index] == "" && fullName != "") {
     117                    this.fullNames[index] = fullName
     118                    this.combinedNames[index] = combinedName
     119                    vI_notificationBar.dump("## identityCollection:   added fullName '" + fullName
     120                        + "' to stored email '" + email +"'\n")
     121                }
     122                // check if id_key, smtp_key or extras can be used
     123                // only try this once, for the first Identity where id is set)
     124                if (!this.id_keys[index] && id_key) {
     125                    this.id_keys[index] = id_key;
     126                    this.smtp_keys[index] = smtp_key;
     127                    this.extras[index] = extra;
     128                    vI_notificationBar.dump("## identityCollection:   added id '" + id_key
     129                        + "' smtp '" + smtp_key + "' (+extra) to stored email '" + email +"'\n")
     130                }
     131                return;
     132            }
     133        }
     134        vI_notificationBar.dump("## identityCollection:   add new address to result:" + combinedName + "\n")
     135        this.emails[index] = email;
     136        this.fullNames[index] = fullName;
     137        this.combinedNames[index] = combinedName;
     138        this.id_keys[index] = id_key;
     139        this.smtp_keys[index] = smtp_key;
     140        this.number = index + 1;
     141    },
     142   
     143    takeOver : function(newIdentityCollection) {
     144        this.number = newIdentityCollection.number
     145        this.emails = newIdentityCollection.emails
     146        this.fullNames = newIdentityCollection.fullNames
     147        this.combinedNames = newIdentityCollection.combinedNames
     148        this.id_keys = newIdentityCollection.id_keys
     149        this.smtp_keys = newIdentityCollection.smtp_keys
     150        this.extras = newIdentityCollection.extras
     151    }
    98152};
    99153
     
    455509    },
    456510       
    457     getVIdentityFromAllRecipients : function(all_addresses) {
     511    getVIdentityFromAllRecipients : function(allIdentities) {
    458512        if (!vI.preferences.getBoolPref("storage"))
    459513            { vI_notificationBar.dump("## vI_storage: Storage deactivated\n"); return; }
     
    466520            recipient = vI_storage.__getDescriptionAndType(awGetInputElement(row).value, recipientType);
    467521            var storageData = vI_rdfDatasource.readVIdentityFromRDF(recipient.recDesc, recipient.recType);
    468             if (storageData) vI_smartIdentity.addWithoutDuplicates(all_addresses,
     522            if (storageData) allIdentities.addWithoutDuplicates(
    469523                storageData.email,
    470524                storageData.fullName,
     
    473527                storageData.smtp)
    474528        }
    475         vI_notificationBar.dump("## vI_storage: found " + all_addresses.number + " address(es)\n")
     529        vI_notificationBar.dump("## vI_storage: found " + allIdentities.number + " address(es)\n")
    476530    }
    477531}
Note: See TracChangeset for help on using the changeset viewer.