Back to index

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

#include <nsMsgBodyHandler.h>

Collaboration diagram for nsMsgBodyHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMsgBodyHandler (nsIMsgSearchScopeTerm *, PRUint32 offset, PRUint32 length, nsIMsgDBHdr *msg, nsIMsgDatabase *db)
 nsMsgBodyHandler (nsIMsgSearchScopeTerm *, PRUint32 offset, PRUint32 length, nsIMsgDBHdr *msg, nsIMsgDatabase *db, const char *headers, PRUint32 headersSize, PRBool ForFilters)
virtual ~nsMsgBodyHandler ()
PRInt32 GetNextLine (nsCString &buf)
void SetStripHtml (PRBool strip)
void SetStripHeaders (PRBool strip)

Protected Member Functions

void Initialize ()
PRInt32 GetNextFilterLine (nsCString &buf)
void OpenLocalFolder ()
PRInt32 GetNextLocalLine (nsCString &buf)
PRInt32 ApplyTransformations (nsCString &buf, PRInt32 length, PRBool &returnThisLine)
void StripHtml (nsCString &buf)

Protected Attributes

PRBool m_Filtering
const char * m_headers
PRUint32 m_headersSize
PRUint32 m_headerBytesRead
nsIMsgSearchScopeTermm_scope
nsCOMPtr< nsILineInputStreamm_fileLineStream
nsCOMPtr< nsILocalFilem_localFile
PRInt32 m_localFileOffset
PRUint32 m_numLocalLines
nsIMsgDBHdrm_msgHdr
nsIMsgDatabasem_db
PRBool m_stripHeaders
PRBool m_stripHtml
PRBool m_passedHeaders
PRBool m_messageIsHtml

Detailed Description

Definition at line 11 of file nsMsgBodyHandler.h.


Constructor & Destructor Documentation

Definition at line 47 of file nsMsgBodyHandler.cpp.

{
  m_scope = scope;
  m_localFileOffset = offset;
  m_numLocalLines = numLines;
  m_msgHdr = msg;
  m_db = db;
  
  // the following are variables used when the body handler is handling stuff from filters....through this constructor, that is not the
  // case so we set them to NULL.
  m_headers = NULL;
  m_headersSize = 0;
  m_Filtering = PR_FALSE; // make sure we set this before we call initialize...
  
  Initialize();  // common initialization stuff
  OpenLocalFolder();     
}

Here is the call graph for this function:

nsMsgBodyHandler::nsMsgBodyHandler ( nsIMsgSearchScopeTerm scope,
PRUint32  offset,
PRUint32  length,
nsIMsgDBHdr msg,
nsIMsgDatabase db,
const char *  headers,
PRUint32  headersSize,
PRBool  ForFilters 
)

Definition at line 65 of file nsMsgBodyHandler.cpp.

{
  m_scope = scope;
  m_localFileOffset = offset;
  m_numLocalLines = numLines;
  m_msgHdr = msg;
  m_db = db;
  m_headersSize = headersSize;
  m_Filtering = Filtering;
  
  Initialize();
  
  if (m_Filtering)
    m_headers = headers;
  else
    OpenLocalFolder();  // if nothing else applies, then we must be a POP folder file
}

Here is the call graph for this function:

Definition at line 99 of file nsMsgBodyHandler.cpp.

{
}

Member Function Documentation

PRInt32 nsMsgBodyHandler::ApplyTransformations ( nsCString buf,
PRInt32  length,
PRBool returnThisLine 
) [protected]

Definition at line 199 of file nsMsgBodyHandler.cpp.

{
  PRInt32 newLength = length;
  eatThisLine = PR_FALSE;
  
  if (!m_passedHeaders)     // buf is a line from the message headers
  {
    if (m_stripHeaders)
      eatThisLine = PR_TRUE;
    
    if (StringBeginsWith(buf, NS_LITERAL_CSTRING("Content-Type:")) && FindInReadable(buf, NS_LITERAL_CSTRING("text/html")))
      m_messageIsHtml = PR_TRUE;
    
    m_passedHeaders = buf.IsEmpty() || buf.First() == nsCRT::CR || buf.First() == nsCRT::LF;
  }
  else // buf is a line from the message body
  {
    if (m_stripHtml && m_messageIsHtml)
    {
      StripHtml (buf);
      newLength = buf.Length();
    }
  }
  
  return newLength;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 141 of file nsMsgBodyHandler.cpp.

{
  // m_nextHdr always points to the next header in the list....the list is NULL terminated...
  PRUint32 numBytesCopied = 0;
  if (m_headersSize > 0)
  {
    // #mscott. Ugly hack! filter headers list have CRs & LFs inside the NULL delimited list of header
    // strings. It is possible to have: To NULL CR LF From. We want to skip over these CR/LFs if they start
    // at the beginning of what we think is another header.
    
    while (m_headersSize > 0 && (m_headers[0] == nsCRT::CR || m_headers[0] == nsCRT::LF || m_headers[0] == ' ' || m_headers[0] == '\0'))
    {
      m_headers++;  // skip over these chars...
      m_headersSize--;
    }
    
    if (m_headersSize > 0)
    {
      numBytesCopied = strlen(m_headers) + 1 ;
      buf.Assign(m_headers);
      m_headers += numBytesCopied;  
      // be careful...m_headersSize is unsigned. Don't let it go negative or we overflow to 2^32....*yikes*     
      if (m_headersSize < numBytesCopied)
        m_headersSize = 0;
      else
        m_headersSize -= numBytesCopied;  // update # bytes we have read from the headers list
      
      return (PRInt32) numBytesCopied;
    }
  }
  else if (m_headersSize == 0) {
    buf.Truncate();
  }
  return -1;
}

Here is the caller graph for this function:

Definition at line 103 of file nsMsgBodyHandler.cpp.

{
  PRInt32 length = 0;
  PRBool eatThisLine = PR_FALSE;
  
  do {
    // first, handle the filtering case...this is easy....
    if (m_Filtering)
      length = GetNextFilterLine(buf);
    else
    {
      // 3 cases: Offline IMAP, POP, or we are dealing with a news message....
      // Offline cases should be same as local mail cases, since we're going
      // to store offline messages in berkeley format folders.
      if (m_db)
      {
         length = GetNextLocalLine (buf); // (2) POP
      }
    }
    
    if (length >= 0)
      length = ApplyTransformations (buf, length, eatThisLine);
  } while (eatThisLine && length >= 0);  // if we hit eof, make sure we break out of this loop. Bug #:
  return length;  
}

Here is the call graph for this function:

Definition at line 179 of file nsMsgBodyHandler.cpp.

{
  if (m_numLocalLines)
  {
    if (m_passedHeaders)
      m_numLocalLines--; // the line count is only for body lines
    // do we need to check the return value here?
    if (m_fileLineStream)
    {
      PRBool more = PR_FALSE;
      nsresult rv = m_fileLineStream->ReadLine(buf, &more);
      if (NS_SUCCEEDED(rv))
        return buf.Length();
    }
  }
  
  return -1;
}

Here is the caller graph for this function:

Definition at line 87 of file nsMsgBodyHandler.cpp.

{
  // Default transformations for local message search and MAPI access
  m_stripHeaders = PR_TRUE;
  m_stripHtml = PR_TRUE;
  m_messageIsHtml = PR_FALSE;
  m_passedHeaders = PR_FALSE;
  m_headerBytesRead = 0;
  
}

Here is the caller graph for this function:

Definition at line 129 of file nsMsgBodyHandler.cpp.

{
  nsCOMPtr <nsIInputStream> inputStream;
  nsresult rv = m_scope->GetInputStream(getter_AddRefs(inputStream));
  if (NS_SUCCEEDED(rv))
  {
    nsCOMPtr <nsISeekableStream> seekableStream = do_QueryInterface(inputStream);
    seekableStream->Seek(PR_SEEK_SET, m_localFileOffset);
  }
  m_fileLineStream = do_QueryInterface(inputStream);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 36 of file nsMsgBodyHandler.h.

Here is the call graph for this function:

Definition at line 35 of file nsMsgBodyHandler.h.

Here is the call graph for this function:

void nsMsgBodyHandler::StripHtml ( nsCString buf) [protected]

Definition at line 226 of file nsMsgBodyHandler.cpp.

{
  char *pBuf = (char*) PR_Malloc (pBufInOut.Length() + 1);
  if (pBuf)
  {
    char *pWalk = pBuf;
    
    char *pWalkInOut = (char *) pBufInOut.get();
    PRBool inTag = PR_FALSE;
    while (*pWalkInOut) // throw away everything inside < >
    {
      if (!inTag)
        if (*pWalkInOut == '<')
          inTag = PR_TRUE;
        else
          *pWalk++ = *pWalkInOut;
        else
          if (*pWalkInOut == '>')
            inTag = PR_FALSE;
          pWalkInOut++;
    }
    *pWalk = 0; // null terminator
    
    pBufInOut.Adopt(pBuf);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 71 of file nsMsgBodyHandler.h.

Definition at line 57 of file nsMsgBodyHandler.h.

Definition at line 43 of file nsMsgBodyHandler.h.

Definition at line 48 of file nsMsgBodyHandler.h.

Definition at line 46 of file nsMsgBodyHandler.h.

Definition at line 47 of file nsMsgBodyHandler.h.

Definition at line 58 of file nsMsgBodyHandler.h.

Definition at line 64 of file nsMsgBodyHandler.h.

Definition at line 77 of file nsMsgBodyHandler.h.

Definition at line 70 of file nsMsgBodyHandler.h.

Definition at line 65 of file nsMsgBodyHandler.h.

Definition at line 76 of file nsMsgBodyHandler.h.

Definition at line 56 of file nsMsgBodyHandler.h.

Definition at line 74 of file nsMsgBodyHandler.h.

Definition at line 75 of file nsMsgBodyHandler.h.


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