~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mailnews/extensions/enigmail/ui/content/pref-enigmail.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
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/
 
8
 *
 
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.
 
13
 *
 
14
 * The Original Code is Enigmail.
 
15
 *
 
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.
 
19
 *
 
20
 * Contributor(s):
 
21
 * Patrick Brunschwig <patrick@mozilla-enigmail.org>
 
22
 *
 
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 ***** */
 
35
 
 
36
// Uses: chrome://enigmail/content/enigmailCommon.js
 
37
 
 
38
Components.utils.import("resource://enigmail/enigmailCommon.jsm");
 
39
 
 
40
// Initialize enigmailCommon
 
41
EnigInitCommon("pref-enigmail");
 
42
 
 
43
var gMimePartsElement, gMimePartsValue, gAdvancedMode;
 
44
 
 
45
function prefOnLoad() {
 
46
 
 
47
   EnigDisplayPrefs(false, true, false);
 
48
   document.getElementById("enigmail_agentPath").value = EnigConvertToUnicode(EnigGetPref("agentPath"), "utf-8");
 
49
 
 
50
   gAdvancedMode = EnigGetPref("advancedUser");
 
51
 
 
52
   if (window.arguments) {
 
53
      if (! window.arguments[0].showBasic) {
 
54
          // hide basic tab
 
55
          document.getElementById("basic").setAttribute("collapsed", true);
 
56
          document.getElementById("basicTab").setAttribute("collapsed", true);
 
57
          selectPrefTabPanel("sendTab");
 
58
      }
 
59
      else {
 
60
        EnigCollapseAdvanced(document.getElementById("prefTabBox"), "collapsed", null);
 
61
        EnigCollapseAdvanced(document.getElementById("enigPrefTabPanel"), "hidden", null);
 
62
        enigShowUserModeButtons(gAdvancedMode);
 
63
      }
 
64
 
 
65
      if ((typeof window.arguments[0].selectTab)=="string") {
 
66
          selectPrefTabPanel(window.arguments[0].selectTab);
 
67
      }
 
68
 
 
69
   }
 
70
   else {
 
71
    enigShowUserModeButtons(gAdvancedMode);
 
72
   }
 
73
 
 
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);
 
80
 
 
81
   }
 
82
 
 
83
   EnigDisplayRadioPref("recipientsSelection", EnigGetPref("recipientsSelection"),
 
84
                        gEnigRecipientsSelection);
 
85
 
 
86
   gMimePartsElement = document.getElementById("mime_parts_on_demand");
 
87
 
 
88
   try {
 
89
     gMimePartsValue = EnigmailCommon.prefRoot.getBoolPref("mail.server.default.mime_parts_on_demand");
 
90
   } catch (ex) {
 
91
     gMimePartsValue = true;
 
92
   }
 
93
 
 
94
   if (gMimePartsValue) {
 
95
     gMimePartsElement.setAttribute("checked", "true");
 
96
   } else {
 
97
     gMimePartsElement.removeAttribute("checked");
 
98
   }
 
99
 
 
100
   var overrideGpg = document.getElementById("enigOverrideGpg");
 
101
   if (EnigGetPref("agentPath")) {
 
102
      overrideGpg.checked = true;
 
103
   }
 
104
   else {
 
105
      overrideGpg.checked = false;
 
106
   }
 
107
   enigActivateDependent(overrideGpg, "enigmail_agentPath enigmail_browsePath");
 
108
   activateRulesButton(document.getElementById("enigmail_recipientsSelection"), "openRulesEditor");
 
109
 
 
110
   var testEmailElement = document.getElementById("enigmail_test_email");
 
111
   var userIdValue = EnigGetPref("userIdValue");
 
112
 
 
113
   enigDetermineGpgPath();
 
114
 
 
115
   if (testEmailElement && userIdValue)
 
116
     testEmailElement.value = userIdValue;
 
117
 
 
118
}
 
119
 
 
120
function enigDetermineGpgPath() {
 
121
  if (! gEnigmailSvc) {
 
122
    try {
 
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);
 
127
      }
 
128
    } catch (ex) {}
 
129
  }
 
130
 
 
131
  if (gEnigmailSvc.initialized && typeof(gEnigmailSvc.agentPath) == "object") {
 
132
    try {
 
133
      var agentPath = "";
 
134
      if (EnigGetOS() == "WINNT") {
 
135
        agentPath = EnigGetFilePath(gEnigmailSvc.agentPath).replace(/\\\\/g, "\\");
 
136
      }
 
137
      else {
 
138
        agentPath = gEnigmailSvc.agentPath.path;
 
139
        // EnigGetFilePath(gEnigmailSvc.agentPath); // .replace(/\\\\/g, "\\");
 
140
      }
 
141
      if (agentPath.length > 50) {
 
142
        agentPath = agentPath.substring(0,50)+"...";
 
143
      }
 
144
      document.getElementById("enigmailGpgPath").setAttribute("value", EnigGetString("prefs.gpgFound", agentPath));
 
145
    }
 
146
    catch(ex) {
 
147
      document.getElementById("enigmailGpgPath").setAttribute("value", "error 2");
 
148
    }
 
149
  }
 
150
  else {
 
151
    document.getElementById("enigmailGpgPath").setAttribute("value", EnigGetString("prefs.gpgNotFound"));
 
152
  }
 
153
}
 
154
 
 
155
function selectPrefTabPanel(panelName) {
 
156
  var prefTabs=document.getElementById("prefTabs");
 
157
  var selectTab=document.getElementById(panelName);
 
158
  prefTabs.selectedTab = selectTab;
 
159
}
 
160
 
 
161
function resetPrefs() {
 
162
  DEBUG_LOG("pref-enigmail.js: resetPrefs\n");
 
163
 
 
164
  EnigDisplayPrefs(true, true, false);
 
165
 
 
166
  EnigSetPref("configuredVersion", EnigGetVersion());
 
167
 
 
168
  EnigDisplayRadioPref("recipientsSelection", EnigGetPref("recipientsSelection"),
 
169
                      gEnigRecipientsSelection);
 
170
 
 
171
}
 
172
 
 
173
function resetRememberedValues() {
 
174
  DEBUG_LOG("pref-enigmail.js: resetRememberedValues\n");
 
175
  var prefs=["confirmBeforeSend",
 
176
             "displaySignWarn",
 
177
             "encryptAttachmentsSkipDlg",
 
178
             "initAlert",
 
179
             "mimePreferPgp",
 
180
             "quotedPrintableWarn",
 
181
             "saveEncrypted",
 
182
             "warnOnRulesConflict",
 
183
             "warnGpgAgentAndIdleTime",
 
184
             "warnClearPassphrase",
 
185
             "warnOnSendingNewsgroups",
 
186
             "warnIso2022jp",
 
187
             "warnRefreshAll"];
 
188
 
 
189
  for (var j=0; j<prefs.length; j++) {
 
190
    EnigSetPref(prefs[j], EnigGetDefaultPref(prefs[j]));
 
191
  }
 
192
  EnigAlert(EnigGetString("warningsAreReset"));
 
193
}
 
194
 
 
195
function prefOnAccept() {
 
196
 
 
197
  DEBUG_LOG("pref-enigmail.js: prefOnAccept\n");
 
198
 
 
199
  var autoKey = document.getElementById("enigmail_autoKeyRetrieve").value;
 
200
 
 
201
  if (autoKey.search(/.[ ,;\t]./)>=0)  {
 
202
    EnigAlert(EnigGetString("prefEnigmail.oneKeyserverOnly"));
 
203
    return false;
 
204
  }
 
205
 
 
206
  var oldAgentPath = EnigGetPref("agentPath");
 
207
 
 
208
  if (! document.getElementById("enigOverrideGpg").checked) {
 
209
    document.getElementById("enigmail_agentPath").value = "";
 
210
  }
 
211
  var newAgentPath = document.getElementById("enigmail_agentPath").value;
 
212
 
 
213
  EnigDisplayPrefs(false, false, true);
 
214
  EnigSetPref("agentPath", EnigConvertFromUnicode(newAgentPath, "utf-8"));
 
215
 
 
216
  //setRecipientsSelectionPref(document.getElementById("enigmail_recipientsSelection").value);
 
217
  //EnigSetRadioPref("recipientsSelection", gEnigRecipientsSelection);
 
218
 
 
219
  if (gMimePartsElement &&
 
220
      (gMimePartsElement.checked != gMimePartsValue) ) {
 
221
 
 
222
    EnigmailCommon.prefRoot.setBoolPref("mail.server.default.mime_parts_on_demand", (gMimePartsElement.checked ? true : false));
 
223
  }
 
224
 
 
225
  EnigSetPref("configuredVersion", EnigGetVersion());
 
226
  EnigSetPref("advancedUser", gAdvancedMode);
 
227
 
 
228
  EnigSavePrefs();
 
229
 
 
230
  if (oldAgentPath != newAgentPath) {
 
231
    if (! gEnigmailSvc) {
 
232
      try {
 
233
        gEnigmailSvc = ENIG_C[ENIG_ENIGMAIL_CONTRACTID].createInstance(ENIG_I.nsIEnigmail);
 
234
      } catch (ex) {}
 
235
    }
 
236
 
 
237
    if (gEnigmailSvc.initialized) {
 
238
      try {
 
239
        gEnigmailSvc.reinitialize();
 
240
      }
 
241
      catch (ex) {
 
242
        EnigError(EnigGetString("invalidGpgPath"));
 
243
      }
 
244
    }
 
245
    else {
 
246
      gEnigmailSvc = null;
 
247
      GetEnigmailSvc();
 
248
    }
 
249
  }
 
250
 
 
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");
 
257
    }
 
258
  }
 
259
 
 
260
 
 
261
  return true;
 
262
}
 
263
 
 
264
function enigActivateDependent (obj, dependentIds) {
 
265
  var idList = dependentIds.split(/ /);
 
266
  var depId;
 
267
 
 
268
  for (depId in idList) {
 
269
    if (obj.checked) {
 
270
      document.getElementById(idList[depId]).removeAttribute("disabled");
 
271
    }
 
272
    else {
 
273
      document.getElementById(idList[depId]).setAttribute("disabled", "true");
 
274
    }
 
275
  }
 
276
  return true;
 
277
}
 
278
 
 
279
function enigShowUserModeButtons(expertUser) {
 
280
  var advUserButton = document.getElementById("enigmail_advancedUser");
 
281
  var basicUserButton = document.getElementById("enigmail_basicUser");
 
282
  if (! expertUser) {
 
283
    basicUserButton.setAttribute("hidden", true);
 
284
    advUserButton.removeAttribute("hidden");
 
285
  }
 
286
  else {
 
287
    advUserButton.setAttribute("hidden", true);
 
288
    basicUserButton.removeAttribute("hidden");
 
289
  }
 
290
}
 
291
 
 
292
function enigSwitchAdvancedMode(expertUser) {
 
293
 
 
294
  var origPref = EnigGetPref("advancedUser");
 
295
  enigShowUserModeButtons(expertUser);
 
296
  gAdvancedMode = expertUser;
 
297
 
 
298
  if (expertUser) {
 
299
    EnigSetPref("advancedUser", true);
 
300
  }
 
301
  else {
 
302
    EnigSetPref("advancedUser", false);
 
303
  }
 
304
 
 
305
  var prefTabBox  = document.getElementById("prefTabBox");
 
306
  if (prefTabBox) {
 
307
    // Thunderbird
 
308
    EnigCollapseAdvanced(document.getElementById("enigPrefTabPanel"), "hidden", null);
 
309
    EnigCollapseAdvanced(prefTabBox, "collapsed", null);
 
310
  }
 
311
  else {
 
312
    // Seamonkey
 
313
    EnigCollapseAdvanced(document.getElementById("enigmailPrefsBox"), "hidden", null);
 
314
  }
 
315
  EnigSetPref("advancedUser", origPref);
 
316
}
 
317
 
 
318
function enigAlertAskNever () {
 
319
  EnigAlert(EnigGetString("prefs.warnAskNever"));
 
320
}
 
321
 
 
322
function activateRulesButton(radioListObj, buttonId) {
 
323
  switch (radioListObj.value) {
 
324
  case "3":
 
325
  case "4":
 
326
    document.getElementById(buttonId).setAttribute("disabled", "true");
 
327
    break;
 
328
  default:
 
329
    document.getElementById(buttonId).removeAttribute("disabled");
 
330
  }
 
331
}
 
332
 
 
333
 
 
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;
 
338
 
 
339
  var enigmailSvc = GetEnigmailSvc();
 
340
  if (!enigmailSvc) {
 
341
    EnigAlert(EnigGetString("testNoSvc"));
 
342
    return;
 
343
  }
 
344
 
 
345
  if (!toMailAddr) {
 
346
 
 
347
    EnigAlert(EnigGetString("testNoEmail"));
 
348
    return;
 
349
  }
 
350
 
 
351
  try {
 
352
    CONSOLE_LOG("\n\nEnigTest: START ********************************\n");
 
353
    CONSOLE_LOG("EnigTest: To: "+toMailAddr+"\n"+plainText+"\n");
 
354
 
 
355
    var uiFlags = nsIEnigmail.UI_INTERACTIVE;
 
356
 
 
357
    var exitCodeObj    = new Object();
 
358
    var statusFlagsObj = new Object();
 
359
    var errorMsgObj    = new Object();
 
360
 
 
361
    var cipherText = enigmailSvc.encryptMessage(window, uiFlags, plainText,
 
362
                                                toMailAddr, toMailAddr, "",
 
363
                                                nsIEnigmail.SEND_SIGNED,
 
364
                                                exitCodeObj, statusFlagsObj,
 
365
                                                errorMsgObj);
 
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");
 
371
 
 
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();
 
377
 
 
378
    var decryptedText = enigmailSvc.decryptMessage(window,
 
379
                                        uiFlags, cipherText,
 
380
                                        signatureObj, exitCodeObj,
 
381
                                        statusFlagsObj, keyIdObj, userIdObj,
 
382
                                        sigDetailsObj,
 
383
                                        errorMsgObj,
 
384
                                        blockSeparationObj);
 
385
 
 
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");
 
392
 
 
393
    cipherText = enigmailSvc.encryptMessage(window, uiFlags, plainText,
 
394
                                                toMailAddr, toMailAddr, "",
 
395
                                                nsIEnigmail.SEND_SIGNED|
 
396
                                                nsIEnigmail.SEND_ENCRYPTED,
 
397
                                                exitCodeObj, statusFlagsObj,
 
398
                                                errorMsgObj);
 
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");
 
404
 
 
405
    decryptedText = enigmailSvc.decryptMessage(window, uiFlags, cipherText,
 
406
                                        signatureObj, exitCodeObj,
 
407
                                        statusFlagsObj, keyIdObj, userIdObj,
 
408
                                        sigDetailsObj,
 
409
                                        errorMsgObj, blockSeparationObj);
 
410
 
 
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");
 
417
 
 
418
    EnigAlert(EnigGetString("testSucceeded"));
 
419
  }
 
420
  catch (ex) {
 
421
    EnigAlert(EnigGetString("undefinedError"));
 
422
  }
 
423
}
 
424
 
 
425
function enigLocateGpg() {
 
426
  var fileName="gpg";
 
427
  var ext="";
 
428
  if (EnigGetOS() == "WINNT") {
 
429
    ext=".exe";
 
430
  }
 
431
  var filePath = EnigFilePicker(EnigGetString("locateGpg"),
 
432
                           "", false, ext,
 
433
                           fileName+ext, null);
 
434
  if (filePath) {
 
435
//     if (EnigmailCommon.getOS() == "WINNT") {
 
436
//       document.getElementById("enigmail_agentPath").value = EnigGetFilePath(filePath);
 
437
//     }
 
438
    document.getElementById("enigmail_agentPath").value = filePath.path;
 
439
  }
 
440
}