diff --git a/mailnews/base/public/nsIMsgFolder.idl b/mailnews/base/public/nsIMsgFolder.idl index dc55cf3af37d..e8a40ccc3643 100644 --- a/mailnews/base/public/nsIMsgFolder.idl +++ b/mailnews/base/public/nsIMsgFolder.idl @@ -384,6 +384,8 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne boolean matchOrChangeFilterDestination(in nsIMsgFolder folder, in boolean caseInsensitive); boolean confirmFolderDeletionForFilter(in nsIMsgWindow msgWindow); void alertFilterChanged(in nsIMsgWindow msgWindow); + void throwAlertMsg(in string msgName, in nsIMsgWindow msgWindow); + wstring getStringWithFolderNameFromBundle(in string msgName); void notifyCompactCompleted(); attribute nsIMsgRetentionSettings retentionSettings; diff --git a/mailnews/base/resources/locale/en-US/messenger.properties b/mailnews/base/resources/locale/en-US/messenger.properties index 2c94b1e69cc2..464effd1fad4 100644 --- a/mailnews/base/resources/locale/en-US/messenger.properties +++ b/mailnews/base/resources/locale/en-US/messenger.properties @@ -66,9 +66,12 @@ compactingFolder=Compacting folder %S... autoCompactAllFolders=Do you wish to compact all local and offline folders to save disk space? confirmFolderDeletionForFilter=Deleting the folder '%S' will disable its associated filter(s). Are you sure you want to delete the folder? alertFilterChanged=Filters associated with this folder will be updated. +filterDisabled=The folder '%S' could not be found, so filter(s) associated with this folder will be disabled. Verify that the folder exists, and that filters point to a valid destination folder. +filterFolderDeniedLocked=The messages could not be filtered to folder '%S' because another operation is in progress. alertFilterCheckbox=Do not warn me again. compactFolderDeniedLock=The folder '%S' cannot be compacted because another operation is in progress. Please try again later. compactFolderWriteFailed=The folder '%S' could not be compacted because writing to folder failed. Verify that you have enough disk space, and that you have write privileges to the file system, then try again. +filterFolderWriteFailed=The messages could not be filtered to folder '%S' because writing to folder failed. Verify that you have enough disk space, and that you have write privileges to the file system, then try again. # LOCALIZATION NOTES(verboseFolderFormat): %1$S is folder name, %2$S is server name verboseFolderFormat=%1$S on %2$S diff --git a/mailnews/base/search/public/nsIMsgFilterHitNotify.idl b/mailnews/base/search/public/nsIMsgFilterHitNotify.idl index 075817b65b0a..b84997f3d72f 100644 --- a/mailnews/base/search/public/nsIMsgFilterHitNotify.idl +++ b/mailnews/base/search/public/nsIMsgFilterHitNotify.idl @@ -38,6 +38,7 @@ #include "nsISupports.idl" #include "nsMsgFilterCore.idl" #include "nsIMsgFilter.idl" +interface nsIMsgWindow; /////////////////////////////////////////////////////////////////////////////// // nsIMsgFilterHitNotify is an interface designed to make evaluating filters @@ -54,6 +55,6 @@ [scriptable, uuid(c9f15174-1f3f-11d3-a51b-0060b0fc04b7)] interface nsIMsgFilterHitNotify : nsISupports { - boolean ApplyFilterHit(in nsIMsgFilter filter); + boolean applyFilterHit(in nsIMsgFilter filter, in nsIMsgWindow msgWindow); }; diff --git a/mailnews/base/search/src/nsMsgFilterList.cpp b/mailnews/base/search/src/nsMsgFilterList.cpp index fb940e29d3f6..d59c476955c7 100644 --- a/mailnews/base/search/src/nsMsgFilterList.cpp +++ b/mailnews/base/search/src/nsMsgFilterList.cpp @@ -166,7 +166,7 @@ nsMsgFilterList::ApplyFiltersToHdr(nsMsgFilterTypeType filterType, { PRBool applyMore; - ret = listener->ApplyFilterHit(filter, &applyMore); + ret = listener->ApplyFilterHit(filter, msgWindow, &applyMore); if (!NS_SUCCEEDED(ret) || !applyMore) break; } diff --git a/mailnews/base/src/nsMsgFolderCompactor.cpp b/mailnews/base/src/nsMsgFolderCompactor.cpp index 64e378e0d137..1acadd757bf7 100644 --- a/mailnews/base/src/nsMsgFolderCompactor.cpp +++ b/mailnews/base/src/nsMsgFolderCompactor.cpp @@ -216,38 +216,6 @@ nsFolderCompactState::CompactHelper(nsIMsgFolder *folder) return rv; } - - -#define MESSENGER_STRING_URL "chrome://messenger/locale/messenger.properties" - -nsresult nsFolderCompactState::GetStringBundle(nsIStringBundle **aBundle) -{ - nsCOMPtr stringBundle; - nsresult res = NS_OK; - - nsCOMPtr sBundleService = - do_GetService(kStringBundleServiceCID, &res); - if (NS_SUCCEEDED(res) && (nsnull != sBundleService)) - { - res = sBundleService->CreateBundle(MESSENGER_STRING_URL, getter_AddRefs(stringBundle)); - } - *aBundle = stringBundle; - NS_IF_ADDREF(*aBundle); - return res; - } - -nsresult nsFolderCompactState::GetStatusFromMsgName(const char *statusMsgName, PRUnichar ** retval) - { - nsCOMPtr stringBundle; - nsresult res = NS_OK; - res = GetStringBundle(getter_AddRefs(stringBundle)); - if (stringBundle && NS_SUCCEEDED(res)) - { - res = stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(statusMsgName).get(), retval); - } - return res; -} - nsresult nsFolderCompactState::ShowStatusMsg(const PRUnichar *aMsg) { nsCOMPtr statusFeedback; @@ -299,50 +267,11 @@ nsFolderCompactState::Init(nsIMsgFolder *folder, const char *baseMsgUri, nsIMsgD } void nsFolderCompactState::ShowCompactingStatusMsg() - { - nsXPIDLString formatString; - - nsresult rv = GetStatusFromMsgName("compactingFolder", getter_Copies(formatString)); - if (NS_SUCCEEDED(rv)) { - nsXPIDLString folderName; - m_folder->GetName(getter_Copies(folderName)); - PRUnichar *u = nsTextFormatter::smprintf((const PRUnichar *) formatString, (const PRUnichar *) folderName); - if (u) - ShowStatusMsg(u); - PR_FREEIF(u); - } -} - -void nsFolderCompactState::ThrowAlertMsg(const char *alertMsgName) -{ - nsresult rv=NS_OK; - nsXPIDLString folderName; - m_folder->GetName(getter_Copies(folderName)); - nsCOMPtr docShell; - if (m_window) - m_window->GetRootDocShell(getter_AddRefs(docShell)); - if (docShell) - { - nsCOMPtr bundle; - rv = GetStringBundle(getter_AddRefs(bundle)); - if (NS_SUCCEEDED(rv) && bundle) - { - const PRUnichar *formatStrings[] = - { - folderName - }; - nsXPIDLString alertString; - nsAutoString alertTemplate; - alertTemplate.AssignWithConversion(alertMsgName); - rv = bundle->FormatStringFromName(alertTemplate.get(), - formatStrings, 1, - getter_Copies(alertString)); - nsCOMPtr dialog(do_GetInterface(docShell)); - if (dialog && alertString) - dialog->Alert(nsnull, alertString); - } - } + nsXPIDLString statusString; + nsresult rv = m_folder->GetStringWithFolderNameFromBundle("compactingFolder", getter_Copies(statusString)); + if (statusString && NS_SUCCEEDED(rv)) + ShowStatusMsg(statusString); } NS_IMETHODIMP nsFolderCompactState::StartCompacting() @@ -355,9 +284,8 @@ NS_IMETHODIMP nsFolderCompactState::StartCompacting() m_folder->AcquireSemaphore(supports); else { - NS_ASSERTION(0, "Some other operation is in progress on this folder"); m_folder->NotifyCompactCompleted(); - ThrowAlertMsg("compactFolderDeniedLock"); + m_folder->ThrowAlertMsg("compactFolderDeniedLock", m_window); if (m_compactAll) CompactNextFolder(); else @@ -579,11 +507,9 @@ nsFolderCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ctxt, { writeCount = m_fileStream->write(m_dataBuffer, readCount); count -= readCount; - NS_ASSERTION (writeCount == readCount, - "Oops, write fail, folder can be corrupted!\n"); if (writeCount != readCount) { - ThrowAlertMsg("compactFolderWriteFailed"); + m_folder->ThrowAlertMsg("compactFolderWriteFailed", m_window); return NS_MSG_ERROR_WRITING_MAIL_FOLDER; } } diff --git a/mailnews/base/src/nsMsgFolderCompactor.h b/mailnews/base/src/nsMsgFolderCompactor.h index 5247a97028f1..9ba74d2afab9 100644 --- a/mailnews/base/src/nsMsgFolderCompactor.h +++ b/mailnews/base/src/nsMsgFolderCompactor.h @@ -70,9 +70,6 @@ public: nsresult GetMessage(nsIMsgDBHdr **message); nsresult BuildMessageURI(const char *baseURI, PRUint32 key, nsCString& uri); - nsresult GetStatusFromMsgName(const char *statusMsgName, PRUnichar ** retval); - nsresult GetStringBundle(nsIStringBundle **stringBundle); - void ThrowAlertMsg(const char* alertMsgName); nsresult ShowStatusMsg(const PRUnichar *aMsg); nsresult ReleaseFolderLock(); void ShowCompactingStatusMsg(); diff --git a/mailnews/base/util/nsMsgFolder.cpp b/mailnews/base/util/nsMsgFolder.cpp index e65ac0b7f761..09748623a134 100644 --- a/mailnews/base/util/nsMsgFolder.cpp +++ b/mailnews/base/util/nsMsgFolder.cpp @@ -2673,8 +2673,8 @@ nsMsgFolder::ThrowConfirmationPrompt(nsIMsgWindow *msgWindow, const PRUnichar *c return rv; } - -NS_IMETHODIMP nsMsgFolder::ConfirmFolderDeletionForFilter(nsIMsgWindow *msgWindow, PRBool *confirmed) +NS_IMETHODIMP +nsMsgFolder::GetStringWithFolderNameFromBundle(const char *msgName, PRUnichar **aResult) { nsCOMPtr bundle; nsresult rv = GetBaseStringBundle(getter_AddRefs(bundle)); @@ -2686,18 +2686,41 @@ NS_IMETHODIMP nsMsgFolder::ConfirmFolderDeletionForFilter(nsIMsgWindow *msgWindo { folderName }; - nsXPIDLString confirmString; - rv = bundle->FormatStringFromName(NS_ConvertASCIItoUCS2("confirmFolderDeletionForFilter").get(), - formatStrings, 1, - getter_Copies(confirmString)); + rv = bundle->FormatStringFromName(NS_ConvertASCIItoUCS2(msgName).get(), + formatStrings, 1, aResult); + } + return rv; +} +NS_IMETHODIMP nsMsgFolder::ConfirmFolderDeletionForFilter(nsIMsgWindow *msgWindow, PRBool *confirmed) +{ + nsXPIDLString confirmString; + nsresult rv = GetStringWithFolderNameFromBundle("confirmFolderDeletionForFilter", getter_Copies(confirmString)); + if (NS_SUCCEEDED(rv) && confirmString) rv = ThrowConfirmationPrompt(msgWindow, confirmString.get(), confirmed); + return rv; +} + +NS_IMETHODIMP nsMsgFolder::ThrowAlertMsg(const char*msgName, nsIMsgWindow *msgWindow) +{ + nsXPIDLString alertString; + nsresult rv = GetStringWithFolderNameFromBundle(msgName, getter_Copies(alertString)); + if (NS_SUCCEEDED(rv) && alertString && msgWindow) + { + nsCOMPtr docShell; + msgWindow->GetRootDocShell(getter_AddRefs(docShell)); + if (docShell) + { + nsCOMPtr dialog(do_GetInterface(docShell)); + if (dialog && alertString) + dialog->Alert(nsnull, alertString); + } } return rv; } NS_IMETHODIMP nsMsgFolder::AlertFilterChanged(nsIMsgWindow *msgWindow) -{ +{ //this is a different alert i.e alert w/ checkbox. nsresult rv = NS_OK; PRBool checkBox=PR_FALSE; GetWarnFilterChanged(&checkBox); diff --git a/mailnews/base/util/nsMsgFolder.h b/mailnews/base/util/nsMsgFolder.h index d2825d16924a..0d29b570ee9d 100644 --- a/mailnews/base/util/nsMsgFolder.h +++ b/mailnews/base/util/nsMsgFolder.h @@ -194,6 +194,8 @@ public: NS_IMETHOD NotifyCompactCompleted(); NS_IMETHOD ConfirmFolderDeletionForFilter(nsIMsgWindow *msgWindow, PRBool *confirmed); NS_IMETHOD AlertFilterChanged(nsIMsgWindow *msgWindow); + NS_IMETHOD ThrowAlertMsg(const char* msgName, nsIMsgWindow *msgWindow); + NS_IMETHOD GetStringWithFolderNameFromBundle(const char* msgName, PRUnichar **aResult); // end NS_DECL_NSIMSGFOLDER diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index a6526cdd51fe..bd67310e05e9 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -2693,7 +2693,7 @@ NS_IMETHODIMP nsImapMailFolder::EndMessage(nsMsgKey key) return NS_OK; } -NS_IMETHODIMP nsImapMailFolder::ApplyFilterHit(nsIMsgFilter *filter, PRBool *applyMore) +NS_IMETHODIMP nsImapMailFolder::ApplyFilterHit(nsIMsgFilter *filter, nsIMsgWindow *msgWindow, PRBool *applyMore) { nsMsgRuleActionType actionType; nsXPIDLCString actionTargetFolderUri; @@ -2808,7 +2808,7 @@ NS_IMETHODIMP nsImapMailFolder::ApplyFilterHit(nsIMsgFilter *filter, PRBool *app PR_FREEIF(tmp); #endif } - nsresult err = MoveIncorporatedMessage(msgHdr, mDatabase, actionTargetFolderUri, filter); + nsresult err = MoveIncorporatedMessage(msgHdr, mDatabase, actionTargetFolderUri, filter, msgWindow); if (NS_SUCCEEDED(err)) m_msgMovedByFilter = PR_TRUE; } @@ -2979,7 +2979,8 @@ NS_IMETHODIMP nsImapMailFolder::LiteSelect(nsIUrlListener *aUrlListener) nsresult nsImapMailFolder::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, nsIMsgDatabase *sourceDB, const char *destFolderUri, - nsIMsgFilter *filter) + nsIMsgFilter *filter, + nsIMsgWindow *msgWindow) { nsresult err = NS_OK; @@ -3008,6 +3009,7 @@ nsresult nsImapMailFolder::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, if (!parentFolder || !canFileMessages) { filter->SetEnabled(PR_FALSE); + destIFolder->ThrowAlertMsg("filterDisabled",msgWindow); return NS_MSG_NOT_A_MAIL_FOLDER; } // put the header into the source db, since it needs to be there when we copy it diff --git a/mailnews/imap/src/nsImapMailFolder.h b/mailnews/imap/src/nsImapMailFolder.h index 3cc0ac04bcf6..aa1bbe1514dc 100644 --- a/mailnews/imap/src/nsImapMailFolder.h +++ b/mailnews/imap/src/nsImapMailFolder.h @@ -274,13 +274,14 @@ public: PRBool copySucceeded); NS_IMETHOD MatchName(nsString *name, PRBool *matches); // nsIMsgFilterHitNotification method(s) - NS_IMETHOD ApplyFilterHit(nsIMsgFilter *filter, PRBool *applyMore); + NS_IMETHOD ApplyFilterHit(nsIMsgFilter *filter, nsIMsgWindow *msgWindow, PRBool *applyMore); NS_IMETHOD IsCommandEnabled(const char *command, PRBool *result); nsresult MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, nsIMsgDatabase *sourceDB, const char *destFolder, - nsIMsgFilter *filter); + nsIMsgFilter *filter, + nsIMsgWindow *msgWindow); static nsresult AllocateUidStringFromKeys(nsMsgKey *keys, PRInt32 numKeys, nsCString &msgIds); protected: // Helper methods diff --git a/mailnews/local/src/nsParseMailbox.cpp b/mailnews/local/src/nsParseMailbox.cpp index 994c97ed60e1..bb12ba0d593f 100644 --- a/mailnews/local/src/nsParseMailbox.cpp +++ b/mailnews/local/src/nsParseMailbox.cpp @@ -1648,7 +1648,7 @@ void nsParseNewMailState::ApplyFilters(PRBool *pMoved, nsIMsgWindow *msgWindow) *pMoved = m_msgMovedByFilter; } -NS_IMETHODIMP nsParseNewMailState::ApplyFilterHit(nsIMsgFilter *filter, PRBool *applyMore) +NS_IMETHODIMP nsParseNewMailState::ApplyFilterHit(nsIMsgFilter *filter, nsIMsgWindow *msgWindow, PRBool *applyMore) { nsMsgRuleActionType actionType; nsXPIDLCString actionTargetFolderUri; @@ -1739,7 +1739,7 @@ NS_IMETHODIMP nsParseNewMailState::ApplyFilterHit(nsIMsgFilter *filter, PRBool * tmp = (char*) cc.value; PR_FREEIF(tmp); } - nsresult err = MoveIncorporatedMessage(msgHdr, m_mailDB, (const char *) actionTargetFolderUri, filter); + nsresult err = MoveIncorporatedMessage(msgHdr, m_mailDB, (const char *) actionTargetFolderUri, filter, msgWindow); if (NS_SUCCEEDED(err)) m_msgMovedByFilter = PR_TRUE; @@ -1793,7 +1793,8 @@ int nsParseNewMailState::MarkFilteredMessageRead(nsIMsgDBHdr *msgHdr) nsresult nsParseNewMailState::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, nsIMsgDatabase *sourceDB, const char *destFolderUri, - nsIMsgFilter *filter) + nsIMsgFilter *filter, + nsIMsgWindow *msgWindow) { nsresult err = 0; nsIOFileStream *destFile; @@ -1818,6 +1819,7 @@ nsresult nsParseNewMailState::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, if (!parentFolder || !canFileMessages) { filter->SetEnabled(PR_FALSE); + destIFolder->ThrowAlertMsg("filterDisabled", msgWindow); return NS_MSG_NOT_A_MAIL_FOLDER; } @@ -1836,7 +1838,7 @@ nsresult nsParseNewMailState::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, // Make sure no one else is writing into this folder if (destIFolder && (err = destIFolder->AcquireSemaphore (myISupports)) != 0) { - NS_ASSERTION(PR_FALSE, "why is this folder busy?"); + destIFolder->ThrowAlertMsg("filterFolderDeniedLocked", msgWindow); return err; } @@ -1867,6 +1869,7 @@ nsresult nsParseNewMailState::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, #endif if (destIFolder) destIFolder->ReleaseSemaphore (myISupports); + destIFolder->ThrowAlertMsg("filterFolderWriteFailed", msgWindow); return NS_MSG_ERROR_WRITING_MAIL_FOLDER; } @@ -1916,7 +1919,7 @@ nsresult nsParseNewMailState::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, if (destMailDB) destMailDB->Close(PR_TRUE); - + destIFolder->ThrowAlertMsg("filterFolderWriteFailed", msgWindow); return NS_MSG_ERROR_WRITING_MAIL_FOLDER; // caller (ApplyFilters) currently ignores error conditions } diff --git a/mailnews/local/src/nsParseMailbox.h b/mailnews/local/src/nsParseMailbox.h index 018d3325ca06..58c3a48eeca8 100644 --- a/mailnews/local/src/nsParseMailbox.h +++ b/mailnews/local/src/nsParseMailbox.h @@ -251,7 +251,7 @@ public: PRBool *pMoved); #endif // nsIMsgFilterHitNotification method(s) - NS_IMETHOD ApplyFilterHit(nsIMsgFilter *filter, PRBool *applyMore); + NS_IMETHOD ApplyFilterHit(nsIMsgFilter *filter, nsIMsgWindow *msgWindow, PRBool *applyMore); nsOutputFileStream *GetLogFile(); virtual PRInt32 PublishMsgHeader(nsIMsgWindow *msgWindow); @@ -263,7 +263,8 @@ protected: virtual nsresult MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr, nsIMsgDatabase *sourceDB, const char *destFolder, - nsIMsgFilter *filter); + nsIMsgFilter *filter, + nsIMsgWindow *msgWindow); virtual int MarkFilteredMessageRead(nsIMsgDBHdr *msgHdr); void LogRuleHit(nsIMsgFilter *filter, nsIMsgDBHdr *msgHdr); nsCOMPtr m_filterList;