From dbc4af4f95364d46fb92ae401d59f2d271417964 Mon Sep 17 00:00:00 2001 From: Rachel Martin Date: Thu, 25 Nov 2021 12:42:03 +0200 Subject: [PATCH] Bug 1739903 - Change filter-related URI APIs to AUTF8String. r=mkmelin --- mailnews/base/public/nsISpamSettings.idl | 9 ++-- mailnews/base/src/nsMsgDBFolder.cpp | 16 +++--- mailnews/base/src/nsMsgDBView.cpp | 8 +-- mailnews/base/src/nsMsgDBView.h | 2 +- mailnews/base/src/nsMsgIncomingServer.cpp | 2 +- mailnews/base/src/nsMsgPurgeService.cpp | 2 +- mailnews/base/src/nsMsgSearchDBView.cpp | 9 ++-- mailnews/base/src/nsMsgSearchDBView.h | 2 +- mailnews/base/src/nsSpamSettings.cpp | 54 ++++++++----------- .../bayesian-spam-filter/nsBayesianFilter.cpp | 54 +++++++++---------- .../bayesian-spam-filter/nsBayesianFilter.h | 10 ++-- mailnews/imap/src/nsImapIncomingServer.cpp | 4 +- mailnews/imap/src/nsImapMailFolder.cpp | 13 +++-- mailnews/local/src/nsLocalMailFolder.cpp | 13 +++-- mailnews/search/public/nsIMsgFilterList.idl | 2 +- mailnews/search/public/nsIMsgFilterPlugin.idl | 20 +++---- 16 files changed, 103 insertions(+), 117 deletions(-) diff --git a/mailnews/base/public/nsISpamSettings.idl b/mailnews/base/public/nsISpamSettings.idl index fcca6c499b..96c81c6c08 100644 --- a/mailnews/base/public/nsISpamSettings.idl +++ b/mailnews/base/public/nsISpamSettings.idl @@ -28,13 +28,14 @@ interface nsISpamSettings: nsISupports { attribute long moveTargetMode; const long MOVE_TARGET_MODE_ACCOUNT = 0; const long MOVE_TARGET_MODE_FOLDER = 1; - attribute string actionTargetAccount; - attribute string actionTargetFolder; + // Despite their name the following are URIs. + attribute AUTF8String actionTargetAccount; + attribute AUTF8String actionTargetFolder; /** * built from moveTargetMode, actionTargetAccount, actionTargetFolder */ - readonly attribute string spamFolderURI; + readonly attribute AUTF8String spamFolderURI; attribute boolean purge; /** @@ -43,7 +44,7 @@ interface nsISpamSettings: nsISupports { attribute long purgeInterval; attribute boolean useWhiteList; - attribute string whiteListAbURI; + attribute AUTF8String whiteListAbURI; /** * Should we do something when the user manually marks a message as junk? diff --git a/mailnews/base/src/nsMsgDBFolder.cpp b/mailnews/base/src/nsMsgDBFolder.cpp index 9d743f32b8..eea6c764af 100644 --- a/mailnews/base/src/nsMsgDBFolder.cpp +++ b/mailnews/base/src/nsMsgDBFolder.cpp @@ -2113,13 +2113,13 @@ nsMsgDBFolder::GetInheritedStringProperty(const char* aPropertyName, } NS_IMETHODIMP -nsMsgDBFolder::OnMessageClassified(const char* aMsgURI, +nsMsgDBFolder::OnMessageClassified(const nsACString& aMsgURI, nsMsgJunkStatus aClassification, uint32_t aJunkPercent) { nsresult rv = GetDatabase(); NS_ENSURE_SUCCESS(rv, NS_OK); - if (!aMsgURI) // This signifies end of batch. + if (aMsgURI.IsEmpty()) // This signifies end of batch. { // Apply filters if needed. if (!mPostBayesMessagesToFilter.IsEmpty()) { @@ -2159,7 +2159,7 @@ nsMsgDBFolder::OnMessageClassified(const char* aMsgURI, NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr msgHdr; - rv = GetMsgDBHdrFromURI(nsDependentCString(aMsgURI), getter_AddRefs(msgHdr)); + rv = GetMsgDBHdrFromURI(aMsgURI, getter_AddRefs(msgHdr)); NS_ENSURE_SUCCESS(rv, rv); nsMsgKey msgKey; @@ -2207,17 +2207,17 @@ nsMsgDBFolder::OnMessageClassified(const char* aMsgURI, } NS_IMETHODIMP -nsMsgDBFolder::OnMessageTraitsClassified(const char* aMsgURI, +nsMsgDBFolder::OnMessageTraitsClassified(const nsACString& aMsgURI, const nsTArray& aTraits, const nsTArray& aPercents) { - if (!aMsgURI) // This signifies end of batch - return NS_OK; // We are not handling batching + if (aMsgURI.IsEmpty()) // This signifies end of batch + return NS_OK; // We are not handling batching MOZ_ASSERT(aTraits.Length() == aPercents.Length()); nsresult rv; nsCOMPtr msgHdr; - rv = GetMsgDBHdrFromURI(nsDependentCString(aMsgURI), getter_AddRefs(msgHdr)); + rv = GetMsgDBHdrFromURI(aMsgURI, getter_AddRefs(msgHdr)); NS_ENSURE_SUCCESS(rv, rv); nsMsgKey msgKey; @@ -2569,7 +2569,7 @@ nsMsgDBFolder::CallFilterPlugins(nsIMsgWindow* aMsgWindow, bool* aFiltersRun) { // post analysis filters will run consistently on a folder, even if // disabled junk processing, which could be dynamic through whitelisting, // makes the bayes analysis unnecessary. - OnMessageClassified(nullptr, nsIJunkMailPlugin::UNCLASSIFIED, 0); + OnMessageClassified(EmptyCString(), nsIJunkMailPlugin::UNCLASSIFIED, 0); } return rv; diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index 21adeb0c34..8752ef3ff6 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -3287,7 +3287,7 @@ nsresult nsMsgDBView::SetMsgHdrJunkStatus(nsIJunkMailPlugin* aJunkPlugin, // adjust its database appropriately. nsCOMPtr msgWindow(do_QueryReferent(mMsgWindowWeak)); rv = aJunkPlugin->SetMessageClassification( - uri.get(), oldUserClassification, aNewClassification, msgWindow, this); + uri, oldUserClassification, aNewClassification, msgWindow, this); NS_ENSURE_SUCCESS(rv, rv); // This routine is only reached if the user someone touched the UI @@ -3308,14 +3308,14 @@ nsresult nsMsgDBView::SetMsgHdrJunkStatus(nsIJunkMailPlugin* aJunkPlugin, return rv; } -nsresult nsMsgDBView::GetFolderFromMsgURI(const char* aMsgURI, +nsresult nsMsgDBView::GetFolderFromMsgURI(const nsACString& aMsgURI, nsIMsgFolder** aFolder) { NS_IF_ADDREF(*aFolder = m_folder); return NS_OK; } NS_IMETHODIMP -nsMsgDBView::OnMessageClassified(const char* aMsgURI, +nsMsgDBView::OnMessageClassified(const nsACString& aMsgURI, nsMsgJunkStatus aClassification, uint32_t aJunkPercent) @@ -3527,7 +3527,7 @@ nsresult nsMsgDBView::DetermineActionsForJunkChange( if (folderFlags & nsMsgFolderFlags::Junk) return NS_OK; nsCString spamFolderURI; - rv = spamSettings->GetSpamFolderURI(getter_Copies(spamFolderURI)); + rv = spamSettings->GetSpamFolderURI(spamFolderURI); NS_ENSURE_SUCCESS(rv, rv); NS_ASSERTION(!spamFolderURI.IsEmpty(), diff --git a/mailnews/base/src/nsMsgDBView.h b/mailnews/base/src/nsMsgDBView.h index 367f0bc5eb..877c568a9a 100644 --- a/mailnews/base/src/nsMsgDBView.h +++ b/mailnews/base/src/nsMsgDBView.h @@ -283,7 +283,7 @@ class nsMsgDBView : public nsIMsgDBView, virtual nsMsgViewIndex FindKey(nsMsgKey key, bool expand); virtual nsresult GetDBForViewIndex(nsMsgViewIndex index, nsIMsgDatabase** db); virtual nsCOMArray* GetFolders(); - virtual nsresult GetFolderFromMsgURI(const char* aMsgURI, + virtual nsresult GetFolderFromMsgURI(const nsACString& aMsgURI, nsIMsgFolder** aFolder); virtual nsresult ListIdsInThread(nsIMsgThread* threadHdr, diff --git a/mailnews/base/src/nsMsgIncomingServer.cpp b/mailnews/base/src/nsMsgIncomingServer.cpp index 2c248596a5..fb453ce91e 100644 --- a/mailnews/base/src/nsMsgIncomingServer.cpp +++ b/mailnews/base/src/nsMsgIncomingServer.cpp @@ -1784,7 +1784,7 @@ nsresult nsMsgIncomingServer::ConfigureTemporaryServerSpamFilters( spamSettings->GetMoveOnSpam(&moveOnSpam); if (moveOnSpam) { nsCString spamFolderURI; - rv = spamSettings->GetSpamFolderURI(getter_Copies(spamFolderURI)); + rv = spamSettings->GetSpamFolderURI(spamFolderURI); if (NS_SUCCEEDED(rv) && (!spamFolderURI.IsEmpty())) { nsCOMPtr moveAction; rv = newFilter->CreateAction(getter_AddRefs(moveAction)); diff --git a/mailnews/base/src/nsMsgPurgeService.cpp b/mailnews/base/src/nsMsgPurgeService.cpp index d559f29376..560e8dbd42 100644 --- a/mailnews/base/src/nsMsgPurgeService.cpp +++ b/mailnews/base/src/nsMsgPurgeService.cpp @@ -237,7 +237,7 @@ nsresult nsMsgPurgeService::PerformPurge() { // check if the spam folder uri is set for this server // if not skip it. nsCString junkFolderURI; - rv = spamSettings->GetSpamFolderURI(getter_Copies(junkFolderURI)); + rv = spamSettings->GetSpamFolderURI(junkFolderURI); NS_ENSURE_SUCCESS(rv, rv); MOZ_LOG(MsgPurgeLogModule, mozilla::LogLevel::Info, diff --git a/mailnews/base/src/nsMsgSearchDBView.cpp b/mailnews/base/src/nsMsgSearchDBView.cpp index 6b485622b0..ef13262ac9 100644 --- a/mailnews/base/src/nsMsgSearchDBView.cpp +++ b/mailnews/base/src/nsMsgSearchDBView.cpp @@ -1094,16 +1094,15 @@ nsMsgSearchDBView::OpenWithHdrs(nsIMsgEnumerator* aHeaders, return rv; } -nsresult nsMsgSearchDBView::GetFolderFromMsgURI(const char* aMsgURI, +nsresult nsMsgSearchDBView::GetFolderFromMsgURI(const nsACString& aMsgURI, nsIMsgFolder** aFolder) { nsCOMPtr msgMessageService; - nsresult rv = GetMessageServiceFromURI(nsDependentCString(aMsgURI), - getter_AddRefs(msgMessageService)); + nsresult rv = + GetMessageServiceFromURI(aMsgURI, getter_AddRefs(msgMessageService)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr msgHdr; - rv = msgMessageService->MessageURIToMsgHdr(nsDependentCString(aMsgURI), - getter_AddRefs(msgHdr)); + rv = msgMessageService->MessageURIToMsgHdr(aMsgURI, getter_AddRefs(msgHdr)); NS_ENSURE_SUCCESS(rv, rv); return msgHdr->GetFolder(aFolder); diff --git a/mailnews/base/src/nsMsgSearchDBView.h b/mailnews/base/src/nsMsgSearchDBView.h index a448c18415..7a8e996268 100644 --- a/mailnews/base/src/nsMsgSearchDBView.h +++ b/mailnews/base/src/nsMsgSearchDBView.h @@ -78,7 +78,7 @@ class nsMsgSearchDBView : public nsMsgGroupView, NS_IMETHOD OnAnnouncerGoingAway(nsIDBChangeAnnouncer* instigator) override; virtual nsCOMArray* GetFolders() override; - virtual nsresult GetFolderFromMsgURI(const char* aMsgURI, + virtual nsresult GetFolderFromMsgURI(const nsACString& aMsgURI, nsIMsgFolder** aFolder) override; NS_IMETHOD GetThreadContainingMsgHdr(nsIMsgDBHdr* msgHdr, diff --git a/mailnews/base/src/nsSpamSettings.cpp b/mailnews/base/src/nsSpamSettings.cpp index 7e4a8edd68..d2626373a4 100644 --- a/mailnews/base/src/nsSpamSettings.cpp +++ b/mailnews/base/src/nsSpamSettings.cpp @@ -123,38 +123,36 @@ NS_IMPL_GETSET(nsSpamSettings, Purge, bool, mPurge) NS_IMPL_GETSET(nsSpamSettings, UseWhiteList, bool, mUseWhiteList) NS_IMPL_GETSET(nsSpamSettings, UseServerFilter, bool, mUseServerFilter) -NS_IMETHODIMP nsSpamSettings::GetWhiteListAbURI(char** aWhiteListAbURI) { - NS_ENSURE_ARG_POINTER(aWhiteListAbURI); - *aWhiteListAbURI = ToNewCString(mWhiteListAbURI); +NS_IMETHODIMP nsSpamSettings::GetWhiteListAbURI(nsACString& aWhiteListAbURI) { + aWhiteListAbURI = mWhiteListAbURI; return NS_OK; } -NS_IMETHODIMP nsSpamSettings::SetWhiteListAbURI(const char* aWhiteListAbURI) { +NS_IMETHODIMP nsSpamSettings::SetWhiteListAbURI( + const nsACString& aWhiteListAbURI) { mWhiteListAbURI = aWhiteListAbURI; return NS_OK; } NS_IMETHODIMP nsSpamSettings::GetActionTargetAccount( - char** aActionTargetAccount) { - NS_ENSURE_ARG_POINTER(aActionTargetAccount); - *aActionTargetAccount = ToNewCString(mActionTargetAccount); + nsACString& aActionTargetAccount) { + aActionTargetAccount = mActionTargetAccount; return NS_OK; } NS_IMETHODIMP nsSpamSettings::SetActionTargetAccount( - const char* aActionTargetAccount) { + const nsACString& aActionTargetAccount) { mActionTargetAccount = aActionTargetAccount; return NS_OK; } NS_IMETHODIMP nsSpamSettings::GetActionTargetFolder( - char** aActionTargetFolder) { - NS_ENSURE_ARG_POINTER(aActionTargetFolder); - *aActionTargetFolder = ToNewCString(mActionTargetFolder); + nsACString& aActionTargetFolder) { + aActionTargetFolder = mActionTargetFolder; return NS_OK; } NS_IMETHODIMP nsSpamSettings::SetActionTargetFolder( - const char* aActionTargetFolder) { + const nsACString& aActionTargetFolder) { mActionTargetFolder = aActionTargetFolder; return NS_OK; } @@ -248,13 +246,13 @@ NS_IMETHODIMP nsSpamSettings::Initialize(nsIMsgIncomingServer* aServer) { rv = aServer->GetCharValue("spamActionTargetAccount", spamActionTargetAccount); NS_ENSURE_SUCCESS(rv, rv); - rv = SetActionTargetAccount(spamActionTargetAccount.get()); + rv = SetActionTargetAccount(spamActionTargetAccount); NS_ENSURE_SUCCESS(rv, rv); nsCString spamActionTargetFolder; rv = aServer->GetCharValue("spamActionTargetFolder", spamActionTargetFolder); NS_ENSURE_SUCCESS(rv, rv); - rv = SetActionTargetFolder(spamActionTargetFolder.get()); + rv = SetActionTargetFolder(spamActionTargetFolder); NS_ENSURE_SUCCESS(rv, rv); bool useWhiteList; @@ -266,7 +264,7 @@ NS_IMETHODIMP nsSpamSettings::Initialize(nsIMsgIncomingServer* aServer) { nsCString whiteListAbURI; rv = aServer->GetCharValue("whiteListAbURI", whiteListAbURI); NS_ENSURE_SUCCESS(rv, rv); - rv = SetWhiteListAbURI(whiteListAbURI.get()); + rv = SetWhiteListAbURI(whiteListAbURI); NS_ENSURE_SUCCESS(rv, rv); bool purgeSpam; @@ -394,7 +392,7 @@ nsresult nsSpamSettings::UpdateJunkFolderState() { // if the spam folder uri changed on us, we need to unset the junk flag // on the old spam folder nsCString newJunkFolderURI; - rv = GetSpamFolderURI(getter_Copies(newJunkFolderURI)); + rv = GetSpamFolderURI(newJunkFolderURI); NS_ENSURE_SUCCESS(rv, rv); if (!mCurrentJunkFolderURI.IsEmpty() && @@ -447,18 +445,17 @@ NS_IMETHODIMP nsSpamSettings::Clone(nsISpamSettings* aSpamSettings) { NS_ENSURE_SUCCESS(rv, rv); nsCString actionTargetAccount; - rv = - aSpamSettings->GetActionTargetAccount(getter_Copies(actionTargetAccount)); + rv = aSpamSettings->GetActionTargetAccount(actionTargetAccount); NS_ENSURE_SUCCESS(rv, rv); mActionTargetAccount = actionTargetAccount; nsCString actionTargetFolder; - rv = aSpamSettings->GetActionTargetFolder(getter_Copies(actionTargetFolder)); + rv = aSpamSettings->GetActionTargetFolder(actionTargetFolder); NS_ENSURE_SUCCESS(rv, rv); mActionTargetFolder = actionTargetFolder; nsCString whiteListAbURI; - rv = aSpamSettings->GetWhiteListAbURI(getter_Copies(whiteListAbURI)); + rv = aSpamSettings->GetWhiteListAbURI(whiteListAbURI); NS_ENSURE_SUCCESS(rv, rv); mWhiteListAbURI = whiteListAbURI; @@ -468,16 +465,14 @@ NS_IMETHODIMP nsSpamSettings::Clone(nsISpamSettings* aSpamSettings) { return rv; } -NS_IMETHODIMP nsSpamSettings::GetSpamFolderURI(char** aSpamFolderURI) { - NS_ENSURE_ARG_POINTER(aSpamFolderURI); - +NS_IMETHODIMP nsSpamSettings::GetSpamFolderURI(nsACString& aSpamFolderURI) { if (mMoveTargetMode == nsISpamSettings::MOVE_TARGET_MODE_FOLDER) return GetActionTargetFolder(aSpamFolderURI); // if the mode is nsISpamSettings::MOVE_TARGET_MODE_ACCOUNT // the spam folder URI = account uri + "/Junk" nsCString folderURI; - nsresult rv = GetActionTargetAccount(getter_Copies(folderURI)); + nsresult rv = GetActionTargetAccount(folderURI); NS_ENSURE_SUCCESS(rv, rv); // we might be trying to get the old spam folder uri @@ -518,11 +513,8 @@ NS_IMETHODIMP nsSpamSettings::GetSpamFolderURI(char** aSpamFolderURI) { if (!folderUriWithNamespace.IsEmpty()) folderURI = folderUriWithNamespace; } - *aSpamFolderURI = ToNewCString(folderURI); - if (!*aSpamFolderURI) - return NS_ERROR_OUT_OF_MEMORY; - else - return rv; + aSpamFolderURI = folderURI; + return NS_OK; } NS_IMETHODIMP nsSpamSettings::GetServerFilterName(nsACString& aFilterName) { @@ -643,7 +635,7 @@ NS_IMETHODIMP nsSpamSettings::LogJunkHit(nsIMsgDBHdr* aMsgHdr, aMsgHdr->GetMessageId(getter_Copies(msgId)); nsCString junkFolderURI; - rv = GetSpamFolderURI(getter_Copies(junkFolderURI)); + rv = GetSpamFolderURI(junkFolderURI); NS_ENSURE_SUCCESS(rv, rv); AutoTArray logMoveFormatStrings; @@ -725,7 +717,7 @@ NS_IMETHODIMP nsSpamSettings::OnStartRunningUrl(nsIURI* aURL) { NS_IMETHODIMP nsSpamSettings::OnStopRunningUrl(nsIURI* aURL, nsresult exitCode) { nsCString junkFolderURI; - nsresult rv = GetSpamFolderURI(getter_Copies(junkFolderURI)); + nsresult rv = GetSpamFolderURI(junkFolderURI); NS_ENSURE_SUCCESS(rv, rv); if (junkFolderURI.IsEmpty()) return NS_ERROR_UNEXPECTED; diff --git a/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.cpp b/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.cpp index 70ecbb8bff..7cb3727b8b 100644 --- a/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.cpp +++ b/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.cpp @@ -955,7 +955,7 @@ class TokenAnalyzer { mTokenListener = aTokenListener; } - void setSource(const char* sourceURI) { mTokenSource = sourceURI; } + void setSource(const nsACString& sourceURI) { mTokenSource = sourceURI; } nsCOMPtr mTokenListener; nsCString mTokenSource; @@ -1312,9 +1312,8 @@ class MessageClassifier : public TokenAnalyzer { virtual ~MessageClassifier() {} virtual void analyzeTokens(Tokenizer& tokenizer) { - mFilter->classifyMessage(tokenizer, mTokenSource.get(), mProTraits, - mAntiTraits, mJunkListener, mTraitListener, - mDetailListener); + mFilter->classifyMessage(tokenizer, mTokenSource, mProTraits, mAntiTraits, + mJunkListener, mTraitListener, mDetailListener); tokenizer.clearTokens(); classifyNextMessage(); } @@ -1324,17 +1323,17 @@ class MessageClassifier : public TokenAnalyzer { MOZ_LOG(BayesianFilterLogModule, LogLevel::Warning, ("classifyNextMessage(%s)", mMessageURIs[mCurMessageToClassify].get())); - mFilter->tokenizeMessage(mMessageURIs[mCurMessageToClassify].get(), - mMsgWindow, this); + mFilter->tokenizeMessage(mMessageURIs[mCurMessageToClassify], mMsgWindow, + this); } else { // call all listeners with null parameters to signify end of batch if (mJunkListener) - mJunkListener->OnMessageClassified(nullptr, + mJunkListener->OnMessageClassified(EmptyCString(), nsIJunkMailPlugin::UNCLASSIFIED, 0); if (mTraitListener) { nsTArray nullTraits; nsTArray nullPercents; - mTraitListener->OnMessageTraitsClassified(nullptr, nullTraits, + mTraitListener->OnMessageTraitsClassified(EmptyCString(), nullTraits, nullPercents); } mTokenListener = @@ -1356,22 +1355,19 @@ class MessageClassifier : public TokenAnalyzer { uint32_t mCurMessageToClassify; // 0-based index }; -nsresult nsBayesianFilter::tokenizeMessage(const char* aMessageURI, +nsresult nsBayesianFilter::tokenizeMessage(const nsACString& aMessageURI, nsIMsgWindow* aMsgWindow, TokenAnalyzer* aAnalyzer) { - NS_ENSURE_ARG_POINTER(aMessageURI); - nsCOMPtr msgService; - nsresult rv = GetMessageServiceFromURI(nsDependentCString(aMessageURI), - getter_AddRefs(msgService)); + nsresult rv = + GetMessageServiceFromURI(aMessageURI, getter_AddRefs(msgService)); NS_ENSURE_SUCCESS(rv, rv); aAnalyzer->setSource(aMessageURI); nsCOMPtr dummyNull; return msgService->StreamMessage( - nsDependentCString(aMessageURI), aAnalyzer->mTokenListener, aMsgWindow, - nullptr, true /* convert data */, "filter"_ns, false, - getter_AddRefs(dummyNull)); + aMessageURI, aAnalyzer->mTokenListener, aMsgWindow, nullptr, + true /* convert data */, "filter"_ns, false, getter_AddRefs(dummyNull)); } // a TraitAnalysis is the per-token representation of the statistical @@ -1420,7 +1416,7 @@ static inline double chi2P(double chi2, double nu, int32_t* error) { } void nsBayesianFilter::classifyMessage( - Tokenizer& tokenizer, const char* messageURI, + Tokenizer& tokenizer, const nsACString& messageURI, nsTArray& aProTraits, nsTArray& aAntiTraits, nsIJunkMailClassificationListener* listener, nsIMsgTraitClassificationListener* aTraitListener, @@ -1677,7 +1673,7 @@ void nsBayesianFilter::classifyMessage( bool isJunk = (prob >= mJunkProbabilityThreshold); MOZ_LOG(BayesianFilterLogModule, LogLevel::Info, ("%s is junk probability = (%f) HAM SCORE:%f SPAM SCORE:%f", - messageURI, prob, H, S)); + PromiseFlatCString(messageURI).get(), prob, H, S)); // the algorithm in "A Plan For Spam" assumes that you have a large good // corpus and a large junk corpus. @@ -1724,7 +1720,7 @@ void nsBayesianFilter::classifyMessage( } void nsBayesianFilter::classifyMessage( - Tokenizer& tokens, const char* messageURI, + Tokenizer& tokens, const nsACString& messageURI, nsIJunkMailClassificationListener* aJunkListener) { AutoTArray proTraits; AutoTArray antiTraits; @@ -1760,9 +1756,9 @@ NS_IMETHODIMP nsBayesianFilter::GetShouldDownloadAllHeaders( /* void classifyMessage (in string aMsgURL, in nsIJunkMailClassificationListener * aListener); */ NS_IMETHODIMP nsBayesianFilter::ClassifyMessage( - const char* aMessageURL, nsIMsgWindow* aMsgWindow, + const nsACString& aMessageURL, nsIMsgWindow* aMsgWindow, nsIJunkMailClassificationListener* aListener) { - AutoTArray urls = {nsDependentCString(aMessageURL)}; + AutoTArray urls = {PromiseFlatCString(aMessageURL)}; MessageClassifier* analyzer = new MessageClassifier(this, aListener, aMsgWindow, urls); NS_ENSURE_TRUE(analyzer, NS_ERROR_OUT_OF_MEMORY); @@ -1784,7 +1780,7 @@ NS_IMETHODIMP nsBayesianFilter::ClassifyMessages( TokenStreamListener* tokenListener = new TokenStreamListener(analyzer); NS_ENSURE_TRUE(tokenListener, NS_ERROR_OUT_OF_MEMORY); analyzer->setTokenListener(tokenListener); - return tokenizeMessage(aMsgURLs[0].get(), aMsgWindow, analyzer); + return tokenizeMessage(aMsgURLs[0], aMsgWindow, analyzer); } nsresult nsBayesianFilter::setAnalysis(Token& token, uint32_t aTraitIndex, @@ -1867,7 +1863,7 @@ NS_IMETHODIMP nsBayesianFilter::ClassifyTraitsInMessages( TokenStreamListener* tokenListener = new TokenStreamListener(analyzer); analyzer->setTokenListener(tokenListener); - return tokenizeMessage(aMsgURIs[0].get(), aMsgWindow, analyzer); + return tokenizeMessage(aMsgURIs[0], aMsgWindow, analyzer); } class MessageObserver : public TokenAnalyzer { @@ -1885,7 +1881,7 @@ class MessageObserver : public TokenAnalyzer { mNewClassifications(aNewClassifications.Clone()) {} virtual void analyzeTokens(Tokenizer& tokenizer) { - mFilter->observeMessage(tokenizer, mTokenSource.get(), mOldClassifications, + mFilter->observeMessage(tokenizer, mTokenSource, mOldClassifications, mNewClassifications, mJunkListener, mTraitListener); // release reference to listener, which will allow us to go away as well. mTokenListener = nullptr; @@ -1901,7 +1897,7 @@ class MessageObserver : public TokenAnalyzer { }; NS_IMETHODIMP nsBayesianFilter::SetMsgTraitClassification( - const char* aMsgURI, const nsTArray& aOldTraits, + const nsACString& aMsgURI, const nsTArray& aOldTraits, const nsTArray& aNewTraits, nsIMsgTraitClassificationListener* aTraitListener, nsIMsgWindow* aMsgWindow, nsIJunkMailClassificationListener* aJunkListener) { @@ -1918,7 +1914,7 @@ NS_IMETHODIMP nsBayesianFilter::SetMsgTraitClassification( // set new message classifications for a message void nsBayesianFilter::observeMessage( - Tokenizer& tokenizer, const char* messageURL, + Tokenizer& tokenizer, const nsACString& messageURL, nsTArray& oldClassifications, nsTArray& newClassifications, nsIJunkMailClassificationListener* aJunkListener, @@ -2010,7 +2006,7 @@ NS_IMETHODIMP nsBayesianFilter::GetUserHasClassified(bool* aResult) { // Set message classification (only allows junk and good) NS_IMETHODIMP nsBayesianFilter::SetMessageClassification( - const char* aMsgURL, nsMsgJunkStatus aOldClassification, + const nsACString& aMsgURL, nsMsgJunkStatus aOldClassification, nsMsgJunkStatus aNewClassification, nsIMsgWindow* aMsgWindow, nsIJunkMailClassificationListener* aListener) { AutoTArray oldClassifications; @@ -2042,11 +2038,11 @@ NS_IMETHODIMP nsBayesianFilter::ResetTrainingData() { } NS_IMETHODIMP nsBayesianFilter::DetailMessage( - const char* aMsgURI, uint32_t aProTrait, uint32_t aAntiTrait, + const nsACString& aMsgURI, uint32_t aProTrait, uint32_t aAntiTrait, nsIMsgTraitDetailListener* aDetailListener, nsIMsgWindow* aMsgWindow) { AutoTArray proTraits = {aProTrait}; AutoTArray antiTraits = {aAntiTrait}; - AutoTArray uris = {nsDependentCString(aMsgURI)}; + AutoTArray uris = {PromiseFlatCString(aMsgURI)}; MessageClassifier* analyzer = new MessageClassifier(this, nullptr, nullptr, aDetailListener, proTraits, diff --git a/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.h b/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.h index df74e436d3..063688db4b 100644 --- a/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.h +++ b/mailnews/extensions/bayesian-spam-filter/nsBayesianFilter.h @@ -345,19 +345,19 @@ class nsBayesianFilter : public nsIJunkMailPlugin, nsresult Init(); - nsresult tokenizeMessage(const char* messageURI, nsIMsgWindow* aMsgWindow, - TokenAnalyzer* analyzer); - void classifyMessage(Tokenizer& tokens, const char* messageURI, + nsresult tokenizeMessage(const nsACString& messageURI, + nsIMsgWindow* aMsgWindow, TokenAnalyzer* analyzer); + void classifyMessage(Tokenizer& tokens, const nsACString& messageURI, nsIJunkMailClassificationListener* listener); - void classifyMessage(Tokenizer& tokenizer, const char* messageURI, + void classifyMessage(Tokenizer& tokenizer, const nsACString& messageURI, nsTArray& aProTraits, nsTArray& aAntiTraits, nsIJunkMailClassificationListener* listener, nsIMsgTraitClassificationListener* aTraitListener, nsIMsgTraitDetailListener* aDetailListener); - void observeMessage(Tokenizer& tokens, const char* messageURI, + void observeMessage(Tokenizer& tokens, const nsACString& messageURI, nsTArray& oldClassifications, nsTArray& newClassifications, nsIJunkMailClassificationListener* listener, diff --git a/mailnews/imap/src/nsImapIncomingServer.cpp b/mailnews/imap/src/nsImapIncomingServer.cpp index d87db8d4f4..e20d0a5a09 100644 --- a/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mailnews/imap/src/nsImapIncomingServer.cpp @@ -1372,11 +1372,11 @@ NS_IMETHODIMP nsImapIncomingServer::DiscoveryDone() { rv = GetSpamSettings(getter_AddRefs(spamSettings)); if (NS_SUCCEEDED(rv) && spamSettings) { nsCString spamFolderUri, existingUri; - spamSettings->GetSpamFolderURI(getter_Copies(spamFolderUri)); + spamSettings->GetSpamFolderURI(spamFolderUri); if (CheckSpecialFolder(spamFolderUri, nsMsgFolderFlags::Junk, existingUri)) { // This only sets the cached values in the spam settings object. - spamSettings->SetActionTargetFolder(existingUri.get()); + spamSettings->SetActionTargetFolder(existingUri); spamSettings->SetMoveTargetMode( nsISpamSettings::MOVE_TARGET_MODE_FOLDER); // Set the preferences too so that the values persist. diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index f29bd95ec3..e417a15730 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -8242,18 +8242,17 @@ nsImapMailFolder::SetJunkScoreForMessages( } NS_IMETHODIMP -nsImapMailFolder::OnMessageClassified(const char* aMsgURI, +nsImapMailFolder::OnMessageClassified(const nsACString& aMsgURI, nsMsgJunkStatus aClassification, uint32_t aJunkPercent) { nsCOMPtr server; nsresult rv = GetServer(getter_AddRefs(server)); NS_ENSURE_SUCCESS(rv, rv); - if (aMsgURI) // not end of batch + if (!aMsgURI.IsEmpty()) // not end of batch { nsCOMPtr msgHdr; - rv = - GetMsgDBHdrFromURI(nsDependentCString(aMsgURI), getter_AddRefs(msgHdr)); + rv = GetMsgDBHdrFromURI(aMsgURI, getter_AddRefs(msgHdr)); NS_ENSURE_SUCCESS(rv, rv); nsMsgKey msgKey; @@ -8298,7 +8297,7 @@ nsImapMailFolder::OnMessageClassified(const char* aMsgURI, (void)spamSettings->GetMoveOnSpam(&moveOnSpam); if (moveOnSpam) { nsCString spamFolderURI; - rv = spamSettings->GetSpamFolderURI(getter_Copies(spamFolderURI)); + rv = spamSettings->GetSpamFolderURI(spamFolderURI); NS_ENSURE_SUCCESS(rv, rv); if (!spamFolderURI.IsEmpty()) { @@ -8335,8 +8334,8 @@ nsImapMailFolder::OnMessageClassified(const char* aMsgURI, else // end of batch { // Parent will apply post bayes filters. - nsMsgDBFolder::OnMessageClassified(nullptr, nsIJunkMailPlugin::UNCLASSIFIED, - 0); + nsMsgDBFolder::OnMessageClassified(EmptyCString(), + nsIJunkMailPlugin::UNCLASSIFIED, 0); if (!m_junkMessagesToMarkAsRead.IsEmpty()) { rv = MarkMessagesRead(m_junkMessagesToMarkAsRead, true); diff --git a/mailnews/local/src/nsLocalMailFolder.cpp b/mailnews/local/src/nsLocalMailFolder.cpp index b483736a83..dd70e95e8d 100644 --- a/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mailnews/local/src/nsLocalMailFolder.cpp @@ -3062,7 +3062,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Shutdown(bool shutdownChildren) { } NS_IMETHODIMP -nsMsgLocalMailFolder::OnMessageClassified(const char* aMsgURI, +nsMsgLocalMailFolder::OnMessageClassified(const nsACString& aMsgURI, nsMsgJunkStatus aClassification, uint32_t aJunkPercent) @@ -3076,14 +3076,13 @@ nsMsgLocalMailFolder::OnMessageClassified(const char* aMsgURI, NS_ENSURE_SUCCESS(rv, rv); nsCString spamFolderURI; - rv = spamSettings->GetSpamFolderURI(getter_Copies(spamFolderURI)); + rv = spamSettings->GetSpamFolderURI(spamFolderURI); NS_ENSURE_SUCCESS(rv, rv); - if (aMsgURI) // not end of batch + if (!aMsgURI.IsEmpty()) // not end of batch { nsCOMPtr msgHdr; - rv = - GetMsgDBHdrFromURI(nsDependentCString(aMsgURI), getter_AddRefs(msgHdr)); + rv = GetMsgDBHdrFromURI(aMsgURI, getter_AddRefs(msgHdr)); NS_ENSURE_SUCCESS(rv, rv); nsMsgKey msgKey; @@ -3141,8 +3140,8 @@ nsMsgLocalMailFolder::OnMessageClassified(const char* aMsgURI, else // end of batch { // Parent will apply post bayes filters. - nsMsgDBFolder::OnMessageClassified(nullptr, nsIJunkMailPlugin::UNCLASSIFIED, - 0); + nsMsgDBFolder::OnMessageClassified(EmptyCString(), + nsIJunkMailPlugin::UNCLASSIFIED, 0); nsTArray> messages; if (!mSpamKeysToMove.IsEmpty()) { nsCOMPtr folder; diff --git a/mailnews/search/public/nsIMsgFilterList.idl b/mailnews/search/public/nsIMsgFilterList.idl index 7a999f509f..fa294d5063 100644 --- a/mailnews/search/public/nsIMsgFilterList.idl +++ b/mailnews/search/public/nsIMsgFilterList.idl @@ -82,7 +82,7 @@ interface nsIMsgFilterList : nsISupports { void writeStrAttr(in nsMsgFilterFileAttribValue attrib, in string value, in nsIOutputStream stream); void writeWstrAttr(in nsMsgFilterFileAttribValue attrib, in wstring value, in nsIOutputStream stream); void writeBoolAttr(in nsMsgFilterFileAttribValue attrib, in boolean value, in nsIOutputStream stream); - boolean matchOrChangeFilterTarget(in ACString oldUri, in ACString newUri, in boolean caseInsensitive); + boolean matchOrChangeFilterTarget(in AUTF8String oldUri, in AUTF8String newUri, in boolean caseInsensitive); /** * Turn filter logging on or off. Turning logging off will close any diff --git a/mailnews/search/public/nsIMsgFilterPlugin.idl b/mailnews/search/public/nsIMsgFilterPlugin.idl index 8d304fbaea..93934a364a 100644 --- a/mailnews/search/public/nsIMsgFilterPlugin.idl +++ b/mailnews/search/public/nsIMsgFilterPlugin.idl @@ -53,7 +53,7 @@ interface nsIJunkMailClassificationListener : nsISupports * @param aJunkPercent indicator of degree of uncertainty, with 100 being * probably junk, and 0 probably good */ - void onMessageClassified(in string aMsgURI, + void onMessageClassified(in AUTF8String aMsgURI, in nsMsgJunkStatus aClassification, in uint32_t aJunkPercent); }; @@ -74,7 +74,7 @@ interface nsIMsgTraitClassificationListener : nsISupports * matched) of the trait with the corresponding array * index in aTraits */ - void onMessageTraitsClassified(in string aMsgURI, + void onMessageTraitsClassified(in AUTF8String aMsgURI, in Array aTraits, in Array aPercents); }; @@ -98,7 +98,7 @@ interface nsIMsgTraitDetailListener : nsISupports * @param runningPercents calculated probability that the message matches the * trait, accounting for this token and all stronger tokens. */ - void onMessageTraitDetails(in string aMsgUri, + void onMessageTraitDetails(in AUTF8String aMsgUri, in unsigned long aProTrait, in Array tokenStrings, in Array tokenPercents, @@ -135,10 +135,10 @@ interface nsIJunkMailPlugin : nsIMsgFilterPlugin * Given a message URI, determine what its current classification is * according to the current training set. */ - void classifyMessage(in string aMsgURI, in nsIMsgWindow aMsgWindow, + void classifyMessage(in AUTF8String aMsgURI, in nsIMsgWindow aMsgWindow, in nsIJunkMailClassificationListener aListener); - void classifyMessages(in Array aMsgURIs, + void classifyMessages(in Array aMsgURIs, in nsIMsgWindow aMsgWindow, in nsIJunkMailClassificationListener aListener); @@ -159,7 +159,7 @@ interface nsIJunkMailPlugin : nsIMsgFilterPlugin */ void classifyTraitsInMessage( - in ACString aMsgURI, + in AUTF8String aMsgURI, in Array aProTraits, in Array aAntiTraits, in nsIMsgTraitClassificationListener aTraitListener, @@ -183,7 +183,7 @@ interface nsIJunkMailPlugin : nsIMsgFilterPlugin */ void classifyTraitsInMessages( - in Array aMsgURIs, + in Array aMsgURIs, in Array aProTraits, in Array aAntiTraits, in nsIMsgTraitClassificationListener aTraitListener, @@ -201,7 +201,7 @@ interface nsIJunkMailPlugin : nsIMsgFilterPlugin * @arg aListener Callback (may be null) */ void setMessageClassification( - in string aMsgURI, in nsMsgJunkStatus aOldUserClassification, + in AUTF8String aMsgURI, in nsMsgJunkStatus aOldUserClassification, in nsMsgJunkStatus aNewClassification, in nsIMsgWindow aMsgWindow, in nsIJunkMailClassificationListener aListener); @@ -220,7 +220,7 @@ interface nsIJunkMailPlugin : nsIMsgFilterPlugin * @param aJunkListener junk-oriented listener (may be null) */ void setMsgTraitClassification( - in string aMsgURI, + in AUTF8String aMsgURI, in Array aOldTraits, in Array aNewTraits, [optional] in nsIMsgTraitClassificationListener aTraitListener, @@ -250,7 +250,7 @@ interface nsIJunkMailPlugin : nsIMsgFilterPlugin * @param aMsgWindow current message window (may be null) */ void detailMessage( - in string aMsgURI, + in AUTF8String aMsgURI, in unsigned long aProTrait, in unsigned long aAntiTrait, in nsIMsgTraitDetailListener aListener,