Back to index

lightning-sunbird  0.9+nobinonly
nsMsgFolderCompactor.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 _nsMsgFolderCompactor_h
00039 #define _nsMsgFolderCompactor_h
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsXPIDLString.h"
00043 #include "nsIMsgFolder.h"    
00044 #include "nsIStreamListener.h"
00045 #include "nsIMsgFolderCompactor.h"
00046 #include "nsICopyMsgStreamListener.h"
00047 #include "nsIMsgWindow.h"
00048 #include "nsIStringBundle.h"
00049 #include "nsIMsgMessageService.h"
00050 
00051 #define COMPACTOR_READ_BUFF_SIZE 16384
00052 
00053 class nsFolderCompactState : public nsIMsgFolderCompactor, public nsIStreamListener, public nsICopyMessageStreamListener, public nsIUrlListener
00054 {
00055 public:
00056   NS_DECL_ISUPPORTS
00057   NS_DECL_NSIREQUESTOBSERVER
00058   NS_DECL_NSISTREAMLISTENER
00059   NS_DECL_NSICOPYMESSAGESTREAMLISTENER
00060   NS_DECL_NSIURLLISTENER
00061   NS_DECL_NSIMSGFOLDERCOMPACTOR
00062 
00063   nsFolderCompactState(void);
00064   virtual ~nsFolderCompactState(void);
00065 //  virtual nsresult Init(nsIMsgFolder *folder, const char *baseMsgUri, nsIMsgDatabase *db,
00066 //                           nsIFileSpec *pathSpec);
00067   // virtual nsresult FinishCompact();
00068 protected:
00069   virtual nsresult InitDB(nsIMsgDatabase *db);
00070   virtual nsresult StartCompacting();
00071   virtual nsresult FinishCompact();
00072   void CloseOutputStream();
00073   void  CleanupTempFilesAfterError();
00074 
00075   nsresult Init(nsIMsgFolder *aFolder, const char* aBaseMsgUri, nsIMsgDatabase *aDb,
00076                             nsIFileSpec *aPathSpec, nsIMsgWindow *aMsgWindow);
00077   nsresult GetMessage(nsIMsgDBHdr **message);
00078   nsresult BuildMessageURI(const char *baseURI, PRUint32 key, nsCString& uri);  
00079   nsresult ShowStatusMsg(const PRUnichar *aMsg);
00080   nsresult ReleaseFolderLock();
00081   void     ShowCompactingStatusMsg();
00082   void     ShowDoneStatus();
00083   nsresult CompactNextFolder();
00084   void     AdvanceToNextLine(const char *buffer, PRUint32 &bufferOffset, PRUint32 maxBufferOffset);
00085   
00086 
00087   nsCString m_baseMessageUri; // base message uri
00088   nsCString m_messageUri; // current message uri being copy
00089   nsCOMPtr<nsIMsgFolder> m_folder; // current folder being compact
00090   nsCOMPtr<nsIMsgDatabase> m_db; // new database for the compact folder
00091   nsFileSpec m_fileSpec; // new mailbox for the compact folder
00092   nsOutputFileStream *m_fileStream; // output file stream for writing
00093   nsMsgKeyArray m_keyArray; // all message keys need to be copied over
00094   PRInt32 m_size; // size of the message key array
00095   PRInt32 m_curIndex; // index of the current copied message key in key array
00096   nsMsgKey m_startOfNewMsg; // offset in mailbox of new message
00097   char m_dataBuffer[COMPACTOR_READ_BUFF_SIZE + 1]; // temp data buffer for copying message
00098   nsresult m_status; // the status of the copying operation
00099   nsCOMPtr <nsIMsgMessageService> m_messageService; // message service for copying 
00100   nsCOMPtr<nsISupportsArray> m_folderArray; // to store all the folders in case of compact all
00101   nsCOMPtr <nsIMsgWindow> m_window;
00102   nsCOMPtr <nsIMsgDBHdr> m_curSrcHdr;
00103   PRUint32 m_folderIndex; // tells which folder to compact in case of compact all
00104   PRBool m_compactAll;  //flag for compact all
00105   PRBool m_compactOfflineAlso; //whether to compact offline also
00106   PRBool m_compactingOfflineFolders; // are we in the offline folder compact phase
00107   PRBool m_parsingFolder; //flag for parsing local folders;
00108   // these members are used to add missing status lines to compacted messages.
00109   PRBool m_needStatusLine;
00110   PRBool m_startOfMsg;
00111   PRInt32 m_statusOffset;
00112   PRInt32 m_addedHeaderSize;
00113   nsCOMPtr <nsISupportsArray> m_offlineFolderArray;
00114 
00115 };
00116 
00117 class nsOfflineStoreCompactState : public nsFolderCompactState
00118 {
00119 public:
00120 
00121   nsOfflineStoreCompactState(void);
00122   virtual ~nsOfflineStoreCompactState(void);
00123   NS_IMETHOD OnStopRequest(nsIRequest *request, nsISupports *ctxt,
00124                                     nsresult status);
00125 
00126 protected:
00127     virtual nsresult InitDB(nsIMsgDatabase *db);
00128     virtual nsresult StartCompacting();
00129     virtual nsresult FinishCompact();
00130 
00131 };
00132 
00133 
00134 
00135 #endif