Back to index

lightning-sunbird  0.9+nobinonly
nsMsgBodyHandler.h
Go to the documentation of this file.
00001 
00002 #ifndef __nsMsgBodyHandler_h
00003 #define __nsMsgBodyHandler_h
00004 
00005 #include "nsIMsgSearchScopeTerm.h"
00006 #include "nsILineInputStream.h"
00007 //---------------------------------------------------------------------------
00008 // nsMsgBodyHandler: used to retrive lines from POP and IMAP offline messages.
00009 // This is a helper class used by nsMsgSearchTerm::MatchBody
00010 //---------------------------------------------------------------------------
00011 class nsMsgBodyHandler
00012 {
00013 public:
00014   nsMsgBodyHandler (nsIMsgSearchScopeTerm *,
00015     PRUint32 offset,
00016     PRUint32 length,
00017     nsIMsgDBHdr * msg,
00018     nsIMsgDatabase * db);
00019   
00020   // we can also create a body handler when doing arbitrary header
00021   // filtering...we need the list of headers and the header size as well
00022   // if we are doing filtering...if ForFilters is false, headers and
00023   // headersSize is ignored!!!
00024   nsMsgBodyHandler (nsIMsgSearchScopeTerm *, PRUint32 offset,
00025     PRUint32 length, nsIMsgDBHdr * msg, nsIMsgDatabase * db,
00026     const char * headers /* NULL terminated list of headers */,
00027     PRUint32 headersSize, PRBool ForFilters);
00028   
00029   virtual ~nsMsgBodyHandler();
00030   
00031   // returns next message line in buf
00032   PRInt32 GetNextLine(nsCString &buf);    
00033   
00034   // Transformations
00035   void SetStripHtml (PRBool strip) { m_stripHtml = strip; }
00036   void SetStripHeaders (PRBool strip) { m_stripHeaders = strip; }
00037   
00038 protected:
00039   void Initialize();  // common initialization code
00040   
00041   // filter related methods. For filtering we always use the headers
00042   // list instead of the database...
00043   PRBool m_Filtering;
00044   PRInt32 GetNextFilterLine(nsCString &buf);
00045   // pointer into the headers list in the original message hdr db...
00046   const char * m_headers;  
00047   PRUint32 m_headersSize;
00048   PRUint32 m_headerBytesRead;
00049   
00050   // local / POP related methods
00051   void OpenLocalFolder();
00052   
00053   // goes through the mail folder 
00054   PRInt32 GetNextLocalLine(nsCString &buf); 
00055 
00056   nsIMsgSearchScopeTerm *m_scope;
00057   nsCOMPtr <nsILineInputStream> m_fileLineStream;
00058   nsCOMPtr <nsILocalFile> m_localFile;
00059   // local file state
00060   //   XP_File       *m_localFile;
00061   // need a file stream here, I bet
00062   
00063   // current offset into the mail folder file.
00064   PRInt32 m_localFileOffset;       
00065   PRUint32 m_numLocalLines;
00066   
00067   // Offline IMAP related methods & state
00068   
00069   
00070   nsIMsgDBHdr * m_msgHdr;
00071   nsIMsgDatabase * m_db;
00072   
00073   // Transformations
00074   PRBool m_stripHeaders;    // PR_TRUE if we're supposed to strip of message headers
00075   PRBool m_stripHtml;              // PR_TRUE if we're supposed to strip off HTML tags
00076   PRBool m_passedHeaders;   // PR_TRUE if we've already skipped over the headers
00077   PRBool m_messageIsHtml;   // PR_TRUE if the Content-type header claims text/html
00078   PRInt32 ApplyTransformations (nsCString &buf, PRInt32 length, PRBool &returnThisLine);
00079   void StripHtml (nsCString &buf);
00080 };
00081 #endif