Back to index

lightning-sunbird  0.9+nobinonly
nsMsgSearchTerm.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 
00039 #ifndef __nsMsgSearchTerm_h
00040 #define __nsMsgSearchTerm_h
00041 //---------------------------------------------------------------------------
00042 // nsMsgSearchTerm specifies one criterion, e.g. name contains phil
00043 //---------------------------------------------------------------------------
00044 #include "nsIMsgSearchSession.h"
00045 #include "nsIMsgSearchScopeTerm.h"
00046 #include "nsIMsgSearchTerm.h"
00047 
00048 // needed to search for addresses in address books
00049 #include "nsIAbMDBDirectory.h"
00050 
00051 #define EMPTY_MESSAGE_LINE(buf) (buf[0] == nsCRT::CR || buf[0] == nsCRT::LF || buf[0] == '\0')
00052 
00053 class nsMsgSearchTerm : public nsIMsgSearchTerm
00054 {
00055 public:
00056        nsMsgSearchTerm();
00057        nsMsgSearchTerm (nsMsgSearchAttribValue, nsMsgSearchOpValue, nsIMsgSearchValue *, nsMsgSearchBooleanOperator, const char * arbitraryHeader);
00058 
00059        virtual ~nsMsgSearchTerm ();
00060 
00061     NS_DECL_ISUPPORTS
00062     NS_DECL_NSIMSGSEARCHTERM
00063 
00064     
00065        PRInt32 GetNextIMAPOfflineMsgLine (char * buf, int bufferSize, int msgOffset, nsIMsgDBHdr * msg, nsIMsgDatabase * db);
00066 
00067 
00068     // nsresult MatchBody (nsIMsgSearchScopeTerm*, PRUint32 offset, PRUint32 length, const char *charset, 
00069     //                                    nsIMsgDBHdr * msg, nsIMsgDatabase * db, PRBool *pResult);
00070     // nsresult MatchArbitraryHeader (nsIMsgSearchScopeTerm *,
00071     //                                   PRUint32 offset,
00072     //                                   PRUint32 length,
00073     //                                   const char *charset,
00074     //                                   nsIMsgDBHdr * msg,
00075     //                                   nsIMsgDatabase *db,
00076     //                                   const char * headers, /* NULL terminated header list for msgs being filtered. Ignored unless ForFilters */
00077     //                                   PRUint32 headersSize, /* size of the NULL terminated list of headers */
00078     //                                   PRBool ForFilters /* true if we are filtering */,
00079     //                                                     PRBool *pResult);
00080        // nsresult MatchDate (PRTime, PRBool *result);
00081        // nsresult MatchStatus (PRUint32, PRBool *result);
00082        // nsresult MatchPriority (nsMsgPriorityValue, PRBool *result);
00083        // nsresult MatchSize (PRUint32, PRBool *result);
00084     // nsresult MatchRfc822String(const char *, const char *charset, PRBool *pResult);
00085        // nsresult MatchAge (PRTime, PRBool *result);
00086     
00087        nsresult DeStream (char *, PRInt16 length);
00088        nsresult DeStreamNew (char *, PRInt16 length);
00089 
00090        nsresult GetLocalTimes (PRTime, PRTime, PRExplodedTime &, PRExplodedTime &);
00091 
00092        PRBool IsBooleanOpAND() { return m_booleanOp == nsMsgSearchBooleanOp::BooleanAND ? PR_TRUE : PR_FALSE;}
00093        nsMsgSearchBooleanOperator GetBooleanOp() {return m_booleanOp;}
00094        // maybe should return nsString &   ??
00095        const char * GetArbitraryHeader() {return m_arbitraryHeader.get();}
00096 
00097        static char * EscapeQuotesInStr(const char *str);
00098 
00099        nsCOMPtr<nsIMsgHeaderParser> m_headerAddressParser;
00100 
00101        nsMsgSearchAttribValue m_attribute;
00102        nsMsgSearchOpValue m_operator;
00103        nsMsgSearchValue m_value;
00104        nsMsgSearchBooleanOperator m_booleanOp;  // boolean operator to be applied to this search term and the search term which precedes it.
00105        nsCString m_arbitraryHeader;         // user specified string for the name of the arbitrary header to be used in the search
00106                                                                  // only has a value when m_attribute = attribOtherHeader!!!!
00107         PRBool m_matchAll; // does this term match all headers?
00108 
00109 protected:
00110        nsresult MatchString (const char *stringToMatch, const char *charset,
00111                           PRBool *pResult);
00112        nsresult OutputValue(nsCString &outputStr);
00113        nsresult ParseAttribute(char *inStream, nsMsgSearchAttribValue *attrib);
00114        nsresult ParseOperator(char *inStream, nsMsgSearchOpValue *value);
00115        nsresult ParseValue(char *inStream);
00116        nsresult InitHeaderAddressParser();
00117     nsresult InitializeAddressBook();
00118     nsresult MatchInAddressBook(const char * aAddress, PRBool *pResult);
00119     // fields used by search in address book
00120     nsCOMPtr <nsIAbMDBDirectory> mDirectory;  
00121 
00122     PRPackedBool mBeginsGrouping;
00123     PRPackedBool mEndsGrouping; 
00124 };
00125 
00126 #endif