Back to index

lightning-sunbird  0.9+nobinonly
nsMsgDBFolder.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 nsMsgDBFolder_h__
00039 #define nsMsgDBFolder_h__
00040 
00041 #include "msgCore.h"
00042 #include "nsIMsgFolder.h" 
00043 #include "nsRDFResource.h"
00044 #include "nsIDBFolderInfo.h"
00045 #include "nsIMsgDatabase.h"
00046 #include "nsIMsgIncomingServer.h"
00047 #include "nsCOMPtr.h"
00048 #include "nsStaticAtom.h"
00049 #include "nsIDBChangeListener.h"
00050 #include "nsIURL.h"
00051 #include "nsWeakReference.h"
00052 #include "nsIMsgFilterList.h"
00053 #include "nsIUrlListener.h"
00054 #include "nsIFileSpec.h"
00055 #include "nsIMsgHdr.h"
00056 #include "nsIOutputStream.h"
00057 #include "nsITransport.h"
00058 #include "nsIMsgStringService.h"
00059 class nsIMsgFolderCacheElement;
00060 class nsIJunkMailPlugin;
00061 class nsICollation;
00062 
00063  /* 
00064   * nsMsgDBFolder
00065   * class derived from nsMsgFolder for those folders that use an nsIMsgDatabase
00066   */ 
00067 
00068 #undef IMETHOD_VISIBILITY
00069 #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
00070 
00071 class NS_MSG_BASE nsMsgDBFolder: public nsRDFResource,
00072                                  public nsSupportsWeakReference,
00073                                  public nsIMsgFolder,
00074                                  public nsIDBChangeListener,
00075                                  public nsIUrlListener
00076 {
00077 public: 
00078   nsMsgDBFolder(void);
00079   virtual ~nsMsgDBFolder(void);
00080   NS_DECL_ISUPPORTS_INHERITED
00081   NS_DECL_NSIMSGFOLDER
00082   NS_DECL_NSICOLLECTION
00083   NS_DECL_NSISERIALIZABLE
00084   NS_DECL_NSIDBCHANGELISTENER
00085   NS_DECL_NSIURLLISTENER
00086   
00087   NS_IMETHOD WriteToFolderCacheElem(nsIMsgFolderCacheElement *element);
00088   NS_IMETHOD ReadFromFolderCacheElem(nsIMsgFolderCacheElement *element);
00089 
00090   // nsRDFResource overrides
00091   NS_IMETHOD Init(const char* aURI);
00092 
00093   // These functions are used for tricking the front end into thinking that we have more 
00094   // messages than are really in the DB.  This is usually after and IMAP message copy where
00095   // we don't want to do an expensive select until the user actually opens that folder
00096   // These functions are called when MSG_Master::GetFolderLineById is populating a MSG_FolderLine
00097   // struct used by the FE
00098   PRInt32 GetNumPendingUnread();
00099   PRInt32 GetNumPendingTotalMessages();
00100 
00101   void ChangeNumPendingUnread(PRInt32 delta);
00102   void ChangeNumPendingTotalMessages(PRInt32 delta);
00103 
00104   NS_IMETHOD MatchName(nsString *name, PRBool *matches);
00105 
00106   nsresult CreateDirectoryForFolder(nsFileSpec &path);
00107   nsresult GetMsgPreviewTextFromStream(nsIMsgDBHdr *msgHdr, nsIInputStream *stream);
00108 protected:
00109   
00110   // this is a little helper function that is not part of the public interface. 
00111   // we use it to get the IID of the incoming server for the derived folder.
00112   // w/out a function like this we would have to implement GetServer in each
00113   // derived folder class.
00114   virtual const char* GetIncomingServerType() = 0;
00115 
00116   virtual nsresult CreateBaseMessageURI(const char *aURI);
00117 
00118   nsresult convertMsgSnippetToPlainText(nsAString& aMessageText);
00119   void compressQuotesInMsgSnippet(const nsString& aMessageText, nsAString& aCompressedQuotesStr);
00120   void decodeMsgSnippet(const nsACString& aEncodingType, PRBool aIsComplete, nsCString& aMsgSnippet);
00121 
00122   // helper routine to parse the URI and update member variables
00123   nsresult parseURI(PRBool needServer=PR_FALSE);
00124   nsresult GetBaseStringBundle(nsIStringBundle **aBundle);
00125   nsresult GetStringFromBundle(const char* msgName, PRUnichar **aResult);
00126   nsresult ThrowConfirmationPrompt(nsIMsgWindow *msgWindow, const PRUnichar *confirmString, PRBool *confirmed);
00127   nsresult GetWarnFilterChanged(PRBool *aVal);
00128   nsresult SetWarnFilterChanged(PRBool aVal);
00129   nsresult CreateCollationKey(const nsString &aSource,  PRUint8 **aKey, PRUint32 *aLength);
00130 
00131   nsresult ListFoldersWithFlag(PRUint32 flag, nsISupportsArray *array);
00132 
00133 protected:
00134   virtual nsresult ReadDBFolderInfo(PRBool force);
00135   virtual nsresult FlushToFolderCache();
00136   virtual nsresult GetDatabase(nsIMsgWindow *aMsgWindow) = 0;
00137   virtual nsresult SendFlagNotifications(nsIMsgDBHdr *item, PRUint32 oldFlags, PRUint32 newFlags);
00138   nsresult CheckWithNewMessagesStatus(PRBool messageAdded);
00139   void     UpdateNewMessages();
00140   nsresult OnHdrAddedOrDeleted(nsIMsgDBHdr *hdrChanged, PRBool added);
00141   nsresult CreateFileSpecForDB(const char *userLeafName, nsFileSpec &baseDir, nsIFileSpec **dbFileSpec);
00142 
00143   nsresult GetFolderCacheKey(nsIFileSpec **aFileSpec, PRBool createDBIfMissing = PR_FALSE);
00144   nsresult GetFolderCacheElemFromFileSpec(nsIFileSpec *fileSpec, nsIMsgFolderCacheElement **cacheElement);
00145   nsresult AddDirectorySeparator(nsFileSpec &path);
00146   nsresult CheckIfFolderExists(const PRUnichar *newFolderName, nsIMsgFolder *parentFolder, nsIMsgWindow *msgWindow);
00147 
00148 
00149   nsresult PromptForCachePassword(nsIMsgIncomingServer *server, nsIMsgWindow *aWindow, PRBool &passwordCorrect);
00150   // offline support methods.
00151   nsresult StartNewOfflineMessage();
00152   nsresult WriteStartOfNewLocalMessage();
00153   nsresult EndNewOfflineMessage();
00154   nsresult CompactOfflineStore(nsIMsgWindow *inWindow);
00155   nsresult AutoCompact(nsIMsgWindow *aWindow);
00156   // this is a helper routine that ignores whether MSG_FLAG_OFFLINE is set for the folder
00157   nsresult MsgFitsDownloadCriteria(nsMsgKey msgKey, PRBool *result);
00158   nsresult GetPromptPurgeThreshold(PRBool *aPrompt);
00159   nsresult GetPurgeThreshold(PRInt32 *aThreshold);
00160   nsresult ApplyRetentionSettings(PRBool deleteViaFolder);
00161 
00162   nsresult PerformBiffNotifications(void); // if there are new, non spam messages, do biff
00163   nsresult CloseDBIfFolderNotOpen();
00164 
00165   virtual nsresult SpamFilterClassifyMessage(const char *aURI, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin);
00166   virtual nsresult SpamFilterClassifyMessages(const char **aURIArray, PRUint32 aURICount, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin);
00167 
00168   void    SetMRUTime();
00169 protected:
00170   nsCOMPtr<nsIMsgDatabase> mDatabase;
00171   nsCString mCharset;
00172   PRBool mCharsetOverride;
00173   PRBool mAddListener;
00174   PRBool mNewMessages;
00175   PRBool mGettingNewMessages;
00176   nsMsgKey mLastMessageLoaded;
00177 
00178   nsCOMPtr <nsIMsgDBHdr> m_offlineHeader;
00179   PRInt32 m_numOfflineMsgLines;
00180        // this is currently used when we do a save as of an imap or news message..
00181   nsCOMPtr<nsIOutputStream> m_tempMessageStream;
00182 
00183   nsCOMPtr <nsIMsgRetentionSettings> m_retentionSettings;
00184   nsCOMPtr <nsIMsgDownloadSettings> m_downloadSettings;
00185   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) mFolderLoadedAtom;
00186   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) mDeleteOrMoveMsgCompletedAtom;
00187   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) mDeleteOrMoveMsgFailedAtom;
00188   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) mJunkStatusChangedAtom;
00189   static NS_MSG_BASE_STATIC_MEMBER_(nsrefcnt) mInstanceCount;
00190 
00191 protected:
00192   PRUint32 mFlags;
00193   nsWeakPtr mParent;     //This won't be refcounted for ownership reasons.
00194   PRInt32 mNumUnreadMessages;        /* count of unread messages (-1 means
00195                                          unknown; -2 means unknown but we already
00196                                          tried to find out.) */
00197   PRInt32 mNumTotalMessages;         /* count of existing messages. */
00198   PRBool mNotifyCountChanges;
00199   PRUint32 mExpungedBytes;
00200   nsCOMPtr<nsISupportsArray> mSubFolders;
00201   nsVoidArray mListeners; //This can't be an nsISupportsArray because due to
00202                           //ownership issues, listeners can't be AddRef'd
00203 
00204   PRBool mInitializedFromCache;
00205   nsISupports *mSemaphoreHolder; // set when the folder is being written to
00206                                                         //Due to ownership issues, this won't be AddRef'd.
00207 
00208   nsWeakPtr mServer;
00209 
00210   // These values are used for tricking the front end into thinking that we have more 
00211   // messages than are really in the DB.  This is usually after and IMAP message copy where
00212   // we don't want to do an expensive select until the user actually opens that folder
00213   PRInt32 mNumPendingUnreadMessages;
00214   PRInt32 mNumPendingTotalMessages;
00215   PRUint32 mFolderSize;
00216 
00217   PRInt32 mNumNewBiffMessages;
00218   PRBool mIsCachable;
00219 
00220   // these are previous set of new msgs, which we might
00221   // want to run junk controls on. This is in addition to "new" hdrs
00222   // in the db, which might get cleared because the user clicked away
00223   // from the folder.
00224   nsMsgKeyArray m_saveNewMsgs;
00225 
00226   // These are the set of new messages for a folder who has had
00227   // its db closed, without the user reading the folder. This 
00228   // happens with pop3 mail filtered to a different local folder.
00229   nsMsgKeyArray m_newMsgs;
00230 
00231   //
00232   // stuff from the uri
00233   //
00234   PRBool mHaveParsedURI;        // is the URI completely parsed?
00235   PRBool mIsServerIsValid;
00236   PRBool mIsServer;
00237   nsString mName;
00238   nsCOMPtr<nsIFileSpec> mPath;
00239   char * mBaseMessageURI; //The uri with the message scheme
00240 
00241   PRBool mInVFEditSearchScope ; // non persistant state used by the virtual folder UI
00242 
00243   // static stuff for cross-instance objects like atoms
00244   static NS_MSG_BASE_STATIC_MEMBER_(nsrefcnt) gInstanceCount;
00245 
00246   static nsresult initializeStrings();
00247   static nsresult createCollationKeyGenerator();
00248 
00249   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedInboxName;
00250   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedTrashName;
00251   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedSentName;
00252   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedDraftsName;
00253   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedTemplatesName;
00254   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedUnsentName;
00255   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedJunkName;
00256   static NS_MSG_BASE_STATIC_MEMBER_(PRUnichar*) kLocalizedBrandShortName;
00257   
00258   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kTotalUnreadMessagesAtom;
00259   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kBiffStateAtom;
00260   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kNewMessagesAtom;
00261   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kInVFEditSearchScopeAtom;
00262   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kNumNewBiffMessagesAtom;
00263   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kTotalMessagesAtom;
00264   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kFolderSizeAtom;
00265   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kStatusAtom;
00266   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kFlaggedAtom;
00267   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kNameAtom;
00268   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kSynchronizeAtom;
00269   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kOpenAtom;
00270   static NS_MSG_BASE_STATIC_MEMBER_(nsIAtom*) kIsDeferred;
00271   static NS_MSG_BASE_STATIC_MEMBER_(nsICollation*) gCollationKeyGenerator;
00272 
00273 #ifdef MSG_FASTER_URI_PARSING
00274   // cached parsing URL object
00275   static NS_MSG_BASE_STATIC_MEMBER_(nsCOMPtr<nsIURL>) mParsingURL;
00276   static NS_MSG_BASE_STATIC_MEMBER_(PRBool) mParsingURLInUse;
00277 #endif
00278 
00279   static const NS_MSG_BASE_STATIC_MEMBER_(nsStaticAtom) folder_atoms[];
00280 };
00281 
00282 #undef  IMETHOD_VISIBILITY
00283 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
00284 
00285 #endif