implement "pre-select the right identity when composing based on folder pane selection" feature.
This commit is contained in:
sspitzer%netscape.com 1999-09-20 08:13:27 +00:00
parent 9207a13c6e
commit 95fca3acb9
5 changed files with 129 additions and 19 deletions

View File

@ -83,11 +83,14 @@ interface nsIMsgAccountManager : nsISupports {
/*
* search for the server with the given username, hostname, and type
* the type is the same as is specified in the preferences,
* i.e. "imap", "pop3", or "nntp"
* i.e. "imap", "pop3", "none", or "nntp"
*/
nsIMsgIncomingServer
FindServer(in string userName, in string hostname, in string type);
nsIMsgIncomingServer
FindServerUsingURI(in string uri);
/**
* find the index of this server in the (ordered) list of accounts
*/

View File

@ -26,6 +26,8 @@
var msgComposeService = Components.classes['component://netscape/messengercompose'].getService();
msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);
var mailSession = Components.classes["component://netscape/messenger/services/session"].getService(Components.interfaces.nsIMsgMailSession);
var accountManager = mailSession.accountManager;
var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService();
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
@ -49,13 +51,34 @@ function ComposeMessage(type, format)
//
//format: 0=default (use preference), 1=HTML, 2=plain text
{
var folderTree = GetFolderTree();
var selectedFolderList = folderTree.selectedItems;
if(selectedFolderList.length > 0)
{
var selectedFolder = selectedFolderList[0];
var uri = selectedFolder.getAttribute('id');
dump("selectedFolder uri = " + uri + "\n");
var identity = null;
try
{
var folderTree = GetFolderTree();
var selectedFolderList = folderTree.selectedItems;
if(selectedFolderList.length > 0)
{
var selectedFolder = selectedFolderList[0];
var uri = selectedFolder.getAttribute('id');
// dump("selectedFolder uri = " + uri + "\n");
// get the server associated with this uri
var server = accountManager.FindServerUsingURI(uri);
// dump("server = " + server + "\n");
// get the identity associated with this server
var identities = accountManager.GetIdentitiesForServer(server);
// dump("identities = " + identities + "\n");
// just get the first one
if (identities.Count() > 0 ) {
identity = identities.GetElementAt(0).QueryInterface(Components.interfaces.nsIMsgIdentity);
}
}
// dump("identity = " + identity + "\n");
}
catch (ex)
{
// dump("failed to get an identity to pre-select\n");
}
dump("\nComposeMessage from XUL\n");
@ -69,7 +92,7 @@ function ComposeMessage(type, format)
if (type == 0) //new message
{
msgComposeService.OpenComposeWindow(null, null, 0, format, null, null);
msgComposeService.OpenComposeWindow(null, null, 0, format, null, identity);
return;
}
@ -94,7 +117,7 @@ function ComposeMessage(type, format)
{
if (appCore)
object = appCore.GetRDFResourceForMessage(tree, nodeList); //temporary
msgComposeService.OpenComposeWindow(null, nodeList[i].getAttribute('id'), type, format, object, null);
msgComposeService.OpenComposeWindow(null, nodeList[i].getAttribute('id'), type, format, object, identity);
}
else
{
@ -108,7 +131,7 @@ function ComposeMessage(type, format)
{
if (appCore)
object = appCore.GetRDFResourceForMessage(tree, nodeList); //temporary
msgComposeService.OpenComposeWindow(null, uri, type, format, object, null);
msgComposeService.OpenComposeWindow(null, uri, type, format, object, identity);
}
}
else

View File

@ -41,6 +41,7 @@
#include "nsSpecialSystemDirectory.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsIURL.h"
// this should eventually be moved to the pop3 server for upgrading
#include "nsIPop3IncomingServer.h"
@ -64,6 +65,7 @@ static NS_DEFINE_CID(kMsgBiffManagerCID, NS_MSGBIFFMANAGER_CID);
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
#define IMAP_SCHEMA "imap:/"
#define IMAP_SCHEMA_LENGTH 6
@ -2289,6 +2291,54 @@ nsMsgAccountManager::MigrateOldNntpPrefs(nsIMsgIncomingServer *server, const cha
return NS_OK;
}
NS_IMETHODIMP
nsMsgAccountManager::FindServerUsingURI(const char* uri, nsIMsgIncomingServer **aResult)
{
nsresult rv;
nsXPIDLCString username;
nsXPIDLCString hostname;
nsXPIDLCString scheme;
nsXPIDLCString type;
nsCOMPtr <nsIURL> url;
if (!uri) return NS_ERROR_NULL_POINTER;
rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, nsCOMTypeInfo<nsIURL>::GetIID(), getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
rv = url->SetSpec(uri);
if (NS_FAILED(rv)) return rv;
rv = url->GetHost(getter_Copies(hostname));
if (NS_FAILED(rv)) return rv;
rv = url->GetPreHost(getter_Copies(username));
if (NS_FAILED(rv)) return rv;
rv = url->GetScheme(getter_Copies(scheme));
if (NS_FAILED(rv)) return rv;
if (PL_strcmp("imap", (const char *)scheme) == 0) {
rv = FindServer(username, hostname, "imap", aResult);
}
else if (PL_strcmp("news", (const char *)scheme) == 0) {
rv = FindServer(username, hostname, "nntp", aResult);
}
else if (PL_strcmp("mailbox", (const char *)scheme) == 0) {
// mailbox:/ can be "pop3" or "none" (a.k.a, local mail)
rv = FindServer(username, hostname, "pop3", aResult);
if (NS_FAILED(rv)) {
rv = FindServer(username, hostname, "none", aResult);
}
}
else {
#ifdef DEBUG_ACCOUNTMANAGER
NS_ASSERTION(0,"FindServerUsingURI failed because scheme was unrecognized");
#endif
rv = NS_ERROR_FAILURE;
}
return rv;
}
NS_IMETHODIMP
nsMsgAccountManager::FindServer(const char* username,
const char* hostname,
@ -2297,7 +2347,11 @@ nsMsgAccountManager::FindServer(const char* username,
{
nsresult rv;
nsCOMPtr<nsISupportsArray> servers;
#ifdef DEBUG_ACCOUNTMANAGER_
printf("FindServer(%s,%s,%s,??)\n", username,hostname,type);
#endif
rv = GetAllServers(getter_AddRefs(servers));
if (NS_FAILED(rv)) return rv;

View File

@ -137,8 +137,26 @@ function ComposeStartup()
// autoselect the first identity. soon, we'll be smarter about this
// and select the one that is appropriate. bug #10235
if (identitySelect) {
identitySelect.selectedIndex = 0;
try {
// find args.preselectid and choose it.
// dump("args.preselectid = " + args.preselectid + "\n");
options = identitySelect.options
var preselectindex = 0;
for (i=0;i<options.length;i++) {
// dump(options[i].value + "\n");
if (options[i].value == args.preselectid) {
preselectindex = i;
break;
}
}
identitySelect.selectedIndex = preselectindex;
}
catch (ex) {
// dump("failed to preselect an identity\n");
if (identitySelect && identitySelect.options && (identitySelect.options.length >0)) {
// just pick the first one
identitySelect.selectedIndex = 0;
}
}
// fill in Recipient type combobox
@ -443,7 +461,7 @@ function SelectAddress()
function queryISupportsArray(supportsArray, iid) {
var result = new Array;
for (var i=0; i<supportsArray.Count(); i++) {
dump(i + "," + result[i] + "\n");
// dump(i + "," + result[i] + "\n");
result[i] = supportsArray.GetElementAt(i).QueryInterface(iid);
}
return result;
@ -467,13 +485,13 @@ function fillIdentitySelect(selectElement)
{
var identities = GetIdentities();
dump("identities = " + identities + "\n");
// dump("identities = " + identities + "\n");
for (var i=0; i<identities.length; i++)
{
var identity = identities[i];
var opt = new Option(identity.identityName, identity.key);
dump(i + " = " + identity.identityName + "," +identity.key + "\n");
// dump(i + " = " + identity.identityName + "," +identity.key + "\n");
selectElement.add(opt, null);
}
@ -487,7 +505,7 @@ function getCurrentIdentity()
// fill in Identity combobox
var identitySelect = document.getElementById("msgIdentity");
var identityKey = identitySelect.value;
dump("Looking for identity " + identityKey + "\n");
// dump("Looking for identity " + identityKey + "\n");
var identity = accountManager.getIdentity(identityKey);
return identity;
@ -579,7 +597,7 @@ function GenerateAttachmentsString()
function RemoveLastAttachment()
{
dump("RemoveLastAttachment()\n");
// dump("RemoveLastAttachment()\n");
selectNode = document.getElementById('attachments');
i = selectNode.options.length;
if (i > 0) {

View File

@ -26,6 +26,8 @@
#include "nsIWebShell.h"
#include "nsAppCoresCIDs.h"
#include "nsIDOMToolkitCore.h"
#include "nsXPIDLString.h"
#include "nsIMsgIdentity.h"
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_CID(kToolkitCoreCID, NS_TOOLKITCORE_CID);
@ -91,6 +93,16 @@ nsresult nsMsgComposeService::OpenComposeWindow(const PRUnichar *msgComposeWindo
args.Append("format=");
args.Append(format);
if (identity) {
nsXPIDLCString key;
rv = identity->GetKey(getter_Copies(key));
if (NS_SUCCEEDED(rv) && key && (PL_strlen(key) > 0)) {
args.Append(",");
args.Append("preselectid=");
args.Append(key);
}
}
if (originalMsgURI && *originalMsgURI)
{
args.Append(",originalMsg='");