Back to index

lightning-sunbird  0.9+nobinonly
nsMsgSearchAdapter.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 #ifndef _nsMsgSearchAdapter_H_
00039 #define _nsMsgSearchAdapter_H_
00040 
00041 #include "nsMsgSearchCore.h"
00042 
00043 #include "nsIMsgSearchAdapter.h"
00044 #include "nsIMsgSearchValidityTable.h"
00045 #include "nsIMsgSearchValidityManager.h"
00046 #include "nsIMsgSearchTerm.h"
00047 #include "nsMsgSearchArray.h"
00048 #include "nsINntpIncomingServer.h"
00049 
00050 class nsIMsgSearchScopeTerm;
00051 
00052 //-----------------------------------------------------------------------------
00053 // These Adapter classes contain the smarts to convert search criteria from 
00054 // the canonical structures in msg_srch.h into whatever format is required
00055 // by their protocol. 
00056 //
00057 // There is a separate Adapter class for area (pop, imap, nntp, ldap) to contain
00058 // the special smarts for that protocol.
00059 //-----------------------------------------------------------------------------
00060 
00061 inline PRBool IsStringAttribute (nsMsgSearchAttribValue a)
00062 {
00063        return ! (a == nsMsgSearchAttrib::Priority || a == nsMsgSearchAttrib::Date || 
00064               a == nsMsgSearchAttrib::MsgStatus || a == nsMsgSearchAttrib::MessageKey ||
00065               a == nsMsgSearchAttrib::Size || a == nsMsgSearchAttrib::AgeInDays ||
00066     a == nsMsgSearchAttrib::FolderInfo || a == nsMsgSearchAttrib::JunkStatus);
00067 }
00068 
00069 class nsMsgSearchAdapter : public nsIMsgSearchAdapter
00070 {
00071 public:
00072   nsMsgSearchAdapter (nsIMsgSearchScopeTerm*, nsISupportsArray *);
00073   virtual ~nsMsgSearchAdapter ();
00074 
00075   NS_DECL_ISUPPORTS
00076   NS_DECL_NSIMSGSEARCHADAPTER
00077 
00078   nsIMsgSearchScopeTerm           *m_scope;
00079   nsCOMPtr<nsISupportsArray>  m_searchTerms;       /* linked list of criteria terms */
00080 
00081   PRBool m_abortCalled;
00082   nsXPIDLString  m_defaultCharset;
00083   PRBool m_forceAsciiSearch;
00084 
00085   static nsresult EncodeImap (char **ppEncoding, 
00086                           nsISupportsArray *searchTerms,  
00087                           const PRUnichar *srcCharset, 
00088                           const PRUnichar *destCharset,
00089                           PRBool reallyDredd = PR_FALSE);
00090        
00091   static nsresult EncodeImapValue(char *encoding, const char *value, PRBool useQuotes, PRBool reallyDredd);
00092 
00093   static char *GetImapCharsetParam(const PRUnichar *destCharset);
00094   static PRUnichar *EscapeSearchUrl (const PRUnichar *nntpCommand);
00095   static PRUnichar *EscapeImapSearchProtocol(const PRUnichar *imapCommand);
00096   static PRUnichar *EscapeQuoteImapSearchProtocol(const PRUnichar *imapCommand);
00097   static char *UnEscapeSearchUrl (const char *commandSpecificData);
00098   // This stuff lives in the base class because the IMAP search syntax 
00099   // is used by the Dredd SEARCH command as well as IMAP itself
00100   static const char *m_kImapBefore;
00101   static const char *m_kImapBody;
00102   static const char *m_kImapCC;
00103   static const char *m_kImapFrom;
00104   static const char *m_kImapNot;
00105   static const char *m_kImapOr;
00106   static const char *m_kImapSince;
00107   static const char *m_kImapSubject;
00108   static const char *m_kImapTo;
00109   static const char *m_kImapHeader;
00110   static const char *m_kImapAnyText;
00111   static const char *m_kImapKeyword;
00112   static const char *m_kNntpKeywords;
00113   static const char *m_kImapSentOn;
00114   static const char *m_kImapSeen;
00115   static const char *m_kImapAnswered;
00116   static const char *m_kImapNotSeen;
00117   static const char *m_kImapNotAnswered;
00118   static const char *m_kImapCharset;
00119   static const char *m_kImapUnDeleted;
00120   static const char *m_kImapSizeSmaller;
00121   static const char *m_kImapSizeLarger;
00122   static const char *m_kImapNew;
00123   static const char *m_kImapNotNew;
00124   static const char *m_kImapFlagged;
00125   static const char *m_kImapNotFlagged;
00126 protected:
00127   typedef enum _msg_TransformType
00128   {
00129          kOverwrite,    /* "John Doe" -> "John*Doe",   simple contains   */
00130          kInsert,       /* "John Doe" -> "John* Doe",  name completion   */
00131          kSurround      /* "John Doe" -> "John* *Doe", advanced contains */
00132   } msg_TransformType;
00133 
00134   char *TransformSpacesToStars (const char *, msg_TransformType transformType);
00135   nsresult OpenNewsResultInUnknownGroup (nsMsgResultElement*);
00136 
00137   static nsresult EncodeImapTerm (nsIMsgSearchTerm *, PRBool reallyDredd, const PRUnichar *srcCharset, const PRUnichar *destCharset, char **ppOutTerm);
00138 };
00139 
00140 //-----------------------------------------------------------------------------
00141 // Validity checking for attrib/op pairs. We need to know what operations are
00142 // legal in three places:
00143 //   1. when the FE brings up the dialog box and needs to know how to build
00144 //      the menus and enable their items
00145 //   2. when the FE fires off a search, we need to check their lists for
00146 //      correctness
00147 //   3. for on-the-fly capability negotion e.g. with XSEARCH-capable news 
00148 //      servers
00149 //-----------------------------------------------------------------------------
00150 
00151 class nsMsgSearchValidityTable : public nsIMsgSearchValidityTable
00152 {
00153 public:
00154   nsMsgSearchValidityTable ();
00155   NS_DECL_NSIMSGSEARCHVALIDITYTABLE
00156   NS_DECL_ISUPPORTS
00157                                                           
00158 protected:
00159   int m_numAvailAttribs;        // number of rows with at least one available operator
00160   typedef struct vtBits
00161   {
00162          PRUint16 bitEnabled : 1;
00163          PRUint16 bitAvailable : 1;
00164          PRUint16 bitValidButNotShown : 1;
00165   } vtBits;
00166   vtBits m_table [nsMsgSearchAttrib::kNumMsgSearchAttributes][nsMsgSearchOp::kNumMsgSearchOperators];
00167 private:    
00168   nsMsgSearchAttribValue m_defaultAttrib;
00169 };
00170 
00171 // Using getters and setters seems a little nicer then dumping the 2-D array
00172 // syntax all over the code
00173 inline nsresult nsMsgSearchValidityTable::SetAvailable (int a, int o, PRBool b)
00174 { m_table [a][o].bitAvailable = b; return NS_OK;}
00175 inline nsresult nsMsgSearchValidityTable::SetEnabled (int a, int o, PRBool b)
00176 { m_table [a][o].bitEnabled = b; return NS_OK; }
00177 inline nsresult nsMsgSearchValidityTable::SetValidButNotShown (int a, int o, PRBool b)
00178 { m_table [a][o].bitValidButNotShown = b; return NS_OK;}
00179 
00180 inline nsresult nsMsgSearchValidityTable::GetAvailable (int a, int o, PRBool *aResult)
00181 { *aResult = m_table [a][o].bitAvailable; return NS_OK;}
00182 inline nsresult nsMsgSearchValidityTable::GetEnabled (int a, int o, PRBool *aResult)
00183 {  *aResult = m_table [a][o].bitEnabled; return NS_OK;}
00184 inline nsresult nsMsgSearchValidityTable::GetValidButNotShown (int a, int o, PRBool *aResult)
00185 {  *aResult = m_table [a][o].bitValidButNotShown; return NS_OK;}
00186 
00187 class nsMsgSearchValidityManager : public nsIMsgSearchValidityManager
00188 {
00189 public:
00190   nsMsgSearchValidityManager ();
00191   
00192 protected:
00193   virtual ~nsMsgSearchValidityManager ();
00194 
00195 public:
00196   NS_DECL_NSIMSGSEARCHVALIDITYMANAGER
00197   NS_DECL_ISUPPORTS
00198   
00199   nsresult GetTable (int, nsMsgSearchValidityTable**);
00200   
00201 #ifdef DOING_EXNEWSSEARCH
00202   nsresult PostProcessValidityTable (nsINntpIncomingServer *);
00203 #endif
00204 
00205 protected:
00206 
00207   // There's one global validity manager that everyone uses. You *could* do 
00208   // this with static members of the adapter classes, but having a dedicated
00209   // object makes cleanup of these tables (at shutdown-time) automagic.
00210 
00211   nsCOMPtr<nsIMsgSearchValidityTable> m_offlineMailTable;
00212   nsCOMPtr<nsIMsgSearchValidityTable> m_offlineMailFilterTable;
00213   nsCOMPtr<nsIMsgSearchValidityTable> m_onlineMailTable;
00214   nsCOMPtr<nsIMsgSearchValidityTable> m_onlineMailFilterTable;
00215 
00216   nsCOMPtr<nsIMsgSearchValidityTable> m_newsTable;
00217 #ifdef DOING_EXNEWSSEARCH
00218   nsCOMPtr<nsIMsgSearchValidityTable> m_newsExTable;
00219 #endif
00220   nsCOMPtr<nsIMsgSearchValidityTable> m_localNewsTable; // used for local news searching or offline news searching...
00221   nsCOMPtr<nsIMsgSearchValidityTable> m_ldapTable;
00222   nsCOMPtr<nsIMsgSearchValidityTable> m_ldapAndTable;
00223   nsCOMPtr<nsIMsgSearchValidityTable> m_localABTable;
00224   nsCOMPtr<nsIMsgSearchValidityTable> m_localABAndTable;
00225   nsCOMPtr<nsIMsgSearchValidityTable> m_newsFilterTable;
00226 
00227   nsresult NewTable (nsIMsgSearchValidityTable **);
00228 
00229   nsresult InitOfflineMailTable();
00230   nsresult InitOfflineMailFilterTable();
00231   nsresult InitOnlineMailTable();
00232   nsresult InitOnlineMailFilterTable();
00233   nsresult InitNewsTable();
00234   nsresult InitLocalNewsTable(); 
00235   nsresult InitNewsFilterTable();
00236 
00237 #ifdef DOING_EXNEWSSEARCH
00238   nsresult InitNewsExTable(nsINntpIncomingServer *host = nsnull);
00239 #endif
00240   //set the custom headers in the table, changes whenever "mailnews.customHeaders" pref changes.
00241   nsresult SetOtherHeadersInTable(nsIMsgSearchValidityTable *table, const char *customHeaders); 
00242 
00243   nsresult InitLdapTable();
00244   nsresult InitLdapAndTable();
00245   nsresult InitLocalABTable();
00246   nsresult InitLocalABAndTable();
00247   nsresult SetUpABTable(nsIMsgSearchValidityTable *aTable, PRBool isOrTable);
00248   nsresult EnableDirectoryAttribute(nsIMsgSearchValidityTable *table, nsMsgSearchAttribValue aSearchAttrib);
00249 };
00250 
00251 #endif