diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index 41b281bb846..fe3e57ebccb 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -2195,7 +2195,8 @@ nsMsgDBView::ApplyCommandToIndices(nsMsgViewCommandTypeValue command, nsMsgViewI // in the last callback. // if ( command == nsMsgViewCommandType::junk - || command == nsMsgViewCommandType::unjunk ) { + || command == nsMsgViewCommandType::unjunk ) + { // get the folder from the first item (if it's the search view, // only one item can be touched at a time; if a regular folder view, @@ -2610,6 +2611,13 @@ nsresult nsMsgDBView::SetJunkScoreByIndex(nsIJunkMailPlugin *aJunkPlugin, uri, oldUserClassification, aNewClassification, mMsgWindow, this); NS_ENSURE_SUCCESS(rv, rv); + // this routine is only reached if the user someone touched the UI + // and told us the junk status of this message. + // Set origin first so that listeners on the junkscore will + // know the correct origin. + rv = SetStringPropertyByIndex(aIndex, "junkscoreorigin", "user"); + NS_ASSERTION(NS_SUCCEEDED(rv), "SetStringPropertyByIndex failed"); + // set the junk score on the message itself // rv = SetStringPropertyByIndex( @@ -2617,11 +2625,6 @@ nsresult nsMsgDBView::SetJunkScoreByIndex(nsIJunkMailPlugin *aJunkPlugin, aNewClassification == nsIJunkMailPlugin::JUNK ? "100" : "0"); NS_ENSURE_SUCCESS(rv, rv); - // this routine is only reached if the user someone touched the UI - // and told us the junk status of this message. - // - rv = SetStringPropertyByIndex(aIndex, "junkscoreorigin", "user"); - NS_ASSERTION(NS_SUCCEEDED(rv), "SetStringPropertyByIndex failed"); return rv; } diff --git a/mailnews/base/src/nsMsgQuickSearchDBView.cpp b/mailnews/base/src/nsMsgQuickSearchDBView.cpp index e9c56d81e0d..cf0bd863ad6 100644 --- a/mailnews/base/src/nsMsgQuickSearchDBView.cpp +++ b/mailnews/base/src/nsMsgQuickSearchDBView.cpp @@ -106,6 +106,47 @@ nsresult nsMsgQuickSearchDBView::OnNewHeader(nsMsgKey newKey, nsMsgKey aParentKe return NS_OK; } +NS_IMETHODIMP nsMsgQuickSearchDBView::OnKeyChange(nsMsgKey aKeyChanged, PRUint32 aOldFlags, + PRUint32 aNewFlags, nsIDBChangeListener *aInstigator) +{ + nsresult rv = nsMsgDBView::OnKeyChange(aKeyChanged, aOldFlags, aNewFlags, aInstigator); + // flags haven't really changed - check if the message is newly classified as junk + if ((aOldFlags == aNewFlags) && (aOldFlags & MSG_FLAG_NEW)) + { + nsCOMPtr msgHdr; + rv = m_db->GetMsgHdrForKey(aKeyChanged, getter_AddRefs(msgHdr)); + if (NS_SUCCEEDED(rv) && msgHdr != nsnull) + { + nsXPIDLCString junkScoreStr; + (void) msgHdr->GetStringProperty("junkscore", getter_Copies(junkScoreStr)); + if (atoi(junkScoreStr.get()) > 50) + { + nsXPIDLCString originStr; + (void) msgHdr->GetStringProperty("junkscoreorigin", + getter_Copies(originStr)); + + // if this was classified by the plugin, see if we're supposed to + // show junk mail + if (originStr.get()[0] == 'p') + { + PRBool match=PR_FALSE; + nsCOMPtr searchSession = do_QueryReferent(m_searchSession); + if (searchSession) + searchSession->MatchHdr(msgHdr, m_db, &match); + if (!match) + { + // remove hdr from view + nsMsgViewIndex deletedIndex = m_keys.FindIndex(aKeyChanged); + if (deletedIndex != nsMsgViewIndex_None) + RemoveByIndex(deletedIndex); + } + } + } + } + } + return rv; +} + NS_IMETHODIMP nsMsgQuickSearchDBView::GetSearchSession(nsIMsgSearchSession* *aSession) {