1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public
5
* License Version 1.1 (the "MPL"); you may not use this file
6
* except in compliance with the MPL. You may obtain a copy of
7
* the MPL at http://www.mozilla.org/MPL/
9
* Software distributed under the MPL is distributed on an "AS
10
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
* implied. See the MPL for the specific language governing
12
* rights and limitations under the MPL.
14
* The Original Code is Enigmail.
16
* The Initial Developer of the Original Code is Ramalingam Saravanan.
17
* Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
18
* Copyright (C) 2001 Ramalingam Saravanan. All Rights Reserved.
21
* Patrick Brunschwig <patrick@mozilla-enigmail.org>
23
* Alternatively, the contents of this file may be used under the terms of
24
* either the GNU General Public License Version 2 or later (the "GPL"), or
25
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26
* in which case the provisions of the GPL or the LGPL are applicable instead
27
* of those above. If you wish to allow use of your version of this file only
28
* under the terms of either the GPL or the LGPL, and not to allow others to
29
* use your version of this file under the terms of the MPL, indicate your
30
* decision by deleting the provisions above and replace them with the notice
31
* and other provisions required by the GPL or the LGPL. If you do not delete
32
* the provisions above, a recipient may use your version of this file under
33
* the terms of any one of the MPL, the GPL or the LGPL.
34
* ***** END LICENSE BLOCK ***** */
36
// Uses: chrome://enigmail/content/enigmailCommon.js
38
Components.utils.import("resource://enigmail/enigmailCommon.jsm");
40
// Initialize enigmailCommon
41
EnigInitCommon("pref-enigmail");
43
var gMimePartsElement, gMimePartsValue, gAdvancedMode;
45
function prefOnLoad() {
47
EnigDisplayPrefs(false, true, false);
48
document.getElementById("enigmail_agentPath").value = EnigConvertToUnicode(EnigGetPref("agentPath"), "utf-8");
50
gAdvancedMode = EnigGetPref("advancedUser");
52
if (window.arguments) {
53
if (! window.arguments[0].showBasic) {
55
document.getElementById("basic").setAttribute("collapsed", true);
56
document.getElementById("basicTab").setAttribute("collapsed", true);
57
selectPrefTabPanel("sendTab");
60
EnigCollapseAdvanced(document.getElementById("prefTabBox"), "collapsed", null);
61
EnigCollapseAdvanced(document.getElementById("enigPrefTabPanel"), "hidden", null);
62
enigShowUserModeButtons(gAdvancedMode);
65
if ((typeof window.arguments[0].selectTab)=="string") {
66
selectPrefTabPanel(window.arguments[0].selectTab);
71
enigShowUserModeButtons(gAdvancedMode);
74
if ((! window.arguments) || (window.arguments[0].clientType!="seamonkey")) {
75
document.getElementById("enigmail_disableSMIMEui").setAttribute("collapsed", true);
76
var uninst = document.getElementById("uninstall");
77
if (uninst) uninst.setAttribute("collapsed", "true");
78
EnigCollapseAdvanced(document.getElementById("prefTabBox"), "collapsed", null);
79
EnigCollapseAdvanced(document.getElementById("enigPrefTabPanel"), "hidden", null);
83
EnigDisplayRadioPref("recipientsSelection", EnigGetPref("recipientsSelection"),
84
gEnigRecipientsSelection);
86
gMimePartsElement = document.getElementById("mime_parts_on_demand");
89
gMimePartsValue = EnigmailCommon.prefRoot.getBoolPref("mail.server.default.mime_parts_on_demand");
91
gMimePartsValue = true;
94
if (gMimePartsValue) {
95
gMimePartsElement.setAttribute("checked", "true");
97
gMimePartsElement.removeAttribute("checked");
100
var overrideGpg = document.getElementById("enigOverrideGpg")
101
if (EnigGetPref("agentPath")) {
102
overrideGpg.checked = true;
105
overrideGpg.checked = false;
107
enigActivateDependent(overrideGpg, "enigmail_agentPath enigmail_browsePath");
108
activateRulesButton(document.getElementById("enigmail_recipientsSelection"), "openRulesEditor");
110
var testEmailElement = document.getElementById("enigmail_test_email");
111
var userIdValue = EnigGetPref("userIdValue");
113
enigDetermineGpgPath();
115
if (testEmailElement && userIdValue)
116
testEmailElement.value = userIdValue;
120
function enigDetermineGpgPath() {
121
if (! gEnigmailSvc) {
123
gEnigmailSvc = ENIG_C[ENIG_ENIGMAIL_CONTRACTID].createInstance(ENIG_I.nsIEnigmail);
124
if (! gEnigmailSvc.initialized) {
125
// attempt to initialize Enigmail
126
gEnigmailSvc.initialize(window, EnigGetVersion(), gPrefEnigmail);
131
if (gEnigmailSvc.initialized && typeof(gEnigmailSvc.agentPath) == "object") {
134
if (EnigGetOS() == "WINNT") {
135
agentPath = EnigGetFilePath(gEnigmailSvc.agentPath).replace(/\\\\/g, "\\");
138
agentPath = gEnigmailSvc.agentPath.path;
139
// EnigGetFilePath(gEnigmailSvc.agentPath); // .replace(/\\\\/g, "\\");
141
if (agentPath.length > 50) {
142
agentPath = agentPath.substring(0,50)+"..."
144
document.getElementById("enigmailGpgPath").setAttribute("value", EnigGetString("prefs.gpgFound", agentPath));
147
document.getElementById("enigmailGpgPath").setAttribute("value", "error 2");
151
document.getElementById("enigmailGpgPath").setAttribute("value", EnigGetString("prefs.gpgNotFound"));
155
function selectPrefTabPanel(panelName) {
156
var prefTabs=document.getElementById("prefTabs");
157
var selectTab=document.getElementById(panelName);
158
prefTabs.selectedTab = selectTab;
161
function resetPrefs() {
162
DEBUG_LOG("pref-enigmail.js: resetPrefs\n");
164
EnigDisplayPrefs(true, true, false);
166
EnigSetPref("configuredVersion", EnigGetVersion());
168
EnigDisplayRadioPref("recipientsSelection", EnigGetPref("recipientsSelection"),
169
gEnigRecipientsSelection);
173
function resetRememberedValues() {
174
DEBUG_LOG("pref-enigmail.js: resetRememberedValues\n");
175
var prefs=["confirmBeforeSend",
177
"encryptAttachmentsSkipDlg",
180
"quotedPrintableWarn",
182
"warnOnRulesConflict",
183
"warnGpgAgentAndIdleTime",
184
"warnClearPassphrase",
185
"warnOnSendingNewsgroups",
189
for (var j=0; j<prefs.length; j++) {
190
EnigSetPref(prefs[j], EnigGetDefaultPref(prefs[j]));
192
EnigAlert(EnigGetString("warningsAreReset"));
195
function prefOnAccept() {
197
DEBUG_LOG("pref-enigmail.js: prefOnAccept\n");
199
var autoKey = document.getElementById("enigmail_autoKeyRetrieve").value;
201
if (autoKey.search(/.[ ,;\t]./)>=0) {
202
EnigAlert(EnigGetString("prefEnigmail.oneKeyserverOnly"));
206
var oldAgentPath = EnigGetPref("agentPath");
208
if (! document.getElementById("enigOverrideGpg").checked) {
209
document.getElementById("enigmail_agentPath").value = "";
211
var newAgentPath = document.getElementById("enigmail_agentPath").value;
213
EnigDisplayPrefs(false, false, true);
214
EnigSetPref("agentPath", EnigConvertFromUnicode(newAgentPath, "utf-8"));
216
//setRecipientsSelectionPref(document.getElementById("enigmail_recipientsSelection").value);
217
//EnigSetRadioPref("recipientsSelection", gEnigRecipientsSelection);
219
if (gMimePartsElement &&
220
(gMimePartsElement.checked != gMimePartsValue) ) {
222
EnigmailCommon.prefRoot.setBoolPref("mail.server.default.mime_parts_on_demand", (gMimePartsElement.checked ? true : false));
225
EnigSetPref("configuredVersion", EnigGetVersion());
226
EnigSetPref("advancedUser", gAdvancedMode);
230
if (oldAgentPath != newAgentPath) {
231
if (! gEnigmailSvc) {
233
gEnigmailSvc = ENIG_C[ENIG_ENIGMAIL_CONTRACTID].createInstance(ENIG_I.nsIEnigmail);
237
if (gEnigmailSvc.initialized) {
239
gEnigmailSvc.reinitialize();
242
EnigError(EnigGetString("invalidGpgPath"));
251
// detect use of gpg-agent and warn if needed
252
var enigmailSvc = GetEnigmailSvc();
253
if (enigmailSvc && enigmailSvc.useGpgAgent()) {
254
if ((document.getElementById("enigmail_maxIdleMinutes").value > 0) &&
255
(! document.getElementById("enigmail_noPassphrase").checked)) {
256
EnigAlertPref(EnigGetString("prefs.warnIdleTimeWithGpgAgent"), "warnGpgAgentAndIdleTime");
264
function enigActivateDependent (obj, dependentIds) {
265
var idList = dependentIds.split(/ /);
268
for (depId in idList) {
270
document.getElementById(idList[depId]).removeAttribute("disabled");
273
document.getElementById(idList[depId]).setAttribute("disabled", "true");
279
function enigShowUserModeButtons(expertUser) {
280
var advUserButton = document.getElementById("enigmail_advancedUser");
281
var basicUserButton = document.getElementById("enigmail_basicUser");
283
basicUserButton.setAttribute("hidden", true);
284
advUserButton.removeAttribute("hidden");
287
advUserButton.setAttribute("hidden", true);
288
basicUserButton.removeAttribute("hidden");
292
function enigSwitchAdvancedMode(expertUser) {
294
var origPref = EnigGetPref("advancedUser");
295
enigShowUserModeButtons(expertUser);
296
gAdvancedMode = expertUser;
299
EnigSetPref("advancedUser", true);
302
EnigSetPref("advancedUser", false);
305
var prefTabBox = document.getElementById("prefTabBox");
308
EnigCollapseAdvanced(document.getElementById("enigPrefTabPanel"), "hidden", null);
309
EnigCollapseAdvanced(prefTabBox, "collapsed", null);
313
EnigCollapseAdvanced(document.getElementById("enigmailPrefsBox"), "hidden", null);
315
EnigSetPref("advancedUser", origPref);
318
function enigAlertAskNever () {
319
EnigAlert(EnigGetString("prefs.warnAskNever"));
322
function activateRulesButton(radioListObj, buttonId) {
323
switch (radioListObj.value) {
326
document.getElementById(buttonId).setAttribute("disabled", "true");
329
document.getElementById(buttonId).removeAttribute("disabled");
334
function EnigTest() {
335
var plainText = "TEST MESSAGE 123\nTEST MESSAGE 345\n";
336
var testEmailElement = document.getElementById("enigmail_test_email");
337
var toMailAddr = testEmailElement.value;
339
var enigmailSvc = GetEnigmailSvc();
341
EnigAlert(EnigGetString("testNoSvc"));
347
EnigAlert(EnigGetString("testNoEmail"));
352
CONSOLE_LOG("\n\nEnigTest: START ********************************\n");
353
CONSOLE_LOG("EnigTest: To: "+toMailAddr+"\n"+plainText+"\n");
355
var uiFlags = nsIEnigmail.UI_INTERACTIVE;
357
var exitCodeObj = new Object();
358
var statusFlagsObj = new Object();
359
var errorMsgObj = new Object();
361
var cipherText = enigmailSvc.encryptMessage(window, uiFlags, null, plainText,
362
toMailAddr, toMailAddr, "",
363
nsIEnigmail.SEND_SIGNED,
364
exitCodeObj, statusFlagsObj,
366
CONSOLE_LOG("************************************************\n");
367
CONSOLE_LOG("EnigTest: SIGNING ONLY\n");
368
CONSOLE_LOG("EnigTest: cipherText = "+cipherText+"\n");
369
CONSOLE_LOG("EnigTest: exitCode = "+exitCodeObj.value+"\n");
370
CONSOLE_LOG("************************************************\n");
372
var signatureObj = new Object();
373
var keyIdObj = new Object();
374
var userIdObj = new Object();
375
var sigDetailsObj = new Object();
376
var blockSeparationObj = new Object();
378
var decryptedText = enigmailSvc.decryptMessage(window,
380
signatureObj, exitCodeObj,
381
statusFlagsObj, keyIdObj, userIdObj,
386
CONSOLE_LOG("\n************************************************\n");
387
CONSOLE_LOG("EnigTest: VERIFICATION\n");
388
CONSOLE_LOG("EnigTest: decryptedText = "+decryptedText+"\n");
389
CONSOLE_LOG("EnigTest: exitCode = "+exitCodeObj.value+"\n");
390
CONSOLE_LOG("EnigTest: signature = "+signatureObj.value+"\n");
391
CONSOLE_LOG("************************************************\n");
393
cipherText = enigmailSvc.encryptMessage(window, uiFlags, null, plainText,
394
toMailAddr, toMailAddr, "",
395
nsIEnigmail.SEND_SIGNED|
396
nsIEnigmail.SEND_ENCRYPTED,
397
exitCodeObj, statusFlagsObj,
399
CONSOLE_LOG("************************************************\n");
400
CONSOLE_LOG("EnigTest: SIGNING + ENCRYPTION\n");
401
CONSOLE_LOG("EnigTest: cipherText = "+cipherText+"\n");
402
CONSOLE_LOG("EnigTest: exitCode = "+exitCodeObj.value+"\n");
403
CONSOLE_LOG("************************************************\n");
405
decryptedText = enigmailSvc.decryptMessage(window, uiFlags, cipherText,
406
signatureObj, exitCodeObj,
407
statusFlagsObj, keyIdObj, userIdObj,
409
errorMsgObj, blockSeparationObj);
411
CONSOLE_LOG("\n************************************************\n");
412
CONSOLE_LOG("EnigTest: DECRYPTION\n");
413
CONSOLE_LOG("EnigTest: decryptedText = "+decryptedText+"\n");
414
CONSOLE_LOG("EnigTest: exitCode = "+exitCodeObj.value+"\n");
415
CONSOLE_LOG("EnigTest: signature = "+signatureObj.value+"\n");
416
CONSOLE_LOG("************************************************\n");
418
EnigAlert(EnigGetString("testSucceeded"));
421
EnigAlert(EnigGetString("undefinedError"));
425
function enigLocateGpg() {
428
if (EnigGetOS() == "WINNT") {
431
var filePath = EnigFilePicker(EnigGetString("locateGpg"),
435
// if (EnigmailCommon.getOS() == "WINNT") {
436
// document.getElementById("enigmail_agentPath").value = EnigGetFilePath(filePath);
438
document.getElementById("enigmail_agentPath").value = filePath.path