From 12e7faae84181168e4fa5a3a617608408a35cfce Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Mon, 17 May 1999 02:07:13 +0000 Subject: [PATCH] more work on msg filters --- mailnews/base/search/public/nsIMsgFilter.h | 5 +- mailnews/base/search/src/nsMsgFilter.cpp | 63 ++++++++++++++++++-- mailnews/base/search/src/nsMsgFilter.h | 3 +- mailnews/base/search/src/nsMsgSearchTerm.cpp | 12 ++-- 4 files changed, 71 insertions(+), 12 deletions(-) diff --git a/mailnews/base/search/public/nsIMsgFilter.h b/mailnews/base/search/public/nsIMsgFilter.h index 215f384dcf2..2c47073933c 100644 --- a/mailnews/base/search/public/nsIMsgFilter.h +++ b/mailnews/base/search/public/nsIMsgFilter.h @@ -23,6 +23,9 @@ #include "nsISupports.h" #include "nsMsgFilterCore.h" +class nsOutputStream; +class nsIMsgDBHdr; + // 605db0f8-04a1-11d3-a50a-0060b0fc04b7 #define NS_IMSGFILTER_IID \ { 0x605db0f8, 0x04a1, 0x11d3, \ @@ -66,7 +69,7 @@ public: */ NS_IMETHOD SetAction(nsMsgRuleActionType type, void *value)= 0; NS_IMETHOD GetAction(nsMsgRuleActionType *type, void **value) = 0; - + NS_IMETHOD LogRuleHit(nsOutputStream *stream, nsIMsgDBHdr *header) = 0; }; #endif diff --git a/mailnews/base/search/src/nsMsgFilter.cpp b/mailnews/base/search/src/nsMsgFilter.cpp index c6bf5364522..62de9a8fccb 100644 --- a/mailnews/base/search/src/nsMsgFilter.cpp +++ b/mailnews/base/search/src/nsMsgFilter.cpp @@ -22,6 +22,7 @@ #include "nsMsgFilterList.h" #include "nsMsgFilter.h" #include "nsMsgUtils.h" +#include "nsFileStream.h" static const char *kImapPrefix = "//imap:"; @@ -163,6 +164,61 @@ NS_IMETHODIMP nsMsgFilter::GetAction(nsMsgRuleActionType *type, void **value) return NS_OK; } +NS_IMETHODIMP nsMsgFilter::LogRuleHit(nsOutputStream *stream, nsIMsgDBHdr *msgHdr) +{ + char *filterName = ""; + time_t date; + char dateStr[40]; /* 30 probably not enough */ + nsMsgRuleActionType actionType; + void *value; + nsString author; + nsString subject; + + GetFilterName(&filterName); + GetAction(&actionType, &value); + nsresult res = msgHdr->GetDate(&date); + struct tm* tmTime = localtime(&date); + strftime(dateStr, 100, "%m/%d/%Y %I:%M %p", tmTime); + + msgHdr->GetAuthor(author); + msgHdr->GetSubject(subject); + if (stream) + { + *stream << "Applied filter \""; + *stream << filterName; + *stream << "\" to message from "; + *stream << nsAutoCString(author); + *stream << " - "; + *stream << nsAutoCString(subject); + *stream << " at "; + *stream << dateStr; + *stream << "\n"; + const char *actionStr = GetActionStr(actionType); + char *actionValue = ""; + if (actionType == nsMsgFilterActionMoveToFolder) + actionValue = (char *) value; + *stream << "Action = "; + *stream << actionStr; + *stream << " "; + *stream << actionValue; + *stream << "\n\n"; +// XP_FilePrintf(*m_logFile, "Action = %s %s\n\n", actionStr, actionValue); + if (actionType == nsMsgFilterActionMoveToFolder) + { + nsString msgId; + msgHdr->GetMessageId(msgId); + *stream << "mailbox:"; + *stream << (char *) value; + *stream << "id = "; + *stream << nsAutoCString(msgId); + *stream << "\n"; + +// XP_FilePrintf(m_logFile, "mailbox:%s?id=%s\n", value, (const char *) msgId); + } + } + return NS_OK; +} + void nsMsgFilter::SetFilterList(nsMsgFilterList *filterList) @@ -340,19 +396,18 @@ static struct RuleActionsTableEntry ruleActionsTable[] = { nsMsgFilterActionWatchThread, nsMsgFilterAll, 0, /*XP_FILTER_WATCH_THREAD */ "Watch thread"} }; -#ifdef FILTER_UI -/*static */char *MSG_Rule::GetActionStr(MSG_RuleActionType action) +const char *nsMsgFilter::GetActionStr(nsMsgRuleActionType action) { int numActions = sizeof(ruleActionsTable) / sizeof(ruleActionsTable[0]); for (int i = 0; i < numActions; i++) { + // ### TODO use string bundle if (action == ruleActionsTable[i].action) - return XP_GetString(ruleActionsTable[i].xp_strIndex); + return ruleActionsTable[i].actionFilingStr; // XP_GetString(ruleActionsTable[i].xp_strIndex); } return ""; } -#endif /*static */nsresult nsMsgFilter::GetActionFilingStr(nsMsgRuleActionType action, nsString2 &actionStr) { int numActions = sizeof(ruleActionsTable) / sizeof(ruleActionsTable[0]); diff --git a/mailnews/base/search/src/nsMsgFilter.h b/mailnews/base/search/src/nsMsgFilter.h index f1aeee70264..adecf4bce4b 100644 --- a/mailnews/base/search/src/nsMsgFilter.h +++ b/mailnews/base/search/src/nsMsgFilter.h @@ -76,6 +76,7 @@ public: */ NS_IMETHOD SetAction(nsMsgRuleActionType type, void *value); NS_IMETHOD GetAction(nsMsgRuleActionType *type, void **value) ; + NS_IMETHOD LogRuleHit(nsOutputStream *stream, nsIMsgDBHdr *header); nsMsgFilterType GetType() {return m_type;} @@ -106,7 +107,7 @@ public: #endif nsresult ConvertMoveToFolderValue(nsString2 &relativePath); -static char *GetActionStr(nsMsgRuleActionType action); +static const char *GetActionStr(nsMsgRuleActionType action); static nsresult GetActionFilingStr(nsMsgRuleActionType action, nsString2 &actionStr); static nsMsgRuleActionType GetActionForFilingStr(nsString2 &actionStr); nsMsgRuleAction m_action; diff --git a/mailnews/base/search/src/nsMsgSearchTerm.cpp b/mailnews/base/search/src/nsMsgSearchTerm.cpp index 0d0edf8c4b2..7e2001583fd 100644 --- a/mailnews/base/search/src/nsMsgSearchTerm.cpp +++ b/mailnews/base/search/src/nsMsgSearchTerm.cpp @@ -1368,15 +1368,15 @@ MWContextType nsMsgResultElement::GetContextType () MWContextType type=(MWContextType)0; switch (m_adapter->m_scope->m_attribute) { - case scopeMailFolder: + case nsMsgSearchScopeMailFolder: type = MWContextMailMsg; break; - case scopeOfflineNewsgroup: // added by mscott could be bug fix... - case scopeNewsgroup: - case scopeAllSearchableGroups: + case nsMsgSearchScopeOfflineNewsgroup: // added by mscott could be bug fix... + case nsMsgSearchScopeNewsgroup: + case nsMsgSearchScopeAllSearchableGroups: type = MWContextNewsMsg; break; - case scopeLdapDirectory: + case nsMsgSearchScopeLdapDirectory: type = MWContextBrowser; break; default: @@ -1394,7 +1394,7 @@ nsresult nsMsgResultElement::Open (void *window) if (window) { - if (m_adapter->m_scope->m_attribute != scopeLdapDirectory) + if (m_adapter->m_scope->m_attribute != nsMsgSearchScopeLdapDirectory) { msgPane = (MSG_MessagePane *) window; XP_ASSERT (MSG_MESSAGEPANE == msgPane->GetPaneType());