Back to index

lightning-sunbird  0.9+nobinonly
nsMailboxProtocol.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) 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 #ifndef nsMailboxProtocol_h___
00039 #define nsMailboxProtocol_h___
00040 
00041 #include "nsMsgProtocol.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsIFileSpec.h"
00044 #include "nsIChannel.h"
00045 #include "nsIOutputStream.h"
00046 #include "nsIMailboxUrl.h"
00047 // State Flags (Note, I use the word state in terms of storing 
00048 // state information about the connection (authentication, have we sent
00049 // commands, etc. I do not intend it to refer to protocol state)
00050 
00051 #define MAILBOX_PAUSE_FOR_READ                   0x00000001  /* should we pause for the next read */
00052 #define MAILBOX_MSG_PARSE_FIRST_LINE    0x00000002 /* have we read in the first line of the msg */
00053 
00054 /* states of the machine
00055  */
00056 typedef enum _MailboxStatesEnum {
00057        MAILBOX_READ_FOLDER,
00058        MAILBOX_FINISH_OPEN_FOLDER,
00059        MAILBOX_OPEN_MESSAGE,
00060        MAILBOX_OPEN_STREAM,
00061        MAILBOX_READ_MESSAGE,
00062        MAILBOX_COMPRESS_FOLDER,
00063        MAILBOX_FINISH_COMPRESS_FOLDER,
00064        MAILBOX_BACKGROUND,
00065        MAILBOX_NULL,
00066        MAILBOX_NULL2,
00067        MAILBOX_DELIVER_QUEUED,
00068        MAILBOX_FINISH_DELIVER_QUEUED,
00069        MAILBOX_DONE,
00070        MAILBOX_ERROR_DONE,
00071        MAILBOX_FREE,
00072        MAILBOX_COPY_MESSAGES,
00073        MAILBOX_FINISH_COPY_MESSAGES
00074 } MailboxStatesEnum;
00075 
00076 class nsMsgLineStreamBuffer;
00077 
00078 class nsMailboxProtocol : public nsMsgProtocol
00079 {
00080 public:
00081        // Creating a protocol instance requires the URL which needs to be run AND it requires
00082        // a transport layer. 
00083        nsMailboxProtocol(nsIURI * aURL);
00084        virtual ~nsMailboxProtocol();
00085 
00086   // initialization function given a new url and transport layer
00087        nsresult Initialize(nsIURI * aURL);
00088 
00089        // the consumer of the url might be something like an nsIDocShell....
00090        virtual nsresult LoadUrl(nsIURI * aURL, nsISupports * aConsumer);
00091 
00093        // we suppport the nsIStreamListener interface 
00095 
00096        NS_IMETHOD OnStartRequest(nsIRequest *request, nsISupports *ctxt);
00097        NS_IMETHOD OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus);
00098   NS_IMETHOD GetContentLength(PRInt32 * aContentLength);
00099 
00100 private:
00101        nsCOMPtr<nsIMailboxUrl>     m_runningUrl; // the nsIMailboxURL that is currently running
00102        nsMailboxAction m_mailboxAction; // current mailbox action associated with this connnection...
00103        PRInt32                     m_originalContentLength; /* the content length at the time of calling graph progress */
00104 
00105        // Event sink handles
00106        nsCOMPtr<nsIStreamListener> m_mailboxParser;
00107 
00108        // Local state for the current operation
00109        nsMsgLineStreamBuffer   * m_lineStreamBuffer; // used to efficiently extract lines from the incoming data stream
00110 
00111        // Generic state information -- What state are we in? What state do we want to go to
00112        // after the next response? What was the last response code? etc. 
00113        MailboxStatesEnum  m_nextState;
00114   MailboxStatesEnum  m_initialState;
00115   
00116   PRInt32 mCurrentProgress;
00117        PRUint32      m_messageID;
00118 
00119        nsCOMPtr<nsIFileSpec> m_tempMessageFile;
00120 
00121   // this is used to hold the source mailbox file open when move/copying
00122   // multiple messages.
00123   nsCOMPtr<nsIInputStream> m_multipleMsgMoveCopyStream;
00124 
00125        virtual nsresult ProcessProtocolState(nsIURI * url, nsIInputStream * inputStream, 
00126                                                                      PRUint32 sourceOffset, PRUint32 length);
00127        virtual nsresult CloseSocket();
00128 
00129        PRInt32 SetupMessageExtraction();
00130   nsresult OpenMultipleMsgTransport(PRUint32 offset, PRInt32 size);
00131   nsresult OpenFileSocketForReuse(nsIURI * aURL, PRUint32 aStartPosition, PRInt32 aReadCount);
00132   PRBool RunningMultipleMsgUrl();
00133 
00135        // Protocol Methods --> This protocol is state driven so each protocol method is 
00136        //                                        designed to re-act to the current "state". I've attempted to 
00137        //                                        group them together based on functionality. 
00139 
00140        // When parsing a mailbox folder in chunks, this protocol state reads in the current chunk
00141        // and forwards it to the mailbox parser. 
00142        PRInt32 ReadFolderResponse(nsIInputStream * inputStream, PRUint32 sourceOffset, PRUint32 length);
00143        PRInt32 ReadMessageResponse(nsIInputStream * inputStream, PRUint32 sourceOffset, PRUint32 length);
00144        PRInt32 DoneReadingMessage();
00145 
00147        // End of Protocol Methods
00149 };
00150 
00151 #endif  // nsMailboxProtocol_h___
00152 
00153 
00154 
00155 
00156 
00157