email/pop3andsmtpmtm/imapservermtm/inc/IMAPSESS.H
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     1 // Copyright (c) 1998-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 // CImImap4Session header
       
    15 // 
       
    16 //
       
    17 
       
    18 #if !defined(__IMAPSESS_H__)
       
    19 #define __IMAPSESS_H__
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32cons.h>
       
    23 #include <mentact.h>
       
    24 #include <msvstd.h>
       
    25 #include <miuthdr.h>
       
    26 #include <imcvcodc.h>
       
    27 #include <imcvsend.h>
       
    28 #include "impsmtm.h"
       
    29 #include <miutatch.h>
       
    30 #include <cimcaf.h>
       
    31 
       
    32 #include "imapio.h"
       
    33 #include "fldindex.h"
       
    34 
       
    35 // Forward declarations
       
    36 class CMsvBodyText;
       
    37 class CRichText;
       
    38 class CParaFormatLayer;
       
    39 class CCharFormatLayer;
       
    40 class CImQPDecode;
       
    41 class CImImap4Settings;
       
    42 class CImImap4Synchronise;
       
    43 class CImImap4FolderSync;
       
    44 class CImCalculateMsgSize;
       
    45 class CImSendConvert;
       
    46 class CImConvertCharconv;
       
    47 class CCnvCharacterSetConverter;
       
    48 class CImConvertHeader;
       
    49 class CImapCancelTimer;
       
    50 class MImapSessionObserver;
       
    51 
       
    52 // States of ImapSession
       
    53 /**
       
    54 @internalComponent
       
    55 @released
       
    56 */
       
    57 enum TImapState
       
    58 	{
       
    59 	EImapStateDisconnected=0,
       
    60 
       
    61 	EImapStateConnectWait,
       
    62 	EImapStateGreetingWait,
       
    63 	EImapStateCapabilityWait,
       
    64 	EImapStateLoginSendUser,
       
    65 	EImapStateLoginSendPassword, // 5
       
    66 	EImapStateLoginWait,
       
    67 	EImapStateNoSelect,
       
    68 	EImapStateSelectWait,
       
    69 	EImapStateSelected,
       
    70 	EImapStateCreateWait,		// 10
       
    71 	EImapStateDeleteWait,
       
    72 	EImapStateDeleteAllWait,
       
    73 	EImapStateDeleteFolderWait,
       
    74 	EImapStateRenameWait,
       
    75 	EImapStateSynchroniseWait,	// 15
       
    76 	EImapStateFetchWait,
       
    77 	EImapStateListWait,
       
    78 	EImapStateLsubWait,
       
    79 	EImapStateSubscribeWait,
       
    80 	EImapStateUnsubscribeWait,	// 20
       
    81 	EImapStateSeparatorWait,
       
    82 	EImapStateCommandWait,
       
    83 	EImapStateAppendSizeWait,
       
    84 	EImapStateAppendPromptWait,
       
    85 	EImapStateAppendWait,		// 25
       
    86 	EImapStateAppendResultWait,
       
    87 	EImapStateDeleteMarkWait,
       
    88 	EImapStateExpungeWait,
       
    89 	EImapStateExpungeAllWait,
       
    90 	EImapStateCloseWait,		// 30
       
    91 	EImapStateLogoutWait,
       
    92 	EImapStateMoveEntryWait,
       
    93 	EImapStateStartTLSWait,
       
    94 	EImapStateSetSeenWait,
       
    95 	EImapStateClearSeenWait,	// 35
       
    96 	EImapStateSendLiteral,
       
    97 	EImapStateIdleWait,
       
    98 	EImapStateIdling,
       
    99 	EImapStateStopIdleWait,
       
   100 	EImapStateFetchCancelWait	// 40
       
   101 	};
       
   102 
       
   103 // States of a synchronise
       
   104 /**
       
   105 @internalComponent
       
   106 @released
       
   107 */
       
   108 enum TImapSyncState
       
   109 	{
       
   110 	ENotSyncing=0,
       
   111 
       
   112 	ESyncOld,
       
   113 	ESyncNew,
       
   114 	EFetching,
       
   115 	ESyncSearch,	
       
   116 	ESyncListOld,	
       
   117 	ESyncListNew,
       
   118 	EGettingStructure
       
   119 	};
       
   120 
       
   121 // Modes updating Seen flag
       
   122 enum TSeenFlagUpdateMode
       
   123 	{
       
   124 	EClearSeenFlag=0,
       
   125 	ESetSeenFlag
       
   126 	};
       
   127 
       
   128 
       
   129 // Positive completion errors
       
   130 const TInt KErrIMAPNO				=1;
       
   131 const TInt KErrRFC2231Encoded		=2;
       
   132 
       
   133 // IMAP text
       
   134 _LIT(KIMAP_INBOX, "INBOX");
       
   135 _LIT8(KIMAP_OK, "OK");
       
   136 
       
   137 //TDes8 over flow handler
       
   138 class TDes8OverflowHandler : public TDes8Overflow
       
   139 /**
       
   140 @internalComponent
       
   141 @released
       
   142 */
       
   143 	{
       
   144 	public:
       
   145 		void Overflow(TDes8&){return;} //nullifies USER:23 panic
       
   146 	};
       
   147 
       
   148 //cached TMsvEntry data
       
   149 class TMsvCacheData
       
   150 /**
       
   151 @internalComponent
       
   152 @released
       
   153 */
       
   154 	{
       
   155 public:
       
   156 	TBool iOrphan;
       
   157 	TUint32 iUid;
       
   158 	};
       
   159 
       
   160 // Remote directory structure
       
   161 class CImImap4DirStruct : public CBase
       
   162 /**
       
   163 @internalComponent
       
   164 @released
       
   165 */
       
   166 	{
       
   167 public:
       
   168 	CImImap4DirStruct();
       
   169 	~CImImap4DirStruct();
       
   170 
       
   171 	void SetLeafnameL(const TDesC& aName);
       
   172 	TPtrC Leafname();
       
   173 	
       
   174 private:
       
   175 	HBufC*			iLeafname;
       
   176 
       
   177 public:	
       
   178 	TBool			iIsMailbox;
       
   179 	TBool			iIsFolder;
       
   180 	};
       
   181 
       
   182 // Class which will defeat the timeout
       
   183 class CIdleTimeoutTimer : public CTimer
       
   184 /**
       
   185 @internalComponent
       
   186 @released
       
   187 */
       
   188 	{
       
   189 public:
       
   190 	static CIdleTimeoutTimer* NewL(CImImap4Session& aOperation);
       
   191 private:
       
   192 	CIdleTimeoutTimer(CImImap4Session& aOperation);
       
   193 	void RunL();
       
   194 private:
       
   195 	CImImap4Session& iOperation;
       
   196 	};
       
   197 
       
   198 class CImImap4SessionDummyRead : public CActive
       
   199 /**
       
   200 @internalComponent
       
   201 @released
       
   202 */
       
   203 	{
       
   204 public:
       
   205 	static CImImap4SessionDummyRead* NewL(CImImap4Session& aOperation, CImapIO& aImapIO, TInt aPriority);
       
   206 	~CImImap4SessionDummyRead();
       
   207 	void Start();
       
   208 
       
   209 private:
       
   210 	CImImap4SessionDummyRead(CImImap4Session& aOperation, CImapIO& aImapIO, TInt aPriority);
       
   211 	void DoCancel();
       
   212 	void RunL();
       
   213 
       
   214 	CImImap4Session& iSession;
       
   215 	CImapIO& iImapIO;
       
   216 	};
       
   217 
       
   218 
       
   219 class CImImap4SessionIdleRead : public CActive
       
   220 /**
       
   221 @internalComponent
       
   222 @released
       
   223 */
       
   224 	{
       
   225 public:
       
   226 	static CImImap4SessionIdleRead* NewL(CImImap4Session& aOperation, TInt aPriority);
       
   227 	~CImImap4SessionIdleRead();
       
   228 	void Start(TRequestStatus& aStatus);
       
   229 
       
   230 private:
       
   231 	CImImap4SessionIdleRead(CImImap4Session& aOperation, TInt aPriority);
       
   232 	void DoCancel();
       
   233 	void RunL();
       
   234 
       
   235 	CImImap4Session& iOperation;
       
   236 	TRequestStatus* iOperationStatus;
       
   237 	};
       
   238 
       
   239 
       
   240 // The session class
       
   241 class CImImap4Session : public CMsgActive
       
   242 /**
       
   243 @internalComponent
       
   244 @released
       
   245 */
       
   246 	{
       
   247 public: // functions
       
   248 	// construct/destruct
       
   249 	~CImImap4Session();
       
   250 	static CImImap4Session *NewL(TInt aId, MImapSessionObserver& aObserver);
       
   251 	static CImImap4Session *NewLC(TInt aId, MImapSessionObserver& aObserver);
       
   252 
       
   253 	// Return the service settings of the current service
       
   254 	CImImap4Settings* ServiceSettings();
       
   255 
       
   256 	// Connect & disconnect to/from a server, and 'are we connected' status
       
   257 	void ConnectL(TRequestStatus& aStatus, const TMsvId aService);
       
   258 	void DisconnectL(TRequestStatus& aStatus);
       
   259 	TBool Connected();
       
   260 	TBool Busy();
       
   261 	TBool IsCancelling() const;
       
   262 	void CancelAndIdleL(TBool aReissueIdle);
       
   263 
       
   264 	// Folder information/manipulation
       
   265 	void ListL(TRequestStatus& aStatus, const TMsvId aFolder, CArrayPtr<CImImap4DirStruct>* aList);
       
   266 	void LsubL(TRequestStatus& aStatus);
       
   267 	void LocalSubscribeL(const TMsvId aTarget, const TBool aSubscribe);
       
   268 	void RemoteSubscribeL(TRequestStatus& aStatus, const TMsvId aTarget, const TBool aSubscribe);
       
   269 	void Create(TRequestStatus& aStatus, const TMsvId aParent, const TDesC& aLeafName, const TBool aFolder);	
       
   270 	void CreateL(TRequestStatus& aStatus, const TMsvId aParent, const TDesC& aLeafName, const TBool aFolder);
       
   271 	void Rename(TRequestStatus& aStatus, const TMsvId aTarget, const TDesC& aNewName);
       
   272 	void RenameL(TRequestStatus& aStatus, const TMsvId aTarget, const TDesC& aNewName);
       
   273 	
       
   274 	void Delete(TRequestStatus& aStatus, const TMsvId aTarget);
       
   275 	void Delete(TRequestStatus& aRequestStatus, const CMsvEntrySelection& aTargetSel);
       
   276 	void DeleteL(TRequestStatus& aRequestStatus, const CMsvEntrySelection& aTargetSel);
       
   277 	void DeleteAllMessagesL(TRequestStatus& aStatus);
       
   278 
       
   279 	// Append to a folder
       
   280 	void Append(TRequestStatus& aStatus, const TMsvId aEntry, const TMsvId aDestination);
       
   281 	void AppendL(TRequestStatus& aStatus, const TMsvId aEntry, const TMsvId aDestination);
       
   282 
       
   283 	// Folder selection
       
   284 	void Select(TRequestStatus& aStatus, const TMsvId aFolder, const TBool aReadWrite);
       
   285 	void SelectL(TRequestStatus& aStatus, const TMsvId aFolder, const TBool aReadWrite);
       
   286 
       
   287 	// Post-folder selection commands
       
   288 	void Synchronise(TRequestStatus& aStatus, const TBool aNewOnly);
       
   289 	void SynchroniseL(TRequestStatus& aStatus, const TBool aNewOnly);
       
   290 	void Copy(TRequestStatus& aStatus, const TMsvId aSource, const TMsvId aDestination, TBool aUnSelectIfSameFolder);
       
   291 	void CopyL(TRequestStatus& aStatus, const TMsvId aSource, const TMsvId aDestination, TBool aUnSelectIfSameFolder);
       
   292 	void Close(TRequestStatus& aStatus, const TBool aExpunge);
       
   293 	void CloseL(TRequestStatus& aStatus, const TBool aExpunge);
       
   294 	void FetchBody(TRequestStatus& aRequestStatus, const TMsvId aPart,TImImap4GetPartialMailInfo aGetPartialMailInfo);
       
   295 
       
   296 	void StartIdle(TRequestStatus& aRequestStatus);
       
   297 	void StartIdleL(TRequestStatus& aRequestStatus);
       
   298 	void StopIdle(TRequestStatus& aRequestStatus);
       
   299 	void SyncStopIdleL(TRequestStatus& aRequestStatus);
       
   300 	void StopIdleL(TRequestStatus& aRequestStatus);
       
   301 
       
   302 	void DoIdleRead(TRequestStatus& aIdleReadStatus);
       
   303 	void CancelIdleRead();
       
   304 	void IdleReadError(TInt aError);
       
   305 	void IdleTimerExpiredL();
       
   306 	void CancelTimerExpired();
       
   307 
       
   308 	// Progress
       
   309 	void IncSyncStats(TImap4SyncProgress& aSync);
       
   310 	TImap4GenericProgress Progress();
       
   311 	void ResetStats();
       
   312 
       
   313 	TBool FolderChanged() const;
       
   314 	TBool ImapIdleSupported() const;
       
   315 	TBool IsIdling() const;
       
   316 	
       
   317 	// Save msvserverentry that Mtm hands us
       
   318 	void SetEntry(CMsvServerEntry *aEntry);
       
   319 
       
   320 	// Log stuff
       
   321 	void LogText(const TDesC8& aString);
       
   322 	void LogText(TRefByValue<const TDesC8> aFmt,...);
       
   323 
       
   324 	// Orphan a local message
       
   325 	void OrphanMessageL(const TMsvId aMessage);
       
   326 
       
   327 	// Delete a local message
       
   328 	void DeleteMessageL(const TMsvId aMessage);
       
   329 
       
   330 	// Copy a message, leaving the structure behind (with a new TMsvId)
       
   331 	void CopyMessage(TRequestStatus& aStatus, const TMsvId iSourceFolder, const TMsvId iSource, const TMsvId iDestinationFolder, TMsvId* iNewSource, const TBool aRemoveOriginal);
       
   332 
       
   333 	// Park entries
       
   334 	void Park();
       
   335 
       
   336 	void ReissueIdleL();
       
   337 	void ReissueDummy();
       
   338 
       
   339 	void DummyComplete(TInt aError);
       
   340 	TInt CommandFailure() const;
       
   341 
       
   342 	// Calculate the total size of the messages to be downloaderd in this selection.
       
   343 	TInt CalculateDownloadSizeL(const CMsvEntrySelection& aSelection);
       
   344 
       
   345 	// This selection should not be deleted during a synchronisation
       
   346 	void SetSynchronisationSelectionL(CMsvEntrySelection& aSelection);
       
   347 
       
   348 	void SetInbox(TMsvId aInbox);
       
   349 	TMsvId GetInbox();
       
   350 	
       
   351 	// Only going to be set on the secondary session
       
   352 	void SetPrimarySession(CActiveWrapper* aPrimarySession);
       
   353 	
       
   354 	// Returns Current TextServerSession 
       
   355 	CImTextServerSession* GetTextServerSession();
       
   356 		
       
   357 private:	
       
   358 	CImImap4Session(MImapSessionObserver& aObserver);
       
   359 	void ConstructL(TInt aId);
       
   360 
       
   361 	void RunL();
       
   362 	void DoRunL();
       
   363 	void DoComplete(TInt& aStatus);
       
   364 
       
   365 	// The get more/send some calls
       
   366 	void GetReply(const TBool aPartial);
       
   367 	void SendMessageL(const TDesC8 &theMessage);
       
   368 	void SendUntaggedMessageL(const TDesC8 &theMessage);
       
   369 	void SendUntaggedMessageWithTimeoutL(const TDesC8 &theMessage, TInt aTimeout);
       
   370 	void NewTag();
       
   371 	void NewTagSent();
       
   372 	
       
   373 	void LostConnection(TInt aError);
       
   374 	void IssueIdleRead();	
       
   375 
       
   376 	void Fail(const TInt aError);
       
   377 	void DoDisconnect();
       
   378 
       
   379 	// Construct full mailbox/folder path from a TMsvId
       
   380 	HBufC8* MakePathL(const TMsvId aTarget, const TBool aIncludeLeaf);
       
   381 
       
   382 	// Cancel current operation
       
   383 	void DoCancel();
       
   384 
       
   385 	// convert to and from Modified UTF-7 if needed
       
   386 	HBufC* DoUnModUTF7LC(TDesC8& aBuffer);
       
   387 
       
   388 	// Enquote string if needed
       
   389 	void DoQuoteL(HBufC8*& aBuffer);
       
   390 
       
   391 	// Update last sync date on folder
       
   392 	void SyncCompleteL();
       
   393 
       
   394 	// Get children of a folder: ONLY the message ones, though
       
   395 	void GetMessageChildrenL(const TMsvId aFolder, CMsvEntrySelection* aChildren);
       
   396 
       
   397 	// Make sorted folder index
       
   398 	void MakeSortedFolderIndexL(TBool aUseCachedEntryData=EFalse);
       
   399 
       
   400 	// Show atom tree (debug only)
       
   401 	void showtree(CImapAtom* aAtom,TInt aIndent);
       
   402 
       
   403 	// Reset subscription flags (recursive)
       
   404 	void ResetSubscriptionFlagsL(const TMsvId aFolder);
       
   405 
       
   406 	// Start new synchronise phase
       
   407 	void SynchroniseNewL();
       
   408 	void SynchroniseNewL(const TUint32 aLowUid,const TUint32 aHighUid);
       
   409 
       
   410 	// Process replies
       
   411 	TInt ProcessGreetingL();
       
   412 	TInt ProcessCommandReplyL();
       
   413 	TInt ProcessContinuationResponse(CImapAtom *aAtom);
       
   414 	TInt ProcessUntaggedL(CImapAtom* aAtom, const TBool aCancelled);
       
   415 	TInt ProcessFetchL(const TUint aMsgnr, CImapAtom* aAtom);
       
   416 	void ProcessListL(CImapAtom* aAtom);
       
   417 	void ProcessLsubL(CImapAtom* aAtom);
       
   418 	TBool ProcessFlagsL(CImapAtom* aAtom, TMsvEmailEntry& aMessage);
       
   419 	void AppendExtendL(HBufC8** aBufferPtr, const TDesC8& aText, TBool aOnStack=ETrue);
       
   420 	void ProcessAddressL(HBufC8** aBuffer, CImapAtom* aAtom);
       
   421 	
       
   422 	// processing address list using envelope
       
   423 	void ProcessAddressListL(HBufC8** aBuffer, CDesCArray& aWhere, CImapAtom* aAtom);
       
   424 	// proccessing address list without using envelope
       
   425 	void ProcessAddressListL(CDesCArray& aWhere, HBufC8** aAddresses);
       
   426 
       
   427 	void ProcessEnvelopeL(CImHeader* aHeader, TMsvEntry& aEntry, CImapAtom *aAtom);
       
   428 	void ProcessHeaderExtraL(CImHeader* aHeader, CImMimeHeader* aMimeHeader, TMsvEmailEntry* aEntry, TPtrC8 aText);
       
   429 	void ProcessSearchL(CImapAtom *aAtom);
       
   430 
       
   431 	// generate a file name for an attachment based on its type
       
   432 	void GetDefaultFilename(TDes& aName, const TMsvEmailEntry& aMessage, const CImMimeHeader* mime);
       
   433 
       
   434 	void BuildTreeL(TMsvId aParent, CImapAtom *aAtom, const TDesC8& aPath,
       
   435 		            const TMsvId aThisMessage, TInt& aAttachments, TBool& aIsMHTML, TInt& aRelatedAttachments);
       
   436 	void BuildTreeOneL(const TMsvId aParent, CImapAtom *aAtom, const TDesC8& aPath,
       
   437 			           const TMsvId aThisMessage, TInt& aAttachments, TBool& aIsMHTML, TInt& aRelatedAttachments);
       
   438 
       
   439 	// Fetch helpers
       
   440 	// AddFetchItem adds item and appropriate fetchable children to
       
   441 	// the current fetch list
       
   442 	void AddFetchItemL(TMsvId aPart, TImap4GetMailOptions aPartTypes, TBool& aHasTextParts);
       
   443 	void AddFetchItemL(TMsvId aPart, TImImap4GetPartialMailInfo aGetPartialMailInfo, TBool& aHasTextParts);
       
   444 
       
   445 	// FetchAnItem issues command to fetch a fetchable part
       
   446 	void FetchAnItemL(const TMsvId aItem);
       
   447 
       
   448 	// Decode received data
       
   449 	void DecodeAndStoreL(const TPtrC8& aData, const TBool aEndOfStream);
       
   450 	TInt WriteToAttachmentL(const TDesC8& aText);
       
   451 	void WriteToBodyL(const TDesC8& aText);
       
   452 
       
   453 	// Helper function to decode UUEncoded attachment in MIME emails
       
   454 	TBool CheckUUEStartL(const TDesC8& aSourceLine);
       
   455 
       
   456 	// Called when we get a tagged completion code
       
   457 	void CommandCompleteL(TInt aResult);
       
   458 
       
   459 	// Dummy read operation queueing
       
   460 	void IssueDummy();
       
   461 	void CancelDummy();
       
   462 
       
   463 	// Set entry, leave if error (not related to setentry() which sets iEntry)
       
   464 	void SetEntryL(const TMsvId aId);
       
   465 
       
   466 	// Change entry, leave if error
       
   467 	void ChangeEntryL(const TMsvEntry& aEntry);
       
   468 
       
   469 	// Change entry, leave if error
       
   470 	void ChangeEntryBulkL(const TMsvEntry& aEntry);
       
   471 	// Get children, leave if error
       
   472 	void GetChildrenL(CMsvEntrySelection& aSelection);
       
   473 
       
   474 	// Scan content-type list for filename information, copy if necessary
       
   475 	TInt FindFilename(const CImMimeHeader& aMimeInfo, TPtrC8& aFilename);
       
   476 
       
   477 	// call FindFilename, default if necessary and QP decode it
       
   478 	void FindFilenameDecodeL(const CImMimeHeader& aMimeInfo, TFileName& aFilename);
       
   479 
       
   480 	// Copy a message, leaving the structure behind (with a new TMsvId) - use CopyMessage() instead
       
   481 	void CopyMessageL(TRequestStatus& aStatus, const TMsvId iSourceFolder, const TMsvId iSource, const TMsvId iDestinationFolder, TMsvId* iNewSource, const TBool aRemoveOriginal);
       
   482 
       
   483 	// private leaving versions of public non-leaving versions
       
   484 	void FetchBodyL(TRequestStatus& aStatus, const TMsvId aPart);
       
   485 	void DeleteL(TRequestStatus& aStatus, const TMsvId aTarget);
       
   486 
       
   487 	void DeleteEntryL( const TMsvId aTarget);
       
   488 
       
   489 	// convenience function to fix up the colon-separated header list
       
   490 	// into a space separated list
       
   491 	void ColonSeparatorToSpace(TDes8& buf);
       
   492 	void StripSpace(HBufC8* aBuf);
       
   493 
       
   494 	void PropagateCompleteFlagL(TMsvId aId, TBool aDoBodyText, TBool aPartialFetched);
       
   495 	void SendLoginL();
       
   496 	void SendCapabilityL();
       
   497 	TPtrC FileNameFromRFC2231(const TDesC8& aEncodedFileName);
       
   498 	static void SetMessageFlagsL(TMsvEmailEntry& aMessageEntry, CImapAtom* aRootAtom);
       
   499 
       
   500 	void FetchLargeHeaderL(TUint aUid, TBool aRange);  
       
   501 	void FetchHeaderL(TUint aUid);
       
   502    
       
   503   	void DoFetchL();
       
   504 
       
   505 	// Set or clear a set of message \Seen flags
       
   506 	TBool ProcessSeenFlagsL(TSeenFlagUpdateMode aUpdateMode);
       
   507 
       
   508 	// Search through all Sibling Atoms for an Attachment
       
   509 	TBool DoesAtomContainAttachment(CImapAtom *aAtom);
       
   510 	TInt32 Minimum(TInt32 aThisPartTypeSizeLimit,TInt32 aTotalMailSizeLimit);
       
   511 	TInt32 GetFetchSizeL(TInt32 aSizeLeft, TInt32 aSizeDownLoaded);
       
   512 	void AttachFooterInfoL();
       
   513 	void CheckForDiskSpaceL(TInt aSizeToBeDownloaded);
       
   514 	TInt32 FetchSize(TInt32 aMinimumLimit,TInt32 aSizeDownLoaded, TInt32 aSizeLeft);
       
   515 	void CheckForPartialPopulate(TImImap4GetPartialMailInfo aGetPartialMailInfo);
       
   516 	void RemoveHtmlPart(TMsvId aPart);
       
   517 	void ProcessFooterMessageL(TInt aSizeLeft);
       
   518 	
       
   519 	void DoSynchroniseL(TBool aNewOnly);
       
   520 	void DoStartIdleL();
       
   521 	void DoStopIdleL();
       
   522 	void DoDisconnectL();
       
   523 	void CreateAttachmentInfoL(TMsvEmailEntry& aMsvEmailEntry);
       
   524 	void CreateUidStringL();
       
   525 	void DoSelectL(const TMsvId aFolder, const TBool aReadWrite);	
       
   526 private:
       
   527 	enum TImap4SecurityState
       
   528 		{
       
   529 		EUnknown,
       
   530 		ENegotiating,
       
   531 		ESecure,
       
   532 		EUnsecure
       
   533 		};
       
   534 	
       
   535 private:
       
   536 	// Copy of the service's settings
       
   537 	CImImap4Settings*		iServiceSettings;
       
   538 	// Copy of the service's iap settings
       
   539 	CImIAPPreferences*		iPrefs;
       
   540 
       
   541 	// Our connection
       
   542 	CImapIO*				iImapIO;
       
   543 
       
   544 	// FS handle
       
   545 	RFs						iFs;
       
   546 
       
   547 	// Current state and line being processed
       
   548 	TImapState				iState;
       
   549 	TImapState				iSavedState;
       
   550 	TBool					iSendQueued;
       
   551 	TBool					iReceiveQueued;
       
   552 	TBool					iGotWholeLine;
       
   553 	TInt					iCommandsOutstanding;
       
   554 	TBool					iSizeWait;
       
   555 
       
   556 	// Generic space to store completion information about commands in progress
       
   557 	TBool					iCommandFlags[4];
       
   558 	TMsvId					iCommandIds[4];
       
   559 	TBuf<256>				iCommandBuf;
       
   560 	TInt					iCommandSize;
       
   561 
       
   562 	// Synchronisation state
       
   563 	TImapSyncState			iSyncState;
       
   564 	TInt					iFolderPosition;
       
   565 	TUint					iHighestUid;
       
   566 	TInt32					iSyncLimit;
       
   567 
       
   568 	// Current tag
       
   569 	TInt					iTag;
       
   570 	TInt					iCancelledTag;
       
   571 
       
   572 	// Mailbox hierarchy
       
   573 	TBuf8<1>				iHierarchySeparator;
       
   574 	TBuf8<64>				iFolderPath;
       
   575 
       
   576 	// List bits
       
   577 	CArrayPtr<CImImap4DirStruct>* iList;
       
   578 
       
   579 	// Seen IMAP4rev1 capability?
       
   580 	// IMAP capabilities
       
   581 	TBool					iSeenVersion;
       
   582 	TBool					iCapabilityStartTLS;
       
   583 	TBool					iCapabilityLoginDisabled;
       
   584 	TBool					iCapabilityIdleSupport;
       
   585 
       
   586 	TImap4SecurityState		iSecurityState;
       
   587 
       
   588 	// Host/username/password
       
   589 	TBuf<64>				iHost;
       
   590 	TInt					iPort;
       
   591 	HBufC8* 				iUsername;
       
   592 	HBufC8* 				iPassword;
       
   593 	TBool					iLiteralUsername;
       
   594 	TBool					iLiteralPassword;
       
   595 
       
   596 	// Mailbox state information from remote host
       
   597 	TMsvId					iMailboxId;
       
   598 	//TBool					iMailboxIsInbox;
       
   599 	CImImap4FolderIndex		iFolderIndex;
       
   600 	TBool					iMailboxReceivedExpunge;
       
   601 	TBool					iMailboxReceivedExists;
       
   602 	TBool					iMailboxReceivedFlags;
       
   603 	TBufC8<128>				iMailboxName;
       
   604 	TInt					iMailboxSize;
       
   605 	TInt					iMailboxRecent;
       
   606 	TBool					iMailboxWritable;
       
   607 	TUint					iUidValidity;
       
   608 	TUint					iUidNext;
       
   609 	CArrayFix<TMsvId>*		iDeletedUids;
       
   610 	TBool					iSomeUnread;
       
   611 
       
   612 	CArrayFix<TUint32>*		iSearchList;
       
   613 	TUint32					iMissingUidLow;
       
   614 	TUint32					iMissingUidHigh;
       
   615 
       
   616 	// Fetch in progress
       
   617 	TMsvId					iMessageId;
       
   618 	//TMsvId				iMessageDestination;
       
   619 	TUint					iMessageUid;
       
   620 	TUint					iMessageFetching;
       
   621 	
       
   622 	CBufBase*				iBodyBuf;
       
   623 	CMsvBodyText*			iBodyText;
       
   624 	CRichText*				iMessageBody;
       
   625 	CParaFormatLayer*		iParaLayer;
       
   626 	CCharFormatLayer*		iCharLayer;
       
   627 	
       
   628 	CArrayFix<TMsvId>*		iFetchList;
       
   629 	TBool					iFetchIsText;
       
   630 	TFileName				iAttachmentName;
       
   631 	CImMimeHeader*			iAttachmentMimeInfo;
       
   632 
       
   633 	TImAttachmentFile*		iAttachmentFile;
       
   634 	TImAttachmentFileState	iAttachmentFileState;
       
   635 	HBufC*					iAttachmentFullPath;
       
   636 	TInt					iSizeOfThisPart;
       
   637 	TInt					iDecodedSizeOfAllParts;
       
   638 	TInt 					iSizeLeftToFetch;
       
   639 	
       
   640 	// Bool to indicate that we are in between of a UUEncoded start and end tag.
       
   641 	TBool					iUUDecoding;
       
   642 	
       
   643 	// Decoder used for fetch in progres
       
   644 	TImCodecB64				iB64Decoder;
       
   645 	TImCodecUU				iUUDecoder;
       
   646 	TImCodecQP				iQPDecoder;
       
   647 	TImEncodingType			iEncodingType;
       
   648 	HBufC8*					iPartialLine;
       
   649 	HBufC*					iDefaultAttachmentName;
       
   650 
       
   651 	// Characterset conversion
       
   652 	CImConvertCharconv*		iCharConv;
       
   653 	CCnvCharacterSetConverter* iCharacterConverter;
       
   654 	CImConvertHeader*		iHeaderConverter;
       
   655 	TBool					iPreparedToConvert;
       
   656 	TBuf8<20>				iLeftOver;
       
   657 
       
   658 	// Bits used when appending
       
   659 	CImCalculateMsgSize*	iMessageSizer;
       
   660 	CImSendMessage*			iMessageSender;
       
   661 	TTime					iMessageDate;
       
   662 	HBufC8*					iLineBuffer;
       
   663 
       
   664 	// Tree of atoms
       
   665 	CImapAtom*				iRootAtom;
       
   666 
       
   667 	// Access to message database
       
   668 	CMsvServerEntry*		iEntry;
       
   669 	CMsvServerEntry*		iMoveEntry;
       
   670 	TMsvId					iMoveSource;		// What we're moving
       
   671 	TMsvId					iMoveSourceFolder;	// Where we're moving it from
       
   672 	TMsvId*					iNewSource;			// Where we save the newly created TMsvId in the source folder
       
   673 	CMsvEntrySelection*		iSelection;
       
   674 	CMsvEntrySelection*		iSynchronisationSelection;
       
   675 
       
   676 	// Dummy operation issued to CImapIO to notify us of connection problems?
       
   677 	CImImap4SessionDummyRead*	iDummyRead;
       
   678 	
       
   679 	// Used to issue and handle responses for IMAP IDLE
       
   680 	CImImap4SessionIdleRead* iIdleRead;
       
   681 
       
   682 	TBool					iUseIdleCommand;
       
   683 	CIdleTimeoutTimer*		iIdleTimer;
       
   684 	TBool					iReissueIdle;
       
   685 	TBool					iDisconnectAfterIdleStopped;
       
   686 	TMsvId					iInbox;
       
   687 	TBool 					iIdleTimerExpired;
       
   688 
       
   689 	// Hideous kludge for brain-dead CC:Mail servers
       
   690 	TBool					iTalkingToCCMail;
       
   691 	TBool					iTalkingToOpenMail;
       
   692 
       
   693 	TRequestStatus*			iRequestStatus;
       
   694 	TUint					iCharset;
       
   695 
       
   696 	TInt					iHeadersFetched;
       
   697 	TInt					iOrphanedMessages;
       
   698 	TInt					iRemoteMessagesDeleteTagged;
       
   699 	TInt					iMsgsDone;
       
   700 	TInt					iCheckDiskSpaceCounter;
       
   701 	TInt					iCurrentDrive;
       
   702 
       
   703 	CArrayFixFlat<TMsvCacheData>* iCachedEntryData;
       
   704 	CArrayFixFlat<TMsvId>* iSetSeenList;
       
   705 	CArrayFixFlat<TMsvId>* iClearSeenList;
       
   706 
       
   707  	TBool					iJustSentFetch;
       
   708  
       
   709  	// 
       
   710  	TImap4GetMailOptions	iGetOptions;
       
   711 	TImImap4GetPartialMailInfo	iGetPartialMailInfo;
       
   712  	TMsvId					iGetPart;
       
   713 
       
   714 	// If a Copy/Move/Delete fails with IMAP server. 
       
   715 	// Store the fact. May need information.
       
   716 	TInt					iCommandFailure;
       
   717 
       
   718 	// bearer timeout value in microseconds
       
   719 	TInt					iIdleTimeout;
       
   720 
       
   721 	TInt					iStore8BitData;
       
   722 	TBool					iFetchPartialMail;
       
   723 	TInt32					iBodyTextSize;
       
   724 	TInt32					iHtmlEntrySize;
       
   725 	TInt32					iBodyPartRemainingSize;
       
   726 	HBufC*					iFooterString;
       
   727 	TBool					iIsDiskSpaceChecked;
       
   728 	TMsvId					iHtmlEntryPart; 
       
   729 	TInt32					iSizeOfToBeFetchedAttachments;
       
   730 	// if set, the there is no IDLE reissued after a synch
       
   731 	TBool					iCompoundStopIdle;
       
   732 	CImCaf*					iCaf;
       
   733 
       
   734 	TBool					iIsICalendar;
       
   735 	TBool					iIsVCalendar;
       
   736 
       
   737 	HBufC8*					iUidString;
       
   738 	
       
   739 	// test to see if the uid is present in the fetch response. If it is, then it is part
       
   740 	// of the fetch command sent by the client. Otherwise it is a server message flag update,
       
   741 	// so just process flags
       
   742 	TBool iFoundUid;
       
   743 
       
   744 	// Indicates that we are stopping idle at the request of the synchronise active object
       
   745 	TBool iStoppingIdleForSync;
       
   746 
       
   747 	// Observer for callback notifications from session
       
   748 	MImapSessionObserver& iObserver;
       
   749 	
       
   750 	// Only going to be set on the secondary session to take ownership of primarysession
       
   751 	CActiveWrapper*			iPrimarySession; 
       
   752 	
       
   753 protected:
       
   754 	// Progress information
       
   755 	TImap4GenericProgress	iProgress;
       
   756 
       
   757 	// The service we're connected to
       
   758 	TMsvId					iServiceId;
       
   759 	// If we sent FETCH BODY MIME
       
   760 	TBool					iParsedTime;
       
   761 	CImapCancelTimer*		iCancelTimer;
       
   762 	TBool					iCancelAndIdle;
       
   763 	};
       
   764 
       
   765 #if 0
       
   766 class CImImapMoveWait: public CActive
       
   767 	{
       
   768 public:
       
   769 	CImImapMoveWait();
       
   770 	~CImImapMoveWait();
       
   771 	inline void Start();
       
   772 protected:
       
   773 	void RunL();
       
   774 	void DoCancel();
       
   775 	};
       
   776 
       
   777 inline void CImImapMoveWait::Start()
       
   778 	{
       
   779 	SetActive();
       
   780 	}
       
   781 #endif
       
   782 
       
   783 #endif
       
   784