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

source: modules/plugins/signatureSwitch.js @ 5449ac

ng_0.9
Last change on this file since 5449ac was 5449ac, checked in by rene <rene@…>, 9 years ago

smime and pgp-signatures can be removed even if signatureswitch-extension is not installed

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/* ***** 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.
6
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.
11
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
15
16    The Original Code is the Virtual Identity Extension.
17
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.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25var EXPORTED_SYMBOLS = ["signatureSwitch"]
26
27const {classes: Cc, interfaces: Ci, utils: Cu, results : Cr} = Components;
28Cu.import("resource://gre/modules/AddonManager.jsm");
29Cu.import("resource://v_identity/vI_prefs.js");
30Cu.import("resource://v_identity/vI_log.js");
31let Log = setupLogging("virtualIdentity.signatureSwitch");
32
33function signatureSwitch(existingIdentity) {
34  // always try to initialize Security/Enigmail-Options
35  try { setSecuritySettings(1); enigSetMenuSettings(''); } catch(vErr) { };
36 
37  let signatureWindow = Cc["@mozilla.org/appshell/window-mediator;1"]
38      .getService(Ci.nsIWindowMediator)
39      .getMostRecentWindow(null);
40
41  if (!existingIdentity) {
42    Log.debug("signatureSwitch hide/remove signatures");
43   
44    // code to hide the text signature
45    if (signatureSwitchInstalled && vIprefs.get("hide_signature") && signatureWindow.ss_signature && signatureWindow.ss_signature.length == 0) {
46      Log.debug("hide text/html signature");
47      signatureWindow.ss_main.signatureSwitch()
48    }
49   
50    // code to hide the sMime signature
51    if (vIprefs.get("hide_sMime_messageSignature")) {
52      var element = signatureWindow.document.getElementById("menu_securitySign1");
53      if (element && element.getAttribute("checked") == "true") {
54        Log.debug("signatureSwitch hide_sMime_messageSignature with doCommand");
55        element.doCommand();
56      }
57    }
58
59    // code to hide the openGPG signature
60    if (vIprefs.get("hide_openPGP_messageSignature")) {
61      var element = signatureWindow.document.getElementById("enigmail_signed_send");
62      if (element && element.getAttribute("checked") == "true") {
63        var skipChangeGPGsign = false;
64        // sometimes GPG delays changing with dialog, so don't act if EnigmailAlertWindow is open to prevent double changes
65        var windows = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
66          .getService(Components.interfaces.nsIWindowWatcher).getWindowEnumerator();
67        while (windows.hasMoreElements()) {
68          var window = windows.getNext();
69          skipChangeGPGsign = skipChangeGPGsign || (window.document.title == EnigGetString("enigAlert"));
70        }
71        if (skipChangeGPGsign)
72          Log.debug("signatureSwitch skip hide_openPGP_messageSignature - EnigMail AlertWindow open");
73        else {
74          Log.debug("signatureSwitch hide_openPGP_messageSignature with doCommand");
75          element.doCommand();
76        }
77      }
78    }
79  }
80  else if (signatureSwitchInstalled) {
81    Log.debug("signatureSwitch restore signature");
82    // code to show the text signature
83    if (signatureWindow.ss_signature && signatureWindow.ss_signature.length > 0) {
84      Log.debug("show text/html signature");
85      signatureWindow.ss_main.signatureSwitch()
86    }
87    // sMime and openGPG signature will not be re-added automatically
88  }
89}
90
91let signatureSwitchInstalled = false;
92// check for signature_switch extension
93AddonManager.getAddonByID("{2ab1b709-ba03-4361-abf9-c50b964ff75d}", function(addon) {
94  signatureSwitchInstalled = (addon && !addon.userDisabled && !addon.appDisable);
95  if (signatureSwitchInstalled)
96    Log.debug("Virtual Identity plugin for signatureSwitch Extension loaded!");
97  else
98    Log.debug("virtualIdentity is ready for signatureSwitch, but you don't use it");
99  });
Note: See TracBrowser for help on using the repository browser.