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

« back to all changes in this revision

Viewing changes to mailnews/extensions/enigmail/ui/content/enigmailCardDetails.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/commonFuncs.jsm");
 
36
Components.utils.import("resource://enigmail/enigmailCommon.jsm");
 
37
Components.utils.import("resource://enigmail/keyManagement.jsm");
 
38
 
 
39
const Ec = EnigmailCommon;
 
40
 
 
41
var gCardData = {};
 
42
 
 
43
function onLoad() {
 
44
  var enigmailSvc = Ec.getService(window);
 
45
  if (!enigmailSvc) {
 
46
    Ec.dispatchEvent(failWithError, 0, Ec.getString("accessError"));
 
47
    return;
 
48
  }
 
49
  var exitCodeObj = new Object();
 
50
  var errorMsgObj = new Object();
 
51
 
 
52
  var dryRun=false;
 
53
  try {
 
54
    dryRun = Ec.getPref("dryRun");
 
55
  }
 
56
  catch(ex) {}
 
57
 
 
58
  var cardStr = enigmailSvc.getCardStatus(exitCodeObj, errorMsgObj);
 
59
  if (exitCodeObj.value == 0) {
 
60
    var statusList=cardStr.split(/[\r\n]+/);
 
61
    for (var i=0; i<statusList.length; i++) {
 
62
      var l=statusList[i].split(/:/);
 
63
      switch (l[0]) {
 
64
      case "name":
 
65
        setValue("firstname", Ec.convertGpgToUnicode(l[1]));
 
66
        setValue(l[0], Ec.convertGpgToUnicode(l[2]));
 
67
        break;
 
68
      case "vendor":
 
69
        setValue(l[0], Ec.convertGpgToUnicode(l[2].replace(/\\x3a/ig, ":")));
 
70
        break;
 
71
      case "sex":
 
72
      case "forcepin":
 
73
        var selItem = document.getElementById("card_"+l[0]+"_"+l[1]);
 
74
        document.getElementById("card_"+l[0]).selectedItem = selItem;
 
75
        gCardData[l[0]] = l[1];
 
76
        break;
 
77
      case "pinretry":
 
78
      case "maxpinlen":
 
79
        setValue(l[0], l[1]+" / "+l[2]+" / "+l[3]);
 
80
        break;
 
81
      case "fpr":
 
82
        setValue("key_fpr_1", EnigmailFuncs.formatFpr(l[1]));
 
83
        setValue("key_fpr_2", EnigmailFuncs.formatFpr(l[2]));
 
84
        setValue("key_fpr_3", EnigmailFuncs.formatFpr(l[3]));
 
85
        break;
 
86
      case "fprtime":
 
87
        setValue("card_key_created_1", Ec.getDateTime(l[1]), true, false);
 
88
        setValue("card_key_created_2", Ec.getDateTime(l[2]), true, false);
 
89
        setValue("card_key_created_3", Ec.getDateTime(l[3]), true, false);
 
90
        break;
 
91
      default:
 
92
        if (l[0]) {
 
93
          setValue(l[0], Ec.convertGpgToUnicode(l[1].replace(/\\x3a/ig, ":")));
 
94
        }
 
95
      }
 
96
    }
 
97
  }
 
98
  else {
 
99
    if (! dryRun) {
 
100
      Ec.dispatchEvent(failWithError, 0, errorMsgObj.value);
 
101
    }
 
102
  }
 
103
  return;
 
104
}
 
105
 
 
106
function failWithError(errorMsg) {
 
107
  Ec.alert(window, errorMsg);
 
108
  window.close();
 
109
}
 
110
 
 
111
 
 
112
function setValue(attrib, value) {
 
113
  var elem = document.getElementById("card_"+attrib);
 
114
  if (elem) {
 
115
    elem.value = value;
 
116
  }
 
117
  gCardData[attrib] = value;
 
118
}
 
119
 
 
120
function getValue(attrib) {
 
121
  var elem = document.getElementById("card_"+attrib);
 
122
  if (elem) {
 
123
    return elem.value;
 
124
  }
 
125
  else {
 
126
    return "";
 
127
  }
 
128
}
 
129
 
 
130
function getSelection(attrib) {
 
131
  var elem = document.getElementById("card_"+attrib);
 
132
  if (elem) {
 
133
    return elem.selectedItem.value;
 
134
  }
 
135
  else {
 
136
    return "";
 
137
  }
 
138
}
 
139
 
 
140
function doEditData() {
 
141
  document.getElementById("bcEditMode").removeAttribute("readonly");
 
142
  document.getElementById("bcEnableMode").removeAttribute("disabled");
 
143
}
 
144
 
 
145
function doReset() {
 
146
  document.getElementById("bcEditMode").setAttribute("readonly", "true");
 
147
  document.getElementById("bcEnableMode").setAttribute("disabled", "true");
 
148
  onLoad();
 
149
}
 
150
 
 
151
function doSaveChanges() {
 
152
  document.getElementById("bcEditMode").setAttribute("readonly", "true");
 
153
  document.getElementById("bcEnableMode").setAttribute("disabled", "true");
 
154
 
 
155
  var enigmailSvc = Ec.getService(window);
 
156
  if (!enigmailSvc) {
 
157
    Ec.alert(window, Ec.getString("accessError"));
 
158
    window.close();
 
159
    return;
 
160
  }
 
161
 
 
162
  var forcepin = (getSelection("forcepin") == gCardData.forcepin ? 0 : 1);
 
163
  EnigmailKeyMgmt.cardAdminData(window,
 
164
                                  Ec.convertFromUnicode(getValue("name")),
 
165
                                  Ec.convertFromUnicode(getValue("firstname")),
 
166
                                  getValue("lang"),
 
167
                                  getSelection("sex"),
 
168
                                  Ec.convertFromUnicode(getValue("url")),
 
169
                                  getValue("login"),
 
170
                                  forcepin,
 
171
    function _cardAdminCb(exitCode, errorMsg) {
 
172
      if (exitCode != 0) {
 
173
        Ec.alert(window, errorMsg);
 
174
      }
 
175
 
 
176
      onLoad();
 
177
    });
 
178
}
 
179
 
 
180
function engmailGenerateCardKey() {
 
181
  window.openDialog("chrome://enigmail/content/enigmailGenCardKey.xul",
 
182
        "", "dialog,modal,centerscreen");
 
183
 
 
184
  var enigmailSvc = Ec.getService(window);
 
185
  if (enigmailSvc) {
 
186
    enigmailSvc.invalidateUserIdList();
 
187
  }
 
188
  onLoad();
 
189
}
 
190
 
 
191
function enigmailAdminPin() {
 
192
  window.openDialog("chrome://enigmail/content/enigmailSetCardPin.xul",
 
193
        "", "dialog,modal,centerscreen");
 
194
  onLoad();
 
195
}