Bug 479844 Consolidate checking for messages to send later into one function. r=Neil,sr=bienvenu
This commit is contained in:
Родитель
6812adf744
Коммит
d2c2d0f385
|
@ -1,4 +1,4 @@
|
|||
# -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
# -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
|
@ -117,35 +117,9 @@ var MailOfflineMgr = {
|
|||
*/
|
||||
haveUnsentMessages: function()
|
||||
{
|
||||
try
|
||||
{
|
||||
var am = Components.classes["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Components.interfaces.nsIMsgAccountManager);
|
||||
var msgSendlater = Components.classes["@mozilla.org/messengercompose/sendlater;1"]
|
||||
.getService(Components.interfaces.nsIMsgSendLater);
|
||||
var identitiesCount, allIdentities, currentIdentity, numMessages, msgFolder;
|
||||
|
||||
if (am)
|
||||
{
|
||||
allIdentities = am.allIdentities;
|
||||
identitiesCount = allIdentities.Count();
|
||||
for (var i = 0; i < identitiesCount; i++)
|
||||
{
|
||||
currentIdentity = allIdentities.QueryElementAt(i, Components.interfaces.nsIMsgIdentity);
|
||||
msgFolder = msgSendlater.getUnsentMessagesFolder(currentIdentity);
|
||||
if(msgFolder)
|
||||
{
|
||||
// if true, descends into all subfolders
|
||||
numMessages = msgFolder.getTotalMessages(false);
|
||||
if(numMessages > 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ex) {
|
||||
}
|
||||
return false;
|
||||
return Components.classes["@mozilla.org/messengercompose/sendlater;1"]
|
||||
.getService(Components.interfaces.nsIMsgSendLater)
|
||||
.hasUnsentMessages();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
|
@ -857,10 +857,8 @@ function UnloadCommandUpdateHandlers()
|
|||
top.controllers.removeController(DefaultController);
|
||||
}
|
||||
|
||||
function IsSendUnsentMsgsEnabled(folderResource)
|
||||
function IsSendUnsentMsgsEnabled(unsentMsgsFolder)
|
||||
{
|
||||
var identity;
|
||||
|
||||
var msgSendlater =
|
||||
Components.classes["@mozilla.org/messengercompose/sendlater;1"]
|
||||
.getService(Components.interfaces.nsIMsgSendLater);
|
||||
|
@ -868,40 +866,28 @@ function IsSendUnsentMsgsEnabled(folderResource)
|
|||
// If we're currently sending unsent msgs, disable this cmd.
|
||||
if (msgSendlater.sendingMessages)
|
||||
return false;
|
||||
try {
|
||||
if (folderResource) {
|
||||
// if folderResource is non-null, it is
|
||||
// resource for the "Unsent Messages" folder
|
||||
// we're here because we've done a right click on the "Unsent Messages"
|
||||
// folder (context menu)
|
||||
var msgFolder = folderResource.QueryInterface(Components.interfaces.nsIMsgFolder);
|
||||
return (msgFolder.getTotalMessages(false) > 0);
|
||||
}
|
||||
else {
|
||||
var folders = GetSelectedMsgFolders();
|
||||
if (folders.length > 0) {
|
||||
identity = getIdentityForServer(folders[0].server);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
dump("ex = " + ex + "\n");
|
||||
identity = null;
|
||||
|
||||
if (unsentMsgsFolder) {
|
||||
// If unsentMsgsFolder is non-null, it is the "Unsent Messages" folder.
|
||||
// We're here because we've done a right click on the "Unsent Messages"
|
||||
// folder (context menu), so we can use the folder and return true/false
|
||||
// straight away.
|
||||
return unsentMsgsFolder.getTotalMessages(false) > 0;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!identity) {
|
||||
var am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
|
||||
identity = am.defaultAccount.defaultIdentity;
|
||||
}
|
||||
// Otherwise, we don't know where we are, so use the current identity and
|
||||
// find out if we have messages or not via that.
|
||||
let identity;
|
||||
let folders = GetSelectedMsgFolders();
|
||||
if (folders.length > 0)
|
||||
identity = getIdentityForServer(folders[0].server);
|
||||
|
||||
var unsentMsgsFolder = msgSendlater.getUnsentMessagesFolder(identity);
|
||||
return (unsentMsgsFolder.getTotalMessages(false) > 0);
|
||||
}
|
||||
catch (ex) {
|
||||
dump("ex = " + ex + "\n");
|
||||
}
|
||||
return false;
|
||||
if (!identity)
|
||||
identity = Components.classes["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Components.interfaces.nsIMsgAccountManager)
|
||||
.defaultAccount.defaultIdentity;
|
||||
|
||||
return msgSendlater.hasUnsentMessages(identity);
|
||||
}
|
||||
|
||||
function IsRenameFolderEnabled()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -76,31 +76,9 @@ function GetMailOfflinePrefs()
|
|||
// Check for unsent messages
|
||||
function CheckForUnsentMessages()
|
||||
{
|
||||
try
|
||||
{
|
||||
var am = Components.classes["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Components.interfaces.nsIMsgAccountManager);
|
||||
var msgSendlater = Components.classes["@mozilla.org/messengercompose/sendlater;1"]
|
||||
.getService(Components.interfaces.nsIMsgSendLater);
|
||||
var identitiesCount, allIdentities, currentIdentity, numMessages, msgFolder;
|
||||
|
||||
if(am) {
|
||||
allIdentities = am.allIdentities;
|
||||
identitiesCount = allIdentities.Count();
|
||||
for (var i = 0; i < identitiesCount; i++) {
|
||||
currentIdentity = allIdentities.QueryElementAt(i, Components.interfaces.nsIMsgIdentity);
|
||||
msgFolder = msgSendlater.getUnsentMessagesFolder(currentIdentity);
|
||||
if(msgFolder) {
|
||||
// if true, descends into all subfolders
|
||||
numMessages = msgFolder.getTotalMessages(false);
|
||||
if(numMessages > 0) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(ex) {
|
||||
}
|
||||
return false;
|
||||
return Components.classes["@mozilla.org/messengercompose/sendlater;1"]
|
||||
.getService(Components.interfaces.nsIMsgSendLater)
|
||||
.hasUnsentMessages();
|
||||
}
|
||||
|
||||
// Init nsIPromptService & strings.
|
||||
|
|
|
@ -818,8 +818,6 @@ function UnloadCommandUpdateHandlers()
|
|||
|
||||
function IsSendUnsentMsgsEnabled(folderResource)
|
||||
{
|
||||
var identity;
|
||||
|
||||
var msgSendlater =
|
||||
Components.classes["@mozilla.org/messengercompose/sendlater;1"]
|
||||
.getService(Components.interfaces.nsIMsgSendLater);
|
||||
|
@ -827,40 +825,29 @@ function IsSendUnsentMsgsEnabled(folderResource)
|
|||
// If we're currently sending unsent msgs, disable this cmd.
|
||||
if (msgSendlater.sendingMessages)
|
||||
return false;
|
||||
try {
|
||||
if (folderResource) {
|
||||
// if folderResource is non-null, it is
|
||||
// resource for the "Unsent Messages" folder
|
||||
// we're here because we've done a right click on the "Unsent Messages"
|
||||
// folder (context menu)
|
||||
var msgFolder = folderResource.QueryInterface(Components.interfaces.nsIMsgFolder);
|
||||
return (msgFolder.getTotalMessages(false) > 0);
|
||||
}
|
||||
else {
|
||||
var folders = GetSelectedMsgFolders();
|
||||
if (folders.length > 0) {
|
||||
identity = getIdentityForServer(folders[0].server);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
dump("ex = " + ex + "\n");
|
||||
identity = null;
|
||||
|
||||
if (folderResource &&
|
||||
folderResource instanceof Components.interfaces.nsIMsgFolder) {
|
||||
// If unsentMsgsFolder is non-null, it is the "Unsent Messages" folder.
|
||||
// We're here because we've done a right click on the "Unsent Messages"
|
||||
// folder (context menu), so we can use the folder and return true/false
|
||||
// straight away.
|
||||
return folderResource.getTotalMessages(false) > 0;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!identity) {
|
||||
var am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
|
||||
identity = am.defaultAccount.defaultIdentity;
|
||||
}
|
||||
// Otherwise, we don't know where we are, so use the current identity and
|
||||
// find out if we have messages or not via that.
|
||||
let identity = null;
|
||||
let folders = GetSelectedMsgFolders();
|
||||
if (folders.length > 0)
|
||||
identity = getIdentityForServer(folders[0].server);
|
||||
|
||||
var unsentMsgsFolder = msgSendlater.getUnsentMessagesFolder(identity);
|
||||
return (unsentMsgsFolder.getTotalMessages(false) > 0);
|
||||
}
|
||||
catch (ex) {
|
||||
dump("ex = " + ex + "\n");
|
||||
}
|
||||
return false;
|
||||
if (!identity)
|
||||
identity = Components.classes["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Components.interfaces.nsIMsgAccountManager)
|
||||
.defaultAccount.defaultIdentity;
|
||||
|
||||
return msgSendLater.hasUnsentMessages(identity);
|
||||
}
|
||||
|
||||
function IsRenameFolderEnabled()
|
||||
|
|
|
@ -48,8 +48,12 @@ interface nsIMsgFolder;
|
|||
* nsIMsgSendLater is a service used for sending messages in the background.
|
||||
* Messages should be saved to an identity's unsent messages folder, and then
|
||||
* can be sent by calling sendUnsentMessages.
|
||||
*
|
||||
* Although the service supports passing identities as parameters, until bug
|
||||
* 317803 is fixed, all identities use the same folder, and hence currently it
|
||||
* has no effect.
|
||||
*/
|
||||
[scriptable, uuid(2e2142b2-8f94-4604-8cc7-06a00d59f6b5)]
|
||||
[scriptable, uuid(fa324a4b-4b87-4e9a-a3c0-af9071a358df)]
|
||||
interface nsIMsgSendLater : nsIStreamListener
|
||||
{
|
||||
/// Used to obtain status feedback for when messages are sent.
|
||||
|
@ -83,6 +87,14 @@ interface nsIMsgSendLater : nsIStreamListener
|
|||
*/
|
||||
nsIMsgFolder getUnsentMessagesFolder(in nsIMsgIdentity userIdentity);
|
||||
|
||||
/**
|
||||
* Returns true if there are any unsent messages to send.
|
||||
*
|
||||
* @param aIdentity The identity whose folder to check for unsent messages.
|
||||
* If not specified, all unsent message folders are checked.
|
||||
*/
|
||||
boolean hasUnsentMessages([optional] in nsIMsgIdentity aIdentity);
|
||||
|
||||
/// Returns true if the service is currently sending messages.
|
||||
readonly attribute boolean sendingMessages;
|
||||
};
|
||||
|
|
|
@ -622,8 +622,25 @@ nsMsgSendLater::GetUnsentMessagesFolder(nsIMsgIdentity *aIdentity, nsIMsgFolder
|
|||
{
|
||||
nsCString uri;
|
||||
GetFolderURIFromUserPrefs(nsIMsgSend::nsMsgQueueForLater, aIdentity, uri);
|
||||
nsresult rv = LocateMessageFolder(aIdentity, nsIMsgSend::nsMsgQueueForLater, uri.get(), folder);
|
||||
return rv;
|
||||
return LocateMessageFolder(aIdentity, nsIMsgSend::nsMsgQueueForLater,
|
||||
uri.get(), folder);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgSendLater::HasUnsentMessages(nsIMsgIdentity *aIdentity, PRBool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aResult);
|
||||
|
||||
nsCOMPtr<nsIMsgFolder> msgFolder;
|
||||
nsresult rv = GetUnsentMessagesFolder(aIdentity, getter_AddRefs(msgFolder));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRInt32 totalMessages;
|
||||
rv = msgFolder->GetTotalMessages(PR_FALSE, &totalMessages);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*aResult = totalMessages > 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -38,8 +38,6 @@
|
|||
#ifndef _nsMsgSendLater_H_
|
||||
#define _nsMsgSendLater_H_
|
||||
|
||||
#include "nsIMsgSendLater.h"
|
||||
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsIMsgFolder.h"
|
||||
#include "nsIMsgSendListener.h"
|
||||
|
|
|
@ -89,6 +89,9 @@ function OnStopCopy(aStatus) {
|
|||
// Check we have a message in the unsent message folder
|
||||
do_check_eq(folder.getTotalMessages(false), 1);
|
||||
|
||||
// Check that the send later service thinks we have messages to send
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), true);
|
||||
|
||||
// Now do a comparison of what is in the sent mail folder
|
||||
var fileData = loadFileToString(folder.filePath);
|
||||
|
||||
|
@ -170,6 +173,9 @@ function run_test() {
|
|||
// servers and identities.
|
||||
loadLocalMailAccount();
|
||||
|
||||
// Check that the send later service thinks we don't have messages to send
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), false);
|
||||
|
||||
var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Ci.nsIMsgAccountManager);
|
||||
acctMgr.setSpecialFolders();
|
||||
|
|
|
@ -92,6 +92,10 @@ msll.prototype = {
|
|||
do_check_eq(aTotal, aSuccessful);
|
||||
do_check_eq(msgSendLater.sendingMessages, false);
|
||||
|
||||
// Check that the send later service now thinks we don't have messages to
|
||||
// send.
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), false);
|
||||
|
||||
// XXX This is another send multiple messages hack
|
||||
if (!transaction) {
|
||||
server.performTest();
|
||||
|
@ -133,6 +137,9 @@ function OnStopCopy(aStatus)
|
|||
// Check this is false before we start sending
|
||||
do_check_eq(msgSendLater.sendingMessages, false);
|
||||
|
||||
// Check that the send later service thinks we have messages to send.
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), true);
|
||||
|
||||
// Check we have a message in the unsent message folder
|
||||
do_check_eq(gSentFolder.getTotalMessages(false), gMsgOrder.length);
|
||||
|
||||
|
@ -245,6 +252,9 @@ function run_test() {
|
|||
// servers and identities.
|
||||
loadLocalMailAccount();
|
||||
|
||||
// Check that the send later service thinks we don't have messages to send.
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), false);
|
||||
|
||||
var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Ci.nsIMsgAccountManager);
|
||||
acctMgr.setSpecialFolders();
|
||||
|
|
|
@ -115,6 +115,8 @@ msll.prototype = {
|
|||
do_check_eq(aSuccessful, 0);
|
||||
do_check_eq(this._initialTotal, 1);
|
||||
do_check_eq(msgSendLater.sendingMessages, false);
|
||||
// Check that the send later service still thinks we have messages to send.
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), true);
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
@ -128,6 +130,9 @@ function OnStopCopy(aStatus) {
|
|||
|
||||
let folder = msgSendLater.getUnsentMessagesFolder(identity);
|
||||
|
||||
// Check that the send later service thinks we have messages to send.
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), true);
|
||||
|
||||
// Check we have a message in the unsent message folder
|
||||
do_check_eq(folder.getTotalMessages(false), 1);
|
||||
|
||||
|
@ -166,6 +171,9 @@ function run_test() {
|
|||
// servers and identities.
|
||||
loadLocalMailAccount();
|
||||
|
||||
// Check that the send later service thinks we don't have messages to send.
|
||||
do_check_eq(msgSendLater.hasUnsentMessages(identity), false);
|
||||
|
||||
var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
|
||||
.getService(Ci.nsIMsgAccountManager);
|
||||
acctMgr.setSpecialFolders();
|
||||
|
|
Загрузка…
Ссылка в новой задаче