This is just some static backup of the original site, don't expect every link to work!

Ignore:
Timestamp:
Nov 3, 2014, 12:35:40 PM (8 years ago)
Author:
rene <rene@…>
Branches:
ng_0.9
Children:
7204cb
Parents:
3c9c29
Message:

code formatting (no code changes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • content/vI_smartIdentity.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27 
    28 let Log = vI.setupLogging("virtualIdentity.smartIdentity");
    29 
    30 Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
    31 Components.utils.import("resource://v_identity/vI_smartIdentityCollection.js", virtualIdentityExtension);
    32 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    33 
    34 var smartIdentity = {
    35     messenger : Components.classes["@mozilla.org/messenger;1"].createInstance()
    36         .QueryInterface(Components.interfaces.nsIMessenger),
    37    
    38     stringBundle : Components.classes["@mozilla.org/intl/stringbundle;1"]
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28
     29    let Log = vI.setupLogging("virtualIdentity.smartIdentity");
     30
     31    Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
     32    Components.utils.import("resource://v_identity/vI_smartIdentityCollection.js", virtualIdentityExtension);
     33    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     34
     35    var smartIdentity = {
     36      messenger: Components.classes["@mozilla.org/messenger;1"].createInstance()
     37        .QueryInterface(Components.interfaces.nsIMessenger),
     38
     39      stringBundle: Components.classes["@mozilla.org/intl/stringbundle;1"]
    3940        .getService(Components.interfaces.nsIStringBundleService)
    4041        .createBundle("chrome://v_identity/locale/v_identity.properties"),
    4142
    42     _smartIdentityCollection : null,
    43        
    44     // After Loading the MessageComposeDialog, check if smartIdentity is needed
    45     init : function(currentWindow) {
    46         var msgHdr;
    47         var msgComposeTypeReference = Components.interfaces.nsIMsgCompType;
    48         var newsgroup = gMsgCompose.compFields.newsgroups;
    49         var autocreate = false;
    50         Log.debug("msgComposeTypeReference = " + gMsgCompose.type);
    51         switch (gMsgCompose.type) {
    52             case msgComposeTypeReference.Reply:
    53             case msgComposeTypeReference.ReplyAll:
    54             case msgComposeTypeReference.ReplyToGroup: // reply to a newsgroup, would possibly be stopped later
    55             case msgComposeTypeReference.ReplyToSender:
    56             case msgComposeTypeReference.ReplyToSenderAndGroup: // reply to a newsgroup, would possibly be stopped later
    57             case msgComposeTypeReference.ReplyWithTemplate:
    58             case msgComposeTypeReference.ReplyToList:
    59                 Log.debug("Reply");
    60                 msgHdr = smartIdentity.messenger.
    61                     messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI);
    62                 smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow));
    63                 smartIdentity._smartIdentityCollection.Reply();
    64                 autocreate = false; break;
    65             case msgComposeTypeReference.Draft:
    66             case msgComposeTypeReference.Template:
    67                 Log.debug("Draft");
    68                 msgHdr = smartIdentity.messenger.
    69                     messageServiceFromURI(gMsgCompose.compFields.draftId).messageURIToMsgHdr(gMsgCompose.compFields.draftId);
    70                 smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow));
    71                 smartIdentity._smartIdentityCollection.Draft();
    72                 autocreate = false; break;
    73             case msgComposeTypeReference.ForwardAsAttachment:
    74             case msgComposeTypeReference.ForwardInline:
    75             case msgComposeTypeReference.New:
    76             case msgComposeTypeReference.NewsPost:
    77             case msgComposeTypeReference.MailToUrl:
    78                 Log.debug("New Mail");
    79                 smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(null, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow));   
    80                 // to enable composing new email with new identity: identity is hidden in subject line
    81                 // used for instance from conversation addon
    82                 var subject = gMsgCompose.compFields.subject.split(/\n/);
    83                 if (subject.length > 1 && subject[1] == "virtualIdentityExtension") {
    84                     Log.debug("NewMail() found stored identity preset: " + subject[2]);
    85                     smartIdentity._smartIdentityCollection.__parseHeadersWithArray(subject[2], smartIdentity._smartIdentityCollection._allIdentities);
    86                     gMsgCompose.compFields.subject = subject[0];
    87                     document.getElementById("msgSubject").value = subject[0];
    88                 }
    89                 else smartIdentity._smartIdentityCollection.NewMail();
    90                 autocreate = true; break;
    91         }
    92         if (smartIdentity._smartIdentityCollection._allIdentities.number > 0) smartIdentity.__smartIdentitySelection(autocreate);
    93     },
    94    
    95     _getRecipients : function(currentWindow) {
    96         var recipients = [];
    97         for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
    98             var recipientType = currentWindow.awGetPopupElement(row).selectedItem.getAttribute("value");
    99             if (recipientType == "addr_reply" || recipientType == "addr_followup" ||
    100                 vI.storage.isDoBcc(row, currentWindow) || currentWindow.awGetInputElement(row).value.match(/^\s*$/) ) continue;
    101             recipients.push( { recipient: currentWindow.awGetInputElement(row).value, recipientType : recipientType } );
    102         }
    103         return recipients;
    104     },
    105    
    106     __smartIdentitySelection : function(autocreate) {
    107         Log.debug("__smartIdentitySelection autocreate=" + autocreate);
    108        
    109         if (vI.vIprefs.get("idSelection_preferExisting")) {
    110             var existingIDIndex = smartIdentity._smartIdentityCollection._foundExistingIdentity();
    111             if (existingIDIndex) {
    112                 Log.debug("found existing Identity, use without interaction.");
    113                 // add all Indentities to Clone Menu before selecting and leaving the function
    114                 document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
    115                 smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, existingIDIndex.key);
    116                 return;
    117             }
    118         }
    119        
    120         document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
    121         Log.debug("__smartIdentitySelection _allIdentities.number=" +
    122                 smartIdentity._smartIdentityCollection._allIdentities.number +
    123                 " _ask_always=" + vI.vIprefs.get("idSelection_ask_always") +
    124                 " _ask=" + vI.vIprefs.get("idSelection_ask"));
    125         if (!autocreate && vI.vIprefs.get("idSelection_ask") &&
    126             ((smartIdentity._smartIdentityCollection._allIdentities.number == 1 && vI.vIprefs.get("idSelection_ask_always"))
    127                 || smartIdentity._smartIdentityCollection._allIdentities.number > 1)) {
    128             for (var index = 0; index < smartIdentity._smartIdentityCollection._allIdentities.number; index++) {
    129                 Log.debug("smartIdentityReplyDialog index=" + index + ": '" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].combinedName + "' "
    130                     + "(" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].id.value + "," + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].smtp.value + ")");
    131             }
    132             window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul",0,
    133                     "chrome, dialog, modal, alwaysRaised, resizable=yes",
    134                      smartIdentity._smartIdentityCollection._allIdentities,
    135                     /* callback: */ smartIdentity.changeIdentityToSmartIdentity).focus();
    136         }
    137         else if (autocreate || vI.vIprefs.get("idSelection_autocreate")) {
    138             smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, 0);
    139         }   
    140     },
    141    
    142     changeIdentityToSmartIdentity : function(allIdentities, selectedValue) {
    143         Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + " from " + allIdentities.number);
    144         Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + ": '" + allIdentities.identityDataCollection[selectedValue].combinedName + "' "
    145             + "(" + allIdentities.identityDataCollection[selectedValue].id.value + "," + allIdentities.identityDataCollection[selectedValue].smtp.value + ")");
    146         document.getElementById("virtualIdentityExtension_msgIdentityClone").selectedMenuItem = allIdentities.menuItems[selectedValue];
    147         if (document.getElementById("virtualIdentityExtension_msgIdentityClone").vid) {
    148             var label=smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.vIUsage");
    149             if (allIdentities.number > 1) label += " "
    150                 + smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.moreThanOne");
    151             vI.SmartReplyNotification.info(label + ".");
    152         }
    153         smartIdentity.__removeSmartIdentityFromRecipients(allIdentities, selectedValue);
    154     },
    155    
    156     __removeSmartIdentityFromRecipients : function(allIdentities, index) {
    157         if (!vI.vIprefs.get("idSelection_removeSmartIdentityFromRecipients")) return;
    158        
    159         // check if selected email is defined as doBcc address. If so, it should not be removed.
    160         var skip_bcc = false;
    161         if (getCurrentIdentity().doBcc) {
    162             var bcc_addresses = new vI.identityCollection();
    163             smartIdentity.__parseHeadersWithArray(getCurrentIdentity().doBccList, bcc_addresses);
    164            
    165             for (var i = 0; i < bcc_addresses.number; i++) {
    166                 if (allIdentities.identityDataCollection[index].email == bcc_addresses.identityDataCollection[i].email) {
    167                     skip_bcc = true; break;
    168                 }
    169             }
    170         }
    171        
    172         // check if there is more than one recipient for this mail. If not, preserve the only one existing.
    173         var recipientCount = 0;
    174         for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
    175             var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
    176             if (recipientType == "addr_to" || recipientType == "addr_cc") recipientCount++;
    177         }
    178         if (recipientCount < 2) return;
    179        
    180        
    181         for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
    182             var popup = awGetPopupElement(row);
    183             var input = awGetInputElement(row);
    184             var recipientType = popup.selectedItem.getAttribute("value");
    185             // if the entry is not a recipient, just continue
    186             if (recipientType == "addr_reply" || recipientType == "addr_followup") continue;
    187             // check if the entry is used as a BCC selected in account settings
    188             if (recipientType == "addr_bcc" && skip_bcc) continue;
    189             // check if entry is matching senders address, if so, remove it
    190             if (input.value == allIdentities.identityDataCollection[index].email ||
    191                 input.value == allIdentities.identityDataCollection[index].combinedName) {
    192                     awSetInputAndPopupValue(input, "", popup, "addr_to", -1);
    193                     awCleanupRows()
    194                     vI.SmartReplyNotification.info(" " + smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.remRecipient"));
    195                     break;
    196             }
    197         }
    198     }
    199 }
    200 vI.smartIdentity = smartIdentity;
    201 }});
     43      _smartIdentityCollection: null,
     44
     45      // After Loading the MessageComposeDialog, check if smartIdentity is needed
     46      init: function (currentWindow) {
     47        var msgHdr;
     48        var msgComposeTypeReference = Components.interfaces.nsIMsgCompType;
     49        var newsgroup = gMsgCompose.compFields.newsgroups;
     50        var autocreate = false;
     51        Log.debug("msgComposeTypeReference = " + gMsgCompose.type);
     52        switch (gMsgCompose.type) {
     53        case msgComposeTypeReference.Reply:
     54        case msgComposeTypeReference.ReplyAll:
     55        case msgComposeTypeReference.ReplyToGroup: // reply to a newsgroup, would possibly be stopped later
     56        case msgComposeTypeReference.ReplyToSender:
     57        case msgComposeTypeReference.ReplyToSenderAndGroup: // reply to a newsgroup, would possibly be stopped later
     58        case msgComposeTypeReference.ReplyWithTemplate:
     59        case msgComposeTypeReference.ReplyToList:
     60          Log.debug("Reply");
     61          msgHdr = smartIdentity.messenger.
     62          messageServiceFromURI(gMsgCompose.originalMsgURI).messageURIToMsgHdr(gMsgCompose.originalMsgURI);
     63          smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow));
     64          smartIdentity._smartIdentityCollection.Reply();
     65          autocreate = false;
     66          break;
     67        case msgComposeTypeReference.Draft:
     68        case msgComposeTypeReference.Template:
     69          Log.debug("Draft");
     70          msgHdr = smartIdentity.messenger.
     71          messageServiceFromURI(gMsgCompose.compFields.draftId).messageURIToMsgHdr(gMsgCompose.compFields.draftId);
     72          smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(msgHdr, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow));
     73          smartIdentity._smartIdentityCollection.Draft();
     74          autocreate = false;
     75          break;
     76        case msgComposeTypeReference.ForwardAsAttachment:
     77        case msgComposeTypeReference.ForwardInline:
     78        case msgComposeTypeReference.New:
     79        case msgComposeTypeReference.NewsPost:
     80        case msgComposeTypeReference.MailToUrl:
     81          Log.debug("New Mail");
     82          smartIdentity._smartIdentityCollection = new vI.smartIdentityCollection(null, getCurrentIdentity(), document.getElementById("virtualIdentityExtension_msgIdentityClone").vid, newsgroup, this._getRecipients(currentWindow));
     83          // to enable composing new email with new identity: identity is hidden in subject line
     84          // used for instance from conversation addon
     85          var subject = gMsgCompose.compFields.subject.split(/\n/);
     86          if (subject.length > 1 && subject[1] == "virtualIdentityExtension") {
     87            Log.debug("NewMail() found stored identity preset: " + subject[2]);
     88            smartIdentity._smartIdentityCollection.__parseHeadersWithArray(subject[2], smartIdentity._smartIdentityCollection._allIdentities);
     89            gMsgCompose.compFields.subject = subject[0];
     90            document.getElementById("msgSubject").value = subject[0];
     91          } else smartIdentity._smartIdentityCollection.NewMail();
     92          autocreate = true;
     93          break;
     94        }
     95        if (smartIdentity._smartIdentityCollection._allIdentities.number > 0) smartIdentity.__smartIdentitySelection(autocreate);
     96      },
     97
     98      _getRecipients: function (currentWindow) {
     99        var recipients = [];
     100        for (var row = 1; row <= top.MAX_RECIPIENTS; row++) {
     101          var recipientType = currentWindow.awGetPopupElement(row).selectedItem.getAttribute("value");
     102          if (recipientType == "addr_reply" || recipientType == "addr_followup" ||
     103            vI.storage.isDoBcc(row, currentWindow) || currentWindow.awGetInputElement(row).value.match(/^\s*$/)) continue;
     104          recipients.push({
     105            recipient: currentWindow.awGetInputElement(row).value,
     106            recipientType: recipientType
     107          });
     108        }
     109        return recipients;
     110      },
     111
     112      __smartIdentitySelection: function (autocreate) {
     113        Log.debug("__smartIdentitySelection autocreate=" + autocreate);
     114
     115        if (vI.vIprefs.get("idSelection_preferExisting")) {
     116          var existingIDIndex = smartIdentity._smartIdentityCollection._foundExistingIdentity();
     117          if (existingIDIndex) {
     118            Log.debug("found existing Identity, use without interaction.");
     119            // add all Indentities to Clone Menu before selecting and leaving the function
     120            document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
     121            smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, existingIDIndex.key);
     122            return;
     123          }
     124        }
     125
     126        document.getElementById("virtualIdentityExtension_msgIdentityClone").addIdentitiesToCloneMenu(smartIdentity._smartIdentityCollection._allIdentities);
     127        Log.debug("__smartIdentitySelection _allIdentities.number=" +
     128          smartIdentity._smartIdentityCollection._allIdentities.number +
     129          " _ask_always=" + vI.vIprefs.get("idSelection_ask_always") +
     130          " _ask=" + vI.vIprefs.get("idSelection_ask"));
     131        if (!autocreate && vI.vIprefs.get("idSelection_ask") &&
     132          ((smartIdentity._smartIdentityCollection._allIdentities.number == 1 && vI.vIprefs.get("idSelection_ask_always")) || smartIdentity._smartIdentityCollection._allIdentities.number > 1)) {
     133          for (var index = 0; index < smartIdentity._smartIdentityCollection._allIdentities.number; index++) {
     134            Log.debug("smartIdentityReplyDialog index=" + index + ": '" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].combinedName + "' " + "(" + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].id.value + "," + smartIdentity._smartIdentityCollection._allIdentities.identityDataCollection[index].smtp.value + ")");
     135          }
     136          window.openDialog("chrome://v_identity/content/vI_smartReplyDialog.xul", 0,
     137            "chrome, dialog, modal, alwaysRaised, resizable=yes",
     138            smartIdentity._smartIdentityCollection._allIdentities,
     139            /* callback: */
     140            smartIdentity.changeIdentityToSmartIdentity).focus();
     141        } else if (autocreate || vI.vIprefs.get("idSelection_autocreate")) {
     142          smartIdentity.changeIdentityToSmartIdentity(smartIdentity._smartIdentityCollection._allIdentities, 0);
     143        }
     144      },
     145
     146      changeIdentityToSmartIdentity: function (allIdentities, selectedValue) {
     147        Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + " from " + allIdentities.number);
     148        Log.debug("changeIdentityToSmartIdentity selectedValue=" + selectedValue + ": '" + allIdentities.identityDataCollection[selectedValue].combinedName + "' " + "(" + allIdentities.identityDataCollection[selectedValue].id.value + "," + allIdentities.identityDataCollection[selectedValue].smtp.value + ")");
     149        document.getElementById("virtualIdentityExtension_msgIdentityClone").selectedMenuItem = allIdentities.menuItems[selectedValue];
     150        if (document.getElementById("virtualIdentityExtension_msgIdentityClone").vid) {
     151          var label = smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.vIUsage");
     152          if (allIdentities.number > 1) label += " " + smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.moreThanOne");
     153          vI.SmartReplyNotification.info(label + ".");
     154        }
     155        smartIdentity.__removeSmartIdentityFromRecipients(allIdentities, selectedValue);
     156      },
     157
     158      __removeSmartIdentityFromRecipients: function (allIdentities, index) {
     159        if (!vI.vIprefs.get("idSelection_removeSmartIdentityFromRecipients")) return;
     160
     161        // check if selected email is defined as doBcc address. If so, it should not be removed.
     162        var skip_bcc = false;
     163        if (getCurrentIdentity().doBcc) {
     164          var bcc_addresses = new vI.identityCollection();
     165          smartIdentity.__parseHeadersWithArray(getCurrentIdentity().doBccList, bcc_addresses);
     166
     167          for (var i = 0; i < bcc_addresses.number; i++) {
     168            if (allIdentities.identityDataCollection[index].email == bcc_addresses.identityDataCollection[i].email) {
     169              skip_bcc = true;
     170              break;
     171            }
     172          }
     173        }
     174
     175        // check if there is more than one recipient for this mail. If not, preserve the only one existing.
     176        var recipientCount = 0;
     177        for (var row = 1; row <= top.MAX_RECIPIENTS; row++) {
     178          var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
     179          if (recipientType == "addr_to" || recipientType == "addr_cc") recipientCount++;
     180        }
     181        if (recipientCount < 2) return;
     182
     183
     184        for (var row = 1; row <= top.MAX_RECIPIENTS; row++) {
     185          var popup = awGetPopupElement(row);
     186          var input = awGetInputElement(row);
     187          var recipientType = popup.selectedItem.getAttribute("value");
     188          // if the entry is not a recipient, just continue
     189          if (recipientType == "addr_reply" || recipientType == "addr_followup") continue;
     190          // check if the entry is used as a BCC selected in account settings
     191          if (recipientType == "addr_bcc" && skip_bcc) continue;
     192          // check if entry is matching senders address, if so, remove it
     193          if (input.value == allIdentities.identityDataCollection[index].email ||
     194            input.value == allIdentities.identityDataCollection[index].combinedName) {
     195            awSetInputAndPopupValue(input, "", popup, "addr_to", -1);
     196            awCleanupRows()
     197            vI.SmartReplyNotification.info(" " + smartIdentity.stringBundle.GetStringFromName("vident.smartIdentity.remRecipient"));
     198            break;
     199          }
     200        }
     201      }
     202    }
     203    vI.smartIdentity = smartIdentity;
     204  }
     205});
Note: See TracChangeset for help on using the changeset viewer.