email/imap4mtm/imapsession/inc/cimapfetchbody.h
changeset 0 72b543305e3a
child 26 ebe688cedc25
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CIMAPFETCHBODY_H__
       
    17 #define __CIMAPFETCHBODY_H__
       
    18 
       
    19 #include <e32std.h>
       
    20 
       
    21 #include "cimapcommand.h"
       
    22 #include "cimapmailstore.h"
       
    23 #include "tmessageflaginfo.h"
       
    24 
       
    25 //forward declaration
       
    26 class CImapSession;
       
    27 class CImapSettings;
       
    28 class CImapMimeHeaderFieldsParser;
       
    29 class CFetchBodyInfo;
       
    30 class CImapFetchBodyResponse;
       
    31 
       
    32 /**
       
    33 @internalTechnology
       
    34 @prototype
       
    35 */
       
    36 class CImapFetchBody : public CImapCommand, public MMailStoreObserver, public MChunkOutOfOrderObserver
       
    37 	{
       
    38 private:
       
    39 	enum TState
       
    40 		{		
       
    41 		/**
       
    42 		Looking for the next data item(s), in the current line.
       
    43 		This state can transition to EStateBodyStructureLiteral or EStateHeaderFieldsLiteral if 
       
    44 		either of these data items are found, or EStateComplete if no data items are found.
       
    45 		*/
       
    46 		EStateDataItemLine,
       
    47 		/**
       
    48 		Waiting for a literal that will be delivered to the body  parser.
       
    49 		*/
       
    50 		EStateBodyLiteral,
       
    51 		/**
       
    52 		Processing the data for BODY[x.MIME]
       
    53 		*/
       
    54 		EStateMime,
       
    55 		/**
       
    56 		This state occurs after EStateHeaderFieldsLiteral.  It means that a data item line
       
    57 		is expected, but it has yet to be fetched from the input stream.
       
    58 		This differs to EStateDataItemLine, which means that the current block of data
       
    59 		still has data items in it.
       
    60 		*/
       
    61 		EStateFetchNextDataItemLine,
       
    62 		/**
       
    63 		Either all data has been parsed, or the data was not recognised.
       
    64 		*/
       
    65 		EStateComplete,
       
    66 		};
       
    67 
       
    68 public:
       
    69 	// Construction and Destruction
       
    70 	static CImapFetchBody* NewL(CImapFolderInfo* aSelectedFolderData, TInt aLogId, TUint aMessageUid, TBool aPeek, CFetchBodyInfo& aFetchBodyInfo, CImapFetchBodyResponse& aFetchBodyResponse, CImapSettings& aImapSettings, CImapMailStore& aImapMailStore, CImapSession& aParent);
       
    71 	~CImapFetchBody();
       
    72 
       
    73 	// Overrides CImapCommand
       
    74 	void Cancel();
       
    75 
       
    76 	// Fetch Body specific
       
    77 	TBool IsStoreOperationComplete();
       
    78 	
       
    79 	// Overrides CImapCommand::SendDataCnfL
       
    80 	virtual void SendDataCnfL();
       
    81 	
       
    82 private:
       
    83 	CImapFetchBody(CImapFolderInfo* aSelectedFolderData, TInt aLogId, TUint aMessageUid, TBool aPeek, CFetchBodyInfo& aFetchBodyInfo, CImapFetchBodyResponse& aFetchBodyResponse, CImapSettings& aImapSettings, CImapMailStore& aImapMailStore, CImapSession& aParent);
       
    84 	void ConstructL();
       
    85 	
       
    86 	// Implements CImapCommand
       
    87 	void SendMessageL(TInt aTagId, MOutputStream& aStream);
       
    88 	CImapCommand::TParseBlockResult DoParseBlockL(const TDesC8& aData);
       
    89 	TInt NumberOfTaggedResponsesExpected() const;
       
    90 
       
    91 	// from MMailStoreObserver
       
    92 	void StoreOperationComplete(TMsvId aId,TInt aErrorCode);
       
    93 
       
    94 	// from MChunkOutOfOrderObserver.		
       
    95 	void  EnableSendFetch();
       
    96 	
       
    97 	void SendMessageL();
       
    98 	TInt CalculateChunk(TInt aPos);
       
    99 	TInt TotalRequestsRequired(TInt aSize);
       
   100 	
       
   101 	TParseBlockResult ProcessStartL();
       
   102 	TParseBlockResult ProcessDataItemsL();
       
   103 	void ProcessStartOfMimeL();
       
   104 	void ProcessRestOfMimeL(const TDesC8& aData);
       
   105 
       
   106 	TBool GetAndStoreNextPart();
       
   107 	void ProcessBodyL();
       
   108 	void ProcessFlagsL();
       
   109 	void ProcessUidL();
       
   110 	void ProcessBodyLiteralL(const TDesC8& aData);
       
   111 	void WriteMimeHeadersToCafL();
       
   112 	void StoreBodyDataL(TInt aExtraFetchRequest);
       
   113 
       
   114 private:
       
   115 	//the uid of the message on the server - used for SEND operations
       
   116 	TUint iMessageUid;
       
   117 	//whether we want to peek, controls the /seen flag
       
   118 	TBool iPeek;
       
   119 	//the size of the data we want to retrieve
       
   120 	TInt32 iSizeToFetch;	
       
   121 	//the total number of requests we need to issue to receive all of the data
       
   122 	TInt iTotalRequests;
       
   123 	//running count of requests that have been issued
       
   124 	TInt iRequestCount;
       
   125 	//the chunk where the data currently being parsed will be stored
       
   126 	TInt iCurrentChunk;
       
   127 	//the output stream used to send the commands
       
   128 	MOutputStream* iOutStream;
       
   129 	//the size of the literal being stored
       
   130 	TInt iLiteralSize;
       
   131 	//the maximum fetch size
       
   132 	TUint iMaxFetchSize;
       
   133 	//the number of commands that may be pipelined
       
   134 	TUint iMaxOutstandingRequests;
       
   135 	//gloabal settings information
       
   136 	CImapSettings& iImapSettings;
       
   137 	//info about this specific fetch
       
   138 	CFetchBodyInfo& iFetchBodyInfo;
       
   139 	//the gloabl mailstore object
       
   140 	CImapMailStore& iImapMailStore;
       
   141 	//the parent session
       
   142 	CImapSession& iParent;
       
   143 	//if the store operation is complete
       
   144 	TBool iStoreComplete;
       
   145 	// Mime header fields parser for BODY[x.MIME] response
       
   146 	CImapMimeHeaderFieldsParser* iHeaderFieldsParser;
       
   147 	/**
       
   148 	Whether the UID data item was found in the untagged response.
       
   149 	If the UID data item was NOT found then the response is an unsolicited FETCH response caused
       
   150 	by a server event (e.g. a user deleting some messages from some other client such as a PC),
       
   151 	rather than a direct response to our UID FETCH command - which would have included the UID DATA item.
       
   152 	
       
   153 	Non-UID FETCH responses should not be returned as the result of a FetchBody request.
       
   154 	*/
       
   155 	TBool iUidDataItemFoundInResponse;
       
   156 	/**
       
   157 	Stores the result of parsing the FLAGS data item and the UID data item.
       
   158 	If both UID and FLAGS data items are included in the response, then the data in this
       
   159 	object will be copied to the equivalent object in iFetchBodyResponse.
       
   160 	If only the FLAGS data item included in the response, then this is an unsolicited FETCH response
       
   161 	and the data is discarded (so as not to corrupt the data in iFetchBodyResponse)
       
   162 	*/
       
   163 	TMessageFlagInfo iMessageFlagInfo;
       
   164 	// Stores fetch body response data
       
   165 	CImapFetchBodyResponse& iFetchBodyResponse;
       
   166 	// part thats being parsed
       
   167 	TPtrC8 iCurrentPart;
       
   168 	//used to track the state of the response parsing
       
   169 	TState iState;
       
   170 	// Stores current body data
       
   171 	HBufC8* iBuf;
       
   172 	// Indicates that we have received the MIME headers
       
   173 	TBool iReceivedMimeHeaders;
       
   174 	// When pipelining this is the amount of commands that are pipelined.
       
   175 	TInt iOutstandingRequests;
       
   176 	// Keeps track of the fetch responses received.
       
   177 	TInt iResponseCount;
       
   178 	// to keep track of all tags we expect to receive.
       
   179 	RArray<TInt>iTagIds;
       
   180 	// Indicates whether to send FETCH command to server.Sending FETCH command 
       
   181 	// to server may be disabled if server sends out of order chunks.
       
   182 	TBool iSendFetch;
       
   183 	// When server responses with no body length, iUnexpectedFormat is set to ETrue.
       
   184 	TBool iUnexpectedFormat;
       
   185 	};
       
   186 
       
   187 #endif // __CIMAPFETCHBODY_H__