Changeset 509348


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

code formatting (no code changes)

Files:
38 edited

Legend:

Unmodified
Added
Removed
  • content/accountManagerOverlays/vI_am-Overlay.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27 function orig_onAccept() {};
    28 var am_Overlay = {
    29     onAccept : function(aServerKeyToSelect, aFocusList) {
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28    function orig_onAccept() {};
     29    var am_Overlay = {
     30      onAccept: function (aServerKeyToSelect, aFocusList) {
    3031        orig_onAccept();
    3132        var gObserver = Components.classes["@mozilla.org/observer-service;1"].
    32             getService(Components.interfaces.nsIObserverService);
     33        getService(Components.interfaces.nsIObserverService);
    3334        gObserver.notifyObservers(null, "am-acceptChanges", "other");
    34     },
    35    
    36     init : function() {
     35      },
     36
     37      init: function () {
    3738        orig_onAccept = onAccept;
    3839        onAccept = am_Overlay.onAccept;
     40      }
    3941    }
    40 }
    41 window.addEventListener('load', am_Overlay.init, false);
    42 }});
     42    window.addEventListener('load', am_Overlay.init, false);
     43  }
     44});
  • content/accountManagerOverlays/vI_am-smtpOverlay.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27 var am_smtpOverlay = {
    28     refreshServerList : function(aServerKeyToSelect, aFocusList) {
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28    var am_smtpOverlay = {
     29      refreshServerList: function (aServerKeyToSelect, aFocusList) {
    2930        gSmtpServerListWindow.orig_refreshServerList(aServerKeyToSelect, aFocusList);
    3031        var gObserver = Components.classes["@mozilla.org/observer-service;1"].
    31             getService(Components.interfaces.nsIObserverService);
     32        getService(Components.interfaces.nsIObserverService);
    3233        gObserver.notifyObservers(null, "am-smtpChanges", "other");
    33     },
    34    
    35     init : function() {
     34      },
     35
     36      init: function () {
    3637        gSmtpServerListWindow.orig_refreshServerList = gSmtpServerListWindow.refreshServerList;
    3738        gSmtpServerListWindow.refreshServerList = am_smtpOverlay.refreshServerList;
     39      }
    3840    }
    39 }
    40 window.addEventListener('load', am_smtpOverlay.init, false);
    41 }});
     41    window.addEventListener('load', am_smtpOverlay.init, false);
     42  }
     43});
  • content/prefDialog/vI_prefDialog.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27 
    28 Components.utils.import("resource://gre/modules/AddonManager.jsm");
    29 let Log = vI.setupLogging("virtualIdentity.prefDialog");
    30 
    31 var prefDialog = {
    32     toggleHelp : function() {
    33         var browserElem = document.getElementById("virtualIdentityExtension_remoteBrowserBox");
    34         if (browserElem.getAttribute("hidden")) {
    35             window.resizeBy( 200, 0);
    36             browserElem.removeAttribute("hidden");
    37         } else {
    38             window.resizeBy( -(browserElem.clientWidth+7), 0);
    39             browserElem.setAttribute("hidden", "true");
    40         }
    41         prefDialog.updateHelpUrl();
    42     },
    43 
    44     updateHelpUrl : function(tabpanel) {
    45         var browserElem = document.getElementById("virtualIdentityExtension_remoteBrowserBox");
    46         if (browserElem.getAttribute("hidden")) return;             // don't load any url if browser is hidden
    47         var panelIndex = (tabpanel)?tabpanel:document.getElementById('prefTabbox').selectedIndex
    48         var prefTree = document.getElementById('prefTabbox').selectedPanel.getElementsByAttribute("class", "vIprefTree")[0];
    49         var currentVersion = document.getElementById("virtualIdentityExtension_extVersion").getAttribute("value").split(/\./);
    50         var extVersion = currentVersion[0] + "." + currentVersion[1];
    51         var url = "https://www.absorb.it/virtual-id/wiki/docs/" + extVersion + "/tab" + panelIndex + "/tree" + prefTree.currentIndex;
    52         document.getElementById("virtualIdentityExtension_remoteBrowserBox").url = url;
    53     },
    54 
    55     preferences : Components.classes["@mozilla.org/preferences-service;1"]
    56                 .getService(Components.interfaces.nsIPrefService)
    57                 .getBranch("extensions.virtualIdentity."),
    58                
    59     unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
    60                 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
    61    
    62     selectFile : function(elementID) {
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28
     29    Components.utils.import("resource://gre/modules/AddonManager.jsm");
     30    let Log = vI.setupLogging("virtualIdentity.prefDialog");
     31
     32    var prefDialog = {
     33      toggleHelp: function () {
     34        var browserElem = document.getElementById("virtualIdentityExtension_remoteBrowserBox");
     35        if (browserElem.getAttribute("hidden")) {
     36          window.resizeBy(200, 0);
     37          browserElem.removeAttribute("hidden");
     38        } else {
     39          window.resizeBy(-(browserElem.clientWidth + 7), 0);
     40          browserElem.setAttribute("hidden", "true");
     41        }
     42        prefDialog.updateHelpUrl();
     43      },
     44
     45      updateHelpUrl: function (tabpanel) {
     46        var browserElem = document.getElementById("virtualIdentityExtension_remoteBrowserBox");
     47        if (browserElem.getAttribute("hidden")) return; // don't load any url if browser is hidden
     48        var panelIndex = (tabpanel) ? tabpanel : document.getElementById('prefTabbox').selectedIndex
     49        var prefTree = document.getElementById('prefTabbox').selectedPanel.getElementsByAttribute("class", "vIprefTree")[0];
     50        var currentVersion = document.getElementById("virtualIdentityExtension_extVersion").getAttribute("value").split(/\./);
     51        var extVersion = currentVersion[0] + "." + currentVersion[1];
     52        var url = "https://www.absorb.it/virtual-id/wiki/docs/" + extVersion + "/tab" + panelIndex + "/tree" + prefTree.currentIndex;
     53        document.getElementById("virtualIdentityExtension_remoteBrowserBox").url = url;
     54      },
     55
     56      preferences: Components.classes["@mozilla.org/preferences-service;1"]
     57        .getService(Components.interfaces.nsIPrefService)
     58        .getBranch("extensions.virtualIdentity."),
     59
     60      unicodeConverter: Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
     61        .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
     62
     63      selectFile: function (elementID) {
    6364        dump("selectFile\n");
    6465        var filePicker = Components.classes["@mozilla.org/filepicker;1"]
    65             .createInstance(Components.interfaces.nsIFilePicker);
     66          .createInstance(Components.interfaces.nsIFilePicker);
    6667        var file = Components.classes["@mozilla.org/file/local;1"]
    67             .createInstance(Components.interfaces.nsIFile);
     68          .createInstance(Components.interfaces.nsIFile);
    6869        var defaultPath = Components.classes["@mozilla.org/file/directory_service;1"]
    69                     .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path;
     70          .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path;
    7071
    7172        try {
    72             file.initWithPath(document.getElementById(elementID).value);
     73          file.initWithPath(document.getElementById(elementID).value);
     74          filePicker.displayDirectory = file.parent;
     75          filePicker.defaultString = file.leafName;
     76        } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
     77          try {
     78            // try linux delimiter
     79            file.initWithPath(defaultPath + "/" + document.getElementById(elementID).value);
    7380            filePicker.displayDirectory = file.parent;
    7481            filePicker.defaultString = file.leafName;
     82          } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
     83            try {
     84              // use windows delimiter
     85              file.initWithPath(defaultPath + "\\" + document.getElementById(elementID).value);
     86              filePicker.displayDirectory = file.parent;
     87              filePicker.defaultString = file.leafName;
     88            } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {};
     89          }
    7590        }
    76         catch(NS_ERROR_FILE_UNRECOGNIZED_PATH) {
    77             try {
    78                 // try linux delimiter
    79                 file.initWithPath(defaultPath + "/" + document.getElementById(elementID).value);
    80                 filePicker.displayDirectory = file.parent;
    81                 filePicker.defaultString = file.leafName;
    82             } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {
    83                 try {
    84                     // use windows delimiter
    85                     file.initWithPath(defaultPath + "\\" + document.getElementById(elementID).value);
    86                     filePicker.displayDirectory = file.parent;
    87                     filePicker.defaultString = file.leafName;
    88                 } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) { };
     91
     92        filePicker.init(window, "", Components.interfaces.nsIFilePicker.modeSave);
     93
     94        if (filePicker.show() != Components.interfaces.nsIFilePicker.returnCancel) {
     95          if (filePicker.file.parent.path == defaultPath)
     96            document.getElementById(elementID).setAttribute("value", filePicker.file.leafName);
     97          else
     98            document.getElementById(elementID).setAttribute("value", filePicker.file.path);
     99        }
     100      },
     101
     102      base: {
     103        _elementIDs: ["VIdent_identity.doFcc",
     104          "VIdent_identity.fccFolderPickerMode",
     105          "VIdent_identity.fccFolder",
     106          "VIdent_identity.fccReplyFollowsParent",
     107          "VIdent_identity.draftFolderPickerMode",
     108          "VIdent_identity.draftFolder",
     109          "VIdent_identity.stationeryFolderPickerMode",
     110          "VIdent_identity.stationeryFolder",
     111          "VIdent_identity.copySMIMESettings",
     112          "VIdent_identity.copyAttachVCardSettings",
     113          "VIdent_identity.smart_reply",
     114          "VIdent_identity.smart_detectByReceivedHeader",
     115          "VIdent_identity.smart_reply_for_newsgroups",
     116          "VIdent_identity.show_status",
     117          "VIdent_identity.show_smtp",
     118          "VIdent_identity.fcc_show_switch",
     119          "VIdent_identity.menu_entry",
     120          "VIdent_identity.smart_reply_headers",
     121          "VIdent_identity.smart_reply_filter",
     122          "VIdent_identity.smart_draft",
     123          "VIdent_identity.smart_reply_notification",
     124          "VIdent_identity.get_header_notification",
     125          "VIdent_identity.smart_reply_defaultFullName",
     126          "VIdent_identity.smart_reply_ignoreFullName",
     127          "VIdent_identity.smart_reply_searchBaseIdentity",
     128          "VIdent_identity.autoTimestamp",
     129          "VIdent_identity.autoTimeString",
     130          "VIdent_identity.autoTimeFormat",
     131          "VIdent_identity.notification_timeout",
     132          "VIdent_identity.debug_notification",
     133          "VIdent_identity.debug_to_file",
     134          "VIdent_identity.debug_to_file_path",
     135          "VIdent_identity.warn_nonvirtual",
     136          "VIdent_identity.warn_virtual",
     137          "VIdent_identity.hide_signature",
     138          "VIdent_identity.hide_sMime_messageSignature",
     139          "VIdent_identity.hide_openPGP_messageSignature",
     140          "VIdent_identity.storage",
     141          "VIdent_identity.storage_store",
     142          "VIdent_identity.storage_store_base_id",
     143          "VIdent_identity.storage_store_SMTP",
     144          "VIdent_identity.storage_dont_update_multiple",
     145          "VIdent_identity.storage_show_switch",
     146          "VIdent_identity.storage_show_baseID_switch",
     147          "VIdent_identity.storage_show_SMTP_switch",
     148          "VIdent_identity.storage_colorIndication",
     149          "VIdent_identity.storage_warn_update",
     150          "VIdent_identity.storage_warn_vI_replace",
     151          "VIdent_identity.storage_notification",
     152          "VIdent_identity.storage_getOneOnly",
     153          "VIdent_identity.storage_timeFormat",
     154          "VIdent_identity.storageExtras_returnReciept",
     155          "VIdent_identity.storageExtras_fcc",
     156          "VIdent_identity.storageExtras_characterEncoding",
     157          "VIdent_identity.storageExtras_messageFormat",
     158          "VIdent_identity.storageExtras_sMime_messageEncryption",
     159          "VIdent_identity.storageExtras_sMime_messageSignature",
     160          "VIdent_identity.storageExtras_openPGP_messageEncryption",
     161          "VIdent_identity.storageExtras_openPGP_messageSignature",
     162          "VIdent_identity.storageExtras_openPGP_PGPMIME",
     163          "VIdent_identity.idSelection_storage_prefer_smart_reply",
     164          "VIdent_identity.idSelection_storage_ignore_smart_reply",
     165          "VIdent_identity.idSelection_ask",
     166          "VIdent_identity.idSelection_ask_always",
     167          "VIdent_identity.idSelection_autocreate",
     168          "VIdent_identity.idSelection_preferExisting",
     169          "VIdent_identity.idSelection_ignoreIDs",
     170          "VIdent_identity.autoReplyToSelf"
     171        ],
     172
     173        init: function () {
     174          // initialize the default window values...
     175          for (var i = 0; i < prefDialog.base._elementIDs.length; i++) {
     176            var elementID = prefDialog.base._elementIDs[i];
     177            var element = document.getElementById(elementID);
     178            if (!element) break;
     179            var eltType = element.localName;
     180            //              try {
     181            if (eltType == "radiogroup")
     182              element.selectedItem = element.childNodes[
     183                prefDialog.preferences.getIntPref(element.getAttribute("prefstring"))];
     184            else if (eltType == "checkbox")
     185              element.checked =
     186              prefDialog.preferences.getBoolPref(element.getAttribute("prefstring"));
     187            else if (eltType == "textbox")
     188              if (element.getAttribute("preftype") == "int")
     189                element.setAttribute("value",
     190                  prefDialog.preferences.getIntPref(element.getAttribute("prefstring")));
     191              else {
     192                element.setAttribute("value",
     193                  prefDialog.unicodeConverter.ConvertToUnicode(prefDialog.preferences.getCharPref(element.getAttribute("prefstring"))));
     194              } else if (eltType == "listbox")
     195              element.value =
     196              prefDialog.preferences.getCharPref(element.getAttribute("prefstring"));
     197            //              } catch (ex) {}
     198            //             dump("setting textbox value: " + element.getAttribute("prefstring") + " " + element.getAttribute("value") + "\n");
     199          }
     200        },
     201
     202        savePrefs: function () {
     203          for (var i = 0; i < prefDialog.base._elementIDs.length; i++) {
     204            var elementID = prefDialog.base._elementIDs[i];
     205            var element = document.getElementById(elementID);
     206            if (!element) break;
     207            var eltType = element.localName;
     208            if (eltType == "radiogroup")
     209              prefDialog.preferences.setIntPref(
     210                element.getAttribute("prefstring"), parseInt(element.value));
     211            else if (eltType == "checkbox")
     212              prefDialog.preferences.setBoolPref(
     213                element.getAttribute("prefstring"), element.checked);
     214            else if (eltType == "textbox") {
     215              if (element.getAttribute("preftype") == "int")
     216                prefDialog.preferences.setIntPref(
     217                  element.getAttribute("prefstring"), element.value);
     218              else prefDialog.preferences.setCharPref(
     219                element.getAttribute("prefstring"), prefDialog.unicodeConverter.ConvertFromUnicode(element.value));
     220            } else if (eltType == "listbox")
     221              prefDialog.preferences.setCharPref(element.getAttribute("prefstring"), element.value);
     222          }
     223        },
     224
     225        modifyAttribute: function (elemID, attribute, value) {
     226          if (value) document.getElementById(elemID).removeAttribute(attribute);
     227          else document.getElementById(elemID).setAttribute(attribute, "true");
     228        },
     229
     230        constraints: function () {
     231          var storage = document.getElementById("VIdent_identity.storage").checked;
     232          var smartDraft = document.getElementById("VIdent_identity.smart_draft").checked;
     233          var smartReply = document.getElementById("VIdent_identity.smart_reply").checked;
     234          var mAttr = prefDialog.base.modifyAttribute;
     235
     236          // idSelectionConstraint
     237          var idSelectionConstraint = (storage || smartReply || smartDraft);
     238          mAttr("VIdent_identity.idSelection_ask", "disabled", idSelectionConstraint);
     239          mAttr("VIdent_identity.idSelection_ask_always", "disabled", idSelectionConstraint);
     240          mAttr("VIdent_identity.idSelection_autocreate", "disabled", idSelectionConstraint);
     241          mAttr("VIdent_identity.idSelection_autocreate.desc", "disabled", idSelectionConstraint);
     242          mAttr("VIdent_identity.idSelection_preferExisting", "disabled", idSelectionConstraint);
     243          mAttr("selection", "featureDisabled", idSelectionConstraint);
     244          mAttr("toCompose", "featureDisabled", idSelectionConstraint);
     245
     246          // idSelectionInputConstraint
     247          var idSelectionInputConstraint = (storage && smartReply);
     248          mAttr("VIdent_identity.idSelection_storage_prefer_smart_reply", "disabled", idSelectionInputConstraint);
     249          mAttr("VIdent_identity.idSelection_storage_ignore_smart_reply", "disabled", idSelectionInputConstraint);
     250          if (idSelectionInputConstraint) prefDialog.base.idSelectionResultConstraint();
     251
     252          // sourceEmailConstraint
     253          var sourceEmailConstraint = (smartReply || smartDraft);
     254          mAttr("sourceEmail", "featureDisabled", sourceEmailConstraint);
     255          mAttr("toSelection", "featureDisabled", sourceEmailConstraint);
     256
     257        },
     258
     259        idSelectionResultConstraint: function () {
     260          var ask = document.getElementById("VIdent_identity.idSelection_ask")
     261          var ask_always = document.getElementById("VIdent_identity.idSelection_ask_always")
     262          var autocreate = document.getElementById("VIdent_identity.idSelection_autocreate")
     263          var autocreate_desc = document.getElementById("VIdent_identity.idSelection_autocreate.desc")
     264          ask_always.setAttribute("disabled", (autocreate.checked || !ask.checked))
     265          autocreate.setAttribute("disabled", (ask.checked && ask_always.checked))
     266          autocreate_desc.setAttribute("disabled", (ask.checked && ask_always.checked))
     267          autocreate_desc.setAttribute("hidden", !ask.checked)
     268        },
     269
     270        smartReplyConstraint: function (element) {
     271          var mAttr = prefDialog.base.modifyAttribute;
     272          mAttr("VIdent_identity.smart_reply_for_newsgroups", "disabled", element.checked);
     273          mAttr("VIdent_identity.smart_reply_headers", "disabled", element.checked);
     274          mAttr("VIdent_identity.smart_reply_filter", "disabled", element.checked);
     275          mAttr("VIdent_identity.smart_reply_defaultFullName", "disabled", element.checked);
     276          mAttr("VIdent_identity.smart_reply_ignoreFullName", "disabled", element.checked);
     277          mAttr("VIdent_identity.smart_reply_headers_reset", "disabled", element.checked);
     278          mAttr("VIdent_identity.smart_detectByReceivedHeader", "disabled", element.checked);
     279          prefDialog.base.constraints();
     280        },
     281
     282        smartReplyHeaderReset: function () {
     283          var textfield = document.getElementById("VIdent_identity.smart_reply_headers")
     284          textfield.value = "envelope-to\nx-original-to\nto\ncc"
     285        },
     286
     287        smartReplyHideSignature: function () {
     288          // check for signature_switch extension
     289          AddonManager.getAddonByID("{2ab1b709-ba03-4361-abf9-c50b964ff75d}", function (addon) {
     290            if (addon && !addon.userDisabled && !addon.appDisable) {
     291              document.getElementById("VIdent_identity.HideSignature.warning").setAttribute("hidden", "true");
     292              document.getElementById("VIdent_identity.hide_signature").setAttribute("disabled", "false");
    89293            }
     294          });
     295        },
     296
     297        autoTimestampConstraint: function (element) {
     298          var mAttr = prefDialog.base.modifyAttribute;
     299          mAttr("VIdent_identity.autoTimestamp.options", "hidden", element.checked);
     300        },
     301
     302        storageConstraint: function (element) {
     303          var mAttr = prefDialog.base.modifyAttribute;
     304          mAttr("VIdent_identity.storage_store", "disabled", element.checked);
     305          mAttr("VIdent_identity.storage_store_base_id", "disabled", element.checked);
     306          mAttr("VIdent_identity.storage_store_SMTP", "disabled", element.checked);
     307          mAttr("VIdent_identity.storage_dont_update_multiple", "disabled", element.checked);
     308          mAttr("VIdent_identity.storage_show_switch", "disabled", element.checked);
     309          mAttr("VIdent_identity.storage_show_baseID_switch", "disabled", element.checked);
     310          mAttr("VIdent_identity.storage_show_SMTP_switch", "disabled", element.checked);
     311          mAttr("VIdent_identity.storage_colorIndication", "disabled", element.checked);
     312          mAttr("VIdent_identity.storage_warn_update", "disabled", element.checked);
     313          mAttr("VIdent_identity.storage_warn_vI_replace", "disabled", element.checked);
     314          mAttr("VIdent_identity.storage_notification", "disabled", element.checked);
     315          mAttr("VIdent_identity.storage_getOneOnly", "disabled", element.checked);
     316          mAttr("VIdent_identity.storageExtras_returnReciept", "disabled", element.checked);
     317          mAttr("VIdent_identity.storageExtras_fcc", "disabled", element.checked);
     318          mAttr("VIdent_identity.storageExtras_characterEncoding", "disabled", element.checked);
     319          mAttr("VIdent_identity.storageExtras_messageFormat", "disabled", element.checked);
     320          mAttr("VIdent_identity.storageExtras_sMime_messageEncryption", "disabled", element.checked);
     321          mAttr("VIdent_identity.storageExtras_sMime_messageSignature", "disabled", element.checked);
     322          mAttr("VIdent_identity.storageExtras_openPGP_messageEncryption", "disabled", element.checked);
     323          mAttr("VIdent_identity.storageExtras_openPGP_messageSignature", "disabled", element.checked);
     324          mAttr("VIdent_identity.storageExtras_openPGP_PGPMIME", "disabled", element.checked);
     325          mAttr("storageOut", "featureDisabled", element.checked);
     326          mAttr("storageUp", "featureDisabled", element.checked);
     327          mAttr("storageUpDown", "featureDisabled", element.checked);
     328          prefDialog.base.constraints();
     329        },
     330
     331        menuButtonConstraints: function (elem) {
     332          var mAttr = prefDialog.base.modifyAttribute;
     333          var valueParam = (document.getElementById("viewGroup").getAttribute("hidden") == "true"); // true -> removeAttribute
     334          var dialogElem = document.getElementById("vI_prefDialog");
     335          mAttr("logoButton2", "hidden", valueParam);
     336          mAttr("toggleIcon", "open", valueParam);
     337          document.getAnonymousElementByAttribute(dialogElem, "class", "box-inherit dialog-content-box").removeAttribute("flex");
     338        },
     339
     340        flipMenuButtons: function (elem) {
     341          var mAttr = prefDialog.base.modifyAttribute;
     342          var valueParam = (elem.getAttribute("open") == "true");
     343          var dialogElem = document.getElementById("vI_prefDialog");
     344          var oldContentElemHeight = document.getAnonymousElementByAttribute(dialogElem, "class", "box-inherit dialog-content-box").clientHeight;
     345          mAttr("viewGroup", "hidden", !valueParam);
     346          mAttr("logoButton2", "hidden", valueParam);
     347          mAttr(elem.id, "open", valueParam);
     348          window.resizeBy(0, document.getAnonymousElementByAttribute(dialogElem, "class", "box-inherit dialog-content-box").clientHeight - oldContentElemHeight);
     349        },
     350
     351        initTreeValues: function () {
     352          var prefTrees = document.getElementById("prefTabbox").getElementsByAttribute("class", "vIprefTree");
     353          for (var i = 0; i < prefTrees.length; i++) prefTrees[i].currentIndex = 0;
    90354        }
    91        
    92         filePicker.init(window, "", Components.interfaces.nsIFilePicker.modeSave);
    93        
    94         if (filePicker.show() != Components.interfaces.nsIFilePicker.returnCancel) {
    95             if (filePicker.file.parent.path == defaultPath)
    96                 document.getElementById(elementID).setAttribute("value", filePicker.file.leafName);
    97             else
    98                 document.getElementById(elementID).setAttribute("value", filePicker.file.path);
    99         }
    100     },
    101                            
    102     base : {
    103         _elementIDs : [ "VIdent_identity.doFcc",
    104                 "VIdent_identity.fccFolderPickerMode",
    105                 "VIdent_identity.fccFolder",
    106                 "VIdent_identity.fccReplyFollowsParent",
    107                 "VIdent_identity.draftFolderPickerMode",
    108                 "VIdent_identity.draftFolder",
    109                 "VIdent_identity.stationeryFolderPickerMode",
    110                 "VIdent_identity.stationeryFolder",
    111                 "VIdent_identity.copySMIMESettings",
    112                 "VIdent_identity.copyAttachVCardSettings",
    113                 "VIdent_identity.smart_reply",
    114                 "VIdent_identity.smart_detectByReceivedHeader",
    115                 "VIdent_identity.smart_reply_for_newsgroups",
    116                 "VIdent_identity.show_status",
    117                 "VIdent_identity.show_smtp",
    118                 "VIdent_identity.fcc_show_switch",
    119                 "VIdent_identity.menu_entry",
    120                 "VIdent_identity.smart_reply_headers",
    121                 "VIdent_identity.smart_reply_filter",
    122                 "VIdent_identity.smart_draft",
    123                 "VIdent_identity.smart_reply_notification",
    124                 "VIdent_identity.get_header_notification",
    125                 "VIdent_identity.smart_reply_defaultFullName",
    126                 "VIdent_identity.smart_reply_ignoreFullName",
    127                 "VIdent_identity.smart_reply_searchBaseIdentity",
    128                 "VIdent_identity.autoTimestamp",
    129                 "VIdent_identity.autoTimeString",
    130                 "VIdent_identity.autoTimeFormat",
    131                 "VIdent_identity.notification_timeout",
    132                 "VIdent_identity.debug_notification",
    133                 "VIdent_identity.debug_to_file",
    134                 "VIdent_identity.debug_to_file_path",
    135                 "VIdent_identity.warn_nonvirtual",
    136                 "VIdent_identity.warn_virtual",
    137                 "VIdent_identity.hide_signature",
    138                 "VIdent_identity.hide_sMime_messageSignature",
    139                 "VIdent_identity.hide_openPGP_messageSignature",
    140                 "VIdent_identity.storage",
    141                 "VIdent_identity.storage_store",
    142                 "VIdent_identity.storage_store_base_id",
    143                 "VIdent_identity.storage_store_SMTP",
    144                 "VIdent_identity.storage_dont_update_multiple",
    145                 "VIdent_identity.storage_show_switch",
    146                 "VIdent_identity.storage_show_baseID_switch",
    147                 "VIdent_identity.storage_show_SMTP_switch",
    148                 "VIdent_identity.storage_colorIndication",
    149                 "VIdent_identity.storage_warn_update",
    150                 "VIdent_identity.storage_warn_vI_replace",
    151                 "VIdent_identity.storage_notification",
    152                 "VIdent_identity.storage_getOneOnly",
    153                 "VIdent_identity.storage_timeFormat",
    154                 "VIdent_identity.storageExtras_returnReciept",
    155                 "VIdent_identity.storageExtras_fcc",
    156                 "VIdent_identity.storageExtras_characterEncoding",
    157                 "VIdent_identity.storageExtras_messageFormat",
    158                 "VIdent_identity.storageExtras_sMime_messageEncryption",
    159                 "VIdent_identity.storageExtras_sMime_messageSignature",
    160                 "VIdent_identity.storageExtras_openPGP_messageEncryption",
    161                 "VIdent_identity.storageExtras_openPGP_messageSignature",
    162                 "VIdent_identity.storageExtras_openPGP_PGPMIME",
    163                 "VIdent_identity.idSelection_storage_prefer_smart_reply",
    164                 "VIdent_identity.idSelection_storage_ignore_smart_reply",
    165                 "VIdent_identity.idSelection_ask",
    166                 "VIdent_identity.idSelection_ask_always",
    167                 "VIdent_identity.idSelection_autocreate",
    168                 "VIdent_identity.idSelection_preferExisting",
    169                 "VIdent_identity.idSelection_ignoreIDs",
    170                 "VIdent_identity.autoReplyToSelf"],
    171    
    172         init : function() {
    173         // initialize the default window values...
    174             for( var i = 0; i < prefDialog.base._elementIDs.length; i++ ) {
    175                 var elementID = prefDialog.base._elementIDs[i];
    176                 var element = document.getElementById(elementID);
    177                 if (!element) break;
    178                 var eltType = element.localName;
    179 //              try {
    180                     if (eltType == "radiogroup")
    181                         element.selectedItem = element.childNodes[
    182                             prefDialog.preferences.getIntPref(element.getAttribute("prefstring"))];
    183                     else if (eltType == "checkbox")
    184                         element.checked =
    185                             prefDialog.preferences.getBoolPref(element.getAttribute("prefstring"));
    186                     else if (eltType == "textbox")
    187                         if (element.getAttribute("preftype") == "int")
    188                             element.setAttribute("value",
    189                             prefDialog.preferences.getIntPref(element.getAttribute("prefstring")) );
    190                         else {
    191                             element.setAttribute("value",
    192                             prefDialog.unicodeConverter.ConvertToUnicode(prefDialog.preferences.getCharPref(element.getAttribute("prefstring"))) );
    193                         }
    194                     else if (eltType == "listbox")
    195                         element.value =
    196                             prefDialog.preferences.getCharPref(element.getAttribute("prefstring"));
    197 //              } catch (ex) {}
    198 //             dump("setting textbox value: " + element.getAttribute("prefstring") + " " + element.getAttribute("value") + "\n");
    199             }
    200         },
    201 
    202         savePrefs : function() {
    203             for( var i = 0; i < prefDialog.base._elementIDs.length; i++ ) {
    204                 var elementID = prefDialog.base._elementIDs[i];
    205                 var element = document.getElementById(elementID);
    206                 if (!element) break;
    207                 var eltType = element.localName;
    208                 if (eltType == "radiogroup")
    209                     prefDialog.preferences.setIntPref(
    210                         element.getAttribute("prefstring"), parseInt(element.value));
    211                 else if (eltType == "checkbox")
    212                     prefDialog.preferences.setBoolPref(
    213                         element.getAttribute("prefstring"), element.checked);
    214                 else if (eltType == "textbox") {
    215                     if (element.getAttribute("preftype") == "int")
    216                         prefDialog.preferences.setIntPref(
    217                             element.getAttribute("prefstring"), element.value);
    218                     else prefDialog.preferences.setCharPref(
    219                             element.getAttribute("prefstring"), prefDialog.unicodeConverter.ConvertFromUnicode(element.value));
    220                 }
    221                 else if (eltType == "listbox")
    222                     prefDialog.preferences.setCharPref(element.getAttribute("prefstring"), element.value);
    223             }
    224         },
    225        
    226         modifyAttribute : function(elemID, attribute, value) {
    227             if (value) document.getElementById(elemID).removeAttribute(attribute);
    228             else document.getElementById(elemID).setAttribute(attribute, "true");
    229         },
    230 
    231         constraints : function() {
    232             var storage = document.getElementById("VIdent_identity.storage").checked;
    233             var smartDraft = document.getElementById("VIdent_identity.smart_draft").checked;
    234             var smartReply = document.getElementById("VIdent_identity.smart_reply").checked;
    235             var mAttr = prefDialog.base.modifyAttribute;
    236 
    237             // idSelectionConstraint
    238             var idSelectionConstraint = (storage || smartReply || smartDraft);
    239             mAttr("VIdent_identity.idSelection_ask","disabled",idSelectionConstraint);
    240             mAttr("VIdent_identity.idSelection_ask_always","disabled",idSelectionConstraint);
    241             mAttr("VIdent_identity.idSelection_autocreate","disabled",idSelectionConstraint);
    242             mAttr("VIdent_identity.idSelection_autocreate.desc","disabled",idSelectionConstraint);
    243             mAttr("VIdent_identity.idSelection_preferExisting","disabled",idSelectionConstraint);
    244             mAttr("selection","featureDisabled",idSelectionConstraint);
    245             mAttr("toCompose","featureDisabled",idSelectionConstraint);
    246 
    247             // idSelectionInputConstraint
    248             var idSelectionInputConstraint = (storage && smartReply);
    249             mAttr("VIdent_identity.idSelection_storage_prefer_smart_reply","disabled",idSelectionInputConstraint);
    250             mAttr("VIdent_identity.idSelection_storage_ignore_smart_reply","disabled",idSelectionInputConstraint);
    251             if (idSelectionInputConstraint) prefDialog.base.idSelectionResultConstraint();
    252 
    253             // sourceEmailConstraint
    254             var sourceEmailConstraint = (smartReply || smartDraft);
    255             mAttr("sourceEmail","featureDisabled",sourceEmailConstraint);
    256             mAttr("toSelection","featureDisabled",sourceEmailConstraint);
    257 
    258         },
    259 
    260         idSelectionResultConstraint : function() {
    261             var ask = document.getElementById("VIdent_identity.idSelection_ask")
    262             var ask_always = document.getElementById("VIdent_identity.idSelection_ask_always")
    263             var autocreate = document.getElementById("VIdent_identity.idSelection_autocreate")
    264             var autocreate_desc = document.getElementById("VIdent_identity.idSelection_autocreate.desc")
    265             ask_always.setAttribute("disabled", (autocreate.checked || !ask.checked))
    266             autocreate.setAttribute("disabled", (ask.checked && ask_always.checked))
    267             autocreate_desc.setAttribute("disabled", (ask.checked && ask_always.checked))
    268             autocreate_desc.setAttribute("hidden", !ask.checked)
    269         },
    270 
    271         smartReplyConstraint : function(element) {
    272             var mAttr = prefDialog.base.modifyAttribute;
    273             mAttr("VIdent_identity.smart_reply_for_newsgroups","disabled",element.checked);
    274             mAttr("VIdent_identity.smart_reply_headers","disabled",element.checked);
    275             mAttr("VIdent_identity.smart_reply_filter","disabled",element.checked);
    276             mAttr("VIdent_identity.smart_reply_defaultFullName","disabled",element.checked);
    277             mAttr("VIdent_identity.smart_reply_ignoreFullName","disabled",element.checked);
    278             mAttr("VIdent_identity.smart_reply_headers_reset","disabled",element.checked);
    279             mAttr("VIdent_identity.smart_detectByReceivedHeader","disabled",element.checked);
    280             prefDialog.base.constraints();
    281         },
    282        
    283         smartReplyHeaderReset : function() {
    284             var textfield = document.getElementById("VIdent_identity.smart_reply_headers")
    285             textfield.value = "envelope-to\nx-original-to\nto\ncc"
    286         },
    287        
    288         smartReplyHideSignature : function() {
    289           // check for signature_switch extension
    290           AddonManager.getAddonByID("{2ab1b709-ba03-4361-abf9-c50b964ff75d}", function(addon) {
    291             if (addon && !addon.userDisabled && !addon.appDisable) {
    292                 document.getElementById("VIdent_identity.HideSignature.warning").setAttribute("hidden", "true");
    293                 document.getElementById("VIdent_identity.hide_signature").setAttribute("disabled", "false");
    294             }
    295           });
    296         },
    297        
    298         autoTimestampConstraint : function(element) {
    299             var mAttr = prefDialog.base.modifyAttribute;
    300             mAttr("VIdent_identity.autoTimestamp.options","hidden",element.checked);
    301         },
    302        
    303         storageConstraint : function(element) {
    304             var mAttr = prefDialog.base.modifyAttribute;
    305             mAttr("VIdent_identity.storage_store","disabled",element.checked);
    306             mAttr("VIdent_identity.storage_store_base_id","disabled",element.checked);
    307             mAttr("VIdent_identity.storage_store_SMTP","disabled",element.checked);
    308             mAttr("VIdent_identity.storage_dont_update_multiple","disabled",element.checked);
    309             mAttr("VIdent_identity.storage_show_switch","disabled",element.checked);
    310             mAttr("VIdent_identity.storage_show_baseID_switch","disabled",element.checked);
    311             mAttr("VIdent_identity.storage_show_SMTP_switch","disabled",element.checked);
    312             mAttr("VIdent_identity.storage_colorIndication","disabled",element.checked);
    313             mAttr("VIdent_identity.storage_warn_update","disabled",element.checked);
    314             mAttr("VIdent_identity.storage_warn_vI_replace","disabled",element.checked);
    315             mAttr("VIdent_identity.storage_notification","disabled",element.checked);
    316             mAttr("VIdent_identity.storage_getOneOnly","disabled",element.checked);
    317             mAttr("VIdent_identity.storageExtras_returnReciept","disabled",element.checked);
    318             mAttr("VIdent_identity.storageExtras_fcc","disabled",element.checked);
    319             mAttr("VIdent_identity.storageExtras_characterEncoding","disabled",element.checked);
    320             mAttr("VIdent_identity.storageExtras_messageFormat","disabled",element.checked);
    321             mAttr("VIdent_identity.storageExtras_sMime_messageEncryption","disabled",element.checked);
    322             mAttr("VIdent_identity.storageExtras_sMime_messageSignature","disabled",element.checked);
    323             mAttr("VIdent_identity.storageExtras_openPGP_messageEncryption","disabled",element.checked);
    324             mAttr("VIdent_identity.storageExtras_openPGP_messageSignature","disabled",element.checked);
    325             mAttr("VIdent_identity.storageExtras_openPGP_PGPMIME","disabled",element.checked);
    326             mAttr("storageOut","featureDisabled",element.checked);
    327             mAttr("storageUp","featureDisabled",element.checked);
    328             mAttr("storageUpDown","featureDisabled",element.checked);
    329             prefDialog.base.constraints();
    330         },
    331 
    332         menuButtonConstraints : function(elem) {
    333             var mAttr = prefDialog.base.modifyAttribute;
    334             var valueParam = (document.getElementById("viewGroup").getAttribute("hidden") == "true");   // true -> removeAttribute
    335             var dialogElem = document.getElementById("vI_prefDialog");
    336             mAttr("logoButton2","hidden", valueParam);
    337             mAttr("toggleIcon","open", valueParam);
    338             document.getAnonymousElementByAttribute(dialogElem, "class", "box-inherit dialog-content-box").removeAttribute("flex");
    339         },
    340 
    341         flipMenuButtons : function(elem) {
    342             var mAttr = prefDialog.base.modifyAttribute;
    343             var valueParam = (elem.getAttribute("open") == "true");
    344             var dialogElem = document.getElementById("vI_prefDialog");
    345             var oldContentElemHeight = document.getAnonymousElementByAttribute(dialogElem, "class", "box-inherit dialog-content-box").clientHeight;
    346             mAttr("viewGroup","hidden", !valueParam);
    347             mAttr("logoButton2","hidden", valueParam);
    348             mAttr(elem.id,"open", valueParam);
    349             window.resizeBy( 0, document.getAnonymousElementByAttribute(dialogElem, "class", "box-inherit dialog-content-box").clientHeight - oldContentElemHeight);
    350         },
    351        
    352         initTreeValues : function() {
    353             var prefTrees = document.getElementById("prefTabbox").getElementsByAttribute("class", "vIprefTree");
    354             for (var i=0 ; i<prefTrees.length; i++) prefTrees[i].currentIndex = 0;
    355         }
    356     },
    357 
    358     init : function() {
    359         prefDialog.unicodeConverter.charset="UTF-8";
    360         prefDialog.base.init();
    361         vI.onInitCopiesAndFolders()
     355      },
     356
     357      init: function () {
     358        prefDialog.unicodeConverter.charset = "UTF-8";
     359        prefDialog.base.init();
     360        vI.onInitCopiesAndFolders()
    362361
    363362        // check for enigmail extension
    364         AddonManager.getAddonByID("{847b3a00-7ab1-11d4-8f02-006008948af5}", function(addon) {
     363        AddonManager.getAddonByID("{847b3a00-7ab1-11d4-8f02-006008948af5}", function (addon) {
    365364          if (addon && !addon.userDisabled && !addon.appDisable) {
    366365            document.getElementById("openPGPencryption").removeAttribute("hidden");
    367366            document.getElementById("VIdent_identity.hide_openPGP_messageSignature").removeAttribute("hidden");
    368367          }
    369         }); 
    370 
    371         prefDialog.base.smartReplyConstraint(document.getElementById("VIdent_identity.smart_reply"));
    372         prefDialog.base.smartReplyHideSignature();
    373         prefDialog.base.storageConstraint(document.getElementById("VIdent_identity.storage"));
    374         prefDialog.base.autoTimestampConstraint(document.getElementById("VIdent_identity.autoTimestamp"));
    375         prefDialog.base.constraints();
    376         prefDialog.base.menuButtonConstraints();
    377         prefDialog.base.initTreeValues();
    378 
    379     },
    380    
    381     savePrefs : function() {
    382         // Copy all changes to Elements
    383         vI.onSaveCopiesAndFolders();
    384         prefDialog.base.savePrefs();
    385     },
    386 
    387     openURL : function(aURL) {
     368        });
     369
     370        prefDialog.base.smartReplyConstraint(document.getElementById("VIdent_identity.smart_reply"));
     371        prefDialog.base.smartReplyHideSignature();
     372        prefDialog.base.storageConstraint(document.getElementById("VIdent_identity.storage"));
     373        prefDialog.base.autoTimestampConstraint(document.getElementById("VIdent_identity.autoTimestamp"));
     374        prefDialog.base.constraints();
     375        prefDialog.base.menuButtonConstraints();
     376        prefDialog.base.initTreeValues();
     377
     378      },
     379
     380      savePrefs: function () {
     381        // Copy all changes to Elements
     382        vI.onSaveCopiesAndFolders();
     383        prefDialog.base.savePrefs();
     384      },
     385
     386      openURL: function (aURL) {
    388387        var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
    389388        var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"].getService(Components.interfaces.nsIExternalProtocolService);
     
    391390        uri.spec = aURL;
    392391        protocolSvc.loadUrl(uri);
     392      }
    393393    }
    394 }
    395 vI.prefDialog = prefDialog;
    396 }});
     394    vI.prefDialog = prefDialog;
     395  }
     396});
  • content/prefDialog/vI_prefDialog_FolderPicker.js

    r3c9c29 r509348  
    1 
    21/**
    3 * some code copied and adapted from Thunderbird Sources
    4 * thanks to all Thunderbird Developers
    5 */
     2 * some code copied and adapted from Thunderbird Sources
     3 * thanks to all Thunderbird Developers
     4 */
    65
    76/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     
    4443
    4544Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    46 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    47 
    48 var gFccRadioElemChoice, gDraftsRadioElemChoice, gTmplRadioElemChoice;
    49 var gFccRadioElemChoiceLocked, gDraftsRadioElemChoiceLocked, gTmplRadioElemChoiceLocked;
    50 var gDefaultPickerMode = "3";
    51 
    52 var gFccFolderWithDelim, gDraftsFolderWithDelim, gTemplatesFolderWithDelim;
    53 
    54 // Picker IDs
    55 var fccAccountPickerId = "msgFccAccountPicker";
    56 var fccFolderPickerId = "msgFccFolderPicker";
    57 var draftsAccountPickerId = "msgDraftsAccountPicker";
    58 var draftsFolderPickerId = "msgDraftsFolderPicker";
    59 var tmplAccountPickerId = "msgStationeryAccountPicker";
    60 var tmplFolderPickerId = "msgStationeryFolderPicker";
    61 
    62 var _GetMsgFolderFromUri = function(uri, checkFolderAttributes)
    63 {
    64     let msgfolder = null;
    65     if (typeof MailUtils != 'undefined') {
    66     return MailUtils.getFolderForURI(uri, checkFolderAttributes);
    67     }
    68     try { // Postbox
    69     let resource = GetResourceFromUri(uri);
    70     msgfolder = resource.QueryInterface(Components.interfaces.nsIMsgFolder);
    71     if (checkFolderAttributes) {
    72         if (!(msgfolder && (msgfolder.parent || msgfolder.isServer))) {
    73         msgfolder = null;
     45virtualIdentityExtension.ns(function () {
     46  with(virtualIdentityExtension.LIB) {
     47
     48    var gFccRadioElemChoice, gDraftsRadioElemChoice, gTmplRadioElemChoice;
     49    var gFccRadioElemChoiceLocked, gDraftsRadioElemChoiceLocked, gTmplRadioElemChoiceLocked;
     50    var gDefaultPickerMode = "3";
     51
     52    var gFccFolderWithDelim, gDraftsFolderWithDelim, gTemplatesFolderWithDelim;
     53
     54    // Picker IDs
     55    var fccAccountPickerId = "msgFccAccountPicker";
     56    var fccFolderPickerId = "msgFccFolderPicker";
     57    var draftsAccountPickerId = "msgDraftsAccountPicker";
     58    var draftsFolderPickerId = "msgDraftsFolderPicker";
     59    var tmplAccountPickerId = "msgStationeryAccountPicker";
     60    var tmplFolderPickerId = "msgStationeryFolderPicker";
     61
     62    var _GetMsgFolderFromUri = function (uri, checkFolderAttributes) {
     63      let msgfolder = null;
     64      if (typeof MailUtils != 'undefined') {
     65        return MailUtils.getFolderForURI(uri, checkFolderAttributes);
     66      }
     67      try { // Postbox
     68        let resource = GetResourceFromUri(uri);
     69        msgfolder = resource.QueryInterface(Components.interfaces.nsIMsgFolder);
     70        if (checkFolderAttributes) {
     71          if (!(msgfolder && (msgfolder.parent || msgfolder.isServer))) {
     72            msgfolder = null;
     73          }
    7474        }
    75     }
    76     }
    77     catch (ex) {
    78     //dump("failed to get the folder resource\n");
    79     }
    80     return msgfolder;
    81 }
    82  
    83 var setDefaultCopiesAndFoldersPrefs = function(identity, server, accountData)
    84 {
    85     var am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
    86     var rootFolder = am.defaultAccount.incomingServer.rootFolder
    87 
    88     var fccElement = document.getElementById("VIdent_identity.fccFolder")
    89     var fccElementValue = fccElement.getAttribute("value");
    90     if (!fccElementValue || !GetMsgFolderFromUri(fccElementValue, false))
    91         fccElement.setAttribute("value", rootFolder.server.serverURI + gFccFolderWithDelim)
    92 
    93     var draftElement = document.getElementById("VIdent_identity.draftFolder")
    94     var draftElementValue = draftElement.getAttribute("value");
    95     if (!draftElementValue || !GetMsgFolderFromUri(draftElementValue, false))
    96         draftElement.setAttribute("value", rootFolder.server.serverURI + gDraftsFolderWithDelim)
    97 
    98     var stationeryElement = document.getElementById("VIdent_identity.stationeryFolder")
    99     var stationeryElementValue = stationeryElement.getAttribute("value");
    100     if (!stationeryElementValue || !GetMsgFolderFromUri(stationeryElementValue, false))
    101         stationeryElement.setAttribute("value", rootFolder.server.serverURI + gTemplatesFolderWithDelim)
    102 }
    103 
    104 
    105 var onInitCopiesAndFolders = function()
    106 {
    107     SetSpecialFolderNamesWithDelims();
    108     SetGlobalRadioElemChoices();
    109 
    110     setDefaultCopiesAndFoldersPrefs();
    111 
    112     SetFolderDisplay(gFccRadioElemChoice, gFccRadioElemChoiceLocked,
    113                      "VIdent_fcc",
    114                      fccAccountPickerId,
    115                      "VIdent_identity.fccFolder",
    116                      fccFolderPickerId);
    117 
    118     SetFolderDisplay(gDraftsRadioElemChoice, gDraftsRadioElemChoiceLocked,
    119                      "VIdent_draft",
    120                      draftsAccountPickerId,
    121                      "VIdent_identity.draftFolder",
    122                      draftsFolderPickerId);
    123 
    124     SetFolderDisplay(gTmplRadioElemChoice, gTmplRadioElemChoiceLocked,
    125                      "VIdent_tmpl",
    126                      tmplAccountPickerId,
    127                      "VIdent_identity.stationeryFolder",
    128                      tmplFolderPickerId);
    129 
    130     setupFccItems();
    131 }
    132 
    133 // Initialize the picker mode choices (account/folder picker) into global vars
    134 var SetGlobalRadioElemChoices = function()
    135 {
    136     var pickerModeElement = document.getElementById("VIdent_identity.fccFolderPickerMode");
    137     gFccRadioElemChoice = pickerModeElement.getAttribute("value");
    138     gFccRadioElemChoiceLocked = pickerModeElement.getAttribute("disabled");
    139     if (!gFccRadioElemChoice) gFccRadioElemChoice = gDefaultPickerMode;
    140 
    141     pickerModeElement = document.getElementById("VIdent_identity.draftFolderPickerMode");
    142     gDraftsRadioElemChoice = pickerModeElement.getAttribute("value");
    143     gDraftsRadioElemChoiceLocked = pickerModeElement.getAttribute("disabled");
    144     if (!gDraftsRadioElemChoice) gDraftsRadioElemChoice = gDefaultPickerMode;
    145 
    146     pickerModeElement = document.getElementById("VIdent_identity.stationeryFolderPickerMode");
    147     gTmplRadioElemChoice = pickerModeElement.getAttribute("value");
    148     gTmplRadioElemChoiceLocked = pickerModeElement.getAttribute("disabled");
    149     if (!gTmplRadioElemChoice) gTmplRadioElemChoice = gDefaultPickerMode;
    150 }
    151 
    152 /*
    153  * Set Account and Folder elements based on the values read from
    154  * preferences file. Default picker mode, if none specified at this stage, is
    155  * set to 1 i.e., Other picker displaying the folder value read from the
    156  * preferences file.
    157  */
    158 var SetFolderDisplay = function(pickerMode, disableMode,
    159                           radioElemPrefix,
    160                           accountPickerId,
    161                           folderPickedField,
    162                           folderPickerId)
    163 {
    164     if (!pickerMode)
     75      } catch (ex) {
     76        //dump("failed to get the folder resource\n");
     77      }
     78      return msgfolder;
     79    }
     80
     81    var setDefaultCopiesAndFoldersPrefs = function (identity, server, accountData) {
     82      var am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
     83      var rootFolder = am.defaultAccount.incomingServer.rootFolder
     84
     85      var fccElement = document.getElementById("VIdent_identity.fccFolder")
     86      var fccElementValue = fccElement.getAttribute("value");
     87      if (!fccElementValue || !GetMsgFolderFromUri(fccElementValue, false))
     88        fccElement.setAttribute("value", rootFolder.server.serverURI + gFccFolderWithDelim)
     89
     90      var draftElement = document.getElementById("VIdent_identity.draftFolder")
     91      var draftElementValue = draftElement.getAttribute("value");
     92      if (!draftElementValue || !GetMsgFolderFromUri(draftElementValue, false))
     93        draftElement.setAttribute("value", rootFolder.server.serverURI + gDraftsFolderWithDelim)
     94
     95      var stationeryElement = document.getElementById("VIdent_identity.stationeryFolder")
     96      var stationeryElementValue = stationeryElement.getAttribute("value");
     97      if (!stationeryElementValue || !GetMsgFolderFromUri(stationeryElementValue, false))
     98        stationeryElement.setAttribute("value", rootFolder.server.serverURI + gTemplatesFolderWithDelim)
     99    }
     100
     101
     102    var onInitCopiesAndFolders = function () {
     103      SetSpecialFolderNamesWithDelims();
     104      SetGlobalRadioElemChoices();
     105
     106      setDefaultCopiesAndFoldersPrefs();
     107
     108      SetFolderDisplay(gFccRadioElemChoice, gFccRadioElemChoiceLocked,
     109        "VIdent_fcc",
     110        fccAccountPickerId,
     111        "VIdent_identity.fccFolder",
     112        fccFolderPickerId);
     113
     114      SetFolderDisplay(gDraftsRadioElemChoice, gDraftsRadioElemChoiceLocked,
     115        "VIdent_draft",
     116        draftsAccountPickerId,
     117        "VIdent_identity.draftFolder",
     118        draftsFolderPickerId);
     119
     120      SetFolderDisplay(gTmplRadioElemChoice, gTmplRadioElemChoiceLocked,
     121        "VIdent_tmpl",
     122        tmplAccountPickerId,
     123        "VIdent_identity.stationeryFolder",
     124        tmplFolderPickerId);
     125
     126      setupFccItems();
     127    }
     128
     129    // Initialize the picker mode choices (account/folder picker) into global vars
     130    var SetGlobalRadioElemChoices = function () {
     131      var pickerModeElement = document.getElementById("VIdent_identity.fccFolderPickerMode");
     132      gFccRadioElemChoice = pickerModeElement.getAttribute("value");
     133      gFccRadioElemChoiceLocked = pickerModeElement.getAttribute("disabled");
     134      if (!gFccRadioElemChoice) gFccRadioElemChoice = gDefaultPickerMode;
     135
     136      pickerModeElement = document.getElementById("VIdent_identity.draftFolderPickerMode");
     137      gDraftsRadioElemChoice = pickerModeElement.getAttribute("value");
     138      gDraftsRadioElemChoiceLocked = pickerModeElement.getAttribute("disabled");
     139      if (!gDraftsRadioElemChoice) gDraftsRadioElemChoice = gDefaultPickerMode;
     140
     141      pickerModeElement = document.getElementById("VIdent_identity.stationeryFolderPickerMode");
     142      gTmplRadioElemChoice = pickerModeElement.getAttribute("value");
     143      gTmplRadioElemChoiceLocked = pickerModeElement.getAttribute("disabled");
     144      if (!gTmplRadioElemChoice) gTmplRadioElemChoice = gDefaultPickerMode;
     145    }
     146
     147    /*
     148     * Set Account and Folder elements based on the values read from
     149     * preferences file. Default picker mode, if none specified at this stage, is
     150     * set to 1 i.e., Other picker displaying the folder value read from the
     151     * preferences file.
     152     */
     153    var SetFolderDisplay = function (pickerMode, disableMode,
     154      radioElemPrefix,
     155      accountPickerId,
     156      folderPickedField,
     157      folderPickerId) {
     158      if (!pickerMode)
    165159        pickerMode = gDefaultPickerMode;
    166160
    167     var selectAccountRadioId = radioElemPrefix + "_selectAccount";
    168     var selectAccountRadioElem = document.getElementById(selectAccountRadioId);
    169     var selectFolderRadioId = radioElemPrefix + "_selectFolder";
    170     var selectFolderRadioElem = document.getElementById(selectFolderRadioId);
    171     var accountPicker = document.getElementById(accountPickerId);
    172     var folderPicker = document.getElementById(folderPickerId);
    173     var rg = selectAccountRadioElem.radioGroup;
    174 
    175     var folderPickedElement = document.getElementById(folderPickedField);
    176     var uri = folderPickedElement.getAttribute("value");
    177     // Get message folder from the given uri. Second argument (false) siginifies
    178     // that there is no need to check for the existence of special folders as
    179     // these folders are created on demand at runtime in case of imap accounts.
    180     // For POP3 accounts, special folders are created at the account creation time.
    181     var msgFolder = GetMsgFolderFromUri(uri, false);
    182     vI.InitFolderDisplays(msgFolder, accountPickerId, folderPickerId)
    183 
    184     switch (pickerMode)
    185     {
    186         case "0" :
    187             rg.selectedItem = selectAccountRadioElem;
    188             SetPickerEnabling(accountPickerId, folderPickerId);
    189             break;
    190 
    191         case "1"  :
    192             rg.selectedItem = selectFolderRadioElem;
    193             SetPickerEnabling(folderPickerId, accountPickerId);
    194             break;
    195     case "2"  :
    196         rg.selectedItem = document.getElementById(radioElemPrefix + "_Settings_Of_Default");
    197         folderPicker.setAttribute("disabled", "true");
    198         accountPicker.setAttribute("disabled", "true");
    199             break;
    200     case "3"  :
    201         rg.selectedItem = document.getElementById(radioElemPrefix + "_Settings_Of_Account");
    202         folderPicker.setAttribute("disabled", "true");
    203         accountPicker.setAttribute("disabled", "true");
    204             break;
    205 
    206         default :
    207             alert("Error in setting initial folder display on pickers\n");
    208             break;
    209     }
    210 
    211     // Check to see if we need to lock page elements. Disable radio buttons
    212     // and account/folder pickers when locked.
    213     if (disableMode) {
    214       selectAccountRadioElem.setAttribute("disabled","true");
    215       selectFolderRadioElem.setAttribute("disabled","true");
    216       accountPicker.setAttribute("disabled","true");
    217       folderPicker.setAttribute("disabled","true");
    218     }
    219 }
    220 
    221 // Need to append special folders when account picker is selected.
    222 // Create a set of global special folder vars to be suffixed to the
    223 // server URI of the selected account.
    224 var SetSpecialFolderNamesWithDelims = function()
    225 {
    226     var folderDelim = "/";
    227     /* we use internal names known to everyone like "Sent", "Templates" and "Drafts" */
    228 
    229     gFccFolderWithDelim = folderDelim + "Sent";
    230     gDraftsFolderWithDelim = folderDelim + "Drafts";
    231     gTemplatesFolderWithDelim = folderDelim + "Templates";
    232 }
    233 
    234 var onSaveCopiesAndFolders = function()
    235 {
    236     vI.SaveFolderSettings( gFccRadioElemChoice,
    237                         "doFcc",
    238                         gFccFolderWithDelim,
    239                         fccAccountPickerId,
    240                         fccFolderPickerId,
    241                         "VIdent_identity.fccFolder",
    242                         "VIdent_identity.fccFolderPickerMode" );
    243 
    244     vI.SaveFolderSettings( gDraftsRadioElemChoice,
    245                         "messageDrafts",
    246                         gDraftsFolderWithDelim,
    247                         draftsAccountPickerId,
    248                         draftsFolderPickerId,
    249                         "VIdent_identity.draftFolder",
    250                         "VIdent_identity.draftFolderPickerMode" );
    251 
    252     vI.SaveFolderSettings( gTmplRadioElemChoice,
    253                         "messageTemplates",
    254                         gTemplatesFolderWithDelim,
    255                         tmplAccountPickerId,
    256                         tmplFolderPickerId,
    257                         "VIdent_identity.stationeryFolder",
    258                         "VIdent_identity.stationeryFolderPickerMode" );
    259 }
    260 
    261 // Check the Fcc Self item and setup associated picker state
    262 var setupFccItems = function()
    263 {
    264     var broadcaster = document.getElementById("VIdent_broadcaster_doFcc");
    265 
    266     var checked = document.getElementById("VIdent_identity.doFcc").checked;
    267     if (checked) {
     161      var selectAccountRadioId = radioElemPrefix + "_selectAccount";
     162      var selectAccountRadioElem = document.getElementById(selectAccountRadioId);
     163      var selectFolderRadioId = radioElemPrefix + "_selectFolder";
     164      var selectFolderRadioElem = document.getElementById(selectFolderRadioId);
     165      var accountPicker = document.getElementById(accountPickerId);
     166      var folderPicker = document.getElementById(folderPickerId);
     167      var rg = selectAccountRadioElem.radioGroup;
     168
     169      var folderPickedElement = document.getElementById(folderPickedField);
     170      var uri = folderPickedElement.getAttribute("value");
     171      // Get message folder from the given uri. Second argument (false) siginifies
     172      // that there is no need to check for the existence of special folders as
     173      // these folders are created on demand at runtime in case of imap accounts.
     174      // For POP3 accounts, special folders are created at the account creation time.
     175      var msgFolder = GetMsgFolderFromUri(uri, false);
     176      vI.InitFolderDisplays(msgFolder, accountPickerId, folderPickerId)
     177
     178      switch (pickerMode) {
     179      case "0":
     180        rg.selectedItem = selectAccountRadioElem;
     181        SetPickerEnabling(accountPickerId, folderPickerId);
     182        break;
     183
     184      case "1":
     185        rg.selectedItem = selectFolderRadioElem;
     186        SetPickerEnabling(folderPickerId, accountPickerId);
     187        break;
     188      case "2":
     189        rg.selectedItem = document.getElementById(radioElemPrefix + "_Settings_Of_Default");
     190        folderPicker.setAttribute("disabled", "true");
     191        accountPicker.setAttribute("disabled", "true");
     192        break;
     193      case "3":
     194        rg.selectedItem = document.getElementById(radioElemPrefix + "_Settings_Of_Account");
     195        folderPicker.setAttribute("disabled", "true");
     196        accountPicker.setAttribute("disabled", "true");
     197        break;
     198
     199      default:
     200        alert("Error in setting initial folder display on pickers\n");
     201        break;
     202      }
     203
     204      // Check to see if we need to lock page elements. Disable radio buttons
     205      // and account/folder pickers when locked.
     206      if (disableMode) {
     207        selectAccountRadioElem.setAttribute("disabled", "true");
     208        selectFolderRadioElem.setAttribute("disabled", "true");
     209        accountPicker.setAttribute("disabled", "true");
     210        folderPicker.setAttribute("disabled", "true");
     211      }
     212    }
     213
     214    // Need to append special folders when account picker is selected.
     215    // Create a set of global special folder vars to be suffixed to the
     216    // server URI of the selected account.
     217    var SetSpecialFolderNamesWithDelims = function () {
     218      var folderDelim = "/";
     219      /* we use internal names known to everyone like "Sent", "Templates" and "Drafts" */
     220
     221      gFccFolderWithDelim = folderDelim + "Sent";
     222      gDraftsFolderWithDelim = folderDelim + "Drafts";
     223      gTemplatesFolderWithDelim = folderDelim + "Templates";
     224    }
     225
     226    var onSaveCopiesAndFolders = function () {
     227      vI.SaveFolderSettings(gFccRadioElemChoice,
     228        "doFcc",
     229        gFccFolderWithDelim,
     230        fccAccountPickerId,
     231        fccFolderPickerId,
     232        "VIdent_identity.fccFolder",
     233        "VIdent_identity.fccFolderPickerMode");
     234
     235      vI.SaveFolderSettings(gDraftsRadioElemChoice,
     236        "messageDrafts",
     237        gDraftsFolderWithDelim,
     238        draftsAccountPickerId,
     239        draftsFolderPickerId,
     240        "VIdent_identity.draftFolder",
     241        "VIdent_identity.draftFolderPickerMode");
     242
     243      vI.SaveFolderSettings(gTmplRadioElemChoice,
     244        "messageTemplates",
     245        gTemplatesFolderWithDelim,
     246        tmplAccountPickerId,
     247        tmplFolderPickerId,
     248        "VIdent_identity.stationeryFolder",
     249        "VIdent_identity.stationeryFolderPickerMode");
     250    }
     251
     252    // Check the Fcc Self item and setup associated picker state
     253    var setupFccItems = function () {
     254      var broadcaster = document.getElementById("VIdent_broadcaster_doFcc");
     255
     256      var checked = document.getElementById("VIdent_identity.doFcc").checked;
     257      if (checked) {
    268258        broadcaster.removeAttribute("disabled");
    269259        SetupFccPickerState(gFccRadioElemChoice,
    270                             fccAccountPickerId,
    271                             fccFolderPickerId);
    272       }
    273     else
     260          fccAccountPickerId,
     261          fccFolderPickerId);
     262      } else
    274263        broadcaster.setAttribute("disabled", "true");
    275 }
    276 
    277 // Set up picker settings for Sent Folder
    278 var SetupFccPickerState = function(pickerMode, accountPickerId, folderPickerId)
    279 {
    280     switch (pickerMode) {
    281         case "0" :
    282             if (!gFccRadioElemChoiceLocked)
    283               SetPickerEnabling(accountPickerId, folderPickerId);
    284             SetRadioButtons("VIdent_fcc_selectAccount", "VIdent_fcc_selectFolder");
    285             break;
    286    
    287         case "1" :
    288             if (!gFccRadioElemChoiceLocked)
    289               SetPickerEnabling(folderPickerId, accountPickerId);
    290             SetRadioButtons("VIdent_fcc_selectFolder", "VIdent_fcc_selectAccount");
    291             break;
    292 
    293         default :
    294           document.getElementById(folderPickerId).setAttribute("disabled", "true");
    295           document.getElementById(accountPickerId).setAttribute("disabled", "true");
    296             break;
    297     }
    298 }
    299 
    300 // Enable and disable pickers based on the radio element clicked
    301 var SetPickerEnabling = function(enablePickerId, disablePickerId)
    302 {
    303     var activePicker = document.getElementById(enablePickerId);
    304     activePicker.removeAttribute("disabled");
    305 
    306     var inactivePicker = document.getElementById(disablePickerId);
    307     inactivePicker.setAttribute("disabled", "true");
    308 }
    309 
    310 // Set radio element choices and picker states
    311 var setPickersState = function(enablePickerId, disablePickerId, event)
    312 {
    313     SetPickerEnabling(enablePickerId, disablePickerId);
    314 
    315     var radioElemValue = event.target.value;
    316    
    317     switch (event.target.id) {
    318     case "VIdent_fcc_Settings_Of_Account":
    319     case "VIdent_fcc_Settings_Of_Default":
    320         document.getElementById(enablePickerId).setAttribute("disabled", "true");
    321         case "VIdent_fcc_selectAccount":
    322         case "VIdent_fcc_selectFolder" :
    323             gFccRadioElemChoice = radioElemValue;   
    324             break;
    325     case "VIdent_draft_Settings_Of_Account":
    326     case "VIdent_draft_Settings_Of_Default":
    327         document.getElementById(enablePickerId).setAttribute("disabled", "true");
    328         case "VIdent_draft_selectAccount":
    329         case "VIdent_draft_selectFolder" :
    330             gDraftsRadioElemChoice = radioElemValue;   
    331             break;
    332     case "VIdent_tmpl_Settings_Of_Account":
    333     case "VIdent_tmpl_Settings_Of_Default":
    334         document.getElementById(enablePickerId).setAttribute("disabled", "true");
    335         case "VIdent_tmpl_selectFolder" :
    336         case "VIdent_tmpl_selectAccount":
    337             gTmplRadioElemChoice = radioElemValue;   
    338             break;
    339         default :
    340             alert("Error in setting picker state. " + event.target.id + "\n");
    341             return;
    342     }
    343    
    344     switch (event.target.id) {
    345         case "VIdent_fcc_Settings_Of_Account":
    346     case "VIdent_fcc_Settings_Of_Default":
    347         document.getElementById("VIdent_identity.fccReplyFollowsParent").setAttribute("disabled","true");
    348         break;
    349         case "VIdent_fcc_selectAccount":
    350         case "VIdent_fcc_selectFolder" :
    351         document.getElementById("VIdent_identity.fccReplyFollowsParent").removeAttribute("disabled")
    352             break;
    353      }
    354 }
    355 
    356 // This routine is to restore the correct radio element
    357 // state when the fcc self checkbox broadcasts the change
    358 var SetRadioButtons = function(selectPickerId, unselectPickerId)
    359 {
    360     var activeRadioElem = document.getElementById(selectPickerId);
    361     activeRadioElem.radioGroup.selectedItem = activeRadioElem;
    362 }
    363 vI.onInitCopiesAndFolders = onInitCopiesAndFolders;
    364 vI.onSaveCopiesAndFolders = onSaveCopiesAndFolders;
    365 vI.setPickersState = setPickersState;
    366 vI.gFccRadioElemChoice = gFccRadioElemChoice;
    367 vI.gDraftsRadioElemChoice = gDraftsRadioElemChoice;
    368 vI.gTmplRadioElemChoice = gTmplRadioElemChoice;
    369 
    370 // patch for https://bugzilla.mozilla.org/show_bug.cgi?id=889022, see there
    371 Components.utils.import("resource:///modules/MailUtils.js");
    372 if (typeof(GetMsgFolderFromUri) != "function") {
    373     var GetMsgFolderFromUri = _GetMsgFolderFromUri;
    374 }
    375 
    376 }});
     264    }
     265
     266    // Set up picker settings for Sent Folder
     267    var SetupFccPickerState = function (pickerMode, accountPickerId, folderPickerId) {
     268      switch (pickerMode) {
     269      case "0":
     270        if (!gFccRadioElemChoiceLocked)
     271          SetPickerEnabling(accountPickerId, folderPickerId);
     272        SetRadioButtons("VIdent_fcc_selectAccount", "VIdent_fcc_selectFolder");
     273        break;
     274
     275      case "1":
     276        if (!gFccRadioElemChoiceLocked)
     277          SetPickerEnabling(folderPickerId, accountPickerId);
     278        SetRadioButtons("VIdent_fcc_selectFolder", "VIdent_fcc_selectAccount");
     279        break;
     280
     281      default:
     282        document.getElementById(folderPickerId).setAttribute("disabled", "true");
     283        document.getElementById(accountPickerId).setAttribute("disabled", "true");
     284        break;
     285      }
     286    }
     287
     288    // Enable and disable pickers based on the radio element clicked
     289    var SetPickerEnabling = function (enablePickerId, disablePickerId) {
     290      var activePicker = document.getElementById(enablePickerId);
     291      activePicker.removeAttribute("disabled");
     292
     293      var inactivePicker = document.getElementById(disablePickerId);
     294      inactivePicker.setAttribute("disabled", "true");
     295    }
     296
     297    // Set radio element choices and picker states
     298    var setPickersState = function (enablePickerId, disablePickerId, event) {
     299      SetPickerEnabling(enablePickerId, disablePickerId);
     300
     301      var radioElemValue = event.target.value;
     302
     303      switch (event.target.id) {
     304      case "VIdent_fcc_Settings_Of_Account":
     305      case "VIdent_fcc_Settings_Of_Default":
     306        document.getElementById(enablePickerId).setAttribute("disabled", "true");
     307      case "VIdent_fcc_selectAccount":
     308      case "VIdent_fcc_selectFolder":
     309        gFccRadioElemChoice = radioElemValue;
     310        break;
     311      case "VIdent_draft_Settings_Of_Account":
     312      case "VIdent_draft_Settings_Of_Default":
     313        document.getElementById(enablePickerId).setAttribute("disabled", "true");
     314      case "VIdent_draft_selectAccount":
     315      case "VIdent_draft_selectFolder":
     316        gDraftsRadioElemChoice = radioElemValue;
     317        break;
     318      case "VIdent_tmpl_Settings_Of_Account":
     319      case "VIdent_tmpl_Settings_Of_Default":
     320        document.getElementById(enablePickerId).setAttribute("disabled", "true");
     321      case "VIdent_tmpl_selectFolder":
     322      case "VIdent_tmpl_selectAccount":
     323        gTmplRadioElemChoice = radioElemValue;
     324        break;
     325      default:
     326        alert("Error in setting picker state. " + event.target.id + "\n");
     327        return;
     328      }
     329
     330      switch (event.target.id) {
     331      case "VIdent_fcc_Settings_Of_Account":
     332      case "VIdent_fcc_Settings_Of_Default":
     333        document.getElementById("VIdent_identity.fccReplyFollowsParent").setAttribute("disabled", "true");
     334        break;
     335      case "VIdent_fcc_selectAccount":
     336      case "VIdent_fcc_selectFolder":
     337        document.getElementById("VIdent_identity.fccReplyFollowsParent").removeAttribute("disabled")
     338        break;
     339      }
     340    }
     341
     342    // This routine is to restore the correct radio element
     343    // state when the fcc self checkbox broadcasts the change
     344    var SetRadioButtons = function (selectPickerId, unselectPickerId) {
     345      var activeRadioElem = document.getElementById(selectPickerId);
     346      activeRadioElem.radioGroup.selectedItem = activeRadioElem;
     347    }
     348    vI.onInitCopiesAndFolders = onInitCopiesAndFolders;
     349    vI.onSaveCopiesAndFolders = onSaveCopiesAndFolders;
     350    vI.setPickersState = setPickersState;
     351    vI.gFccRadioElemChoice = gFccRadioElemChoice;
     352    vI.gDraftsRadioElemChoice = gDraftsRadioElemChoice;
     353    vI.gTmplRadioElemChoice = gTmplRadioElemChoice;
     354
     355    // patch for https://bugzilla.mozilla.org/show_bug.cgi?id=889022, see there
     356    Components.utils.import("resource:///modules/MailUtils.js");
     357    if (typeof (GetMsgFolderFromUri) != "function") {
     358      var GetMsgFolderFromUri = _GetMsgFolderFromUri;
     359    }
     360
     361  }
     362});
  • content/prefDialog/vI_prefDialog_TB3FolderPicker.js

    r3c9c29 r509348  
    1 
    21/**
    3 * some code copied and adapted from Thunderbird Sources
    4 * thanks to all Thunderbird Developers
    5 */
     2 * some code copied and adapted from Thunderbird Sources
     3 * thanks to all Thunderbird Developers
     4 */
    65
    76/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     
    4443
    4544Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    46 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
     45virtualIdentityExtension.ns(function () {
     46  with(virtualIdentityExtension.LIB) {
    4747
    48 var InitFolderDisplays = function(msgFolder, accountPickerId, folderPickerId) {
    49     var accountPicker = document.getElementById(accountPickerId);
    50     var folderPicker = document.getElementById(folderPickerId);
    51     InitFolderDisplay(msgFolder.server.rootFolder, accountPicker);
    52     InitFolderDisplay(msgFolder, folderPicker);
    53 }
     48    var InitFolderDisplays = function (msgFolder, accountPickerId, folderPickerId) {
     49      var accountPicker = document.getElementById(accountPickerId);
     50      var folderPicker = document.getElementById(folderPickerId);
     51      InitFolderDisplay(msgFolder.server.rootFolder, accountPicker);
     52      InitFolderDisplay(msgFolder, folderPicker);
     53    }
    5454
    55 // Initialize the folder display based on prefs values
    56 var InitFolderDisplay = function(folder, folderPicker) {
    57     try {
    58       folderPicker.firstChild.selectFolder(folder);
    59     } catch(ex) {
    60       folderPicker.setAttribute("label", folder.prettyName);
     55    // Initialize the folder display based on prefs values
     56    var InitFolderDisplay = function (folder, folderPicker) {
     57      try {
     58        folderPicker.firstChild.selectFolder(folder);
     59      } catch (ex) {
     60        folderPicker.setAttribute("label", folder.prettyName);
     61      }
     62      folderPicker.folder = folder;
    6163    }
    62     folderPicker.folder = folder;
    63 }
    6464
    65 // Capture any menulist changes
    66 var noteSelectionChange = function(radioItemId, aEvent)
    67 {
    68     var checkedElem = document.getElementById(radioItemId);
    69     var folder = aEvent.target._folder;
    70     var modeValue  = checkedElem.value;
    71     var radioGroup = checkedElem.radioGroup.getAttribute("id");
    72     var picker;
    73     switch (radioGroup)
    74     {
    75         case "VIdent_doFcc" :
    76             vI.gFccRadioElemChoice = modeValue;
    77             picker = document.getElementById("msgFccFolderPicker");
    78             break;
    79    
    80         case "VIdent_messageDrafts" :
    81             vI.gDraftsRadioElemChoice = modeValue;
    82             picker = document.getElementById("msgDraftsFolderPicker");
    83             break;
     65    // Capture any menulist changes
     66    var noteSelectionChange = function (radioItemId, aEvent) {
     67      var checkedElem = document.getElementById(radioItemId);
     68      var folder = aEvent.target._folder;
     69      var modeValue = checkedElem.value;
     70      var radioGroup = checkedElem.radioGroup.getAttribute("id");
     71      var picker;
     72      switch (radioGroup) {
     73      case "VIdent_doFcc":
     74        vI.gFccRadioElemChoice = modeValue;
     75        picker = document.getElementById("msgFccFolderPicker");
     76        break;
    8477
    85         case "VIdent_messageTemplates" :
    86             vI.gTmplRadioElemChoice = modeValue;
    87             picker = document.getElementById("msgStationeryFolderPicker");
    88             break;
     78      case "VIdent_messageDrafts":
     79        vI.gDraftsRadioElemChoice = modeValue;
     80        picker = document.getElementById("msgDraftsFolderPicker");
     81        break;
     82
     83      case "VIdent_messageTemplates":
     84        vI.gTmplRadioElemChoice = modeValue;
     85        picker = document.getElementById("msgStationeryFolderPicker");
     86        break;
     87      }
     88      picker.folder = folder;
     89      picker.setAttribute("label", folder.prettyName);
    8990    }
    90     picker.folder = folder;
    91     picker.setAttribute("label", folder.prettyName);
    92 }
    9391
    94 // Save folder settings and radio element choices
    95 var SaveFolderSettings = function(radioElemChoice,
    96                             radioGroupId,
    97                             folderSuffix,
    98                             accountPickerId,
    99                             folderPickerId,
    100                             folderElementId,
    101                             folderPickerModeId)
    102 {
    103     var formElement = document.getElementById(folderElementId);
    104     var uri = "";
     92    // Save folder settings and radio element choices
     93    var SaveFolderSettings = function (radioElemChoice,
     94      radioGroupId,
     95      folderSuffix,
     96      accountPickerId,
     97      folderPickerId,
     98      folderElementId,
     99      folderPickerModeId) {
     100      var formElement = document.getElementById(folderElementId);
     101      var uri = "";
    105102
    106     switch (radioElemChoice)
    107     {
    108         case "0" :
    109             uri = document.getElementById(accountPickerId).selectedItem._folder.URI;
    110             if (uri) {
    111                 // Create  Folder URI
    112                 uri = uri + folderSuffix;
    113             }
    114             break;
     103      switch (radioElemChoice) {
     104      case "0":
     105        uri = document.getElementById(accountPickerId).selectedItem._folder.URI;
     106        if (uri) {
     107          // Create  Folder URI
     108          uri = uri + folderSuffix;
     109        }
     110        break;
    115111
    116         case "1" :
    117             uri = document.getElementById(folderPickerId).folder.URI;
    118             break;
     112      case "1":
     113        uri = document.getElementById(folderPickerId).folder.URI;
     114        break;
    119115
    120         default :
    121             break;
     116      default:
     117        break;
     118      }
     119      formElement.setAttribute("value", uri);
     120
     121      formElement = document.getElementById(folderPickerModeId);
     122      formElement.setAttribute("value", radioElemChoice);
    122123    }
    123     formElement.setAttribute("value", uri);
    124 
    125     formElement = document.getElementById(folderPickerModeId);
    126     formElement.setAttribute("value", radioElemChoice);
    127 }
    128 vI.InitFolderDisplays = InitFolderDisplays;
    129 vI.SaveFolderSettings = SaveFolderSettings;
    130 vI.noteSelectionChange = noteSelectionChange;
    131 }});
     124    vI.InitFolderDisplays = InitFolderDisplays;
     125    vI.SaveFolderSettings = SaveFolderSettings;
     126    vI.noteSelectionChange = noteSelectionChange;
     127  }
     128});
  • content/vI_Dialog.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27 var Dialog = {
    28     setDescription : function(object, description) {
    29         var new_text = document.createTextNode(description);
    30         object.appendChild(new_text);
    31     },
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28    var Dialog = {
     29      setDescription: function (object, description) {
     30        var new_text = document.createTextNode(description);
     31        object.appendChild(new_text);
     32      },
    3233
    33     init : function(warning) {
    34         document.getElementById("virtualIdentityExtension_Dialog").setAttribute("class", warning.class);
    35         Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_title"), warning.title);
    36         Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_recLabel"), warning.recLabel);
    37         Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_recipient"), warning.recipient);
    38         document.getElementById("virtualIdentityExtension_Dialog_browser").outputString = warning.warning;
    39         Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_query"), warning.query);
    40         // show abort button
    41         if (warning.class == "replaceVIdentity") {
    42             document.documentElement.getButton("extra1").hidden = true;
    43             document.documentElement.getButton("extra2").hidden = true;
    44         }
    45     }
    46 }
    47 vI.Dialog = Dialog;
    48 }});
     34      init: function (warning) {
     35        document.getElementById("virtualIdentityExtension_Dialog").setAttribute("class", warning.class);
     36        Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_title"), warning.title);
     37        Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_recLabel"), warning.recLabel);
     38        Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_recipient"), warning.recipient);
     39        document.getElementById("virtualIdentityExtension_Dialog_browser").outputString = warning.warning;
     40        Dialog.setDescription(document.getElementById("virtualIdentityExtension_Dialog_query"), warning.query);
     41        // show abort button
     42        if (warning.class == "replaceVIdentity") {
     43          document.documentElement.getButton("extra1").hidden = true;
     44          document.documentElement.getButton("extra2").hidden = true;
     45        }
     46      }
     47    }
     48    vI.Dialog = Dialog;
     49  }
     50});
  • content/vI_getHeader.js

    r3c9c29 r509348  
    2727
    2828Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    29 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
     29virtualIdentityExtension.ns(function () {
     30  with(virtualIdentityExtension.LIB) {
    3031
    31 Components.utils.import("resource://v_identity/stdlib/msgHdrUtils.js", virtualIdentityExtension);
    32 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    33 let Log = vI.setupLogging("virtualIdentity.getHeader");
     32    Components.utils.import("resource://v_identity/stdlib/msgHdrUtils.js", virtualIdentityExtension);
     33    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     34    let Log = vI.setupLogging("virtualIdentity.getHeader");
    3435
    35 // var storedHeaders = { };
    36 var getHeader = {
    37     unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
    38             .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
     36    // var storedHeaders = { };
     37    var getHeader = {
     38      unicodeConverter: Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
     39        .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
    3940
    40     headerToSearch : null,
    41    
    42     prefObserverToSearchArray : function() {
    43         var headerList = getHeader.unicodeConverter.ConvertToUnicode(vI.vIprefs.get("smart_reply_headers")).split(/\n/)
    44        
    45         getHeader.headerToSearch = [];
    46        
    47         // prepare headerToSearch for speedup.
    48         for (var index = 0; index < headerList.length; index++) {
    49             var headerToSearch_splitted = headerList[index].split(/:/)
    50             // use first part (all before ':') as the header name
    51             var headerNameToSearch = headerToSearch_splitted[0].toLowerCase()
    52             // check second or third part for any number
    53             var headerNumberToSearch = null;
    54             if (headerToSearch_splitted.length > 1) parseInt(headerToSearch_splitted[1]);
    55             if ((!headerNumberToSearch || isNaN(headerNumberToSearch)) && headerToSearch_splitted.length > 2) headerNumberToSearch = parseInt(headerToSearch_splitted[2]);
    56            
    57             // create header name to store the value
    58             var headerNameToStore = headerNameToSearch;
    59             if (headerNumberToSearch && !isNaN(headerNumberToSearch)) headerNameToStore += ":" + headerNumberToSearch
    60            
    61             getHeader.headerToSearch.push({ headerNameToSearch : headerNameToSearch, headerNumberToSearch : headerNumberToSearch,
    62                     headerNameToStore : headerNameToStore });
    63         }
    64     },
     41      headerToSearch: null,
    6542
    66     getHeader: function() {
    67       vI.clearDebugOutput();
    68       if (!getHeader.headerToSearch) getHeader.prefObserverToSearchArray()
    69      
    70       vI.msgHdrGetHeaders(getHeader.hdr, function (aHeaders) {
    71         let label = "";
    72         if (aHeaders.has("list-id")) {
    73           getHeader.hdr.setStringProperty("vI_list-id","found");
    74           Log.debug("found header: list-id  ...stored to recognize mailing-list");
     43      prefObserverToSearchArray: function () {
     44        var headerList = getHeader.unicodeConverter.ConvertToUnicode(vI.vIprefs.get("smart_reply_headers")).split(/\n/)
     45
     46        getHeader.headerToSearch = [];
     47
     48        // prepare headerToSearch for speedup.
     49        for (var index = 0; index < headerList.length; index++) {
     50          var headerToSearch_splitted = headerList[index].split(/:/)
     51            // use first part (all before ':') as the header name
     52          var headerNameToSearch = headerToSearch_splitted[0].toLowerCase()
     53            // check second or third part for any number
     54          var headerNumberToSearch = null;
     55          if (headerToSearch_splitted.length > 1) parseInt(headerToSearch_splitted[1]);
     56          if ((!headerNumberToSearch || isNaN(headerNumberToSearch)) && headerToSearch_splitted.length > 2) headerNumberToSearch = parseInt(headerToSearch_splitted[2]);
     57
     58          // create header name to store the value
     59          var headerNameToStore = headerNameToSearch;
     60          if (headerNumberToSearch && !isNaN(headerNumberToSearch)) headerNameToStore += ":" + headerNumberToSearch
     61
     62          getHeader.headerToSearch.push({
     63            headerNameToSearch: headerNameToSearch,
     64            headerNumberToSearch: headerNumberToSearch,
     65            headerNameToStore: headerNameToStore
     66          });
    7567        }
    76         if (aHeaders.has("received")) {
    77           getHeader.hdr.setStringProperty("vI_received","found");
    78           Log.debug("found header: received  ...stored to recognize received mail");
    79         }
    80         if (aHeaders.has("content-base")) {
    81           getHeader.hdr.setStringProperty("vI_content_base","found");
    82           Log.debug("found header: content-base  ...stored to recognize blog/news-feed");
    83         }
    84         for (let index = 0; index < getHeader.headerToSearch.length; index++) {
    85           let {headerNameToSearch: headerNameToSearch, headerNumberToSearch: headerNumberToSearch,
    86             headerNameToStore: headerNameToStore} = getHeader.headerToSearch[index];
    87           if (aHeaders.has(headerNameToSearch)) {
    88             let value = "";
    89             let values = aHeaders.getAll(headerNameToSearch);
    90             if (!headerNumberToSearch || isNaN(headerNumberToSearch))
    91               for (let i = 0; i < values.length;)
    92                 value += ((value)?(", "):("")) + values[i++];
    93             else value = values[headerNumberToSearch-1];
    94             if (value) {
    95               getHeader.hdr.setStringProperty("vI_" + headerNameToStore,
    96                 getHeader.unicodeConverter.ConvertFromUnicode(value) + getHeader.unicodeConverter.Finish());
    97              
    98               let storedValue = getHeader.hdr.getProperty("vI_" + headerNameToStore);
    99               let storedConvValue = getHeader.unicodeConverter.ConvertToUnicode(storedValue);
    100              
    101               Log.debug("found header: " + headerNameToStore +
     68      },
     69
     70      getHeader: function () {
     71        vI.clearDebugOutput();
     72        if (!getHeader.headerToSearch) getHeader.prefObserverToSearchArray()
     73
     74        vI.msgHdrGetHeaders(getHeader.hdr, function (aHeaders) {
     75          let label = "";
     76          if (aHeaders.has("list-id")) {
     77            getHeader.hdr.setStringProperty("vI_list-id", "found");
     78            Log.debug("found header: list-id  ...stored to recognize mailing-list");
     79          }
     80          if (aHeaders.has("received")) {
     81            getHeader.hdr.setStringProperty("vI_received", "found");
     82            Log.debug("found header: received  ...stored to recognize received mail");
     83          }
     84          if (aHeaders.has("content-base")) {
     85            getHeader.hdr.setStringProperty("vI_content_base", "found");
     86            Log.debug("found header: content-base  ...stored to recognize blog/news-feed");
     87          }
     88          for (let index = 0; index < getHeader.headerToSearch.length; index++) {
     89            let {
     90              headerNameToSearch: headerNameToSearch,
     91              headerNumberToSearch: headerNumberToSearch,
     92              headerNameToStore: headerNameToStore
     93            } = getHeader.headerToSearch[index];
     94            if (aHeaders.has(headerNameToSearch)) {
     95              let value = "";
     96              let values = aHeaders.getAll(headerNameToSearch);
     97              if (!headerNumberToSearch || isNaN(headerNumberToSearch))
     98                for (let i = 0; i < values.length;)
     99                  value += ((value) ? (", ") : ("")) + values[i++];
     100              else value = values[headerNumberToSearch - 1];
     101              if (value) {
     102                getHeader.hdr.setStringProperty("vI_" + headerNameToStore,
     103                  getHeader.unicodeConverter.ConvertFromUnicode(value) + getHeader.unicodeConverter.Finish());
     104
     105                let storedValue = getHeader.hdr.getProperty("vI_" + headerNameToStore);
     106                let storedConvValue = getHeader.unicodeConverter.ConvertToUnicode(storedValue);
     107
     108                Log.debug("found header: " + headerNameToStore +
    102109                  " - stored as '" + storedConvValue + "'");
    103               label += (label)?"\n":""
    104               label += headerNameToStore + ":\t" + storedConvValue
     110                label += (label) ? "\n" : ""
     111                label += headerNameToStore + ":\t" + storedConvValue
     112              }
    105113            }
    106114          }
    107         }
    108         vI.GetHeaderNotification.info(label);
    109       });
    110     },
    111    
    112     setupEventListener: function() {
    113         getHeader.unicodeConverter.charset = "UTF-8";
    114        
     115          vI.GetHeaderNotification.info(label);
     116        });
     117      },
     118
     119      setupEventListener: function () {
     120        getHeader.unicodeConverter.charset = "UTF-8";
     121
    115122        // read headers later if msg is loaded completely - this ensures compatibility to Thunderbird Conversation
    116123        getHeader.orig_OnMsgLoaded = OnMsgLoaded;
    117124        OnMsgLoaded = getHeader.OnMsgLoaded;
    118125
    119     },
    120    
    121     OnMsgLoaded: function(url) {
    122         const Cc = Components.classes;
    123         const Ci = Components.interfaces;
    124         // Necko URL, so convert it into a message header
     126      },
     127
     128      OnMsgLoaded: function (url) {
     129        const Cc = Components.classes;
     130        const Ci = Components.interfaces;
     131        // Necko URL, so convert it into a message header
    125132        let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    126133        var neckoURL = ioService.newURI(null, null, url.baseURI);
    127         neckoURL.QueryInterface(Ci.nsIMsgMessageUrl);
    128        
    129         getHeader.hdr = neckoURL.messageHeader;
    130         if (getHeader.hdr) getHeader.getHeader();
     134        neckoURL.QueryInterface(Ci.nsIMsgMessageUrl);
     135
     136        getHeader.hdr = neckoURL.messageHeader;
     137        if (getHeader.hdr) getHeader.getHeader();
    131138        getHeader.orig_OnMsgLoaded(url);
    132     }
    133 }
     139      }
     140    }
    134141
    135142
    136 var prefObserver = {
    137     unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
    138             .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
    139            
    140     observer_added : false,
    141    
    142     init : function() {
    143       vI.vIprefs.addObserver("smart_reply_headers", this.observe, this);
    144     },
    145    
    146     cleanup : function() {
    147       let self = this;
    148       vI.vIprefs.removeObserver("smart_reply_headers", self.observe);
    149     },
    150    
    151     observe: function(self, subject, topic, data) {
    152         if (topic == "nsPref:changed") {
    153             // remove (old) prepared headerArray
    154             getHeader.headerToSearch = null;
    155             ReloadMessage();
    156         }
    157     },
     143    var prefObserver = {
     144      unicodeConverter: Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
     145        .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
    158146
    159 }
    160 addEventListener('messagepane-loaded', getHeader.setupEventListener, true);
    161 window.addEventListener("load", function(e) { prefObserver.init(); }, false);
    162 window.addEventListener("unload", function(e) { prefObserver.cleanup(); }, false);
    163 // vI.storedHeaders = storedHeaders;
    164 }});
     147      observer_added: false,
     148
     149      init: function () {
     150        vI.vIprefs.addObserver("smart_reply_headers", this.observe, this);
     151      },
     152
     153      cleanup: function () {
     154        let self = this;
     155        vI.vIprefs.removeObserver("smart_reply_headers", self.observe);
     156      },
     157
     158      observe: function (self, subject, topic, data) {
     159        if (topic == "nsPref:changed") {
     160          // remove (old) prepared headerArray
     161          getHeader.headerToSearch = null;
     162          ReloadMessage();
     163        }
     164      },
     165
     166    }
     167    addEventListener('messagepane-loaded', getHeader.setupEventListener, true);
     168    window.addEventListener("load", function (e) {
     169      prefObserver.init();
     170    }, false);
     171    window.addEventListener("unload", function (e) {
     172      prefObserver.cleanup();
     173    }, false);
     174    // vI.storedHeaders = storedHeaders;
     175  }
     176});
  • content/vI_overlay.js

    r3c9c29 r509348  
    11  /* ***** BEGIN LICENSE BLOCK *****
    2     This program is free software; you can redistribute it and/or modify
    3     it under the terms of the GNU General Public License as published by
    4     the Free Software Foundation; either version 2 of the License, or
    5     (at your option) any later version.
     2      This program is free software; you can redistribute it and/or modify
     3      it under the terms of the GNU General Public License as published by
     4      the Free Software Foundation; either version 2 of the License, or
     5      (at your option) any later version.
    66
    7     This program is distributed in the hope that it will be useful,
    8     but WITHOUT ANY WARRANTY; without even the implied warranty of
    9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10     GNU General Public License for more details.
     7      This program is distributed in the hope that it will be useful,
     8      but WITHOUT ANY WARRANTY; without even the implied warranty of
     9      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10      GNU General Public License for more details.
    1111
    12     You should have received a copy of the GNU General Public License
    13     along with this program; if not, write to the Free Software
    14     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     12      You should have received a copy of the GNU General Public License
     13      along with this program; if not, write to the Free Software
     14      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1515
    16     The Original Code is the Virtual Identity Extension.
     16      The Original Code is the Virtual Identity Extension.
    1717
    18     The Initial Developer of the Original Code is Rene Ejury.
    19     Portions created by the Initial Developer are Copyright (C) 2011
    20     the Initial Developer. All Rights Reserved.
     18      The Initial Developer of the Original Code is Rene Ejury.
     19      Portions created by the Initial Developer are Copyright (C) 2011
     20      the Initial Developer. All Rights Reserved.
    2121
    22     Contributor(s):
    23  * ***** END LICENSE BLOCK ***** */
     22      Contributor(s):
     23   * ***** END LICENSE BLOCK ***** */
    2424
    25 Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27  
    28 let Log = vI.setupLogging("virtualIdentity.overlay");
     25  Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
     26  virtualIdentityExtension.ns(function () {
     27    with(virtualIdentityExtension.LIB) {
    2928
    30 Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
    31 Components.utils.import("resource://v_identity/vI_account.js", virtualIdentityExtension);
    32 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     29      let Log = vI.setupLogging("virtualIdentity.overlay");
    3330
    34 Components.utils.import("resource://gre/modules/AddonManager.jsm"); 
     31      Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
     32      Components.utils.import("resource://v_identity/vI_account.js", virtualIdentityExtension);
     33      Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    3534
    36 const virtualIdentity_ID="{dddd428e-5ac8-4a81-9f78-276c734f75b8}"
    37 AddonManager.getAddonByID(virtualIdentity_ID, function(addon) {
    38   if (addon)
    39     vI.extensionVersion = addon.version;
    40 });
     35      Components.utils.import("resource://gre/modules/AddonManager.jsm");
     36
     37      const virtualIdentity_ID = "{dddd428e-5ac8-4a81-9f78-276c734f75b8}"
     38      AddonManager.getAddonByID(virtualIdentity_ID, function (addon) {
     39        if (addon)
     40          vI.extensionVersion = addon.version;
     41      });
    4142
    4243
    43 function extensionInit() {
    44   Log.debug("init")
    45   vI.upgrade.quickUpgrade();
    46   vI.vIaccount_cleanupSystem(); // always clean leftover accounts and directories
    47  
    48   if (vI.vIprefs.get("error_console")) {
    49     document.getElementById("virtualIdentityExtension_vIErrorBoxSplitter").removeAttribute("hidden");
    50     document.getElementById("virtualIdentityExtension_vIErrorBox").removeAttribute("hidden");
    51     document.getElementById("virtualIdentityExtension_vIErrorBox").setAttribute("class", "console-box");
    52     vI.prefroot.setBoolPref("javascript.options.showInConsole", true);
    53     vI.prefroot.setBoolPref("browser.dom.window.dump.enabled", true);
    54     vI.prefroot.setBoolPref("javascript.options.strict", true);
    55   }
    56 }
     44      function extensionInit() {
     45        Log.debug("init")
     46        vI.upgrade.quickUpgrade();
     47        vI.vIaccount_cleanupSystem(); // always clean leftover accounts and directories
    5748
    58 addEventListener('messagepane-loaded', extensionInit, true);
    59 // this is the entry place, nameSpaceWrapper is loaded and the show can start
    60 try {
    61   Components.utils.import("resource://v_identity/plugins/conversations.js", virtualIdentityExtension);
    62 } catch(e) {
    63   vI.dumpCallStack(e);
    64 }
     49        if (vI.vIprefs.get("error_console")) {
     50          document.getElementById("virtualIdentityExtension_vIErrorBoxSplitter").removeAttribute("hidden");
     51          document.getElementById("virtualIdentityExtension_vIErrorBox").removeAttribute("hidden");
     52          document.getElementById("virtualIdentityExtension_vIErrorBox").setAttribute("class", "console-box");
     53          vI.prefroot.setBoolPref("javascript.options.showInConsole", true);
     54          vI.prefroot.setBoolPref("browser.dom.window.dump.enabled", true);
     55          vI.prefroot.setBoolPref("javascript.options.strict", true);
     56        }
     57      }
     58
     59      addEventListener('messagepane-loaded', extensionInit, true);
     60      // this is the entry place, nameSpaceWrapper is loaded and the show can start
     61      try {
     62        Components.utils.import("resource://v_identity/plugins/conversations.js", virtualIdentityExtension);
     63      } catch (e) {
     64        vI.dumpCallStack(e);
     65      }
    6566
    6667
    67 }});
     68    }
     69  });
  • content/vI_rdfAccountMismatchDialog.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27 let Log = vI.setupLogging("virtualIdentity.rdfAccountMismatchDialog");
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28    let Log = vI.setupLogging("virtualIdentity.rdfAccountMismatchDialog");
    2829
    29 var rdfAccountMismatchDialog = {
    30     mismatchItems : null,
    31     type : null,
     30    var rdfAccountMismatchDialog = {
     31      mismatchItems: null,
     32      type: null,
    3233
    33     init : function() {
    34         rdfAccountMismatchDialog.type = window.arguments[0];
     34      init: function () {
     35        rdfAccountMismatchDialog.type = window.arguments[0];
    3536        rdfAccountMismatchDialog.mismatchItems = window.arguments[1];
    3637
     
    3839        document.getElementById("virtualIdentityExtension_rdfAccountMismatchDialog_vbox_" + rdfAccountMismatchDialog.type).removeAttribute("hidden");
    3940        document.getElementById("virtualIdentityExtension_rdfAccountMismatchDialog_listhead_" + rdfAccountMismatchDialog.type).removeAttribute("hidden");
    40        
    41         for (var i = 0; i < rdfAccountMismatchDialog.mismatchItems.length; i++) {
    42 //             var label = document.createElement("label");
    43             var listitem = document.createElement("listitem");
    44             listitem.setAttribute("id", "virtualIdentityExtension_mismatchLine_" + i);
    45             listitem.setAttribute("class", "mismatchLine");
    46             listitem.setAttribute("type",rdfAccountMismatchDialog.type);
    47             listitem.setAttribute("oldkey",rdfAccountMismatchDialog.mismatchItems[i].oldkey);
    48             listitem.setAttribute("label",rdfAccountMismatchDialog.mismatchItems[i].label);
    49             listitem.setAttribute("ext1",rdfAccountMismatchDialog.mismatchItems[i].ext1);
    50             listitem.setAttribute("ext2",rdfAccountMismatchDialog.mismatchItems[i].ext2);
    51             listitem.setAttribute("count",rdfAccountMismatchDialog.mismatchItems[i].count);
    52             document.getElementById("virtualIdentityExtension_rdfAccountMismatchDialog_listbox").appendChild(listitem)
    53         }
    54     },
    5541
    56     accept : function() {
    5742        for (var i = 0; i < rdfAccountMismatchDialog.mismatchItems.length; i++) {
    58             rdfAccountMismatchDialog.mismatchItems[i].key = document.getElementById("virtualIdentityExtension_mismatchLine_" + i).key
     43          //             var label = document.createElement("label");
     44          var listitem = document.createElement("listitem");
     45          listitem.setAttribute("id", "virtualIdentityExtension_mismatchLine_" + i);
     46          listitem.setAttribute("class", "mismatchLine");
     47          listitem.setAttribute("type", rdfAccountMismatchDialog.type);
     48          listitem.setAttribute("oldkey", rdfAccountMismatchDialog.mismatchItems[i].oldkey);
     49          listitem.setAttribute("label", rdfAccountMismatchDialog.mismatchItems[i].label);
     50          listitem.setAttribute("ext1", rdfAccountMismatchDialog.mismatchItems[i].ext1);
     51          listitem.setAttribute("ext2", rdfAccountMismatchDialog.mismatchItems[i].ext2);
     52          listitem.setAttribute("count", rdfAccountMismatchDialog.mismatchItems[i].count);
     53          document.getElementById("virtualIdentityExtension_rdfAccountMismatchDialog_listbox").appendChild(listitem)
    5954        }
    60         /* window.argument[2] stores callback parent */
     55      },
     56
     57      accept: function () {
     58        for (var i = 0; i < rdfAccountMismatchDialog.mismatchItems.length; i++) {
     59          rdfAccountMismatchDialog.mismatchItems[i].key = document.getElementById("virtualIdentityExtension_mismatchLine_" + i).key
     60        }
     61        /* window.argument[2] stores callback parent */
    6162        window.arguments[2].repairAccountMismatch(rdfAccountMismatchDialog.type, rdfAccountMismatchDialog.mismatchItems);
    62     }
    63 }
    64 window.addEventListener("load", rdfAccountMismatchDialog.init, false);
    65 vI.rdfAccountMismatchDialog = rdfAccountMismatchDialog;
    66 }});
     63      }
     64    }
     65    window.addEventListener("load", rdfAccountMismatchDialog.init, false);
     66    vI.rdfAccountMismatchDialog = rdfAccountMismatchDialog;
     67  }
     68});
  • content/vI_rdfDataEditor.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
    2728
    28 Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
    29 let Log = vI.setupLogging("virtualIdentity.rdfDataEditor");
    30 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     29    Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
     30    let Log = vI.setupLogging("virtualIdentity.rdfDataEditor");
     31    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    3132
    32 var rdfDataEditor = {
    33     __rdfDatasource : null,
    34     __rdfDataTree : null,
    35     __type : null,
    36     __recipient : null,
    37     __identityData : null,
    38    
    39     __populateIdentityMenu : function() {
    40         var listitem = document.createElement("menuitem");
    41         listitem.setAttribute("label", "");
    42         document.getElementById("virtualIdentityExtension_IdentityListPopup").appendChild(listitem);
    43         document.getElementById("virtualIdentityExtension_IdentityList").selectedItem = listitem;
    44         var separator = document.createElement("menuseparator");
    45         document.getElementById("virtualIdentityExtension_IdentityListPopup").appendChild(separator);
     33    var rdfDataEditor = {
     34      __rdfDatasource: null,
     35      __rdfDataTree: null,
     36      __type: null,
     37      __recipient: null,
     38      __identityData: null,
    4639
    47         FillIdentityList(document.getElementById("virtualIdentityExtension_IdentityList"))
    48     },
     40      __populateIdentityMenu: function () {
     41        var listitem = document.createElement("menuitem");
     42        listitem.setAttribute("label", "");
     43        document.getElementById("virtualIdentityExtension_IdentityListPopup").appendChild(listitem);
     44        document.getElementById("virtualIdentityExtension_IdentityList").selectedItem = listitem;
     45        var separator = document.createElement("menuseparator");
     46        document.getElementById("virtualIdentityExtension_IdentityListPopup").appendChild(separator);
    4947
    50     init : function() {
    51         if (window.arguments[0]["recipientCol"])
    52             rdfDataEditor.__recipient = window.arguments[0]["recipientCol"];
    53         rdfDataEditor.__type = window.arguments[1];
    54         rdfDataEditor.__rdfDatasource = window.arguments[2];
    55         rdfDataEditor.__rdfDataTree = window.arguments[3];
    56         ;
    57         rdfDataEditor.__identityData = new vI.identityData();
    58         rdfDataEditor.__identityData.copy(window.arguments[0].identityData);
     48        FillIdentityList(document.getElementById("virtualIdentityExtension_IdentityList"))
     49      },
    5950
    60        
    61         // set recipient
    62         document.getElementById("recipient").value = rdfDataEditor.__recipient;
    63        
    64         // set type of entry (and populate Menu)
    65         var typeMenuPopup = document.getElementById("type_menu_popup")
    66         for each (var typeField in Array("email", "maillist", "newsgroup", "filter")) {
    67             var menuitem = document.createElement("menuitem");
    68             var label = Components.classes["@mozilla.org/intl/stringbundle;1"]
    69               .getService(Components.interfaces.nsIStringBundleService)
    70               .createBundle("chrome://v_identity/locale/vI_rdfDataEditor.properties")
    71               .GetStringFromName("vI_rdfDataTree.dataType." + typeField);
    72             menuitem.setAttribute("label", label);
    73             menuitem.setAttribute("key", typeField);
    74             typeMenuPopup.appendChild(menuitem);
    75             if (typeField == rdfDataEditor.__type) document.getElementById("type_menu").selectedItem = menuitem
    76         }
    77        
    78         // set sender
    79         document.getElementById("sender").value = rdfDataEditor.__identityData.combinedName;
     51      init: function () {
     52        if (window.arguments[0]["recipientCol"])
     53          rdfDataEditor.__recipient = window.arguments[0]["recipientCol"];
     54        rdfDataEditor.__type = window.arguments[1];
     55        rdfDataEditor.__rdfDatasource = window.arguments[2];
     56        rdfDataEditor.__rdfDataTree = window.arguments[3];;
     57        rdfDataEditor.__identityData = new vI.identityData();
     58        rdfDataEditor.__identityData.copy(window.arguments[0].identityData);
    8059
    81         // set Identity
    82         rdfDataEditor.__populateIdentityMenu();
    83         var MenuItems = document.getElementById("virtualIdentityExtension_IdentityListPopup").childNodes;
    84         for (var index = 0; index < MenuItems.length; index++) {
    85             if (MenuItems[index].getAttribute("value") == rdfDataEditor.__identityData.id.key) {
    86                 document.getElementById("virtualIdentityExtension_IdentityList").selectedItem =
    87                         MenuItems[index];
    88                 break;
    89             }
    90         }
    9160
    92         // set SMTP
    93         document.getElementById("virtualIdentityExtension_smtpServerListHbox").addNoneServer(); // add non (not stored) Server
    94         document.getElementById("virtualIdentityExtension_smtpServerListHbox").smtp = rdfDataEditor.__identityData.smtp.keyNice;
    95        
    96         // set extra values
     61        // set recipient
     62        document.getElementById("recipient").value = rdfDataEditor.__recipient;
     63
     64        // set type of entry (and populate Menu)
     65        var typeMenuPopup = document.getElementById("type_menu_popup")
     66        for each(var typeField in Array("email", "maillist", "newsgroup", "filter")) {
     67          var menuitem = document.createElement("menuitem");
     68          var label = Components.classes["@mozilla.org/intl/stringbundle;1"]
     69            .getService(Components.interfaces.nsIStringBundleService)
     70            .createBundle("chrome://v_identity/locale/vI_rdfDataEditor.properties")
     71            .GetStringFromName("vI_rdfDataTree.dataType." + typeField);
     72          menuitem.setAttribute("label", label);
     73          menuitem.setAttribute("key", typeField);
     74          typeMenuPopup.appendChild(menuitem);
     75          if (typeField == rdfDataEditor.__type) document.getElementById("type_menu").selectedItem = menuitem
     76        }
     77
     78        // set sender
     79        document.getElementById("sender").value = rdfDataEditor.__identityData.combinedName;
     80
     81        // set Identity
     82        rdfDataEditor.__populateIdentityMenu();
     83        var MenuItems = document.getElementById("virtualIdentityExtension_IdentityListPopup").childNodes;
     84        for (var index = 0; index < MenuItems.length; index++) {
     85          if (MenuItems[index].getAttribute("value") == rdfDataEditor.__identityData.id.key) {
     86            document.getElementById("virtualIdentityExtension_IdentityList").selectedItem =
     87              MenuItems[index];
     88            break;
     89          }
     90        }
     91
     92        // set SMTP
     93        document.getElementById("virtualIdentityExtension_smtpServerListHbox").addNoneServer(); // add non (not stored) Server
     94        document.getElementById("virtualIdentityExtension_smtpServerListHbox").smtp = rdfDataEditor.__identityData.smtp.keyNice;
     95
     96        // set extra values
    9797        rdfDataEditor.__identityData.extras.setValuesToEnvironment();
    98         this.hideUnusedEditorFields();
     98        this.hideUnusedEditorFields();
    9999        Log.debug("init done");
    100     },
    101    
    102     hideUnusedEditorFields : function() {
    103       var allHidden = true;
    104       var hide = (document.getElementById("vI_storageExtras_hideUnusedEditorFields").getAttribute("checked") == "true")
    105       rdfDataEditor.__identityData.extras.loopThroughExtras(
    106         function(extra) {
    107           var hidden = hide && !vI.vIprefs.get(extra.option);
    108           document.getElementById("vI_" + extra.option).setAttribute("hidden", hidden)
    109           document.getElementById("vI_" + extra.option + "_store").setAttribute("hidden", hidden)
    110           if (!hidden) allHidden = false
    111         } );
    112       document.getElementById("storeValue").setAttribute("hidden", allHidden)
    113       // resize the window to the content
    114       window.sizeToContent();
    115     },
     100      },
    116101
    117     identityExtras_adapt: function(sourceId, targetId) {
    118       var checked = document.getElementById(sourceId).getAttribute("checked");
    119       if (targetId) var target = document.getElementById(targetId)
    120       else var target = document.getElementById(sourceId.replace(/_store/,""))
    121       if (checked == "true") target.removeAttribute("disabled")
    122       else target.setAttribute("disabled", "true");
    123     },
    124  
    125     blurEvent : function(elementId) {
    126         var elem = document.getElementById(elementId);
    127         var localIdentityData = new vI.identityData(elem.value, null, null, null, null, null, null);
    128         elem.value = localIdentityData.combinedName;                   
    129     },
    130    
    131     accept : function() {
    132         Log.debug("accept");
     102      hideUnusedEditorFields: function () {
     103        var allHidden = true;
     104        var hide = (document.getElementById("vI_storageExtras_hideUnusedEditorFields").getAttribute("checked") == "true")
     105        rdfDataEditor.__identityData.extras.loopThroughExtras(
     106          function (extra) {
     107            var hidden = hide && !vI.vIprefs.get(extra.option);
     108            document.getElementById("vI_" + extra.option).setAttribute("hidden", hidden)
     109            document.getElementById("vI_" + extra.option + "_store").setAttribute("hidden", hidden)
     110            if (!hidden) allHidden = false
     111          });
     112        document.getElementById("storeValue").setAttribute("hidden", allHidden)
     113          // resize the window to the content
     114        window.sizeToContent();
     115      },
     116
     117      identityExtras_adapt: function (sourceId, targetId) {
     118        var checked = document.getElementById(sourceId).getAttribute("checked");
     119        if (targetId) var target = document.getElementById(targetId)
     120        else var target = document.getElementById(sourceId.replace(/_store/, ""))
     121        if (checked == "true") target.removeAttribute("disabled")
     122        else target.setAttribute("disabled", "true");
     123      },
     124
     125      blurEvent: function (elementId) {
     126        var elem = document.getElementById(elementId);
     127        var localIdentityData = new vI.identityData(elem.value, null, null, null, null, null, null);
     128        elem.value = localIdentityData.combinedName;
     129      },
     130
     131      accept: function () {
     132        Log.debug("accept");
    133133        var localIdentityData = new vI.identityData(document.getElementById("sender").value, null,
    134             document.getElementById("virtualIdentityExtension_IdentityList").selectedItem.getAttribute("value"),
    135             document.getElementById("virtualIdentityExtension_SmtpServerList").selectedItem.getAttribute("key"));
     134          document.getElementById("virtualIdentityExtension_IdentityList").selectedItem.getAttribute("value"),
     135          document.getElementById("virtualIdentityExtension_SmtpServerList").selectedItem.getAttribute("key"));
    136136        localIdentityData.extras.getValuesFromEnvironment();
    137137        rdfDataEditor.__rdfDatasource.updateRDF(
    138                 document.getElementById("recipient").value,
    139                 document.getElementById("type_menu").selectedItem.getAttribute("key"),
    140                 localIdentityData,
    141                 true, true, rdfDataEditor.__recipient, rdfDataEditor.__type, true);
    142         Log.debug("updateRDF done " + localIdentityData.extras.status());
    143         return document.getElementById("type_menu").selectedItem.getAttribute("key");
    144     }
    145 }
    146 vI.rdfDataEditor = rdfDataEditor;
    147 }});
     138          document.getElementById("recipient").value,
     139          document.getElementById("type_menu").selectedItem.getAttribute("key"),
     140          localIdentityData,
     141          true, true, rdfDataEditor.__recipient, rdfDataEditor.__type, true);
     142        Log.debug("updateRDF done " + localIdentityData.extras.status());
     143        return document.getElementById("type_menu").selectedItem.getAttribute("key");
     144      }
     145    }
     146    vI.rdfDataEditor = rdfDataEditor;
     147  }
     148});
  • content/vI_rdfDataTree.js

    r3c9c29 r509348  
    3030
    3131Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    32 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    33 
    34 let Log = vI.setupLogging("virtualIdentity.rdfDataTree");
    35 
    36 Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
    37 Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
    38 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    39 
    40 //prepares an object for easy comparison against another. for strings, lowercases them
    41 var prepareForComparison = function(element, field) {
    42     if (field == "changedCol") {
     32virtualIdentityExtension.ns(function () {
     33  with(virtualIdentityExtension.LIB) {
     34
     35    let Log = vI.setupLogging("virtualIdentity.rdfDataTree");
     36
     37    Components.utils.import("resource://v_identity/vI_identityData.js", virtualIdentityExtension);
     38    Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
     39    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     40
     41    //prepares an object for easy comparison against another. for strings, lowercases them
     42    var prepareForComparison = function (element, field) {
     43      if (field == "changedCol") {
    4344        field = "changed"
    44     }
    45     if (field == "usedCol") {
     45      }
     46      if (field == "usedCol") {
    4647        field = "used"
    47     }
    48     var o = element[field];
    49     if (typeof o == "string") { return o.toLowerCase().replace(/\"/g,""); }
    50     return "";
    51 };
    52 
    53 
    54 var rdfDataTree = function(treeType, rdfDatasource) {
    55     this.treeType = treeType;
    56     this._rdfDatasource = rdfDatasource;
    57     this.filterText = "";
    58     this.loadTable();
    59 };
    60 
    61 rdfDataTree.prototype = {
    62     idTable : null,
    63     idData : null,
    64     filterText : null,
    65     treeType : null,
    66     _rdfDatasource : null,
    67 
    68     get treeElem() { return document.getElementById("rdfDataTree_" + this.treeType); },
    69     get tabElem() { return document.getElementById(this.treeType + "Tab"); },
    70    
    71     //this function is called every time the tree is sorted, filtered, or reloaded
    72     loadTable : function() {
    73 //         Log.debug("loadTable.");
    74         //remember scroll position. this is useful if this is an editable table
    75         //to prevent the user from losing the row they edited
    76         var topVisibleRow = null;
    77         if (this.idTable)
     48      }
     49      var o = element[field];
     50      if (typeof o == "string") {
     51        return o.toLowerCase().replace(/\"/g, "");
     52      }
     53      return "";
     54    };
     55
     56
     57    var rdfDataTree = function (treeType, rdfDatasource) {
     58      this.treeType = treeType;
     59      this._rdfDatasource = rdfDatasource;
     60      this.filterText = "";
     61      this.loadTable();
     62    };
     63
     64    rdfDataTree.prototype = {
     65      idTable: null,
     66      idData: null,
     67      filterText: null,
     68      treeType: null,
     69      _rdfDatasource: null,
     70
     71      get treeElem() {
     72        return document.getElementById("rdfDataTree_" + this.treeType);
     73      },
     74      get tabElem() {
     75        return document.getElementById(this.treeType + "Tab");
     76      },
     77
     78      //this function is called every time the tree is sorted, filtered, or reloaded
     79      loadTable: function () {
     80        //         Log.debug("loadTable.");
     81        //remember scroll position. this is useful if this is an editable table
     82        //to prevent the user from losing the row they edited
     83        var topVisibleRow = null;
     84        if (this.idTable)
    7885          topVisibleRow = this.treeElem.treeBoxObject.getFirstVisibleRow();
    79         if (this.idData == null) {
    80             this.idData = [];
    81             this._rdfDatasource.readAllEntriesFromRDF(this.addNewDatum, this.treeType, this.idData);
    82         }
    83         if (this.filterText == "") {
    84             //show all of them
    85             this.idTable = this.idData;
    86         } else {
    87             //filter out the ones we want to display
    88             var curTable = [];
    89             var curFilterText = this.filterText;
    90             this.idData.forEach(function(element) {
    91                 //we'll match on every property
    92                 for (var i in element) {
    93                     if (prepareForComparison(element, i).indexOf(curFilterText) != -1) {
    94                         curTable.push(element);
    95                         break;
    96                     }
    97                 }
    98             });
    99             this.idTable = curTable;
    100         }   
    101        
    102         this.sort();
    103        
    104         //restore scroll position
    105         if (topVisibleRow && topVisibleRow <= this.idTable.length) {
    106             this.treeElem.treeBoxObject.scrollToRow(topVisibleRow);
    107         }
    108 
    109         // set Tab label
    110         this.tabElem.setAttribute("label", this.treeType + " (" + this.idTable.length + ")");
    111 //         Log.debug("loadTable done.");
    112     },
    113 
    114     addNewDatum : function(resource, name, localIdentityData, idData, used, changed) {
    115         var usedDate = "", changedDate = "";
     86        if (this.idData == null) {
     87          this.idData = [];
     88          this._rdfDatasource.readAllEntriesFromRDF(this.addNewDatum, this.treeType, this.idData);
     89        }
     90        if (this.filterText == "") {
     91          //show all of them
     92          this.idTable = this.idData;
     93        } else {
     94          //filter out the ones we want to display
     95          var curTable = [];
     96          var curFilterText = this.filterText;
     97          this.idData.forEach(function (element) {
     98            //we'll match on every property
     99            for (var i in element) {
     100              if (prepareForComparison(element, i).indexOf(curFilterText) != -1) {
     101                curTable.push(element);
     102                break;
     103              }
     104            }
     105          });
     106          this.idTable = curTable;
     107        }
     108
     109        this.sort();
     110
     111        //restore scroll position
     112        if (topVisibleRow && topVisibleRow <= this.idTable.length) {
     113          this.treeElem.treeBoxObject.scrollToRow(topVisibleRow);
     114        }
     115
     116        // set Tab label
     117        this.tabElem.setAttribute("label", this.treeType + " (" + this.idTable.length + ")");
     118        //         Log.debug("loadTable done.");
     119      },
     120
     121      addNewDatum: function (resource, name, localIdentityData, idData, used, changed) {
     122        var usedDate = "",
     123          changedDate = "";
    116124        var format = vI.prefroot.getCharPref("extensions.virtualIdentity.storage_timeFormat")
    117125        if (format != "") {
    118             if (used) usedDate = new Date(parseFloat(used)).toLocaleFormat(format);
    119             if (changed) changedDate = new Date(parseFloat(changed)).toLocaleFormat(format);
     126          if (used) usedDate = new Date(parseFloat(used)).toLocaleFormat(format);
     127          if (changed) changedDate = new Date(parseFloat(changed)).toLocaleFormat(format);
    120128        } else {
    121             if (used) usedDate = new Date(parseFloat(used)).toLocaleString();
    122             if (changed) changedDate = new Date(parseFloat(changed)).toLocaleString();
    123         }
    124         var pref = {    recipientCol : name,
    125                 indexCol : idData.length + 1 + ".",
    126                 senderCol : localIdentityData.combinedName,
    127                 smtpCol : localIdentityData.smtp.value,
    128 //              smtpKey : localIdentityData.smtp.key,
    129                 idCol : localIdentityData.id.value,
    130                 usedCol : usedDate,
    131                 used : used,
    132                 changedCol : changedDate,
    133                 changed : changed,
    134 //              idKey : localIdentityData.id.key,
    135                 resource : resource,
    136                 identityData : localIdentityData}
    137 //      Log.debug("addNewDatum.");
    138         localIdentityData.extras.addPrefs(pref);
    139         idData.push(pref);
    140     },
    141     sort : function(columnName) {
    142 //      Log.debug("sort: " + columnName);
    143         var order = this.treeElem.getAttribute("sortDirection") == "ascending" ? 1 : -1;
    144         // if the column is passed and it's already sorted by that column, reverse sort
    145         if (columnName && (this.treeElem.getAttribute("sortResource") == columnName)) {
    146                 order *= -1;
    147         }
    148        
    149         function columnSort(a, b) {
     129          if (used) usedDate = new Date(parseFloat(used)).toLocaleString();
     130          if (changed) changedDate = new Date(parseFloat(changed)).toLocaleString();
     131        }
     132        var pref = {
     133            recipientCol: name,
     134            indexCol: idData.length + 1 + ".",
     135            senderCol: localIdentityData.combinedName,
     136            smtpCol: localIdentityData.smtp.value,
     137            //              smtpKey : localIdentityData.smtp.key,
     138            idCol: localIdentityData.id.value,
     139            usedCol: usedDate,
     140            used: used,
     141            changedCol: changedDate,
     142            changed: changed,
     143            //              idKey : localIdentityData.id.key,
     144            resource: resource,
     145            identityData: localIdentityData
     146          }
     147          //        Log.debug("addNewDatum.");
     148        localIdentityData.extras.addPrefs(pref);
     149        idData.push(pref);
     150      },
     151      sort: function (columnName) {
     152        //      Log.debug("sort: " + columnName);
     153        var order = this.treeElem.getAttribute("sortDirection") == "ascending" ? 1 : -1;
     154        // if the column is passed and it's already sorted by that column, reverse sort
     155        if (columnName && (this.treeElem.getAttribute("sortResource") == columnName)) {
     156          order *= -1;
     157        }
     158
     159        function columnSort(a, b) {
    150160          try {
    151             if (prepareForComparison(a, columnName) >
    152                 prepareForComparison(b, columnName)) return 1 * order;
    153             if (prepareForComparison(a, columnName) <
    154                 prepareForComparison(b, columnName)) return -1 * order;
    155           } catch(e) {};
    156             return 0;
    157         }
    158        
    159         if (!columnName)
     161            if (prepareForComparison(a, columnName) >
     162              prepareForComparison(b, columnName)) return 1 * order;
     163            if (prepareForComparison(a, columnName) <
     164              prepareForComparison(b, columnName)) return -1 * order;
     165          } catch (e) {};
     166          return 0;
     167        }
     168
     169        if (!columnName)
    160170          columnName = this.treeElem.getAttribute("sortResource")
    161        
     171
    162172        this.idTable.sort(columnSort);
    163        
    164         //setting these will make the sort option persist
    165         this.treeElem.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
    166         this.treeElem.setAttribute("sortResource", columnName);
    167        
    168         this.treeElem.view = new rdfDataTreeCollection.treeView(this.idTable);
    169        
    170         //set the appropriate attributes to show to indicator
    171         var cols = this.treeElem.getElementsByTagName("treecol");
    172         for (var i = 0; i < cols.length; i++) {
    173             cols[i].removeAttribute("sortDirection");
    174             if (cols[i].id.match(columnName))
    175                 cols[i].setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
    176         }
    177     }
    178 };
    179 
    180 var rdfDataTreeCollection = {
    181     promptService : Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
    182             .getService(Components.interfaces.nsIPromptService),
    183 
    184     treeTypes : Array("email", "maillist", "newsgroup", "filter"),
    185 
    186     trees : {},
    187     tabbox : null,
    188    
    189     _strings : null,
    190     _rdfDatasource : null,
    191    
    192     onTabSelect : function () {
    193         rdfDataTreeCollection.hideInfoBox();
    194         if (rdfDataTreeCollection.tabbox) {
    195             rdfDataTreeCollection.moveConstraints();
    196             rdfDataTreeCollection.updateButtonMenu();
    197         }
    198     },
    199    
    200     onselect : function () {
    201         rdfDataTreeCollection.moveConstraints();
    202         rdfDataTreeCollection.updateButtonMenu();
    203 
    204         var tree = rdfDataTreeCollection.trees[rdfDataTreeCollection.tabbox.selectedPanel.id];
    205         var htmlBox = document.getElementById("rdfDataTreeCollectionInfoBox")
    206         if (tree.treeElem.view.selection.count != 1)
    207             { rdfDataTreeCollection.hideInfoBox(); return; }
    208        
    209         var identityData = tree.idTable[tree.treeElem.currentIndex]["identityData"];
    210         var _identityInfo =
    211             "<div id='recipientLabel'>" +
    212                 tree.idTable[tree.treeElem.currentIndex]["recipientCol"].replace(/>/g,"&gt;").replace(/</g,"&lt;") +
    213             "</div><div id='vICard'>" +
    214             "<table><tr>" +
    215                 "<td class='image'><img src='chrome://v_identity/skin/vi-info.png' /></td>" +
    216                 "<td class='identityTable'>" +
    217                     "<div class='name'>" + identityData.combinedNameHtml + "</div>" +   
    218                     "<table><tbody>" + identityData.getMatrix() + "</tbody></table>" +
    219                 "</td>" +
    220             "</tr></table></div>"
    221 
    222         htmlBox.outputString = _identityInfo;
    223         rdfDataTreeCollection.infoBoxHidden = false;
    224         htmlBox.setAttribute("style", "height:" + htmlBox.contentDocument.lastChild.scrollHeight +"px");
    225         rdfDataTreeCollection.overflow(); // better resize one time too much, mozilla is still magic  :)
    226     },
    227 
    228     init : function() {
    229         rdfDataTreeCollection.tabbox = document.getElementById("TreeTabbox");
    230         rdfDataTreeCollection._strings = Components.classes["@mozilla.org/intl/stringbundle;1"]
     173
     174        //setting these will make the sort option persist
     175        this.treeElem.setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
     176        this.treeElem.setAttribute("sortResource", columnName);
     177
     178        this.treeElem.view = new rdfDataTreeCollection.treeView(this.idTable);
     179
     180        //set the appropriate attributes to show to indicator
     181        var cols = this.treeElem.getElementsByTagName("treecol");
     182        for (var i = 0; i < cols.length; i++) {
     183          cols[i].removeAttribute("sortDirection");
     184          if (cols[i].id.match(columnName))
     185            cols[i].setAttribute("sortDirection", order == 1 ? "ascending" : "descending");
     186        }
     187      }
     188    };
     189
     190    var rdfDataTreeCollection = {
     191      promptService: Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
     192        .getService(Components.interfaces.nsIPromptService),
     193
     194      treeTypes: Array("email", "maillist", "newsgroup", "filter"),
     195
     196      trees: {},
     197      tabbox: null,
     198
     199      _strings: null,
     200      _rdfDatasource: null,
     201
     202      onTabSelect: function () {
     203        rdfDataTreeCollection.hideInfoBox();
     204        if (rdfDataTreeCollection.tabbox) {
     205          rdfDataTreeCollection.moveConstraints();
     206          rdfDataTreeCollection.updateButtonMenu();
     207        }
     208      },
     209
     210      onselect: function () {
     211        rdfDataTreeCollection.moveConstraints();
     212        rdfDataTreeCollection.updateButtonMenu();
     213
     214        var tree = rdfDataTreeCollection.trees[rdfDataTreeCollection.tabbox.selectedPanel.id];
     215        var htmlBox = document.getElementById("rdfDataTreeCollectionInfoBox")
     216        if (tree.treeElem.view.selection.count != 1) {
     217          rdfDataTreeCollection.hideInfoBox();
     218          return;
     219        }
     220
     221        var identityData = tree.idTable[tree.treeElem.currentIndex]["identityData"];
     222        var _identityInfo =
     223          "<div id='recipientLabel'>" +
     224          tree.idTable[tree.treeElem.currentIndex]["recipientCol"].replace(/>/g, "&gt;").replace(/</g, "&lt;") +
     225          "</div><div id='vICard'>" +
     226          "<table><tr>" +
     227          "<td class='image'><img src='chrome://v_identity/skin/vi-info.png' /></td>" +
     228          "<td class='identityTable'>" +
     229          "<div class='name'>" + identityData.combinedNameHtml + "</div>" +
     230          "<table><tbody>" + identityData.getMatrix() + "</tbody></table>" +
     231          "</td>" +
     232          "</tr></table></div>"
     233
     234        htmlBox.outputString = _identityInfo;
     235        rdfDataTreeCollection.infoBoxHidden = false;
     236        htmlBox.setAttribute("style", "height:" + htmlBox.contentDocument.lastChild.scrollHeight + "px");
     237        rdfDataTreeCollection.overflow(); // better resize one time too much, mozilla is still magic  :)
     238      },
     239
     240      init: function () {
     241        rdfDataTreeCollection.tabbox = document.getElementById("TreeTabbox");
     242        rdfDataTreeCollection._strings = Components.classes["@mozilla.org/intl/stringbundle;1"]
    231243          .getService(Components.interfaces.nsIStringBundleService)
    232244          .createBundle("chrome://v_identity/locale/vI_rdfDataEditor.properties");
    233245
    234         rdfDataTreeCollection._rdfDatasource = new vI.rdfDatasource("virtualIdentity.rdf");
    235        
    236         for each (var treeType in rdfDataTreeCollection.treeTypes)
    237             rdfDataTreeCollection.trees[treeType] = new rdfDataTree(treeType, rdfDataTreeCollection._rdfDatasource);
    238     },
    239    
    240     clean : function() {
     246        rdfDataTreeCollection._rdfDatasource = new vI.rdfDatasource("virtualIdentity.rdf");
     247
     248        for each(var treeType in rdfDataTreeCollection.treeTypes)
     249        rdfDataTreeCollection.trees[treeType] = new rdfDataTree(treeType, rdfDataTreeCollection._rdfDatasource);
     250      },
     251
     252      clean: function () {
    241253        if (rdfDataTreeCollection._rdfDatasource) rdfDataTreeCollection._rdfDatasource.clean();
    242     },
    243 
    244     get _braille() {
    245         var braille = false;
    246         try {   braille = (vI.prefroot.getCharPref("accessibility.usebrailledisplay") ||
    247                 vI.prefroot.getCharPref("accessibility.usetexttospeech")); }
    248         catch (e) { };
    249         return braille;
    250     },
    251 
    252     // generic custom tree view stuff
    253     treeView : function (table) {
    254         this.rowCount = table.length;
    255         this.getCellText = function(row, col) {
    256             var retValue = table[row][col.id.substr(0,col.id.indexOf("_"))];
    257             if (!rdfDataTreeCollection._braille && (retValue == "no" || retValue == "yes"))
    258                 return ""; // image will be used as indicator
    259             else return retValue;
    260         };
    261         this.getCellValue = function(row, col) {
    262             return this.getCellText(row, col);
    263         };
    264         this.setTree = function(treebox) {
    265             this.treebox = treebox;
    266         };
    267         this.isEditable = function(row, col) {
    268             return col.editable;
    269         };
    270         this.isContainer = function(row){ return false; };
    271         this.isSeparator = function(row){ return false; };
    272         this.isSorted = function(){ return false; };
    273         this.getLevel = function(row){ return 0; };
    274         this.getImageSrc = function(row,col){ return null; };
    275         this.getRowProperties = function(row,props){};
    276         this.getCellProperties = function(row,col,props){};
    277         this.getColumnProperties = function(colid,col,props){};
    278         this.cycleHeader = function(col, elem) {
    279             var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    280             if (treeType != "filter")
    281                 rdfDataTreeCollection.trees[treeType].sort(col.id.substr(0,col.id.indexOf("_")));
    282         };
    283         this.getCellProperties = function(row,col,props){
    284             var returnValue = null;
    285             if (!rdfDataTreeCollection._braille) {
    286                 var aserv=Components.classes["@mozilla.org/atom-service;1"].
    287                     getService(Components.interfaces.nsIAtomService);
    288                 if (typeof props == 'undefined') {
    289                     // Requires Gecko 22
    290                     switch (table[row][col.id.substr(0,col.id.indexOf("_"))]) {
    291                         case "yes": returnValue = aserv.getAtom("yes"); break;
    292                         case "no":  returnValue = aserv.getAtom("no"); break;
    293                     }
    294                 } else {
    295                     // Obsolete since Gecko 22
    296                     switch (table[row][col.id.substr(0,col.id.indexOf("_"))]) {
    297                         case "yes": props.AppendElement(aserv.getAtom("yes")); break;
    298                         case "no":  props.AppendElement(aserv.getAtom("no")); break;
    299                     }
    300                 }
     254      },
     255
     256      get _braille() {
     257        var braille = false;
     258        try {
     259          braille = (vI.prefroot.getCharPref("accessibility.usebrailledisplay") ||
     260            vI.prefroot.getCharPref("accessibility.usetexttospeech"));
     261        } catch (e) {};
     262        return braille;
     263      },
     264
     265      // generic custom tree view stuff
     266      treeView: function (table) {
     267        this.rowCount = table.length;
     268        this.getCellText = function (row, col) {
     269          var retValue = table[row][col.id.substr(0, col.id.indexOf("_"))];
     270          if (!rdfDataTreeCollection._braille && (retValue == "no" || retValue == "yes"))
     271            return ""; // image will be used as indicator
     272          else return retValue;
     273        };
     274        this.getCellValue = function (row, col) {
     275          return this.getCellText(row, col);
     276        };
     277        this.setTree = function (treebox) {
     278          this.treebox = treebox;
     279        };
     280        this.isEditable = function (row, col) {
     281          return col.editable;
     282        };
     283        this.isContainer = function (row) {
     284          return false;
     285        };
     286        this.isSeparator = function (row) {
     287          return false;
     288        };
     289        this.isSorted = function () {
     290          return false;
     291        };
     292        this.getLevel = function (row) {
     293          return 0;
     294        };
     295        this.getImageSrc = function (row, col) {
     296          return null;
     297        };
     298        this.getRowProperties = function (row, props) {};
     299        this.getCellProperties = function (row, col, props) {};
     300        this.getColumnProperties = function (colid, col, props) {};
     301        this.cycleHeader = function (col, elem) {
     302          var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     303          if (treeType != "filter")
     304            rdfDataTreeCollection.trees[treeType].sort(col.id.substr(0, col.id.indexOf("_")));
     305        };
     306        this.getCellProperties = function (row, col, props) {
     307          var returnValue = null;
     308          if (!rdfDataTreeCollection._braille) {
     309            var aserv = Components.classes["@mozilla.org/atom-service;1"].
     310            getService(Components.interfaces.nsIAtomService);
     311            if (typeof props == 'undefined') {
     312              // Requires Gecko 22
     313              switch (table[row][col.id.substr(0, col.id.indexOf("_"))]) {
     314              case "yes":
     315                returnValue = aserv.getAtom("yes");
     316                break;
     317              case "no":
     318                returnValue = aserv.getAtom("no");
     319                break;
     320              }
     321            } else {
     322              // Obsolete since Gecko 22
     323              switch (table[row][col.id.substr(0, col.id.indexOf("_"))]) {
     324              case "yes":
     325                props.AppendElement(aserv.getAtom("yes"));
     326                break;
     327              case "no":
     328                props.AppendElement(aserv.getAtom("no"));
     329                break;
     330              }
    301331            }
    302             return returnValue;
    303         };
    304     },
    305 
    306    
    307     __setFilter : function (text) {
    308         // loop trough all trees
    309         for each (var treeType in rdfDataTreeCollection.treeTypes) {
    310             var tree = rdfDataTreeCollection.trees[treeType];
    311             tree.filterText = text;
    312             tree.loadTable();
    313         }
    314     },
    315 
    316     inputFilter : function(event) {
     332          }
     333          return returnValue;
     334        };
     335      },
     336
     337
     338      __setFilter: function (text) {
     339        // loop trough all trees
     340        for each(var treeType in rdfDataTreeCollection.treeTypes) {
     341          var tree = rdfDataTreeCollection.trees[treeType];
     342          tree.filterText = text;
     343          tree.loadTable();
     344        }
     345      },
     346
     347      inputFilter: function (event) {
    317348        var value = "";
    318349        if (typeof event.target.value == "string") {
    319             value = event.target.value.toLowerCase().replace(/\"/g,"");
    320         }
    321         rdfDataTreeCollection.__setFilter(value);
    322         document.getElementById("clearFilter").disabled = value.length == 0;
    323     },
    324    
    325     clearFilter : function() {
    326         document.getElementById("clearFilter").disabled = true;
    327         var filterElement = document.getElementById("filter");
    328         filterElement.focus();
    329         filterElement.value = "";
    330         rdfDataTreeCollection.__setFilter("");
    331     },
    332    
    333     __updateMenu : function(modifySelected, removeSelected) {
    334         var tree = rdfDataTreeCollection.trees[rdfDataTreeCollection.tabbox.selectedPanel.id];
    335         var noSelections = (tree.treeElem.view.selection.count == 0)
    336         modifySelected.setAttribute("disabled", noSelections)
    337         removeSelected.setAttribute("disabled", noSelections)   
    338     },
    339    
    340     updateButtonMenu : function() {
    341         rdfDataTreeCollection.__updateMenu(
    342             document.getElementById("editButton_" + rdfDataTreeCollection.tabbox.selectedPanel.id),
    343             document.getElementById("deleteButton_" + rdfDataTreeCollection.tabbox.selectedPanel.id))
    344     },
    345    
    346     updateContextMenu : function() {
    347         rdfDataTreeCollection.__updateMenu(
    348             document.getElementById("context_modifySelected"),
    349             document.getElementById("context_removeSelected"))
    350     },
    351    
    352     updateMenu : function() {
    353         rdfDataTreeCollection.__updateMenu(
    354             document.getElementById("menu_modifySelected"),
    355             document.getElementById("menu_removeSelected"))
    356     },
    357 
    358     modifySelected : function() {
    359         var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    360         var tree = rdfDataTreeCollection.trees[treeType];
    361         if (tree.treeElem.view.selection.count == 0) return;
    362         if (tree.treeElem.view.selection.count > 5) {
    363             var warning = rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.modify.Warning1") + " " +
    364                 tree.treeElem.view.selection.count + " " +
    365                 rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.modify.Warning2")
    366             if (!rdfDataTreeCollection.promptService.confirm(window,"Warning",warning)) return;
    367         }
    368        
    369         var start = new Object(); var end = new Object();
    370         var numRanges = tree.treeElem.view.selection.getRangeCount();
    371 
    372         var retVar = { treeType: null };
    373         for (var t=0; t<numRanges; t++){
    374             tree.treeElem.view.selection.getRangeAt(t,start,end);
    375             for (var v=start.value; v<=end.value; v++)
    376                 window.openDialog("chrome://v_identity/content/vI_rdfDataEditor.xul",0,
    377                     "chrome, dialog, modal, alwaysRaised, resizable=yes",
    378                     tree.idTable[v], treeType,
    379                     rdfDataTreeCollection._rdfDatasource, retVar).focus();
    380         }
    381        
    382         // reload all trees (multiple types might have changed)
    383         for each (var treeType in rdfDataTreeCollection.treeTypes) {
    384             rdfDataTreeCollection.trees[treeType].idData = null;
    385             rdfDataTreeCollection.trees[treeType].loadTable()
    386         }
    387         rdfDataTreeCollection.tabbox.selectedTab = document.getElementById(retVar.treeType + "Tab");
    388         rdfDataTreeCollection.hideInfoBox();
    389     },
    390    
    391     removeSelected : function() {
    392         var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    393         var tree = rdfDataTreeCollection.trees[treeType];
    394         if (tree.treeElem.view.selection.count == 0) return;
    395         var warning = rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.remove.Warning1") + " " +
    396             tree.treeElem.view.selection.count + " " +
    397             rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.remove.Warning2")
    398        
    399         if (!rdfDataTreeCollection.promptService.confirm(window,"Warning",warning)) return;
    400        
    401         var start = new Object(); var end = new Object();
    402         var numRanges = tree.treeElem.view.selection.getRangeCount();
    403 
    404         for (var t=0; t<numRanges; t++){
    405             tree.treeElem.view.selection.getRangeAt(t,start,end);
    406             for (var v=start.value; v<=end.value; v++){
    407                 rdfDataTreeCollection._rdfDatasource.removeVIdentityFromRDF(tree.idTable[v]["resource"], treeType)
    408             }
    409         }
    410        
    411         tree.idData = null; tree.idTable = null;
    412         tree.loadTable();
    413         rdfDataTreeCollection.hideInfoBox();
    414     },
    415    
    416     moveConstraints : function() {
    417         var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    418         if (treeType != "filter") return;
    419         var tree = rdfDataTreeCollection.trees[treeType];
    420         if (tree.treeElem.view.selection.count == 0) {
    421             document.getElementById("reorderUpButton_filter").setAttribute("disabled","true");
    422             document.getElementById("reorderDownButton_filter").setAttribute("disabled","true");
    423             return;
    424         };
    425         var start = new Object(); var end = new Object();
    426         var numRanges = tree.treeElem.view.selection.getRangeCount();
    427         if (numRanges > 1) {
    428             document.getElementById("reorderUpButton_filter").setAttribute("disabled","true");
    429             document.getElementById("reorderDownButton_filter").setAttribute("disabled","true");
    430             return;
    431         }
    432         tree.treeElem.view.selection.getRangeAt(0,start,end);
    433         if (start.value > 0)
    434             document.getElementById("reorderUpButton_filter").removeAttribute("disabled");
    435         else    document.getElementById("reorderUpButton_filter").setAttribute("disabled","true");
    436         if (end.value < tree.idTable.length - 1)
    437             document.getElementById("reorderDownButton_filter").removeAttribute("disabled");
    438         else    document.getElementById("reorderDownButton_filter").setAttribute("disabled","true");
    439     },
    440 
    441     moveUpSelected : function() {
    442         var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    443         if (treeType != "filter") return; // just to be safe, button should be disabled
    444         var tree = rdfDataTreeCollection.trees[treeType];
    445         if (tree.treeElem.view.selection.count == 0) return; // just to be safe, button should be disabled
    446 
    447         var start = new Object(); var end = new Object();
    448         var numRanges = tree.treeElem.view.selection.getRangeCount();
    449         if (numRanges > 1) return;  // just to be safe, button should be disabled
    450        
    451         tree.treeElem.view.selection.getRangeAt(0,start,end);
    452         for (var v=start.value; v<=end.value; v++){
    453             var resource = rdfDataTreeCollection._rdfDatasource.filterContainer.RemoveElementAt(v+1, true);
    454             rdfDataTreeCollection._rdfDatasource.filterContainer.InsertElementAt(resource,v,true);
    455         }
    456         tree.idData = null; tree.idTable = null;
    457         tree.loadTable();
    458         tree.treeElem.view.selection.rangedSelect(start.value-1,end.value-1,false);
    459     },
    460 
    461     moveDownSelected : function() {
    462         var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    463         if (treeType != "filter") return; // just to be safe, button should be disabled
    464         var tree = rdfDataTreeCollection.trees[treeType];
    465         if (tree.treeElem.view.selection.count == 0) return; // just to be safe, button should be disabled
    466 
    467         var start = new Object(); var end = new Object();
    468         var numRanges = tree.treeElem.view.selection.getRangeCount();
    469         if (numRanges > 1) return;  // just to be safe, button should be disabled
    470        
    471         tree.treeElem.view.selection.getRangeAt(0,start,end);
    472         for (var v=end.value; v>=start.value; v--){
    473             var resource = rdfDataTreeCollection._rdfDatasource.filterContainer.RemoveElementAt(v+1, true);
    474             rdfDataTreeCollection._rdfDatasource.filterContainer.InsertElementAt(resource,v+2,true);
    475         }
    476         tree.idData = null; tree.idTable = null;
    477         tree.loadTable();
    478         tree.treeElem.view.selection.rangedSelect(start.value+1,end.value+1,false);
    479     },
    480 
    481     infoBoxHidden : true,
    482     overflow : function() {
    483         if (rdfDataTreeCollection.infoBoxHidden) return;
    484         var htmlBox = document.getElementById("rdfDataTreeCollectionInfoBox")
    485         htmlBox.setAttribute("style", "height:" + htmlBox.contentDocument.lastChild.scrollHeight +"px");
    486     },
    487 
    488     hideInfoBox : function() {
    489         rdfDataTreeCollection.infoBoxHidden = true;
    490         document.getElementById("rdfDataTreeCollectionInfoBox").setAttribute("style", "height:0px");
    491         for each (var treeType in rdfDataTreeCollection.treeTypes) {
    492             try { if (rdfDataTreeCollection.trees[treeType])
    493                 rdfDataTreeCollection.trees[treeType].treeElem.view.selection.selectNone() } catch (e) { }
    494         }
    495     },
    496 
    497     selectAll : function() {
    498         var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    499         var tree = rdfDataTreeCollection.trees[treeType];
    500         tree.treeElem.view.selection.selectAll();
    501     },
    502    
    503     newItem : function() {
    504         var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
    505         var newItemPreset = { identityData : new vI.identityData ("", null, null, vI.NO_SMTP_TAG, null, null) };
    506         var retVar = { treeType: null };
    507 
    508         window.openDialog("chrome://v_identity/content/vI_rdfDataEditor.xul",0,
    509             "chrome, dialog, modal, alwaysRaised, resizable=yes",
    510             newItemPreset, treeType,
    511             rdfDataTreeCollection._rdfDatasource, retVar).focus();
    512 
    513         // reload all trees (multiple types might have changed)
    514         for each (var treeType in rdfDataTreeCollection.treeTypes) {
    515             rdfDataTreeCollection.trees[treeType].idData = null;
    516             rdfDataTreeCollection.trees[treeType].idTable = null;
    517             rdfDataTreeCollection.trees[treeType].loadTable()
    518         }
    519         rdfDataTreeCollection.tabbox.selectedTab = document.getElementById(retVar.treeType + "Tab");
    520         rdfDataTreeCollection.hideInfoBox();
    521     }
    522 };
    523 
    524 vI.rdfDataTreeCollection = rdfDataTreeCollection;
    525 vI.rdfDataTree = rdfDataTree;
    526 }});
     350          value = event.target.value.toLowerCase().replace(/\"/g, "");
     351        }
     352        rdfDataTreeCollection.__setFilter(value);
     353        document.getElementById("clearFilter").disabled = value.length == 0;
     354      },
     355
     356      clearFilter: function () {
     357        document.getElementById("clearFilter").disabled = true;
     358        var filterElement = document.getElementById("filter");
     359        filterElement.focus();
     360        filterElement.value = "";
     361        rdfDataTreeCollection.__setFilter("");
     362      },
     363
     364      __updateMenu: function (modifySelected, removeSelected) {
     365        var tree = rdfDataTreeCollection.trees[rdfDataTreeCollection.tabbox.selectedPanel.id];
     366        var noSelections = (tree.treeElem.view.selection.count == 0)
     367        modifySelected.setAttribute("disabled", noSelections)
     368        removeSelected.setAttribute("disabled", noSelections)
     369      },
     370
     371      updateButtonMenu: function () {
     372        rdfDataTreeCollection.__updateMenu(
     373          document.getElementById("editButton_" + rdfDataTreeCollection.tabbox.selectedPanel.id),
     374          document.getElementById("deleteButton_" + rdfDataTreeCollection.tabbox.selectedPanel.id))
     375      },
     376
     377      updateContextMenu: function () {
     378        rdfDataTreeCollection.__updateMenu(
     379          document.getElementById("context_modifySelected"),
     380          document.getElementById("context_removeSelected"))
     381      },
     382
     383      updateMenu: function () {
     384        rdfDataTreeCollection.__updateMenu(
     385          document.getElementById("menu_modifySelected"),
     386          document.getElementById("menu_removeSelected"))
     387      },
     388
     389      modifySelected: function () {
     390        var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     391        var tree = rdfDataTreeCollection.trees[treeType];
     392        if (tree.treeElem.view.selection.count == 0) return;
     393        if (tree.treeElem.view.selection.count > 5) {
     394          var warning = rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.modify.Warning1") + " " +
     395            tree.treeElem.view.selection.count + " " +
     396            rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.modify.Warning2")
     397          if (!rdfDataTreeCollection.promptService.confirm(window, "Warning", warning)) return;
     398        }
     399
     400        var start = new Object();
     401        var end = new Object();
     402        var numRanges = tree.treeElem.view.selection.getRangeCount();
     403
     404        var retVar = {
     405          treeType: null
     406        };
     407        for (var t = 0; t < numRanges; t++) {
     408          tree.treeElem.view.selection.getRangeAt(t, start, end);
     409          for (var v = start.value; v <= end.value; v++)
     410            window.openDialog("chrome://v_identity/content/vI_rdfDataEditor.xul", 0,
     411              "chrome, dialog, modal, alwaysRaised, resizable=yes",
     412              tree.idTable[v], treeType,
     413              rdfDataTreeCollection._rdfDatasource, retVar).focus();
     414        }
     415
     416        // reload all trees (multiple types might have changed)
     417        for each(var treeType in rdfDataTreeCollection.treeTypes) {
     418          rdfDataTreeCollection.trees[treeType].idData = null;
     419          rdfDataTreeCollection.trees[treeType].loadTable()
     420        }
     421        rdfDataTreeCollection.tabbox.selectedTab = document.getElementById(retVar.treeType + "Tab");
     422        rdfDataTreeCollection.hideInfoBox();
     423      },
     424
     425      removeSelected: function () {
     426        var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     427        var tree = rdfDataTreeCollection.trees[treeType];
     428        if (tree.treeElem.view.selection.count == 0) return;
     429        var warning = rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.remove.Warning1") + " " +
     430          tree.treeElem.view.selection.count + " " +
     431          rdfDataTreeCollection._strings.GetStringFromName("vI_rdfDataTree.remove.Warning2")
     432
     433        if (!rdfDataTreeCollection.promptService.confirm(window, "Warning", warning)) return;
     434
     435        var start = new Object();
     436        var end = new Object();
     437        var numRanges = tree.treeElem.view.selection.getRangeCount();
     438
     439        for (var t = 0; t < numRanges; t++) {
     440          tree.treeElem.view.selection.getRangeAt(t, start, end);
     441          for (var v = start.value; v <= end.value; v++) {
     442            rdfDataTreeCollection._rdfDatasource.removeVIdentityFromRDF(tree.idTable[v]["resource"], treeType)
     443          }
     444        }
     445
     446        tree.idData = null;
     447        tree.idTable = null;
     448        tree.loadTable();
     449        rdfDataTreeCollection.hideInfoBox();
     450      },
     451
     452      moveConstraints: function () {
     453        var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     454        if (treeType != "filter") return;
     455        var tree = rdfDataTreeCollection.trees[treeType];
     456        if (tree.treeElem.view.selection.count == 0) {
     457          document.getElementById("reorderUpButton_filter").setAttribute("disabled", "true");
     458          document.getElementById("reorderDownButton_filter").setAttribute("disabled", "true");
     459          return;
     460        };
     461        var start = new Object();
     462        var end = new Object();
     463        var numRanges = tree.treeElem.view.selection.getRangeCount();
     464        if (numRanges > 1) {
     465          document.getElementById("reorderUpButton_filter").setAttribute("disabled", "true");
     466          document.getElementById("reorderDownButton_filter").setAttribute("disabled", "true");
     467          return;
     468        }
     469        tree.treeElem.view.selection.getRangeAt(0, start, end);
     470        if (start.value > 0)
     471          document.getElementById("reorderUpButton_filter").removeAttribute("disabled");
     472        else document.getElementById("reorderUpButton_filter").setAttribute("disabled", "true");
     473        if (end.value < tree.idTable.length - 1)
     474          document.getElementById("reorderDownButton_filter").removeAttribute("disabled");
     475        else document.getElementById("reorderDownButton_filter").setAttribute("disabled", "true");
     476      },
     477
     478      moveUpSelected: function () {
     479        var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     480        if (treeType != "filter") return; // just to be safe, button should be disabled
     481        var tree = rdfDataTreeCollection.trees[treeType];
     482        if (tree.treeElem.view.selection.count == 0) return; // just to be safe, button should be disabled
     483
     484        var start = new Object();
     485        var end = new Object();
     486        var numRanges = tree.treeElem.view.selection.getRangeCount();
     487        if (numRanges > 1) return; // just to be safe, button should be disabled
     488
     489        tree.treeElem.view.selection.getRangeAt(0, start, end);
     490        for (var v = start.value; v <= end.value; v++) {
     491          var resource = rdfDataTreeCollection._rdfDatasource.filterContainer.RemoveElementAt(v + 1, true);
     492          rdfDataTreeCollection._rdfDatasource.filterContainer.InsertElementAt(resource, v, true);
     493        }
     494        tree.idData = null;
     495        tree.idTable = null;
     496        tree.loadTable();
     497        tree.treeElem.view.selection.rangedSelect(start.value - 1, end.value - 1, false);
     498      },
     499
     500      moveDownSelected: function () {
     501        var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     502        if (treeType != "filter") return; // just to be safe, button should be disabled
     503        var tree = rdfDataTreeCollection.trees[treeType];
     504        if (tree.treeElem.view.selection.count == 0) return; // just to be safe, button should be disabled
     505
     506        var start = new Object();
     507        var end = new Object();
     508        var numRanges = tree.treeElem.view.selection.getRangeCount();
     509        if (numRanges > 1) return; // just to be safe, button should be disabled
     510
     511        tree.treeElem.view.selection.getRangeAt(0, start, end);
     512        for (var v = end.value; v >= start.value; v--) {
     513          var resource = rdfDataTreeCollection._rdfDatasource.filterContainer.RemoveElementAt(v + 1, true);
     514          rdfDataTreeCollection._rdfDatasource.filterContainer.InsertElementAt(resource, v + 2, true);
     515        }
     516        tree.idData = null;
     517        tree.idTable = null;
     518        tree.loadTable();
     519        tree.treeElem.view.selection.rangedSelect(start.value + 1, end.value + 1, false);
     520      },
     521
     522      infoBoxHidden: true,
     523      overflow: function () {
     524        if (rdfDataTreeCollection.infoBoxHidden) return;
     525        var htmlBox = document.getElementById("rdfDataTreeCollectionInfoBox")
     526        htmlBox.setAttribute("style", "height:" + htmlBox.contentDocument.lastChild.scrollHeight + "px");
     527      },
     528
     529      hideInfoBox: function () {
     530        rdfDataTreeCollection.infoBoxHidden = true;
     531        document.getElementById("rdfDataTreeCollectionInfoBox").setAttribute("style", "height:0px");
     532        for each(var treeType in rdfDataTreeCollection.treeTypes) {
     533          try {
     534            if (rdfDataTreeCollection.trees[treeType])
     535              rdfDataTreeCollection.trees[treeType].treeElem.view.selection.selectNone()
     536          } catch (e) {}
     537        }
     538      },
     539
     540      selectAll: function () {
     541        var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     542        var tree = rdfDataTreeCollection.trees[treeType];
     543        tree.treeElem.view.selection.selectAll();
     544      },
     545
     546      newItem: function () {
     547        var treeType = rdfDataTreeCollection.tabbox.selectedPanel.id;
     548        var newItemPreset = {
     549          identityData: new vI.identityData("", null, null, vI.NO_SMTP_TAG, null, null)
     550        };
     551        var retVar = {
     552          treeType: null
     553        };
     554
     555        window.openDialog("chrome://v_identity/content/vI_rdfDataEditor.xul", 0,
     556          "chrome, dialog, modal, alwaysRaised, resizable=yes",
     557          newItemPreset, treeType,
     558          rdfDataTreeCollection._rdfDatasource, retVar).focus();
     559
     560        // reload all trees (multiple types might have changed)
     561        for each(var treeType in rdfDataTreeCollection.treeTypes) {
     562          rdfDataTreeCollection.trees[treeType].idData = null;
     563          rdfDataTreeCollection.trees[treeType].idTable = null;
     564          rdfDataTreeCollection.trees[treeType].loadTable()
     565        }
     566        rdfDataTreeCollection.tabbox.selectedTab = document.getElementById(retVar.treeType + "Tab");
     567        rdfDataTreeCollection.hideInfoBox();
     568      }
     569    };
     570
     571    vI.rdfDataTreeCollection = rdfDataTreeCollection;
     572    vI.rdfDataTree = rdfDataTree;
     573  }
     574});
  • 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});
  • content/vI_smartReplyDialog.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    27 var smartReply_dialog = {
    28     Obj_radioGroup : null,
    29     all_addresses : null,
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28    var smartReply_dialog = {
     29      Obj_radioGroup: null,
     30      all_addresses: null,
    3031
    31     init : function() {
    32         smartReply_dialog.Obj_radioGroup = document.getElementById("replySelector.radiogroup");
    33         smartReply_dialog.all_addresses = window.arguments[0];
    34         for (var index = 0; index < smartReply_dialog.all_addresses.number; index++) {
    35             var menuentry = smartReply_dialog.all_addresses.identityDataCollection[index].combinedName;
     32      init: function () {
     33        smartReply_dialog.Obj_radioGroup = document.getElementById("replySelector.radiogroup");
     34        smartReply_dialog.all_addresses = window.arguments[0];
     35        for (var index = 0; index < smartReply_dialog.all_addresses.number; index++) {
     36          var menuentry = smartReply_dialog.all_addresses.identityDataCollection[index].combinedName;
    3637
    37             var id = null; var smtp = null;
     38          var id = null;
     39          var smtp = null;
    3840
    39             if (smartReply_dialog.all_addresses.identityDataCollection[index].id)
    40                 id = smartReply_dialog.all_addresses.identityDataCollection[index].id.value;
    41             if (smartReply_dialog.all_addresses.identityDataCollection[index].smtp)
    42                 smtp = smartReply_dialog.all_addresses.identityDataCollection[index].smtp.value;
    43            
    44             let defaultServerTag = Components.classes["@mozilla.org/intl/stringbundle;1"]
    45               .getService(Components.interfaces.nsIStringBundleService)
    46               .createBundle("chrome://messenger/locale/messenger.properties")
    47               .GetStringFromName("defaultServerTag")
    48            
    49             menuentry += (id?" (" + id + "," + (smtp?smtp:defaultServerTag) + ")":"")
    50             smartReply_dialog.add_row(menuentry);
    51         }
    52     },
     41          if (smartReply_dialog.all_addresses.identityDataCollection[index].id)
     42            id = smartReply_dialog.all_addresses.identityDataCollection[index].id.value;
     43          if (smartReply_dialog.all_addresses.identityDataCollection[index].smtp)
     44            smtp = smartReply_dialog.all_addresses.identityDataCollection[index].smtp.value;
    5345
    54     add_row : function(combinedName) {
    55         var radio = document.createElement("radio");
    56         radio.setAttribute("label",combinedName);
    57         smartReply_dialog.Obj_radioGroup.appendChild(radio);
    58     },
     46          let defaultServerTag = Components.classes["@mozilla.org/intl/stringbundle;1"]
     47            .getService(Components.interfaces.nsIStringBundleService)
     48            .createBundle("chrome://messenger/locale/messenger.properties")
     49            .GetStringFromName("defaultServerTag")
    5950
    60     accept : function() {
    61         /* window.argument[1] stores callback function */
    62         window.arguments[1](smartReply_dialog.all_addresses, smartReply_dialog.Obj_radioGroup.selectedIndex);
    63         document.documentElement.acceptDialog();
    64     }
    65 }
    66 window.addEventListener("load", smartReply_dialog.init, false);
    67 vI.smartReply_dialog = smartReply_dialog;
    68 }});
     51          menuentry += (id ? " (" + id + "," + (smtp ? smtp : defaultServerTag) + ")" : "")
     52          smartReply_dialog.add_row(menuentry);
     53        }
     54      },
     55
     56      add_row: function (combinedName) {
     57        var radio = document.createElement("radio");
     58        radio.setAttribute("label", combinedName);
     59        smartReply_dialog.Obj_radioGroup.appendChild(radio);
     60      },
     61
     62      accept: function () {
     63        /* window.argument[1] stores callback function */
     64        window.arguments[1](smartReply_dialog.all_addresses, smartReply_dialog.Obj_radioGroup.selectedIndex);
     65        document.documentElement.acceptDialog();
     66      }
     67    }
     68    window.addEventListener("load", smartReply_dialog.init, false);
     69    vI.smartReply_dialog = smartReply_dialog;
     70  }
     71});
  • content/vI_statusmenu.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.statusmenu");
    29 
    30 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    31 
    32 var statusmenu = {
    33     stringBundle : Components.classes["@mozilla.org/intl/stringbundle;1"]
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28
     29    let Log = vI.setupLogging("virtualIdentity.statusmenu");
     30
     31    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     32
     33    var statusmenu = {
     34      stringBundle: Components.classes["@mozilla.org/intl/stringbundle;1"]
    3435        .getService(Components.interfaces.nsIStringBundleService)
    3536        .createBundle("chrome://v_identity/locale/v_identity.properties"),
    3637
    37     objStatusMenu : null,
    38     objSaveBaseIDMenuItem : null,
    39     objStorageSaveMenuItem : null,
    40     objStatusMenuSeparator : null,
    41     objSaveSwitch : null,
    42     objSaveBaseIDSwitch : null,
    43     objSaveSMTPSwitch : null,
    44     objFccSwitch : null,
    45     objStatusText : null,
    46     objStatusLogo : null,
    47    
    48     observe: function(self, subject, topic, data) {
    49 //         Log.debug("statusmenu observe " + data);
    50         switch (data) {
    51             case "show_status":
    52                 statusmenu.objStatusMenu.setAttribute("hidden", !vI.vIprefs.get(data));
    53                 statusmenu.objStatusLogo.setAttribute("hidden", !vI.vIprefs.get(data));
    54                 // no break, continue like with doFcc           
    55             case "fcc_show_switch":
    56                 statusmenu.objFccSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
    57                 // no break, continue like with doFcc           
    58             case "doFcc":
    59                 statusmenu.objFccSwitch.setAttribute("checked", vI.vIprefs.get(data));
    60                 break;
    61             case "storage_show_switch":
    62                 statusmenu.objSaveSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
    63                 break;
    64             case "storage_show_baseID_switch":
    65                 statusmenu.objSaveBaseIDSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
    66                 break;
    67             case "storage_show_SMTP_switch":
    68 //                 Log.debug("changed storage_show_SMTP_switch to " + statusmenu.objSaveSMTPMenuItem + "=" + vI.vIprefs.get(data));
    69                 statusmenu.objSaveSMTPSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
    70                 break;
    71             case "storage_store":
    72                 statusmenu.objStorageSaveMenuItem.setAttribute("checked", vI.vIprefs.get(data));
    73                 break;
    74             case "storage_store_base_id":
    75                 statusmenu.objSaveBaseIDMenuItem.setAttribute("checked", vI.vIprefs.get(data));
    76                 break;
    77             case "storage_store_SMTP":
    78 //                 Log.debug("changed storage_store_SMTP to " + statusmenu.objSaveSMTPMenuItem + "=" + vI.vIprefs.get(data));
    79                 statusmenu.objSaveSMTPMenuItem.setAttribute("checked", vI.vIprefs.get(data));
    80 //                 Log.debug("changed storage_store_SMTP done");
    81                 break;
    82             case "storage_colorIndication":
    83                 document.getElementById("identityHbox").setAttribute("colorize", vI.vIprefs.get(data))
    84                 document.getElementById("baseIDHbox").setAttribute("colorize", vI.vIprefs.get(data))
    85                 document.getElementById("smtpServerHbox").setAttribute("colorize", vI.vIprefs.get(data))
    86                 break;
    87             case "storage":
    88                 if (vI.vIprefs.get(data)) {
    89                     statusmenu.objStorageSaveMenuItem.removeAttribute("hidden");
    90                     statusmenu.objSaveBaseIDMenuItem.removeAttribute("hidden");
    91                     statusmenu.objSaveSMTPMenuItem.removeAttribute("hidden");
    92                     statusmenu.objStatusMenuSeparator.removeAttribute("hidden");
    93                 }
    94                 else {
    95                     statusmenu.objStorageSaveMenuItem.setAttribute("hidden", "true");
    96                     statusmenu.objSaveBaseIDMenuItem.setAttribute("hidden", "true");
    97                     statusmenu.objSaveSMTPMenuItem.setAttribute("hidden", "true");
    98                     statusmenu.objStatusMenuSeparator.setAttribute("hidden", "true");
    99                 }
    100                 break;
    101         }
    102         statusmenu.menuConstraint(statusmenu.objStorageSaveMenuItem);
    103     },
    104    
    105     addObserver: function() {
    106         vI.vIprefs.addObserver("show_status", this.observe, this);
     38      objStatusMenu: null,
     39      objSaveBaseIDMenuItem: null,
     40      objStorageSaveMenuItem: null,
     41      objStatusMenuSeparator: null,
     42      objSaveSwitch: null,
     43      objSaveBaseIDSwitch: null,
     44      objSaveSMTPSwitch: null,
     45      objFccSwitch: null,
     46      objStatusText: null,
     47      objStatusLogo: null,
     48
     49      observe: function (self, subject, topic, data) {
     50        //         Log.debug("statusmenu observe " + data);
     51        switch (data) {
     52        case "show_status":
     53          statusmenu.objStatusMenu.setAttribute("hidden", !vI.vIprefs.get(data));
     54          statusmenu.objStatusLogo.setAttribute("hidden", !vI.vIprefs.get(data));
     55          // no break, continue like with doFcc           
     56        case "fcc_show_switch":
     57          statusmenu.objFccSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
     58          // no break, continue like with doFcc         
     59        case "doFcc":
     60          statusmenu.objFccSwitch.setAttribute("checked", vI.vIprefs.get(data));
     61          break;
     62        case "storage_show_switch":
     63          statusmenu.objSaveSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
     64          break;
     65        case "storage_show_baseID_switch":
     66          statusmenu.objSaveBaseIDSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
     67          break;
     68        case "storage_show_SMTP_switch":
     69          //                 Log.debug("changed storage_show_SMTP_switch to " + statusmenu.objSaveSMTPMenuItem + "=" + vI.vIprefs.get(data));
     70          statusmenu.objSaveSMTPSwitch.setAttribute("hidden", !vI.vIprefs.get(data));
     71          break;
     72        case "storage_store":
     73          statusmenu.objStorageSaveMenuItem.setAttribute("checked", vI.vIprefs.get(data));
     74          break;
     75        case "storage_store_base_id":
     76          statusmenu.objSaveBaseIDMenuItem.setAttribute("checked", vI.vIprefs.get(data));
     77          break;
     78        case "storage_store_SMTP":
     79          //                 Log.debug("changed storage_store_SMTP to " + statusmenu.objSaveSMTPMenuItem + "=" + vI.vIprefs.get(data));
     80          statusmenu.objSaveSMTPMenuItem.setAttribute("checked", vI.vIprefs.get(data));
     81          //                 Log.debug("changed storage_store_SMTP done");
     82          break;
     83        case "storage_colorIndication":
     84          document.getElementById("identityHbox").setAttribute("colorize", vI.vIprefs.get(data))
     85          document.getElementById("baseIDHbox").setAttribute("colorize", vI.vIprefs.get(data))
     86          document.getElementById("smtpServerHbox").setAttribute("colorize", vI.vIprefs.get(data))
     87          break;
     88        case "storage":
     89          if (vI.vIprefs.get(data)) {
     90            statusmenu.objStorageSaveMenuItem.removeAttribute("hidden");
     91            statusmenu.objSaveBaseIDMenuItem.removeAttribute("hidden");
     92            statusmenu.objSaveSMTPMenuItem.removeAttribute("hidden");
     93            statusmenu.objStatusMenuSeparator.removeAttribute("hidden");
     94          } else {
     95            statusmenu.objStorageSaveMenuItem.setAttribute("hidden", "true");
     96            statusmenu.objSaveBaseIDMenuItem.setAttribute("hidden", "true");
     97            statusmenu.objSaveSMTPMenuItem.setAttribute("hidden", "true");
     98            statusmenu.objStatusMenuSeparator.setAttribute("hidden", "true");
     99          }
     100          break;
     101        }
     102        statusmenu.menuConstraint(statusmenu.objStorageSaveMenuItem);
     103      },
     104
     105      addObserver: function () {
     106        vI.vIprefs.addObserver("show_status", this.observe, this);
    107107        vI.vIprefs.addObserver("fcc_show_switch", this.observe, this);
    108         vI.vIprefs.addObserver("doFcc", this.observe, this);
    109         vI.vIprefs.addObserver("storage", this.observe, this);
    110         vI.vIprefs.addObserver("storage_show_switch", this.observe, this);
    111         vI.vIprefs.addObserver("storage_show_baseID_switch", this.observe, this);
    112         vI.vIprefs.addObserver("storage_show_SMTP_switch", this.observe, this);
    113         vI.vIprefs.addObserver("storage_colorIndication", this.observe, this);
    114         vI.vIprefs.addObserver("storage_store", this.observe, this);
    115         vI.vIprefs.addObserver("storage_store_base_id", this.observe, this);
    116         vI.vIprefs.addObserver("storage_store_SMTP", this.observe, this);
    117     },
    118    
    119     removeObserver: function() {
     108        vI.vIprefs.addObserver("doFcc", this.observe, this);
     109        vI.vIprefs.addObserver("storage", this.observe, this);
     110        vI.vIprefs.addObserver("storage_show_switch", this.observe, this);
     111        vI.vIprefs.addObserver("storage_show_baseID_switch", this.observe, this);
     112        vI.vIprefs.addObserver("storage_show_SMTP_switch", this.observe, this);
     113        vI.vIprefs.addObserver("storage_colorIndication", this.observe, this);
     114        vI.vIprefs.addObserver("storage_store", this.observe, this);
     115        vI.vIprefs.addObserver("storage_store_base_id", this.observe, this);
     116        vI.vIprefs.addObserver("storage_store_SMTP", this.observe, this);
     117      },
     118
     119      removeObserver: function () {
    120120        vI.vIprefs.removeObserver("show_status", this.observe);
    121         vI.vIprefs.removeObserver("fcc_show_switch", this.observe);
    122         vI.vIprefs.removeObserver("doFcc", this.observe);
    123         vI.vIprefs.removeObserver("storage", this.observe);
    124         vI.vIprefs.removeObserver("storage_show_switch", this.observe);
    125         vI.vIprefs.removeObserver("storage_show_baseID_switch", this.observe);
    126         vI.vIprefs.removeObserver("storage_show_SMTP_switch", this.observe);
    127         vI.vIprefs.removeObserver("storage_colorIndication", this.observe);
    128         vI.vIprefs.removeObserver("storage_store", this.observe);
    129         vI.vIprefs.removeObserver("storage_store_base_id", this.observe);
    130         vI.vIprefs.removeObserver("storage_store_SMTP", this.observe);
    131     },
    132    
    133     init : function () {
    134         statusmenu.objStatusMenu = document.getElementById("virtualIdentityExtension_vIStatusMenu");
     121        vI.vIprefs.removeObserver("fcc_show_switch", this.observe);
     122        vI.vIprefs.removeObserver("doFcc", this.observe);
     123        vI.vIprefs.removeObserver("storage", this.observe);
     124        vI.vIprefs.removeObserver("storage_show_switch", this.observe);
     125        vI.vIprefs.removeObserver("storage_show_baseID_switch", this.observe);
     126        vI.vIprefs.removeObserver("storage_show_SMTP_switch", this.observe);
     127        vI.vIprefs.removeObserver("storage_colorIndication", this.observe);
     128        vI.vIprefs.removeObserver("storage_store", this.observe);
     129        vI.vIprefs.removeObserver("storage_store_base_id", this.observe);
     130        vI.vIprefs.removeObserver("storage_store_SMTP", this.observe);
     131      },
     132
     133      init: function () {
     134        statusmenu.objStatusMenu = document.getElementById("virtualIdentityExtension_vIStatusMenu");
    135135        statusmenu.objStatusLogo = document.getElementById("virtualIdentityExtension_Logo");
    136         statusmenu.objSaveBaseIDMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_saveBaseID");
    137         statusmenu.objSaveSMTPMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_saveSMTP");
    138         statusmenu.objStorageSaveMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_save");
    139         statusmenu.objStatusMenuSeparator = document.getElementById("virtualIdentityExtension_statusMenu_separator");
    140         statusmenu.objSaveSwitch = document.getElementById("virtualIdentityExtension_saveSwitch");
    141         statusmenu.objSaveBaseIDSwitch = document.getElementById("virtualIdentityExtension_saveBaseIDSwitch");
    142         statusmenu.objSaveSMTPSwitch = document.getElementById("virtualIdentityExtension_SaveSmtpSwitch");
    143         statusmenu.objFccSwitch = document.getElementById("virtualIdentityExtension_fccSwitch");
    144         statusmenu.objStatusText = document.getElementById("statusText");
    145         statusmenu.objStatusTooltipLine1 = document.getElementById("virtualIdentityExtension_statusMenuTooltip_StatusValueLine1");
    146         statusmenu.objStatusTooltipLine2 = document.getElementById("virtualIdentityExtension_statusMenuTooltip_StatusValueLine2");
    147 
    148         statusmenu.addObserver();
     136        statusmenu.objSaveBaseIDMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_saveBaseID");
     137        statusmenu.objSaveSMTPMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_saveSMTP");
     138        statusmenu.objStorageSaveMenuItem = document.getElementById("virtualIdentityExtension_statusMenu_storage_save");
     139        statusmenu.objStatusMenuSeparator = document.getElementById("virtualIdentityExtension_statusMenu_separator");
     140        statusmenu.objSaveSwitch = document.getElementById("virtualIdentityExtension_saveSwitch");
     141        statusmenu.objSaveBaseIDSwitch = document.getElementById("virtualIdentityExtension_saveBaseIDSwitch");
     142        statusmenu.objSaveSMTPSwitch = document.getElementById("virtualIdentityExtension_SaveSmtpSwitch");
     143        statusmenu.objFccSwitch = document.getElementById("virtualIdentityExtension_fccSwitch");
     144        statusmenu.objStatusText = document.getElementById("statusText");
     145        statusmenu.objStatusTooltipLine1 = document.getElementById("virtualIdentityExtension_statusMenuTooltip_StatusValueLine1");
     146        statusmenu.objStatusTooltipLine2 = document.getElementById("virtualIdentityExtension_statusMenuTooltip_StatusValueLine2");
     147
     148        statusmenu.addObserver();
    149149        statusmenu.observe(this, null, null, "show_status");
    150         statusmenu.observe(this, null, null, "fcc_show_switch");
    151         statusmenu.observe(this, null, null, "storage_show_switch");
    152         statusmenu.observe(this, null, null, "storage_show_baseID_switch");
    153         statusmenu.observe(this, null, null, "storage_show_SMTP_switch");
    154         statusmenu.observe(this, null, null, "storage_colorIndication");
    155         statusmenu.observe(this, null, null, "storage_store_base_id");
    156         statusmenu.observe(this, null, null, "storage_store_SMTP");
    157         statusmenu.observe(this, null, null, "storage_store");
    158         statusmenu.observe(this, null, null, "storage");
    159     },
    160    
    161     __timeout : 5,  // timeout for status messages in seconds
    162     __addStatusMessage : function(save, smtp) {
     150        statusmenu.observe(this, null, null, "fcc_show_switch");
     151        statusmenu.observe(this, null, null, "storage_show_switch");
     152        statusmenu.observe(this, null, null, "storage_show_baseID_switch");
     153        statusmenu.observe(this, null, null, "storage_show_SMTP_switch");
     154        statusmenu.observe(this, null, null, "storage_colorIndication");
     155        statusmenu.observe(this, null, null, "storage_store_base_id");
     156        statusmenu.observe(this, null, null, "storage_store_SMTP");
     157        statusmenu.observe(this, null, null, "storage_store");
     158        statusmenu.observe(this, null, null, "storage");
     159      },
     160
     161      __timeout: 5, // timeout for status messages in seconds
     162      __addStatusMessage: function (save, smtp) {
    163163        if (vI.vIprefs.get("show_status")) {
    164             var sourceString = "vident.statusText.save." + save;
    165             if (smtp != "off") sourceString = sourceString + ".smtp"
    166             var messageLine1 = statusmenu.stringBundle.GetStringFromName(sourceString + ".line1");
    167             var messageLine2 = statusmenu.stringBundle.GetStringFromName(sourceString + ".line2");
    168             if (!messageLine2) {
    169                 statusmenu.objStatusText.setAttribute("label", messageLine1);
    170                 statusmenu.objStatusTooltipLine1.setAttribute("value", messageLine1);
    171                 statusmenu.objStatusTooltipLine2.setAttribute("hidden", "true");
    172             }   
    173             else {
    174                 statusmenu.objStatusText.setAttribute("label", messageLine1 + " " + messageLine2);
    175                 statusmenu.objStatusTooltipLine1.setAttribute("value", messageLine1);
    176                 statusmenu.objStatusTooltipLine2.setAttribute("value", messageLine2);
    177                 statusmenu.objStatusTooltipLine2.removeAttribute("hidden");
    178             }
    179             window.setTimeout(virtualIdentityExtension.statusmenu.__clearStatusMessage, statusmenu.__timeout * 1000);
     164          var sourceString = "vident.statusText.save." + save;
     165          if (smtp != "off") sourceString = sourceString + ".smtp"
     166          var messageLine1 = statusmenu.stringBundle.GetStringFromName(sourceString + ".line1");
     167          var messageLine2 = statusmenu.stringBundle.GetStringFromName(sourceString + ".line2");
     168          if (!messageLine2) {
     169            statusmenu.objStatusText.setAttribute("label", messageLine1);
     170            statusmenu.objStatusTooltipLine1.setAttribute("value", messageLine1);
     171            statusmenu.objStatusTooltipLine2.setAttribute("hidden", "true");
     172          } else {
     173            statusmenu.objStatusText.setAttribute("label", messageLine1 + " " + messageLine2);
     174            statusmenu.objStatusTooltipLine1.setAttribute("value", messageLine1);
     175            statusmenu.objStatusTooltipLine2.setAttribute("value", messageLine2);
     176            statusmenu.objStatusTooltipLine2.removeAttribute("hidden");
     177          }
     178          window.setTimeout(virtualIdentityExtension.statusmenu.__clearStatusMessage, statusmenu.__timeout * 1000);
    180179        }
    181     },
    182 
    183     __clearStatusMessage : function() {
    184         statusmenu.objStatusText.setAttribute("label", "");
    185     },
    186 
    187     changeSMTPStatus : function (elem) {
    188         statusmenu.objSaveSMTPMenuItem.setAttribute("checked", elem.getAttribute("checked"));
    189         statusmenu.menuConstraint();
    190     },
    191 
    192     changeBaseIDStatus : function (elem) {
    193         statusmenu.objSaveBaseIDMenuItem.setAttribute("checked", elem.getAttribute("checked"));
    194         statusmenu.menuConstraint();
    195     },
    196 
    197     changeSaveStatus : function (elem) {
    198         statusmenu.objStorageSaveMenuItem.setAttribute("checked", elem.getAttribute("checked"));
    199         statusmenu.menuConstraint();
    200     },
    201 
    202     menuConstraint : function () {
    203         var save = "off"; var smtp = "off";
    204         if (statusmenu.objStorageSaveMenuItem.getAttribute("checked") == "true") {
    205             statusmenu.objSaveSMTPMenuItem.removeAttribute("disabled");
    206             statusmenu.objSaveBaseIDMenuItem.removeAttribute("disabled");
    207             if (vI.vIprefs.get("storage")) {
    208                 if (statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true") save = "base";
    209                 else save = "ok";
    210                 if (statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true") smtp = "save";
    211             }
    212         }
    213         else {
    214             statusmenu.objSaveSMTPMenuItem.setAttribute("disabled", "true");
    215             statusmenu.objSaveBaseIDMenuItem.setAttribute("disabled", "true");
    216         }
    217         statusmenu.objStatusMenu.setAttribute("save", save);
    218         statusmenu.objStatusMenu.setAttribute("smtp", smtp);
    219         statusmenu.__addStatusMessage(save, smtp);
    220     },
    221 
    222     clicked : function (button) {
    223         if (button != 0) return; // only react on left mouse button
    224         if (!vI.vIprefs.get("storage")) return;
    225 
    226         var curSaveStatus = vI.vIprefs.get("storage_store")
    227         var curSaveSMTPStatus = vI.vIprefs.get("storage_store_SMTP")
    228         var curSaveBaseIDStatus = vI.vIprefs.get("storage_store_base_id")
    229         var newSaveStatus = ((!curSaveStatus) || (curSaveStatus && !curSaveSMTPStatus) || (curSaveStatus && !curSaveBaseIDStatus))
    230         var newSaveSMTPStatus = ((!curSaveSMTPStatus && curSaveStatus) || (curSaveBaseIDStatus && !curSaveSMTPStatus))
    231         var newSaveBaseIDStatus = ((curSaveSMTPStatus && curSaveStatus && !curSaveBaseIDStatus) || (curSaveBaseIDStatus && !curSaveSMTPStatus))
    232        
    233         vI.vIprefs.set("storage_store", newSaveStatus)
     180      },
     181
     182      __clearStatusMessage: function () {
     183        statusmenu.objStatusText.setAttribute("label", "");
     184      },
     185
     186      changeSMTPStatus: function (elem) {
     187        statusmenu.objSaveSMTPMenuItem.setAttribute("checked", elem.getAttribute("checked"));
     188        statusmenu.menuConstraint();
     189      },
     190
     191      changeBaseIDStatus: function (elem) {
     192        statusmenu.objSaveBaseIDMenuItem.setAttribute("checked", elem.getAttribute("checked"));
     193        statusmenu.menuConstraint();
     194      },
     195
     196      changeSaveStatus: function (elem) {
     197        statusmenu.objStorageSaveMenuItem.setAttribute("checked", elem.getAttribute("checked"));
     198        statusmenu.menuConstraint();
     199      },
     200
     201      menuConstraint: function () {
     202        var save = "off";
     203        var smtp = "off";
     204        if (statusmenu.objStorageSaveMenuItem.getAttribute("checked") == "true") {
     205          statusmenu.objSaveSMTPMenuItem.removeAttribute("disabled");
     206          statusmenu.objSaveBaseIDMenuItem.removeAttribute("disabled");
     207          if (vI.vIprefs.get("storage")) {
     208            if (statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true") save = "base";
     209            else save = "ok";
     210            if (statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true") smtp = "save";
     211          }
     212        } else {
     213          statusmenu.objSaveSMTPMenuItem.setAttribute("disabled", "true");
     214          statusmenu.objSaveBaseIDMenuItem.setAttribute("disabled", "true");
     215        }
     216        statusmenu.objStatusMenu.setAttribute("save", save);
     217        statusmenu.objStatusMenu.setAttribute("smtp", smtp);
     218        statusmenu.__addStatusMessage(save, smtp);
     219      },
     220
     221      clicked: function (button) {
     222        if (button != 0) return; // only react on left mouse button
     223        if (!vI.vIprefs.get("storage")) return;
     224
     225        var curSaveStatus = vI.vIprefs.get("storage_store")
     226        var curSaveSMTPStatus = vI.vIprefs.get("storage_store_SMTP")
     227        var curSaveBaseIDStatus = vI.vIprefs.get("storage_store_base_id")
     228        var newSaveStatus = ((!curSaveStatus) || (curSaveStatus && !curSaveSMTPStatus) || (curSaveStatus && !curSaveBaseIDStatus))
     229        var newSaveSMTPStatus = ((!curSaveSMTPStatus && curSaveStatus) || (curSaveBaseIDStatus && !curSaveSMTPStatus))
     230        var newSaveBaseIDStatus = ((curSaveSMTPStatus && curSaveStatus && !curSaveBaseIDStatus) || (curSaveBaseIDStatus && !curSaveSMTPStatus))
     231
     232        vI.vIprefs.set("storage_store", newSaveStatus)
    234233        vI.vIprefs.set("storage_store_SMTP", newSaveSMTPStatus)
    235234        vI.vIprefs.set("storage_store_base_id", newSaveBaseIDStatus)
    236        
    237         statusmenu.menuConstraint();
    238     }
    239 }
    240 vI.statusmenu = statusmenu;
    241 }});
     235
     236        statusmenu.menuConstraint();
     237      }
     238    }
     239    vI.statusmenu = statusmenu;
     240  }
     241});
  • content/vI_storage.js

    r3c9c29 r509348  
    2222    Contributor(s): Mike Krieger, Sebastian Apel
    2323 * ***** END LICENSE BLOCK ***** */
    24  
     24
    2525/**
    26 * some code copied and adapted from 'addressContext' and from 'Birthday Reminder'
    27 * thanks to Mike Krieger and Sebastian Apel
    28 */
     26 * some code copied and adapted from 'addressContext' and from 'Birthday Reminder'
     27 * thanks to Mike Krieger and Sebastian Apel
     28 */
    2929
    3030Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    31 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
    32 
    33 Components.utils.import("resource://gre/modules/AddonManager.jsm");
    34 let Log = vI.setupLogging("virtualIdentity.storage");
    35 Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
    36 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    37 
    38 var storage = {
    39     focusedElement : null,
    40    
    41     lastCheckedEmail : {},  // array of last checked emails per row,
    42                 // to prevent ugly double dialogs and time-consuming double-checks
    43    
    44     _rdfDatasourceAccess : null,    // local storage
    45 
    46     stringBundle : Components.classes["@mozilla.org/intl/stringbundle;1"]
     31virtualIdentityExtension.ns(function () {
     32  with(virtualIdentityExtension.LIB) {
     33
     34    Components.utils.import("resource://gre/modules/AddonManager.jsm");
     35    let Log = vI.setupLogging("virtualIdentity.storage");
     36    Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
     37    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     38
     39    var storage = {
     40      focusedElement: null,
     41
     42      lastCheckedEmail: {}, // array of last checked emails per row,
     43      // to prevent ugly double dialogs and time-consuming double-checks
     44
     45      _rdfDatasourceAccess: null, // local storage
     46
     47      stringBundle: Components.classes["@mozilla.org/intl/stringbundle;1"]
    4748        .getService(Components.interfaces.nsIStringBundleService)
    4849        .createBundle("chrome://v_identity/locale/v_identity.properties"),
    4950
    50     clean: function() {
    51         Log.debug("clean.");
    52         storage.multipleRecipients = null;
    53         storage.lastCheckedEmail = {};
    54         storage.firstUsedInputElement = null;
    55         awSetInputAndPopupValue = storage.original_functions.awSetInputAndPopupValue;
     51      clean: function () {
     52        Log.debug("clean.");
     53        storage.multipleRecipients = null;
     54        storage.lastCheckedEmail = {};
     55        storage.firstUsedInputElement = null;
     56        awSetInputAndPopupValue = storage.original_functions.awSetInputAndPopupValue;
    5657        if (storage._rdfDatasourceAccess) storage._rdfDatasourceAccess.clean();
    57     },
    58    
    59     original_functions : {
    60         awSetInputAndPopupValue : null
    61     },
    62 
    63     replacement_functions : {
    64         awSetInputAndPopupValue : function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
    65             Log.debug("awSetInputAndPopupValue '" + inputElem.id + "'");
    66             storage.original_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber);
    67             storage.__updateVIdentityFromStorage(inputElem, storage.currentWindow);
    68         }
    69     },
    70        
    71     awOnBlur : function (element, currentWindow) {
    72         // only react on events triggered by addressCol2 - textinput Elements
    73         if (!element || ! element.id.match(/^addressCol2*/)) return;
    74         Log.debug("awOnBlur '" + element.id + "' '" + element.value + "'");
     58      },
     59
     60      original_functions: {
     61        awSetInputAndPopupValue: null
     62      },
     63
     64      replacement_functions: {
     65        awSetInputAndPopupValue: function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
     66          Log.debug("awSetInputAndPopupValue '" + inputElem.id + "'");
     67          storage.original_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber);
     68          storage.__updateVIdentityFromStorage(inputElem, storage.currentWindow);
     69        }
     70      },
     71
     72      awOnBlur: function (element, currentWindow) {
     73        // only react on events triggered by addressCol2 - textinput Elements
     74        if (!element || !element.id.match(/^addressCol2*/)) return;
     75        Log.debug("awOnBlur '" + element.id + "' '" + element.value + "'");
    7576        if (typeof element.value == 'undefined') {
    76             element.value = element.getAttribute("value");
    77             Log.debug("awOnBlur second try'" + element.id + "' '" + element.value + "'");
     77          element.value = element.getAttribute("value");
     78          Log.debug("awOnBlur second try'" + element.id + "' '" + element.value + "'");
    7879        }
    7980        if (element.value == "" || typeof element.value == 'undefined') return;
    8081        storage.__updateVIdentityFromStorage(element, currentWindow);
    81         storage.focusedElement = null;
    82     },
    83 
    84     awOnFocus : function (element, currentWindow) {
    85         if (!element || ! element.id.match(/^addressCol2*/)) return;
    86         storage.focusedElement = element;
    87     },
    88 
    89     awPopupOnCommand : function (element, currentWindow) {
    90         Log.debug("awPopupOnCommand '" + element.id + "' '" + element.value + "'");
    91         storage.__updateVIdentityFromStorage(currentWindow.document.getElementById(element.id.replace(/^addressCol1/,"addressCol2")), currentWindow);
    92         if (element.selectedItem.getAttribute("value") == "addr_reply") // if reply-to is manually entered disable AutoReplyToSelf
    93             currentWindow.document.getElementById("virtualIdentityExtension_autoReplyToSelfLabel").setAttribute("hidden", "true");
    94 
    95     },
    96    
    97   initialized : null,
    98   currentWindow: null,
    99     init: function() {
    100         if (!storage.initialized) {
    101             storage._rdfDatasourceAccess = new vI.rdfDatasourceAccess();
    102 
    103             // better approach would be to use te onchange event, but this one is not fired in any change case
    104             // see https://bugzilla.mozilla.org/show_bug.cgi?id=355367
    105             // same seems to happen with the ondragdrop event
    106             if (!top.MAX_RECIPIENTS || top.MAX_RECIPIENTS == 0) top.MAX_RECIPIENTS = 1;
    107             for (var row = 1; row <= top.MAX_RECIPIENTS ; row ++) {
    108                 var input = window.awGetInputElement(row);
    109                 if (input) {
    110                     var oldBlur = input.getAttribute("onblur")
    111                     input.setAttribute("onblur", (oldBlur?oldBlur+"; ":"") +
    112                         "window.setTimeout(virtualIdentityExtension.storage.awOnBlur, 250, this, window);")
    113                     var oldFocus = input.getAttribute("onfocus")
    114                     input.setAttribute("onfocus", (oldFocus?oldFocus+"; ":"") +
    115                         "window.setTimeout(virtualIdentityExtension.storage.awOnFocus, 250, this, window);")
    116                 }
    117                 var popup = window.awGetPopupElement(row);
    118                 if (popup) {
    119                     var oldCommand = popup.getAttribute("oncommand")
    120                     popup.setAttribute("oncommand", (oldCommand?oldCommand+"; ":"") +
    121                         "window.setTimeout(virtualIdentityExtension.storage.awPopupOnCommand, 250, this, window);")
    122                 }
    123             }
    124             storage.currentWindow = window;
    125             storage.initialized = true;
    126         }
     82        storage.focusedElement = null;
     83      },
     84
     85      awOnFocus: function (element, currentWindow) {
     86        if (!element || !element.id.match(/^addressCol2*/)) return;
     87        storage.focusedElement = element;
     88      },
     89
     90      awPopupOnCommand: function (element, currentWindow) {
     91        Log.debug("awPopupOnCommand '" + element.id + "' '" + element.value + "'");
     92        storage.__updateVIdentityFromStorage(currentWindow.document.getElementById(element.id.replace(/^addressCol1/, "addressCol2")), currentWindow);
     93        if (element.selectedItem.getAttribute("value") == "addr_reply") // if reply-to is manually entered disable AutoReplyToSelf
     94          currentWindow.document.getElementById("virtualIdentityExtension_autoReplyToSelfLabel").setAttribute("hidden", "true");
     95
     96      },
     97
     98      initialized: null,
     99      currentWindow: null,
     100      init: function () {
     101        if (!storage.initialized) {
     102          storage._rdfDatasourceAccess = new vI.rdfDatasourceAccess();
     103
     104          // better approach would be to use te onchange event, but this one is not fired in any change case
     105          // see https://bugzilla.mozilla.org/show_bug.cgi?id=355367
     106          // same seems to happen with the ondragdrop event
     107          if (!top.MAX_RECIPIENTS || top.MAX_RECIPIENTS == 0) top.MAX_RECIPIENTS = 1;
     108          for (var row = 1; row <= top.MAX_RECIPIENTS; row++) {
     109            var input = window.awGetInputElement(row);
     110            if (input) {
     111              var oldBlur = input.getAttribute("onblur")
     112              input.setAttribute("onblur", (oldBlur ? oldBlur + "; " : "") +
     113                "window.setTimeout(virtualIdentityExtension.storage.awOnBlur, 250, this, window);")
     114              var oldFocus = input.getAttribute("onfocus")
     115              input.setAttribute("onfocus", (oldFocus ? oldFocus + "; " : "") +
     116                "window.setTimeout(virtualIdentityExtension.storage.awOnFocus, 250, this, window);")
     117            }
     118            var popup = window.awGetPopupElement(row);
     119            if (popup) {
     120              var oldCommand = popup.getAttribute("oncommand")
     121              popup.setAttribute("oncommand", (oldCommand ? oldCommand + "; " : "") +
     122                "window.setTimeout(virtualIdentityExtension.storage.awPopupOnCommand, 250, this, window);")
     123            }
     124          }
     125          storage.currentWindow = window;
     126          storage.initialized = true;
     127        }
    127128
    128129        if (typeof awSetInputAndPopupValue == 'function' && storage.original_functions.awSetInputAndPopupValue == null) {
    129             storage.original_functions.awSetInputAndPopupValue = awSetInputAndPopupValue;
    130             awSetInputAndPopupValue = function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
    131                 storage.replacement_functions.awSetInputAndPopupValue (inputElem, inputValue, popupElem, popupValue, rowNumber) }
    132         }
    133         // reset unavailable storageExtras preferences
    134         AddonManager.getAddonByID("{847b3a00-7ab1-11d4-8f02-006008948af5}", function(addon) {
     130          storage.original_functions.awSetInputAndPopupValue = awSetInputAndPopupValue;
     131          awSetInputAndPopupValue = function (inputElem, inputValue, popupElem, popupValue, rowNumber) {
     132            storage.replacement_functions.awSetInputAndPopupValue(inputElem, inputValue, popupElem, popupValue, rowNumber)
     133          }
     134        }
     135        // reset unavailable storageExtras preferences
     136        AddonManager.getAddonByID("{847b3a00-7ab1-11d4-8f02-006008948af5}", function (addon) {
    135137          if (addon && !addon.userDisabled && !addon.appDisable) {
    136138            vI.vIprefs.commit("storageExtras_openPGP_messageEncryption", false)
     
    138140            vI.vIprefs.commit("storageExtras_openPGP_PGPMIME", false)
    139141          }
    140         });
    141     },
    142    
    143     firstUsedInputElement : null,   // this stores the first Element for which a Lookup in the Storage was successfull
    144     __updateVIdentityFromStorage: function(inputElement, currentWindow) {
    145         if (!vI.vIprefs.get("storage"))
    146             { Log.debug("Storage deactivated"); return; }
    147         var currentDocument = currentWindow.document;
    148     var recipientType = currentDocument.getElementById(inputElement.id.replace(/^addressCol2/,"addressCol1"))
    149             .selectedItem.getAttribute("value");
    150 
    151     var row = inputElement.id.replace(/^addressCol2#/,"")
    152         if (recipientType == "addr_reply" || recipientType == "addr_followup" || storage.isDoBcc(row, currentWindow)) {
    153             // reset firstUsedInputElement if recipientType was changed (and don't care about doBcc fields)
    154             if (storage.firstUsedInputElement == inputElement)
    155                 storage.firstUsedInputElement = null;
    156             Log.debug("field is a 'reply-to' or 'followup-to' or preconfigured 'doBcc'. not searched.")
    157             return;
    158         }
    159        
    160         if (inputElement.value == "") {
    161             Log.debug("no recipient found, not checked."); return;
    162         }
    163        
    164         var row = inputElement.id.replace(/^addressCol2#/,"")
    165         if (storage.lastCheckedEmail[row] && storage.lastCheckedEmail[row] == inputElement.value) {
    166             Log.debug("same email than before, not checked again."); return;
    167         }
    168         storage.lastCheckedEmail[row] = inputElement.value;
    169        
    170         // firstUsedInputElement was set before and we are not editing the same
    171         var isNotFirstInputElement = (storage.firstUsedInputElement && storage.firstUsedInputElement != inputElement)
    172         var currentIdentity = currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").identityData
    173         var storageResult = storage._rdfDatasourceAccess.updateVIdentityFromStorage(inputElement.value, recipientType,
    174             currentIdentity, currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").vid, isNotFirstInputElement, window);
    175        
    176         if (storageResult.identityCollection.number == 0) return; // return if there was no match
    177         Log.debug("__updateVIdentityFromStorage result: " + storageResult.result);
    178         // found storageData, so store InputElement
    179         if (!storage.firstUsedInputElement) storage.firstUsedInputElement = inputElement;
    180        
    181         var newMenuItem = null;
    182         if (storageResult.result != "equal") {
    183             for (var j = 0; j < storageResult.identityCollection.number; j++) {
    184                 Log.debug("__updateVIdentityFromStorage adding: " + storageResult.identityCollection.identityDataCollection[j].combinedName);
    185                 let menuItem = currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone")
    186                   .addIdentityToCloneMenu(storageResult.identityCollection.identityDataCollection[j])
    187                 if (!newMenuItem) newMenuItem = menuItem;
    188             }
    189         }
    190         if (storageResult.result == "accept") {
    191             Log.debug("__updateVIdentityFromStorage selecting: " + storageResult.identityCollection.identityDataCollection[0].combinedName);
    192             currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").selectedMenuItem = newMenuItem;
    193             if (currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").vid)
    194                 vI.StorageNotification.info(storage.stringBundle.GetStringFromName("vident.smartIdentity.vIStorageUsage") + ".");
    195         }
    196     },
    197    
    198     isDoBcc : function(row, currentWindow) {
    199         var recipientType = currentWindow.awGetPopupElement(row).selectedItem.getAttribute("value");
    200         if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false
    201 
    202         var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {});
     142        });
     143      },
     144
     145      firstUsedInputElement: null, // this stores the first Element for which a Lookup in the Storage was successfull
     146      __updateVIdentityFromStorage: function (inputElement, currentWindow) {
     147        if (!vI.vIprefs.get("storage")) {
     148          Log.debug("Storage deactivated");
     149          return;
     150        }
     151        var currentDocument = currentWindow.document;
     152        var recipientType = currentDocument.getElementById(inputElement.id.replace(/^addressCol2/, "addressCol1"))
     153          .selectedItem.getAttribute("value");
     154
     155        var row = inputElement.id.replace(/^addressCol2#/, "")
     156        if (recipientType == "addr_reply" || recipientType == "addr_followup" || storage.isDoBcc(row, currentWindow)) {
     157          // reset firstUsedInputElement if recipientType was changed (and don't care about doBcc fields)
     158          if (storage.firstUsedInputElement == inputElement)
     159            storage.firstUsedInputElement = null;
     160          Log.debug("field is a 'reply-to' or 'followup-to' or preconfigured 'doBcc'. not searched.")
     161          return;
     162        }
     163
     164        if (inputElement.value == "") {
     165          Log.debug("no recipient found, not checked.");
     166          return;
     167        }
     168
     169        var row = inputElement.id.replace(/^addressCol2#/, "")
     170        if (storage.lastCheckedEmail[row] && storage.lastCheckedEmail[row] == inputElement.value) {
     171          Log.debug("same email than before, not checked again.");
     172          return;
     173        }
     174        storage.lastCheckedEmail[row] = inputElement.value;
     175
     176        // firstUsedInputElement was set before and we are not editing the same
     177        var isNotFirstInputElement = (storage.firstUsedInputElement && storage.firstUsedInputElement != inputElement)
     178        var currentIdentity = currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").identityData
     179        var storageResult = storage._rdfDatasourceAccess.updateVIdentityFromStorage(inputElement.value, recipientType,
     180          currentIdentity, currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").vid, isNotFirstInputElement, window);
     181
     182        if (storageResult.identityCollection.number == 0) return; // return if there was no match
     183        Log.debug("__updateVIdentityFromStorage result: " + storageResult.result);
     184        // found storageData, so store InputElement
     185        if (!storage.firstUsedInputElement) storage.firstUsedInputElement = inputElement;
     186
     187        var newMenuItem = null;
     188        if (storageResult.result != "equal") {
     189          for (var j = 0; j < storageResult.identityCollection.number; j++) {
     190            Log.debug("__updateVIdentityFromStorage adding: " + storageResult.identityCollection.identityDataCollection[j].combinedName);
     191            let menuItem = currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone")
     192              .addIdentityToCloneMenu(storageResult.identityCollection.identityDataCollection[j])
     193            if (!newMenuItem) newMenuItem = menuItem;
     194          }
     195        }
     196        if (storageResult.result == "accept") {
     197          Log.debug("__updateVIdentityFromStorage selecting: " + storageResult.identityCollection.identityDataCollection[0].combinedName);
     198          currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").selectedMenuItem = newMenuItem;
     199          if (currentDocument.getElementById("virtualIdentityExtension_msgIdentityClone").vid)
     200            vI.StorageNotification.info(storage.stringBundle.GetStringFromName("vident.smartIdentity.vIStorageUsage") + ".");
     201        }
     202      },
     203
     204      isDoBcc: function (row, currentWindow) {
     205        var recipientType = currentWindow.awGetPopupElement(row).selectedItem.getAttribute("value");
     206        if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false
     207
     208        var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {});
    203209        if (doBccArray && doBccArray.count) {
    204             for (var index = 0; index < doBccArray.count; index++ ) {
    205                 if (doBccArray.StringAt(index) == currentWindow.awGetInputElement(row).value) {
    206                     Log.debug("ignoring doBcc field '" +
    207                         doBccArray.StringAt(index));
    208                     return true;
    209                 }
     210          for (var index = 0; index < doBccArray.count; index++) {
     211            if (doBccArray.StringAt(index) == currentWindow.awGetInputElement(row).value) {
     212              Log.debug("ignoring doBcc field '" +
     213                doBccArray.StringAt(index));
     214              return true;
    210215            }
    211         }
    212         return false
    213     }
    214 }
    215 vI.storage = storage;
    216 }});
     216          }
     217        }
     218        return false
     219      }
     220    }
     221    vI.storage = storage;
     222  }
     223});
  • content/vI_upgrade.js

    r3c9c29 r509348  
    2424
    2525Components.utils.import("resource://v_identity/vI_nameSpaceWrapper.js");
    26 virtualIdentityExtension.ns(function() { with (virtualIdentityExtension.LIB) {
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
    2728
    28 let Log = vI.setupLogging("virtualIdentity.upgrade");
    29 Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
    30 Components.utils.import("resource://v_identity/vI_account.js", virtualIdentityExtension);
    31 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     29    let Log = vI.setupLogging("virtualIdentity.upgrade");
     30    Components.utils.import("resource://v_identity/vI_rdfDatasource.js", virtualIdentityExtension);
     31    Components.utils.import("resource://v_identity/vI_account.js", virtualIdentityExtension);
     32    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    3233
    33 var upgrade = {
    34     versionChecker : Components.classes["@mozilla.org/xpcom/version-comparator;1"]
    35       .getService(Components.interfaces.nsIVersionComparator),
    36                            
    37     rdfDatasource : null,
     34    var upgrade = {
     35      versionChecker: Components.classes["@mozilla.org/xpcom/version-comparator;1"]
     36        .getService(Components.interfaces.nsIVersionComparator),
    3837
    39     quickUpgrade : function(currentVersion) {
    40       upgrade.rdfDatasource = new vI.rdfDatasource("virtualIdentity.rdf", true);
    41       if (upgrade.rdfDatasource.extUpgradeRequired())
    42         upgrade.extUpgrade();
    43       upgrade.rdfDatasource.refreshAccountInfo();
    44       upgrade.rdfDatasource.clean();
    45       return true;
    46     },
     38      rdfDatasource: null,
    4739
    48     extUpgrade : function() {
    49         var currentVersion = upgrade.rdfDatasource.getCurrentExtFileVersion();
    50         Log.debug("checking for previous version, found " +
    51             currentVersion + "... extension-upgrade required.")
    52         switch (currentVersion) {
    53             case null:
    54                 // no break
    55             default:
    56                 upgrade.__transferMovedUserPrefs(currentVersion);
    57                 upgrade.__removeObsoleteUserPrefs(currentVersion);
    58                 upgrade.__removeExtraAddedHeaders(currentVersion);
    59                 upgrade.__cleanupSmartMailboxFolders(currentVersion);
    60         }
    61         upgrade.rdfDatasource.storeExtVersion();
    62         Log.debug("extension-upgrade to " + upgrade.rdfDatasource.getCurrentExtFileVersion() + " done.");
    63     },
    64    
    65     __cleanupSmartMailboxFolders : function(currentVersion) {
     40      quickUpgrade: function (currentVersion) {
     41        upgrade.rdfDatasource = new vI.rdfDatasource("virtualIdentity.rdf", true);
     42        if (upgrade.rdfDatasource.extUpgradeRequired())
     43          upgrade.extUpgrade();
     44        upgrade.rdfDatasource.refreshAccountInfo();
     45        upgrade.rdfDatasource.clean();
     46        return true;
     47      },
     48
     49      extUpgrade: function () {
     50        var currentVersion = upgrade.rdfDatasource.getCurrentExtFileVersion();
     51        Log.debug("checking for previous version, found " +
     52          currentVersion + "... extension-upgrade required.")
     53        switch (currentVersion) {
     54        case null:
     55          // no break
     56        default:
     57          upgrade.__transferMovedUserPrefs(currentVersion);
     58          upgrade.__removeObsoleteUserPrefs(currentVersion);
     59          upgrade.__removeExtraAddedHeaders(currentVersion);
     60          upgrade.__cleanupSmartMailboxFolders(currentVersion);
     61        }
     62        upgrade.rdfDatasource.storeExtVersion();
     63        Log.debug("extension-upgrade to " + upgrade.rdfDatasource.getCurrentExtFileVersion() + " done.");
     64      },
     65
     66      __cleanupSmartMailboxFolders: function (currentVersion) {
    6667        if ((!currentVersion || upgrade.versionChecker.compare(currentVersion, "0.9.26") < 0)) {
    67             Log.debug("cleaning leftover 'smart mailboxes' == 'unified folder mailboxes'");
    68             // remove obsolete 'smart mailboxes'=='unified folder' server entries
    69             // this is only required because of a virtualIdentity bug introduced in 0.9.22 and fixed in 0.9.26
     68          Log.debug("cleaning leftover 'smart mailboxes' == 'unified folder mailboxes'");
     69          // remove obsolete 'smart mailboxes'=='unified folder' server entries
     70          // this is only required because of a virtualIdentity bug introduced in 0.9.22 and fixed in 0.9.26
    7071
    71             //  compare against all accounts, getAccountsArray() does not include 'smart mailboxes' == 'unified folders'
    72             var all_accounts = vI.prefroot.getCharPref("mail.accountmanager.accounts").split(",");
     72          //  compare against all accounts, getAccountsArray() does not include 'smart mailboxes' == 'unified folders'
     73          var all_accounts = vI.prefroot.getCharPref("mail.accountmanager.accounts").split(",");
    7374
    74             for each (let pref in vI.prefroot.getChildList("mail.server")) {
    75                 if (pref.indexOf(".hostname") == pref.length - 9 && vI.prefroot.getCharPref(pref) == "smart mailboxes") {
    76                     // ok, smart mailbox server found, check if it still in use
    77                     let server = pref.replace(/^mail\.server\./,"").replace(/\.hostname$/,"");
    78                     let inUse = false;
    79                     for each (let account in all_accounts) {
    80                         if (vI.prefroot.getCharPref("mail.account." + account + ".server") == server)
    81                             inUse = true;
    82                     }
    83                     if (!inUse) {
    84                         Log.debug("cleaning leftover 'smart mailbox' for server " + server);
    85                         for each (let obsoletePref in vI.prefroot.getChildList("mail.server." + server)) {
    86                             if (obsoletePref.indexOf(".directory") == obsoletePref.length - 10) {
    87                                 // remove obsolete 'smart mailbox' directory
    88                                 try {
    89                                     let file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
    90                                     file.initWithPath(vI.prefroot.getCharPref(obsoletePref));
    91                                     Log.debug("removing obsolete storage Folder " + vI.prefroot.getCharPref(obsoletePref));
    92                                     file.remove(true);
    93                                 } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) { };
    94                             }
    95                             vI.prefroot.clearUserPref(obsoletePref);
    96                         }
    97                     }
     75          for each(let pref in vI.prefroot.getChildList("mail.server")) {
     76            if (pref.indexOf(".hostname") == pref.length - 9 && vI.prefroot.getCharPref(pref) == "smart mailboxes") {
     77              // ok, smart mailbox server found, check if it still in use
     78              let server = pref.replace(/^mail\.server\./, "").replace(/\.hostname$/, "");
     79              let inUse = false;
     80              for each(let account in all_accounts) {
     81                if (vI.prefroot.getCharPref("mail.account." + account + ".server") == server)
     82                  inUse = true;
     83              }
     84              if (!inUse) {
     85                Log.debug("cleaning leftover 'smart mailbox' for server " + server);
     86                for each(let obsoletePref in vI.prefroot.getChildList("mail.server." + server)) {
     87                  if (obsoletePref.indexOf(".directory") == obsoletePref.length - 10) {
     88                    // remove obsolete 'smart mailbox' directory
     89                    try {
     90                      let file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
     91                      file.initWithPath(vI.prefroot.getCharPref(obsoletePref));
     92                      Log.debug("removing obsolete storage Folder " + vI.prefroot.getCharPref(obsoletePref));
     93                      file.remove(true);
     94                    } catch (NS_ERROR_FILE_UNRECOGNIZED_PATH) {};
     95                  }
     96                  vI.prefroot.clearUserPref(obsoletePref);
    9897                }
     98              }
    9999            }
     100          }
    100101        }
    101     },
    102    
    103     __removeExtraAddedHeaders : function(currentVersion) {
    104         if ((!currentVersion || upgrade.versionChecker.compare(currentVersion, "0.6.9") < 0) && 
    105                 vI.prefroot.getCharPref("mailnews.headers.extraExpandedHeaders") != "") {
    106             // clean extraExpandedHeaders once, because the whole header-saving and restoring was broken too long
    107             Log.debug("cleaning extraExpandedHeaders");
    108             vI.prefroot.setCharPref("mailnews.headers.extraExpandedHeaders", "")
    109             Log.debug("cleaned extraExpandedHeaders");
     102      },
     103
     104      __removeExtraAddedHeaders: function (currentVersion) {
     105        if ((!currentVersion || upgrade.versionChecker.compare(currentVersion, "0.6.9") < 0) &&
     106          vI.prefroot.getCharPref("mailnews.headers.extraExpandedHeaders") != "") {
     107          // clean extraExpandedHeaders once, because the whole header-saving and restoring was broken too long
     108          Log.debug("cleaning extraExpandedHeaders");
     109          vI.prefroot.setCharPref("mailnews.headers.extraExpandedHeaders", "")
     110          Log.debug("cleaned extraExpandedHeaders");
    110111        }
    111     },
    112    
    113     __transferMovedUserPrefs : function(currentVersion) {
    114         // transfer renamed preferences
    115         var transferPrefs = [   { version : "0.5.3",
    116                     prefs : Array({ sourcePref : "smart_reply_ask", targetPref : "idSelection_ask" },
    117                         { sourcePref : "smart_reply_ask_always", targetPref : "idSelection_ask_always" },
    118                         { sourcePref : "smart_reply_autocreate", targetPref : "idSelection_autocreate" },
    119                         { sourcePref : "smart_timestamp", targetPref : "autoTimestamp" },
    120                         { sourcePref : "storage_prefer_smart_reply", targetPref : "idSelection_storage_prefer_smart_reply" },
    121                         { sourcePref : "storage_ignore_smart_reply", targetPref : "idSelection_storage_ignore_smart_reply" }) }];
    122         // remove obsolete preference-tree virtualIdentity
    123         for (var i = 0; i < transferPrefs.length; i++) {
    124             // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
    125             if (!currentVersion || (upgrade.versionChecker.compare(currentVersion, transferPrefs[i].version) < 0)) {
    126                 // remove any obsolete preferences under extensions.virtualIdentity
    127                 Log.debug("transfer changed preferences of pre-" + transferPrefs[i].version + " release...")
    128                 for each (let transferPref in transferPrefs[i].prefs) {
    129                     try {   vI.vIprefs.commit(transferPref.targetPref,
    130                             vI.vIprefs.get(transferPref.sourcePref));
    131                         vI.vIprefs.clearUserPref(transferPref.sourcePref);
    132                     }
    133                     catch (e) { };
    134                 }
    135                 Log.debug("done.")
    136             }
    137         }
    138     },
    139    
    140     __removeObsoleteUserPrefs : function(currentVersion) {
    141         var obsoletePrefs = [   { version : "0.5.0",
    142                     prefs : Array("aBook_use", "aBook_storedefault", "aBook_dont_update_multiple",
    143                     "aBook_show_switch", "aBook_warn_update", "aBook_use_for_smart_reply",
    144                     "aBook_prefer_smart_reply", "aBook_ignore_smart_reply", "aBook_warn_vI_replace",
    145                     "aBook_use_non_vI", "aBook_notification", "storeVIdentity", "experimental",
    146                     "storage_use_for_smart_reply") },
    147                     { version : "0.5.3", prefs : Array("storage_use_for_smart_reply") },
    148                     { version : "0.5.6", prefs : Array("copyEnigmailSettings") },
    149                     { version: "0.9", prefs : Array("extensions.virtualIdentity.{2ab1b709-ba03-4361-abf9-c50b964ff75d}",
    150                                                     "extensions.virtualIdentity.{847b3a00-7ab1-11d4-8f02-006008948af5}",
    151                                                     "extensions.virtualIdentity.smart_reply_added_extraHeaders",
    152                                                     "mailnews.headers.extraExpandedHeaders") }
    153                     ];
    154         // remove obsolete preference-tree virtualIdentity
    155         for (var i = 0; i < obsoletePrefs.length; i++) {
    156             // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
    157             if (!currentVersion || (upgrade.versionChecker.compare(currentVersion, obsoletePrefs[i].version) < 0)) {
    158                 // remove any obsolete preferences under extensions.virtualIdentity
    159                 Log.debug("removing obsolete preferences of pre-" + obsoletePrefs[i].version + " release...")
    160                 for each (let pref in obsoletePrefs[i].prefs) {
    161                     try { vI.vIprefs.clearUserPref(pref); Log.debug(".") }
    162                     catch (e) { };
    163                 }
    164                 Log.debug("done.")
    165             }
    166         }
    167     },
    168 }
    169 vI.upgrade = upgrade;
    170 }});
     112      },
     113
     114      __transferMovedUserPrefs: function (currentVersion) {
     115        // transfer renamed preferences
     116        var transferPrefs = [{
     117          version: "0.5.3",
     118          prefs: Array({
     119            sourcePref: "smart_reply_ask",
     120            targetPref: "idSelection_ask"
     121          }, {
     122            sourcePref: "smart_reply_ask_always",
     123            targetPref: "idSelection_ask_always"
     124          }, {
     125            sourcePref: "smart_reply_autocreate",
     126            targetPref: "idSelection_autocreate"
     127          }, {
     128            sourcePref: "smart_timestamp",
     129            targetPref: "autoTimestamp"
     130          }, {
     131            sourcePref: "storage_prefer_smart_reply",
     132            targetPref: "idSelection_storage_prefer_smart_reply"
     133          }, {
     134            sourcePref: "storage_ignore_smart_reply",
     135            targetPref: "idSelection_storage_ignore_smart_reply"
     136          })
     137        }];
     138        // remove obsolete preference-tree virtualIdentity
     139        for (var i = 0; i < transferPrefs.length; i++) {
     140          // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
     141          if (!currentVersion || (upgrade.versionChecker.compare(currentVersion, transferPrefs[i].version) < 0)) {
     142            // remove any obsolete preferences under extensions.virtualIdentity
     143            Log.debug("transfer changed preferences of pre-" + transferPrefs[i].version + " release...")
     144            for each(let transferPref in transferPrefs[i].prefs) {
     145              try {
     146                vI.vIprefs.commit(transferPref.targetPref,
     147                  vI.vIprefs.get(transferPref.sourcePref));
     148                vI.vIprefs.clearUserPref(transferPref.sourcePref);
     149              } catch (e) {};
     150            }
     151            Log.debug("done.")
     152          }
     153        }
     154      },
     155
     156      __removeObsoleteUserPrefs: function (currentVersion) {
     157        var obsoletePrefs = [{
     158          version: "0.5.0",
     159          prefs: Array("aBook_use", "aBook_storedefault", "aBook_dont_update_multiple",
     160            "aBook_show_switch", "aBook_warn_update", "aBook_use_for_smart_reply",
     161            "aBook_prefer_smart_reply", "aBook_ignore_smart_reply", "aBook_warn_vI_replace",
     162            "aBook_use_non_vI", "aBook_notification", "storeVIdentity", "experimental",
     163            "storage_use_for_smart_reply")
     164        }, {
     165          version: "0.5.3",
     166          prefs: Array("storage_use_for_smart_reply")
     167        }, {
     168          version: "0.5.6",
     169          prefs: Array("copyEnigmailSettings")
     170        }, {
     171          version: "0.9",
     172          prefs: Array("extensions.virtualIdentity.{2ab1b709-ba03-4361-abf9-c50b964ff75d}",
     173            "extensions.virtualIdentity.{847b3a00-7ab1-11d4-8f02-006008948af5}",
     174            "extensions.virtualIdentity.smart_reply_added_extraHeaders",
     175            "mailnews.headers.extraExpandedHeaders")
     176        }];
     177        // remove obsolete preference-tree virtualIdentity
     178        for (var i = 0; i < obsoletePrefs.length; i++) {
     179          // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
     180          if (!currentVersion || (upgrade.versionChecker.compare(currentVersion, obsoletePrefs[i].version) < 0)) {
     181            // remove any obsolete preferences under extensions.virtualIdentity
     182            Log.debug("removing obsolete preferences of pre-" + obsoletePrefs[i].version + " release...")
     183            for each(let pref in obsoletePrefs[i].prefs) {
     184              try {
     185                vI.vIprefs.clearUserPref(pref);
     186                Log.debug(".")
     187              } catch (e) {};
     188            }
     189            Log.debug("done.")
     190          }
     191        }
     192      },
     193    }
     194    vI.upgrade = upgrade;
     195  }
     196});
  • content/v_identity.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.main");
    29 Components.utils.import("resource://v_identity/vI_account.js", virtualIdentityExtension);
    30 Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
    31 Components.utils.import("resource://v_identity/vI_replyToSelf.js", virtualIdentityExtension);
    32 Components.utils.import("resource://v_identity/vI_accountUtils.js", virtualIdentityExtension);
    33 Components.utils.import("resource://v_identity/plugins/signatureSwitch.js", virtualIdentityExtension);
    34 
    35 var main = {
    36     headerParser : Components.classes["@mozilla.org/messenger/headerparser;1"]
    37                 .getService(Components.interfaces.nsIMsgHeaderParser),
    38    
    39     unicodeConverter : Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
    40                 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
    41                            
    42     accountManager : Components.classes["@mozilla.org/messenger/account-manager;1"]
    43             .getService(Components.interfaces.nsIMsgAccountManager),
    44        
    45 
    46     gMsgCompose : null, // to store the global gMsgCompose after MsgComposeDialog is closed
    47 
    48     // Those variables keep pointers to original functions which might get replaced later
    49     original_functions : {
    50         GenericSendMessage : null,
    51         FillIdentityList : null
    52     },
    53 
    54     // some pointers to the layout-elements of the extension
    55     elements : {
    56         init_base : function() {
    57             main.elements.Area_MsgIdentityHbox = document.getElementById("virtualIdentityExtension_msgIdentityHbox");
    58             main.elements.Obj_MsgIdentity = document.getElementById("msgIdentity");
    59         },
    60         init_rest : function() {
    61             main.elements.Obj_MsgIdentityPopup = document.getElementById("msgIdentityPopup");
    62             main.elements.Obj_vILogo = document.getElementById("virtualIdentityExtension_Logo");
    63         },
    64         strings : null
    65     },
    66 
    67     ComposeStateListener : {
    68         NotifyComposeBodyReady: function() {
    69             Log.debug("NotifyComposeBodyReady");
    70             main.initSystemStage2();
    71         },
    72         NotifyComposeFieldsReady: function() {
    73             Log.debug("NotifyComposeFieldsReady");
    74         },
    75         ComposeProcessDone: function(aResult) {
    76             Log.debug("StateListener reports ComposeProcessDone");
    77             vI.vIaccount_removeUsedVIAccount();
    78             main.Cleanup(); // not really required, parallel handled by main.close
    79             vI.storage.clean();
    80         },
    81         SaveInFolderDone: function(folderURI) {
    82             Log.debug("SaveInFolderDone");
    83             vI.vIaccount_removeUsedVIAccount();
    84             main.Cleanup();
    85             vI.storage.clean();
    86         }
    87     },
    88    
    89     replacement_functions : {
    90         FillIdentityList: function(menulist) {
    91             Log.debug("mod. FillIdentityList");
    92             var accounts = virtualIdentityExtension.getAccountsArray();
    93             for (let acc = 0; acc < accounts.length; acc++) {
    94                 let server = accounts[acc].incomingServer;
    95                 if (!server)
    96                     continue;
    97                
    98                 // check for VirtualIdentity Account
    99                 try {   vI.prefroot.getBoolPref("mail.account." + accounts[acc].key + ".vIdentity"); continue; } catch (e) { };
    100                 let account = accounts[acc];
    101                 let identities = virtualIdentityExtension.getIdentitiesArray(account);
    102 
    103                 if (identities.length == 0)
    104                     continue;
    105 
    106                 for (let i = 0; i < identities.length; i++) {
    107                     let identity = identities[i];
    108                     let item = menulist.appendItem(identity.identityName, identity.key,
    109                                                     account.incomingServer.prettyName);
    110                     item.setAttribute("accountkey", account.key);
    111                     if (i == 0) {
    112                         // Mark the first identity as default.
    113                         item.setAttribute("default", "true");
    114                     }
    115                 }
     26virtualIdentityExtension.ns(function () {
     27  with(virtualIdentityExtension.LIB) {
     28
     29    let Log = vI.setupLogging("virtualIdentity.main");
     30    Components.utils.import("resource://v_identity/vI_account.js", virtualIdentityExtension);
     31    Components.utils.import("resource://v_identity/vI_prefs.js", virtualIdentityExtension);
     32    Components.utils.import("resource://v_identity/vI_replyToSelf.js", virtualIdentityExtension);
     33    Components.utils.import("resource://v_identity/vI_accountUtils.js", virtualIdentityExtension);
     34    Components.utils.import("resource://v_identity/plugins/signatureSwitch.js", virtualIdentityExtension);
     35
     36    var main = {
     37      headerParser: Components.classes["@mozilla.org/messenger/headerparser;1"]
     38        .getService(Components.interfaces.nsIMsgHeaderParser),
     39
     40      unicodeConverter: Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
     41        .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
     42
     43      accountManager: Components.classes["@mozilla.org/messenger/account-manager;1"]
     44        .getService(Components.interfaces.nsIMsgAccountManager),
     45
     46
     47      gMsgCompose: null, // to store the global gMsgCompose after MsgComposeDialog is closed
     48
     49      // Those variables keep pointers to original functions which might get replaced later
     50      original_functions: {
     51        GenericSendMessage: null,
     52        FillIdentityList: null
     53      },
     54
     55      // some pointers to the layout-elements of the extension
     56      elements: {
     57        init_base: function () {
     58          main.elements.Area_MsgIdentityHbox = document.getElementById("virtualIdentityExtension_msgIdentityHbox");
     59          main.elements.Obj_MsgIdentity = document.getElementById("msgIdentity");
     60        },
     61        init_rest: function () {
     62          main.elements.Obj_MsgIdentityPopup = document.getElementById("msgIdentityPopup");
     63          main.elements.Obj_vILogo = document.getElementById("virtualIdentityExtension_Logo");
     64        },
     65        strings: null
     66      },
     67
     68      ComposeStateListener: {
     69        NotifyComposeBodyReady: function () {
     70          Log.debug("NotifyComposeBodyReady");
     71          main.initSystemStage2();
     72        },
     73        NotifyComposeFieldsReady: function () {
     74          Log.debug("NotifyComposeFieldsReady");
     75        },
     76        ComposeProcessDone: function (aResult) {
     77          Log.debug("StateListener reports ComposeProcessDone");
     78          vI.vIaccount_removeUsedVIAccount();
     79          main.Cleanup(); // not really required, parallel handled by main.close
     80          vI.storage.clean();
     81        },
     82        SaveInFolderDone: function (folderURI) {
     83          Log.debug("SaveInFolderDone");
     84          vI.vIaccount_removeUsedVIAccount();
     85          main.Cleanup();
     86          vI.storage.clean();
     87        }
     88      },
     89
     90      replacement_functions: {
     91        FillIdentityList: function (menulist) {
     92          Log.debug("mod. FillIdentityList");
     93          var accounts = virtualIdentityExtension.getAccountsArray();
     94          for (let acc = 0; acc < accounts.length; acc++) {
     95            let server = accounts[acc].incomingServer;
     96            if (!server)
     97              continue;
     98
     99            // check for VirtualIdentity Account
     100            try {
     101              vI.prefroot.getBoolPref("mail.account." + accounts[acc].key + ".vIdentity");
     102              continue;
     103            } catch (e) {};
     104            let account = accounts[acc];
     105            let identities = virtualIdentityExtension.getIdentitiesArray(account);
     106
     107            if (identities.length == 0)
     108              continue;
     109
     110            for (let i = 0; i < identities.length; i++) {
     111              let identity = identities[i];
     112              let item = menulist.appendItem(identity.identityName, identity.key,
     113                account.incomingServer.prettyName);
     114              item.setAttribute("accountkey", account.key);
     115              if (i == 0) {
     116                // Mark the first identity as default.
     117                item.setAttribute("default", "true");
     118              }
    116119            }
    117         },
    118        
    119         GenericSendMessageInProgress : false,
    120         GenericSendMessage: function (msgType) {
    121             if (main.replacement_functions.GenericSendMessageInProgress) return;
    122             main.replacement_functions.GenericSendMessageInProgress = true;
    123            
    124             // if addressCol2 is focused while sending check storage for the entered address before continuing
    125             vI.storage.awOnBlur(vI.storage.focusedElement, window);
    126 
    127             Log.debug("VIdentity_GenericSendMessage");
    128            
    129             Log.debug("VIdentity_GenericSendMessage top=" + top);
    130            
    131             if (msgType == Components.interfaces.nsIMsgCompDeliverMode.Now)
    132               vI.addReplyToSelf(window);
    133 
    134             var vid = document.getElementById("virtualIdentityExtension_msgIdentityClone").vid
    135             var virtualIdentityData = document.getElementById("virtualIdentityExtension_msgIdentityClone").identityData;
    136            
    137             let returnValue = vI.vIaccount_prepareSendMsg(vid, msgType, virtualIdentityData,
    138                             main.accountManager.getIdentity(main.elements.Obj_MsgIdentity.value),
    139                             main._getRecipients(), window );
    140             if (returnValue.update == "abort") {
    141                 main.replacement_functions.GenericSendMessageInProgress = false;
    142                 Log.debug("sending: --------------  aborted  ---------------------------------")
    143                 return;
    144             }
    145             else if (returnValue.update == "takeover") {
    146                     var msgIdentityCloneElem = document.getElementById("virtualIdentityExtension_msgIdentityClone");
    147                     msgIdentityCloneElem.selectedMenuItem = msgIdentityCloneElem.addIdentityToCloneMenu(returnValue.storedIdentity);
    148                     main.replacement_functions.GenericSendMessageInProgress = false;
    149                     Log.debug("sending: --------------  aborted  ---------------------------------")
    150                     return;
    151             }
    152            
    153             if (vid) main.addVirtualIdentityToMsgIdentityMenu();
    154            
    155             // final check if eyerything is nice before we handover to the real sending...
    156             if (vI.vIaccount_finalCheck(virtualIdentityData, getCurrentIdentity())) {
    157                 main.replacement_functions.GenericSendMessageInProgress = false;
    158                 main.original_functions.GenericSendMessage(msgType);
    159             }
    160             else    main.Cleanup();
    161             main.replacement_functions.GenericSendMessageInProgress = false;
    162             //          Log.debug("original_functions.GenericSendMessage done");
    163         },
    164        
    165         replace_FillIdentityList : function() {
    166             //~ Log.debug("replace FillIdentityList");
    167             main.original_functions.FillIdentityList = FillIdentityList;
    168             FillIdentityList = main.replacement_functions.FillIdentityList;
    169         }
    170     },
    171 
    172     remove: function() {
    173         window.removeEventListener('compose-window-reopen', main.reopen, true);
    174         window.removeEventListener('compose-window-close', main.close, true);
    175         Log.debug("end. remove Account if there.")
    176         main.Cleanup();
    177         vI.storage.clean();
    178     },
    179 
    180     _getRecipients : function() {
    181         var recipients = [];
    182         for (var row = 1; row <= top.MAX_RECIPIENTS; row ++) {
    183             var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
    184             if (recipientType == "addr_reply" || recipientType == "addr_followup" ||
    185                 main._recipientIsDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/) ) continue;
    186             recipients.push( { recipient: awGetInputElement(row).value, recipientType : recipientType } );
    187         }
    188         return recipients;
    189     },
    190    
    191     _recipientIsDoBcc : function(row) {
    192         var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
    193         if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false
    194 
    195         var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {});
    196 
    197         for (var index = 0; index < doBccArray.count; index++ ) {
    198             if (doBccArray.StringAt(index) == awGetInputElement(row).value) {
    199                 Log.debug("_recipientIsDoBcc: ignoring doBcc field '" +
    200                     doBccArray.StringAt(index));
    201                 return true;
    202             }
    203         }       
    204         return false
    205     },
    206 
    207     // initialization //
    208     init: function() {
    209         window.removeEventListener('load', main.init, false);
    210         window.removeEventListener('compose-window-init', main.init, true);
    211         if (main.elements.Area_MsgIdentityHbox) return; // init done before, (?reopen)
    212         Log.debug("init.")
    213         main.unicodeConverter.charset="UTF-8";
    214         if (!main.adapt_genericSendMessage()) { Log.error("init failed."); return; }
    215        
    216         main.adapt_interface();
    217         gMsgCompose.RegisterStateListener(main.ComposeStateListener);
    218         document.getElementById("virtualIdentityExtension_tooltipPopupset")
    219             .addTooltip(document.getElementById("virtualIdentityExtension_msgIdentityClone"), false);
    220         window.addEventListener('compose-window-reopen', main.reopen, true);
    221         window.addEventListener('compose-window-close', main.close, true);
    222        
    223         // append observer to virtualIdentityExtension_fccSwitch, because it does'n work with real identities (hidden by css)
    224         document.getElementById("virtualIdentityExtension_fccSwitch").appendChild(document.getElementById("virtualIdentityExtension_msgIdentityClone_observer").cloneNode(false));
     120          }
     121        },
     122
     123        GenericSendMessageInProgress: false,
     124        GenericSendMessage: function (msgType) {
     125          if (main.replacement_functions.GenericSendMessageInProgress) return;
     126          main.replacement_functions.GenericSendMessageInProgress = true;
     127
     128          // if addressCol2 is focused while sending check storage for the entered address before continuing
     129          vI.storage.awOnBlur(vI.storage.focusedElement, window);
     130
     131          Log.debug("VIdentity_GenericSendMessage");
     132
     133          Log.debug("VIdentity_GenericSendMessage top=" + top);
     134
     135          if (msgType == Components.interfaces.nsIMsgCompDeliverMode.Now)
     136            vI.addReplyToSelf(window);
     137
     138          var vid = document.getElementById("virtualIdentityExtension_msgIdentityClone").vid
     139          var virtualIdentityData = document.getElementById("virtualIdentityExtension_msgIdentityClone").identityData;
     140
     141          let returnValue = vI.vIaccount_prepareSendMsg(vid, msgType, virtualIdentityData,
     142            main.accountManager.getIdentity(main.elements.Obj_MsgIdentity.value),
     143            main._getRecipients(), window);
     144          if (returnValue.update == "abort") {
     145            main.replacement_functions.GenericSendMessageInProgress = false;
     146            Log.debug("sending: --------------  aborted  ---------------------------------")
     147            return;
     148          } else if (returnValue.update == "takeover") {
     149            var msgIdentityCloneElem = document.getElementById("virtualIdentityExtension_msgIdentityClone");
     150            msgIdentityCloneElem.selectedMenuItem = msgIdentityCloneElem.addIdentityToCloneMenu(returnValue.storedIdentity);
     151            main.replacement_functions.GenericSendMessageInProgress = false;
     152            Log.debug("sending: --------------  aborted  ---------------------------------")
     153            return;
     154          }
     155
     156          if (vid) main.addVirtualIdentityToMsgIdentityMenu();
     157
     158          // final check if eyerything is nice before we handover to the real sending...
     159          if (vI.vIaccount_finalCheck(virtualIdentityData, getCurrentIdentity())) {
     160            main.replacement_functions.GenericSendMessageInProgress = false;
     161            main.original_functions.GenericSendMessage(msgType);
     162          } else main.Cleanup();
     163          main.replacement_functions.GenericSendMessageInProgress = false;
     164          //            Log.debug("original_functions.GenericSendMessage done");
     165        },
     166
     167        replace_FillIdentityList: function () {
     168          //~ Log.debug("replace FillIdentityList");
     169          main.original_functions.FillIdentityList = FillIdentityList;
     170          FillIdentityList = main.replacement_functions.FillIdentityList;
     171        }
     172      },
     173
     174      remove: function () {
     175        window.removeEventListener('compose-window-reopen', main.reopen, true);
     176        window.removeEventListener('compose-window-close', main.close, true);
     177        Log.debug("end. remove Account if there.")
     178        main.Cleanup();
     179        vI.storage.clean();
     180      },
     181
     182      _getRecipients: function () {
     183        var recipients = [];
     184        for (var row = 1; row <= top.MAX_RECIPIENTS; row++) {
     185          var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
     186          if (recipientType == "addr_reply" || recipientType == "addr_followup" ||
     187            main._recipientIsDoBcc(row) || awGetInputElement(row).value.match(/^\s*$/)) continue;
     188          recipients.push({
     189            recipient: awGetInputElement(row).value,
     190            recipientType: recipientType
     191          });
     192        }
     193        return recipients;
     194      },
     195
     196      _recipientIsDoBcc: function (row) {
     197        var recipientType = awGetPopupElement(row).selectedItem.getAttribute("value");
     198        if (recipientType != "addr_bcc" || !getCurrentIdentity().doBcc) return false
     199
     200        var doBccArray = gMsgCompose.compFields.splitRecipients(getCurrentIdentity().doBccList, false, {});
     201
     202        for (var index = 0; index < doBccArray.count; index++) {
     203          if (doBccArray.StringAt(index) == awGetInputElement(row).value) {
     204            Log.debug("_recipientIsDoBcc: ignoring doBcc field '" +
     205              doBccArray.StringAt(index));
     206            return true;
     207          }
     208        }
     209        return false
     210      },
     211
     212      // initialization //
     213      init: function () {
     214        window.removeEventListener('load', main.init, false);
     215        window.removeEventListener('compose-window-init', main.init, true);
     216        if (main.elements.Area_MsgIdentityHbox) return; // init done before, (?reopen)
     217        Log.debug("init.")
     218        main.unicodeConverter.charset = "UTF-8";
     219        if (!main.adapt_genericSendMessage()) {
     220          Log.error("init failed.");
     221          return;
     222        }
     223
     224        main.adapt_interface();
     225        gMsgCompose.RegisterStateListener(main.ComposeStateListener);
     226        document.getElementById("virtualIdentityExtension_tooltipPopupset")
     227          .addTooltip(document.getElementById("virtualIdentityExtension_msgIdentityClone"), false);
     228        window.addEventListener('compose-window-reopen', main.reopen, true);
     229        window.addEventListener('compose-window-close', main.close, true);
     230
     231        // append observer to virtualIdentityExtension_fccSwitch, because it does'n work with real identities (hidden by css)
     232        document.getElementById("virtualIdentityExtension_fccSwitch").appendChild(document.getElementById("virtualIdentityExtension_msgIdentityClone_observer").cloneNode(false));
    225233
    226234        main.AccountManagerObserver.register();
    227        
    228         main.initSystemStage1();
    229         Log.debug("init done.")
    230     },
    231    
    232     initSystemStage1 : function() {
    233         Log.debug("initSystemStage1.")
    234         main.gMsgCompose = gMsgCompose;
    235         document.getElementById("virtualIdentityExtension_msgIdentityClone").init();
    236         vI.statusmenu.init();
    237         Log.debug("initSystemStage1 done.")
    238     },
    239    
    240     initSystemStage2 : function() {
    241         Log.debug("initSystemStage2.")
     235
     236        main.initSystemStage1();
     237        Log.debug("init done.")
     238      },
     239
     240      initSystemStage1: function () {
     241        Log.debug("initSystemStage1.")
     242        main.gMsgCompose = gMsgCompose;
     243        document.getElementById("virtualIdentityExtension_msgIdentityClone").init();
     244        vI.statusmenu.init();
     245        Log.debug("initSystemStage1 done.")
     246      },
     247
     248      initSystemStage2: function () {
     249        Log.debug("initSystemStage2.")
    242250        vI.initReplyTo(window);
    243         vI.storage.init();
    244         vI.smartIdentity.init(window);
    245         Log.debug("initSystemStage2 done.")
    246     },
    247    
    248     close : function() {
    249         main.Cleanup();
    250         vI.storage.clean();
    251     },
    252    
    253     adapt_interface : function() {
    254         if (main.elements.Obj_MsgIdentityPopup) return; // only rearrange the interface once
    255        
    256         // initialize the pointers to extension elements
    257         main.elements.init_base()
    258        
    259         // rearrange the positions of some elements
    260         var parent_hbox = main.elements.Obj_MsgIdentity.parentNode;
    261         var storage_box = document.getElementById("addresses-box");
    262         var virtualIdentityExtension_autoReplyToSelfLabel = document.getElementById("virtualIdentityExtension_autoReplyToSelfLabelBox");
    263        
    264         storage_box.removeChild(virtualIdentityExtension_autoReplyToSelfLabel);
    265         parent_hbox.appendChild(virtualIdentityExtension_autoReplyToSelfLabel);
    266         storage_box.removeChild(main.elements.Area_MsgIdentityHbox);
    267         parent_hbox.appendChild(main.elements.Area_MsgIdentityHbox);
    268 
    269         main.elements.Obj_MsgIdentity.setAttribute("hidden", "true");
    270         main.elements.Obj_MsgIdentity.previousSibling.setAttribute("control", "virtualIdentityExtension_msgIdentityClone");
    271        
    272         var access_label = parent_hbox.getElementsByAttribute( "control", "msgIdentity" )[0];
    273         if (access_label) access_label.setAttribute("control", "virtualIdentityExtension_msgIdentityClone");