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

« back to all changes in this revision

Viewing changes to extensions/enigmail/ui/content/enigmailCommon.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
 
// enigmailCommon.js: shared JS functions for Enigmail
37
 
 
38
 
// WARNING: This module functions must not be loaded in overlays to standard
39
 
// functionality!
40
 
 
41
 
Components.utils.import("resource://enigmail/enigmailCommon.jsm");
42
 
Components.utils.import("resource://enigmail/commonFuncs.jsm");
43
 
Components.utils.import("resource://enigmail/keyManagement.jsm");
44
 
 
45
 
 
46
 
// The compatible Enigmime version
47
 
var gEnigmimeVersion = "1.4";
48
 
var gEnigmailSvc;
49
 
var gEnigPromptSvc;
50
 
 
51
 
 
52
 
// Maximum size of message directly processed by Enigmail
53
 
const ENIG_MSG_BUFFER_SIZE = 96000;
54
 
const ENIG_MSG_HEADER_SIZE = 16000;
55
 
const ENIG_UNLIMITED_BUFFER_SIZE = -1;
56
 
 
57
 
const ENIG_KEY_BUFFER_SIZE = 64000;
58
 
 
59
 
const ENIG_PROCESSINFO_CONTRACTID = "@mozilla.org/xpcom/process-info;1";
60
 
const ENIG_IPCBUFFER_CONTRACTID   = "@mozilla.org/ipc/ipc-buffer;1";
61
 
const ENIG_ENIGMAIL_CONTRACTID    = "@mozdev.org/enigmail/enigmail;1";
62
 
const ENIG_ENIGMIMELISTENER_CONTRACTID = "@mozilla.org/enigmail/mime-listener;1";
63
 
const ENIG_ENIGMIMESERVICE_CONTRACTID = "@mozdev.org/enigmail/enigmimeservice;1";
64
 
const ENIG_STRINGBUNDLE_CONTRACTID = "@mozilla.org/intl/stringbundle;1";
65
 
const ENIG_LOCAL_FILE_CONTRACTID = "@mozilla.org/file/local;1";
66
 
const ENIG_DIRSERVICE_CONTRACTID = "@mozilla.org/file/directory_service;1";
67
 
const ENIG_MIME_CONTRACTID = "@mozilla.org/mime;1";
68
 
const ENIG_WMEDIATOR_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=window-mediator";
69
 
const ENIG_ASS_CONTRACTID = "@mozilla.org/appshell/appShellService;1";
70
 
const ENIG_CLIPBOARD_CONTRACTID = "@mozilla.org/widget/clipboard;1";
71
 
const ENIG_CLIPBOARD_HELPER_CONTRACTID = "@mozilla.org/widget/clipboardhelper;1"
72
 
const ENIG_TRANSFERABLE_CONTRACTID = "@mozilla.org/widget/transferable;1"
73
 
const ENIG_LOCALE_SVC_CONTRACTID = "@mozilla.org/intl/nslocaleservice;1";
74
 
const ENIG_DATE_FORMAT_CONTRACTID = "@mozilla.org/intl/scriptabledateformat;1"
75
 
const ENIG_ACCOUNT_MANAGER_CONTRACTID = "@mozilla.org/messenger/account-manager;1";
76
 
const ENIG_THREAD_MANAGER_CID = "@mozilla.org/thread-manager;1";
77
 
const ENIG_SIMPLEURI_CONTRACTID   = "@mozilla.org/network/simple-uri;1";
78
 
const ENIG_SEAMONKEY_ID = "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}"
79
 
 
80
 
 
81
 
const ENIG_STANDARD_URL_CONTRACTID = "@mozilla.org/network/standard-url;1";
82
 
const ENIG_SCRIPTABLEINPUTSTREAM_CONTRACTID = "@mozilla.org/scriptableinputstream;1";
83
 
const ENIG_BINARYINPUTSTREAM_CONTRACTID = "@mozilla.org/binaryinputstream;1";
84
 
const ENIG_SAVEASCHARSET_CONTRACTID = "@mozilla.org/intl/saveascharset;1";
85
 
 
86
 
const ENIG_STREAMCONVERTERSERVICE_CID_STR =
87
 
      "{892FFEB0-3F80-11d3-A16C-0050041CAF44}";
88
 
 
89
 
 
90
 
const ENIG_ISCRIPTABLEUNICODECONVERTER_CONTRACTID = "@mozilla.org/intl/scriptableunicodeconverter";
91
 
 
92
 
const ENIG_IOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
93
 
 
94
 
const ENIG_C = Components.classes;
95
 
const ENIG_I = Components.interfaces;
96
 
 
97
 
// Key algorithms
98
 
const ENIG_KEYTYPE_DSA = 1;
99
 
const ENIG_KEYTYPE_RSA = 2;
100
 
 
101
 
 
102
 
// field ID's of key list (as described in the doc/DETAILS file in the GnuPG distribution)
103
 
const ENIG_KEY_TRUST=1;
104
 
const ENIG_KEY_ID = 4;
105
 
const ENIG_CREATED = 5;
106
 
const ENIG_EXPIRY = 6;
107
 
const ENIG_UID_ID = 7;
108
 
const ENIG_OWNERTRUST = 8;
109
 
const ENIG_USER_ID = 9;
110
 
const ENIG_SIG_TYPE = 10;
111
 
const ENIG_KEY_USE_FOR = 11;
112
 
 
113
 
const ENIG_KEY_EXPIRED="e";
114
 
const ENIG_KEY_REVOKED="r";
115
 
const ENIG_KEY_INVALID="i";
116
 
const ENIG_KEY_DISABLED="d";
117
 
const ENIG_KEY_NOT_VALID=ENIG_KEY_EXPIRED+ENIG_KEY_REVOKED+ENIG_KEY_INVALID+ENIG_KEY_DISABLED;
118
 
 
119
 
 
120
 
// Interfaces
121
 
const nsIEnigmail               = ENIG_I.nsIEnigmail;
122
 
 
123
 
// Encryption flags
124
 
if (nsIEnigmail) {
125
 
  const ENIG_SIGN    = nsIEnigmail.SEND_SIGNED;
126
 
  const ENIG_ENCRYPT = nsIEnigmail.SEND_ENCRYPTED;
127
 
  const ENIG_ENCRYPT_OR_SIGN = ENIG_ENCRYPT | ENIG_SIGN;
128
 
}
129
 
 
130
 
// UsePGPMimeOption values
131
 
const PGP_MIME_NEVER    = 0;
132
 
const PGP_MIME_POSSIBLE = 1;
133
 
const PGP_MIME_ALWAYS   = 2;
134
 
 
135
 
const ENIG_POSSIBLE_PGPMIME = -2081;
136
 
const ENIG_PGP_DESKTOP_ATT  = -2082;
137
 
 
138
 
var gUsePGPMimeOptionList = ["usePGPMimeNever", "usePGPMimePossible",
139
 
                             "usePGPMimeAlways"];
140
 
 
141
 
var gEnigRecipientsSelection = ["-",
142
 
                                "perRecipientRules",
143
 
                                "perRecipientRulesAndEmail",
144
 
                                "perEmailAddress",
145
 
                                "askRecipientsAlways"];
146
 
 
147
 
const ENIG_BUTTON_POS_0           = 1;
148
 
const ENIG_BUTTON_POS_1           = 1 << 8;
149
 
const ENIG_BUTTON_POS_2           = 1 << 16;
150
 
const ENIG_BUTTON_TITLE_IS_STRING = 127;
151
 
 
152
 
const ENIG_HEADERMODE_KEYID = 0x01;
153
 
const ENIG_HEADERMODE_URL   = 0x10;
154
 
 
155
 
 
156
 
 
157
 
function EnigGetFrame(win, frameName) {
158
 
  return EnigmailCommon.getFrame(win, frameName);
159
 
}
160
 
 
161
 
// Initializes enigmailCommon
162
 
function EnigInitCommon(id) {
163
 
   DEBUG_LOG("enigmailCommon.js: EnigInitCommon: id="+id+"\n");
164
 
 
165
 
   gEnigPromptSvc = enigGetService("@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService");
166
 
}
167
 
 
168
 
 
169
 
function GetEnigmailSvc() {
170
 
  if (! gEnigmailSvc)
171
 
    gEnigmailSvc = EnigmailCommon.getService(window);
172
 
  return gEnigmailSvc;
173
 
}
174
 
 
175
 
// maxBytes == -1 => read everything
176
 
function EnigReadURLContents(url, maxBytes) {
177
 
  DEBUG_LOG("enigmailCommon.js: EnigReadURLContents: url="+url+
178
 
            ", "+maxBytes+"\n");
179
 
 
180
 
  var ioServ = enigGetService(ENIG_IOSERVICE_CONTRACTID, "nsIIOService");
181
 
  if (!ioServ)
182
 
    throw Components.results.NS_ERROR_FAILURE;
183
 
 
184
 
  var fileChannel = ioServ.newChannel(url, null, null)
185
 
 
186
 
  var rawInStream = fileChannel.open();
187
 
 
188
 
  var inStream = ENIG_C[ENIG_BINARYINPUTSTREAM_CONTRACTID].createInstance(ENIG_I.nsIBinaryInputStream);
189
 
  inStream.setInputStream(rawInStream);
190
 
 
191
 
  var available = inStream.available()
192
 
  if ((maxBytes < 0) || (maxBytes > available))
193
 
    maxBytes = available;
194
 
 
195
 
  var data = inStream.readBytes(maxBytes);
196
 
 
197
 
  inStream.close();
198
 
 
199
 
  return data;
200
 
}
201
 
 
202
 
// maxBytes == -1 => read whole file
203
 
function EnigReadFileContents(localFile, maxBytes) {
204
 
 
205
 
  DEBUG_LOG("enigmailCommon.js: EnigReadFileContents: file="+localFile.leafName+
206
 
            ", "+maxBytes+"\n");
207
 
 
208
 
  if (!localFile.exists() || !localFile.isReadable())
209
 
    throw Components.results.NS_ERROR_FAILURE;
210
 
 
211
 
  var ioServ = enigGetService(ENIG_IOSERVICE_CONTRACTID, "nsIIOService");
212
 
  if (!ioServ)
213
 
    throw Components.results.NS_ERROR_FAILURE;
214
 
 
215
 
  var fileURI = ioServ.newFileURI(localFile);
216
 
  return EnigReadURLContents(fileURI.asciiSpec, maxBytes);
217
 
 
218
 
}
219
 
 
220
 
///////////////////////////////////////////////////////////////////////////////
221
 
 
222
 
function WRITE_LOG(str) {
223
 
  EnigmailCommon.WRITE_LOG(str);
224
 
}
225
 
 
226
 
function DEBUG_LOG(str) {
227
 
  EnigmailCommon.DEBUG_LOG(str);
228
 
}
229
 
 
230
 
function WARNING_LOG(str) {
231
 
  EnigmailCommon.WARNING_LOG(str);
232
 
}
233
 
 
234
 
function ERROR_LOG(str) {
235
 
  EnigmailCommon.ERROR_LOG(str);
236
 
}
237
 
 
238
 
function CONSOLE_LOG(str) {
239
 
  EnigmailCommon.CONSOLE_LOG(str);
240
 
}
241
 
 
242
 
 
243
 
// write exception information
244
 
function EnigWriteException(referenceInfo, ex) {
245
 
  EnigmailCommon.writeException(referenceInfo, ex);
246
 
}
247
 
 
248
 
///////////////////////////////////////////////////////////////////////////////
249
 
 
250
 
function EnigAlert(mesg) {
251
 
  return EnigmailCommon.alert(window, mesg);
252
 
}
253
 
 
254
 
/**
255
 
 * Displays an alert dialog with 3-4 optional buttons.
256
 
 * checkBoxLabel: if not null, display checkbox with text; the checkbox state is returned in checkedObj
257
 
 * button-Labels: use "&" to indicate access key
258
 
 *     use "buttonType:label" or ":buttonType" to indicate special button types
259
 
 *        (buttonType is one of cancel, help, extra1, extra2)
260
 
 * return: 0-2: button Number pressed
261
 
 *          -1: ESC or close window button pressed
262
 
 *
263
 
 */
264
 
function EnigLongAlert(mesg, checkBoxLabel, okLabel, labelButton2, labelButton3, checkedObj) {
265
 
  return EnigmailCommon.longAlert(window, mesg, checkBoxLabel, okLabel, labelButton2, labelButton3, checkedObj);
266
 
}
267
 
 
268
 
function EnigAlertPref(mesg, prefText) {
269
 
  return EnigmailCommon.alertPref(window, mesg, prefText);
270
 
}
271
 
 
272
 
// Confirmation dialog with OK / Cancel buttons (both customizable)
273
 
function EnigConfirm(mesg, okLabel, cancelLabel) {
274
 
  return EnigmailCommon.confirmDlg(window, mesg, okLabel, cancelLabel);
275
 
}
276
 
 
277
 
 
278
 
function EnigConfirmPref(mesg, prefText, okLabel, cancelLabel) {
279
 
  return EnigmailCommon.confirmPref(window, mesg, prefText, okLabel, cancelLabel);
280
 
}
281
 
 
282
 
function EnigError(mesg) {
283
 
  return gEnigPromptSvc.alert(window, EnigGetString("enigError"), mesg);
284
 
}
285
 
 
286
 
function EnigPrefWindow(showBasic, clientType, selectTab) {
287
 
  DEBUG_LOG("enigmailCommon.js: EnigPrefWindow\n");
288
 
  EnigmailFuncs.openPrefWindow(window, showBasic, selectTab);
289
 
}
290
 
 
291
 
 
292
 
function EnigHelpWindow(source) {
293
 
  EnigmailFuncs.openHelpWindow(source);
294
 
}
295
 
 
296
 
 
297
 
function EnigDisplayRadioPref(prefName, prefValue, optionElementIds) {
298
 
  DEBUG_LOG("enigmailCommon.js: EnigDisplayRadioPref: "+prefName+", "+prefValue+"\n");
299
 
 
300
 
  if (prefValue >= optionElementIds.length)
301
 
    return;
302
 
 
303
 
  var groupElement = document.getElementById("enigmail_"+prefName);
304
 
  var optionElement = document.getElementById(optionElementIds[prefValue]);
305
 
 
306
 
  if (groupElement && optionElement) {
307
 
    groupElement.selectedItem = optionElement;
308
 
    groupElement.value = prefValue;
309
 
  }
310
 
}
311
 
 
312
 
function EnigSetRadioPref(prefName, optionElementIds) {
313
 
  DEBUG_LOG("enigmailCommon.js: EnigSetRadioPref: "+prefName+"\n");
314
 
 
315
 
  try {
316
 
    var groupElement = document.getElementById("enigmail_"+prefName);
317
 
    if (groupElement) {
318
 
      var optionElement = groupElement.selectedItem;
319
 
      var prefValue = optionElement.value;
320
 
      if (prefValue < optionElementIds.length) {
321
 
        EnigSetPref(prefName, prefValue);
322
 
        groupElement.value = prefValue;
323
 
      }
324
 
    }
325
 
  }
326
 
  catch (ex) {}
327
 
}
328
 
 
329
 
function EnigSavePrefs() {
330
 
  return EnigmailCommon.savePrefs();
331
 
}
332
 
 
333
 
function EnigGetPref(prefName) {
334
 
  return EnigmailCommon.getPref(prefName);
335
 
}
336
 
 
337
 
function EnigGetDefaultPref(prefName) {
338
 
  DEBUG_LOG("enigmailCommon.js: EnigGetDefaultPref: prefName="+prefName+"\n");
339
 
  var prefValue=null;
340
 
  try {
341
 
    EnigmailCommon.prefBranch.lockPref(prefName);
342
 
    prefValue = EnigGetPref(prefName);
343
 
    EnigmailCommon.prefBranch.unlockPref(prefName);
344
 
  }
345
 
  catch (ex) {}
346
 
 
347
 
  return prefValue;
348
 
}
349
 
 
350
 
function EnigSetPref(prefName, value) {
351
 
  return EnigmailCommon.setPref(prefName, value);
352
 
}
353
 
 
354
 
function EnigGetSignMsg(identity) {
355
 
  EnigmailFuncs.getSignMsg(identity);
356
 
}
357
 
 
358
 
 
359
 
function EnigConvertFromUnicode(text, charset) {
360
 
  DEBUG_LOG("enigmailCommon.js: EnigConvertFromUnicode: "+charset+"\n");
361
 
 
362
 
  if (!text)
363
 
    return "";
364
 
 
365
 
  if (! charset) charset="utf-8";
366
 
 
367
 
  // Encode plaintext
368
 
  try {
369
 
    var unicodeConv = ENIG_C[ENIG_ISCRIPTABLEUNICODECONVERTER_CONTRACTID].getService(ENIG_I.nsIScriptableUnicodeConverter);
370
 
 
371
 
    unicodeConv.charset = charset;
372
 
    return unicodeConv.ConvertFromUnicode(text);
373
 
 
374
 
  } catch (ex) {
375
 
    DEBUG_LOG("enigmailCommon.js: EnigConvertFromUnicode: caught an exception\n");
376
 
 
377
 
    return text;
378
 
  }
379
 
}
380
 
 
381
 
 
382
 
function EnigConvertToUnicode(text, charset) {
383
 
  // DEBUG_LOG("enigmailCommon.js: EnigConvertToUnicode: "+charset+"\n");
384
 
 
385
 
  if (!text || !charset /*|| (charset.toLowerCase() == "iso-8859-1")*/)
386
 
    return text;
387
 
 
388
 
  // Encode plaintext
389
 
  try {
390
 
    var unicodeConv = ENIG_C[ENIG_ISCRIPTABLEUNICODECONVERTER_CONTRACTID].getService(ENIG_I.nsIScriptableUnicodeConverter);
391
 
 
392
 
    unicodeConv.charset = charset;
393
 
    return unicodeConv.ConvertToUnicode(text);
394
 
 
395
 
  } catch (ex) {
396
 
    DEBUG_LOG("enigmailCommon.js: EnigConvertToUnicode: caught an exception while converting'"+text+"' to "+charset+"\n");
397
 
    return text;
398
 
  }
399
 
}
400
 
 
401
 
function EnigConvertGpgToUnicode(text) {
402
 
  return EnigmailCommon.convertGpgToUnicode(text);
403
 
}
404
 
 
405
 
function EnigFormatFpr(fingerprint) {
406
 
  return EnigmailFuncs.formatFpr(fingerprint);
407
 
}
408
 
 
409
 
/////////////////////////
410
 
// Console stuff
411
 
/////////////////////////
412
 
 
413
 
 
414
 
// return the options passed to a window
415
 
function EnigGetWindowOptions() {
416
 
  var winOptions=[];
417
 
  if (window.location.search) {
418
 
    var optList=window.location.search.substr(1).split(/\&/);
419
 
    for (var i=0; i<optList.length; i++) {
420
 
      var anOption=optList[i].split(/\=/);
421
 
      winOptions[anOption[0]] = unescape(anOption[1]);
422
 
    }
423
 
  }
424
 
  return winOptions;
425
 
}
426
 
 
427
 
function EnigRulesEditor() {
428
 
  EnigmailFuncs.openRulesEditor();
429
 
}
430
 
 
431
 
function EngmailCardDetails() {
432
 
  EnigmailFuncs.openCardDetails();
433
 
}
434
 
 
435
 
function EnigKeygen() {
436
 
  EnigmailFuncs.openKeyGen();
437
 
 
438
 
}
439
 
 
440
 
// retrieves a localized string from the enigmail.properties stringbundle
441
 
function EnigGetString(aStr) {
442
 
  var argList = new Array();
443
 
  // unfortunately arguments.shift() doesn't work, so we use a workaround
444
 
 
445
 
  if (arguments.length > 1)
446
 
    for (let i=1; i<arguments.length; i++)
447
 
      argList.push(arguments[i]);
448
 
  return EnigmailCommon.getString(aStr, (arguments.length > 1 ? argList : null));
449
 
}
450
 
 
451
 
// Remove all quoted strings (and angle brackets) from a list of email
452
 
// addresses, returning a list of pure email addresses
453
 
function EnigStripEmail(mailAddrs) {
454
 
  return EnigmailFuncs.stripEmail(mailAddrs);
455
 
}
456
 
 
457
 
 
458
 
//get path for temporary directory (e.g. /tmp, C:\TEMP)
459
 
function EnigGetTempDir() {
460
 
  return EnigmailCommon.getTempDir();
461
 
}
462
 
 
463
 
// get the OS platform
464
 
function EnigGetOS () {
465
 
  return EnigmailCommon.getOS();
466
 
}
467
 
 
468
 
function EnigGetVersion() {
469
 
  return EnigmailCommon.getVersion();
470
 
}
471
 
 
472
 
function EnigDisplayPrefs(showDefault, showPrefs, setPrefs) {
473
 
  DEBUG_LOG("enigmailCommon.js: EnigDisplayPrefs\n");
474
 
 
475
 
  var obj = new Object;
476
 
  var prefList = EnigmailCommon.prefBranch.getChildList("",obj);
477
 
 
478
 
  for (var prefItem in prefList) {
479
 
    var prefName=prefList[prefItem];
480
 
    var prefElement = document.getElementById("enigmail_"+prefName);
481
 
 
482
 
    if (prefElement) {
483
 
      var prefType = EnigmailCommon.prefBranch.getPrefType(prefName);
484
 
      var prefValue;
485
 
      if (showDefault) {
486
 
        prefValue = EnigGetDefaultPref(prefName);
487
 
      }
488
 
      else {
489
 
        prefValue = EnigGetPref(prefName);
490
 
      }
491
 
 
492
 
      DEBUG_LOG("enigmailCommon.js: EnigDisplayPrefs: "+prefName+"="+prefValue+"\n");
493
 
 
494
 
      switch (prefType) {
495
 
      case EnigmailCommon.prefBranch.PREF_BOOL:
496
 
        if (showPrefs) {
497
 
          if (prefElement.getAttribute("invert") == "true") {
498
 
            prefValue = ! prefValue;
499
 
          }
500
 
 
501
 
          if (prefValue) {
502
 
            prefElement.setAttribute("checked", "true");
503
 
          } else {
504
 
            prefElement.removeAttribute("checked");
505
 
          }
506
 
        }
507
 
 
508
 
        if (setPrefs) {
509
 
 
510
 
          if (prefElement.getAttribute("invert") == "true") {
511
 
            if (prefElement.checked) {
512
 
              EnigSetPref(prefName, false);
513
 
            } else {
514
 
              EnigSetPref(prefName, true);
515
 
            }
516
 
          }
517
 
          else {
518
 
            if (prefElement.checked) {
519
 
              EnigSetPref(prefName, true);
520
 
            } else {
521
 
              EnigSetPref(prefName, false);
522
 
            }
523
 
          }
524
 
        }
525
 
 
526
 
        break;
527
 
 
528
 
      case EnigmailCommon.prefBranch.PREF_INT:
529
 
        if (showPrefs)
530
 
          prefElement.value = prefValue;
531
 
 
532
 
        if (setPrefs) {
533
 
          try {
534
 
            EnigSetPref(prefName, 0+prefElement.value);
535
 
          } catch (ex) {}
536
 
        }
537
 
        break;
538
 
 
539
 
      case EnigmailCommon.prefBranch.PREF_STRING:
540
 
        if (showPrefs)
541
 
          prefElement.value = prefValue;
542
 
        if (setPrefs)
543
 
          EnigSetPref(prefName, prefElement.value);
544
 
        break;
545
 
 
546
 
      default:
547
 
        DEBUG_LOG("enigmailCommon.js: EnigDisplayPrefs: "+prefName+" does not have a type?!\n");
548
 
      }
549
 
    }
550
 
  }
551
 
}
552
 
 
553
 
function EnigFilePicker(title, displayDir, save, defaultExtension, defaultName, filterPairs) {
554
 
  return EnigmailCommon.filePicker(window, title, displayDir, save, defaultExtension,
555
 
                                   defaultName, filterPairs);
556
 
}
557
 
 
558
 
// get keys from keyserver
559
 
function EnigDownloadKeys(inputObj, resultObj) {
560
 
  return EnigmailFuncs.downloadKeys(window, inputObj, resultObj);
561
 
}
562
 
 
563
 
// create new PGP Rule
564
 
function EnigNewRule(emailAddress) {
565
 
  return EnigmailFuncs.createNewRule(window, emailAddress);
566
 
}
567
 
 
568
 
function EnigGetTrustCode(keyObj) {
569
 
  return EnigmailFuncs.getTrustCode(keyObj);
570
 
}
571
 
 
572
 
// Load the key list into memory
573
 
// sortDirection: 1 = ascending / -1 = descending
574
 
 
575
 
function EnigLoadKeyList(refresh, keyListObj, sortColumn, sortDirection) {
576
 
  return EnigmailFuncs.loadKeyList(window, refresh, keyListObj, sortColumn, sortDirection);
577
 
}
578
 
 
579
 
function EnigEditKeyTrust(userIdArr, keyIdArr) {
580
 
  return EnigmailFuncs.editKeyTrust(window, userIdArr, keyIdArr);
581
 
}
582
 
 
583
 
function EnigDisplayKeyDetails(keyId, refresh) {
584
 
  return EnigmailFuncs.openKeyDetails(window, keyId, refresh);
585
 
}
586
 
 
587
 
function EnigSignKey(userId, keyId, signingKeyHint) {
588
 
  return EnigmailFuncs.signKey(window, userId, keyId, signingKeyHint);
589
 
}
590
 
 
591
 
 
592
 
function EnigChangeKeyPwd(keyId, userId) {
593
 
 
594
 
  var enigmailSvc = GetEnigmailSvc();
595
 
  if (!enigmailSvc)
596
 
    return;
597
 
 
598
 
  if (! enigmailSvc.useGpgAgent()) {
599
 
    // no gpg-agent: open dialog to enter new passphrase
600
 
    var inputObj = {
601
 
      keyId: keyId,
602
 
      userId: userId
603
 
    };
604
 
 
605
 
    window.openDialog("chrome://enigmail/content/enigmailChangePasswd.xul",
606
 
        "", "dialog,modal,centerscreen", inputObj);
607
 
  }
608
 
  else {
609
 
    // gpg-agent used: gpg-agent will handle everything
610
 
    EnigmailKeyMgmt.changePassphrase(window, "0x"+keyId, "", "",
611
 
      function _changePwdCb(exitCode, errorMsg) {
612
 
        if (exitCode != 0) {
613
 
          EnigAlert(EnigGetString("changePassFailed")+"\n\n"+errorMsg);
614
 
        }
615
 
      });
616
 
  }
617
 
}
618
 
 
619
 
 
620
 
function EnigRevokeKey(keyId, userId, callbackFunc) {
621
 
  var enigmailSvc = GetEnigmailSvc();
622
 
  if (!enigmailSvc)
623
 
    return false;
624
 
 
625
 
  var userDesc="0x"+keyId.substr(-8,8)+" - "+userId;
626
 
  if (!EnigConfirm(EnigGetString("revokeKeyAsk", userDesc), EnigGetString("keyMan.button.revokeKey"))) return;
627
 
 
628
 
  var tmpDir=EnigGetTempDir();
629
 
 
630
 
  try {
631
 
    var revFile = ENIG_C[ENIG_LOCAL_FILE_CONTRACTID].createInstance(EnigGetLocalFileApi());
632
 
    revFile.initWithPath(tmpDir);
633
 
    if (!(revFile.isDirectory() && revFile.isWritable())) {
634
 
      EnigAlert(EnigGetString("noTempDir"));
635
 
      return false;
636
 
    }
637
 
  }
638
 
  catch (ex) {}
639
 
  revFile.append("revkey.asc");
640
 
 
641
 
  EnigmailKeyMgmt.genRevokeCert(window, "0x"+keyId, revFile, "0", "",
642
 
    function _revokeCertCb(exitCode, errorMsg) {
643
 
      if (exitCode != 0) {
644
 
        revFile.remove(false);
645
 
        EnigAlert(EnigGetString("revokeKeyFailed")+"\n\n"+errorMsg);
646
 
        return;
647
 
      }
648
 
      var errorMsgObj = {};
649
 
      var keyList = {};
650
 
      var r = enigmailSvc.importKeyFromFile(window, revFile, errorMsgObj, keyList);
651
 
      revFile.remove(false);
652
 
      if (r != 0) {
653
 
        EnigAlert(EnigGetString("revokeKeyFailed")+"\n\n"+EnigConvertGpgToUnicode(errorMsgObj.value));
654
 
      }
655
 
      else {
656
 
        EnigAlert(EnigGetString("revokeKeyOk"));
657
 
      }
658
 
      if (callbackFunc) {
659
 
        callbackFunc(r == 0);
660
 
      }
661
 
    });
662
 
}
663
 
 
664
 
function EnigGetLocalFileApi() {
665
 
  return EnigmailCommon.getLocalFileApi();
666
 
}
667
 
 
668
 
function EnigShowPhoto (keyId, userId, photoNumber) {
669
 
  EnigmailFuncs.showPhoto(window, keyId, userId, photoNumber);
670
 
}
671
 
 
672
 
function EnigGetFilePath (nsFileObj) {
673
 
  return EnigmailCommon.getFilePath(nsFileObj);
674
 
}
675
 
 
676
 
function EnigCreateRevokeCert(keyId, userId, callbackFunc) {
677
 
  var defaultFileName = userId.replace(/[\<\>]/g, "");
678
 
  defaultFileName += " (0x"+keyId.substr(-8,8)+") rev.asc"
679
 
  var outFile = EnigFilePicker(EnigGetString("saveRevokeCertAs"),
680
 
                               "", true, "*.asc",
681
 
                               defaultFileName,
682
 
                               [EnigGetString("asciiArmorFile"), "*.asc"]);
683
 
  if (! outFile) return -1;
684
 
 
685
 
  var enigmailSvc = GetEnigmailSvc();
686
 
  if (!enigmailSvc)
687
 
    return -1;
688
 
 
689
 
  var errorMsgObj = {};
690
 
  EnigmailKeyMgmt.genRevokeCert(window, "0x"+keyId, outFile, "1", "",
691
 
    function _revokeCertCb(exitCode, errorMsg) {
692
 
      if (exitCode != 0) {
693
 
        EnigAlert(EnigGetString("revokeCertFailed")+"\n\n"+errorMsg);
694
 
      }
695
 
      else {
696
 
        EnigAlert(EnigGetString("revokeCertOK"));
697
 
      }
698
 
 
699
 
      if (callbackFunc) callbackFunc(exitCode == 0);
700
 
    });
701
 
}
702
 
 
703
 
 
704
 
// return the label of trust for a given trust code
705
 
function EnigGetTrustLabel(trustCode) {
706
 
  var keyTrust;
707
 
  switch (trustCode) {
708
 
  case 'q':
709
 
    keyTrust=EnigGetString("keyValid.unknown");
710
 
    break;
711
 
  case 'i':
712
 
    keyTrust=EnigGetString("keyValid.invalid");
713
 
    break;
714
 
  case 'd':
715
 
  case 'D':
716
 
    keyTrust=EnigGetString("keyValid.disabled");
717
 
    break;
718
 
  case 'r':
719
 
    keyTrust=EnigGetString("keyValid.revoked");
720
 
    break;
721
 
  case 'e':
722
 
    keyTrust=EnigGetString("keyValid.expired");
723
 
    break;
724
 
  case 'n':
725
 
    keyTrust=EnigGetString("keyTrust.untrusted");
726
 
    break;
727
 
  case 'm':
728
 
    keyTrust=EnigGetString("keyTrust.marginal");
729
 
    break;
730
 
  case 'f':
731
 
    keyTrust=EnigGetString("keyTrust.full");
732
 
    break;
733
 
  case 'u':
734
 
    keyTrust=EnigGetString("keyTrust.ultimate");
735
 
    break;
736
 
  case 'g':
737
 
    keyTrust=EnigGetString("keyTrust.group");
738
 
    break;
739
 
  case '-':
740
 
    keyTrust="-";
741
 
    break;
742
 
  default:
743
 
    keyTrust="";
744
 
  }
745
 
  return keyTrust;
746
 
}
747
 
 
748
 
function EnigGetDateTime(dateNum, withDate, withTime) {
749
 
  return EnigmailCommon.getDateTime(dateNum, withDate, withTime);
750
 
}
751
 
 
752
 
function enigCreateInstance (aURL, aInterface)
753
 
{
754
 
  return ENIG_C[aURL].createInstance(ENIG_I[aInterface]);
755
 
}
756
 
 
757
 
function enigGetService (aURL, aInterface)
758
 
{
759
 
  // determine how 'aInterface' is passed and handle accordingly
760
 
  switch (typeof(aInterface))
761
 
  {
762
 
    case "object":
763
 
      return ENIG_C[aURL].getService(aInterface);
764
 
      break;
765
 
 
766
 
    case "string":
767
 
      return ENIG_C[aURL].getService(ENIG_I[aInterface]);
768
 
      break;
769
 
 
770
 
    default:
771
 
      return ENIG_C[aURL].getService();
772
 
  }
773
 
 
774
 
  return null;
775
 
}
776
 
 
777
 
function EnigCollapseAdvanced(obj, attribute, dummy) {
778
 
  return EnigmailFuncs.collapseAdvanced(obj, attribute, dummy);
779
 
}
780
 
 
781
 
 
782
 
function EnigOpenURL(event, hrefObj) {
783
 
  var xulAppinfo = ENIG_C["@mozilla.org/xre/app-info;1"].getService(ENIG_I.nsIXULAppInfo);
784
 
  if (xulAppinfo.ID == ENIG_SEAMONKEY_ID) return;
785
 
 
786
 
  try {
787
 
    var ioservice  = ENIG_C["@mozilla.org/network/io-service;1"].
788
 
                  getService(ENIG_I.nsIIOService);
789
 
    var iUri = ioservice.newURI(hrefObj.href, null, null);
790
 
    var eps  = ENIG_C["@mozilla.org/uriloader/external-protocol-service;1"].
791
 
                  getService(ENIG_I.nsIExternalProtocolService);
792
 
 
793
 
    eps.loadURI(iUri, null);
794
 
 
795
 
    event.preventDefault();
796
 
    event.stopPropagation();
797
 
  }
798
 
  catch (ex) {}
799
 
}
800