1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14
* The Original Code is Enigmail.
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.
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 ***** */
35
// Uses: chrome://enigmail/content/enigmailCommon.js
37
// Initialize enigmailCommon
38
EnigInitCommon("enigmailSingleRcptSettings");
43
function enigmailDlgOnLoad() {
47
var ruleEmail=document.getElementById("ruleEmail");
48
if (window.arguments[INPUT].toAddress.indexOf("{")==0) {
51
if (window.arguments[INPUT].toAddress.search(/}$/)>=0) {
55
var matchingRule=document.getElementById("matchingRule");
56
if (matchBegin && matchEnd) {
57
matchingRule.selectedIndex=0;
59
else if (matchBegin) {
60
matchingRule.selectedIndex=2;
63
matchingRule.selectedIndex=3;
66
matchingRule.selectedIndex=1;
70
var negateRule=document.getElementById("negateRule");
71
if (typeof(window.arguments[INPUT].negate)=="number") {
72
negateRule.selectedIndex = (window.arguments[INPUT].negate ? 1 : 0);
75
ruleEmail.value = window.arguments[INPUT].toAddress.replace(/[{}]/g, "");
76
window.arguments[RESULT].cancelled=true;
79
if (typeof(window.arguments[INPUT].keyId)=="object") {
80
switch (window.arguments[INPUT].keyId.join("")) {
90
enigSetKeys(window.arguments[INPUT].keyId);
91
action="actionUseKey";
98
if (window.arguments[INPUT].command=="add") {
99
action="actionUseKey";
102
var actionType = document.getElementById("actionType");
103
actionType.selectedItem = document.getElementById("actionType."+action);
104
enigEnableKeySel(action=="actionUseKey");
106
if (typeof(window.arguments[INPUT].sign)=="number") {
107
document.getElementById("sign").selectedIndex=window.arguments[INPUT].sign;
110
document.getElementById("sign").selectedIndex=1;
112
if (typeof(window.arguments[INPUT].encrypt)=="number") {
113
document.getElementById("encrypt").selectedIndex=window.arguments[INPUT].encrypt;
116
document.getElementById("encrypt").selectedIndex=1;
118
if (typeof(window.arguments[INPUT].pgpmime)=="number") {
119
document.getElementById("pgpmime").selectedIndex=window.arguments[INPUT].pgpmime;
122
document.getElementById("pgpmime").selectedIndex=1;
126
function enigmailDlgOnAccept() {
127
var enigmailSvc = GetEnigmailSvc();
132
var ruleEmail = document.getElementById("ruleEmail");
133
var matchingRule = document.getElementById("matchingRule").value;
134
var matchBegin=false;
136
switch (Number(matchingRule)) {
149
// Remove trailing whitespace
150
ruleEmail.value = ruleEmail.value.replace(/\s+$/,"").replace(/^\s+/,"");
151
if (ruleEmail.value.length==0) {
152
EnigAlert(EnigGetString("noEmptyRule"));
155
if (ruleEmail.value.search(/[\<\>]/)>=0) {
156
EnigAlert(EnigGetString("invalidAddress"));
159
if (ruleEmail.value.search(/[{}]/)>=0) {
160
EnigAlert(EnigGetString("noCurlyBrackets"));
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;
172
var mailAddrs=ruleEmail.value.split(/[ ,]+/);
173
for (i=0; i<mailAddrs.length; i++) {
174
email += (matchBegin ? " {" : " ") + mailAddrs[i] + (matchEnd ? "}" : "");
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);*/
183
var actionType = document.getElementById("actionType");
184
switch(Number(actionType.selectedItem.value)) {
186
window.arguments[RESULT].keyId = ".";
190
if (keyList == "" && (window.arguments[RESULT].encrypt>0)) {
191
if (!EnigConfirm(EnigGetString("noEncryption", ruleEmail.value, ruleEmail.value))) {
194
window.arguments[RESULT].encrypt = 0;
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();
213
function enigmailDlgKeySelection() {
214
DEBUG_LOG("enigmailMsgComposeHelper.js: enigmailDlgKeySelection: \n");
216
var enigmailSvc = GetEnigmailSvc();
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+",";
236
inputObj.options = "multisel,forUser,noplaintext";
239
window.openDialog("chrome://enigmail/content/enigmailUserSelection.xul","", "dialog,modal,centerscreen", inputObj, resultObj);
241
if (resultObj.cancelled) return;
243
// cancel pressed -> do nothing
246
enigSetKeys(resultObj.userList);
249
function enigSetKeys(keyList) {
250
var encryptionList=document.getElementById("encryptionList");
251
while (encryptionList.getRowCount()>0) {
252
encryptionList.removeItemAt(0);
254
if ((keyList.length==0) || (keyList.length==1 && keyList[0].length==0)) {
255
encryptionList.appendItem(EnigGetString("noKeyToUse"),"");
258
var enigmailSvc = GetEnigmailSvc();
262
var exitCodeObj= new Object;
263
var statusFlagsObj = new Object;
264
var errorMsgObj = new Object;
265
var userListTxt = enigmailSvc.getUserIdList(false,
270
if (exitCodeObj.value != 0) {
271
EnigAlert(errorMsgObj.value);
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(/:/);
282
if (userDescList.length >= 9) {
283
userDesc = userDescList[9];
286
if(keyList[i].indexOf("GROUP:") == 0) {
287
encryptionList.appendItem(keyList[i].substr(6)+" "+EnigGetString("keyTrust.group"), keyList[i]);
290
encryptionList.appendItem("0x"+keyList[i].substr(10,8)+" ("+EnigConvertGpgToUnicode(userDesc)+")",
296
function enigEnableKeySel(enable) {
298
document.getElementById("encryptionList").removeAttribute("disabled");
299
document.getElementById("encryptionListButton").removeAttribute("disabled");
302
document.getElementById("encryptionList").setAttribute("disabled", "true");
303
document.getElementById("encryptionListButton").setAttribute("disabled", "true");