Back to index

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

#include <nsMsgSearchTerm.h>

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

List of all members.

Public Member Functions

 nsMsgSearchTerm ()
 nsMsgSearchTerm (nsMsgSearchAttribValue, nsMsgSearchOpValue, nsIMsgSearchValue *, nsMsgSearchBooleanOperator, const char *arbitraryHeader)
virtual ~nsMsgSearchTerm ()
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGSEARCHTERM
PRInt32 
GetNextIMAPOfflineMsgLine (char *buf, int bufferSize, int msgOffset, nsIMsgDBHdr *msg, nsIMsgDatabase *db)
nsresult DeStream (char *, PRInt16 length)
nsresult DeStreamNew (char *, PRInt16 length)
nsresult GetLocalTimes (PRTime, PRTime, PRExplodedTime &, PRExplodedTime &)
PRBool IsBooleanOpAND ()
nsMsgSearchBooleanOperator GetBooleanOp ()
const char * GetArbitraryHeader ()
boolean matchRfc822String (in string aString, in string charset, in boolean charsetOverride)
boolean matchRfc2047String (in string aString, in string charset, in boolean charsetOverride)
boolean matchDate (in PRTime aTime)
boolean matchStatus (in unsigned long aStatus)
boolean matchPriority (in nsMsgPriorityValue priority)
boolean matchAge (in PRTime days)
boolean matchSize (in unsigned long size)
boolean matchLabel (in nsMsgLabelValue aLabelValue)
boolean matchJunkStatus (in string aJunkScore)
boolean matchBody (in nsIMsgSearchScopeTerm scopeTerm, in unsigned long offset, in unsigned long length, in string charset, in nsIMsgDBHdr msg, in nsIMsgDatabase db)
boolean matchArbitraryHeader (in nsIMsgSearchScopeTerm scopeTerm, in unsigned long offset, in unsigned long length, in string charset, in boolean charsetOverride, in nsIMsgDBHdr msg, in nsIMsgDatabase db, in string headers, in unsigned long headerLength, in boolean forFilters)
boolean matchKeyword (in string keyword)

Static Public Member Functions

static char * EscapeQuotesInStr (const char *str)

Public Attributes

nsCOMPtr< nsIMsgHeaderParserm_headerAddressParser
nsMsgSearchAttribValue m_attribute
nsMsgSearchOpValue m_operator
nsMsgSearchValue m_value
nsMsgSearchBooleanOperator m_booleanOp
nsCString m_arbitraryHeader
PRBool m_matchAll
attribute nsMsgSearchAttribValue attrib
attribute nsMsgSearchOpValue op
attribute nsIMsgSearchValue value
attribute boolean booleanAnd
attribute string arbitraryHeader
attribute boolean beginsGrouping
attribute boolean endsGrouping
readonly attribute boolean matchAllBeforeDeciding
readonly attribute ACString termAsString
attribute boolean matchAll

Protected Member Functions

nsresult MatchString (const char *stringToMatch, const char *charset, PRBool *pResult)
nsresult OutputValue (nsCString &outputStr)
nsresult ParseAttribute (char *inStream, nsMsgSearchAttribValue *attrib)
nsresult ParseOperator (char *inStream, nsMsgSearchOpValue *value)
nsresult ParseValue (char *inStream)
nsresult InitHeaderAddressParser ()
nsresult InitializeAddressBook ()
nsresult MatchInAddressBook (const char *aAddress, PRBool *pResult)

Protected Attributes

nsCOMPtr< nsIAbMDBDirectorymDirectory
PRPackedBool mBeginsGrouping
PRPackedBool mEndsGrouping

Detailed Description

Definition at line 53 of file nsMsgSearchTerm.h.


Constructor & Destructor Documentation

Definition at line 368 of file nsMsgSearchTerm.cpp.

Here is the call graph for this function:


Member Function Documentation

nsresult nsMsgSearchTerm::DeStream ( char *  ,
PRInt16  length 
)
nsresult nsMsgSearchTerm::DeStreamNew ( char *  inStream,
PRInt16  length 
)

Definition at line 650 of file nsMsgSearchTerm.cpp.

{
  if (!strcmp(inStream, "ALL"))
  {
    m_matchAll = PR_TRUE;
    return NS_OK;
  }
  char *commaSep = PL_strchr(inStream, ',');
  nsresult rv = ParseAttribute(inStream, &m_attribute);  // will allocate space for arbitrary header if necessary
  NS_ENSURE_SUCCESS(rv, rv);
  if (!commaSep)
    return NS_ERROR_INVALID_ARG;
  char *secondCommaSep = PL_strchr(commaSep + 1, ',');
  if (commaSep)
    rv = ParseOperator(commaSep + 1, &m_operator);
  NS_ENSURE_SUCCESS(rv, rv);
  // convert label filters and saved searches to keyword equivalents
  if (secondCommaSep)
    ParseValue(secondCommaSep + 1);
  if (m_attribute == nsMsgSearchAttrib::Label)
  {
    nsCAutoString keyword("$label");
    m_value.attribute = m_attribute = nsMsgSearchAttrib::Keywords;
    keyword.Append('0' + m_value.u.label);
    m_value.string = PL_strdup(keyword.get());
  }
  return NS_OK;
}

Here is the call graph for this function:

char * nsMsgSearchTerm::EscapeQuotesInStr ( const char *  str) [static]

Definition at line 379 of file nsMsgSearchTerm.cpp.

{
  int  numQuotes = 0;
  for (const char *strPtr = str; *strPtr; strPtr++)
    if (*strPtr == '"')
      numQuotes++;
    int escapedStrLen = PL_strlen(str) + numQuotes;
    char      *escapedStr = (char *) PR_Malloc(escapedStrLen + 1);
    if (escapedStr)
    {
      char *destPtr;
      for (destPtr = escapedStr; *str; str++)
      {
        if (*str == '"')
          *destPtr++ = '\\';
        *destPtr++ = *str;
      }
      *destPtr = '\0';
    }
    return escapedStr;
}

Here is the caller graph for this function:

Definition at line 95 of file nsMsgSearchTerm.h.

{return m_arbitraryHeader.get();}

Here is the call graph for this function:

Definition at line 93 of file nsMsgSearchTerm.h.

{return m_booleanOp;}
nsresult nsMsgSearchTerm::GetLocalTimes ( PRTime  a,
PRTime  b,
PRExplodedTime aExploded,
PRExplodedTime bExploded 
)

Definition at line 1068 of file nsMsgSearchTerm.cpp.

Here is the call graph for this function:

NS_DECL_ISUPPORTS NS_DECL_NSIMSGSEARCHTERM PRInt32 nsMsgSearchTerm::GetNextIMAPOfflineMsgLine ( char *  buf,
int  bufferSize,
int  msgOffset,
nsIMsgDBHdr msg,
nsIMsgDatabase db 
)

Definition at line 1384 of file nsMsgSearchTerm.cpp.

Here is the call graph for this function:

Definition at line 847 of file nsMsgSearchTerm.cpp.

{
  // the search attribute value has the URI for the address book we need to load. 
  // we need both the database and the directory.
  nsresult rv = NS_OK;

  if (mDirectory)
  {
    nsXPIDLCString dirURI;
    mDirectory->GetDirUri(getter_Copies(dirURI));
    if (strcmp(dirURI.get(), m_value.string))
      mDirectory = nsnull; // clear out the directory....we are no longer pointing to the right one
  }
  if (!mDirectory)
  {  
    nsCOMPtr <nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr <nsIRDFResource> resource;
    rv = rdfService->GetResource(nsDependentCString(m_value.string), getter_AddRefs(resource));
    NS_ENSURE_SUCCESS(rv, rv);

    mDirectory = do_QueryInterface(resource, &rv);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 92 of file nsMsgSearchTerm.h.

boolean nsIMsgSearchTerm::matchArbitraryHeader ( in nsIMsgSearchScopeTerm  scopeTerm,
in unsigned long  offset,
in unsigned long  length,
in string  charset,
in boolean  charsetOverride,
in nsIMsgDBHdr  msg,
in nsIMsgDatabase  db,
in string  headers,
in unsigned long  headerLength,
in boolean  forFilters 
) [inherited]
boolean nsIMsgSearchTerm::matchBody ( in nsIMsgSearchScopeTerm  scopeTerm,
in unsigned long  offset,
in unsigned long  length,
in string  charset,
in nsIMsgDBHdr  msg,
in nsIMsgDatabase  db 
) [inherited]
boolean nsIMsgSearchTerm::matchDate ( in PRTime  aTime) [inherited]
nsresult nsMsgSearchTerm::MatchInAddressBook ( const char *  aAddress,
PRBool pResult 
) [protected]

Definition at line 876 of file nsMsgSearchTerm.cpp.

{
  nsresult rv = InitializeAddressBook(); 
  *pResult = PR_FALSE;

  // Some junkmails have empty From: fields.
  if (aAddress == NULL || strlen(aAddress) == 0)
    return rv;

  if (mDirectory)
  {
    PRBool cardExists = PR_FALSE;
    rv = mDirectory->HasCardForEmailAddress(aAddress, &cardExists);
    if ( (m_operator == nsMsgSearchOp::IsInAB && cardExists) || (m_operator == nsMsgSearchOp::IsntInAB && !cardExists))
      *pResult = PR_TRUE;
  }
  
  return rv;
}

Here is the call graph for this function:

boolean nsIMsgSearchTerm::matchJunkStatus ( in string  aJunkScore) [inherited]
boolean nsIMsgSearchTerm::matchKeyword ( in string  keyword) [inherited]
boolean nsIMsgSearchTerm::matchRfc2047String ( in string  aString,
in string  charset,
in boolean  charsetOverride 
) [inherited]
boolean nsIMsgSearchTerm::matchRfc822String ( in string  aString,
in string  charset,
in boolean  charsetOverride 
) [inherited]
boolean nsIMsgSearchTerm::matchSize ( in unsigned long  size) [inherited]
boolean nsIMsgSearchTerm::matchStatus ( in unsigned long  aStatus) [inherited]
nsresult nsMsgSearchTerm::MatchString ( const char *  stringToMatch,
const char *  charset,
PRBool pResult 
) [protected]

Definition at line 928 of file nsMsgSearchTerm.cpp.

{
  NS_ENSURE_ARG_POINTER(pResult);
  PRBool result = PR_FALSE;
  
  nsresult err = NS_OK;
  nsAutoString utf16StrToMatch;
  nsAutoString needle; 

  // Save some performance for opIsEmpty
  if(nsMsgSearchOp::IsEmpty != m_operator)  
  {
    NS_ASSERTION(IsUTF8(nsDependentCString(m_value.string)),
                        "m_value.string is not UTF-8");
    CopyUTF8toUTF16(m_value.string, needle);

    if (charset != nsnull)
    {
      ConvertToUnicode(charset, stringToMatch ? stringToMatch : "",
                       utf16StrToMatch);
    }
    else { 
      NS_ASSERTION(IsUTF8(nsDependentCString(stringToMatch)),
                   "stringToMatch is not UTF-8");
      CopyUTF8toUTF16(stringToMatch, utf16StrToMatch);
    }
  }
  
  switch (m_operator)
  {
  case nsMsgSearchOp::Contains:
    if (CaseInsensitiveFindInReadable(needle, utf16StrToMatch))
      result = PR_TRUE;
    break;
  case nsMsgSearchOp::DoesntContain:
    if(!CaseInsensitiveFindInReadable(needle, utf16StrToMatch))
      result = PR_TRUE;
    break;
  case nsMsgSearchOp::Is:
    if(needle.Equals(utf16StrToMatch, nsCaseInsensitiveStringComparator()))
      result = PR_TRUE;
    break;
  case nsMsgSearchOp::Isnt:
    if(!needle.Equals(utf16StrToMatch, nsCaseInsensitiveStringComparator()))
      result = PR_TRUE;
    break;
  case nsMsgSearchOp::IsEmpty:
    // For IsEmpty, we didn't copy stringToMatch to utf16StrToMatch.
    if (!PL_strlen(stringToMatch))
      result = PR_TRUE;
    break;
  case nsMsgSearchOp::BeginsWith:
    if (StringBeginsWith(utf16StrToMatch, needle,
                         nsCaseInsensitiveStringComparator()))
      result = PR_TRUE;
    break;
  case nsMsgSearchOp::EndsWith: 
    if (StringEndsWith(utf16StrToMatch, needle,
                       nsCaseInsensitiveStringComparator()))
      result = PR_TRUE;
    break;
  default:
    NS_ASSERTION(PR_FALSE, "invalid operator matching search results");
  }
  
  *pResult = result;
  return err;
}

Here is the call graph for this function:

nsresult nsMsgSearchTerm::OutputValue ( nsCString outputStr) [protected]

Definition at line 402 of file nsMsgSearchTerm.cpp.

{
  if (IS_STRING_ATTRIBUTE(m_attribute) && m_value.string)
  {
    PRBool    quoteVal = PR_FALSE;
    // need to quote strings with ')' and strings starting with '"' or ' '
    // filter code will escape quotes
    if (PL_strchr(m_value.string, ')') ||
      (m_value.string[0] == ' ') ||
      (m_value.string[0] == '"'))
    {
      quoteVal = PR_TRUE;
      outputStr += "\"";
    }
    if (PL_strchr(m_value.string, '"'))
    {
      char *escapedString = nsMsgSearchTerm::EscapeQuotesInStr(m_value.string);
      if (escapedString)
      {
        outputStr += escapedString;
        PR_Free(escapedString);
      }
      
    }
    else
    {
      outputStr += m_value.string;
    }
    if (quoteVal)
      outputStr += "\"";
  }
  else
  {
    switch (m_attribute)
    {
    case nsMsgSearchAttrib::Date:
      {
        PRExplodedTime exploded;
        PR_ExplodeTime(m_value.u.date, PR_LocalTimeParameters, &exploded);
        
        // wow, so tm_mon is 0 based, tm_mday is 1 based.
        char dateBuf[100];
        PR_FormatTimeUSEnglish (dateBuf, sizeof(dateBuf), "%d-%b-%Y", &exploded);
        outputStr += dateBuf;
        break;
      }
    case nsMsgSearchAttrib::AgeInDays:
      {
        outputStr.AppendInt(m_value.u.age);
        break;
      }
    case nsMsgSearchAttrib::Label:
      {
        outputStr.AppendInt(m_value.u.label);
        break;
      }
    case nsMsgSearchAttrib::JunkStatus:
      {
        outputStr.AppendInt(m_value.u.junkStatus); // only if we write to disk, right?
        break;
      }
    case nsMsgSearchAttrib::MsgStatus:
      {
        nsCAutoString status;
        NS_MsgGetUntranslatedStatusName (m_value.u.msgStatus, &status);
        outputStr += status;
        break;
      }
    case nsMsgSearchAttrib::Priority:
      {
        nsCAutoString priority;
        NS_MsgGetUntranslatedPriorityName(m_value.u.priority, priority);
        outputStr += priority;
        break;
      }
    case nsMsgSearchAttrib::HasAttachmentStatus:
      {
        outputStr.Append("true");  // don't need anything here, really
        break;
      }
    case nsMsgSearchAttrib::Size:
      {
        outputStr.AppendInt(m_value.u.size);
        break;
      }
    default:
      NS_ASSERTION(PR_FALSE, "trying to output invalid attribute");
      break;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsMsgSearchTerm::ParseAttribute ( char *  inStream,
nsMsgSearchAttribValue attrib 
) [protected]

Definition at line 613 of file nsMsgSearchTerm.cpp.

{   
    while (nsCRT::IsAsciiSpace(*inStream))
        inStream++;
    
    // if we are dealing with an arbitrary header, it may be quoted....
    PRBool quoteVal = PR_FALSE;
    if (*inStream == '"')
    {
        quoteVal = PR_TRUE;
        inStream++;
    }
    
    // arbitrary headers are quoted
    char *separator = strchr(inStream, quoteVal ? '"' : ',');

    if (separator)
        *separator = '\0';
    
    PRInt16 attributeVal;
    nsresult rv = NS_MsgGetAttributeFromString(inStream, &attributeVal);
    NS_ENSURE_SUCCESS(rv, rv);
    
    *attrib = (nsMsgSearchAttribValue) attributeVal;
    
    if (*attrib > nsMsgSearchAttrib::OtherHeader && *attrib < nsMsgSearchAttrib::kNumMsgSearchAttributes)  // if we are dealing with an arbitrary header....
        m_arbitraryHeader = inStream;
    
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgSearchTerm::ParseOperator ( char *  inStream,
nsMsgSearchOpValue value 
) [protected]

Definition at line 594 of file nsMsgSearchTerm.cpp.

{
  NS_ENSURE_ARG_POINTER(value);
  PRInt16                          operatorVal;
  while (nsCRT::IsAsciiSpace(*inStream))
    inStream++;
  
  char *commaSep = PL_strchr(inStream, ',');
  
  if (commaSep)
    *commaSep = '\0';
  
  nsresult err = NS_MsgGetOperatorFromString(inStream, &operatorVal);
  *value = (nsMsgSearchOpValue) operatorVal;
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsMsgSearchTerm::ParseValue ( char *  inStream) [protected]

Definition at line 534 of file nsMsgSearchTerm.cpp.

{
  if (IS_STRING_ATTRIBUTE(m_attribute))
  {
    PRBool    quoteVal = PR_FALSE;
    while (nsCRT::IsAsciiSpace(*inStream))
      inStream++;
    // need to remove pair of '"', if present
    if (*inStream == '"')
    {
      quoteVal = PR_TRUE;
      inStream++;
    }
    int valueLen = PL_strlen(inStream);
    if (quoteVal && inStream[valueLen - 1] == '"')
      valueLen--;
    
    m_value.string = (char *) PR_Malloc(valueLen + 1);
    PL_strncpy(m_value.string, inStream, valueLen + 1);
    m_value.string[valueLen] = '\0';
  }
  else
  {
    switch (m_attribute)
    {
    case nsMsgSearchAttrib::Date:
      PR_ParseTimeString (inStream, PR_FALSE, &m_value.u.date);
      break;
    case nsMsgSearchAttrib::MsgStatus:
      m_value.u.msgStatus = NS_MsgGetStatusValueFromName(inStream);
      break;
    case nsMsgSearchAttrib::Priority:
      NS_MsgGetPriorityFromString(inStream, m_value.u.priority);
      break;
    case nsMsgSearchAttrib::AgeInDays:
      m_value.u.age = atoi(inStream);
      break;
    case nsMsgSearchAttrib::Label:
      m_value.u.label = atoi(inStream);
      break;
    case nsMsgSearchAttrib::JunkStatus:
      m_value.u.junkStatus = atoi(inStream); // only if we read from disk, right?
      break;
    case nsMsgSearchAttrib::HasAttachmentStatus:
      m_value.u.msgStatus = MSG_FLAG_ATTACHMENT;
      break; // this should always be true.
    case nsMsgSearchAttrib::Size:
      m_value.u.size = atoi(inStream);
      break;
    default:
      NS_ASSERTION(PR_FALSE, "invalid attribute parsing search term value");
      break;
    }
  }
  m_value.attribute = m_attribute;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 56 of file nsIMsgSearchTerm.idl.

Definition at line 51 of file nsIMsgSearchTerm.idl.

Definition at line 58 of file nsIMsgSearchTerm.idl.

Definition at line 55 of file nsIMsgSearchTerm.idl.

Definition at line 59 of file nsIMsgSearchTerm.idl.

Definition at line 105 of file nsMsgSearchTerm.h.

Definition at line 101 of file nsMsgSearchTerm.h.

Definition at line 104 of file nsMsgSearchTerm.h.

Definition at line 99 of file nsMsgSearchTerm.h.

Definition at line 107 of file nsMsgSearchTerm.h.

Definition at line 102 of file nsMsgSearchTerm.h.

Definition at line 103 of file nsMsgSearchTerm.h.

Definition at line 97 of file nsIMsgSearchTerm.idl.

Definition at line 93 of file nsIMsgSearchTerm.idl.

Definition at line 122 of file nsMsgSearchTerm.h.

Definition at line 120 of file nsMsgSearchTerm.h.

Definition at line 123 of file nsMsgSearchTerm.h.

Definition at line 52 of file nsIMsgSearchTerm.idl.

readonly attribute ACString nsIMsgSearchTerm::termAsString [inherited]

Definition at line 95 of file nsIMsgSearchTerm.idl.

Definition at line 53 of file nsIMsgSearchTerm.idl.


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