Back to index

lightning-sunbird  0.9+nobinonly
nsImapServerResponseParser.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; 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  *   Lorenzo Colitti <lorenzo@colitti.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef _nsIMAPServerResponseParser_H_
00040 #define _nsIMAPServerResponseParser_H_
00041 
00042 #include "nsImapCore.h"
00043 #include "nsIMAPHostSessionList.h"
00044 #include "nsImapSearchResults.h"
00045 #include "nsString.h"
00046 #include "nsMsgKeyArray.h"
00047 
00048 class nsIMAPNamespace;
00049 class nsIMAPNamespaceList;
00050 class nsIMAPBodyShell;
00051 class nsIMAPBodypart;
00052 class nsImapSearchResultIterator;
00053 class nsImapFlagAndUidState;
00054 class nsCString;
00055 
00056 #include "nsIMAPGenericParser.h"
00057 
00058 class nsImapServerResponseParser : public nsIMAPGenericParser 
00059 {
00060 public:
00061     nsImapServerResponseParser(nsImapProtocol &imapConnection);
00062     virtual ~nsImapServerResponseParser();
00063 
00064   // Overridden from the base parser class
00065   virtual PRBool     LastCommandSuccessful();
00066   virtual void              HandleMemoryFailure();
00067 
00068   // aignoreBadAndNOResponses --> don't throw a error dialog if this command results in a NO or Bad response
00069   // from the server..in other words the command is "exploratory" and we don't really care if it succeeds or fails.
00070   // This value is typically FALSE for almost all cases. 
00071   virtual void              ParseIMAPServerResponse(const char *currentCommand, PRBool aIgnoreBadAndNOResponses);
00072   virtual void              InitializeState();
00073   PRBool             CommandFailed();
00074     
00075     enum eIMAPstate {
00076         kNonAuthenticated,
00077         kAuthenticated,
00078         kFolderSelected
00079     } ;
00080 
00081   virtual eIMAPstate GetIMAPstate();
00082   virtual PRBool WaitingForMoreClientInput() { return fWaitingForMoreClientInput; };
00083     
00084   const char *GetSelectedMailboxName();   // can be NULL
00085 
00086   // if we get a PREAUTH greeting from the server, initialize the parser to begin in
00087   // the kAuthenticated state
00088   void        PreauthSetAuthenticatedState();
00089 
00090   // these functions represent the state of the currently selected
00091   // folder
00092   PRBool     CurrentFolderReadOnly();
00093   PRInt32    NumberOfMessages();
00094   PRInt32    NumberOfRecentMessages();
00095   PRInt32    NumberOfUnseenMessages();
00096   PRInt32    FolderUID();
00097   PRUint32   CurrentResponseUID();
00098   PRUint32   HighestRecordedUID();
00099   void       SetCurrentResponseUID(PRUint32 uid);
00100   PRBool     IsNumericString(const char *string);
00101   PRInt32    SizeOfMostRecentMessage();
00102   void       SetTotalDownloadSize(PRInt32 newSize) { fTotalDownloadSize = newSize; }
00103   void       SetFetchingEverythingRFC822(PRBool fetchingEverythingRFC822) { fFetchEverythingRFC822 = fetchingEverythingRFC822;}
00104   
00105   nsImapSearchResultIterator *CreateSearchResultIterator();
00106   void ResetSearchResultSequence() {fSearchResults->ResetSequence();}
00107   
00108   // create a struct mailbox_spec from our info, used in
00109   // libmsg c interface
00110   nsImapMailboxSpec *CreateCurrentMailboxSpec(const char *mailboxName = nsnull);
00111   
00112   // zero stops a list recording of flags and causes the flags for
00113   // each individual message to be sent back to libmsg 
00114   void ResetFlagInfo(int numberOfInterestingMessages);
00115   
00116   // set this to false if you don't want to alert the user to server 
00117   // error messages
00118   void SetReportingErrors(PRBool reportThem) { fReportingErrors=reportThem;}
00119   PRBool GetReportingErrors() { return fReportingErrors; }
00120 
00121   PRUint32 GetCapabilityFlag() { return fCapabilityFlag; }
00122   void   SetCapabilityFlag(PRUint32 capability) {fCapabilityFlag = capability;}
00123   PRBool ServerHasIMAP4Rev1Capability() { return ((fCapabilityFlag & kIMAP4rev1Capability) != 0); }
00124   PRBool ServerHasACLCapability() { return ((fCapabilityFlag & kACLCapability) != 0); }
00125   PRBool ServerHasNamespaceCapability() { return ((fCapabilityFlag & kNamespaceCapability) != 0); }
00126   PRBool ServerIsNetscape3xServer() { return fServerIsNetscape3xServer; }
00127   PRBool ServerHasServerInfo() {return ((fCapabilityFlag & kXServerInfoCapability) != 0); }
00128   PRBool ServerIsAOLServer() {return ((fCapabilityFlag & kAOLImapCapability) != 0); }
00129   void SetFetchingFlags(PRBool aFetchFlags) { fFetchingAllFlags = aFetchFlags;}
00130   void ResetCapabilityFlag() ;
00131 
00132   const char *GetMailAccountUrl() { return fMailAccountUrl; }
00133   const char *GetXSenderInfo() { return fXSenderInfo; }
00134   void FreeXSenderInfo() { PR_FREEIF(fXSenderInfo); }
00135   const char *GetManageListsUrl() { return fManageListsUrl; }
00136   const char *GetManageFiltersUrl() {return fManageFiltersUrl;}
00137   const char *GetManageFolderUrl() {return fFolderAdminUrl;}
00138 
00139 
00140   // Call this when adding a pipelined command to the session
00141   void IncrementNumberOfTaggedResponsesExpected(const char *newExpectedTag);
00142     
00143   // Interrupt a Fetch, without really Interrupting (through netlib)
00144   PRBool GetLastFetchChunkReceived(); 
00145   void ClearLastFetchChunkReceived(); 
00146   virtual PRUint16   SupportsUserFlags() { return fSupportsUserDefinedFlags; };
00147   virtual PRUint16  SettablePermanentFlags() { return fSettablePermanentFlags;};
00148   void SetFlagState(nsIImapFlagAndUidState *state);
00149   PRBool GetDownloadingHeaders();
00150   PRBool GetFillingInShell();
00151   void UseCachedShell(nsIMAPBodyShell *cachedShell);
00152   void SetHostSessionList(nsIImapHostSessionList *aHostSession);
00153   nsIImapHostSessionList *GetHostSessionList();
00154   char  *fAuthChallenge;    // the challenge returned by the server in
00155                             //response to authenticate using CRAM-MD5 or NTLM
00156 
00157 protected:
00158   virtual void    flags();
00159   virtual void         envelope_data();
00160   virtual void         xaolenvelope_data();
00161   virtual void         parse_address(nsCAutoString &addressLine);
00162   virtual void         internal_date();
00163   virtual nsresult BeginMessageDownload(const char *content_type);
00164 
00165   virtual void    response_data();
00166   virtual void    resp_text();
00167   virtual void    resp_cond_state();
00168   virtual void    text_mime2();
00169   virtual void    text();
00170   virtual void    parse_folder_flags();
00171   virtual void    language_data();
00172   virtual void    authChallengeResponse_data();
00173   virtual void    resp_text_code();
00174   virtual void    response_done();
00175   virtual void    response_tagged();
00176   virtual void    response_fatal();
00177   virtual void    resp_cond_bye();
00178   virtual void    mailbox_data();
00179   virtual void    numeric_mailbox_data();
00180   virtual void    capability_data();
00181   virtual void         xserverinfo_data();
00182   virtual void         xmailboxinfo_data();
00183   virtual void         namespace_data();
00184   virtual void         myrights_data();
00185   virtual void         acl_data();
00186   virtual void         bodystructure_data();
00187   nsIMAPBodypart  *bodystructure_part(char *partNum, nsIMAPBodypart *parentPart);
00188   nsIMAPBodypart  *bodystructure_leaf(char *partNum, nsIMAPBodypart *parentPart);
00189   nsIMAPBodypart  *bodystructure_multipart(char *partNum, nsIMAPBodypart *parentPart);
00190   virtual void         mime_data();
00191   virtual void         mime_part_data();
00192   virtual void         mime_header_data();
00193   virtual void    quota_data();
00194   virtual void    msg_fetch();
00195   virtual void    msg_obsolete();
00196   virtual void         msg_fetch_headers(const char *partNum);
00197   virtual void    msg_fetch_content(PRBool chunk, PRInt32 origin, const char *content_type);
00198   virtual PRBool  msg_fetch_quoted(PRBool chunk, PRInt32 origin);
00199   virtual PRBool  msg_fetch_literal(PRBool chunk, PRInt32 origin);
00200   virtual void    mailbox_list(PRBool discoveredFromLsub);
00201   virtual void    mailbox(nsImapMailboxSpec *boxSpec);
00202   
00203   virtual void    ProcessOkCommand(const char *commandToken);
00204   virtual void    ProcessBadCommand(const char *commandToken);
00205   virtual void    PreProcessCommandToken(const char *commandToken,
00206                                              const char *currentCommand);
00207   virtual void    PostProcessEndOfLine();
00208 
00209   // Overridden from the nsIMAPGenericParser, to retrieve the next line
00210   // from the open socket.
00211   virtual PRBool  GetNextLineForParser(char **nextLine);
00212   // overriden to do logging
00213   virtual void    SetSyntaxError(PRBool error, const char *msg = nsnull);
00214 
00215 private:
00216   PRPackedBool    fProcessingTaggedResponse;
00217   PRPackedBool    fCurrentCommandFailed;
00218   PRPackedBool    fReportingErrors;
00219   
00220   
00221   PRPackedBool    fCurrentFolderReadOnly;
00222   PRPackedBool    fCurrentLineContainedFlagInfo;
00223   PRPackedBool    fFetchingAllFlags;
00224   PRPackedBool    fWaitingForMoreClientInput;
00225   // when issuing a fetch command, are we fetching everything or just a part?
00226   PRPackedBool    fFetchEverythingRFC822;
00227   // Is the server a Netscape 3.x Messaging Server?
00228   PRPackedBool         fServerIsNetscape3xServer;
00229   PRPackedBool    fDownloadingHeaders;
00230   PRPackedBool    fCurrentCommandIsSingleMessageFetch;
00231   PRPackedBool    fGotPermanentFlags;
00232   imapMessageFlagsType        fSavedFlagInfo;
00233   nsCStringArray  fCustomFlags;
00234 
00235   PRUint16  fSupportsUserDefinedFlags;
00236   PRUint16  fSettablePermanentFlags;
00237 
00238   PRInt32           fFolderUIDValidity;
00239   PRInt32           fNumberOfUnseenMessages;
00240   PRInt32           fNumberOfExistingMessages;
00241   PRInt32           fNumberOfRecentMessages;
00242   PRUint32          fCurrentResponseUID;
00243   PRUint32          fHighestRecordedUID;
00244   // used to handle server that sends msg size after headers
00245   PRUint32          fReceivedHeaderOrSizeForUID;
00246   PRInt32           fSizeOfMostRecentMessage;
00247   PRInt32           fTotalDownloadSize;
00248   
00249   PRInt32           fStatusUnseenMessages;
00250   PRInt32           fStatusRecentMessages;
00251   PRUint32          fStatusNextUID;
00252   PRUint32          fStatusExistingMessages;
00253 
00254   int               fNumberOfTaggedResponsesExpected;
00255 
00256   char              *fCurrentCommandTag;
00257 
00258   nsCString         fZeroLengthMessageUidString;
00259 
00260   char              *fSelectedMailboxName;
00261 
00262   nsImapSearchResultSequence    *fSearchResults;
00263 
00264   nsCOMPtr <nsIImapFlagAndUidState> fFlagState;         // NOT owned by us, it's a copy, do not destroy
00265 
00266   eIMAPstate               fIMAPstate;
00267 
00268   PRUint32      fCapabilityFlag; 
00269   char          *fMailAccountUrl;
00270   char          *fNetscapeServerVersionString;
00271   char          *fXSenderInfo; /* changed per message download */
00272   char          *fLastAlert;       /* used to avoid displaying the same alert over and over */
00273   char          *fManageListsUrl;
00274   char          *fManageFiltersUrl;
00275   char          *fFolderAdminUrl;
00276   
00277   PRInt32     fUidOfSingleMessageFetch;
00278   PRInt32     fFetchResponseIndex;
00279 
00280   // used for aborting a fetch stream when we're pseudo-Interrupted
00281   PRInt32 numberOfCharsInThisChunk;
00282   PRInt32 charsReadSoFar;
00283   PRBool fLastChunk;
00284 
00285   // points to the current body shell, if any
00286   nsIMAPBodyShell         *m_shell;
00287 
00288   // The connection object
00289   nsImapProtocol &fServerConnection;
00290 
00291   nsIImapHostSessionList *fHostSessionList;
00292   nsMsgKeyArray fCopyResponseKeyArray;
00293 };
00294 
00295 #endif