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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "MPL"); you may not use this file
 * except in compliance with the MPL. You may obtain a copy of
 * the MPL at http://www.mozilla.org/MPL/
 *
 * Software distributed under the MPL is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the MPL for the specific language governing
 * rights and limitations under the MPL.
 *
 * The Original Code is Enigmail.
 *
 * The Initial Developer of the Original Code is Patrick Brunschwig.
 * Portions created by Patrick Brunschwig <patrick@mozilla-enigmail.org> are
 * Copyright (C) 2004 Patrick Brunschwig. All Rights Reserved.
 *
 * Contributor(s):
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * ***** END LICENSE BLOCK ***** */

// Uses: chrome://enigmail/content/enigmailCommon.js

// Initialize enigmailCommon
EnigInitCommon("enigmailSingleRcptSettings");

const INPUT=0;
const RESULT=1;

function enigmailDlgOnLoad() {
  var matchBegin=false;
  var matchEnd=false;

  var ruleEmail=document.getElementById("ruleEmail");
  if (window.arguments[INPUT].toAddress.indexOf("{")==0) {
    matchBegin=true;
  }
  if (window.arguments[INPUT].toAddress.search(/}$/)>=0) {
    matchEnd=true;
  }

  var matchingRule=document.getElementById("matchingRule");
  if (matchBegin && matchEnd) {
    matchingRule.selectedIndex=0;
  }
  else if (matchBegin) {
    matchingRule.selectedIndex=2;
  }
  else if (matchEnd) {
    matchingRule.selectedIndex=3;
  }
  else {
    matchingRule.selectedIndex=1;
  }

/*
  var negateRule=document.getElementById("negateRule");
  if (typeof(window.arguments[INPUT].negate)=="number") {
    negateRule.selectedIndex = (window.arguments[INPUT].negate ? 1 : 0);
  }
*/
  ruleEmail.value = window.arguments[INPUT].toAddress.replace(/[{}]/g, "");
  window.arguments[RESULT].cancelled=true;

  var action="";
  if (typeof(window.arguments[INPUT].keyId)=="object") {
    switch (window.arguments[INPUT].keyId.join("")) {
    case ".":
      enigSetKeys("");
      action="actionStop";
      break;
    case "":
      enigSetKeys("");
      action="actionCont";
      break;
    default:
      enigSetKeys(window.arguments[INPUT].keyId);
      action="actionUseKey";
    }
  }
  else {
    enigSetKeys("");
    action="actionCont";
  }
  if (window.arguments[INPUT].command=="add") {
    action="actionUseKey";
  }

  var actionType = document.getElementById("actionType");
  actionType.selectedItem = document.getElementById("actionType."+action);
  enigEnableKeySel(action=="actionUseKey");

  if (typeof(window.arguments[INPUT].sign)=="number") {
    document.getElementById("sign").selectedIndex=window.arguments[INPUT].sign;
  }
  else {
    document.getElementById("sign").selectedIndex=1;
  }
  if (typeof(window.arguments[INPUT].encrypt)=="number") {
    document.getElementById("encrypt").selectedIndex=window.arguments[INPUT].encrypt;
  }
  else {
    document.getElementById("encrypt").selectedIndex=1;
  }
  if (typeof(window.arguments[INPUT].pgpmime)=="number") {
    document.getElementById("pgpmime").selectedIndex=window.arguments[INPUT].pgpmime;
  }
  else {
    document.getElementById("pgpmime").selectedIndex=1;
  }
}

function enigmailDlgOnAccept() {
  var enigmailSvc = GetEnigmailSvc();
  if (!enigmailSvc)
    return false;

  var keyList="";
  var ruleEmail  = document.getElementById("ruleEmail");
  var matchingRule = document.getElementById("matchingRule").value;
  var matchBegin=false;
  var matchEnd=false;
  switch (Number(matchingRule)) {
  case 0:
    matchBegin=true;
    matchEnd=true;
    break;
  case 2:
    matchBegin=true;
    break;
  case 3:
    matchEnd=true;
    break;
  }

  // Remove trailing whitespace
  ruleEmail.value = ruleEmail.value.replace(/\s+$/,"").replace(/^\s+/,"");
  if (ruleEmail.value.length==0) {
    EnigAlert(EnigGetString("noEmptyRule"));
    return false;
  }
  if (ruleEmail.value.search(/[\<\>]/)>=0) {
    EnigAlert(EnigGetString("invalidAddress"));
    return false;
  }
  if (ruleEmail.value.search(/[{}]/)>=0) {
    EnigAlert(EnigGetString("noCurlyBrackets"));
    return false;
  }
  var encryptionList=document.getElementById("encryptionList");
  for (var i=0; i<encryptionList.getRowCount(); i++) {
    var item=encryptionList.getItemAtIndex(i);
    var valueLabel=item.getAttribute("value");
    if (valueLabel.length>0) {
      keyList+=", "+valueLabel;
    }
  }
  var email="";
  var mailAddrs=ruleEmail.value.split(/[ ,]+/);
  for (i=0; i<mailAddrs.length; i++) {
    email += (matchBegin ? " {" : " ") + mailAddrs[i] + (matchEnd ? "}" : "");
  }
  window.arguments[RESULT].email   = email.substr(1);
  window.arguments[RESULT].keyId   = keyList.substr(2);
  window.arguments[RESULT].sign    = document.getElementById("sign").value;
  window.arguments[RESULT].encrypt = document.getElementById("encrypt").value;
  window.arguments[RESULT].pgpMime = document.getElementById("pgpmime").value;
  window.arguments[RESULT].negate = 0; /*Number(document.getElementById("negateRule").value);*/

  var actionType = document.getElementById("actionType");
  switch(Number(actionType.selectedItem.value)) {
  case 1:
    window.arguments[RESULT].keyId = ".";
    break;

  case 2:
    if (keyList == "" && (window.arguments[RESULT].encrypt>0)) {
      if (!EnigConfirm(EnigGetString("noEncryption", ruleEmail.value, ruleEmail.value))) {
        return false;
      }
      window.arguments[RESULT].encrypt = 0;
    }
    break;
  }

  window.arguments[RESULT].cancelled=false;
  if (window.arguments[INPUT].options.indexOf("nosave")<0) {
    enigmailSvc.addRule(false,
                        window.arguments[RESULT].email,
                        window.arguments[RESULT].keyId,
                        window.arguments[RESULT].sign,
                        window.arguments[RESULT].encrypt,
                        window.arguments[RESULT].pgpMime,
                        window.arguments[RESULT].negate);
   enigmailSvc.saveRulesFile();
  }
  return true;
}

function enigmailDlgKeySelection() {
  DEBUG_LOG("enigmailMsgComposeHelper.js: enigmailDlgKeySelection: \n");

  var enigmailSvc = GetEnigmailSvc();
  if (!enigmailSvc)
    return;

  var resultObj = new Object();
  var inputObj = new Object();
  inputObj.dialogHeader = "";
  inputObj.forUser = document.getElementById("ruleEmail").value.replace(/[ ,]+/g, ", ");
  inputObj.toAddr = inputObj.forUser;
  inputObj.toKeys = "";
  var encryptionList=document.getElementById("encryptionList");
  encryptionList.clearSelection();
  for (var i=0; i<encryptionList.getRowCount(); i++) {
    var item=encryptionList.getItemAtIndex(i);
    var valueLabel=item.getAttribute("value");
    if (valueLabel.length>0) {
      inputObj.toKeys += valueLabel+",";
    }
  }

  inputObj.options = "multisel,forUser,noplaintext";
  var userIdValue="";

  window.openDialog("chrome://enigmail/content/enigmailUserSelection.xul","", "dialog,modal,centerscreen", inputObj, resultObj);
  try {
    if (resultObj.cancelled) return;
  } catch (ex) {
    // cancel pressed -> do nothing
    return;
  }
  enigSetKeys(resultObj.userList);
}

function enigSetKeys(keyList) {
  var encryptionList=document.getElementById("encryptionList");
  while (encryptionList.getRowCount()>0) {
    encryptionList.removeItemAt(0);
  }
  if ((keyList.length==0) || (keyList.length==1 && keyList[0].length==0)) {
    encryptionList.appendItem(EnigGetString("noKeyToUse"),"");
  }
  else {
    var enigmailSvc = GetEnigmailSvc();
    if (!enigmailSvc)
      return;

    var exitCodeObj= new Object;
    var statusFlagsObj = new Object;
    var errorMsgObj = new Object;
    var userListTxt = enigmailSvc.getUserIdList(false,
                                               false,
                                               exitCodeObj,
                                               statusFlagsObj,
                                               errorMsgObj);
    if (exitCodeObj.value != 0) {
      EnigAlert(errorMsgObj.value);
      return;
    }

    for (var i=0; i<keyList.length; i++) {
      var keyId=keyList[i].substring(2);
      var keyStart=userListTxt.indexOf(":"+keyId+":");
      keyStart+= userListTxt.substr(keyStart).indexOf("\nuid:");
      var keyEnd=userListTxt.substring(keyStart+2).indexOf("\n")+2;
      var userDescList=userListTxt.substr(keyStart,keyEnd).split(/:/);
      var userDesc = "";
      if (userDescList.length >= 9) {
        userDesc = userDescList[9];
      }

      if(keyList[i].indexOf("GROUP:") == 0) {
        encryptionList.appendItem(keyList[i].substr(6)+" "+EnigGetString("keyTrust.group"), keyList[i]);
      }
      else
        encryptionList.appendItem("0x"+keyList[i].substr(10,8)+" ("+EnigConvertGpgToUnicode(userDesc)+")",
                                keyList[i]);
    }
  }
}

function enigEnableKeySel(enable) {
  if (enable) {
    document.getElementById("encryptionList").removeAttribute("disabled");
    document.getElementById("encryptionListButton").removeAttribute("disabled");
  }
  else {
    document.getElementById("encryptionList").setAttribute("disabled", "true");
    document.getElementById("encryptionListButton").setAttribute("disabled", "true");
  }
}