!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2001
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * ddrinan@netscape.com
24 * Scott MacGregor <mscott@netscape.com>
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 const gISMimeCompFields = Components.interfaces.nsIMsgSMIMECompFields;
41 const gSMimeCompFieldsContractID = "@mozilla.org/messenger-smime/composefields;1";
42 const gSMimeContractID = "@mozilla.org/messenger-smime/smimejshelper;1";
43 const gISMimeJSHelper = Components.interfaces.nsISMimeJSHelper;
44 var gNextSecurityButtonCommand = "";
45 var gBundle;
46 var gBrandBundle;
47 var gSMFields;
48 var gEncryptedURIService = null;
49
50
onComposerClose
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
51 function onComposerClose()
52 {
53 gSMFields = null;
54 setNoEncryptionUI();
55 setNoSignatureUI();
56
57 if (!gMsgCompose)
58 return;
59
60 if (!gMsgCompose.compFields)
61 return;
62
63 gMsgCompose.compFields.securityInfo = null;
64 }
65
onComposerReOpen
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
66 function onComposerReOpen()
67 {
68 // are we already set up?
69 if (gSMFields)
70 return;
71
72 if (!gMsgCompose)
73 return;
74
75 if (!gMsgCompose.compFields)
76 return;
77
78 gMsgCompose.compFields.securityInfo = null;
79
80 gSMFields = Components.classes[gSMimeCompFieldsContractID].createInstance(gISMimeCompFields);
81 if (gSMFields)
82 {
83 gMsgCompose.compFields.securityInfo = gSMFields;
84 // set up the intial security state....
85 var encryptionPolicy = gCurrentIdentity.getIntAttribute("encryptionpolicy");
86 // 0 == never, 1 == if possible, 2 == always Encrypt.
87 gSMFields.requireEncryptMessage = encryptionPolicy == 2;
88
89 gSMFields.signMessage = gCurrentIdentity.getBoolAttribute("sign_mail");
90
91 if (gEncryptedURIService && !gSMFields.requireEncryptMessage)
92 {
93 if (gEncryptedURIService.isEncrypted(gMsgCompose.originalMsgURI))
94 {
95 // Override encryption setting if original is known as encrypted.
96 gSMFields.requireEncryptMessage = true;
97 }
98 }
99
100 if (gSMFields.requireEncryptMessage)
101 {
102 setEncryptionUI();
103 }
104 else
105 {
106 setNoEncryptionUI();
107 }
108
109 if (gSMFields.signMessage)
110 {
111 setSignatureUI();
112 }
113 else
114 {
115 setNoSignatureUI();
116 }
117 }
118 }
119
120
121 // this function gets called multiple times,
122 // but only on first open, not on composer recycling
smimeComposeOnLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
123 function smimeComposeOnLoad()
124 {
125 if (!gEncryptedURIService)
126 {
127 gEncryptedURIService =
128 Components.classes["@mozilla.org/messenger-smime/smime-encrypted-uris-service;1"]
129 .getService(Components.interfaces.nsIEncryptedSMIMEURIsService);
130 }
131
132 onComposerReOpen();
133 }
134
setupBundles
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
135 function setupBundles()
136 {
137 if (gBundle && gBrandBundle)
138 return;
139
140 if (!gBundle) {
141 gBundle = document.getElementById("bundle_comp_smime");
142 gBrandBundle = document.getElementById("bundle_brand");
143 }
144 }
145
146 // stub routine to make our call to MsgAccountManager work correctly
GetSelectedFolderURI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
147 function GetSelectedFolderURI()
148 {
149 return;
150 }
151
GetServer
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
152 function GetServer(uri)
153 {
154 var servers = gAccountManager.GetServersForIdentity(gCurrentIdentity);
155 return servers.QueryElementAt(0, Components.interfaces.nsIMsgIncomingServer);
156 }
157
showNeedSetupInfo
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
158 function showNeedSetupInfo()
159 {
160 var ifps = Components.interfaces.nsIPromptService;
161
162 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService();
163 promptService = promptService.QueryInterface(ifps);
164 setupBundles();
165
166 if (promptService && gBundle && gBrandBundle) {
167 var dummy = new Object;
168 var buttonPressed =
169 promptService.confirmEx(window,
170 gBrandBundle.getString("brandShortName"),
171 gBundle.getString("NeedSetup"),
172 ifps.STD_YES_NO_BUTTONS,
173 0,
174 0,
175 0,
176 null,
177 dummy);
178
179 if (0 == buttonPressed) {
180 MsgAccountManager('am-smime.xul');
181 }
182 }
183 }
184
noEncryption
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
185 function noEncryption()
186 {
187 if (!gSMFields)
188 return;
189
190 gSMFields.requireEncryptMessage = false;
191 setNoEncryptionUI();
192 }
193
encryptMessage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
194 function encryptMessage()
195 {
196 if (!gSMFields)
197 return;
198
199 var encryptionCertName = gCurrentIdentity.getUnicharAttribute("encryption_cert_name");
200 if (!encryptionCertName)
201 {
202 gSMFields.requireEncryptMessage = false;
203 setNoEncryptionUI();
204 showNeedSetupInfo();
205 return;
206 }
207
208 gSMFields.requireEncryptMessage = true;
209 setEncryptionUI();
210 }
211
signMessage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
212 function signMessage()
213 {
214 if (!gSMFields)
215 return;
216
217 // toggle
218 gSMFields.signMessage = !gSMFields.signMessage;
219
220 if (gSMFields.signMessage) // make sure we have a cert name...
221 {
222 var signingCertName = gCurrentIdentity.getUnicharAttribute("signing_cert_name");
223 if (!signingCertName)
224 {
225 gSMFields.signMessage = false;
226 showNeedSetupInfo();
227 return;
228 }
229
230 setSignatureUI();
231 }
232 else
233 {
234 setNoSignatureUI();
235 }
236 }
237
setSecuritySettings
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
238 function setSecuritySettings(menu_id)
239 {
240 if (!gSMFields)
241 return;
242
243 document.getElementById("menu_securityEncryptRequire" + menu_id).setAttribute("checked", gSMFields.requireEncryptMessage);
244 document.getElementById("menu_securityNoEncryption" + menu_id).setAttribute("checked", !gSMFields.requireEncryptMessage);
245 document.getElementById("menu_securitySign" + menu_id).setAttribute("checked", gSMFields.signMessage);
246 }
247
setNextCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
248 function setNextCommand(what)
249 {
250 gNextSecurityButtonCommand = what;
251 }
252
doSecurityButton
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
253 function doSecurityButton()
254 {
255 var what = gNextSecurityButtonCommand;
256 gNextSecurityButtonCommand = "";
257
258 switch (what)
259 {
260 case "noEncryption":
261 noEncryption();
262 break;
263
264 case "encryptMessage":
265 encryptMessage();
266 break;
267
268 case "signMessage":
269 signMessage();
270 break;
271
272 case "show":
273 default:
274 showMessageComposeSecurityStatus();
275 break;
276 }
277 }
278
setNoSignatureUI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
279 function setNoSignatureUI()
280 {
281 top.document.getElementById("securityStatus").removeAttribute("signing");
282 top.document.getElementById("signing-status").collapsed = true;
283 }
284
setSignatureUI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
285 function setSignatureUI()
286 {
287 top.document.getElementById("securityStatus").setAttribute("signing", "ok");
288 top.document.getElementById("signing-status").collapsed = false;
289 }
290
setNoEncryptionUI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
291 function setNoEncryptionUI()
292 {
293 top.document.getElementById("securityStatus").removeAttribute("crypto");
294 top.document.getElementById("encryption-status").collapsed = true;
295 }
296
setEncryptionUI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
297 function setEncryptionUI()
298 {
299 top.document.getElementById("securityStatus").setAttribute("crypto", "ok");
300 top.document.getElementById("encryption-status").collapsed = false;
301 }
302
showMessageComposeSecurityStatus
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
303 function showMessageComposeSecurityStatus()
304 {
305 Recipients2CompFields(gMsgCompose.compFields);
306
307 var encryptionCertName = gCurrentIdentity.getUnicharAttribute("encryption_cert_name");
308 var signingCertName = gCurrentIdentity.getUnicharAttribute("signing_cert_name");
309
310 window.openDialog('chrome://messenger-smime/content/msgCompSecurityInfo.xul',
311 '',
312 'chrome,resizable=1,modal=1,dialog=1',
313 {
314 compFields : gMsgCompose.compFields,
315 subject : GetMsgSubjectElement().value,
316 smFields : gSMFields,
317 isSigningCertAvailable : (signingCertName.length > 0),
318 isEncryptionCertAvailable : (encryptionCertName.length > 0),
319 currentIdentity : gCurrentIdentity
320 }
321 );
322 }
323
324 var SecurityController =
325 {
supportsCommand
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
326 supportsCommand: function(command)
327 {
328 switch ( command )
329 {
330 case "cmd_viewSecurityStatus":
331 return true;
332
333 default:
334 return false;
335 }
336 },
337
isCommandEnabled
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
338 isCommandEnabled: function(command)
339 {
340 switch ( command )
341 {
342 case "cmd_viewSecurityStatus":
343 {
344 return true;
345 }
346
347 default:
348 return false;
349 }
350 return false;
351 }
352 };
353
onComposerSendMessage
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
354 function onComposerSendMessage()
355 {
356 try {
357 if (!gMsgCompose.compFields.securityInfo.requireEncryptMessage) {
358 return;
359 }
360
361 var helper = Components.classes[gSMimeContractID].createInstance(gISMimeJSHelper);
362
363 var emailAddresses = new Object();
364 var missingCount = new Object();
365
366 helper.getNoCertAddresses(
367 gMsgCompose.compFields,
368 missingCount,
369 emailAddresses);
370 }
371 catch (e)
372 {
373 return;
374 }
375
376 if (missingCount.value > 0)
377 {
378 var prefService =
379 Components.classes["@mozilla.org/preferences-service;1"]
380 .getService(Components.interfaces.nsIPrefService);
381 var prefs = prefService.getBranch(null);
382
383 var autocompleteLdap = false;
384 autocompleteLdap = prefs.getBoolPref("ldap_2.autoComplete.useDirectory");
385
386 if (autocompleteLdap)
387 {
388 var autocompleteDirectory = null;
389 autocompleteDirectory = prefs.getCharPref(
390 "ldap_2.autoComplete.directoryServer");
391
392 if(gCurrentIdentity.overrideGlobalPref) {
393 autocompleteDirectory = gCurrentIdentity.directoryServer;
394 }
395
396 if (autocompleteDirectory)
397 {
398 window.openDialog('chrome://messenger-smime/content/certFetchingStatus.xul',
399 '',
400 'chrome,resizable=1,modal=1,dialog=1',
401 autocompleteDirectory,
402 emailAddresses.value
403 );
404 }
405 }
406 }
407 }
408
onComposerFromChanged
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
409 function onComposerFromChanged()
410 {
411 if (!gSMFields)
412 return;
413
414 // In order to provide maximum protection to the user:
415 // - If encryption is already enabled, we will not turn it off automatically.
416 // - If encryption is not enabled, but the new account defaults to encryption, we will turn it on.
417 // - If signing is disabled, we will not turn it on automatically.
418 // - If signing is enabled, but the new account defaults to not sign, we will turn signing off.
419
420 if (!gSMFields.requireEncryptMessage)
421 {
422 var encryptionPolicy = gCurrentIdentity.getIntAttribute("encryptionpolicy");
423 // 0 == never, 1 == if possible, 2 == always Encrypt.
424
425 if (encryptionPolicy == 2)
426 {
427 gSMFields.requireEncryptMessage = true;
428 setEncryptionUI();
429 }
430 }
431
432 if (gSMFields.signMessage)
433 {
434 var signMessage = gCurrentIdentity.getBoolAttribute("sign_mail");
435
436 if (!signMessage)
437 {
438 gSMFields.signMessage = false;
439 setNoSignatureUI();
440 }
441 }
442 }
443
444 top.controllers.appendController(SecurityController);
445 addEventListener('compose-window-close', onComposerClose, true);
446 addEventListener('compose-window-reopen', onComposerReOpen, true);
447 addEventListener('compose-send-message', onComposerSendMessage, true);
448 addEventListener('compose-from-changed', onComposerFromChanged, true);