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

« back to all changes in this revision

Viewing changes to mailnews/extensions/enigmail/ui/content/enigmailSetupWizard.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 Patrick Brunschwig.
 
17
 * Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org> are
 
18
 * Copyright (C) 2005 Patrick Brunschwig. All Rights Reserved.
 
19
 *
 
20
 * Contributor(s):
 
21
 *
 
22
 * Alternatively, the contents of this file may be used under the terms of
 
23
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
24
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
25
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
26
 * of those above. If you wish to allow use of your version of this file only
 
27
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
28
 * use your version of this file under the terms of the MPL, indicate your
 
29
 * decision by deleting the provisions above and replace them with the notice
 
30
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
31
 * the provisions above, a recipient may use your version of this file under
 
32
 * the terms of any one of the MPL, the GPL or the LGPL.
 
33
 * ***** END LICENSE BLOCK ***** */
 
34
 
 
35
Components.utils.import("resource://enigmail/enigmailCommon.jsm");
 
36
Components.utils.import("resource://enigmail/keyManagement.jsm");
 
37
 
 
38
// const Ec is already defined in enigmailKeygen.js
 
39
 
 
40
var gEnigModifySettings;
 
41
var gLastDirection=0;
 
42
var gEnigAccountMgr;
 
43
var gPubkeyFile = {value: null};
 
44
var gSeckeyFile = {value: null};
 
45
var gCreateNewKey=false;
 
46
var gPrefEnigmail;
 
47
 
 
48
 
 
49
EnigInitCommon("enigmailSetupWizard");
 
50
 
 
51
function onLoad() {
 
52
  gEnigModifySettings = {
 
53
    imapOnDemand: true,
 
54
    flowedText: true,
 
55
    viewPlainText: true,
 
56
    quotedPrintable: true,
 
57
    composeHTML: true
 
58
  };
 
59
  gEnigAccountMgr = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
 
60
 
 
61
  fillIdentities('checkbox');
 
62
}
 
63
 
 
64
 
 
65
function onCancel() {
 
66
  if (gKeygenRequest) {
 
67
    if (EnigConfirm(EnigGetString("keyAbort"), EnigGetString("keyMan.button.generateKeyAbort"), EnigGetString("keyMan.button.generateKeyContinue"))) {
 
68
      enigmailKeygenCloseRequest();
 
69
      return true;
 
70
    }
 
71
    else {
 
72
      return false;
 
73
    }
 
74
  }
 
75
  else {
 
76
    return (EnigLongAlert(EnigGetString("setupWizard.reallyCancel"), null, EnigGetString("dlg.button.close"), EnigGetString("dlg.button.continue")) == 0);
 
77
  }
 
78
}
 
79
 
 
80
 
 
81
function setLastPage() {
 
82
  var wizard = document.getElementById("enigmailSetupWizard");
 
83
  if (wizard.currentPage) {
 
84
    wizard.setAttribute("lastViewedPage", wizard.currentPage.pageid);
 
85
  }
 
86
}
 
87
 
 
88
function onBack() {
 
89
  DEBUG_LOG("onBack");
 
90
  gLastDirection=-1;
 
91
  setLastPage();
 
92
}
 
93
 
 
94
function onNext() {
 
95
  DEBUG_LOG("onNext");
 
96
  gLastDirection=1;
 
97
  setLastPage();
 
98
  var wizard = document.getElementById("enigmailSetupWizard");
 
99
  if (wizard.currentPage) {
 
100
    switch(wizard.currentPage.pageid) {
 
101
    case "pgKeySel":
 
102
      wizardSelKey();
 
103
      break;
 
104
    case "pgWelcome":
 
105
      checkIdentities();
 
106
      break;
 
107
    case "pgSettings":
 
108
      return loadKeys();
 
109
    case "pgKeyCreate":
 
110
      return checkPassphrase();
 
111
    }
 
112
  }
 
113
 
 
114
  return true;
 
115
}
 
116
 
 
117
function setNextPage(pageId) {
 
118
  var wizard = document.getElementById("enigmailSetupWizard");
 
119
  wizard.currentPage.next = pageId;
 
120
}
 
121
 
 
122
function disableNext(disable) {
 
123
  var wizard = document.getElementById("enigmailSetupWizard");
 
124
  wizard.getButton("next").disabled = disable;
 
125
}
 
126
 
 
127
 
 
128
function countSelectedId() {
 
129
  var idCount=0;
 
130
  var node = document.getElementById("idSelection").firstChild;
 
131
  while (node) {
 
132
    if (node.checked) {
 
133
      ++idCount;
 
134
    }
 
135
    node = node.nextSibling;
 
136
  }
 
137
  return idCount;
 
138
}
 
139
 
 
140
function browseKeyFile(referencedId, referencedVar) {
 
141
  var filePath = EnigFilePicker(EnigGetString("importKeyFile"),
 
142
                               "", false, "*.asc", "",
 
143
                               [EnigGetString("gnupgFile"), "*.asc;*.gpg;*.pgp"]);
 
144
 
 
145
  if (filePath) {
 
146
    document.getElementById(referencedId).value = EnigGetFilePath(filePath);
 
147
    referencedVar.value = filePath;
 
148
  }
 
149
}
 
150
 
 
151
function importKeyFiles() {
 
152
  if (document.getElementById("publicKeysFile").value.length == 0) {
 
153
    EnigAlert(EnigString("setupWizard.specifyFile"));
 
154
    return false;
 
155
  }
 
156
 
 
157
  var importedKeys;
 
158
  var exitCode;
 
159
 
 
160
  var enigmailSvc = enigGetSvc();
 
161
  if (! enigmailSvc) return false;
 
162
 
 
163
  var errorMsgObj = {};
 
164
  var keyListObj = {};
 
165
  exitCode = enigmailSvc.importKeyFromFile(window, gPubkeyFile.value, errorMsgObj, keyListObj);
 
166
  if (exitCode != 0) {
 
167
    EnigAlert(EnigGetString("importKeysFailed")+"\n\n"+errorMsgObj.value);
 
168
    return false;
 
169
  }
 
170
  importedKeys = keyListObj.value;
 
171
 
 
172
  if (document.getElementById("privateKeysFile").value.length > 0) {
 
173
 
 
174
    exitCode = enigmailSvc.importKeyFromFile(window, gSeckeyFile.value, errorMsgObj, keyListObj);
 
175
    if (exitCode != 0) {
 
176
      EnigAlert(EnigGetString("importKeysFailed")+"\n\n"+errorMsgObj.value);
 
177
      return false;
 
178
    }
 
179
    importedKeys += keyListObj.value;
 
180
  }
 
181
 
 
182
 
 
183
  exitCode = 0;
 
184
  var keyList=importedKeys.split(/;/);
 
185
  setKeyTrustNextKey(keyList, 0);
 
186
 
 
187
  return true;
 
188
}
 
189
 
 
190
function setKeyTrustNextKey(keyList, index) {
 
191
  Ec.DEBUG_LOG("enigmailSetupWizard.js: setKeyTrustNextKey("+index+")\n");
 
192
 
 
193
  var aKey = keyList[index].split(/:/);
 
194
  if (Number(aKey[1]) & 16) {
 
195
    // imported key contains secret key
 
196
    EnigmailKeyMgmt.setKeyTrust(window, aKey[0], 5,
 
197
      function(exitCode, errorMsg) {
 
198
        if (exitCode != 0) {
 
199
          return;
 
200
        }
 
201
 
 
202
        ++index;
 
203
        if (index < keyList.length) {
 
204
          setKeyTrustNextKey(keyList, index);
 
205
        }
 
206
        else
 
207
          loadKeys();
 
208
      }
 
209
    );
 
210
  }
 
211
  else {
 
212
    ++index;
 
213
    if (index < keyList.length) {
 
214
      setKeyTrustNextKey(keyList, index);
 
215
    }
 
216
    else
 
217
      loadKeys();
 
218
  }
 
219
}
 
220
 
 
221
 
 
222
function displayKeyCreate() {
 
223
  if (gLastDirection == 1) {
 
224
    fillIdentities('menulist');
 
225
  }
 
226
 
 
227
  if (countSelectedId() == 1) {
 
228
    var node = document.getElementById("idSelection").firstChild;
 
229
    while (node) {
 
230
      if (node.checked) {
 
231
        var identity = gEnigAccountMgr.getIdentity(node.getAttribute("account-id"));
 
232
        var idName = identity.identityName;
 
233
 
 
234
        var serverList = queryISupArray(
 
235
                getServersForIdentity(gEnigAccountMgr, identity),
 
236
                Components.interfaces.nsIMsgIncomingServer);
 
237
 
 
238
        if (serverList.length > 0) {
 
239
          var inServer = serverList[0];
 
240
 
 
241
          idName += " - "+inServer.prettyName;
 
242
        }
 
243
        document.getElementById("userIdentityLabel").value = idName;
 
244
        break;
 
245
      }
 
246
      node = node.nextSibling;
 
247
    }
 
248
    document.getElementById("userIdentity").setAttribute("collapsed", "true");
 
249
    document.getElementById("userIdentityLabel").removeAttribute("collapsed");
 
250
 
 
251
  }
 
252
  else {
 
253
    document.getElementById("userIdentityLabel").setAttribute("collapsed", "true");
 
254
    document.getElementById("userIdentity").removeAttribute("collapsed");
 
255
  }
 
256
}
 
257
 
 
258
 
 
259
function displayKeySel() {
 
260
  var uidChildren = document.getElementById("uidSelectionChildren");
 
261
  if (document.getElementById("createPgpKey").value=="0") {
 
262
    setUseKey();
 
263
  }
 
264
  else {
 
265
    setNewKey();
 
266
  }
 
267
}
 
268
 
 
269
 
 
270
function clearKeyListEntries(){
 
271
  // remove all rows
 
272
  var treeChildren = document.getElementById("uidSelectionChildren");
 
273
  while (treeChildren.firstChild) {
 
274
    treeChildren.removeChild(treeChildren.firstChild);
 
275
  }
 
276
}
 
277
 
 
278
function onSetStartNow(doStart) {
 
279
  if (doStart) {
 
280
    setNextPage("pgSelectId");
 
281
  }
 
282
  else {
 
283
    setNextPage("pgNoStart");
 
284
  }
 
285
}
 
286
 
 
287
function onKeySelected() {
 
288
  var wizard = document.getElementById("enigmailSetupWizard");
 
289
  var uidSel = document.getElementById("uidSelection");
 
290
  disableNext(uidSel.view.selection.count == 0);
 
291
}
 
292
 
 
293
function wizardSetFocus() {
 
294
  document.getElementById("startNow").focus();
 
295
}
 
296
 
 
297
function loadKeys() {
 
298
  var wizard = document.getElementById("enigmailSetupWizard");
 
299
 
 
300
  var enigmailSvc = enigGetSvc();
 
301
 
 
302
  if (!enigmailSvc) {
 
303
    return false;
 
304
  }
 
305
  clearKeyListEntries();
 
306
 
 
307
  var exitCodeObj = {};
 
308
  var statusFlagsObj = {};
 
309
  var errorMsgObj = {};
 
310
  var keyList = Ec.getSecretKeys(window);
 
311
  if (keyList == null) {
 
312
    return false;
 
313
  }
 
314
 
 
315
 
 
316
  if (keyList.length ==0) {
 
317
    setNextPage("pgNoKeyFound");
 
318
    return true;
 
319
  }
 
320
 
 
321
  var uidChildren = document.getElementById("uidSelectionChildren");
 
322
  for (i=0; i < keyList.length; i++) {
 
323
    var item = uidChildren.appendChild( document.createElement('treeitem') );
 
324
    item.setAttribute("keyId", keyList[i].id);
 
325
    var row = item.appendChild(document.createElement('treerow'));
 
326
    var cell = row.appendChild( document.createElement('treecell') );
 
327
    cell.setAttribute('label', keyList[i].name);
 
328
    cell.setAttribute('observes', "bcKeyEnabled");
 
329
    cell = row.appendChild( document.createElement('treecell') );
 
330
    cell.setAttribute('label', "0x"+keyList[i].id.substr(-8,8));
 
331
    cell.setAttribute('observes', "bcKeyEnabled");
 
332
    cell = row.appendChild( document.createElement('treecell') );
 
333
    cell.setAttribute('label', keyList[i].created);
 
334
    cell.setAttribute('observes', "bcKeyEnabled");
 
335
  }
 
336
  onKeySelected();
 
337
  return true;
 
338
}
 
339
 
 
340
function enigGetSvc() {
 
341
  // Lazy initialization of enigmail JS component (for efficiency)
 
342
  // variant of GetEnigmailSvc function
 
343
 
 
344
  if (gEnigmailSvc) {
 
345
    return gEnigmailSvc.initialized ? gEnigmailSvc : null;
 
346
  }
 
347
 
 
348
  try {
 
349
    gEnigmailSvc = ENIG_C[ENIG_ENIGMAIL_CONTRACTID].createInstance(ENIG_I.nsIEnigmail);
 
350
 
 
351
  } catch (ex) {
 
352
    ERROR_LOG("enigmailWizard.js: Error in instantiating EnigmailService\n");
 
353
    return null;
 
354
  }
 
355
 
 
356
  DEBUG_LOG("enigmailWizard.js: gEnigmailSvc = "+gEnigmailSvc+"\n");
 
357
 
 
358
  while (!gEnigmailSvc.initialized) {
 
359
    // Try to initialize enigmail
 
360
 
 
361
    if (! gPrefEnigmail) {
 
362
      EnigmailCommon.initPrefService();
 
363
      gPrefEnigmail = EnigmailCommon.prefBranch;
 
364
    }
 
365
 
 
366
    try {
 
367
      // Initialize enigmail
 
368
      gEnigmailSvc.initialize(window, EnigGetVersion(), gPrefEnigmail);
 
369
 
 
370
      try {
 
371
        // Reset alert count to default value
 
372
        gPrefEnigmail.clearUserPref("initAlert");
 
373
      } catch(ex) {}
 
374
 
 
375
    } catch (ex) {
 
376
 
 
377
      // Display initialization error alert
 
378
      EnigAlert(EnigGetString("setupWizard.locateGpg"));
 
379
      var gpgPath = wizardLocateGpg();
 
380
      if (! gpgPath) {
 
381
        if (onCancel()) {
 
382
          window.close();
 
383
          return null;
 
384
        }
 
385
      }
 
386
      else {
 
387
        EnigSetPref("agentPath", EnigGetFilePath(gpgPath));
 
388
      }
 
389
    }
 
390
 
 
391
    var configuredVersion = EnigGetPref("configuredVersion");
 
392
 
 
393
    DEBUG_LOG("enigmailWizard.js: enigGetSvc: "+configuredVersion+"\n");
 
394
 
 
395
  }
 
396
 
 
397
  return gEnigmailSvc.initialized ? gEnigmailSvc : null;
 
398
}
 
399
 
 
400
function wizardLocateGpg() {
 
401
  var fileName="gpg";
 
402
  var ext="";
 
403
  if (navigator.platform.search(/Win/i) == 0) {
 
404
    ext=".exe";
 
405
  }
 
406
  var filePath = EnigFilePicker(EnigGetString("locateGpg"),
 
407
                           "", false, ext,
 
408
                           fileName+ext, null);
 
409
  return filePath;
 
410
}
 
411
 
 
412
function checkPassphrase() {
 
413
 
 
414
  var passphrase = enigmailCheckPassphrase();
 
415
  if (passphrase == null) return false;
 
416
 
 
417
  if (passphrase.length < 8) {
 
418
    EnigAlert(EnigGetString("passphrase.min8keys"));
 
419
    return false;
 
420
  }
 
421
  return true;
 
422
 
 
423
}
 
424
 
 
425
function wizardGenKey() {
 
426
  var wizard = document.getElementById("enigmailSetupWizard");
 
427
  var passphrase = document.getElementById("passphrase").value;
 
428
 
 
429
  var curId = wizardGetSelectedIdentity();
 
430
 
 
431
  var userName = curId.fullName;
 
432
  var userEmail = curId.email;
 
433
 
 
434
  var ipcRequest = null;
 
435
  var listener = {
 
436
      onStartRequest: function () {},
 
437
      onStopRequest: function(status) {
 
438
        wizardKeygenTerminate(status);
 
439
      },
 
440
      onDataAvailable: function(data) {
 
441
        DEBUG_LOG("enigmailSetupWizard.js: genKey - onDataAvailable() "+data+"\n");
 
442
 
 
443
        gAllData += data;
 
444
        var keyCreatedIndex = gAllData.indexOf("[GNUPG:] KEY_CREATED");
 
445
        if (keyCreatedIndex >0) {
 
446
          gGeneratedKey = gAllData.substr(keyCreatedIndex);
 
447
          gGeneratedKey = gGeneratedKey.replace(/(.*\[GNUPG:\] KEY_CREATED . )([a-fA-F0-9]+)([\n\r].*)*/, "$2");
 
448
          gAllData = gAllData.replace(/\[GNUPG:\] KEY_CREATED . [a-fA-F0-9]+[\n\r]/, "");
 
449
        }
 
450
        gAllData = gAllData.replace(/[\r\n]*\[GNUPG:\] GOOD_PASSPHRASE/g, "").replace(/([\r\n]*\[GNUPG:\] PROGRESS primegen )(.)( \d+ \d+)/g, "$2");
 
451
        var progMeter = document.getElementById("keygenProgress");
 
452
        var progValue = Number(progMeter.value);
 
453
        progValue += (1+(100-progValue)/200);
 
454
        if (progValue >= 95) progValue=10;
 
455
        progMeter.setAttribute("value", progValue);
 
456
      }
 
457
  };
 
458
  wizard.getButton("next").disabled = true;
 
459
  wizard.getButton("back").disabled = true;
 
460
 
 
461
  try {
 
462
    gKeygenRequest = Ec.generateKey(window,
 
463
                       Ec.convertFromUnicode(userName),
 
464
                       "",
 
465
                       userEmail,
 
466
                       365*5 /* 5 years */,
 
467
                       2048,
 
468
                       ENIG_KEYTYPE_RSA,
 
469
                       passphrase,
 
470
                       listener);
 
471
  } catch (ex) {
 
472
    Ec.DEBUG_LOG("enigmailSetupWizard.js: genKey - generateKey() failed with "+ex.toString()+"\n"+ex.stack+"\n");
 
473
  }
 
474
 
 
475
  if (!gKeygenRequest) {
 
476
    EnigAlert(EnigGetString("keyGenFailed"));
 
477
    wizard.getButton("back").disabled = false;
 
478
    return false;
 
479
  }
 
480
 
 
481
  WRITE_LOG("enigmailKeygen.js: Start: gKeygenRequest = "+gKeygenRequest+"\n");
 
482
  return false;
 
483
}
 
484
 
 
485
function wizardSelKey() {
 
486
  // use existing key
 
487
  var createKey=document.getElementById("createPgpKey");
 
488
  if (createKey.value == "0") {
 
489
    var uidSel = document.getElementById("uidSelection");
 
490
    var currIndex = uidSel.view.selection.currentIndex;
 
491
    var currItem = uidSel.view.getItemAtIndex(currIndex);
 
492
    gGeneratedKey = currItem.getAttribute("keyId");
 
493
  }
 
494
}
 
495
 
 
496
 
 
497
function queryISupArray(supportsArray, iid) {
 
498
  var result = [];
 
499
  var i;
 
500
  try {
 
501
    // Gecko <= 20
 
502
    for (i=0; i<supportsArray.Count(); i++) {
 
503
      result.push(supportsArray.GetElementAt(i).QueryInterface(iid));
 
504
    }
 
505
  }
 
506
  catch(ex) {
 
507
    // Gecko > 20
 
508
    for (i=0; i<supportsArray.length; i++) {
 
509
      result.push(supportsArray.queryElementAt(i, iid));
 
510
    }
 
511
  }
 
512
 
 
513
  return result;
 
514
}
 
515
 
 
516
function countIdentities() {
 
517
  var accountManager = Components.classes[ENIG_ACCOUNT_MANAGER_CONTRACTID].getService(Components.interfaces.nsIMsgAccountManager);
 
518
  var idSupports = accountManager.allIdentities;
 
519
  var identities = queryISupArray(idSupports,
 
520
                                       Components.interfaces.nsIMsgIdentity);
 
521
  return identities.length;
 
522
}
 
523
 
 
524
function checkIdentities() {
 
525
  var wizard = document.getElementById("enigmailSetupWizard");
 
526
 
 
527
  if (wizard.currentPage.next != "pgNoStart") {
 
528
    if (countIdentities() <= 1) {
 
529
      setNextPage("pgSign");
 
530
    }
 
531
  }
 
532
}
 
533
 
 
534
 
 
535
function fillIdentities(fillType)
 
536
{
 
537
  DEBUG_LOG("enigmailSetupWizard.js: fillIdentities\n");
 
538
 
 
539
  var defIdentity;
 
540
  var parentElement;
 
541
  var identities = queryISupArray(gEnigAccountMgr.allIdentities,
 
542
                                       Components.interfaces.nsIMsgIdentity);
 
543
 
 
544
  if (fillType == "checkbox") {
 
545
    parentElement = document.getElementById("idSelection");
 
546
  }
 
547
  else {
 
548
    parentElement = document.getElementById("userIdentityPopup");
 
549
 
 
550
    // Find out default identity
 
551
    var defIdentities = gEnigAccountMgr.defaultAccount.identities;
 
552
    try {
 
553
      // Gecko >= 20
 
554
      if (defIdentities.length >= 1) {
 
555
        defIdentity = defIdentities.queryElementAt(0, Components.interfaces.nsIMsgIdentity);
 
556
      } else {
 
557
        defIdentity = identities[0];
 
558
      }
 
559
    }
 
560
    catch (ex) {
 
561
      // Gecko < 20
 
562
      if (defIdentities.Count() >= 1) {
 
563
        defIdentity = defIdentities.QueryElementAt(0, Components.interfaces.nsIMsgIdentity);
 
564
      } else {
 
565
        defIdentity = identities[0];
 
566
      }
 
567
    }
 
568
 
 
569
    if (document.getElementById("activateId").value == "0") {
 
570
      // try to match with selected id
 
571
      var node = document.getElementById("idSelection").firstChild;
 
572
      while (node) {
 
573
        if (node.checked) {
 
574
          var currId = gEnigAccountMgr.getIdentity(node.getAttribute("account-id"));
 
575
          if (currId.key == defIdentity.key) {
 
576
            break;
 
577
          }
 
578
        }
 
579
        node = node.nextSibling;
 
580
      }
 
581
 
 
582
      // default ID wasn't selected, take 1st selected ID
 
583
      if (! node) {
 
584
        node = document.getElementById("idSelection").firstChild;
 
585
        while (node) {
 
586
          if (node.checked) {
 
587
            defIdentity = gEnigAccountMgr.getIdentity(node.getAttribute("account-id"));
 
588
            break;
 
589
          }
 
590
          node = node.nextSibling;
 
591
        }
 
592
      }
 
593
    }
 
594
  }
 
595
 
 
596
  var child=parentElement.firstChild;
 
597
  while (child) {
 
598
    parentElement.removeChild(child);
 
599
    child=parentElement.firstChild;
 
600
  }
 
601
 
 
602
  DEBUG_LOG("enigmailSetupWizard.js: fillIdentities: "+identities + "\n");
 
603
 
 
604
  var disableId = document.getElementById("activateId").value == "1";
 
605
  var selected = false;
 
606
  for (var i=0; i<identities.length; i++) {
 
607
    var identity = identities[i];
 
608
 
 
609
    DEBUG_LOG("id.valid="+identity.valid+"\n");
 
610
    if (!identity.valid || !identity.email)
 
611
      continue;
 
612
 
 
613
    var serverList = queryISupArray(
 
614
            getServersForIdentity(gEnigAccountMgr, identity),
 
615
            Components.interfaces.nsIMsgIncomingServer);
 
616
 
 
617
    if (serverList.length > 0) {
 
618
      var inServer = serverList[0];
 
619
 
 
620
      var accountName = " - "+inServer.prettyName;
 
621
 
 
622
      DEBUG_LOG("enigmailKeygen.js: accountName="+accountName+"\n");
 
623
      DEBUG_LOG("enigmailKeygen.js: email="+identity.email+"\n");
 
624
 
 
625
      if (fillType == "checkbox") {
 
626
        var item = document.createElement('checkbox');
 
627
        item.setAttribute('checked', "true");
 
628
        item.setAttribute('disabled', disableId);
 
629
        item.setAttribute('oncommand', "checkIdSelection()");
 
630
      }
 
631
      else {
 
632
        item = document.createElement('menuitem');
 
633
        item.setAttribute('label', identity.identityName + accountName);
 
634
        item.setAttribute('class', 'identity-popup-item');
 
635
      }
 
636
      item.setAttribute('label', identity.identityName + accountName);
 
637
      item.setAttribute('accountname', accountName);
 
638
      item.setAttribute('id', "acc-"+identity.key);
 
639
      item.setAttribute('account-id', identity.key);
 
640
      item.setAttribute('email', identity.email);
 
641
 
 
642
      parentElement.appendChild(item);
 
643
 
 
644
      if (fillType != "checkbox") {
 
645
        // pre-select default ID
 
646
        var idList = document.getElementById("userIdentity");
 
647
        if (!selected)
 
648
          idList.selectedItem = item;
 
649
        if (identity.key == defIdentity.key) {
 
650
          idList.selectedItem = item;
 
651
          selected = true;
 
652
        }
 
653
      }
 
654
    }
 
655
  }
 
656
}
 
657
 
 
658
function wizardGetSelectedIdentity()
 
659
{
 
660
  var item = document.getElementById("userIdentity").selectedItem;
 
661
  var identityKey = item.getAttribute('account-id');
 
662
 
 
663
  return gEnigAccountMgr.getIdentity(identityKey);
 
664
}
 
665
 
 
666
function applyWizardSettings() {
 
667
  DEBUG_LOG("enigmailSetupWizard.js: applyWizardSettings\n");
 
668
 
 
669
  loadLastPage();
 
670
 
 
671
  if (document.getElementById("activateId").value == "1") {
 
672
    var idSupports = gEnigAccountMgr.allIdentities;
 
673
    var identities = queryISupArray(idSupports,
 
674
                                       Components.interfaces.nsIMsgIdentity);
 
675
    for (var i=0; i<identities.length; i++) {
 
676
      wizardApplyId(identities[i], gGeneratedKey);
 
677
    }
 
678
  }
 
679
  else {
 
680
    var node = document.getElementById("idSelection").firstChild;
 
681
    while (node) {
 
682
      if (node.checked) {
 
683
        var identity = gEnigAccountMgr.getIdentity(node.getAttribute("account-id"));
 
684
        wizardApplyId(identity, gGeneratedKey);
 
685
      }
 
686
      node = node.nextSibling;
 
687
    }
 
688
  }
 
689
 
 
690
  applyMozSetting("imapOnDemand", "mail.server.default.mime_parts_on_demand", false);
 
691
  applyMozSetting("flowedText" ,"mailnews.send_plaintext_flowed", false);
 
692
  applyMozSetting("quotedPrintable", "mail.strictly_mime", false);
 
693
  applyMozSetting("viewPlainText", "mailnews.display.html_as", 1);
 
694
  applyMozSetting("viewPlainText", "mailnews.display.prefer_plaintext", true);
 
695
 
 
696
  EnigSetPref("configuredVersion", EnigGetVersion());
 
697
  EnigSavePrefs();
 
698
}
 
699
 
 
700
function applyMozSetting(param, preference, newVal) {
 
701
  if (gEnigModifySettings[param]) {
 
702
    if (typeof(newVal)=="boolean") {
 
703
      EnigmailCommon.prefRoot.setBoolPref(preference, newVal);
 
704
    }
 
705
    else if (typeof(newVal)=="number") {
 
706
      EnigmailCommon.prefRoot.setIntPref(preference, newVal);
 
707
    }
 
708
    else if (typeof(newVal)=="string") {
 
709
      EnigmailCommon.prefRoot.setCharPref(preference, newVal);
 
710
    }
 
711
  }
 
712
}
 
713
 
 
714
function wizardApplyId(identity, keyId) {
 
715
  DEBUG_LOG("enigmailSetupWizard.js: wizardApplyId: identity.Key="+identity.key+"\n");
 
716
  var accountManager = Components.classes[ENIG_ACCOUNT_MANAGER_CONTRACTID].getService(Components.interfaces.nsIMsgAccountManager);
 
717
  var idServers = getServersForIdentity(accountManager, identity);
 
718
  var servers = queryISupArray(idServers ,Components.interfaces.nsIMsgIncomingServer);
 
719
 
 
720
  var newsServer = false;
 
721
  for (var i=0; i<servers.length; i++) {
 
722
    newsServer = (servers[i].localStoreType == "news");
 
723
  }
 
724
 
 
725
  identity.setBoolAttribute("enablePgp", true);
 
726
  identity.setIntAttribute("pgpKeyMode", 1);
 
727
  identity.setCharAttribute("pgpkeyId", "0x"+keyId.substr(-8,8));
 
728
  identity.setIntAttribute("openPgpHeaderMode", 0);
 
729
 
 
730
  var signMsg = (document.getElementById("signMsg").value== "1");
 
731
  var encryptMsg = ((!newsServer) && (document.getElementById("encryptMsg").value== "1"));
 
732
 
 
733
  identity.setBoolAttribute("pgpSignEncrypted", signMsg);
 
734
  identity.setBoolAttribute("pgpSignPlain", signMsg);
 
735
  identity.setIntAttribute("defaultEncryptionPolicy", (encryptMsg ? 1 : 0));
 
736
  if ((document.getElementById("changeSettings").value == "1") &&
 
737
      gEnigModifySettings["composeHTML"]) {
 
738
    identity.setBoolAttribute("compose_html", false);
 
739
  }
 
740
}
 
741
 
 
742
 
 
743
function wizardKeygenTerminate(exitCode) {
 
744
  DEBUG_LOG("enigmailSetupWizard.js: wizardKeygenTerminate\n");
 
745
 
 
746
  // Give focus to this window
 
747
  window.focus();
 
748
 
 
749
  gKeygenRequest = null;
 
750
 
 
751
  if ((! gGeneratedKey) || gGeneratedKey == KEYGEN_CANCELLED) return;
 
752
 
 
753
  var progMeter = document.getElementById("keygenProgress");
 
754
  progMeter.setAttribute("value", 100);
 
755
 
 
756
  var curId = wizardGetSelectedIdentity();
 
757
 
 
758
  if (EnigConfirm(EnigGetString("keygenComplete", curId.email)+"\n\n"+EnigGetString("revokeCertRecommended"), EnigGetString("keyMan.button.generateCert"), EnigGetString("dlg.button.skip"))) {
 
759
    EnigCreateRevokeCert(gGeneratedKey, curId.email, wizardKeygenCleanup);
 
760
  }
 
761
  else
 
762
    wizardKeygenCleanup();
 
763
 
 
764
}
 
765
 
 
766
function wizardKeygenCleanup() {
 
767
  DEBUG_LOG("enigmailSetupWizard.js: wizardKeygenCleanup\n");
 
768
  enigmailKeygenCloseRequest();
 
769
  var enigmailSvc = enigGetSvc();
 
770
  enigmailSvc.invalidateUserIdList();
 
771
 
 
772
  var wizard = document.getElementById("enigmailSetupWizard");
 
773
  wizard.goTo("pgComplete");
 
774
}
 
775
 
 
776
 
 
777
function disableIdSel(doDisable) {
 
778
  var idSelectionBox = document.getElementById("idSelection");
 
779
  var node = idSelectionBox.firstChild;
 
780
  while (node) {
 
781
    node.setAttribute('disabled',doDisable);
 
782
    node = node.nextSibling;
 
783
  }
 
784
 
 
785
  if (doDisable) {
 
786
    disableNext(false);
 
787
  }
 
788
  else {
 
789
    checkIdSelection();
 
790
  }
 
791
}
 
792
 
 
793
function checkIdSelection() {
 
794
  var node = document.getElementById("idSelection").firstChild;
 
795
 
 
796
  disableNext(countSelectedId() < 1);
 
797
}
 
798
 
 
799
function showPrefDetails() {
 
800
 
 
801
  window.openDialog("chrome://enigmail/content/enigmailWizardPrefs.xul",
 
802
            "", "chrome,modal,centerscreen", gEnigModifySettings);
 
803
  return true;
 
804
}
 
805
 
 
806
 
 
807
function loadLastPage() {
 
808
  var wizard = document.getElementById("enigmailSetupWizard");
 
809
  wizard.canRewind=false;
 
810
  wizard.getButton("cancel").disabled = true;
 
811
}
 
812
 
 
813
 
 
814
function setNewKey() {
 
815
  setNextPage('pgKeyCreate');
 
816
  disableNext(false);
 
817
  gCreateNewKey = true;
 
818
  document.getElementById("uidSelection").boxObject.element.setAttribute("disabled", "true");
 
819
}
 
820
 
 
821
function setUseKey() {
 
822
  setNextPage('pgSummary');
 
823
  gCreateNewKey = false;
 
824
  document.getElementById("uidSelection").boxObject.element.removeAttribute("disabled");
 
825
  onKeySelected();
 
826
}
 
827
 
 
828
function setImportKeys() {
 
829
  setNextPage('pgKeyImport');
 
830
  gCreateNewKey = false;
 
831
  disableNext(false);
 
832
  document.getElementById("uidSelection").boxObject.element.setAttribute("disabled", "true");
 
833
}
 
834
 
 
835
function displayActions() {
 
836
 
 
837
  var currItem=0;
 
838
  function appendDesc(what) {
 
839
    ++currItem;
 
840
    var item = document.getElementById("applyDesc"+currItem);
 
841
    item.value="\u2013 "+what;
 
842
    item.removeAttribute("collapsed");
 
843
  }
 
844
 
 
845
  var createKey1=document.getElementById("createPgpKey");
 
846
  var createKey2=document.getElementById("newPgpKey");
 
847
 
 
848
  if (gCreateNewKey ||
 
849
      document.getElementById("pgSettings").next == "pgKeyCreate") {
 
850
    setNextPage('pgKeygen');
 
851
    appendDesc(EnigGetString("setupWizard.createKey"));
 
852
  }
 
853
  else {
 
854
    setNextPage('pgComplete');
 
855
    appendDesc(EnigGetString("setupWizard.useKey", gGeneratedKey));
 
856
  }
 
857
 
 
858
  var descList=document.getElementById("appliedSettings");
 
859
 
 
860
  if (countIdentities() >1) {
 
861
    if (document.getElementById("activateId").value == "1") {
 
862
      appendDesc(EnigGetString("setupWizard.applyAllId"));
 
863
    }
 
864
    else {
 
865
      var idList = "";
 
866
      var node = document.getElementById("idSelection").firstChild;
 
867
      while (node) {
 
868
        if (node.checked) {
 
869
          var identity = gEnigAccountMgr.getIdentity(node.getAttribute("account-id"));
 
870
          idList+="<"+identity.email+"> ";
 
871
        }
 
872
        node = node.nextSibling;
 
873
      }
 
874
      appendDesc(EnigGetString("setupWizard.applySomeId", idList));
 
875
    }
 
876
  }
 
877
  else {
 
878
    appendDesc(EnigGetString("setupWizard.applySingleId", idList));
 
879
  }
 
880
 
 
881
  if (document.getElementById("signMsg").value== "1") {
 
882
    appendDesc(EnigGetString("setupWizard.signAll"));
 
883
  }
 
884
  else {
 
885
    appendDesc(EnigGetString("setupWizard.signNone"));
 
886
  }
 
887
 
 
888
  if (document.getElementById("encryptMsg").value== "1") {
 
889
    appendDesc(EnigGetString("setupWizard.encryptAll"));
 
890
  }
 
891
  else {
 
892
    appendDesc(EnigGetString("setupWizard.encryptNone"));
 
893
  }
 
894
 
 
895
  if (document.getElementById("changeSettings").value == "1") {
 
896
    if (gEnigModifySettings["imapOnDemand"] &&
 
897
        gEnigModifySettings["flowedText"] &&
 
898
        gEnigModifySettings["quotedPrintable"] &&
 
899
        gEnigModifySettings["viewPlainText"] &&
 
900
        gEnigModifySettings["composeHTML"]) {
 
901
      appendDesc(EnigGetString("setupWizard.setAllPrefs"));
 
902
    }
 
903
    else if (gEnigModifySettings["imapOnDemand"] ||
 
904
        gEnigModifySettings["flowedText"] ||
 
905
        gEnigModifySettings["quotedPrintable"] ||
 
906
        gEnigModifySettings["viewPlainText"] ||
 
907
        gEnigModifySettings["composeHTML"]) {
 
908
      appendDesc(EnigGetString("setupWizard.setSomePrefs"));
 
909
    }
 
910
    else {
 
911
      appendDesc(EnigGetString("setupWizard.setNoPrefs"));
 
912
    }
 
913
  }
 
914
  else {
 
915
    appendDesc(EnigGetString("setupWizard.setNoPrefs"));
 
916
  }
 
917
}
 
918
 
 
919
// Helper function
 
920
function getServersForIdentity(accMgr, identity) {
 
921
  try {
 
922
    // Gecko >= 20
 
923
    return accMgr.getServersForIdentity(identity);
 
924
  }
 
925
  catch(ex) {
 
926
    // Gecko < 20
 
927
    return accMgr.GetServersForIdentity(identity);
 
928
  }
 
929
}