Back to index

lightning-sunbird  0.9+nobinonly
nsLocalMailFolder.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) 1998
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  
00040    Interface for representing Local Mail folders.
00041  
00042 *********************************************************************************************************/
00043 
00044 #ifndef nsMsgLocalMailFolder_h__
00045 #define nsMsgLocalMailFolder_h__
00046 
00047 #include "nsMsgDBFolder.h" /* include the interface we are going to support */
00048 #include "nsFileSpec.h"
00049 #include "nsAutoPtr.h"
00050 #include "nsICopyMessageListener.h"
00051 #include "nsFileStream.h"
00052 #include "nsIFileStreams.h"
00053 #include "nsIPop3IncomingServer.h"  // need this for an interface ID
00054 #include "nsMsgTxn.h"
00055 #include "nsIMsgMessageService.h"
00056 #include "nsIMsgParseMailMsgState.h"
00057 #include "nsITransactionManager.h"
00058 #include "nsIMsgLocalMailFolder.h"
00059 #include "nsIMsgStringService.h"
00060 #include "nsIMsgFilterPlugin.h"
00061 #define COPY_BUFFER_SIZE 16384
00062 
00063 struct nsLocalMailCopyState
00064 {
00065   nsLocalMailCopyState();
00066   virtual ~nsLocalMailCopyState();
00067   
00068   nsOutputFileStream * m_fileStream;
00069   nsCOMPtr<nsISupports> m_srcSupport;
00070   nsCOMPtr<nsISupportsArray> m_messages;
00071   nsRefPtr<nsMsgTxn> m_undoMsgTxn;
00072   nsCOMPtr<nsIMsgDBHdr> m_message; // current copy message
00073   nsCOMPtr<nsIMsgParseMailMsgState> m_parseMsgState;
00074   nsCOMPtr<nsIMsgCopyServiceListener> m_listener;
00075   nsCOMPtr<nsIMsgWindow> m_msgWindow;
00076   nsCOMPtr<nsIMsgDatabase> m_destDB;
00077 
00078   // for displaying status;
00079   nsCOMPtr <nsIMsgStatusFeedback> m_statusFeedback;
00080   nsCOMPtr <nsIStringBundle> m_stringBundle;
00081   PRInt64 m_lastProgressTime;
00082 
00083   nsMsgKey m_curDstKey;
00084   PRUint32 m_curCopyIndex;
00085   nsCOMPtr <nsIMsgMessageService> m_messageService;
00086   PRUint32 m_totalMsgCount;
00087   char *m_dataBuffer;
00088   PRUint32 m_dataBufferSize;
00089   PRUint32 m_leftOver;
00090   PRPackedBool m_isMove;
00091   PRPackedBool m_isFolder;   // isFolder move/copy
00092   PRPackedBool m_dummyEnvelopeNeeded;
00093   PRPackedBool m_copyingMultipleMessages;
00094   PRPackedBool m_fromLineSeen;
00095   PRPackedBool m_allowUndo;
00096   PRPackedBool m_writeFailed;
00097   PRPackedBool m_notifyFolderLoaded;
00098 };
00099 
00100 struct nsLocalFolderScanState
00101 {
00102   nsLocalFolderScanState();
00103   ~nsLocalFolderScanState();
00104 
00105   nsFileSpec *m_fileSpec;
00106   nsCOMPtr<nsILocalFile> m_localFile;
00107   nsCOMPtr<nsIFileInputStream> m_fileStream;
00108   nsCOMPtr<nsIInputStream> m_inputStream;
00109   nsCOMPtr<nsISeekableStream> m_seekableStream;
00110   nsCOMPtr<nsILineInputStream> m_fileLineStream;
00111   nsCString m_header;
00112   nsCString m_accountKey;
00113   const char *m_uidl;       // memory is owned by m_header
00114 };
00115 
00116 class nsMsgLocalMailFolder : public nsMsgDBFolder,
00117                              public nsIMsgLocalMailFolder,
00118                              public nsICopyMessageListener,
00119                              public nsIJunkMailClassificationListener
00120 {
00121 public:
00122   nsMsgLocalMailFolder(void);
00123   virtual ~nsMsgLocalMailFolder(void);
00124   NS_DECL_NSICOPYMESSAGELISTENER
00125   NS_DECL_NSIMSGLOCALMAILFOLDER
00126   NS_DECL_NSIJUNKMAILCLASSIFICATIONLISTENER
00127   NS_DECL_ISUPPORTS_INHERITED
00128   // nsIRDFResource methods:
00129   NS_IMETHOD Init(const char *aURI);
00130   
00131   // nsICollection methods:
00132   NS_IMETHOD Enumerate(nsIEnumerator* *result);
00133 
00134   // nsIUrlListener methods
00135   NS_IMETHOD OnStartRunningUrl(nsIURI * aUrl);
00136   NS_IMETHOD OnStopRunningUrl(nsIURI * aUrl, nsresult aExitCode);
00137 
00138   // nsIMsgFolder methods:
00139   NS_IMETHOD GetSubFolders(nsIEnumerator* *result);
00140   NS_IMETHOD GetMsgDatabase(nsIMsgWindow *aMsgWindow,
00141                               nsIMsgDatabase** aMsgDatabase);
00142 
00143   NS_IMETHOD OnAnnouncerGoingAway(nsIDBChangeAnnouncer *instigator);
00144   NS_IMETHOD GetMessages(nsIMsgWindow *aMsgWindow, nsISimpleEnumerator* *result);
00145   NS_IMETHOD UpdateFolder(nsIMsgWindow *aWindow);
00146 
00147   NS_IMETHOD CreateSubfolder(const PRUnichar *folderName ,nsIMsgWindow *msgWindow);
00148   NS_IMETHOD AddSubfolder(const nsAString& folderName, nsIMsgFolder** newFolder);
00149 
00150   NS_IMETHOD Compact(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow);
00151   NS_IMETHOD CompactAll(nsIUrlListener *aListener, nsIMsgWindow *aMsgWindow, nsISupportsArray *aFolderArray, PRBool aCompactOfflineAlso, nsISupportsArray *aOfflineFolderArray);
00152   NS_IMETHOD EmptyTrash(nsIMsgWindow *msgWindow, nsIUrlListener *aListener);
00153   NS_IMETHOD Delete ();
00154   NS_IMETHOD DeleteSubFolders(nsISupportsArray *folders, nsIMsgWindow *msgWindow);
00155   NS_IMETHOD CreateStorageIfMissing(nsIUrlListener* urlListener);
00156   NS_IMETHOD Rename (const PRUnichar *aNewName, nsIMsgWindow *msgWindow);
00157   NS_IMETHOD RenameSubFolders (nsIMsgWindow *msgWindow, nsIMsgFolder *oldFolder);
00158 
00159   NS_IMETHOD GetPrettyName(PRUnichar** prettyName);     // Override of the base, for top-level mail folder
00160   NS_IMETHOD SetPrettyName(const PRUnichar *aName);
00161 
00162   NS_IMETHOD GetFolderURL(char **url);
00163 
00164   NS_IMETHOD UpdateSummaryTotals(PRBool force) ;
00165 
00166   NS_IMETHOD  GetManyHeadersToDownload(PRBool *retval);
00167 
00168   NS_IMETHOD GetDeletable (PRBool *deletable); 
00169   NS_IMETHOD GetRequiresCleanup(PRBool *requiresCleanup);
00170   NS_IMETHOD GetSizeOnDisk(PRUint32* size);
00171 
00172   NS_IMETHOD  GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, nsIMsgDatabase **db);
00173 
00174   NS_IMETHOD DeleteMessages(nsISupportsArray *messages, 
00175                       nsIMsgWindow *msgWindow, PRBool
00176                       deleteStorage, PRBool isMove,
00177                       nsIMsgCopyServiceListener* listener, PRBool allowUndo);
00178   NS_IMETHOD CopyMessages(nsIMsgFolder *srcFolder, nsISupportsArray* messages,
00179                           PRBool isMove, nsIMsgWindow *msgWindow,
00180                           nsIMsgCopyServiceListener* listener, PRBool isFolder, PRBool allowUndo);
00181   NS_IMETHOD CopyFolder(nsIMsgFolder *srcFolder, PRBool isMoveFolder, nsIMsgWindow *msgWindow,
00182                           nsIMsgCopyServiceListener* listener);
00183   NS_IMETHOD CopyFileMessage(nsIFileSpec* fileSpec, nsIMsgDBHdr* msgToReplace,
00184                              PRBool isDraftOrTemplate, 
00185                              PRUint32 newMsgFlags,
00186                              nsIMsgWindow *msgWindow,
00187                              nsIMsgCopyServiceListener* listener);
00188   NS_IMETHOD GetNewMessages(nsIMsgWindow *aWindow, nsIUrlListener *aListener);
00189   NS_IMETHOD NotifyCompactCompleted();
00190   NS_IMETHOD Shutdown(PRBool shutdownChildren);
00191 
00192   NS_IMETHOD WriteToFolderCacheElem(nsIMsgFolderCacheElement *element);
00193   NS_IMETHOD ReadFromFolderCacheElem(nsIMsgFolderCacheElement *element);
00194 
00195   NS_IMETHOD GetName(PRUnichar **aName);
00196 
00197   // Used when headers_only is TRUE
00198   NS_IMETHOD DownloadMessagesForOffline(nsISupportsArray *aMessages, nsIMsgWindow *aWindow);
00199   NS_IMETHOD FetchMsgPreviewText(nsMsgKey *aKeysToFetch, PRUint32 aNumKeys,
00200                                                  PRBool aLocalOnly, nsIUrlListener *aUrlListener, 
00201                                                  PRBool *aAsyncResults);
00202   NS_IMETHOD AddKeywordsToMessages(nsISupportsArray *aMessages, const char *aKeywords);
00203   NS_IMETHOD RemoveKeywordsFromMessages(nsISupportsArray *aMessages, const char *aKeywords);
00204 
00205 protected:
00206   nsresult CopyFolderAcrossServer(nsIMsgFolder *srcFolder, nsIMsgWindow *msgWindow,nsIMsgCopyServiceListener* listener);
00207 
00208   nsresult CreateSubFolders(nsFileSpec &path);
00209   nsresult GetTrashFolder(nsIMsgFolder** trashFolder);
00210   nsresult WriteStartOfNewMessage();
00211   nsresult IsChildOfTrash(PRBool *result);
00212   nsresult RecursiveSetDeleteIsMoveTrash(PRBool bVal);
00213   nsresult ConfirmFolderDeletion(nsIMsgWindow *aMsgWindow, PRBool *aResult);
00214 
00215   nsresult DeleteMessage(nsISupports *message, nsIMsgWindow *msgWindow,
00216                    PRBool deleteStorage, PRBool commit);
00217   nsresult GetDatabase(nsIMsgWindow *msgWindow);
00218 
00219   // copy message helper
00220   nsresult DisplayMoveCopyStatusMsg();
00221   nsresult SortMessagesBasedOnKey(nsISupportsArray *messages, nsMsgKeyArray *aKeyArray, nsIMsgFolder *srcFolder);
00222 
00223   nsresult CopyMessageTo(nsISupports *message, nsIMsgFolder *dstFolder,
00224                          nsIMsgWindow *msgWindow, PRBool isMove);
00225 
00226   // copy multiple messages at a time from this folder
00227   nsresult CopyMessagesTo(nsISupportsArray *messages, nsIMsgWindow *aMsgWindow,
00228                                        nsIMsgFolder *dstFolder,
00229                                        PRBool isMove);
00230   virtual const char* GetIncomingServerType();
00231   nsresult InitCopyState(nsISupports* aSupport, nsISupportsArray* messages,
00232                          PRBool isMove, nsIMsgCopyServiceListener* listener, nsIMsgWindow *msgWindow, PRBool isMoveFolder, PRBool allowUndo);
00233   void CopyPropertiesToMsgHdr(nsIMsgDBHdr *destHdr, nsIMsgDBHdr *srcHdr);
00234   virtual nsresult CreateBaseMessageURI(const char *aURI);
00235   virtual nsresult SpamFilterClassifyMessage(const char *aURI, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin);
00236   virtual nsresult SpamFilterClassifyMessages(const char **aURIArray, PRUint32 aURICount, nsIMsgWindow *aMsgWindow, nsIJunkMailPlugin *aJunkMailPlugin);
00237   nsresult ChangeKeywordForMessages(nsISupportsArray *aMessages, const char *aKeyword, PRBool add);
00238   PRBool GetDeleteFromServerOnMove();
00239 
00240 protected:
00241   nsLocalMailCopyState *mCopyState; //We only allow one of these at a time
00242   const char *mType;
00243   PRPackedBool mHaveReadNameFromDB;
00244   PRPackedBool mInitialized;
00245   PRPackedBool mCheckForNewMessagesAfterParsing;
00246   PRPackedBool m_parsingFolder;
00247   nsCOMPtr<nsIMsgStringService> mMsgStringService;
00248   nsCOMPtr<nsIUrlListener> mReparseListener;
00249   PRInt32 mNumFilterClassifyRequests;
00250   nsMsgKeyArray mSpamKeysToMove;
00251   nsCString mSpamFolderURI;
00252   nsresult setSubfolderFlag(const PRUnichar *aFolderName, PRUint32 flags);
00253 
00254 
00255   // state variables for DownloadMessagesForOffline
00256 
00257   // Do we notify the owning window of Delete's before or after
00258   // Adding the new msg?
00259 #define DOWNLOAD_NOTIFY_FIRST 1
00260 #define DOWNLOAD_NOTIFY_LAST  2
00261 
00262 #ifndef DOWNLOAD_NOTIFY_STYLE
00263 #define DOWNLOAD_NOTIFY_STYLE      DOWNLOAD_NOTIFY_FIRST
00264 #endif
00265 
00266   nsCOMPtr<nsISupportsArray> mDownloadMessages;
00267   nsCOMPtr<nsIMsgWindow> mDownloadWindow;
00268   nsMsgKey mDownloadSelectKey;
00269   PRUint32 mDownloadState;
00270 #define DOWNLOAD_STATE_NONE 0
00271 #define DOWNLOAD_STATE_INITED      1
00272 #define DOWNLOAD_STATE_GOTMSG      2
00273 #define DOWNLOAD_STATE_DIDSEL      3
00274 
00275 #if DOWNLOAD_NOTIFY_STYLE == DOWNLOAD_NOTIFY_LAST
00276   nsMsgKey mDownloadOldKey;
00277   nsMsgKey mDownloadOldParent;
00278   PRUint32 mDownloadOldFlags;
00279 #endif
00280 };
00281 
00282 #endif // nsMsgLocalMailFolder_h__