1999-06-08 00:59:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1999-06-08 02:17:35 +00:00
|
|
|
* 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 Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
1999-06-08 00:59:02 +00:00
|
|
|
*/
|
|
|
|
|
1999-06-08 02:17:35 +00:00
|
|
|
|
1999-06-08 00:59:02 +00:00
|
|
|
/*
|
|
|
|
* Command-specific code. This stuff should be called by the widgets
|
|
|
|
*/
|
|
|
|
|
1999-06-04 04:00:58 +00:00
|
|
|
var messenger = Components.classes['component://netscape/messenger'].createInstance();
|
|
|
|
messenger = messenger.QueryInterface(Components.interfaces.nsIMessenger);
|
|
|
|
|
1999-06-11 00:25:15 +00:00
|
|
|
var msgComposeService = Components.classes['component://netscape/messengercompose'].getService();
|
|
|
|
msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);
|
|
|
|
|
1999-06-03 22:56:45 +00:00
|
|
|
var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService();
|
|
|
|
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
|
|
|
|
|
|
|
//put this in a function so we can change the position in hierarchy if we have to.
|
|
|
|
function GetFolderTree()
|
|
|
|
{
|
|
|
|
var folderTree = frames[0].frames[0].document.getElementById('folderTree');
|
|
|
|
return folderTree;
|
|
|
|
}
|
|
|
|
|
1999-06-04 04:00:58 +00:00
|
|
|
function FindMessenger()
|
1999-05-28 19:41:31 +00:00
|
|
|
{
|
1999-06-04 04:00:58 +00:00
|
|
|
return messenger;
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function OpenURL(url)
|
|
|
|
{
|
|
|
|
dump("\n\nOpenURL from XUL\n\n\n");
|
1999-06-08 04:28:43 +00:00
|
|
|
messenger.SetWindow(window);
|
1999-06-08 00:26:29 +00:00
|
|
|
messenger.OpenURL(url);
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
1999-06-11 00:25:15 +00:00
|
|
|
function ComposeMessage(type, format)
|
|
|
|
//type: 0=new message, 1=reply, 2=reply all,
|
|
|
|
// 3=forward inline, 4=forward quoted, 5=forward as attachment
|
|
|
|
//
|
|
|
|
//format: 0=default (use preference), 1=HTML, 2=plain text
|
1999-05-28 19:41:31 +00:00
|
|
|
{
|
|
|
|
dump("\nComposeMessage from XUL\n");
|
1999-06-11 00:25:15 +00:00
|
|
|
var uri = null;
|
1999-05-28 19:41:31 +00:00
|
|
|
|
1999-06-11 00:25:15 +00:00
|
|
|
if (! msgComposeService)
|
|
|
|
{
|
|
|
|
dump("### msgComposeService is invalid\n");
|
|
|
|
return;
|
|
|
|
}
|
1999-05-28 19:41:31 +00:00
|
|
|
|
1999-06-11 00:25:15 +00:00
|
|
|
if (type == 0) //new message
|
|
|
|
{
|
|
|
|
msgComposeService.OpenComposeWindow(null, null, 0, format, null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tree = frames[0].frames[1].document.getElementById('threadTree');
|
|
|
|
if (tree)
|
1999-05-28 19:41:31 +00:00
|
|
|
{
|
1999-06-11 00:25:15 +00:00
|
|
|
var nodeList = tree.getElementsByAttribute("selected", "true");
|
|
|
|
var appCore = FindMessenger();
|
|
|
|
if (appCore)
|
|
|
|
appCore.SetWindow(window);
|
|
|
|
|
|
|
|
var object = null;
|
|
|
|
|
|
|
|
if (nodeList && nodeList.length > 0)
|
1999-05-28 19:41:31 +00:00
|
|
|
{
|
1999-06-11 00:25:15 +00:00
|
|
|
uri = "";
|
|
|
|
for (var i = 0; i < nodeList.length && i < 8; i ++)
|
|
|
|
{
|
|
|
|
if (type == 1 || type == 2) //reply or reply all
|
|
|
|
{
|
|
|
|
if (appCore)
|
|
|
|
object = appCore.GetRDFResourceForMessage(tree, nodeList); //temporary
|
|
|
|
msgComposeService.OpenComposeWindow(null, nodeList[i].getAttribute('id'), type, format, object);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
uri += " "
|
|
|
|
uri += nodeList[i].getAttribute('id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type >= 3 && type <= 5) //forward
|
|
|
|
{
|
|
|
|
if (appCore)
|
|
|
|
object = appCore.GetRDFResourceForMessage(tree, nodeList); //temporary
|
|
|
|
msgComposeService.OpenComposeWindow(null, uri, type, format, object);
|
|
|
|
}
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
1999-06-11 00:25:15 +00:00
|
|
|
dump("### nodeList is invalid\n");
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
1999-06-11 00:25:15 +00:00
|
|
|
else
|
|
|
|
dump("### tree is invalid\n");
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function NewMessage()
|
|
|
|
{
|
|
|
|
|
|
|
|
dump("\n\nnewMsg from XUL\n\n\n");
|
1999-06-11 00:25:15 +00:00
|
|
|
ComposeMessage(0, 0);
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function GetNewMessages()
|
|
|
|
{
|
|
|
|
var folderTree = frames[0].frames[0].document.getElementById('folderTree');
|
|
|
|
var selectedFolderList = folderTree.getElementsByAttribute("selected", "true");
|
|
|
|
if(selectedFolderList.length > 0)
|
|
|
|
{
|
|
|
|
var selectedFolder = selectedFolderList[0];
|
1999-06-08 00:26:29 +00:00
|
|
|
messenger.GetNewMessages(folderTree.database, selectedFolder);
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
dump("Nothing was selected\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function LoadMessage(messageNode)
|
|
|
|
{
|
|
|
|
var uri = messageNode.getAttribute('id');
|
|
|
|
dump(uri);
|
1999-06-11 22:11:32 +00:00
|
|
|
if(uri)
|
|
|
|
OpenURL(uri);
|
1999-05-28 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ChangeFolderByDOMNode(folderNode)
|
|
|
|
{
|
|
|
|
var uri = folderNode.getAttribute('id');
|
|
|
|
dump(uri + "\n");
|
|
|
|
ChangeFolderByURI(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ChangeFolderByURI(uri)
|
|
|
|
{
|
|
|
|
var tree = frames[0].frames[1].document.getElementById('threadTree');
|
|
|
|
tree.childNodes[5].setAttribute('id', uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SortThreadPane(column, sortKey)
|
|
|
|
{
|
|
|
|
var node = frames[0].frames[1].document.getElementById(column);
|
|
|
|
if(!node)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var rdfCore = XPAppCoresManager.Find("RDFCore");
|
|
|
|
if (!rdfCore)
|
|
|
|
{
|
|
|
|
rdfCore = new RDFCore();
|
|
|
|
if (!rdfCore)
|
|
|
|
{
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
rdfCore.Init("RDFCore");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// sort!!!
|
|
|
|
sortDirection = "ascending";
|
|
|
|
var currentDirection = node.getAttribute('sortDirection');
|
|
|
|
if (currentDirection == "ascending")
|
|
|
|
sortDirection = "descending";
|
|
|
|
else if (currentDirection == "descending")
|
|
|
|
sortDirection = "ascending";
|
|
|
|
else sortDirection = "ascending";
|
|
|
|
|
|
|
|
rdfCore.doSort(node, sortKey, sortDirection);
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function MsgPreferences()
|
|
|
|
{
|
|
|
|
var prefsCore = XPAppCoresManager.Find("PrefsCore");
|
|
|
|
if (!prefsCore) {
|
|
|
|
prefsCore = new PrefsCore();
|
|
|
|
if (prefsCore) {
|
|
|
|
prefsCore.Init("PrefsCore");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prefsCore) {
|
|
|
|
prefsCore.ShowWindow(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-03 22:56:45 +00:00
|
|
|
|
|
|
|
function GetSelectedFolderResource()
|
|
|
|
{
|
|
|
|
var folderTree = GetFolderTree();
|
|
|
|
var selectedFolderList = folderTree.getElementsByAttribute("selected", "true");
|
|
|
|
var selectedFolder = selectedFolderList[0];
|
|
|
|
var uri = selectedFolder.getAttribute('id');
|
|
|
|
|
|
|
|
|
|
|
|
var folderResource = RDF.GetResource(uri);
|
|
|
|
return folderResource;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function SetFolderCharset(folderResource, aCharset)
|
|
|
|
{
|
|
|
|
var folderTree = GetFolderTree();
|
|
|
|
|
|
|
|
var db = folderTree.database;
|
|
|
|
var db2 = db.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
|
|
|
|
var charsetResource = RDF.GetLiteral(aCharset);
|
|
|
|
var charsetProperty = RDF.GetResource("http://home.netscape.com/NC-rdf#Charset");
|
|
|
|
|
|
|
|
db2.Assert(folderResource, charsetProperty, charsetResource, true);
|
|
|
|
}
|