From 660f34e419073c7f9388e69e8a672a0938be0910 Mon Sep 17 00:00:00 2001 From: David Bienvenu Date: Tue, 29 Jun 2010 08:55:49 -0700 Subject: [PATCH] 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 --- .../extensions/mdn/src/nsMsgMdnGenerator.cpp | 50 +++++++++++---- .../extensions/mdn/src/nsMsgMdnGenerator.h | 2 + .../extensions/mdn/test/unit/test_mdnFlags.js | 64 +++++++++++++++++++ 3 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 mailnews/extensions/mdn/test/unit/test_mdnFlags.js diff --git a/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp b/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp index 7958d80bb8..5370f18adb 100644 --- a/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp +++ b/mailnews/extensions/mdn/src/nsMsgMdnGenerator.cpp @@ -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 msgDB; + nsresult rv = folder->GetMsgDatabase(getter_AddRefs(msgDB)); + NS_ENSURE_SUCCESS(rv, rv); + rv = msgDB->MarkMDNSent(key, PR_TRUE, nsnull); + nsCOMPtr 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 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) { diff --git a/mailnews/extensions/mdn/src/nsMsgMdnGenerator.h b/mailnews/extensions/mdn/src/nsMsgMdnGenerator.h index 3c983a7767..ec6fb83222 100644 --- a/mailnews/extensions/mdn/src/nsMsgMdnGenerator.h +++ b/mailnews/extensions/mdn/src/nsMsgMdnGenerator.h @@ -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(); diff --git a/mailnews/extensions/mdn/test/unit/test_mdnFlags.js b/mailnews/extensions/mdn/test/unit/test_mdnFlags.js new file mode 100644 index 0000000000..9d112ddd9b --- /dev/null +++ b/mailnews/extensions/mdn/test/unit/test_mdnFlags.js @@ -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); +}