Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes
nsMsgFilter Class Reference

#include <nsMsgFilter.h>

Inheritance diagram for nsMsgFilter:
Inheritance graph
[legend]
Collaboration diagram for nsMsgFilter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsMsgFilter ()
virtual ~nsMsgFilter ()
NS_DECL_NSIMSGFILTER
nsMsgFilterTypeType 
GetType ()
void SetType (nsMsgFilterTypeType type)
PRBool GetEnabled ()
void SetFilterScript (nsCString *filterName)
void SetFilterList (nsIMsgFilterList *filterList)
PRBool IsRule ()
PRBool IsScript ()
nsresult SaveToTextFile (nsIOFileStream *aStream)
nsresult SaveRule (nsIOFileStream *aStream)
PRInt16 GetVersion ()
nsresult ConvertMoveOrCopyToFolderValue (nsIMsgRuleAction *filterAction, nsCString &relativePath)
void AddTerm (in nsMsgSearchAttribValue attrib, in nsMsgSearchOpValue op, in nsIMsgSearchValue value, in boolean BooleanAND, in string arbitraryHeader)
void GetTerm (in long termIndex, out nsMsgSearchAttribValue attrib, out nsMsgSearchOpValue op, out nsIMsgSearchValue value, out boolean BooleanAND, out string arbitraryHeader)
void appendTerm (in nsIMsgSearchTerm term)
nsIMsgSearchTerm createTerm ()
void MatchHdr (in nsIMsgDBHdr msgHdr, in nsIMsgFolder folder, in nsIMsgDatabase db, in string headers, in unsigned long headerSize, out boolean result)
void logRuleHit (in nsIMsgRuleAction aFilterAction, in nsIMsgDBHdr aHeader)
nsIMsgRuleAction createAction ()
nsIMsgRuleAction getActionAt (in long aIndex)
void appendAction (in nsIMsgRuleAction action)
void clearActionList ()
void getSortedActionList (in nsISupportsArray actionList)

Static Public Member Functions

static const char * GetActionStr (nsMsgRuleActionType action)
static nsresult GetActionFilingStr (nsMsgRuleActionType action, nsCString &actionStr)
static nsMsgRuleActionType GetActionForFilingStr (nsCString &actionStr)

Public Attributes

nsMsgRuleAction m_action
attribute nsMsgFilterTypeType filterType
attribute boolean temporary
 some filters are "temporary".
attribute boolean enabled
attribute wstring filterName
attribute string filterDesc
attribute string unparsedBuffer
attribute boolean unparseable
readonly attribute nsIMsgFilterList filterList
attribute nsISupportsArray searchTerms
attribute nsIMsgSearchScopeTerm scope
readonly attribute nsISupportsArray actionList

Protected Attributes

nsMsgFilterTypeType m_type
nsString m_filterName
nsCString m_scriptFileName
nsCString m_description
nsCString m_unparsedBuffer
PRPackedBool m_enabled
PRPackedBool m_temporary
PRPackedBool m_unparseable
nsIMsgFilterListm_filterList
nsCOMPtr< nsISupportsArraym_termList
nsCOMPtr< nsIMsgSearchScopeTermm_scope
nsCOMPtr< nsISupportsArraym_actionList
nsMsgSearchBoolExpressionm_expressionTree
nsCOMPtr< nsIDateTimeFormatmDateFormatter

Detailed Description

Definition at line 73 of file nsMsgFilter.h.


Constructor & Destructor Documentation

Definition at line 184 of file nsMsgFilter.cpp.

{
  delete m_expressionTree;
}

Member Function Documentation

void nsIMsgFilter::AddTerm ( in nsMsgSearchAttribValue  attrib,
in nsMsgSearchOpValue  op,
in nsIMsgSearchValue  value,
in boolean  BooleanAND,
in string  arbitraryHeader 
) [inherited]

Definition at line 584 of file nsMsgFilter.cpp.

{
  NS_ENSURE_ARG_POINTER(filterAction);
  PRInt16 filterVersion = kFileVersion;
  if (m_filterList)
      m_filterList->GetVersion(&filterVersion);
  if (filterVersion <= k60Beta1Version)
  {
    nsCOMPtr <nsIImportService> impSvc = do_GetService(NS_IMPORTSERVICE_CONTRACTID);
    NS_ASSERTION(impSvc, "cannot get importService");
    nsCOMPtr <nsIMsgFolder> rootFolder;
    nsXPIDLCString folderUri;

    m_filterList->GetFolder(getter_AddRefs(rootFolder));

         // if relative path starts with kImap, this is a move to folder on the same server
    if (moveValue.Find(kImapPrefix) == 0)
    {
      PRInt32 prefixLen = PL_strlen(kImapPrefix);
      nsCAutoString originalServerPath;
      moveValue.Mid(originalServerPath, prefixLen, moveValue.Length() - prefixLen);
      if ( filterVersion == k45Version && impSvc)
      {
        nsAutoString unicodeStr;
        impSvc->SystemStringToUnicode(originalServerPath.get(), unicodeStr);
        nsresult rv = CopyUTF16toMUTF7(unicodeStr, originalServerPath);
        NS_ENSURE_SUCCESS(rv, rv); 
      }

      nsCOMPtr <nsIMsgFolder> destIFolder;
      if (rootFolder)
      {
        rootFolder->FindSubFolder(originalServerPath, getter_AddRefs(destIFolder));
        if (destIFolder)
        {
          destIFolder->GetURI(getter_Copies(folderUri));
          filterAction->SetTargetFolderUri(folderUri);
          moveValue.Assign(folderUri);
        }
      }
    }
         else
    {
      // start off leaving the value the same.
      filterAction->SetTargetFolderUri(moveValue.get());
      nsresult rv = NS_OK;
      nsCOMPtr <nsIMsgFolder> localMailRoot;
      rootFolder->GetURI(getter_Copies(folderUri));
      // if the root folder is not imap, than the local mail root is the server root.
      // otherwise, it's the migrated local folders.
      if (nsCRT::strncmp("imap:", folderUri, 5))
      {
        localMailRoot = rootFolder;
      }
      else
      {
        nsCOMPtr<nsIMsgAccountManager> accountManager = 
                 do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
        if (NS_SUCCEEDED(rv))
        {
          nsCOMPtr <nsIMsgIncomingServer> server; 
          rv = accountManager->GetLocalFoldersServer(getter_AddRefs(server)); 
          if (NS_SUCCEEDED(rv) && server)
          {
            rv = server->GetRootFolder(getter_AddRefs(localMailRoot));
          }
        }
      }
      if (NS_SUCCEEDED(rv) && localMailRoot)
      {
        nsXPIDLCString localRootURI;
        nsCOMPtr <nsIMsgFolder> destIMsgFolder;
        nsCOMPtr <nsIMsgFolder> localMailRootMsgFolder = do_QueryInterface(localMailRoot);
        localMailRoot->GetURI(getter_Copies(localRootURI));
        nsCString destFolderUri;
        destFolderUri.Assign( localRootURI);
        // need to remove ".sbd" from moveValue, and perhaps escape it.
        moveValue.ReplaceSubstring(".sbd/", "/");

#if defined(XP_MAC) || defined(XP_MACOSX)
        char *unescapedMoveValue = ToNewCString(moveValue);
        nsUnescape(unescapedMoveValue);
        moveValue.Assign(unescapedMoveValue);
        nsCRT::free(unescapedMoveValue);
#endif
        destFolderUri.Append('/');
        if ( filterVersion == k45Version && impSvc)
        {
          nsAutoString unicodeStr;
          impSvc->SystemStringToUnicode(moveValue.get(), unicodeStr);
          rv = NS_MsgEscapeEncodeURLPath(unicodeStr, moveValue);
        }
        destFolderUri.Append(moveValue);
        localMailRootMsgFolder->GetChildWithURI (destFolderUri.get(), PR_TRUE, PR_FALSE /*caseInsensitive*/, getter_AddRefs(destIMsgFolder));

        if (destIMsgFolder)
        {
          destIMsgFolder->GetURI(getter_Copies(folderUri));
                    filterAction->SetTargetFolderUri(folderUri);
          moveValue.Assign(folderUri);
        }
      }
    }
  }
  else
    filterAction->SetTargetFolderUri(moveValue.get());
    
  return NS_OK;
       // set m_action.m_value.m_folderUri
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 878 of file nsMsgFilter.cpp.

{
  int  numActions = sizeof(ruleActionsTable) / sizeof(ruleActionsTable[0]);
  
  for (int i = 0; i < numActions; i++)
  {
    if (action == ruleActionsTable[i].action)
    {
      actionStr = ruleActionsTable[i].actionFilingStr;
      return NS_OK;
    }
  }
  return NS_ERROR_INVALID_ARG;
}

Here is the caller graph for this function:

Definition at line 894 of file nsMsgFilter.cpp.

{
  int  numActions = sizeof(ruleActionsTable) / sizeof(ruleActionsTable[0]);
  
  for (int i = 0; i < numActions; i++)
  {
    if (actionStr.Equals(ruleActionsTable[i].actionFilingStr))
      return ruleActionsTable[i].action;
  }
  return nsMsgFilterAction::None;
}

Here is the caller graph for this function:

Definition at line 867 of file nsMsgFilter.cpp.

{
  int  numActions = sizeof(ruleActionsTable) / sizeof(ruleActionsTable[0]);
  
  for (int i = 0; i < numActions; i++)
  {
    if (action == ruleActionsTable[i].action)
      return ruleActionsTable[i].actionFilingStr; 
  }
  return "";
}

Definition at line 86 of file nsMsgFilter.h.

{return m_enabled;}
void nsIMsgFilter::GetTerm ( in long  termIndex,
out nsMsgSearchAttribValue  attrib,
out nsMsgSearchOpValue  op,
out nsIMsgSearchValue  value,
out boolean  BooleanAND,
out string  arbitraryHeader 
) [inherited]
NS_DECL_NSIMSGFILTER nsMsgFilterTypeType nsMsgFilter::GetType ( void  ) [inline]

Definition at line 84 of file nsMsgFilter.h.

{return m_type;}

Definition at line 907 of file nsMsgFilter.cpp.

{
    if (!m_filterList) return 0;
    PRInt16 version;
    m_filterList->GetVersion(&version);
    return version;
}

Definition at line 89 of file nsMsgFilter.h.

Definition at line 92 of file nsMsgFilter.h.

Here is the caller graph for this function:

void nsIMsgFilter::logRuleHit ( in nsIMsgRuleAction  aFilterAction,
in nsIMsgDBHdr  aHeader 
) [inherited]
void nsIMsgFilter::MatchHdr ( in nsIMsgDBHdr  msgHdr,
in nsIMsgFolder  folder,
in nsIMsgDatabase  db,
in string  headers,
in unsigned long  headerSize,
out boolean  result 
) [inherited]

Definition at line 716 of file nsMsgFilter.cpp.

{
  nsresult err = NS_OK;
  nsCOMPtr<nsIMsgFilterList> filterList;
  GetFilterList(getter_AddRefs(filterList));
  nsCAutoString      actionFilingStr;
   
  PRUint32 numActions;
  err = m_actionList->Count(&numActions);
  NS_ENSURE_SUCCESS(err, err);

  for (PRUint32 index =0; index < numActions; index++)
  {
    nsCOMPtr<nsIMsgRuleAction> action;
    err = m_actionList->QueryElementAt(index, NS_GET_IID(nsIMsgRuleAction), (void **)getter_AddRefs(action));
    if (!action)
      continue;
 
    nsMsgRuleActionType actionType;
    action->GetType(&actionType);
    GetActionFilingStr(actionType, actionFilingStr);
  
    err = filterList->WriteStrAttr(nsIMsgFilterList::attribAction, actionFilingStr.get(), aStream);
    NS_ENSURE_SUCCESS(err, err);
  
    switch(actionType)
    {
      case nsMsgFilterAction::MoveToFolder:
      case nsMsgFilterAction::CopyToFolder:
      {
        nsXPIDLCString imapTargetString;
        action->GetTargetFolderUri(getter_Copies(imapTargetString));
        err = filterList->WriteStrAttr(nsIMsgFilterList::attribActionValue, imapTargetString.get(), aStream);
      }
      break;
      case nsMsgFilterAction::ChangePriority:
      {
        nsMsgPriorityValue priorityValue;
        action->GetPriority(&priorityValue);
        nsCAutoString priority;
        NS_MsgGetUntranslatedPriorityName(priorityValue, priority);
        err = filterList->WriteStrAttr(
                nsIMsgFilterList::attribActionValue, priority.get(), aStream);
      }
      break;
      case nsMsgFilterAction::Label:
      {
        nsMsgLabelValue label;
        action->GetLabel(&label);
        err = filterList->WriteIntAttr(nsIMsgFilterList::attribActionValue, label, aStream);
      }
      break;
      case nsMsgFilterAction::JunkScore:
      {
        PRInt32 junkScore;
        action->GetJunkScore(&junkScore);
        err = filterList->WriteIntAttr(nsIMsgFilterList::attribActionValue, junkScore, aStream);
      }
      break;
      case nsMsgFilterAction::AddTag:
      case nsMsgFilterAction::Reply:
      case nsMsgFilterAction::Forward:
      {
        nsXPIDLCString strValue;
        action->GetStrValue(getter_Copies(strValue));
        // strValue is e-mail address
        err = filterList->WriteStrAttr(nsIMsgFilterList::attribActionValue, strValue.get(), aStream);
      }
      break;
      default:
        break;
    }
  }
  // and here the fun begins - file out term list...
  PRUint32 searchIndex;
  nsCAutoString  condition;
  PRUint32 count;
  m_termList->Count(&count);
  for (searchIndex = 0; searchIndex < count && NS_SUCCEEDED(err);
        searchIndex++)
  {
    nsCAutoString    stream;
  
    nsCOMPtr<nsIMsgSearchTerm> term;
    m_termList->QueryElementAt(searchIndex, NS_GET_IID(nsIMsgSearchTerm),
      (void **)getter_AddRefs(term));
    if (!term)
      continue;
  
    if (condition.Length() > 1)
      condition += ' ';
  
    PRBool booleanAnd;
    PRBool matchAll;
    term->GetBooleanAnd(&booleanAnd);
    term->GetMatchAll(&matchAll);
    if (matchAll)
    {
      condition += "ALL";
      break;
    }
    else if (booleanAnd)
      condition += "AND (";
    else
      condition += "OR (";
  
    nsresult searchError = term->GetTermAsString(stream);
    if (NS_FAILED(searchError))
    {
      err = searchError;
      break;
    }
  
    condition += stream;
    condition += ')';
  }
  if (NS_SUCCEEDED(err))
    err = filterList->WriteStrAttr(nsIMsgFilterList::attribCondition, condition.get(), aStream);
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 695 of file nsMsgFilter.cpp.

{
  NS_ENSURE_ARG_POINTER(aStream);
  if (m_unparseable)
  {
    //we need to trim leading whitespaces before filing out
    m_unparsedBuffer.Trim(kWhitespace, PR_TRUE /*leadingCharacters*/, PR_FALSE /*trailingCharacters*/);
    *aStream << m_unparsedBuffer.get();
    return NS_OK;
  }
  nsresult err = m_filterList->WriteWstrAttr(nsIMsgFilterList::attribName, m_filterName.get(), aStream);
  err = m_filterList->WriteBoolAttr(nsIMsgFilterList::attribEnabled, m_enabled, aStream);
  err = m_filterList->WriteStrAttr(nsIMsgFilterList::attribDescription, m_description.get(), aStream);
  err = m_filterList->WriteIntAttr(nsIMsgFilterList::attribType, m_type, aStream);
  if (IsScript())
    err = m_filterList->WriteStrAttr(nsIMsgFilterList::attribScriptFile, m_scriptFileName.get(), aStream);
  else
    err = SaveRule(aStream);
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 565 of file nsMsgFilter.cpp.

{
  // doesn't hold a ref.
  m_filterList = filterList;
}

Here is the caller graph for this function:

Definition at line 579 of file nsMsgFilter.cpp.

{
  m_scriptFileName = *fileName;
}

Here is the caller graph for this function:

Definition at line 85 of file nsMsgFilter.h.

{m_type = type;}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 124 of file nsIMsgFilter.idl.

Definition at line 78 of file nsIMsgFilter.idl.

Definition at line 80 of file nsIMsgFilter.idl.

Definition at line 84 of file nsIMsgFilter.idl.

attribute wstring nsIMsgFilter::filterName [inherited]

Definition at line 79 of file nsIMsgFilter.idl.

Definition at line 70 of file nsIMsgFilter.idl.

Definition at line 109 of file nsMsgFilter.h.

Definition at line 124 of file nsMsgFilter.h.

Definition at line 114 of file nsMsgFilter.h.

Definition at line 117 of file nsMsgFilter.h.

Definition at line 125 of file nsMsgFilter.h.

Definition at line 120 of file nsMsgFilter.h.

Definition at line 112 of file nsMsgFilter.h.

Definition at line 122 of file nsMsgFilter.h.

Definition at line 113 of file nsMsgFilter.h.

Definition at line 118 of file nsMsgFilter.h.

Definition at line 121 of file nsMsgFilter.h.

Definition at line 111 of file nsMsgFilter.h.

Definition at line 119 of file nsMsgFilter.h.

Definition at line 115 of file nsMsgFilter.h.

Definition at line 126 of file nsMsgFilter.h.

Definition at line 105 of file nsIMsgFilter.idl.

Definition at line 103 of file nsIMsgFilter.idl.

some filters are "temporary".

For example, the filters we create when the user filters return receipts to the Sent folder. we don't show temporary filters in the UI and we don't write them to disk.

Definition at line 77 of file nsIMsgFilter.idl.

Definition at line 82 of file nsIMsgFilter.idl.

Definition at line 81 of file nsIMsgFilter.idl.


The documentation for this class was generated from the following files: