2009-09-01 01:46:26 +04:00
|
|
|
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2008-07-22 16:21:15 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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 the Initial Developer are Copyright (C) 1998-1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Jan Varga (varga@ku.sk)
|
|
|
|
* Håkan Waara (hwaara@chello.se)
|
|
|
|
* Neil Rashbrook (neil@parkwaycc.co.uk)
|
|
|
|
* Seth Spitzer <sspitzer@netscape.com>
|
2009-09-01 01:46:26 +04:00
|
|
|
* Karsten Düsterloh <mnyromyr@tprac.de>
|
2010-06-07 01:59:58 +04:00
|
|
|
* Ian Neal <iann_bugzilla@blueyonder.co.uk>
|
2008-07-22 16:21:15 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* This is where functions related to the 3 pane window are kept */
|
|
|
|
|
|
|
|
// from MailNewsTypes.h
|
|
|
|
const nsMsgKey_None = 0xFFFFFFFF;
|
|
|
|
const nsMsgViewIndex_None = 0xFFFFFFFF;
|
|
|
|
const kMailCheckOncePrefName = "mail.startup.enabledMailCheckOnce";
|
|
|
|
|
|
|
|
var gFolderTree;
|
|
|
|
var gSearchInput;
|
|
|
|
|
|
|
|
var gUnreadCount = null;
|
|
|
|
var gTotalCount = null;
|
|
|
|
|
|
|
|
var gCurrentLoadingFolderURI;
|
|
|
|
var gCurrentFolderToReroot;
|
|
|
|
var gCurrentLoadingFolderSortType = 0;
|
|
|
|
var gCurrentLoadingFolderSortOrder = 0;
|
|
|
|
var gCurrentLoadingFolderViewType = 0;
|
|
|
|
var gCurrentLoadingFolderViewFlags = 0;
|
|
|
|
var gRerootOnFolderLoad = false;
|
|
|
|
var gCurrentDisplayedMessage = null;
|
|
|
|
var gNextMessageAfterDelete = null;
|
|
|
|
var gNextMessageAfterLoad = null;
|
|
|
|
var gNextMessageViewIndexAfterDelete = -2;
|
|
|
|
var gCurrentlyDisplayedMessage=nsMsgViewIndex_None;
|
|
|
|
var gStartMsgKey = nsMsgKey_None;
|
|
|
|
var gSearchEmailAddress = null;
|
|
|
|
var gRightMouseButtonDown = false;
|
|
|
|
// Global var to keep track of which row in the thread pane has been selected
|
|
|
|
// This is used to make sure that the row with the currentIndex has the selection
|
|
|
|
// after a Delete or Move of a message that has a row index less than currentIndex.
|
|
|
|
var gThreadPaneCurrentSelectedIndex = -1;
|
2008-09-29 04:41:52 +04:00
|
|
|
// Account Wizard can exceptionally override this feature.
|
2008-07-22 16:21:15 +04:00
|
|
|
var gLoadStartFolder = true;
|
|
|
|
|
|
|
|
// Global var to keep track of if the 'Delete Message' or 'Move To' thread pane
|
|
|
|
// context menu item was triggered. This helps prevent the tree view from
|
|
|
|
// not updating on one of those menu item commands.
|
|
|
|
var gThreadPaneDeleteOrMoveOccurred = false;
|
|
|
|
|
|
|
|
//If we've loaded a message, set to true. Helps us keep the start page around.
|
|
|
|
var gHaveLoadedMessage;
|
|
|
|
|
|
|
|
var gDisplayStartupPage = false;
|
|
|
|
|
|
|
|
function SelectAndScrollToKey(aMsgKey)
|
|
|
|
{
|
|
|
|
// select the desired message
|
|
|
|
// if the key isn't found, we won't select anything
|
2009-09-01 01:46:26 +04:00
|
|
|
if (!gDBView)
|
|
|
|
return false;
|
2008-07-22 16:21:15 +04:00
|
|
|
gDBView.selectMsgByKey(aMsgKey);
|
|
|
|
|
|
|
|
// is there a selection?
|
|
|
|
// if not, bail out.
|
|
|
|
var indicies = GetSelectedIndices(gDBView);
|
|
|
|
if (!indicies || !indicies.length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// now scroll to it
|
|
|
|
EnsureRowInThreadTreeIsVisible(indicies[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A helper routine called after a folder is loaded to make sure
|
|
|
|
// we select and scroll to the correct message (could be the first new message,
|
|
|
|
// could be the last displayed message, etc.)
|
|
|
|
function ScrollToMessageAfterFolderLoad(folder)
|
|
|
|
{
|
|
|
|
var scrolled = pref.getBoolPref("mailnews.scroll_to_new_message") &&
|
|
|
|
ScrollToMessage(nsMsgNavigationType.firstNew, true, false /* selectMessage */);
|
|
|
|
if (!scrolled && folder && pref.getBoolPref("mailnews.remember_selected_message"))
|
|
|
|
{
|
|
|
|
// If we failed to scroll to a new message,
|
|
|
|
// reselect the last selected message
|
|
|
|
var lastMessageLoaded = folder.lastMessageLoaded;
|
|
|
|
if (lastMessageLoaded != nsMsgKey_None)
|
|
|
|
scrolled = SelectAndScrollToKey(lastMessageLoaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!scrolled)
|
|
|
|
{
|
|
|
|
// if we still haven't scrolled,
|
|
|
|
// scroll to the newest, which might be the top or the bottom
|
|
|
|
// depending on our sort order and sort type
|
2009-09-01 01:46:26 +04:00
|
|
|
if (gDBView && gDBView.sortOrder == nsMsgViewSortOrder.ascending)
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
|
|
|
switch (gDBView.sortType)
|
|
|
|
{
|
|
|
|
case nsMsgViewSortType.byDate:
|
|
|
|
case nsMsgViewSortType.byReceived:
|
|
|
|
case nsMsgViewSortType.byId:
|
|
|
|
case nsMsgViewSortType.byThread:
|
|
|
|
scrolled = ScrollToMessage(nsMsgNavigationType.lastMessage, true, false /* selectMessage */);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if still we haven't scrolled,
|
|
|
|
// scroll to the top.
|
|
|
|
if (!scrolled)
|
|
|
|
EnsureRowInThreadTreeIsVisible(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the folderListener object
|
2009-09-01 01:46:26 +04:00
|
|
|
var folderListener =
|
|
|
|
{
|
|
|
|
OnItemAdded: function(parentItem, item) {},
|
|
|
|
OnItemRemoved: function(parentItem, item) {},
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
OnItemPropertyChanged: function(item, property, oldValue, newValue) {},
|
|
|
|
OnItemBoolPropertyChanged: function(item, property, oldValue, newValue) {},
|
|
|
|
OnItemUnicharPropertyChanged: function(item, property, oldValue, newValue) {},
|
|
|
|
OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {},
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
OnItemIntPropertyChanged: function(item, property, oldValue, newValue)
|
|
|
|
{
|
|
|
|
// handle the currently visible folder
|
|
|
|
if (item == gMsgFolderSelected)
|
|
|
|
{
|
|
|
|
let prop = property.toString();
|
|
|
|
if (prop == "TotalMessages" || prop == "TotalUnreadMessages")
|
|
|
|
{
|
|
|
|
UpdateStatusMessageCounts(gMsgFolderSelected);
|
|
|
|
item = item.QueryInterface(Components.interfaces.nsIRDFResource);
|
|
|
|
UpdateLocationBar(item);
|
|
|
|
}
|
|
|
|
}
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
// check folders shown in tabs
|
|
|
|
if (item instanceof Components.interfaces.nsIMsgFolder)
|
|
|
|
{
|
|
|
|
// find corresponding tabinfos
|
|
|
|
// we may have the folder openened in more than one tab
|
|
|
|
let tabmail = GetTabMail();
|
|
|
|
for (let i = 0; i < tabmail.tabInfo.length; ++i)
|
|
|
|
{
|
|
|
|
// if we never switched away from the tab, we only have just one
|
|
|
|
let tabFolder = tabmail.tabInfo[i].msgSelectedFolder || gMsgFolderSelected;
|
|
|
|
if (tabFolder == item)
|
|
|
|
{
|
|
|
|
// update tab title incl. any icon styles
|
|
|
|
tabmail.setTabTitle(tabmail.tabInfo[i]);
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
}
|
2009-09-01 01:46:26 +04:00
|
|
|
}
|
|
|
|
},
|
2008-07-22 16:21:15 +04:00
|
|
|
|
|
|
|
OnItemEvent: function(folder, event) {
|
|
|
|
var eventType = event.toString();
|
|
|
|
if (eventType == "FolderLoaded") {
|
|
|
|
if (folder) {
|
|
|
|
const nsMsgFolderFlags = Components.interfaces.nsMsgFolderFlags;
|
|
|
|
var scrolled = false;
|
|
|
|
var msgFolder = folder.QueryInterface(Components.interfaces.nsIMsgFolder);
|
|
|
|
var uri = folder.URI;
|
|
|
|
var rerootingFolder = (uri == gCurrentFolderToReroot);
|
|
|
|
if (rerootingFolder) {
|
|
|
|
viewDebug("uri = gCurrentFolderToReroot, setting gQSViewIsDirty\n");
|
|
|
|
gQSViewIsDirty = true;
|
|
|
|
gCurrentFolderToReroot = null;
|
|
|
|
if (msgFolder) {
|
|
|
|
msgFolder.endFolderLoading();
|
|
|
|
// Suppress command updating when rerooting the folder.
|
|
|
|
// When rerooting, we'll be clearing the selection
|
|
|
|
// which will cause us to update commands.
|
|
|
|
if (gDBView) {
|
|
|
|
gDBView.suppressCommandUpdating = true;
|
|
|
|
// If the db's view isn't set, something went wrong and we
|
|
|
|
// should reroot the folder, which will re-open the view.
|
|
|
|
if (!gDBView.db)
|
|
|
|
gRerootOnFolderLoad = true;
|
|
|
|
}
|
|
|
|
if (gRerootOnFolderLoad)
|
|
|
|
RerootFolder(uri, msgFolder, gCurrentLoadingFolderViewType, gCurrentLoadingFolderViewFlags, gCurrentLoadingFolderSortType, gCurrentLoadingFolderSortOrder);
|
|
|
|
|
|
|
|
if (gDBView)
|
|
|
|
gDBView.suppressCommandUpdating = false;
|
|
|
|
|
|
|
|
gCurrentLoadingFolderSortType = 0;
|
|
|
|
gCurrentLoadingFolderSortOrder = 0;
|
|
|
|
gCurrentLoadingFolderViewType = 0;
|
|
|
|
gCurrentLoadingFolderViewFlags = 0;
|
|
|
|
|
|
|
|
// Used for rename folder msg loading after folder is loaded.
|
|
|
|
scrolled = LoadCurrentlyDisplayedMessage();
|
|
|
|
|
|
|
|
if (gStartMsgKey != nsMsgKey_None) {
|
|
|
|
scrolled = SelectAndScrollToKey(gStartMsgKey);
|
|
|
|
gStartMsgKey = nsMsgKey_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gNextMessageAfterLoad) {
|
|
|
|
var type = gNextMessageAfterLoad;
|
|
|
|
gNextMessageAfterLoad = null;
|
|
|
|
|
|
|
|
// Scroll to and select the proper message.
|
|
|
|
scrolled = ScrollToMessage(type, true, true /* selectMessage */);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uri == gCurrentLoadingFolderURI) {
|
|
|
|
viewDebug("uri == current loading folder uri\n");
|
|
|
|
gCurrentLoadingFolderURI = "";
|
|
|
|
// Scroll to message for virtual folders is done in
|
|
|
|
// gSearchNotificationListener.OnSearchDone (see searchBar.js).
|
|
|
|
if (!scrolled && !(gMsgFolderSelected.flags & nsMsgFolderFlags.Virtual))
|
|
|
|
ScrollToMessageAfterFolderLoad(msgFolder);
|
|
|
|
SetBusyCursor(window, false);
|
|
|
|
}
|
|
|
|
// Folder loading is over,
|
|
|
|
// now issue quick search if there is an email address.
|
|
|
|
viewDebug("in folder loaded gVirtualFolderTerms = " + gVirtualFolderTerms + "\n");
|
2009-09-01 01:46:26 +04:00
|
|
|
viewDebug("in folder loaded gMsgFolderSelected = " +
|
|
|
|
gMsgFolderSelected && gMsgFolderSelected.URI + "\n");
|
2008-07-22 16:21:15 +04:00
|
|
|
if (rerootingFolder)
|
|
|
|
{
|
|
|
|
if (gSearchEmailAddress)
|
|
|
|
{
|
|
|
|
Search(gSearchEmailAddress);
|
|
|
|
gSearchEmailAddress = null;
|
|
|
|
}
|
|
|
|
else if (gVirtualFolderTerms)
|
|
|
|
{
|
|
|
|
gDefaultSearchViewTerms = null;
|
|
|
|
viewDebug("searching gVirtualFolderTerms\n");
|
|
|
|
gDBView.viewFolder = gMsgFolderSelected;
|
|
|
|
ViewChangeByFolder(gMsgFolderSelected);
|
|
|
|
}
|
|
|
|
else if (gMsgFolderSelected.flags & nsMsgFolderFlags.Virtual)
|
|
|
|
{
|
|
|
|
viewDebug("selected folder is virtual\n");
|
|
|
|
gDefaultSearchViewTerms = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get the view value from the folder.
|
|
|
|
if (msgFolder)
|
|
|
|
{
|
|
|
|
// If our new view is the same as the old view and we already
|
|
|
|
// have the list of search terms built up for the old view,
|
|
|
|
// just re-use it.
|
|
|
|
var result = GetMailViewForFolder(msgFolder);
|
|
|
|
if (GetSearchInput() && gCurrentViewValue == result && gDefaultSearchViewTerms)
|
|
|
|
{
|
|
|
|
viewDebug("searching gDefaultSearchViewTerms and rerootingFolder\n");
|
|
|
|
Search("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
viewDebug("changing view by value\n");
|
|
|
|
ViewChangeByValue(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eventType == "ImapHdrDownloaded") {
|
|
|
|
if (folder) {
|
|
|
|
var imapFolder = folder.QueryInterface(Components.interfaces.nsIMsgImapMailFolder);
|
|
|
|
if (imapFolder) {
|
|
|
|
var hdrParser = imapFolder.hdrParser;
|
|
|
|
if (hdrParser) {
|
|
|
|
var msgHdr = hdrParser.GetNewMsgHdr();
|
|
|
|
if (msgHdr)
|
|
|
|
{
|
|
|
|
var hdrs = hdrParser.headers;
|
|
|
|
if (hdrs && hdrs.indexOf("X-attachment-size:") > 0) {
|
2009-03-25 18:45:53 +03:00
|
|
|
msgHdr.OrFlags(Components.interfaces.nsMsgMessageFlags
|
|
|
|
.Attachment);
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
if (hdrs && hdrs.indexOf("X-image-size:") > 0) {
|
|
|
|
msgHdr.setStringProperty("imageSize", "1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eventType == "DeleteOrMoveMsgCompleted") {
|
|
|
|
HandleDeleteOrMoveMsgCompleted(folder);
|
|
|
|
}
|
|
|
|
else if (eventType == "DeleteOrMoveMsgFailed") {
|
|
|
|
HandleDeleteOrMoveMsgFailed(folder);
|
|
|
|
}
|
|
|
|
else if (eventType == "AboutToCompact") {
|
|
|
|
if (gDBView)
|
|
|
|
gCurrentlyDisplayedMessage = gDBView.currentlyDisplayedMessage;
|
|
|
|
}
|
|
|
|
else if (eventType == "CompactCompleted") {
|
|
|
|
HandleCompactCompleted(folder);
|
|
|
|
}
|
|
|
|
else if (eventType == "RenameCompleted") {
|
|
|
|
SelectFolder(folder.URI);
|
|
|
|
}
|
|
|
|
else if (eventType == "JunkStatusChanged") {
|
|
|
|
HandleJunkStatusChanged(folder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var folderObserver = {
|
|
|
|
canDrop: function(index, orientation)
|
|
|
|
{
|
|
|
|
return CanDropOnFolderTree(index, orientation);
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop: function(row, orientation)
|
|
|
|
{
|
|
|
|
DropOnFolderTree(row, orientation);
|
|
|
|
},
|
|
|
|
|
|
|
|
onToggleOpenState: function(index)
|
|
|
|
{
|
|
|
|
var folderTree = GetFolderTree();
|
|
|
|
|
|
|
|
// Nothing to do when collapsing an item.
|
|
|
|
if (folderTree.view.isContainerOpen(index))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var folderResource = GetFolderResource(folderTree, index);
|
|
|
|
|
|
|
|
if (folderTree.view.getLevel(index) == 0)
|
|
|
|
{
|
|
|
|
// (Imap/Nntp/Pop) Account item.
|
|
|
|
|
|
|
|
folderResource.QueryInterface(Components.interfaces.nsIMsgFolder)
|
|
|
|
.server.performExpand(msgWindow);
|
|
|
|
}
|
|
|
|
else if (folderResource instanceof Components.interfaces.nsIMsgImapMailFolder)
|
|
|
|
{
|
|
|
|
// Imap message folder item.
|
|
|
|
|
|
|
|
folderResource.performExpand(msgWindow);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onCycleHeader: function(colID, elt)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
onCycleCell: function(row, colID)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
onSelectionChanged: function()
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
onPerformAction: function(action)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
onPerformActionOnRow: function(action, row)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
|
|
|
onPerformActionOnCell: function(action, row, colID)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function HandleDeleteOrMoveMsgFailed(folder)
|
|
|
|
{
|
|
|
|
gDBView.onDeleteCompleted(false);
|
|
|
|
if(IsCurrentLoadedFolder(folder)) {
|
|
|
|
if(gNextMessageAfterDelete) {
|
|
|
|
gNextMessageAfterDelete = null;
|
|
|
|
gNextMessageViewIndexAfterDelete = -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fix me???
|
|
|
|
// ThreadPaneSelectionChange(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// WARNING
|
|
|
|
// this is a fragile and complicated function.
|
|
|
|
// be careful when hacking on it.
|
|
|
|
// Don't forget about things like different imap
|
|
|
|
// delete models, multiple views (from multiple thread panes,
|
|
|
|
// search windows, stand alone message windows)
|
|
|
|
function HandleDeleteOrMoveMsgCompleted(folder)
|
|
|
|
{
|
|
|
|
// you might not have a db view. this can happen if
|
|
|
|
// biff fires when the 3 pane is set to account central.
|
|
|
|
if (!gDBView)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gDBView.onDeleteCompleted(true);
|
|
|
|
|
|
|
|
if (!IsCurrentLoadedFolder(folder)) {
|
|
|
|
// default value after delete/move/copy is over
|
|
|
|
gNextMessageViewIndexAfterDelete = -2;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var treeView = gDBView.QueryInterface(Components.interfaces.nsITreeView);
|
|
|
|
var treeSelection = treeView.selection;
|
|
|
|
|
|
|
|
if (gNextMessageViewIndexAfterDelete == -2) {
|
|
|
|
// a move or delete can cause our selection can change underneath us.
|
|
|
|
// this can happen when the user
|
|
|
|
// deletes message from the stand alone msg window
|
|
|
|
// or the search view, or another 3 pane
|
|
|
|
if (treeSelection.count == 0) {
|
|
|
|
// this can happen if you double clicked a message
|
|
|
|
// in the thread pane, and deleted it from the stand alone msg window
|
|
|
|
// see bug #172392
|
|
|
|
treeSelection.clearSelection();
|
|
|
|
setTitleFromFolder(folder, null);
|
|
|
|
ClearMessagePane();
|
|
|
|
UpdateMailToolbar("delete from another view, 0 rows now selected");
|
|
|
|
}
|
|
|
|
else if (treeSelection.count == 1) {
|
|
|
|
// this can happen if you had two messages selected
|
|
|
|
// in the thread pane, and you deleted one of them from another view
|
|
|
|
// (like the view in the stand alone msg window)
|
|
|
|
// since one item is selected, we should load it.
|
|
|
|
var startIndex = {};
|
|
|
|
var endIndex = {};
|
|
|
|
treeSelection.getRangeAt(0, startIndex, endIndex);
|
|
|
|
|
|
|
|
// select the selected item, so we'll load it
|
|
|
|
treeSelection.select(startIndex.value);
|
|
|
|
treeView.selectionChanged();
|
|
|
|
|
|
|
|
EnsureRowInThreadTreeIsVisible(startIndex.value);
|
|
|
|
|
|
|
|
UpdateMailToolbar("delete from another view, 1 row now selected");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// this can happen if you have more than 2 messages selected
|
|
|
|
// in the thread pane, and you deleted one of them from another view
|
|
|
|
// (like the view in the stand alone msg window)
|
|
|
|
// since multiple messages are still selected, do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (gNextMessageViewIndexAfterDelete != nsMsgViewIndex_None)
|
|
|
|
{
|
|
|
|
var viewSize = treeView.rowCount;
|
|
|
|
if (gNextMessageViewIndexAfterDelete >= viewSize)
|
|
|
|
{
|
|
|
|
if (viewSize > 0)
|
|
|
|
gNextMessageViewIndexAfterDelete = viewSize - 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gNextMessageViewIndexAfterDelete = nsMsgViewIndex_None;
|
|
|
|
|
|
|
|
// there is nothing to select since viewSize is 0
|
|
|
|
treeSelection.clearSelection();
|
|
|
|
setTitleFromFolder(folder, null);
|
|
|
|
ClearMessagePane();
|
|
|
|
UpdateMailToolbar("delete from current view, 0 rows left");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we are about to set the selection with a new element then DON'T clear
|
|
|
|
// the selection then add the next message to select. This just generates
|
|
|
|
// an extra round of command updating notifications that we are trying to
|
|
|
|
// optimize away.
|
|
|
|
if (gNextMessageViewIndexAfterDelete != nsMsgViewIndex_None)
|
|
|
|
{
|
|
|
|
// When deleting a message we don't update the commands
|
|
|
|
// when the selection goes to 0
|
|
|
|
// (we have a hack in nsMsgDBView which prevents that update)
|
|
|
|
// so there is no need to
|
|
|
|
// update commands when we select the next message after the delete;
|
|
|
|
// the commands already
|
|
|
|
// have the right update state...
|
|
|
|
gDBView.suppressCommandUpdating = true;
|
|
|
|
|
|
|
|
// This check makes sure that the tree does not perform a
|
|
|
|
// selection on a non selected row (row < 0), else assertions will
|
|
|
|
// be thrown.
|
|
|
|
if (gNextMessageViewIndexAfterDelete >= 0)
|
|
|
|
treeSelection.select(gNextMessageViewIndexAfterDelete);
|
|
|
|
|
|
|
|
// If gNextMessageViewIndexAfterDelete has the same value
|
|
|
|
// as the last index we had selected, the tree won't generate a
|
|
|
|
// selectionChanged notification for the tree view. So force a manual
|
|
|
|
// selection changed call.
|
|
|
|
// (don't worry it's cheap if we end up calling it twice).
|
|
|
|
if (treeView)
|
|
|
|
treeView.selectionChanged();
|
|
|
|
|
|
|
|
EnsureRowInThreadTreeIsVisible(gNextMessageViewIndexAfterDelete);
|
|
|
|
gDBView.suppressCommandUpdating = false;
|
|
|
|
|
|
|
|
// hook for extra toolbar items
|
|
|
|
// XXX TODO
|
|
|
|
// I think there is a bug in the suppression code above.
|
|
|
|
// What if I have two rows selected, and I hit delete,
|
|
|
|
// and so we load the next row.
|
|
|
|
// What if I have commands that only enable where
|
|
|
|
// exactly one row is selected?
|
|
|
|
UpdateMailToolbar("delete from current view, at least one row selected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// default value after delete/move/copy is over
|
|
|
|
gNextMessageViewIndexAfterDelete = -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
function HandleCompactCompleted(folder)
|
|
|
|
{
|
2008-08-06 03:39:41 +04:00
|
|
|
if (folder && folder.server.type != "imap")
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
2009-08-24 01:02:48 +04:00
|
|
|
let msgFolder = msgWindow.openFolder;
|
|
|
|
if (msgFolder && folder.URI == msgFolder.URI)
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
2009-08-24 01:02:48 +04:00
|
|
|
// pretend the selection changed, to reselect the current folder+view.
|
|
|
|
gMsgFolderSelected = null;
|
|
|
|
msgWindow.openFolder = null;
|
|
|
|
FolderPaneSelectionChange();
|
|
|
|
LoadCurrentlyDisplayedMessage();
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function LoadCurrentlyDisplayedMessage()
|
|
|
|
{
|
|
|
|
var scrolled = (gCurrentlyDisplayedMessage != nsMsgViewIndex_None);
|
|
|
|
if (scrolled)
|
|
|
|
{
|
|
|
|
var treeView = gDBView.QueryInterface(Components.interfaces.nsITreeView);
|
|
|
|
var treeSelection = treeView.selection;
|
|
|
|
treeSelection.select(gCurrentlyDisplayedMessage);
|
|
|
|
if (treeView)
|
|
|
|
treeView.selectionChanged();
|
|
|
|
EnsureRowInThreadTreeIsVisible(gCurrentlyDisplayedMessage);
|
|
|
|
SetFocusThreadPane();
|
|
|
|
gCurrentlyDisplayedMessage = nsMsgViewIndex_None; //reset
|
|
|
|
}
|
|
|
|
return scrolled;
|
|
|
|
}
|
|
|
|
|
2009-08-24 01:02:48 +04:00
|
|
|
function IsCurrentLoadedFolder(aFolder)
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
2009-08-24 01:02:48 +04:00
|
|
|
let msgFolderUri = aFolder.QueryInterface(Components.interfaces.nsIMsgFolder)
|
|
|
|
.URI;
|
|
|
|
let currentLoadedFolder = GetThreadPaneFolder();
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2009-08-24 01:02:48 +04:00
|
|
|
// If the currently loaded folder is virtual,
|
|
|
|
// check if aFolder is one of its searched folders.
|
|
|
|
if (currentLoadedFolder.flags & Components.interfaces.nsMsgFolderFlags.Virtual)
|
|
|
|
{
|
|
|
|
return currentLoadedFolder.msgDatabase.dBFolderInfo
|
|
|
|
.getCharProperty("searchFolderUri").split("|")
|
|
|
|
.indexOf(msgFolderUri) != -1;
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
2009-08-24 01:02:48 +04:00
|
|
|
// Is aFolder the currently loaded folder?
|
|
|
|
return currentLoadedFolder.URI == msgFolderUri;
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function ServerContainsFolder(server, folder)
|
|
|
|
{
|
|
|
|
if (!folder || !server)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return server.equals(folder.server);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectServer(server)
|
|
|
|
{
|
|
|
|
SelectFolder(server.rootFolder.URI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we have this incoming server listener in case we need to
|
|
|
|
// alter the folder pane selection when a server is removed
|
|
|
|
// or changed (currently, when the real username or real hostname change)
|
|
|
|
var gThreePaneIncomingServerListener = {
|
|
|
|
onServerLoaded: function(server) {},
|
|
|
|
onServerUnloaded: function(server) {
|
|
|
|
var selectedFolders = GetSelectedMsgFolders();
|
|
|
|
for (var i = 0; i < selectedFolders.length; i++) {
|
|
|
|
if (ServerContainsFolder(server, selectedFolders[i])) {
|
|
|
|
SelectServer(accountManager.defaultAccount.incomingServer);
|
|
|
|
// we've made a new selection, we're done
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if nothing is selected at this point, better go select the default
|
|
|
|
// this could happen if nothing was selected when the server was removed
|
|
|
|
selectedFolders = GetSelectedMsgFolders();
|
|
|
|
if (selectedFolders.length == 0) {
|
|
|
|
SelectServer(accountManager.defaultAccount.incomingServer);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onServerChanged: function(server) {
|
|
|
|
// if the current selected folder is on the server that changed
|
|
|
|
// and that server is an imap or news server,
|
|
|
|
// we need to update the selection.
|
|
|
|
// on those server types, we'll be reconnecting to the server
|
|
|
|
// and our currently selected folder will need to be reloaded
|
|
|
|
// or worse, be invalid.
|
|
|
|
if (server.type != "imap" && server.type !="nntp")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var selectedFolders = GetSelectedMsgFolders();
|
|
|
|
for (var i = 0; i < selectedFolders.length; i++) {
|
|
|
|
// if the selected item is a server, we don't have to update
|
|
|
|
// the selection
|
|
|
|
if (!(selectedFolders[i].isServer) && ServerContainsFolder(server, selectedFolders[i])) {
|
|
|
|
SelectServer(server);
|
|
|
|
// we've made a new selection, we're done
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpdateMailPaneConfig() {
|
2009-09-01 01:46:26 +04:00
|
|
|
const dynamicIds = ["messagesBox", "mailContent", "messengerBox"];
|
2008-07-22 16:21:15 +04:00
|
|
|
var desiredId = dynamicIds[pref.getIntPref("mail.pane_config.dynamic")];
|
|
|
|
var messagePane = GetMessagePane();
|
|
|
|
if (messagePane.parentNode.id != desiredId) {
|
|
|
|
ClearAttachmentList();
|
|
|
|
var messagePaneSplitter = GetThreadAndMessagePaneSplitter();
|
|
|
|
var desiredParent = document.getElementById(desiredId);
|
|
|
|
// See Bug 381992. The ctor for the browser element will fire again when we
|
|
|
|
// re-insert the messagePaneBox back into the document.
|
|
|
|
// But the dtor doesn't fire when the element is removed from the document.
|
|
|
|
// Manually call destroy here to avoid a nasty leak.
|
|
|
|
getMessageBrowser().destroy();
|
|
|
|
desiredParent.appendChild(messagePaneSplitter);
|
|
|
|
desiredParent.appendChild(messagePane);
|
|
|
|
messagePaneSplitter.orient = desiredParent.orient;
|
2009-09-01 01:46:26 +04:00
|
|
|
// Reroot message display
|
|
|
|
InvalidateTabDBs();
|
|
|
|
let tabmail = GetTabMail();
|
|
|
|
tabmail.currentTabInfo = null;
|
|
|
|
tabmail.updateCurrentTab();
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 18:31:21 +03:00
|
|
|
const MailPrefObserver = {
|
2008-07-22 16:21:15 +04:00
|
|
|
observe: function observe(subject, topic, prefName) {
|
2011-02-19 18:31:21 +03:00
|
|
|
if (topic == "nsPref:changed") {
|
|
|
|
if (prefName == "mail.pane_config.dynamic") {
|
|
|
|
UpdateMailPaneConfig();
|
|
|
|
} else if (prefName == "mail.showCondensedAddresses") {
|
|
|
|
let currentDisplayNameVersion =
|
|
|
|
pref.getIntPref("mail.displayname.version");
|
|
|
|
pref.setIntPref("mail.displayname.version",
|
|
|
|
++currentDisplayNameVersion);
|
|
|
|
|
|
|
|
// Refresh the thread pane.
|
|
|
|
GetThreadTree().treeBoxObject.invalid();
|
|
|
|
}
|
|
|
|
}
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Functions related to startup */
|
|
|
|
function OnLoadMessenger()
|
|
|
|
{
|
|
|
|
AddMailOfflineObserver();
|
|
|
|
CreateMailWindowGlobals();
|
2011-02-19 18:31:21 +03:00
|
|
|
pref.addObserver("mail.pane_config.dynamic", MailPrefObserver, false);
|
|
|
|
pref.addObserver("mail.showCondensedAddresses", MailPrefObserver, false);
|
2008-07-22 16:21:15 +04:00
|
|
|
UpdateMailPaneConfig();
|
|
|
|
Create3PaneGlobals();
|
2009-03-22 17:45:17 +03:00
|
|
|
verifyAccounts(null, false);
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
// initialize tabmail system - see tabmail.js and tabmail.xml for details
|
|
|
|
let tabmail = GetTabMail();
|
|
|
|
tabmail.registerTabType(gMailNewsTabsType);
|
|
|
|
tabmail.openFirstTab();
|
2011-10-28 20:29:34 +04:00
|
|
|
Services.obs.addObserver(MailWindowIsClosing,
|
|
|
|
"quit-application-requested", false);
|
2009-09-01 01:46:26 +04:00
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
InitMsgWindow();
|
|
|
|
messenger.setWindow(window, msgWindow);
|
|
|
|
|
|
|
|
InitializeDataSources();
|
|
|
|
InitPanes();
|
|
|
|
|
|
|
|
MigrateJunkMailSettings();
|
|
|
|
|
|
|
|
accountManager.setSpecialFolders();
|
|
|
|
accountManager.loadVirtualFolders();
|
|
|
|
accountManager.addIncomingServerListener(gThreePaneIncomingServerListener);
|
|
|
|
|
|
|
|
AddToSession();
|
|
|
|
|
2010-06-17 12:14:31 +04:00
|
|
|
var startFolderUri = null;
|
2008-07-22 16:21:15 +04:00
|
|
|
//need to add to session before trying to load start folder otherwise listeners aren't
|
|
|
|
//set up correctly.
|
|
|
|
// argument[0] --> folder uri
|
|
|
|
// argument[1] --> optional message key
|
|
|
|
// argument[2] --> optional email address; // Will come from aim; needs to show msgs from buddy's email address.
|
|
|
|
if ("arguments" in window)
|
|
|
|
{
|
2010-06-17 12:14:31 +04:00
|
|
|
var args = window.arguments;
|
2008-11-04 20:42:25 +03:00
|
|
|
// filter our any feed urls that came in as arguments to the new window...
|
2010-06-17 12:14:31 +04:00
|
|
|
if (args.length && /^feed:/i.test(args[0]))
|
2008-11-04 20:42:25 +03:00
|
|
|
{
|
|
|
|
var feedHandler =
|
|
|
|
Components.classes["@mozilla.org/newsblog-feed-downloader;1"]
|
|
|
|
.getService(Components.interfaces.nsINewsBlogFeedDownloader);
|
|
|
|
if (feedHandler)
|
2010-06-17 12:14:31 +04:00
|
|
|
feedHandler.subscribeToFeed(args[0], null, msgWindow);
|
2008-11-04 20:42:25 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-17 12:14:31 +04:00
|
|
|
startFolderUri = (args.length > 0) ? args[0] : null;
|
2008-11-04 20:42:25 +03:00
|
|
|
}
|
2010-06-17 12:14:31 +04:00
|
|
|
gStartMsgKey = (args.length > 1) ? args[1] : nsMsgKey_None;
|
|
|
|
gSearchEmailAddress = (args.length > 2) ? args[2] : null;
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
2010-06-17 12:14:31 +04:00
|
|
|
window.setTimeout(loadStartFolder, 0, startFolderUri);
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2011-06-18 21:55:57 +04:00
|
|
|
Services.obs.notifyObservers(window, "mail-startup-done", null);
|
2009-07-31 13:16:38 +04:00
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
// FIX ME - later we will be able to use onload from the overlay
|
|
|
|
OnLoadMsgHeaderPane();
|
|
|
|
|
|
|
|
gHaveLoadedMessage = false;
|
|
|
|
|
|
|
|
//Set focus to the Thread Pane the first time the window is opened.
|
|
|
|
SetFocusThreadPane();
|
2009-04-21 21:51:43 +04:00
|
|
|
|
|
|
|
// Before and after callbacks for the customizeToolbar code
|
|
|
|
var mailToolbox = getMailToolbox();
|
|
|
|
mailToolbox.customizeInit = MailToolboxCustomizeInit;
|
|
|
|
mailToolbox.customizeDone = MailToolboxCustomizeDone;
|
|
|
|
mailToolbox.customizeChange = MailToolboxCustomizeChange;
|
2009-09-05 17:43:21 +04:00
|
|
|
|
2011-01-28 01:32:33 +03:00
|
|
|
// initialize the sync UI
|
|
|
|
gSyncUI.init();
|
|
|
|
|
2009-09-05 17:43:21 +04:00
|
|
|
window.addEventListener("AppCommand", HandleAppCommandEvent, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function HandleAppCommandEvent(evt)
|
|
|
|
{
|
|
|
|
evt.stopPropagation();
|
|
|
|
switch (evt.command)
|
|
|
|
{
|
|
|
|
case "Back":
|
|
|
|
goDoCommand('cmd_goBack');
|
|
|
|
break;
|
|
|
|
case "Forward":
|
|
|
|
goDoCommand('cmd_goForward');
|
|
|
|
break;
|
|
|
|
case "Stop":
|
|
|
|
goDoCommand('cmd_stop');
|
|
|
|
break;
|
|
|
|
case "Search":
|
|
|
|
goDoCommand('cmd_search');
|
|
|
|
break;
|
|
|
|
case "Bookmarks":
|
|
|
|
toAddressBook();
|
|
|
|
break;
|
|
|
|
case "Reload":
|
|
|
|
goDoCommand('cmd_reload');
|
|
|
|
break;
|
|
|
|
case "Home":
|
|
|
|
goDoCommand('cmd_goStartPage');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function OnUnloadMessenger()
|
|
|
|
{
|
2011-02-19 18:31:21 +03:00
|
|
|
pref.removeObserver("mail.pane_config.dynamic", MailPrefObserver, false);
|
|
|
|
pref.removeObserver("mail.showCondensedAddresses", MailPrefObserver, false);
|
2009-09-05 17:43:21 +04:00
|
|
|
window.removeEventListener("AppCommand", HandleAppCommandEvent, true);
|
2011-10-28 20:29:34 +04:00
|
|
|
Services.obs.removeObserver(MailWindowIsClosing,
|
|
|
|
"quit-application-requested");
|
2008-07-22 16:21:15 +04:00
|
|
|
|
|
|
|
OnLeavingFolder(gMsgFolderSelected); // mark all read in current folder
|
|
|
|
accountManager.removeIncomingServerListener(gThreePaneIncomingServerListener);
|
2009-09-01 01:46:26 +04:00
|
|
|
GetTabMail().closeTabs();
|
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
// FIX ME - later we will be able to use onload from the overlay
|
|
|
|
OnUnloadMsgHeaderPane();
|
2008-09-25 18:51:22 +04:00
|
|
|
UnloadPanes();
|
2008-07-22 16:21:15 +04:00
|
|
|
OnMailWindowUnload();
|
|
|
|
}
|
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
// we probably want to warn if more than one tab is closed
|
2011-10-28 20:29:34 +04:00
|
|
|
function MailWindowIsClosing(aCancelQuit, aTopic, aData)
|
2009-09-01 01:46:26 +04:00
|
|
|
{
|
2011-10-28 20:29:34 +04:00
|
|
|
if (aTopic == "quit-application-requested" &&
|
|
|
|
aCancelQuit instanceof Components.interfaces.nsISupportsPRBool &&
|
|
|
|
aCancelQuit.data)
|
|
|
|
return false;
|
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
let reallyClose = true;
|
|
|
|
let numtabs = GetTabMail().tabInfo.length;
|
|
|
|
if (numtabs > 1)
|
|
|
|
{
|
|
|
|
let shouldPrompt = pref.getBoolPref("browser.tabs.warnOnClose");
|
|
|
|
if (shouldPrompt)
|
|
|
|
{
|
|
|
|
// default to true: if it were false, we wouldn't get this far
|
|
|
|
let warnOnClose = {value: true};
|
2011-08-15 13:49:36 +04:00
|
|
|
let buttonPressed = Services.prompt.confirmEx(
|
2009-09-01 01:46:26 +04:00
|
|
|
window,
|
|
|
|
gMessengerBundle.getString('tabs.closeWarningTitle'),
|
|
|
|
gMessengerBundle.getFormattedString("tabs.closeWarning", [numtabs], 1),
|
2011-08-15 13:49:36 +04:00
|
|
|
(Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) +
|
|
|
|
(Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1),
|
2009-09-01 01:46:26 +04:00
|
|
|
gMessengerBundle.getString('tabs.closeButton'),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
gMessengerBundle.getString('tabs.closeWarningPromptMe'),
|
|
|
|
warnOnClose);
|
|
|
|
reallyClose = (buttonPressed == 0);
|
|
|
|
// don't set the pref unless OK was pressed and it's false
|
|
|
|
if (reallyClose && !warnOnClose.value)
|
|
|
|
pref.setBoolPref("browser.tabs.warnOnClose", false);
|
|
|
|
}
|
|
|
|
}
|
2011-10-28 20:29:34 +04:00
|
|
|
|
|
|
|
if (!reallyClose && aTopic == "quit-application-requested")
|
|
|
|
aCancelQuit.data = true;
|
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
return reallyClose;
|
|
|
|
}
|
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
function Create3PaneGlobals()
|
|
|
|
{
|
2008-09-29 04:41:52 +04:00
|
|
|
// Update <mailWindow.js> global variables.
|
2008-07-22 16:21:15 +04:00
|
|
|
accountCentralBox = document.getElementById("accountCentralBox");
|
2010-06-07 01:59:58 +04:00
|
|
|
gDisableViewsSearch = document.getElementById("mailDisableViewsSearch");
|
2008-09-29 04:41:52 +04:00
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
GetMessagePane().collapsed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadStartFolder(initialUri)
|
|
|
|
{
|
|
|
|
var defaultServer = null;
|
|
|
|
var isLoginAtStartUpEnabled = false;
|
|
|
|
|
|
|
|
//First get default account
|
|
|
|
try
|
|
|
|
{
|
2008-09-08 02:34:52 +04:00
|
|
|
if (!initialUri)
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
2008-09-29 04:41:52 +04:00
|
|
|
// Startup time.
|
|
|
|
defaultServer = accountManager.defaultAccount.incomingServer;
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2008-09-08 02:34:52 +04:00
|
|
|
// set the initialUri to the server, so we select it
|
|
|
|
// so we'll get account central
|
|
|
|
initialUri = defaultServer.serverURI;
|
2008-07-22 16:21:15 +04:00
|
|
|
|
|
|
|
// Enable check new mail once by turning checkmail pref 'on' to bring
|
|
|
|
// all users to one plane. This allows all users to go to Inbox. User can
|
|
|
|
// always go to server settings panel and turn off "Check for new mail at startup"
|
|
|
|
if (!pref.getBoolPref(kMailCheckOncePrefName))
|
|
|
|
{
|
|
|
|
pref.setBoolPref(kMailCheckOncePrefName, true);
|
|
|
|
defaultServer.loginAtStartUp = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the user pref to see if the login at startup is enabled for default account
|
|
|
|
isLoginAtStartUpEnabled = defaultServer.loginAtStartUp;
|
|
|
|
|
|
|
|
// Get Inbox only if login at startup is enabled.
|
|
|
|
if (isLoginAtStartUpEnabled)
|
|
|
|
{
|
|
|
|
//now find Inbox
|
2008-09-08 02:34:52 +04:00
|
|
|
var rootMsgFolder = defaultServer.rootMsgFolder;
|
2008-12-25 07:45:11 +03:00
|
|
|
const kInboxFlag = Components.interfaces.nsMsgFolderFlags.Inbox;
|
|
|
|
var inboxFolder = rootMsgFolder.getFolderWithFlags(kInboxFlag);
|
2008-09-08 02:34:52 +04:00
|
|
|
if (inboxFolder)
|
|
|
|
initialUri = inboxFolder.URI;
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-08 02:34:52 +04:00
|
|
|
SelectFolder(initialUri);
|
2008-07-22 16:21:15 +04:00
|
|
|
|
2008-09-29 04:41:52 +04:00
|
|
|
// Perform biff on the server to check for new mail, if:
|
|
|
|
// the login at startup is enabled, and
|
|
|
|
// this feature is not exceptionally overridden, and
|
|
|
|
// the account is not deferred-to or deferred.
|
2008-09-08 02:34:52 +04:00
|
|
|
if (isLoginAtStartUpEnabled &&
|
|
|
|
gLoadStartFolder &&
|
|
|
|
!defaultServer.isDeferredTo &&
|
2008-07-22 16:21:15 +04:00
|
|
|
defaultServer.rootFolder == defaultServer.rootMsgFolder)
|
|
|
|
defaultServer.performBiff(msgWindow);
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
2012-04-29 19:11:16 +04:00
|
|
|
// If no default account then show account central page.
|
|
|
|
ShowAccountCentral();
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MsgGetMessagesForAllServers(defaultServer);
|
|
|
|
|
2011-06-18 21:42:16 +04:00
|
|
|
if (CheckForUnsentMessages() && !Services.io.offline)
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
|
|
|
InitPrompts();
|
|
|
|
InitServices();
|
|
|
|
|
|
|
|
var sendUnsentWhenGoingOnlinePref = pref.getIntPref("offline.send.unsent_messages");
|
2011-08-15 13:49:36 +04:00
|
|
|
if (sendUnsentWhenGoingOnlinePref == 0) // pref is "ask"
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
2011-08-15 13:49:36 +04:00
|
|
|
var buttonPressed = Services.prompt.confirmEx(window,
|
2008-07-22 16:21:15 +04:00
|
|
|
gOfflinePromptsBundle.getString('sendMessagesOfflineWindowTitle'),
|
2008-08-15 15:36:42 +04:00
|
|
|
gOfflinePromptsBundle.getString('sendMessagesLabel2'),
|
2011-08-15 13:49:36 +04:00
|
|
|
Services.prompt.BUTTON_TITLE_IS_STRING * (Services.prompt.BUTTON_POS_0 +
|
|
|
|
Services.prompt.BUTTON_POS_1),
|
2008-07-22 16:21:15 +04:00
|
|
|
gOfflinePromptsBundle.getString('sendMessagesSendButtonLabel'),
|
|
|
|
gOfflinePromptsBundle.getString('sendMessagesNoSendButtonLabel'),
|
|
|
|
null, null, {value:0});
|
|
|
|
if (buttonPressed == 0)
|
|
|
|
SendUnsentMessages();
|
|
|
|
}
|
|
|
|
else if(sendUnsentWhenGoingOnlinePref == 1) // pref is "yes"
|
|
|
|
SendUnsentMessages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddToSession()
|
|
|
|
{
|
|
|
|
try {
|
2010-01-20 08:24:36 +03:00
|
|
|
var mailSession = Components.classes["@mozilla.org/messenger/services/session;1"]
|
2008-07-22 16:21:15 +04:00
|
|
|
.getService(Components.interfaces.nsIMsgMailSession);
|
|
|
|
var nsIFolderListener = Components.interfaces.nsIFolderListener;
|
|
|
|
var notifyFlags = nsIFolderListener.intPropertyChanged | nsIFolderListener.event;
|
|
|
|
mailSession.AddFolderListener(folderListener, notifyFlags);
|
|
|
|
} catch (ex) {
|
|
|
|
dump("Error adding to session\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function InitPanes()
|
|
|
|
{
|
|
|
|
OnLoadFolderPane();
|
|
|
|
OnLoadLocationTree();
|
|
|
|
OnLoadThreadPane();
|
|
|
|
SetupCommandUpdateHandlers();
|
|
|
|
}
|
|
|
|
|
2008-09-25 18:51:22 +04:00
|
|
|
function UnloadPanes()
|
|
|
|
{
|
|
|
|
// Call to <mail3PaneWindowCommands.js>.
|
|
|
|
UnloadCommandUpdateHandlers();
|
|
|
|
}
|
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
function InitializeDataSources()
|
|
|
|
{
|
|
|
|
//Setup common mailwindow stuff.
|
|
|
|
AddDataSources();
|
|
|
|
|
|
|
|
SetupMoveCopyMenus('goMenu', accountManagerDataSource, folderDataSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnFolderUnreadColAttrModified(event)
|
|
|
|
{
|
|
|
|
if (event.attrName == "hidden")
|
|
|
|
{
|
|
|
|
var folderNameCell = document.getElementById("folderNameCell");
|
|
|
|
var label = {"true": "?folderTreeName", "false": "?folderTreeSimpleName"};
|
|
|
|
folderNameCell.setAttribute("label", label[event.newValue]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnAttachmentColAttrModified(event)
|
|
|
|
{
|
|
|
|
if (event.attrName == "hidden")
|
|
|
|
UpdateAttachmentCol(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpgradeFolderPaneUI()
|
|
|
|
{
|
|
|
|
// placeholder in case any new columns get added to the folder pane
|
|
|
|
// note that this function fails to notice a pane layout switch
|
|
|
|
// var folderPaneUIVersion = pref.getIntPref("mail.ui.folderpane.version");
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnLoadFolderPane()
|
|
|
|
{
|
|
|
|
UpgradeFolderPaneUI();
|
|
|
|
|
|
|
|
var folderUnreadCol = document.getElementById("folderUnreadCol");
|
|
|
|
var hidden = folderUnreadCol.getAttribute("hidden");
|
|
|
|
if (hidden != "true")
|
|
|
|
{
|
|
|
|
var folderNameCell = document.getElementById("folderNameCell");
|
|
|
|
folderNameCell.setAttribute("label", "?folderTreeSimpleName");
|
|
|
|
}
|
|
|
|
folderUnreadCol.addEventListener("DOMAttrModified", OnFolderUnreadColAttrModified, false);
|
|
|
|
|
|
|
|
//Add folderDataSource and accountManagerDataSource to folderPane
|
|
|
|
var database = GetFolderDatasource();
|
|
|
|
database.AddDataSource(accountManagerDataSource);
|
|
|
|
database.AddDataSource(folderDataSource);
|
2011-02-16 06:39:04 +03:00
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
var folderTree = GetFolderTree();
|
|
|
|
folderTree.setAttribute("ref", "msgaccounts:/");
|
|
|
|
|
|
|
|
var folderTreeBuilder = folderTree.builder.QueryInterface(Components.interfaces.nsIXULTreeBuilder);
|
|
|
|
folderTreeBuilder.addObserver(folderObserver);
|
|
|
|
folderTree.addEventListener("click",FolderPaneOnClick,true);
|
|
|
|
folderTree.addEventListener("mousedown",TreeOnMouseDown,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpgradeThreadPaneUI()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (pref.getIntPref("mailnews.ui.threadpane.version") < 6)
|
|
|
|
pref.setIntPref("mailnews.ui.threadpane.version", 6);
|
|
|
|
}
|
|
|
|
catch (ex)
|
|
|
|
{
|
|
|
|
dump("UpgradeThreadPane: ex = " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnLoadThreadPane()
|
|
|
|
{
|
|
|
|
UpgradeThreadPaneUI();
|
|
|
|
UpdateAttachmentCol(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpdateAttachmentCol(aFirstTimeFlag)
|
|
|
|
{
|
|
|
|
var attachmentCol = document.getElementById("attachmentCol");
|
|
|
|
var threadTree = GetThreadTree();
|
|
|
|
threadTree.setAttribute("noattachcol", attachmentCol.getAttribute("hidden"));
|
|
|
|
if (aFirstTimeFlag)
|
|
|
|
attachmentCol.addEventListener("DOMAttrModified", OnAttachmentColAttrModified, false);
|
|
|
|
else
|
|
|
|
threadTree.treeBoxObject.clearStyleAndImageCaches();
|
|
|
|
}
|
|
|
|
|
|
|
|
function OnLoadLocationTree()
|
|
|
|
{
|
2010-06-07 01:59:58 +04:00
|
|
|
var locationTree = document.getElementById("folderLocationPopup").tree;
|
|
|
|
if (locationTree)
|
|
|
|
{
|
2008-07-22 16:21:15 +04:00
|
|
|
locationTree.database.AddDataSource(accountManagerDataSource);
|
|
|
|
locationTree.database.AddDataSource(folderDataSource);
|
|
|
|
locationTree.setAttribute("ref", "msgaccounts:/");
|
2010-06-07 01:59:58 +04:00
|
|
|
}
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function OnLocationTreeSelect(menulist)
|
|
|
|
{
|
|
|
|
SelectFolder(menulist.getAttribute('uri'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function UpdateLocationBar(resource)
|
|
|
|
{
|
|
|
|
var tree = GetFolderTree();
|
|
|
|
var folders = document.getElementById('locationFolders');
|
|
|
|
var icon = document.getElementById('locationIcon');
|
|
|
|
var names = ['BiffState', 'NewMessages', 'HasUnreadMessages',
|
|
|
|
'SpecialFolder', 'IsServer', 'IsSecure', 'ServerType', 'NoSelect'];
|
2009-08-24 06:04:23 +04:00
|
|
|
let folder = resource.QueryInterface(Components.interfaces.nsIMsgFolder);
|
|
|
|
folders.setAttribute("label", folder.prettyName);
|
|
|
|
|
|
|
|
const rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIRDFService);
|
|
|
|
function GetFolderAttribute(tree, source, attribute) {
|
|
|
|
let property = rdfService.GetResource("http://home.netscape.com/NC-rdf#" + attribute);
|
|
|
|
let target = tree.database.GetTarget(source, property, true);
|
|
|
|
if (target)
|
|
|
|
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
|
|
|
return target;
|
|
|
|
}
|
2008-07-22 16:21:15 +04:00
|
|
|
for (var i in names) {
|
|
|
|
var name = names[i];
|
|
|
|
var value = GetFolderAttribute(tree, resource, name);
|
|
|
|
folders.setAttribute(name, value);
|
|
|
|
icon.setAttribute(name, value);
|
|
|
|
}
|
|
|
|
folders.setAttribute('uri', resource.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetFolderDatasource()
|
|
|
|
{
|
2008-09-29 04:41:52 +04:00
|
|
|
return GetFolderTree().database;
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Functions for accessing particular parts of the window*/
|
|
|
|
function GetFolderTree()
|
|
|
|
{
|
|
|
|
if (!gFolderTree)
|
|
|
|
gFolderTree = document.getElementById("folderTree");
|
|
|
|
return gFolderTree;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetSearchInput()
|
|
|
|
{
|
|
|
|
if (!gSearchInput)
|
|
|
|
gSearchInput = document.getElementById("searchInput");
|
|
|
|
return gSearchInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetMessagePaneFrame()
|
|
|
|
{
|
|
|
|
return window.content;
|
|
|
|
}
|
|
|
|
|
|
|
|
function FindInSidebar(currentWindow, id)
|
|
|
|
{
|
|
|
|
var item = currentWindow.document.getElementById(id);
|
|
|
|
if (item)
|
|
|
|
return item;
|
|
|
|
|
|
|
|
for (var i = 0; i < currentWindow.frames.length; ++i)
|
|
|
|
{
|
|
|
|
var frameItem = FindInSidebar(currentWindow.frames[i], id);
|
|
|
|
if (frameItem)
|
|
|
|
return frameItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetUnreadCountElement()
|
|
|
|
{
|
|
|
|
if (!gUnreadCount)
|
|
|
|
gUnreadCount = document.getElementById('unreadMessageCount');
|
|
|
|
return gUnreadCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetTotalCountElement()
|
|
|
|
{
|
|
|
|
if (!gTotalCount)
|
|
|
|
gTotalCount = document.getElementById('totalMessageCount');
|
|
|
|
return gTotalCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
function FindMessenger()
|
|
|
|
{
|
|
|
|
return messenger;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ClearThreadPaneSelection()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
if (gDBView) {
|
|
|
|
var treeView = gDBView.QueryInterface(Components.interfaces.nsITreeView);
|
|
|
|
var treeSelection = treeView.selection;
|
|
|
|
if (treeSelection)
|
|
|
|
treeSelection.clearSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
dump("ClearThreadPaneSelection: ex = " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ClearMessagePane()
|
|
|
|
{
|
2009-09-01 01:46:26 +04:00
|
|
|
if (gHaveLoadedMessage)
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
|
|
|
gHaveLoadedMessage = false;
|
|
|
|
gCurrentDisplayedMessage = null;
|
|
|
|
if (GetMessagePaneFrame().location.href != "about:blank")
|
2009-09-01 01:46:26 +04:00
|
|
|
GetMessagePaneFrame().location.href = "about:blank";
|
2008-07-22 16:21:15 +04:00
|
|
|
|
|
|
|
// hide the message header view AND the message pane...
|
|
|
|
HideMessageHeaderPane();
|
|
|
|
gMessageNotificationBar.clearMsgNotifications();
|
|
|
|
ClearPendingReadTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetSelectedFolderIndex()
|
|
|
|
{
|
|
|
|
var startIndex = {};
|
|
|
|
var endIndex = {};
|
2008-09-29 04:41:52 +04:00
|
|
|
GetFolderTree().view.selection.getRangeAt(0, startIndex, endIndex);
|
2008-07-22 16:21:15 +04:00
|
|
|
return startIndex.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to change the highlighted row to where the mouse was clicked
|
|
|
|
// without loading the contents of the selected row.
|
|
|
|
// It will also keep the outline/dotted line in the original row.
|
|
|
|
function ChangeSelectionWithoutContentLoad(event, tree)
|
|
|
|
{
|
2010-12-15 01:31:18 +03:00
|
|
|
// usually, we're only interested in tree content clicks, not scrollbars etc.
|
|
|
|
if (event.originalTarget.localName != "treechildren")
|
|
|
|
return;
|
|
|
|
|
2008-07-22 16:21:15 +04:00
|
|
|
var treeBoxObj = tree.treeBoxObject;
|
|
|
|
var treeSelection = tree.view.selection;
|
|
|
|
|
|
|
|
var row = treeBoxObj.getRowAt(event.clientX, event.clientY);
|
|
|
|
// make sure that row.value is valid so that it doesn't mess up
|
|
|
|
// the call to ensureRowIsVisible().
|
2009-09-01 01:46:26 +04:00
|
|
|
if ((row >= 0) && !treeSelection.isSelected(row))
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
|
|
|
var saveCurrentIndex = treeSelection.currentIndex;
|
|
|
|
treeSelection.selectEventsSuppressed = true;
|
|
|
|
treeSelection.select(row);
|
|
|
|
treeSelection.currentIndex = saveCurrentIndex;
|
|
|
|
treeBoxObj.ensureRowIsVisible(row);
|
|
|
|
treeSelection.selectEventsSuppressed = false;
|
|
|
|
|
|
|
|
// Keep track of which row in the thread pane is currently selected.
|
2009-09-01 01:46:26 +04:00
|
|
|
if (tree.id == "threadTree")
|
2008-07-22 16:21:15 +04:00
|
|
|
gThreadPaneCurrentSelectedIndex = row;
|
|
|
|
}
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
|
|
|
|
function TreeOnMouseDown(event)
|
|
|
|
{
|
2009-09-01 01:46:26 +04:00
|
|
|
// Detect right mouse click and change the highlight to the row
|
|
|
|
// where the click happened without loading the message headers in
|
|
|
|
// the Folder or Thread Pane.
|
|
|
|
// Same for middle click, which will open the folder/message in a tab.
|
|
|
|
gRightMouseButtonDown = event.button == kMouseButtonRight;
|
|
|
|
if (!gRightMouseButtonDown)
|
|
|
|
gRightMouseButtonDown = AllowOpenTabOnMiddleClick() &&
|
|
|
|
event.button == kMouseButtonMiddle;
|
|
|
|
if (gRightMouseButtonDown)
|
|
|
|
ChangeSelectionWithoutContentLoad(event, event.target.parentNode);
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function FolderPaneOnClick(event)
|
|
|
|
{
|
2010-12-15 01:31:18 +03:00
|
|
|
// usually, we're only interested in tree content clicks, not scrollbars etc.
|
|
|
|
if (event.originalTarget.localName != "treechildren")
|
|
|
|
return;
|
|
|
|
|
2009-09-01 01:46:26 +04:00
|
|
|
// we may want to open the folder in a new tab on middle click
|
|
|
|
if (event.button == kMouseButtonMiddle)
|
|
|
|
{
|
|
|
|
if (AllowOpenTabOnMiddleClick())
|
|
|
|
{
|
|
|
|
MsgOpenNewTabForFolder();
|
|
|
|
RestoreSelectionWithoutContentLoad(GetFolderTree());
|
|
|
|
return;
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
2009-09-01 01:46:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, we only care about left click events
|
|
|
|
if (event.button != kMouseButtonLeft)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var folderTree = GetFolderTree();
|
|
|
|
var row = {}, col = {}, elt = {};
|
|
|
|
folderTree.treeBoxObject.getCellAt(event.clientX, event.clientY, row, col, elt);
|
|
|
|
if (row.value == -1)
|
|
|
|
{
|
|
|
|
if (event.originalTarget.localName == "treecol")
|
|
|
|
{
|
|
|
|
// clicking on the name column in the folder pane should not sort
|
2008-07-22 16:21:15 +04:00
|
|
|
event.stopPropagation();
|
|
|
|
}
|
2009-09-01 01:46:26 +04:00
|
|
|
}
|
|
|
|
else if ((event.detail == 2) &&
|
|
|
|
(elt.value != "twisty") &&
|
|
|
|
(folderTree.view.getLevel(row.value) != 0))
|
|
|
|
{
|
|
|
|
FolderPaneDoubleClick(row.value, event);
|
|
|
|
}
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function FolderPaneDoubleClick(folderIndex, event)
|
|
|
|
{
|
2009-09-01 01:46:26 +04:00
|
|
|
// In tabmail land, lazyness is dead!
|
|
|
|
// We either open the folder in a tab or a new window...
|
|
|
|
if (AllowOpenTabOnDoubleClick())
|
|
|
|
{
|
|
|
|
MsgOpenNewTabForFolder();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
let folderResource = GetFolderResource(GetFolderTree(), folderIndex);
|
|
|
|
// Open a new msg window only if we are double clicking on
|
|
|
|
// folders or newsgroups.
|
|
|
|
MsgOpenNewWindowForFolder(folderResource.Value, nsMsgKey_None);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Double-clicking should not toggle the open/close state of the folder.
|
|
|
|
// This will happen if we don't prevent the event from bubbling to the
|
|
|
|
// default handler in tree.xml.
|
|
|
|
event.stopPropagation();
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function ChangeSelection(tree, newIndex)
|
|
|
|
{
|
|
|
|
if(newIndex >= 0)
|
|
|
|
{
|
|
|
|
tree.view.selection.select(newIndex);
|
|
|
|
tree.treeBoxObject.ensureRowIsVisible(newIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetSelectedMsgFolders()
|
|
|
|
{
|
|
|
|
var folderArray = [];
|
|
|
|
var folderTree = GetFolderTree();
|
|
|
|
var rangeCount = folderTree.view.selection.getRangeCount();
|
|
|
|
|
2009-08-19 03:20:38 +04:00
|
|
|
for (let i = 0; i < rangeCount; i++)
|
2008-07-22 16:21:15 +04:00
|
|
|
{
|
|
|
|
var startIndex = {};
|
|
|
|
var endIndex = {};
|
|
|
|
folderTree.view.selection.getRangeAt(i, startIndex, endIndex);
|
|
|
|
for (var j = startIndex.value; j <= endIndex.value; j++)
|
|
|
|
{
|
|
|
|
var folderResource = GetFolderResource(folderTree, j);
|
2009-08-19 03:20:38 +04:00
|
|
|
let msgFolder = folderResource.QueryInterface(Components.interfaces.nsIMsgFolder);
|
|
|
|
folderArray.push(msgFolder);
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return folderArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetFirstSelectedMessage()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return gDBView.URIForFirstSelectedMessage;
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetSelectedIndices(dbView)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return dbView.getIndicesForSelection({});
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
dump("ex = " + ex + "\n");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetSelectedMessages()
|
|
|
|
{
|
2009-01-17 20:09:40 +03:00
|
|
|
if (!GetDBView())
|
2008-07-22 16:21:15 +04:00
|
|
|
return null;
|
2009-01-08 12:34:27 +03:00
|
|
|
|
2009-01-17 20:09:40 +03:00
|
|
|
var messageArray = GetDBView().getURIsForSelection({});
|
2009-01-08 12:34:27 +03:00
|
|
|
return messageArray.length ? messageArray : null;
|
2008-07-22 16:21:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function GetLoadedMsgFolder()
|
|
|
|
{
|
|
|
|
if (!gDBView) return null;
|
|
|
|
return gDBView.msgFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetLoadedMessage()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return gDBView.URIForFirstSelectedMessage;
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Clear everything related to the current message. called after load start page.
|
|
|
|
function ClearMessageSelection()
|
|
|
|
{
|
|
|
|
ClearThreadPaneSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Figures out how many messages are selected (hilighted - does not necessarily
|
|
|
|
// have the dotted outline) above a given index row value in the thread pane.
|
|
|
|
function NumberOfSelectedMessagesAboveCurrentIndex(index)
|
|
|
|
{
|
|
|
|
var numberOfMessages = 0;
|
|
|
|
var indicies = GetSelectedIndices(gDBView);
|
|
|
|
|
|
|
|
if (indicies && indicies.length)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < indicies.length; i++)
|
|
|
|
{
|
|
|
|
if (indicies[i] < index)
|
|
|
|
++numberOfMessages;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return numberOfMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SetNextMessageAfterDelete()
|
|
|
|
{
|
|
|
|
var treeSelection = GetThreadTree().view.selection;
|
|
|
|
|
|
|
|
if (treeSelection.isSelected(treeSelection.currentIndex))
|
|
|
|
gNextMessageViewIndexAfterDelete = gDBView.msgToSelectAfterDelete;
|
|
|
|
else if(gDBView.removeRowOnMoveOrDelete)
|
|
|
|
{
|
|
|
|
// Only set gThreadPaneDeleteOrMoveOccurred to true if the message was
|
|
|
|
// truly moved to the trash or deleted, as opposed to an IMAP delete
|
|
|
|
// (where it is only "marked as deleted". This will prevent bug 142065.
|
|
|
|
//
|
|
|
|
// If it's an IMAP delete, then just set gNextMessageViewIndexAfterDelete
|
|
|
|
// to treeSelection.currentIndex (where the outline is at) because nothing
|
|
|
|
// was moved or deleted from the folder.
|
|
|
|
gThreadPaneDeleteOrMoveOccurred = true;
|
|
|
|
gNextMessageViewIndexAfterDelete = treeSelection.currentIndex - NumberOfSelectedMessagesAboveCurrentIndex(treeSelection.currentIndex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gNextMessageViewIndexAfterDelete = treeSelection.currentIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
function EnsureFolderIndex(builder, msgFolder)
|
|
|
|
{
|
|
|
|
// try to get the index of the folder in the tree
|
|
|
|
var index = builder.getIndexOfResource(msgFolder);
|
|
|
|
if (index == -1) {
|
|
|
|
// if we couldn't find the folder, open the parent
|
|
|
|
builder.toggleOpenState(EnsureFolderIndex(builder, msgFolder.parent));
|
|
|
|
index = builder.getIndexOfResource(msgFolder);
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectFolder(folderUri)
|
|
|
|
{
|
|
|
|
var folderTree = GetFolderTree();
|
2009-08-11 20:01:51 +04:00
|
|
|
let msgFolder = GetMsgFolderFromUri(folderUri);
|
2008-07-22 16:21:15 +04:00
|
|
|
|
|
|
|
// Before we can select a folder, we need to make sure it is "visible"
|
|
|
|
// in the tree. To do that, we need to ensure that all its
|
|
|
|
// ancestors are expanded.
|
|
|
|
var folderIndex = EnsureFolderIndex(folderTree.builderView, msgFolder);
|
|
|
|
ChangeSelection(folderTree, folderIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectMessage(messageUri)
|
|
|
|
{
|
|
|
|
var msgHdr = messenger.msgHdrFromURI(messageUri);
|
|
|
|
if (msgHdr)
|
|
|
|
gDBView.selectMsgByKey(msgHdr.messageKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReloadMessage()
|
|
|
|
{
|
|
|
|
gDBView.reloadMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function SetBusyCursor(window, enable)
|
|
|
|
{
|
|
|
|
// setCursor() is only available for chrome windows.
|
|
|
|
// However one of our frames is the start page which
|
|
|
|
// is a non-chrome window, so check if this window has a
|
|
|
|
// setCursor method
|
|
|
|
if ("setCursor" in window) {
|
|
|
|
if (enable)
|
2008-09-27 19:50:43 +04:00
|
|
|
window.setCursor("progress");
|
2008-07-22 16:21:15 +04:00
|
|
|
else
|
|
|
|
window.setCursor("auto");
|
|
|
|
}
|
|
|
|
|
|
|
|
var numFrames = window.frames.length;
|
|
|
|
for(var i = 0; i < numFrames; i++)
|
|
|
|
SetBusyCursor(window.frames[i], enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetDBView()
|
|
|
|
{
|
|
|
|
return gDBView;
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetFolderResource(tree, index)
|
|
|
|
{
|
|
|
|
return tree.builderView.getResourceAtIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
function GetFolderIndex(tree, resource)
|
|
|
|
{
|
|
|
|
return tree.builderView.getIndexOfResource(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some of the per account junk mail settings have been
|
|
|
|
// converted to global prefs. Let's try to migrate some
|
|
|
|
// of those settings from the default account.
|
|
|
|
function MigrateJunkMailSettings()
|
|
|
|
{
|
|
|
|
var junkMailSettingsVersion = pref.getIntPref("mail.spam.version");
|
|
|
|
if (!junkMailSettingsVersion)
|
|
|
|
{
|
|
|
|
// Get the default account, check to see if we have values for our
|
|
|
|
// globally migrated prefs.
|
|
|
|
var defaultAccount;
|
|
|
|
try {
|
|
|
|
defaultAccount = accountManager.defaultAccount;
|
2008-09-29 04:41:52 +04:00
|
|
|
} catch (ex) {
|
|
|
|
defaultAccount = null;
|
|
|
|
}
|
2008-07-22 16:21:15 +04:00
|
|
|
if (defaultAccount && defaultAccount.incomingServer)
|
|
|
|
{
|
|
|
|
// we only care about
|
|
|
|
var prefix = "mail.server." + defaultAccount.incomingServer.key + ".";
|
|
|
|
if (pref.prefHasUserValue(prefix + "manualMark"))
|
|
|
|
pref.setBoolPref("mail.spam.manualMark", pref.getBoolPref(prefix + "manualMark"));
|
|
|
|
if (pref.prefHasUserValue(prefix + "manualMarkMode"))
|
|
|
|
pref.setIntPref("mail.spam.manualMarkMode", pref.getIntPref(prefix + "manualMarkMode"));
|
|
|
|
if (pref.prefHasUserValue(prefix + "spamLoggingEnabled"))
|
|
|
|
pref.setBoolPref("mail.spam.logging.enabled", pref.getBoolPref(prefix + "spamLoggingEnabled"));
|
|
|
|
if (pref.prefHasUserValue(prefix + "markAsReadOnSpam"))
|
|
|
|
pref.setBoolPref("mail.spam.markAsReadOnSpam", pref.getBoolPref(prefix + "markAsReadOnSpam"));
|
|
|
|
}
|
|
|
|
// bump the version so we don't bother doing this again.
|
|
|
|
pref.setIntPref("mail.spam.version", 1);
|
|
|
|
}
|
|
|
|
}
|