S/MIME UI work

git-svn-id: svn://10.0.0.236/branches/PSM_2_2_DEV_20011002_BRANCH@105826 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ddrinan%netscape.com
2001-10-19 21:36:55 +00:00
parent 9560e3853c
commit 15874430b3
12 changed files with 379 additions and 1 deletions

View File

@@ -0,0 +1,207 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributors:
* ddrinan@netscape.com
*/
var gIncomingServer;
var gServerType;
var gPref = null;
var gLockedPref = null;
function onInit()
{
onLockPreference();
// init values here
document.getElementById("encryption.ifPossibleEncryptMail").checked = gIncomingServer.ifPossibleEncryptMail;
document.getElementById("encryption.alwaysEncryptMail").checked = gIncomingServer.alwaysEncryptMail;
document.getElementById("encryption.certificateName").setAttribute("value", gIncomingServer.encryptionCertName);
document.getElementById("signing.signMail").checked = gIncomingServer.signMail;
document.getElementById("signing.certificateName").setAttribute("value", gIncomingServer.signingCertName);
// Disable the encrypt if possibe check box.
document.getElementById("encryption.ifPossibleEncryptMail").setAttribute("disabled", "true");
}
function onPreInit(account, accountValues)
{
gServerType = getAccountValue(account, accountValues, "server", "type");
hideShowControls(gServerType);
gIncomingServer= account.incomingServer;
gIncomingServer.type = gServerType;
var prefBundle = document.getElementById("bundle_prefs");
var headertitle = document.getElementById("headertitle");
headertitle.setAttribute('title',prefBundle.getString("prefPanel-security"));
}
function hideShowControls(type)
{
var controls = document.getElementsByAttribute("hidable", "true");
var len = controls.length;
for (var i=0; i<len; i++) {
var control = controls[i];
var hideFor = control.getAttribute("hidefor");
if (!hideFor)
throw "this should not happen, things that are hidable should have hidefor set";
var box = getEnclosingContainer(control);
if (!box)
throw "this should not happen, things that are hidable should be in a box";
// hide unsupported server type
// adding support for hiding multiple server types using hideFor="server1,server2"
var hideForBool = false;
var hideForTokens = hideFor.split(",");
for (var j = 0; j < hideForTokens.length; j++) {
if (hideForTokens[j] == type) {
hideForBool = true;
break;
}
}
if (hideForBool) {
box.setAttribute("hidden", "true");
}
else {
box.removeAttribute("hidden");
}
}
}
function getEnclosingContainer(startNode) {
var parent = startNode;
var box;
while (parent && parent != document) {
var isContainer = (parent.getAttribute("iscontrolcontainer") == "true");
if (!box || isContainer)
box=parent;
// break out with a controlcontainer
if (isContainer)
break;
parent = parent.parentNode;
}
return box;
}
function onSave()
{
gIncomingServer.ifPossibleEncryptMail = document.getElementById("encryption.ifPossibleEncryptMail").checked;
gIncomingServer.alwaysEncryptMail = document.getElementById("encryption.alwaysEncryptMail").checked;
gIncomingServer.encryptionCertName = document.getElementById("encryption.certificateName").value;
gIncomingServer.signMail = document.getElementById("signing.signMail").checked;
gIncomingServer.signingCertName = document.getElementById("signing.certificateName").value;
}
// Does the work of disabling an element given the array which contains xul id/prefstring pairs.
// Also saves the id/locked state in an array so that other areas of the code can avoid
// stomping on the disabled state indiscriminately.
function disableIfLocked( prefstrArray )
{
if (!gLockedPref)
gLockedPref = new Array;
for (i=0; i<prefstrArray.length; i++) {
var id = prefstrArray[i].id;
var element = document.getElementById(id);
if (gPref.prefIsLocked(prefstrArray[i].prefstring)) {
element.disabled = true;
gLockedPref[id] = true;
} else {
element.removeAttribute("disabled");
gLockedPref[id] = false;
}
}
}
// Disables xul elements that have associated preferences locked.
function onLockPreference()
{
var isDownloadLocked = false;
var isGetNewLocked = false;
var initPrefString = "mail.server";
var finalPrefString;
var prefService = Components.classes["@mozilla.org/preferences-service;1"];
prefService = prefService.getService();
prefService = prefService.QueryInterface(Components.interfaces.nsIPrefService);
// This panel does not use the code in AccountManager.js to handle
// the load/unload/disable. keep in mind new prefstrings and changes
// to code in AccountManager, and update these as well.
var allPrefElements = [
{ prefstring:"encrypt_if_possible", id:"encryption.ifPossibleEncryptMail"},
{ prefstring:"encrypt_always", id:"encryption.alwaysEncryptMail"},
{ prefstring:"encryption_cert_name", id:"encryption.certificateName"},
{ prefstring:"sign", id:"signing.signMail"},
{ prefstring:"signing_cert_name", id:"signing.certificateName"}
];
finalPrefString = initPrefString + "." + gIncomingServer.key + ".";
gPref = prefService.getBranch(finalPrefString);
disableIfLocked( allPrefElements );
}
function smimeSelectCert(smime_cert)
{
var picker = Components.classes["@mozilla.org/user_cert_picker;1"]
.getService(Components.interfaces.nsIUserCertPicker);
var canceled = new Object;
var x509cert = 0;
var certUsage;
var prefBundle = document.getElementById("bundle_prefs");
if (smime_cert == "encryption.certificateName") {
certUsage = 5;
} else if (smime_cert == "signing.certificateName") {
certUsage = 4;
}
try {
x509cert = picker.pickByUsage(window,
"X",
"Y",
certUsage, // this is from enum SECCertUsage
false, false, canceled);
} catch(e) {
// XXX display error message in the future
}
if (!canceled.value && x509cert) {
var certInfo = document.getElementById(smime_cert);
if (certInfo) {
certInfo.setAttribute("disabled", "false");
certInfo.value = x509cert.nickname;
}
}
}

View File

@@ -0,0 +1,80 @@
<?xml version="1.0"?>
<!--
The contents of this file are subject to the Netscape Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/NPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-2001 Netscape Communications Corporation. All
Rights Reserved.
Contributors:
ddrinan@netscape.com
-->
<?xml-stylesheet href="chrome://messenger/skin/accountManage.css" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://messenger/locale/am-security.dtd">
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
class="color-dialog"
onload="parent.onPanelLoaded('am-security.xul');"
orient="vertical">
<stringbundle id="bundle_prefs" src="chrome://messenger/locale/prefs.properties"/>
<script type="application/x-javascript" src="chrome://messenger/content/AccountManager.js"/>
<script type="application/x-javascript" src="chrome://messenger/content/am-security.js"/>
<hbox id="headertitle" class="box-smallheader"/>
<groupbox orient="vertical" id="encryption.titlebox" hidable="true" hidefor="nntp">
<label value="&encryptionGroupTitle.label;"/>
<checkbox iscontrolcontainer="true" hidable="true" hidefor="nntp"
id="encryption.ifPossibleEncryptMail" disabled="true" label="&ifPossibleEncryptMail.label;" />
<checkbox iscontrolcontainer="true" hidable="true" hidefor="nntp"
id="encryption.alwaysEncryptMail" label="&alwaysEncryptMail.label;" />
<html iscontrolcontainer="true" hidable="true" hidefor="nntp"> &encryptionCert.message;</html>
<separator class="thin" hidable="true" hidefor="nntp"/>
<textbox iscontrolcontainer="true" hidable="true" hidefor="nntp" id="encryption.certificateName" value="&encryptionCert.notselected;" readonly="true" disabled="true"/>
<separator class="thin" hidable="true" hidefor="nntp"/>
<hbox iscontrolcontainer="true" hidable="true" hidefor="nntp">
<spacer flex="1"/>
<button id="encryptionCertSelectButton"
label="&certificate.button;"
oncommand="smimeSelectCert('encryption.certificateName')"/>
</hbox>
</groupbox>
<separator class="thin"/>
<groupbox orient="vertical" id="signing.titlebox">
<label value="&signingGroupTitle.label;"/>
<checkbox iscontrolcontainer="true" id="signing.signMail" label="&signMail.label;" />
<html>&signingCert.message;</html>
<separator class="thin"/>
<textbox id="signing.certificateName" value="&signingCert.notselected;" readonly="true" disabled="true"/>
<separator class="thin"/>
<hbox>
<spacer flex="1"/>
<button id="signingCertSelectButton"
label="&certificate.button;"
oncommand="smimeSelectCert('signing.certificateName')"/>
</hbox>
</groupbox>
</window>

View File

@@ -0,0 +1,10 @@
<!ENTITY encryptionGroupTitle.label "Encryption">
<!ENTITY ifPossibleEncryptMail.label "Encrypt messages if possible">
<!ENTITY alwaysEncryptMail.label "Always encrypt messages">
<!ENTITY encryptionCert.message "Personal certificate used for encryption">
<!ENTITY encryptionCert.notselected "No certificate set">
<!ENTITY certificate.button "Select Certificate">
<!ENTITY signingGroupTitle.label "Signing">
<!ENTITY signMail.label "Digitally sign messages">
<!ENTITY signingCert.message "Personal certificate used for signing">
<!ENTITY signingCert.notselected "No certificate set">

View File

@@ -59,5 +59,6 @@ prefPanel-offline-and-diskspace=Offline & Disk Space
prefPanel-diskspace=Disk Space
prefPanel-addressing=Addressing
prefPanel-advanced=Advanced
prefPanel-security=Security
## LOCALIZATION NOTE (prefPanel-smtp): Don't translate "SMTP"
prefPanel-smtp=Outgoing Server (SMTP)

View File

@@ -267,6 +267,15 @@ interface nsIMsgIncomingServer : nsISupports {
/* used for setting up the search UI */
readonly attribute nsMsgSearchScopeValue searchScope;
/* S/MIME attributes... */
/* ...encryption */
attribute boolean ifPossibleEncryptMail;
attribute boolean alwaysEncryptMail;
attribute string encryptionCertName;
/* ...signing */
attribute boolean signMail;
attribute string signingCertName;
};
%{C++

View File

@@ -57,6 +57,7 @@ static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define NC_RDF_PAGETITLE_ADDRESSING NC_NAMESPACE_URI "PageTitleAddressing"
#define NC_RDF_PAGETITLE_SMTP NC_NAMESPACE_URI "PageTitleSMTP"
#define NC_RDF_PAGETAG NC_NAMESPACE_URI "PageTag"
#define NC_RDF_PAGETITLE_SECURITY NC_NAMESPACE_URI "PageTitleSecurity"
#define NC_RDF_ACCOUNTROOT "msgaccounts:/"
@@ -103,6 +104,7 @@ nsIRDFResource* nsMsgAccountManagerDataSource::kNC_PageTitleDiskSpace=nsnull;
nsIRDFResource* nsMsgAccountManagerDataSource::kNC_PageTitleAddressing=nsnull;
nsIRDFResource* nsMsgAccountManagerDataSource::kNC_PageTitleAdvanced=nsnull;
nsIRDFResource* nsMsgAccountManagerDataSource::kNC_PageTitleSMTP=nsnull;
nsIRDFResource* nsMsgAccountManagerDataSource::kNC_PageTitleSecurity=nsnull;
// common literals
nsIRDFLiteral* nsMsgAccountManagerDataSource::kTrueLiteral = nsnull;
@@ -154,6 +156,7 @@ nsMsgAccountManagerDataSource::nsMsgAccountManagerDataSource()
getRDFService()->GetResource(NC_RDF_PAGETITLE_ADDRESSING, &kNC_PageTitleAddressing);
getRDFService()->GetResource(NC_RDF_PAGETITLE_ADVANCED, &kNC_PageTitleAdvanced);
getRDFService()->GetResource(NC_RDF_PAGETITLE_SMTP, &kNC_PageTitleSMTP);
getRDFService()->GetResource(NC_RDF_PAGETITLE_SECURITY, &kNC_PageTitleSecurity);
getRDFService()->GetResource(NC_RDF_ACCOUNTROOT, &kNC_AccountRoot);
@@ -302,7 +305,9 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source,
else if (source == kNC_PageTitleSMTP)
mStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("prefPanel-smtp").get(),
getter_Copies(pageTitle));
else if (source == kNC_PageTitleSecurity)
mStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2("prefPanel-security").get(),
getter_Copies(pageTitle));
else {
nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(source, &rv);
if (NS_SUCCEEDED(rv)) {
@@ -328,6 +333,8 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source,
str = NS_LITERAL_STRING("am-advanced.xul");
else if (source == kNC_PageTitleSMTP)
str = NS_LITERAL_STRING("am-smtp.xul");
else if (source == kNC_PageTitleSecurity)
str = NS_LITERAL_STRING("am-security.xul");
else {
str = NS_LITERAL_STRING("am-main.xul");
@@ -568,6 +575,8 @@ nsMsgAccountManagerDataSource::createSettingsResources(nsIRDFResource *aSource,
else if (supportsDiskSpace) {
aNodeArray->AppendElement(kNC_PageTitleDiskSpace);
}
aNodeArray->AppendElement(kNC_PageTitleSecurity);
}
}
}

View File

@@ -130,6 +130,7 @@ protected:
static nsIRDFResource* kNC_PageTitleAddressing;
static nsIRDFResource* kNC_PageTitleAdvanced;
static nsIRDFResource* kNC_PageTitleSMTP;
static nsIRDFResource* kNC_PageTitleSecurity;
static nsIRDFLiteral* kTrueLiteral;

View File

@@ -1349,6 +1349,26 @@ nsMsgIncomingServer::GetSearchScope(nsMsgSearchScopeValue *searchScope)
return NS_OK;
}
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer,
IfPossibleEncryptMail,
"encrypt_mail_if_possible");
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer,
AlwaysEncryptMail,
"encrypt_mail_always");
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer,
EncryptionCertName,
"encryption_cert_name");
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer,
SignMail,
"sign_mail");
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer,
SigningCertName,
"signing_cert_name");
// use the convenience macros to implement the accessors
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, Username, "userName");
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, PrefPassword, "password");

View File

@@ -2325,3 +2325,26 @@ function DisplaySaveFolderDlg(folderURI)
return;
}
function EncryptMessage()
{
var msgCompFields = msgCompose.compFields;
if (msgCompFields) {
if (msgCompFields.encrypted) {
msgCompFields.encrypted = false;
} else {
msgCompFields.encrypted = true;
}
}
}
function SignMessage()
{
var msgCompFields = msgCompose.compFields;
if (msgCompFields) {
if (msgCompFields.signed) {
msgCompFields.signed = false;
} else {
msgCompFields.signed = true;
}
}
}

View File

@@ -342,6 +342,16 @@
</rule>
</template>
</menu>
<menuseparator/>
<menu label="&securityMenu.label;">
<menupopup>
<menuitem id="menu_securityEncryptAlways" type="checkbox" label="&menu_securityEncryptAlways.label;" oncommand="EncryptMessage()"/>
<menuitem id="menu_securityEncryptIfPossible" type="checkbox" label="&menu_securityEncryptIfPossible.label;" disabled="true"/>
<menuitem id="menu_securitySign" type="checkbox" label="&menu_securitySign.label;" oncommand="SignMessage()"/>
</menupopup>
</menu>
<!--menuseparator/>
<menuitem label="&addSignatureCmd.label;" disabled="true" oncommand=""/>
<menuitem label="&attachVCardCmd.label;" disabled="true" accesskey="&attachVCardCmd.accesskey;" oncommand="AttachVCard()"/-->

View File

@@ -142,6 +142,11 @@
<!ENTITY fileCarbonCopyCmd.accesskey "i">
<!ENTITY fileHereMenu.label "File Here">
<!ENTITY securityMenu.label "Security">
<!ENTITY menu_securityEncryptIfPossible.label "Encrypt if Possible">
<!ENTITY menu_securityEncryptAlways.label "Always Encrypt">
<!ENTITY menu_securitySign.label "Sign">
<!--LOCALIZATION NOTE Debug Menu Don't translate anything in the Debug menu section -->
<!-- Debug Menu, imported from editorAppShell.dtd -->
<!ENTITY debugMenu.label "Debug">

View File

@@ -44,6 +44,8 @@ messenger.jar:
content/messenger/am-copies.js (base/prefs/resources/content/am-copies.js)
content/messenger/am-offline.xul (base/prefs/resources/content/am-offline.xul)
content/messenger/am-offline.js (base/prefs/resources/content/am-offline.js)
content/messenger/am-security.xul (base/prefs/resources/content/am-security.xul)
content/messenger/am-security.js (base/prefs/resources/content/am-security.js)
content/messenger/am-addressing.xul (base/prefs/resources/content/am-addressing.xul)
content/messenger/am-addressing.js (base/prefs/resources/content/am-addressing.js)
content/messenger/am-advanced.xul (base/prefs/resources/content/am-advanced.xul)
@@ -251,6 +253,7 @@ en-US.jar:
locale/en-US/messenger/am-imap-advanced.dtd (base/prefs/resources/locale/en-US/am-imap-advanced.dtd)
locale/en-US/messenger/am-copies.dtd (base/prefs/resources/locale/en-US/am-copies.dtd)
locale/en-US/messenger/am-offline.dtd (base/prefs/resources/locale/en-US/am-offline.dtd)
locale/en-US/messenger/am-security.dtd (base/prefs/resources/locale/en-US/am-security.dtd)
locale/en-US/messenger/am-addressing.dtd (base/prefs/resources/locale/en-US/am-addressing.dtd)
locale/en-US/messenger/am-main.dtd (base/prefs/resources/locale/en-US/am-main.dtd)
locale/en-US/messenger/am-identity-advanced.dtd (base/prefs/resources/locale/en-US/am-identity-advanced.dtd)