fix bug 558543 return receipt notification bar shouldn't appear after the first time the user responds to the request, for local mail, r/sr=neil

This commit is contained in:
David Bienvenu 2010-06-29 08:55:49 -07:00
Родитель f5f01c8424
Коммит 660f34e419
3 изменённых файлов: 102 добавлений и 14 удалений

Просмотреть файл

@ -63,6 +63,7 @@
#include "nsDirectoryServiceDefs.h"
#include "nsMsgUtils.h"
#include "nsNetUtil.h"
#include "nsIMsgDatabase.h"
#define MDN_NOT_IN_TO_CC ((int) 0x0001)
#define MDN_OUTSIDE_DOMAIN ((int) 0x0002)
@ -174,15 +175,27 @@ nsresult nsMsgMdnGenerator::StoreMDNSentFlag(nsIMsgFolder *folder,
{
DEBUG_MDN("nsMsgMdnGenerator::StoreMDNSentFlag");
// Store the $MDNSent flag if the folder is an Imap Mail Folder
// otherwise, do nothing.
nsCOMPtr<nsIMsgDatabase> msgDB;
nsresult rv = folder->GetMsgDatabase(getter_AddRefs(msgDB));
NS_ENSURE_SUCCESS(rv, rv);
rv = msgDB->MarkMDNSent(key, PR_TRUE, nsnull);
nsCOMPtr<nsIMsgImapMailFolder> imapFolder = do_QueryInterface(folder);
if (!imapFolder)
return NS_OK;
// Store the $MDNSent flag if the folder is an Imap Mail Folder
if (imapFolder)
return imapFolder->StoreImapFlags(kImapMsgMDNSentFlag, PR_TRUE, &key, 1, nsnull);
return rv;
}
// XXX todo: also clear MDNReportNeeded?
nsresult nsMsgMdnGenerator::ClearMDNNeededFlag(nsIMsgFolder *folder,
nsMsgKey key)
{
DEBUG_MDN("nsMsgMdnGenerator::ClearMDNNeededFlag");
return imapFolder->StoreImapFlags(kImapMsgMDNSentFlag, PR_TRUE, &key, 1, nsnull);
nsCOMPtr<nsIMsgDatabase> msgDB;
nsresult rv = folder->GetMsgDatabase(getter_AddRefs(msgDB));
NS_ENSURE_SUCCESS(rv, rv);
return msgDB->MarkMDNNeeded(key, PR_FALSE, nsnull);
}
PRBool nsMsgMdnGenerator::ProcessSendMode()
@ -1063,20 +1076,29 @@ NS_IMETHODIMP nsMsgMdnGenerator::Process(EDisposeType type,
NS_IMETHODIMP nsMsgMdnGenerator::UserAgreed()
{
DEBUG_MDN("nsMsgMdnGenerator::UserAgreed");
nsresult rv = StoreMDNSentFlag(m_folder, m_key);
NS_ASSERTION(NS_SUCCEEDED(rv), "StoreMDNSentFlag failed");
return CreateMdnMsg();
DEBUG_MDN("nsMsgMdnGenerator::UserAgreed");
(void) NoteMDNRequestHandled();
return CreateMdnMsg();
}
NS_IMETHODIMP nsMsgMdnGenerator::UserDeclined()
{
DEBUG_MDN("nsMsgMdnGenerator::UserDeclined");
nsresult rv = StoreMDNSentFlag(m_folder, m_key);
NS_ASSERTION(NS_SUCCEEDED(rv), "StoreMDNSentFlag failed");
return NS_OK;
DEBUG_MDN("nsMsgMdnGenerator::UserDeclined");
return NoteMDNRequestHandled();
}
/**
* Set/clear flags appropriately so we won't ask user again about MDN
* request for this message.
*/
nsresult nsMsgMdnGenerator::NoteMDNRequestHandled()
{
nsresult rv = StoreMDNSentFlag(m_folder, m_key);
NS_ASSERTION(NS_SUCCEEDED(rv), "StoreMDNSentFlag failed");
rv = ClearMDNNeededFlag(m_folder, m_key);
NS_ASSERTION(NS_SUCCEEDED(rv), "ClearMDNNeededFlag failed");
return rv;
}
NS_IMETHODIMP nsMsgMdnGenerator::OnStartRunningUrl(nsIURI *url)
{

Просмотреть файл

@ -74,6 +74,8 @@ private:
PRBool MailAddrMatch(const char *addr1, const char *addr2);
nsresult StoreMDNSentFlag(nsIMsgFolder *folder, nsMsgKey key);
nsresult ClearMDNNeededFlag(nsIMsgFolder *folder, nsMsgKey key);
nsresult NoteMDNRequestHandled();
nsresult CreateMdnMsg();
nsresult CreateFirstPart();

Просмотреть файл

@ -0,0 +1,64 @@
/**
* This tests that setting mdn flags works correctly, so that we don't
* reprompt when the user re-selects a message.
*/
load("../../mailnews/resources/mailDirService.js");
load("../../mailnews/resources/mailTestUtils.js");
var gMessenger = Cc["@mozilla.org/messenger;1"].
createInstance(Ci.nsIMessenger);
loadLocalMailAccount();
let acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
.getService(Ci.nsIMsgAccountManager);
let localAccount = acctMgr.FindAccountForServer(gLocalIncomingServer);
let identity = acctMgr.createIdentity();
identity.email = "bob@t2.exemple.net";
localAccount.addIdentity(identity);
localAccount.defaultIdentity = identity;
function run_test()
{
var headers =
"from: alice@t1.example.com\r\n" +
"to: bob@t2.exemple.net\r\n" +
"return-path: alice@t1.example.com\r\n" +
"Disposition-Notification-To: alice@t1.example.com\r\n";
let mimeHdr = Components.classes["@mozilla.org/messenger/mimeheaders;1"]
.createInstance(Components.interfaces.nsIMimeHeaders);
mimeHdr.initialize(headers, headers.length);
let receivedHeader = mimeHdr.extractHeader("To", false);
let localFolder = gLocalInboxFolder.QueryInterface(Ci.nsIMsgLocalMailFolder);
gLocalInboxFolder.addMessage("From \r\n"+ headers + "\r\nhello\r\n");
// Need to setup some prefs
let prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("");
prefs.setBoolPref("mail.mdn.report.enabled", true);
prefs.setIntPref("mail.mdn.report.not_in_to_cc", 2);
prefs.setIntPref("mail.mdn.report.other", 2);
prefs.setIntPref("mail.mdn.report.outside_domain", 2);
var msgFolder = gLocalInboxFolder;
var msgWindow = {};
var msgHdr = gLocalInboxFolder.GetMessageHeader(0);
// Everything looks good so far, let's generate the MDN response.
var mdnGenerator = Components.classes["@mozilla.org/messenger-mdn/generator;1"]
.createInstance(Components.interfaces.nsIMsgMdnGenerator);
const MDN_DISPOSE_TYPE_DISPLAYED = 0;
mdnGenerator.process(MDN_DISPOSE_TYPE_DISPLAYED, msgWindow, msgFolder,
msgHdr.messageKey, mimeHdr, false);
mdnGenerator.userDeclined();
do_check_neq(msgHdr.flags & Ci.nsMsgMessageFlags.MDNReportSent, 0);
do_check_eq(msgHdr.flags & Ci.nsMsgMessageFlags.MDNReportNeeded, 0);
}