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

« back to all changes in this revision

Viewing changes to mailnews/extensions/enigmail/ui/content/enigmailSingleRcptSettings.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) 2004 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
// Uses: chrome://enigmail/content/enigmailCommon.js
 
36
 
 
37
// Initialize enigmailCommon
 
38
EnigInitCommon("enigmailSingleRcptSettings");
 
39
 
 
40
const INPUT=0;
 
41
const RESULT=1;
 
42
 
 
43
function enigmailDlgOnLoad() {
 
44
  var matchBegin=false;
 
45
  var matchEnd=false;
 
46
 
 
47
  var ruleEmail=document.getElementById("ruleEmail");
 
48
  if (window.arguments[INPUT].toAddress.indexOf("{")==0) {
 
49
    matchBegin=true;
 
50
  }
 
51
  if (window.arguments[INPUT].toAddress.search(/}$/)>=0) {
 
52
    matchEnd=true;
 
53
  }
 
54
 
 
55
  var matchingRule=document.getElementById("matchingRule");
 
56
  if (matchBegin && matchEnd) {
 
57
    matchingRule.selectedIndex=0;
 
58
  }
 
59
  else if (matchBegin) {
 
60
    matchingRule.selectedIndex=2;
 
61
  }
 
62
  else if (matchEnd) {
 
63
    matchingRule.selectedIndex=3;
 
64
  }
 
65
  else {
 
66
    matchingRule.selectedIndex=1;
 
67
  }
 
68
 
 
69
/*
 
70
  var negateRule=document.getElementById("negateRule");
 
71
  if (typeof(window.arguments[INPUT].negate)=="number") {
 
72
    negateRule.selectedIndex = (window.arguments[INPUT].negate ? 1 : 0);
 
73
  }
 
74
*/
 
75
  ruleEmail.value = window.arguments[INPUT].toAddress.replace(/[{}]/g, "");
 
76
  window.arguments[RESULT].cancelled=true;
 
77
 
 
78
  var action="";
 
79
  if (typeof(window.arguments[INPUT].keyId)=="object") {
 
80
    switch (window.arguments[INPUT].keyId.join("")) {
 
81
    case ".":
 
82
      enigSetKeys("");
 
83
      action="actionStop";
 
84
      break;
 
85
    case "":
 
86
      enigSetKeys("");
 
87
      action="actionCont";
 
88
      break;
 
89
    default:
 
90
      enigSetKeys(window.arguments[INPUT].keyId);
 
91
      action="actionUseKey";
 
92
    }
 
93
  }
 
94
  else {
 
95
    enigSetKeys("");
 
96
    action="actionCont";
 
97
  }
 
98
  if (window.arguments[INPUT].command=="add") {
 
99
    action="actionUseKey";
 
100
  }
 
101
 
 
102
  var actionType = document.getElementById("actionType");
 
103
  actionType.selectedItem = document.getElementById("actionType."+action);
 
104
  enigEnableKeySel(action=="actionUseKey");
 
105
 
 
106
  if (typeof(window.arguments[INPUT].sign)=="number") {
 
107
    document.getElementById("sign").selectedIndex=window.arguments[INPUT].sign;
 
108
  }
 
109
  else {
 
110
    document.getElementById("sign").selectedIndex=1;
 
111
  }
 
112
  if (typeof(window.arguments[INPUT].encrypt)=="number") {
 
113
    document.getElementById("encrypt").selectedIndex=window.arguments[INPUT].encrypt;
 
114
  }
 
115
  else {
 
116
    document.getElementById("encrypt").selectedIndex=1;
 
117
  }
 
118
  if (typeof(window.arguments[INPUT].pgpmime)=="number") {
 
119
    document.getElementById("pgpmime").selectedIndex=window.arguments[INPUT].pgpmime;
 
120
  }
 
121
  else {
 
122
    document.getElementById("pgpmime").selectedIndex=1;
 
123
  }
 
124
}
 
125
 
 
126
function enigmailDlgOnAccept() {
 
127
  var enigmailSvc = GetEnigmailSvc();
 
128
  if (!enigmailSvc)
 
129
    return false;
 
130
 
 
131
  var keyList="";
 
132
  var ruleEmail  = document.getElementById("ruleEmail");
 
133
  var matchingRule = document.getElementById("matchingRule").value;
 
134
  var matchBegin=false;
 
135
  var matchEnd=false;
 
136
  switch (Number(matchingRule)) {
 
137
  case 0:
 
138
    matchBegin=true;
 
139
    matchEnd=true;
 
140
    break;
 
141
  case 2:
 
142
    matchBegin=true;
 
143
    break;
 
144
  case 3:
 
145
    matchEnd=true;
 
146
    break;
 
147
  }
 
148
 
 
149
  // Remove trailing whitespace
 
150
  ruleEmail.value = ruleEmail.value.replace(/\s+$/,"").replace(/^\s+/,"");
 
151
  if (ruleEmail.value.length==0) {
 
152
    EnigAlert(EnigGetString("noEmptyRule"));
 
153
    return false;
 
154
  }
 
155
  if (ruleEmail.value.search(/[\<\>]/)>=0) {
 
156
    EnigAlert(EnigGetString("invalidAddress"));
 
157
    return false;
 
158
  }
 
159
  if (ruleEmail.value.search(/[{}]/)>=0) {
 
160
    EnigAlert(EnigGetString("noCurlyBrackets"));
 
161
    return false;
 
162
  }
 
163
  var encryptionList=document.getElementById("encryptionList");
 
164
  for (var i=0; i<encryptionList.getRowCount(); i++) {
 
165
    var item=encryptionList.getItemAtIndex(i);
 
166
    var valueLabel=item.getAttribute("value");
 
167
    if (valueLabel.length>0) {
 
168
      keyList+=", "+valueLabel;
 
169
    }
 
170
  }
 
171
  var email="";
 
172
  var mailAddrs=ruleEmail.value.split(/[ ,]+/);
 
173
  for (i=0; i<mailAddrs.length; i++) {
 
174
    email += (matchBegin ? " {" : " ") + mailAddrs[i] + (matchEnd ? "}" : "");
 
175
  }
 
176
  window.arguments[RESULT].email   = email.substr(1);
 
177
  window.arguments[RESULT].keyId   = keyList.substr(2);
 
178
  window.arguments[RESULT].sign    = document.getElementById("sign").value;
 
179
  window.arguments[RESULT].encrypt = document.getElementById("encrypt").value;
 
180
  window.arguments[RESULT].pgpMime = document.getElementById("pgpmime").value;
 
181
  window.arguments[RESULT].negate = 0; /*Number(document.getElementById("negateRule").value);*/
 
182
 
 
183
  var actionType = document.getElementById("actionType");
 
184
  switch(Number(actionType.selectedItem.value)) {
 
185
  case 1:
 
186
    window.arguments[RESULT].keyId = ".";
 
187
    break;
 
188
 
 
189
  case 2:
 
190
    if (keyList == "" && (window.arguments[RESULT].encrypt>0)) {
 
191
      if (!EnigConfirm(EnigGetString("noEncryption", ruleEmail.value, ruleEmail.value))) {
 
192
        return false;
 
193
      }
 
194
      window.arguments[RESULT].encrypt = 0;
 
195
    }
 
196
    break;
 
197
  }
 
198
 
 
199
  window.arguments[RESULT].cancelled=false;
 
200
  if (window.arguments[INPUT].options.indexOf("nosave")<0) {
 
201
    enigmailSvc.addRule(false,
 
202
                        window.arguments[RESULT].email,
 
203
                        window.arguments[RESULT].keyId,
 
204
                        window.arguments[RESULT].sign,
 
205
                        window.arguments[RESULT].encrypt,
 
206
                        window.arguments[RESULT].pgpMime,
 
207
                        window.arguments[RESULT].negate);
 
208
   enigmailSvc.saveRulesFile();
 
209
  }
 
210
  return true;
 
211
}
 
212
 
 
213
function enigmailDlgKeySelection() {
 
214
  DEBUG_LOG("enigmailMsgComposeHelper.js: enigmailDlgKeySelection: \n");
 
215
 
 
216
  var enigmailSvc = GetEnigmailSvc();
 
217
  if (!enigmailSvc)
 
218
    return;
 
219
 
 
220
  var resultObj = new Object();
 
221
  var inputObj = new Object();
 
222
  inputObj.dialogHeader = "";
 
223
  inputObj.forUser = document.getElementById("ruleEmail").value.replace(/[ ,]+/g, ", ");
 
224
  inputObj.toAddr = inputObj.forUser;
 
225
  inputObj.toKeys = "";
 
226
  var encryptionList=document.getElementById("encryptionList");
 
227
  encryptionList.clearSelection();
 
228
  for (var i=0; i<encryptionList.getRowCount(); i++) {
 
229
    var item=encryptionList.getItemAtIndex(i);
 
230
    var valueLabel=item.getAttribute("value");
 
231
    if (valueLabel.length>0) {
 
232
      inputObj.toKeys += valueLabel+",";
 
233
    }
 
234
  }
 
235
 
 
236
  inputObj.options = "multisel,forUser,noplaintext";
 
237
  var userIdValue="";
 
238
 
 
239
  window.openDialog("chrome://enigmail/content/enigmailUserSelection.xul","", "dialog,modal,centerscreen", inputObj, resultObj);
 
240
  try {
 
241
    if (resultObj.cancelled) return;
 
242
  } catch (ex) {
 
243
    // cancel pressed -> do nothing
 
244
    return;
 
245
  }
 
246
  enigSetKeys(resultObj.userList);
 
247
}
 
248
 
 
249
function enigSetKeys(keyList) {
 
250
  var encryptionList=document.getElementById("encryptionList");
 
251
  while (encryptionList.getRowCount()>0) {
 
252
    encryptionList.removeItemAt(0);
 
253
  }
 
254
  if ((keyList.length==0) || (keyList.length==1 && keyList[0].length==0)) {
 
255
    encryptionList.appendItem(EnigGetString("noKeyToUse"),"");
 
256
  }
 
257
  else {
 
258
    var enigmailSvc = GetEnigmailSvc();
 
259
    if (!enigmailSvc)
 
260
      return;
 
261
 
 
262
    var exitCodeObj= new Object;
 
263
    var statusFlagsObj = new Object;
 
264
    var errorMsgObj = new Object;
 
265
    var userListTxt = enigmailSvc.getUserIdList(false,
 
266
                                               false,
 
267
                                               exitCodeObj,
 
268
                                               statusFlagsObj,
 
269
                                               errorMsgObj);
 
270
    if (exitCodeObj.value != 0) {
 
271
      EnigAlert(errorMsgObj.value);
 
272
      return;
 
273
    }
 
274
 
 
275
    for (var i=0; i<keyList.length; i++) {
 
276
      var keyId=keyList[i].substring(2);
 
277
      var keyStart=userListTxt.indexOf(":"+keyId+":");
 
278
      keyStart+= userListTxt.substr(keyStart).indexOf("\nuid:");
 
279
      var keyEnd=userListTxt.substring(keyStart+2).indexOf("\n")+2;
 
280
      var userDescList=userListTxt.substr(keyStart,keyEnd).split(/:/);
 
281
      var userDesc = "";
 
282
      if (userDescList.length >= 9) {
 
283
        userDesc = userDescList[9];
 
284
      }
 
285
 
 
286
      if(keyList[i].indexOf("GROUP:") == 0) {
 
287
        encryptionList.appendItem(keyList[i].substr(6)+" "+EnigGetString("keyTrust.group"), keyList[i]);
 
288
      }
 
289
      else
 
290
        encryptionList.appendItem("0x"+keyList[i].substr(10,8)+" ("+EnigConvertGpgToUnicode(userDesc)+")",
 
291
                                keyList[i]);
 
292
    }
 
293
  }
 
294
}
 
295
 
 
296
function enigEnableKeySel(enable) {
 
297
  if (enable) {
 
298
    document.getElementById("encryptionList").removeAttribute("disabled");
 
299
    document.getElementById("encryptionListButton").removeAttribute("disabled");
 
300
  }
 
301
  else {
 
302
    document.getElementById("encryptionList").setAttribute("disabled", "true");
 
303
    document.getElementById("encryptionListButton").setAttribute("disabled", "true");
 
304
  }
 
305
}