Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsMsgSearchTerm.cpp File Reference
#include "msgCore.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsMsgSearchCore.h"
#include "nsIMsgSearchSession.h"
#include "nsMsgUtils.h"
#include "nsIMsgDatabase.h"
#include "nsMsgSearchTerm.h"
#include "nsMsgSearchScopeTerm.h"
#include "nsMsgBodyHandler.h"
#include "nsMsgResultElement.h"
#include "nsIMsgImapMailFolder.h"
#include "nsMsgSearchImap.h"
#include "nsMsgLocalSearch.h"
#include "nsMsgSearchNews.h"
#include "nsMsgSearchValue.h"
#include "nsMsgI18N.h"
#include "nsIMimeConverter.h"
#include "nsMsgMimeCID.h"
#include "nsTime.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIMsgFilterPlugin.h"
#include "nsIFileSpec.h"
#include "nsIRDFService.h"
#include "nsISupportsObsolete.h"
#include "nsNetCID.h"
#include "nsIFileStreams.h"
#include "nsUnicharUtils.h"

Go to the source code of this file.

Classes

struct  nsMsgSearchAttribEntry
struct  nsMsgSearchOperatorEntry

Defines

#define MAILNEWS_CUSTOM_HEADERS   "mailnews.customHeaders"
#define MSG_STATUS_MASK   (MSG_FLAG_READ | MSG_FLAG_REPLIED | MSG_FLAG_FORWARDED | MSG_FLAG_NEW | MSG_FLAG_MARKED)

Functions

nsresult NS_MsgGetAttributeFromString (const char *string, PRInt16 *attrib)
nsresult NS_MsgGetStringForAttribute (PRInt16 attrib, const char **string)
nsresult NS_MsgGetOperatorFromString (const char *string, PRInt16 *op)
nsresult NS_MsgGetStringForOperator (PRInt16 op, const char **string)
void NS_MsgGetUntranslatedStatusName (uint32 s, nsCString *outName)
PRInt32 NS_MsgGetStatusValueFromName (char *name)

Variables

nsMsgSearchAttribEntry SearchAttribEntryTable []
nsMsgSearchOperatorEntry SearchOperatorEntryTable []

Class Documentation

struct nsMsgSearchAttribEntry

Definition at line 81 of file nsMsgSearchTerm.cpp.

Class Members
nsMsgSearchAttribValue attrib
const char * attribName
struct nsMsgSearchOperatorEntry

Definition at line 204 of file nsMsgSearchTerm.cpp.

Class Members
nsMsgSearchOpValue op
const char * opName

Define Documentation

#define MAILNEWS_CUSTOM_HEADERS   "mailnews.customHeaders"

Definition at line 79 of file nsMsgSearchTerm.cpp.


Function Documentation

nsresult NS_MsgGetAttributeFromString ( const char *  string,
PRInt16 attrib 
)

Definition at line 113 of file nsMsgSearchTerm.cpp.

{
  NS_ENSURE_ARG_POINTER(string);
  NS_ENSURE_ARG_POINTER(attrib);
  
  PRBool found = PR_FALSE;
  for (int idxAttrib = 0; idxAttrib < (int)(sizeof(SearchAttribEntryTable) / sizeof(nsMsgSearchAttribEntry)); idxAttrib++)
  {
    if (!PL_strcasecmp(string, SearchAttribEntryTable[idxAttrib].attribName))
    {
      found = PR_TRUE;
      *attrib = SearchAttribEntryTable[idxAttrib].attrib;
      break;
    }
  }  
  if (!found)
  {
    nsresult rv;
    PRBool goodHdr;
    IsRFC822HeaderFieldName(string, &goodHdr);
    if (!goodHdr)
      return NS_MSG_INVALID_CUSTOM_HEADER;
    //49 is for showing customize... in ui, headers start from 50 onwards up until 99.
    *attrib = nsMsgSearchAttrib::OtherHeader+1;

    nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIPrefBranch> prefBranch;
    rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
    NS_ENSURE_SUCCESS(rv, rv);

    nsXPIDLCString headers;
    prefBranch->GetCharPref(MAILNEWS_CUSTOM_HEADERS, getter_Copies(headers));

    if (!headers.IsEmpty())
    {
      char *headersString = ToNewCString(headers);

      nsCAutoString hdrStr;
      hdrStr.Adopt(headersString);
      hdrStr.StripWhitespace();  //remove whitespace before parsing

      char *newStr=nsnull;
      char *token = nsCRT::strtok(headersString,":", &newStr);
      PRUint32 i=0;
      while (token)
      {
        if (nsCRT::strcasecmp(token, string) == 0)
        {
          *attrib += i; //we found custom header in the pref
          found = PR_TRUE;
          break;
        }
        token = nsCRT::strtok(newStr,":", &newStr);
        i++;
      }
    }
  }
  // If we didn't find the header in MAILNEWS_CUSTOM_HEADERS, we're 
  // going to return NS_OK and an attrib of nsMsgSearchAttrib::OtherHeader+1.
  // in case it's a client side spam filter description filter, 
  // which doesn't add its headers to mailnews.customMailHeaders.
  // We've already checked that it's a valid header and returned
  // an error if so.

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult NS_MsgGetOperatorFromString ( const char *  string,
PRInt16 op 
)

Definition at line 229 of file nsMsgSearchTerm.cpp.

{
  NS_ENSURE_ARG_POINTER(string);
  NS_ENSURE_ARG_POINTER(op);
       
       PRBool found = PR_FALSE;
       for (unsigned int idxOp = 0; idxOp < sizeof(SearchOperatorEntryTable) / sizeof(nsMsgSearchOperatorEntry); idxOp++)
       {
              // I'm using the idx's as aliases into MSG_SearchAttribute and 
              // MSG_SearchOperator enums which is legal because of the way the
              // enums are defined (starts at 0, numItems at end)
              if (!PL_strcasecmp(string, SearchOperatorEntryTable[idxOp].opName))
              {
                     found = PR_TRUE;
                     *op = SearchOperatorEntryTable[idxOp].op;
                     break;
              }
       }
       return (found) ? NS_OK : NS_ERROR_INVALID_ARG;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 319 of file nsMsgSearchTerm.cpp.

{
  if (!strcmp("read", name))
    return MSG_FLAG_READ;
  if (!strcmp("replied", name))
    return MSG_FLAG_REPLIED;
  if (!strcmp("forwarded", name))
    return MSG_FLAG_FORWARDED;
  if (!strcmp("replied and forwarded", name))
    return MSG_FLAG_FORWARDED|MSG_FLAG_REPLIED;
  if (!strcmp("new", name))
    return MSG_FLAG_NEW;
  if (!strcmp("flagged", name))
    return MSG_FLAG_MARKED;
  return 0;
}

Here is the caller graph for this function:

nsresult NS_MsgGetStringForAttribute ( PRInt16  attrib,
const char **  string 
)

Definition at line 182 of file nsMsgSearchTerm.cpp.

{
  NS_ENSURE_ARG_POINTER(string);

  PRBool found = PR_FALSE;
       for (int idxAttrib = 0; idxAttrib < (int)(sizeof(SearchAttribEntryTable) / sizeof(nsMsgSearchAttribEntry)); idxAttrib++)
       {
              // I'm using the idx's as aliases into MSG_SearchAttribute and 
              // MSG_SearchOperator enums which is legal because of the way the
              // enums are defined (starts at 0, numItems at end)
              if (attrib == SearchAttribEntryTable[idxAttrib].attrib)
              {
                     found = PR_TRUE;
                     *string = SearchAttribEntryTable[idxAttrib].attribName;
                     break;
              }
       }
       // we no longer return invalid attribute. If we cannot find the string in the table, 
       // then it is an arbitrary header. Return success regardless if found or not
       return NS_OK;
}
nsresult NS_MsgGetStringForOperator ( PRInt16  op,
const char **  string 
)

Definition at line 250 of file nsMsgSearchTerm.cpp.

{
  NS_ENSURE_ARG_POINTER(string);
  
  PRBool found = PR_FALSE;
       for (unsigned int idxOp = 0; idxOp < sizeof(SearchOperatorEntryTable) / sizeof(nsMsgSearchOperatorEntry); idxOp++)
       {
              // I'm using the idx's as aliases into MSG_SearchAttribute and 
              // MSG_SearchOperator enums which is legal because of the way the
              // enums are defined (starts at 0, numItems at end)
              if (op == SearchOperatorEntryTable[idxOp].op)
              {
                     found = PR_TRUE;
                     *string = SearchOperatorEntryTable[idxOp].opName;
                     break;
              }
       }

       return (found) ? NS_OK : NS_ERROR_INVALID_ARG;
}

Definition at line 271 of file nsMsgSearchTerm.cpp.

{
       const char *tmpOutName = NULL;
#define MSG_STATUS_MASK (MSG_FLAG_READ | MSG_FLAG_REPLIED | MSG_FLAG_FORWARDED | MSG_FLAG_NEW | MSG_FLAG_MARKED)
       PRUint32 maskOut = (s & MSG_STATUS_MASK);

       // diddle the flags to pay attention to the most important ones first, if multiple
       // flags are set. Should remove this code from the winfe.
       if (maskOut & MSG_FLAG_NEW) 
              maskOut = MSG_FLAG_NEW;
       if ( maskOut & MSG_FLAG_REPLIED &&
               maskOut & MSG_FLAG_FORWARDED ) 
              maskOut = MSG_FLAG_REPLIED|MSG_FLAG_FORWARDED;
       else if ( maskOut & MSG_FLAG_FORWARDED )
              maskOut = MSG_FLAG_FORWARDED;
       else if ( maskOut & MSG_FLAG_REPLIED ) 
              maskOut = MSG_FLAG_REPLIED;

       switch (maskOut)
       {
       case MSG_FLAG_READ:
              tmpOutName = "read";
              break;
       case MSG_FLAG_REPLIED:
              tmpOutName = "replied";
              break;
       case MSG_FLAG_FORWARDED:
              tmpOutName = "forwarded";
              break;
       case MSG_FLAG_FORWARDED|MSG_FLAG_REPLIED:
              tmpOutName = "replied and forwarded";
              break;
       case MSG_FLAG_NEW:
              tmpOutName = "new";
              break;
        case MSG_FLAG_MARKED:
                tmpOutName = "flagged";
                break;
       default:
              // This is fine, status may be "unread" for example
        break;
       }

       if (tmpOutName)
              *outName = tmpOutName;
}

Here is the caller graph for this function:


Variable Documentation

Initial value:
{
  {nsMsgSearchOp::Contains, "contains"},
  {nsMsgSearchOp::DoesntContain,"doesn't contain"},
  {nsMsgSearchOp::Is,"is"},
  {nsMsgSearchOp::Isnt,     "isn't"},
  {nsMsgSearchOp::IsEmpty, "is empty"},
  {nsMsgSearchOp::IsBefore, "is before"},
  {nsMsgSearchOp::IsAfter, "is after"},
  {nsMsgSearchOp::IsHigherThan, "is higher than"},
  {nsMsgSearchOp::IsLowerThan, "is lower than"},
  {nsMsgSearchOp::BeginsWith, "begins with"},
  {nsMsgSearchOp::EndsWith, "ends with"},
  {nsMsgSearchOp::IsInAB, "is in ab"},
  {nsMsgSearchOp::IsntInAB, "isn't in ab"},
  {nsMsgSearchOp::IsGreaterThan, "is greater than"},
  {nsMsgSearchOp::IsLessThan, "is less than"}
}

Definition at line 210 of file nsMsgSearchTerm.cpp.