email/pop3andsmtpmtm/imapservermtm/test/src/T_IMPS01.cpp
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 //
       
    15 
       
    16 #include <logcli.h>
       
    17 #include <logview.h>
       
    18 
       
    19 #include "EmailTestUtils.h"
       
    20 #include <commdb.h>
       
    21 #include <bacline.h>
       
    22 #include <cemailaccounts.h>
       
    23 
       
    24 
       
    25 
       
    26 #include "t_log.h"
       
    27 
       
    28 // For loading the serial comms device drivers 
       
    29 #if defined (__WINS__)
       
    30 	#define PDD_NAME		_L("ECDRV")
       
    31 	#define LDD_NAME		_L("ECOMM")
       
    32 #else
       
    33 	#define PDD_NAME		_L("EUART1")
       
    34 	#define LDD_NAME		_L("ECOMM")
       
    35 #endif
       
    36 
       
    37 // --------------------------------------------------------------------------
       
    38 
       
    39 //#define _DEBUG_MTMCOMMAND_
       
    40 
       
    41 // Static variables
       
    42 
       
    43 LOCAL_D RTest test(_L("IMPS.dll Testrig"));
       
    44 LOCAL_D RFs theFs;
       
    45 
       
    46 // LOCAL_C CMsvServer* theServer;
       
    47 
       
    48 _LIT(KFolderNameToEncode, "αινσϊ");
       
    49 
       
    50 _LIT(KMessageNameTest, "Test: 12");
       
    51 _LIT(KMessageNameAttachment, "Test: 9");
       
    52 
       
    53 _LIT(KMessageNamePriority,"Test: 23");
       
    54 _LIT(KMessageNameXPriority,"Test: 15");
       
    55 _LIT(KMessageNamePrecedence,"Test: 24");
       
    56 _LIT(KMessageNameImportance,"Test: 14");
       
    57 
       
    58 _LIT(KMessageNameMimeHTML, "Test: 2");
       
    59 
       
    60 
       
    61 LOCAL_D const TUid KUidImQueuedOperationList = {0x10001794};	// 2648441492 dec.
       
    62 
       
    63 _LIT(KTestParams,"-testparams");
       
    64 enum TCmdLineArgs
       
    65 	{
       
    66 	EArgProgramName,
       
    67 	EArgTestParams,
       
    68 	EArgRemoveMsgStore,
       
    69 	EArgMainMenu
       
    70 	};
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 
       
    74 class TestScheduler : public CActiveScheduler
       
    75 	{
       
    76 public:
       
    77 	void Error (TInt aError) const;
       
    78 	};
       
    79 
       
    80 void TestScheduler::Error(TInt anError) const
       
    81 	{
       
    82 	test.Printf(_L("Scheduler Error %d"), anError );
       
    83 	CActiveScheduler::Stop();
       
    84 	}
       
    85 
       
    86 // -------------------------------------------------------------------------
       
    87 
       
    88 class TestUiTimer : public CTimer
       
    89 	{
       
    90 public:
       
    91 	static TestUiTimer* NewL( CConsoleBase*, CBaseServerMtm* &aImppServerMtm );
       
    92 	~TestUiTimer();
       
    93 
       
    94 	void RunL();
       
    95 	void DoCancel();
       
    96 	void ConstructL();
       
    97 	void IssueRequest();
       
    98 	void Dump();
       
    99 	TPtrC StateName(TImap4GenericProgress::TImap4GenericProgressState aState);
       
   100 	TPtrC OpName(TImap4GenericProgress::TImap4GenericProgressOp aOp);
       
   101 	TPtrC SyncStateName(TImap4SyncProgress::TImap4SyncProgressState aState);
       
   102 
       
   103 	CConsoleBase*				iConsole;
       
   104 	CBaseServerMtm*				&iImppServerMtm;
       
   105 	TTimeIntervalMicroSeconds32 period;
       
   106 protected:
       
   107 	TestUiTimer( CConsoleBase* , CBaseServerMtm* &aImppServerMtm );
       
   108 
       
   109 	TInt iCount;
       
   110 	TBool iClosing;
       
   111 	TBool iDoneConnecting;
       
   112 	};
       
   113 
       
   114 // --------------------------------------------------------------------------
       
   115 
       
   116 enum TImap4OpType
       
   117 	{
       
   118 	EImap4OpCopyToLocal,
       
   119 	EImap4OpMoveToLocal,
       
   120 	EImap4OpCopyFromLocal,
       
   121 	EImap4OpMoveFromLocal,
       
   122 	EImap4OpCopyWithinService,
       
   123 	EImap4OpMoveWithinService,
       
   124 	EImap4OpMoveWithinServiceToInbox,
       
   125 	EImap4OpPopulate,
       
   126 	EImap4OpDelete,
       
   127 	EImap4OpUndelete,
       
   128 	EImap4OpCopyWithinFolder,
       
   129 	EImap4OpCopyToLocalAndDelete,
       
   130 	EImap4OpMoveToLocalAndDelete,
       
   131 	EImap4OpCopyFromLocalAndDelete,
       
   132 	EImap4OpMoveFromLocalAndDelete,
       
   133 	EImap4OpCopyWithinServiceAndDelete,
       
   134 	EImap4OpMoveWithinServiceAndDelete
       
   135 	};
       
   136 
       
   137 enum TDebugLevel
       
   138 	{
       
   139 	EDebugLevel0=0,
       
   140 	EDebugLevel1,
       
   141 	EDebugLevel2,
       
   142 	EDebugLevel3,
       
   143 	EDebugLevel4,
       
   144 	EDebugLevel5,
       
   145 	EDebugLevel6,
       
   146 	EDebugLevel7,
       
   147 	EDebugLevel8,
       
   148 	EDebugLevel9
       
   149 	};
       
   150 class CActiveConsole;
       
   151 class CTestRefreshMBox : public CActive
       
   152 	{
       
   153 public:
       
   154 	static CTestRefreshMBox* NewLC(CCommandLineArguments* aCmdLineArgs);
       
   155 	static CTestRefreshMBox* NewL(CCommandLineArguments* aCmdLineArgs);
       
   156 
       
   157 	// Destruction
       
   158 	~CTestRefreshMBox();
       
   159 	
       
   160 	// Issue request
       
   161 	void StartL();
       
   162 	void EnterStateL(TInt aState);
       
   163 
       
   164 	// Cancel request.
       
   165 	// Defined as pure virtual by CActive;
       
   166 	// implementation provided by this class.
       
   167 	void DoCancel();
       
   168 
       
   169 	// Service  request.
       
   170 	// Defined as pure virtual by CActive;
       
   171 	// implementation provided by this class,
       
   172 	void RunL();
       
   173 	TInt NumBadMessages();
       
   174 
       
   175 	void ModifyImap4SynchronisationLimitsL(TInt aInboxSyncLimit,TInt aMailboxSyncLimit);
       
   176 	void FindImap4SettingsL();
       
   177 	void CreateDefaultServiceL(CImImap4Settings* aSettings);
       
   178 	void CreateServiceL( const CImImap4Settings* aSettings,
       
   179 						 const TDesC& aDetails, const TDesC& aDescription,
       
   180 						 const TBool aLocalOnly =EFalse);
       
   181 	void QueueOpL(TImap4OpType aOp);
       
   182 	void UnQueueOpL(TImap4OpType aOp);
       
   183 	void QueueLocalToLocalOpL(TImap4OpType aOp);
       
   184 
       
   185  	CMsvServerEntry* ServerEntry();
       
   186 	void SelectServiceIdL();
       
   187 	TMsvId iServiceId;
       
   188 	void DoCancelOffLineOpsL();
       
   189 	
       
   190 	void SetConsole(CActiveConsole* aConsole) {iConsole=aConsole;} 
       
   191 
       
   192 	CEmailTestUtils*		iTestUtils;
       
   193 	TInt iDebugLevel;
       
   194 
       
   195 private:
       
   196     void EndOfTest();  
       
   197 	void SetSubscriptionsL( TFolderSyncType aSync, TFolderSubscribeType aSubscribe );
       
   198 	void FindAttachmentL();
       
   199 	void FindMessagesInSelectionL();
       
   200 
       
   201 	void DoConnectL();
       
   202 	void DoConnectAndSyncL();
       
   203 	void DoFullSyncL();
       
   204 	void DoInboxNewSyncL();
       
   205 	void DoSyncTreeL();
       
   206 	void DoFetchInboxL();
       
   207 	void DoDisconnectL();
       
   208 	void DoWaitForBackgroundL();
       
   209 	void DoFetchAttachmentL();
       
   210     void DoFetchAttachedMessageL();
       
   211 	void DoRenameFolderL();
       
   212 	void DoAutomatedOffLineOpsL();
       
   213 	void DoAutomatedSyncOpsL();
       
   214 	void DoFetchTestL();
       
   215 	void DoFolderRemoveL();
       
   216 	void DoFolderRemoveL(TMsvId aParent, const TDesC& aName);
       
   217 	void DoFolderCreateL();
       
   218 	void DoFolderCreateL(TMsvId aParent, const TDesC& aName);
       
   219 	void DoAutomatedSecondaryConnectOpsL();
       
   220 	void DoCopyMessagesL();
       
   221 
       
   222 	TBool StateMachineCheckServerContentsL();
       
   223 	void DoCheckServerContentsL();
       
   224 
       
   225 	TBool StateMachineNSynchronisationL();
       
   226 	void DoNSynchronisationRegressionL();
       
   227 	void DoNSynchronisationTestsL();
       
   228 	void DoNSynchronisationSpecialTestsL();
       
   229 	void DoNSynchronisationPerformanceTestsL();
       
   230 	void DoNSynchronisationOneOffTestsL();
       
   231 
       
   232 	void StartTimerL();
       
   233 	void ClearTimer();
       
   234 	void ConstructL();
       
   235 	TPtrC TestMsgName(TImap4OpType aOpType, TImap4GetMailOptions aOptions);
       
   236 	void TestFolders(TImap4OpType aOpType,
       
   237 					 TMsvId& srcFolder, TMsvId& destination);
       
   238 	
       
   239 	TMsvId FindMessageByNameL(TMsvId aSrcFolder, const TDesC& aName);
       
   240 	TMsvId FindMessageByOpL(TMsvId aSrcFolder, TImap4OpType aOp);
       
   241 	TMsvId FindMessageByOpL(TMsvId aSrcFolder, TImap4OpType aOp, TImap4GetMailOptions aOptions);
       
   242 	TMsvId FindFolderByNameL(TMsvId aSrcFolder, const TDesC& aName);
       
   243 	TMsvId FindByNameL(TMsvId aSrcFolder, const TDesC& aName, TBool aSearchOnDetails);
       
   244 	
       
   245 	TMsvId CountMessagesByNameL(TMsvId aSrcFolder, const TDesC& aName);
       
   246 	TInt CountMessagesByOpL(TMsvId aSrcFolder, TImap4OpType aOp);
       
   247 
       
   248 
       
   249 protected:
       
   250 	// Data members defined by this class
       
   251 	CBaseServerMtm*			iImppServerMtm;
       
   252 	CMsvServerEntry*		iEntry;
       
   253 	CMsvEntrySelection*		iSelection;
       
   254 	TInt					iState;
       
   255 
       
   256 private:
       
   257 	CMsvServerEntry* SetEntryL(TMsvId aFolder, const TDesC& aName);
       
   258 	CImHeader* GetHeaderLC();
       
   259 	CImImap4Settings* GetImap4SettingsLC();
       
   260 
       
   261 	TBool HandleSyncStateL();
       
   262 	TBool HandleOffLineStateL();
       
   263 	TBool TestSecondaryConnectStateMachineL();
       
   264 
       
   265 	void NextState(TInt aInc);
       
   266 	void NextState();
       
   267 	void PerformOpL( TImap4OpType aOpType, const TDesC8& aParams);
       
   268 	void PerformSpecialOpL(TMsvId aId, TImap4Cmds aCommand);
       
   269 	
       
   270 	void DoOpByIdL( TImap4OpType aOpType, TMsvId aId );
       
   271 	void DoOpByIdL( TImap4OpType aOpType, TMsvId aId, const TDesC8& aParams );
       
   272 	void DoOpL( TImap4OpType aOpType, const TDesC& aName, TMsvId aSourceFolder, TMsvId aDestFolder, const TDesC8& aParams);
       
   273 	void DoOpL( TImap4OpType aOpType, TMsvId aSourceFolder, TMsvId aDestFolder, const TDesC8& aParams);
       
   274 	void DoOpL( TImap4OpType aOpType, TMsvId aSourceFolder, TMsvId aDestFolder);
       
   275 	void DoOpL( TImap4OpType aOpType, TMsvId aSourceFolder, TMsvId aDestFolder, TImap4GetMailOptions aOptions);
       
   276 	void DoOpNamedL( TImap4OpType aOpType, TMsvId aSrcFolder, TMsvId aDestFolder, const TDesC8& params);
       
   277 	void DoOpNamedL( TImap4OpType aOpType, TMsvId aSrcFolder, TMsvId aDestFolder);
       
   278 	void DoOpNamedL( TImap4OpType aOpType, TMsvId aSrcFolder, TMsvId aDestFolder, TImap4GetMailOptions aOptions);
       
   279 
       
   280 	TBool TestQueueL( TMsvId aFolder, CImOffLineOperation::TOffLineOpType aOpType, TMsvId aMessage, TMsvId aTarget, TInt aFnId,	const TDesC8& aParams );
       
   281 	TBool TestQueueL( TMsvId aFolder, CImOffLineOperation::TOffLineOpType aOpType, TMsvId aMessage, TMsvId aTarget, TImap4GetMailOptions aOptions );
       
   282 	TBool TestQueueL( TMsvId aFolder, CImOffLineOperation::TOffLineOpType aOpType, TMsvId aMessage, TMsvId aTarget );
       
   283 	TBool TestQueueEmptyL( TMsvId aFolder );
       
   284 	TMsvId FindShadowL( TMsvId aFolder, TMsvId aSourceId );
       
   285 	TBool TestShadowL( TMsvId aFolder, TMsvId aSourceId );
       
   286 	TBool TestVisible( TMsvId aSourceId );
       
   287 	TBool TestInvisible( TMsvId aSourceId );
       
   288 	TBool TestComplete( TMsvId aSourceId );
       
   289 	TBool TestExists( TMsvId aSourceId );
       
   290 	TImDisconnectedOperationType TestDisconnectedFlags( TMsvId aSourceId );
       
   291 	TBool TestSubscribed( TMsvId aSourceId );
       
   292 	TBool TestNotSubscribed( TMsvId aSourceId );
       
   293 	TBool TestLocalSubscription( TMsvId aSourceId );
       
   294 	TBool TestNotLocalSubscription( TMsvId aSourceId );
       
   295 
       
   296 	void TestPriorityAndReceiptAddressL();
       
   297 
       
   298 	void DebugFormatL(TInt aDebugLevel,TRefByValue<const TDesC> aFmt,...);
       
   299 	void DebugUidListL(TInt aDebugLevel);
       
   300 
       
   301 	TMsvId iRemoteInbox;
       
   302 
       
   303 	TMsvId iRemoteFolder1;
       
   304 	TMsvId iRemoteFolder2;
       
   305 	TMsvId iLocalFolder1;
       
   306 	TMsvId iLocalFolder2;
       
   307 
       
   308 	TInt iOpState;
       
   309 	TInt iTestNum;
       
   310 	TMsvId iSourceId;
       
   311 	TMsvId iSourceFolder;
       
   312 	TMsvId iDestFolder;
       
   313 	TMsvId iOrigSourceId;
       
   314 
       
   315 	CLogClient *iLogClient;
       
   316 	CLogViewEvent *iLogView;
       
   317 	CLogFilter *iLogFilter;
       
   318 
       
   319 	TUint32 iMessageUid;
       
   320 	TInt iSyncLimit;
       
   321 	TTime iTimeStamp;
       
   322 	
       
   323 private:
       
   324 	CTestRefreshMBox();
       
   325 	TestUiTimer*			iTimer;
       
   326 
       
   327 	TBool					iRenamedFolder;
       
   328 	
       
   329 	CActiveConsole*			iConsole;
       
   330 	CCommandLineArguments*	iCmdLineArgs;	
       
   331 
       
   332 public:
       
   333 	enum
       
   334 		{
       
   335 		EImapTestConnect,
       
   336 		EImapTestConnectAndSync,
       
   337 		EImapTestFullSync,
       
   338 		EImapTestInboxNewSync,
       
   339 		EImapTestSyncTree,
       
   340 		EImapTestDisconnect,
       
   341 		EImapTestFetchInbox,
       
   342 		EImapTestOffLineOp,
       
   343 		EImapTestWaitForBackground,
       
   344 		EImapTestFetchAttachment,
       
   345 		EImapTestCancelOffLineOps,
       
   346 		EImapTestRenameFolder,
       
   347 		EImapTestAutoOffLineOp,
       
   348 		EImapTestAutoSyncOp,
       
   349 		EImapTestFetchTest,
       
   350 		EImapTestFolderDelete,
       
   351 		EImapTestFolderCreate,
       
   352 		EImapTestCheckServerContents,
       
   353 		EImapTestAutoSecondaryConnect,
       
   354 		EImapTestLocalSubscribe,
       
   355 		EImapTestLocalUnsubscribe,
       
   356         EImapTestFetchAttachedMessage,
       
   357         EImapTestCopyMessages,
       
   358 		EImapTestNSynchronisation,	 
       
   359 		EImapTestNSynchronisationTests,			 
       
   360 		EImapTestNSynchronisationSpecialTests,
       
   361 		EImapTestNSynchronisationPerformanceTests,
       
   362 		EImapTestNSynchronisationOneOffTests
       
   363 		};
       
   364 	};
       
   365 
       
   366 // --------------------------------------------------------------------------
       
   367 
       
   368 // My derived Console, as per the example code and the stuff in T_POPC 
       
   369 
       
   370 class CActiveConsole : public CActive
       
   371 	{
       
   372 public:
       
   373 	// Construction
       
   374 	static CActiveConsole* NewLC( CTestRefreshMBox *aRefresher,CCommandLineArguments* aCmdLineArgs );
       
   375 
       
   376 	// Destruction
       
   377 	~CActiveConsole();
       
   378 
       
   379 	// Issue request
       
   380 	void RequestCharacter();
       
   381 	
       
   382 	// Cancel request.
       
   383 	// Defined as pure virtual by CActive;
       
   384 	void DoCancel();
       
   385 
       
   386 	// Service completed request.
       
   387 	// Defined as pure virtual by CActive;
       
   388 	void RunL();
       
   389 
       
   390 	// Called from RunL() to handle the completed request
       
   391 	void ProcessKeyPressL(TChar aChar); 
       
   392 
       
   393 	void DumpMessageStructureL( TMsvId aId,
       
   394 							   TInt aSummary,
       
   395 							   TInt aParts,
       
   396 							   TBool aRecurse,
       
   397 							   TBool aShowIds,
       
   398 							   MsgMatchFn aMatch =0);
       
   399 private:
       
   400 	void ConstructL();
       
   401 	CActiveConsole();
       
   402 
       
   403 	void DisplayMainMenu();
       
   404 	void DisplayImap4ServerMenu();
       
   405 	void DisplayImap4SettingsMenu();
       
   406 	void DisplayImap4DumpMenu();
       
   407 	void DisplayHousekeepingMenu();
       
   408 	void DisplayOffLineOpMenu();
       
   409 	void DisplayOffLineOpQueueMenu();
       
   410 	void DisplayOffLineOpUnQueueMenu();
       
   411 	void DisplayOffLineOpQueueLocalToLocalMenu();
       
   412 	void DisplayConnectMenu();
       
   413 	void DisplayConnect2Menu();
       
   414 	void DisplayAutomationMenu();
       
   415 	void DisplaySynchroniseMenu();
       
   416 	void DisplayDebugMenu();
       
   417 
       
   418 	void SelectImap4ServerEntryL(TChar aChar);
       
   419 	void SelectImap4SettingsEntryL(TChar aChar);
       
   420 	
       
   421 
       
   422 public:
       
   423 	TBool	iIssueCancel;
       
   424 
       
   425 private:	
       
   426 	TUint iMenuState;
       
   427 	TUint iPrevState;
       
   428 
       
   429 	CTestRefreshMBox *iRefresher;
       
   430 	
       
   431 	CCommandLineArguments*	iCmdLineArgs;
       
   432 	TInt					iLevel;
       
   433 
       
   434 	enum
       
   435 		{
       
   436 		EExit = 0,
       
   437 		EMainMenu,
       
   438 		EImap4ServerMenu,
       
   439 		EImap4SettingsMenu,
       
   440 		EImap4DumpMenu,
       
   441 		EHousekeepingMenu,
       
   442 		EOffLineOpMenu,
       
   443 		EOffLineOpQueueMenu,
       
   444 		EOffLineOpUnQueueMenu,
       
   445 		EOffLineOpQueueLocalToLocalMenu,
       
   446 		EConnectMenu,
       
   447 		EConnect2Menu,
       
   448 		EAutomationMenu,
       
   449 		ESynchroniseMenu,
       
   450 		EDebugMenu
       
   451 		};
       
   452 	};
       
   453 
       
   454 // -------------------------------------------------------------------------
       
   455 
       
   456 // Constants
       
   457 
       
   458 _LIT(KFilePathMailTest, "c:\\mailtest\\");
       
   459 
       
   460 #define KPeriod 10000	// period of timer
       
   461 
       
   462 // -------------------------------------------------------------------------
       
   463 
       
   464 TestUiTimer* TestUiTimer::NewL( CConsoleBase* aConsole, CBaseServerMtm* &aImppServerMtm)
       
   465 	{
       
   466 	TestUiTimer* self = new(ELeave) TestUiTimer( aConsole , aImppServerMtm);
       
   467 	CleanupStack::PushL(self);
       
   468 	self->iImppServerMtm = aImppServerMtm;
       
   469 	self->ConstructL();
       
   470 	CleanupStack::Pop();
       
   471 	return self;
       
   472 	}
       
   473 
       
   474 
       
   475 TestUiTimer::TestUiTimer( CConsoleBase* aConsole , CBaseServerMtm* &aImppServerMtm)
       
   476 	: CTimer(10 /*KMsgPop3RefreshMailboxPriority+1*/) , iImppServerMtm(aImppServerMtm)
       
   477 	{
       
   478 	iConsole = aConsole;
       
   479 	period = 	KPeriod;
       
   480 	iClosing = EFalse;
       
   481 	iCount = 0;
       
   482 	iDoneConnecting = EFalse;
       
   483 	}
       
   484 
       
   485 TestUiTimer::~TestUiTimer()
       
   486 	{
       
   487 	}
       
   488 
       
   489 void TestUiTimer::ConstructL()
       
   490 	{
       
   491 	CTimer::ConstructL();
       
   492 
       
   493 	CActiveScheduler::Add( this );
       
   494 	}
       
   495 
       
   496 
       
   497 void TestUiTimer::IssueRequest()
       
   498 	{
       
   499 	After( period );
       
   500 	}
       
   501 
       
   502 
       
   503 void TestUiTimer::DoCancel()
       
   504 	{
       
   505 	CTimer::DoCancel();
       
   506 	}
       
   507 
       
   508 TPtrC TestUiTimer::OpName(TImap4GenericProgress::TImap4GenericProgressOp aOp)
       
   509 	{
       
   510 	switch (aOp)
       
   511 		{
       
   512 	case TImap4GenericProgress::EConnect:
       
   513 		return _L("EConnect");
       
   514 	case TImap4GenericProgress::EDisconnect:
       
   515 		return _L("EDisconnect");
       
   516 	case TImap4GenericProgress::ESync:
       
   517 		return _L("ESync");
       
   518 	case TImap4GenericProgress::ESelect:
       
   519 		return _L("ESelect");
       
   520 		
       
   521 	case TImap4GenericProgress::ECopyToLocal:
       
   522 		return _L("ECopyToLocal");
       
   523 	case TImap4GenericProgress::ECopyWithinService:
       
   524 		return _L("ECopyWithinService");
       
   525 	case TImap4GenericProgress::ECopyFromLocal:
       
   526 		return _L("ECopyFromLocal");
       
   527 	case TImap4GenericProgress::EMoveToLocal:
       
   528 		return _L("EMoveToLocal");
       
   529 	case TImap4GenericProgress::EMoveWithinService:
       
   530 		return _L("EMoveWithinService");
       
   531 	case TImap4GenericProgress::EMoveFromLocal:
       
   532 		return _L("EMoveFromLocal");
       
   533 	case TImap4GenericProgress::EPopulate:
       
   534 		return _L("EPopulate");
       
   535 	case TImap4GenericProgress::EDelete:
       
   536 		return _L("EDelete");
       
   537 		
       
   538 	case TImap4GenericProgress::EOffLineDelete:
       
   539 	case TImap4GenericProgress::EOffLineUndelete:
       
   540 	case TImap4GenericProgress::EOffLineCopyToLocal:
       
   541 	case TImap4GenericProgress::EOffLineMoveToLocal:
       
   542 	case TImap4GenericProgress::EOffLineCopyFromLocal:
       
   543 	case TImap4GenericProgress::EOffLineMoveFromLocal:
       
   544 	case TImap4GenericProgress::EOffLineCopyWithinService:
       
   545 	case TImap4GenericProgress::EOffLineMoveWithinService:
       
   546 	case TImap4GenericProgress::EOffLinePopulate:
       
   547 		return _L("EOffLineOp");
       
   548 		
       
   549 	default:
       
   550 		test.Panic(_L("Unknown Op %d"),aOp);
       
   551 		break;
       
   552 		}
       
   553 	return _L("EUnknown");
       
   554 	}
       
   555 
       
   556 TPtrC TestUiTimer::StateName(TImap4GenericProgress::TImap4GenericProgressState aState)
       
   557 	{
       
   558 	switch (aState)
       
   559 		{
       
   560 	case TImap4GenericProgress::EDisconnected:
       
   561 		return _L("EDisconnected");
       
   562 	case TImap4GenericProgress::EConnecting:
       
   563 		return _L("EConnecting");
       
   564 	case TImap4GenericProgress::EIdle:
       
   565 		return _L("EIdle");
       
   566 	case TImap4GenericProgress::ESelecting:
       
   567 		return _L("ESelecting");
       
   568 	case TImap4GenericProgress::EFetching:
       
   569 		return _L("EFetching");
       
   570 	case TImap4GenericProgress::EAppending:
       
   571 		return _L("EAppending");
       
   572 	case TImap4GenericProgress::ECopying:
       
   573 		return _L("ECopying");
       
   574 	case TImap4GenericProgress::EDeleting:
       
   575 		return _L("EDeleting");
       
   576 	case TImap4GenericProgress::ESyncing:
       
   577 		return _L("ESyncing");
       
   578 	case TImap4GenericProgress::EDisconnecting:
       
   579 		return _L("EDisconnecting");
       
   580 	case TImap4GenericProgress::EBusy:		
       
   581 		return _L("EBusy");
       
   582 	default:
       
   583 		test.Panic(_L("Unknown State %d"),aState);
       
   584 		break;
       
   585 		}
       
   586 	return _L("EUnknown");
       
   587 	}
       
   588 
       
   589 
       
   590 TPtrC TestUiTimer::SyncStateName(TImap4SyncProgress::TImap4SyncProgressState aState)
       
   591 	{
       
   592 	switch (aState)
       
   593 		{
       
   594 	case TImap4SyncProgress::EIdle:
       
   595 		return _L("Idle");
       
   596 	case TImap4SyncProgress::EBusy:
       
   597 		return _L("Busy");
       
   598 	case TImap4SyncProgress::EConnecting:
       
   599 		return _L("Connecting");
       
   600 	case TImap4SyncProgress::EDisconnecting:
       
   601 		return _L("Disconnecting");
       
   602 	case TImap4SyncProgress::ESyncInbox:
       
   603 		return _L("SyncInbox");
       
   604 	case TImap4SyncProgress::ESyncFolderTree:
       
   605 		return _L("SyncFolderTree");
       
   606 	case TImap4SyncProgress::ECheckRemoteSubscription:
       
   607 		return _L("CheckRemoteSubscription");
       
   608 	case TImap4SyncProgress::EUpdateRemoteSubscription:
       
   609 		return _L("UpdateRemoteSubscription");
       
   610 	case TImap4SyncProgress::ESyncOther:
       
   611 		return _L("SyncOther");
       
   612 	case TImap4SyncProgress::EDeleting:
       
   613 		return _L("Deleting");
       
   614 	case TImap4SyncProgress::EProcessingPendingOps:
       
   615 		return _L("ProcPending");
       
   616 	default:
       
   617 		test.Panic(_L("Unknown SyncState %d"),aState);
       
   618 		break;
       
   619 		}
       
   620 	return _L("EUnknown");
       
   621 	}
       
   622 
       
   623 void TestUiTimer::Dump()
       
   624 	{
       
   625 	// display the current progress
       
   626 	TImap4CompoundProgress temp;	
       
   627 	TPckgC<TImap4CompoundProgress> paramPack(temp);
       
   628 
       
   629 	const TDesC8& progBuf = iImppServerMtm->Progress();	
       
   630 	paramPack.Set(progBuf);
       
   631 	TImap4CompoundProgress progress=paramPack();	
       
   632 
       
   633 	test.Console()->SetPos(0, 15);
       
   634 
       
   635 	if ( progress.iGenericProgress.iState == TImap4GenericProgress::EConnecting &&
       
   636 		 progress.iGenericProgress.iErrorCode == KErrNone )
       
   637 		{
       
   638 		if ( iDoneConnecting )
       
   639 			return;
       
   640 		iDoneConnecting = ETrue;
       
   641 		}
       
   642 	
       
   643 	TPtrC opName = OpName(progress.iGenericProgress.iOperation);
       
   644 	TPtrC stateName = StateName(progress.iGenericProgress.iState);
       
   645 
       
   646 	test.Printf(_L("%-11S: %-14S M %3d/%3d P %2d/%2d B %6d/%6d T %6d Err %d\n"),
       
   647 				&opName, &stateName,
       
   648 				progress.iGenericProgress.iMsgsDone, progress.iGenericProgress.iMsgsToDo,
       
   649 				progress.iGenericProgress.iPartsDone, progress.iGenericProgress.iPartsToDo,
       
   650 				progress.iGenericProgress.iBytesDone, progress.iGenericProgress.iBytesToDo,
       
   651 				progress.iGenericProgress.iTotalSize,
       
   652 				progress.iGenericProgress.iErrorCode);
       
   653 	
       
   654 	TPtrC syncName = SyncStateName(progress.iSyncProgress.iState);
       
   655 	test.Printf(_L("           : %-14S M %3d/%3d F %2d/%2d   \n"),
       
   656 				&syncName,
       
   657 				progress.iSyncProgress.iMsgsDone, progress.iSyncProgress.iMsgsToDo,
       
   658 				progress.iSyncProgress.iFoldersDone, progress.iSyncProgress.iFoldersToDo);
       
   659 	}
       
   660 
       
   661 void TestUiTimer::RunL()
       
   662 	{
       
   663 	Dump();
       
   664 	IssueRequest();
       
   665 	};
       
   666 
       
   667 // -------------------------------------------------------------------------
       
   668 
       
   669 // CTestRefresh CActive object
       
   670 CTestRefreshMBox::CTestRefreshMBox() // construct low-priority active object
       
   671 	: CActive(-3)
       
   672 	{
       
   673 	}
       
   674 
       
   675 CTestRefreshMBox  *CTestRefreshMBox::NewLC(CCommandLineArguments* aCmdLineArgs)
       
   676 	{
       
   677 	CTestRefreshMBox* self=new (ELeave) CTestRefreshMBox();
       
   678 	
       
   679 	CleanupStack::PushL(self);
       
   680 	self->iCmdLineArgs = aCmdLineArgs;
       
   681 	self->ConstructL();
       
   682 	return self;
       
   683 	}
       
   684 
       
   685 CTestRefreshMBox  *CTestRefreshMBox::NewL(CCommandLineArguments* aCmdLineArgs)
       
   686 	{
       
   687 	CTestRefreshMBox* self=NewLC(aCmdLineArgs);
       
   688 	CleanupStack::Pop();
       
   689 	return self;
       
   690 	}
       
   691 
       
   692 void CTestRefreshMBox::ConstructL()
       
   693 	{
       
   694 	iTestUtils = CEmailTestUtils::NewL(test);
       
   695 
       
   696 	iTestUtils->CreateAllTestDirectories();
       
   697 	iTestUtils->FileSession().SetSessionPath(_L("C:\\"));
       
   698 
       
   699 #if 1
       
   700 	test.Printf(_L("Remove message store? (y/N)\n"));
       
   701 	TChar choice;
       
   702 	if (iCmdLineArgs)
       
   703 		{
       
   704 		TLex lex(iCmdLineArgs->Arg(EArgRemoveMsgStore));
       
   705 		choice=lex.Get();
       
   706 		}
       
   707 	else
       
   708 		choice = test.Getch();
       
   709 	if (choice=='y' || choice=='Y')
       
   710 #endif
       
   711 		iTestUtils->Reset();
       
   712 		iTestUtils->CleanMessageFolderL();	
       
   713 		iTestUtils->ClearEmailAccountsL();
       
   714 		iTestUtils->GoClientSideL();
       
   715 	
       
   716 	iTestUtils->GoServerSideL();
       
   717 	iEntry = iTestUtils->iServerEntry;
       
   718 
       
   719 	CActiveScheduler::Add(this); // add to active scheduler
       
   720 
       
   721 	// Get server MTM.
       
   722 	iTestUtils->InstantiateImapServerMtmL();
       
   723 	iImppServerMtm = iTestUtils->iImapServerMtm;
       
   724 
       
   725 	iTestUtils->FileSession().SetSessionPath(_L("c:\\"));
       
   726 
       
   727 	test.Printf(_L("Created server mtm \n"));
       
   728 	// create an entry selection
       
   729 	iSelection = new (ELeave) CMsvEntrySelection;
       
   730 
       
   731 	test.Console()->ClearScreen(); // get rid of menu
       
   732 	User::LeaveIfError(iEntry->SetEntry(KMsvRootIndexEntryId));
       
   733 
       
   734 	// test num written to log
       
   735 	iTestNum = 1;
       
   736 
       
   737 	// default debug level
       
   738 	iDebugLevel = EDebugLevel3;
       
   739 	}
       
   740  
       
   741 CTestRefreshMBox::~CTestRefreshMBox()
       
   742 	{ 
       
   743 	Cancel(); // make sure we're cancelled
       
   744 
       
   745 	ClearTimer();
       
   746 
       
   747 	delete iSelection;
       
   748 	delete iTestUtils;
       
   749 	delete iLogView;
       
   750 	delete iLogClient;
       
   751 	delete iLogFilter;
       
   752 	}
       
   753 
       
   754 void  CTestRefreshMBox::DoCancel()
       
   755 	{
       
   756 	if (iTimer)
       
   757 		iTimer->Cancel();	// stop the timer
       
   758 	}
       
   759 
       
   760 void CTestRefreshMBox::StartL()
       
   761 	{
       
   762 	if (iCmdLineArgs)
       
   763 		iConsole->iIssueCancel=FALSE;
       
   764 	switch(iState)
       
   765 		{
       
   766 	case EImapTestConnect:
       
   767 		DoConnectL();
       
   768 		break;
       
   769 
       
   770 	case EImapTestConnectAndSync:
       
   771 		DoConnectAndSyncL();
       
   772 		break;
       
   773 
       
   774 	case EImapTestFullSync:
       
   775 		DoFullSyncL();
       
   776 		break;
       
   777 
       
   778 	case EImapTestInboxNewSync:
       
   779 		DoInboxNewSyncL();
       
   780 		break;
       
   781 
       
   782 	case EImapTestSyncTree:
       
   783 		DoSyncTreeL();
       
   784 		break;
       
   785 
       
   786 	case EImapTestFetchInbox:
       
   787 		DoFetchInboxL();
       
   788 		break;
       
   789 
       
   790 	case EImapTestDisconnect:
       
   791 		DoDisconnectL();
       
   792 		break;
       
   793 
       
   794 	case EImapTestAutoOffLineOp:
       
   795 		DoAutomatedOffLineOpsL();
       
   796 		break;
       
   797 
       
   798 	case EImapTestAutoSyncOp:
       
   799 		DoAutomatedSyncOpsL();
       
   800 		break;
       
   801 
       
   802 	case EImapTestAutoSecondaryConnect:
       
   803 		DoAutomatedSecondaryConnectOpsL();
       
   804 		break;
       
   805 
       
   806 	case EImapTestOffLineOp:
       
   807 		break;
       
   808 
       
   809 	case EImapTestCancelOffLineOps:
       
   810 		DoCancelOffLineOpsL();
       
   811 		break;
       
   812 
       
   813 	case EImapTestWaitForBackground:
       
   814 		DoWaitForBackgroundL();
       
   815 		break;
       
   816 
       
   817 	case EImapTestFetchAttachment:
       
   818 		DoFetchAttachmentL();
       
   819 		break;
       
   820 
       
   821 	case EImapTestRenameFolder:
       
   822 		DoRenameFolderL();
       
   823 		break;
       
   824 
       
   825 	case EImapTestFetchTest:
       
   826 		DoFetchTestL();
       
   827 		break;
       
   828 
       
   829 	case EImapTestFolderDelete:
       
   830 		DoFolderRemoveL();
       
   831 		break;
       
   832 
       
   833 	case EImapTestFolderCreate:
       
   834 		DoFolderCreateL(iServiceId, _L("Test1"));
       
   835 		break;
       
   836 
       
   837 	case EImapTestCheckServerContents:
       
   838 		DoCheckServerContentsL();
       
   839 		break;
       
   840 
       
   841 	case EImapTestNSynchronisation:	   
       
   842 		DoNSynchronisationRegressionL();
       
   843 		break;
       
   844 
       
   845 	case EImapTestNSynchronisationTests:
       
   846 		DoNSynchronisationTestsL();
       
   847 		break;
       
   848 
       
   849 	case EImapTestNSynchronisationSpecialTests:
       
   850 		DoNSynchronisationSpecialTestsL();
       
   851 		break;
       
   852 
       
   853 	case EImapTestNSynchronisationPerformanceTests:
       
   854 		DoNSynchronisationPerformanceTestsL();
       
   855 		break;
       
   856 
       
   857 	case EImapTestNSynchronisationOneOffTests:
       
   858 		DoNSynchronisationOneOffTestsL();
       
   859 		break;
       
   860 
       
   861     case EImapTestLocalSubscribe:
       
   862         PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("Test1")), KIMAP4MTMLocalSubscribe);
       
   863         break;
       
   864 
       
   865     case EImapTestLocalUnsubscribe:
       
   866         PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("Test1")), KIMAP4MTMLocalUnsubscribe);
       
   867         break;
       
   868 
       
   869 	case EImapTestFetchAttachedMessage:
       
   870 		DoFetchAttachedMessageL();
       
   871 		break;
       
   872 		
       
   873 	case EImapTestCopyMessages:
       
   874 		DoCopyMessagesL();
       
   875 		break;
       
   876 		}
       
   877 	}
       
   878 
       
   879 void CTestRefreshMBox::EndOfTest()
       
   880 	{
       
   881 	if (iCmdLineArgs)
       
   882 		{
       
   883 		iConsole->iIssueCancel=TRUE;
       
   884 		iConsole->DoCancel();
       
   885 		}
       
   886 	}
       
   887 
       
   888 const TInt KDebugLogMaxLineSize=256;
       
   889 
       
   890 void CTestRefreshMBox::DebugFormatL(TInt aDebugLevel,TRefByValue<const TDesC> aFmt,...)
       
   891 	{
       
   892 	// Log this debug text?
       
   893 	if (aDebugLevel>iDebugLevel)
       
   894 		return;
       
   895 
       
   896 	// Build parameter list.
       
   897 	VA_LIST list;
       
   898 	VA_START(list, aFmt);
       
   899 
       
   900 	// Print to log file.
       
   901 	TBuf<KDebugLogMaxLineSize> buf;
       
   902 	TRAPD(ret,buf.FormatList(aFmt, list));		
       
   903 
       
   904 	// Log the debug buffer.
       
   905 	if (ret==KErrNone)
       
   906 		iTestUtils->WriteComment(buf);
       
   907 	else
       
   908 		iTestUtils->WriteComment(_L("ERROR: Formatting debug output"));
       
   909 	}
       
   910 
       
   911 void CTestRefreshMBox::DebugUidListL(TInt /*aDebugLevel*/)
       
   912 	{
       
   913 #if 0	// crashes on big test
       
   914 	
       
   915 	// Log this debug text?
       
   916 	if (aDebugLevel>iDebugLevel)
       
   917 		return;
       
   918 
       
   919 	// Build list of UIDs.
       
   920 	TBuf<KDebugLogMaxLineSize> buf;
       
   921  	TMsvEntry* entryPtr;
       
   922 	for (TInt i=0;i<iSelection->Count();i++)
       
   923 		{
       
   924 		TRAPD(ret,buf.AppendFormat(i?_L(", "):_L("UID list: ")));
       
   925 		if (!ret)
       
   926 			{
       
   927 			User::LeaveIfError(iEntry->GetEntryFromId((*iSelection)[i],entryPtr));
       
   928 			TRAPD(ret,buf.AppendFormat(_L("%d"),((TMsvEmailEntry)(*entryPtr)).UID()));		
       
   929 			if (ret!=KErrNone)
       
   930 				{
       
   931 				iTestUtils->WriteComment(_L("ERROR: Formatting debug output"));
       
   932 				return;
       
   933 				}
       
   934 			}
       
   935 		}
       
   936 
       
   937 	// Log the debug buffer.
       
   938 	iTestUtils->WriteComment(buf);
       
   939 #endif
       
   940 	}
       
   941 
       
   942 void CTestRefreshMBox::EnterStateL(TInt aState)
       
   943 	{
       
   944 	iState = aState;
       
   945 	StartL();
       
   946 	}
       
   947 
       
   948 void CTestRefreshMBox::StartTimerL()
       
   949 	{
       
   950 	if (!iTimer)
       
   951 		{
       
   952 		iTimer = TestUiTimer::NewL( test.Console(), iImppServerMtm );
       
   953 		iTimer->IssueRequest( );	// START THE OBSERVATION TIMER
       
   954 		}
       
   955 	}
       
   956 
       
   957 void CTestRefreshMBox::ClearTimer()
       
   958 	{
       
   959 	if (iTimer)
       
   960 		{
       
   961 		// output last known state before clearing
       
   962 		iTimer->Dump();
       
   963 		
       
   964 		delete iTimer;
       
   965 		iTimer = NULL;
       
   966 		}
       
   967 	}
       
   968 
       
   969 CMsvServerEntry* CTestRefreshMBox::ServerEntry()
       
   970 	{
       
   971 	return iEntry;
       
   972 	}
       
   973 
       
   974 void CTestRefreshMBox::SelectServiceIdL()
       
   975 	{
       
   976 	User::LeaveIfError(iEntry->SetEntry(iServiceId));
       
   977 	}
       
   978 
       
   979 CMsvServerEntry* CTestRefreshMBox::SetEntryL(TMsvId aFolder, const TDesC& aName)
       
   980 	{
       
   981 	TMsvId id = FindMessageByNameL(aFolder, aName);
       
   982 	User::LeaveIfError(iEntry->SetEntry(id));
       
   983 	return iEntry;
       
   984 	}
       
   985 
       
   986 void CTestRefreshMBox::DoConnectAndSyncL()
       
   987 	{
       
   988 	// Kick off connection to specified service
       
   989 	test.Console()->SetPos(0, 13);
       
   990 	test.Printf(_L("DoConnectAndSync\n"));
       
   991 
       
   992 	iSelection->Reset();
       
   993 	iSelection->AppendL(iServiceId);
       
   994 	TBuf8<128> paramBuf(_L8(""));
       
   995 
       
   996 	SetActive();
       
   997 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMConnectAndSynchronise,paramBuf,iStatus);
       
   998 
       
   999 	// create the progress Timer object
       
  1000 	StartTimerL();
       
  1001 	}
       
  1002 
       
  1003 void CTestRefreshMBox::DoConnectL()
       
  1004 	{
       
  1005 	// Kick off connection to specified service
       
  1006 	test.Console()->SetPos(0, 13);
       
  1007 	test.Printf(_L("DoConnect\n"));
       
  1008 
       
  1009 	iSelection->Reset();
       
  1010 	iSelection->AppendL(iServiceId);
       
  1011 	TBuf8<128> paramBuf(_L8(""));
       
  1012 
       
  1013 	SetActive();
       
  1014 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMConnect,paramBuf,iStatus);
       
  1015 
       
  1016 	// create the progress Timer object
       
  1017 	StartTimerL();
       
  1018 	}
       
  1019 
       
  1020 void CTestRefreshMBox::DoFullSyncL()
       
  1021 	{
       
  1022 	// Kick off connection to specified service
       
  1023 	test.Console()->SetPos(0, 13);
       
  1024 	test.Printf(_L("DoFullSync\n"));
       
  1025 
       
  1026 	iSelection->Reset();
       
  1027 	TBuf8<128> paramBuf(_L8(""));
       
  1028 
       
  1029 	SetActive();
       
  1030 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMFullSync,paramBuf,iStatus);
       
  1031 
       
  1032 	// create the progress Timer object
       
  1033 	StartTimerL();
       
  1034 	}
       
  1035 
       
  1036 void CTestRefreshMBox::DoInboxNewSyncL()
       
  1037 	{
       
  1038 	// Kick off connection to specified service
       
  1039 	test.Console()->SetPos(0, 13);
       
  1040 	test.Printf(_L("DoInboxNewSync\n"));
       
  1041 
       
  1042 	iSelection->Reset();
       
  1043 	TBuf8<128> paramBuf(_L8(""));
       
  1044 
       
  1045 	SetActive();
       
  1046 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMInboxNewSync,paramBuf,iStatus);
       
  1047 
       
  1048 	// create the progress Timer object
       
  1049 	StartTimerL();
       
  1050 	}
       
  1051 
       
  1052 void CTestRefreshMBox::DoSyncTreeL()
       
  1053 	{
       
  1054 	// Kick off connection to specified service
       
  1055 	test.Console()->SetPos(0, 13);
       
  1056 	test.Printf(_L("DoSyncTree\n"));
       
  1057 
       
  1058 	iSelection->Reset();
       
  1059 	TBuf8<128> paramBuf(_L8(""));
       
  1060 
       
  1061 	SetActive();
       
  1062 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMSyncTree,paramBuf,iStatus);
       
  1063 
       
  1064 	// create the progress Timer object
       
  1065 	StartTimerL();
       
  1066 	}
       
  1067 
       
  1068 void CTestRefreshMBox::DoFetchTestL()
       
  1069 	{
       
  1070 	test.Console()->SetPos(0, 13);
       
  1071 	test.Printf(_L("DoFetchTest\n"));
       
  1072 
       
  1073 	TMsvId id = FindMessageByNameL(iRemoteInbox, KMessageNameTest);
       
  1074 
       
  1075 	// check message is there
       
  1076 	test(id != KErrNone);
       
  1077 	test(id != KErrNotFound);
       
  1078 
       
  1079 	iSelection->Reset();
       
  1080 	iSelection->AppendL(id);
       
  1081 	
       
  1082 	SetActive();
       
  1083 	iImppServerMtm->CopyToLocalL(*iSelection, KMsvGlobalInBoxIndexEntryId, iStatus);
       
  1084 
       
  1085 	StartTimerL();
       
  1086 	}
       
  1087 
       
  1088 void CTestRefreshMBox::DoFetchInboxL()
       
  1089 	{
       
  1090 	test.Console()->SetPos(0, 13);
       
  1091 	test.Printf(_L("DoFetchInbox\n"));
       
  1092 
       
  1093 	User::LeaveIfError(iEntry->SetEntry( iRemoteInbox ));
       
  1094 
       
  1095 	User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  1096 
       
  1097 	// strip out any nested folders
       
  1098 	TInt a=0;
       
  1099 	while (a<iSelection->Count())
       
  1100 		{
       
  1101 		iEntry->SetEntry((*iSelection)[a]);
       
  1102 		if (iEntry->Entry().iType == KUidMsvFolderEntry)
       
  1103 			iSelection->Delete(a);
       
  1104 		else
       
  1105 			a++;
       
  1106 		}
       
  1107 	
       
  1108 	SetActive();
       
  1109 	iImppServerMtm->CopyToLocalL(*iSelection, KMsvGlobalInBoxIndexEntryId, iStatus);
       
  1110 
       
  1111 	StartTimerL();
       
  1112 	}
       
  1113 
       
  1114 void CTestRefreshMBox::DoDisconnectL()
       
  1115 	{
       
  1116 	test.Console()->SetPos(0, 13);
       
  1117 	test.Printf(_L("DoDisconnect\n"));
       
  1118 
       
  1119 	TBuf8<128> paramBuf(_L8(""));
       
  1120 
       
  1121 	SetActive();
       
  1122 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMDisconnect,paramBuf,iStatus);
       
  1123 
       
  1124 	StartTimerL();
       
  1125 	}
       
  1126 
       
  1127 void CTestRefreshMBox::DoWaitForBackgroundL()
       
  1128 	{
       
  1129 	test.Console()->SetPos(0, 13);
       
  1130 	test.Printf(_L("DoWaitForBackground\n"));
       
  1131 
       
  1132 	TBuf8<128> paramBuf(_L8(""));
       
  1133 
       
  1134 	SetActive();
       
  1135 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMWaitForBackground,paramBuf,iStatus);
       
  1136 	}
       
  1137 
       
  1138 
       
  1139 void CTestRefreshMBox::FindMessagesInSelectionL()
       
  1140 	{
       
  1141 	TInt i=0;
       
  1142 	while (i<iSelection->Count())
       
  1143 		{
       
  1144 		User::LeaveIfError(iEntry->SetEntry((*iSelection)[i]));
       
  1145 		TMsvEmailEntry entry=iEntry->Entry();
       
  1146 		if (entry.iType!=KUidMsvMessageEntry)
       
  1147 			iSelection->Delete(i,1);
       
  1148 		else
       
  1149 			i++;
       
  1150 		}
       
  1151 	}
       
  1152 
       
  1153 void CTestRefreshMBox::FindAttachmentL()
       
  1154 	{
       
  1155 	TMsvId id = FindMessageByNameL(iRemoteInbox, KMessageNameAttachment);
       
  1156 	if (id == KErrNotFound)
       
  1157 		User::Leave(KErrNotFound);
       
  1158 
       
  1159 	User::LeaveIfError(iEntry->SetEntry(id));
       
  1160 	User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvFolderEntry, *iSelection));
       
  1161 	if (iSelection->Count() == 0)
       
  1162 		User::Leave(KErrNotFound);
       
  1163 
       
  1164 	User::LeaveIfError(iEntry->SetEntry((*iSelection)[0]));
       
  1165 	User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvAttachmentEntry, *iSelection));
       
  1166 	if (iSelection->Count() == 0)
       
  1167 		User::Leave(KErrNotFound);
       
  1168 	}
       
  1169 
       
  1170 void CTestRefreshMBox::DoFetchAttachmentL()
       
  1171 	{
       
  1172 	test.Console()->SetPos(0, 13);
       
  1173 	test.Printf(_L("DoFetchAttachment\n"));
       
  1174 
       
  1175 	// get attachment id into selection
       
  1176 	FindAttachmentL();
       
  1177 	
       
  1178 	SetActive();
       
  1179 
       
  1180 	TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailBodyTextAndAttachments);
       
  1181     iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMPopulate,package,iStatus);
       
  1182 
       
  1183 	// create the progress Timer object
       
  1184 	StartTimerL();
       
  1185 	}
       
  1186 
       
  1187 void CTestRefreshMBox::DoFetchAttachedMessageL()
       
  1188 	{
       
  1189 	test.Console()->SetPos(0, 13);
       
  1190 	test.Printf(_L("DoFetchAttachedMessage\n"));
       
  1191 
       
  1192 	TMsvId id = FindMessageByNameL(iRemoteInbox, KMessageNameAttachment);
       
  1193 	if (id == KErrNotFound)
       
  1194 		User::Leave(KErrNotFound);
       
  1195 
       
  1196 	User::LeaveIfError(iEntry->SetEntry(id));
       
  1197 	User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvFolderEntry, *iSelection));
       
  1198 	if (iSelection->Count() == 0)
       
  1199 		User::Leave(KErrNotFound);
       
  1200 
       
  1201 	User::LeaveIfError(iEntry->SetEntry((*iSelection)[0]));
       
  1202 	User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  1203 	if (iSelection->Count() == 0)
       
  1204 		User::Leave(KErrNotFound);
       
  1205 
       
  1206 	SetActive();
       
  1207 	TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailBodyTextAndAttachments);
       
  1208     iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMPopulate,package,iStatus);
       
  1209 
       
  1210 	// create the progress Timer object
       
  1211 	StartTimerL();
       
  1212 	}
       
  1213 
       
  1214 void CTestRefreshMBox::DoCopyMessagesL()
       
  1215 	{
       
  1216 	test.Console()->SetPos(0, 13);
       
  1217 	test.Printf(_L("DoCopyMessages\n"));
       
  1218 
       
  1219 	iSelection->Reset();
       
  1220 
       
  1221 	User::LeaveIfError(iEntry->SetEntry( iRemoteInbox ));
       
  1222 	User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  1223 
       
  1224 	SetActive();
       
  1225 	iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteFolder2, iStatus);
       
  1226 
       
  1227 	// create the progress Timer object
       
  1228 	StartTimerL();
       
  1229 	}
       
  1230 
       
  1231 void CTestRefreshMBox::DoFolderCreateL()
       
  1232 	{
       
  1233 	DoFolderCreateL(iServiceId, KMessageNameTest);
       
  1234 	}
       
  1235 
       
  1236 void CTestRefreshMBox::DoFolderCreateL(TMsvId aParent, const TDesC& aName)
       
  1237 	{
       
  1238 	test.Console()->SetPos(0, 13);
       
  1239 	test.Printf(_L("DoFolderCreate\n"));
       
  1240 
       
  1241 	// visit service
       
  1242 	User::LeaveIfError(iEntry->SetEntry(aParent));
       
  1243 
       
  1244 	// create the msventry
       
  1245 	TMsvEmailEntry newEntry;
       
  1246 	newEntry.iType=KUidMsvFolderEntry;
       
  1247 	newEntry.iMtm=iEntry->Entry().iMtm;
       
  1248 	newEntry.iServiceId=iServiceId;
       
  1249 	newEntry.iSize=0;
       
  1250 	newEntry.iDetails.Set(aName);
       
  1251 	newEntry.SetMailbox(ETrue);
       
  1252 	newEntry.SetValidUID(EFalse);
       
  1253 	newEntry.SetComplete(ETrue);
       
  1254 	newEntry.SetVisible(ETrue);
       
  1255 	User::LeaveIfError(iEntry->CreateEntry(newEntry));
       
  1256 
       
  1257 	// tell the IMAP server about it
       
  1258 	SetActive();
       
  1259 	TRAPD(err, iImppServerMtm->CreateL(newEntry,iStatus));
       
  1260 	if (err != KErrNone)
       
  1261 		test.Printf(_L("Op FolderCreate left with error %d\n"), err);
       
  1262 	
       
  1263 	StartTimerL();
       
  1264 	}
       
  1265 
       
  1266 void CTestRefreshMBox::DoFolderRemoveL()
       
  1267 	{
       
  1268 	DoFolderRemoveL(iServiceId, _L("Test1"));
       
  1269 	}
       
  1270 
       
  1271 void CTestRefreshMBox::DoFolderRemoveL(TMsvId aParent, const TDesC& aName)
       
  1272 	{
       
  1273 	test.Console()->SetPos(0, 13);
       
  1274 	test.Printf(_L("DoFolderRemove\n"));
       
  1275 
       
  1276 	TMsvId id = FindFolderByNameL(aParent, aName);
       
  1277 	if (id == KErrNotFound)
       
  1278 		{
       
  1279 		test.Printf(_L("Can't find folder '%S'\n"),&aName);
       
  1280 		return;
       
  1281 		}
       
  1282 
       
  1283 	iSelection->Reset();
       
  1284 	iSelection->AppendL(id);
       
  1285 
       
  1286 	TBuf8<128> params(_L8(""));
       
  1287 	TRAPD(err, PerformOpL(EImap4OpDelete,params));
       
  1288 	if (err != KErrNone)
       
  1289 		test.Printf(_L("Op FolderDelete left with error %d\n"), err);
       
  1290 
       
  1291 	StartTimerL();
       
  1292 	}
       
  1293 
       
  1294 TPtrC CTestRefreshMBox::TestMsgName(TImap4OpType aOpType,
       
  1295 									TImap4GetMailOptions aOptions=EGetImap4EmailBodyTextAndAttachments)
       
  1296 	{
       
  1297 	switch (aOpType)
       
  1298 		{
       
  1299 	case EImap4OpCopyToLocal:
       
  1300 		return _L("Test: 22");
       
  1301 	case EImap4OpCopyFromLocal:
       
  1302 		return _L("Test: 21");
       
  1303 	case EImap4OpCopyWithinService:
       
  1304 		return _L("Test: 20");
       
  1305 			
       
  1306 	case EImap4OpMoveToLocal:
       
  1307 		return _L("Test: 19");
       
  1308 	case EImap4OpMoveFromLocal:
       
  1309 		return _L("Test: 18");
       
  1310 	case EImap4OpMoveWithinServiceToInbox:
       
  1311 	case EImap4OpMoveWithinService:
       
  1312 		return _L("Test: 17");
       
  1313 
       
  1314 	case EImap4OpDelete:
       
  1315 		return _L("Test: 16");
       
  1316 
       
  1317 	case EImap4OpPopulate:
       
  1318 		switch (aOptions)
       
  1319 			{
       
  1320 		case EGetImap4EmailHeaders:
       
  1321 			return _L("Test: 9");
       
  1322 		case EGetImap4EmailBodyText:
       
  1323 			return _L("Test: 11");
       
  1324 		case EGetImap4EmailBodyTextAndAttachments:
       
  1325 			return _L("Test: 12");
       
  1326 		case EGetImap4EmailAttachments:
       
  1327 			return _L("Test: 10");
       
  1328 			}
       
  1329 		return _L("Test: 9");
       
  1330 
       
  1331 	case EImap4OpCopyWithinFolder:
       
  1332 		return _L("Test: 8");
       
  1333 
       
  1334 	case EImap4OpCopyToLocalAndDelete:
       
  1335 		return _L("Test: 7");
       
  1336 	case EImap4OpCopyFromLocalAndDelete:
       
  1337 		return _L("Test: 6");
       
  1338 	case EImap4OpCopyWithinServiceAndDelete:
       
  1339 		return _L("Test: 5");
       
  1340 			
       
  1341 	case EImap4OpMoveToLocalAndDelete:
       
  1342 		return _L("Test: 4");
       
  1343 	case EImap4OpMoveFromLocalAndDelete:
       
  1344 		return _L("Test: 3");
       
  1345 	case EImap4OpMoveWithinServiceAndDelete:
       
  1346 		return _L("Test: 27");
       
  1347 	default:
       
  1348 		break;
       
  1349 		}
       
  1350 	return _L("");
       
  1351 	}
       
  1352 
       
  1353 void CTestRefreshMBox::TestFolders(TImap4OpType aOpType,
       
  1354 								   TMsvId& srcFolder, TMsvId& destination)
       
  1355 	{
       
  1356 	if (aOpType == EImap4OpCopyToLocal ||
       
  1357 		aOpType == EImap4OpMoveToLocal)
       
  1358 		{
       
  1359 		destination = iLocalFolder1;
       
  1360 		srcFolder = iRemoteInbox;
       
  1361 		}
       
  1362 	else if (aOpType == EImap4OpCopyFromLocal ||
       
  1363 		aOpType == EImap4OpMoveFromLocal)
       
  1364 		{
       
  1365 		destination = iRemoteFolder1;
       
  1366 		srcFolder = KMsvGlobalInBoxIndexEntryId;
       
  1367 		}
       
  1368 	else if (aOpType == EImap4OpCopyWithinService ||
       
  1369 		aOpType == EImap4OpMoveWithinService)
       
  1370 		{
       
  1371 		destination = iRemoteFolder2;
       
  1372 		srcFolder = iRemoteInbox;
       
  1373 		}
       
  1374 	else if (aOpType == EImap4OpMoveWithinServiceToInbox)
       
  1375 		{
       
  1376 		destination = iRemoteInbox;
       
  1377 		srcFolder = iRemoteFolder2;
       
  1378 		}
       
  1379 	else
       
  1380 		{
       
  1381 		destination = iRemoteInbox;
       
  1382 		srcFolder = iRemoteInbox;
       
  1383 		}
       
  1384 	}
       
  1385 
       
  1386 
       
  1387 TMsvId CTestRefreshMBox::CountMessagesByNameL(TMsvId aSrcFolder, const TDesC& aName)
       
  1388 	{
       
  1389 	CMsvEntrySelection* children = new (ELeave) CMsvEntrySelection;
       
  1390 	CleanupStack::PushL(children);
       
  1391 
       
  1392 	User::LeaveIfError(iEntry->SetEntry( aSrcFolder ));
       
  1393 	User::LeaveIfError(iEntry->GetChildren( *children ));
       
  1394 
       
  1395 	TInt r = 0;
       
  1396 	for (TInt i=0; i < children->Count(); i++)
       
  1397 		{
       
  1398 		User::LeaveIfError(iEntry->SetEntry( (*children)[i] ));
       
  1399 		if ( iEntry->Entry().iDescription.Compare(aName) == 0 )
       
  1400 			r++;
       
  1401 		}
       
  1402 
       
  1403 	CleanupStack::PopAndDestroy();
       
  1404 
       
  1405 	return r;
       
  1406 	}
       
  1407 
       
  1408 // searches on Description field
       
  1409 TMsvId CTestRefreshMBox::FindMessageByNameL(TMsvId aSrcFolder, const TDesC& aName)
       
  1410 	{
       
  1411 	return FindByNameL(aSrcFolder, aName, EFalse);
       
  1412 	}
       
  1413 
       
  1414 // searches on Details field
       
  1415 TMsvId CTestRefreshMBox::FindFolderByNameL(TMsvId aSrcFolder, const TDesC& aName)
       
  1416 	{
       
  1417 	CMsvEntrySelection* children = new (ELeave) CMsvEntrySelection;
       
  1418 	CleanupStack::PushL(children);
       
  1419 	TMsvId r = KErrNotFound;
       
  1420 	User::LeaveIfError(iEntry->SetEntry( aSrcFolder ));
       
  1421 	iEntry->GetChildrenWithType(KUidMsvFolderEntry, *children);
       
  1422 
       
  1423 	children->InsertL(0, aSrcFolder);
       
  1424 	
       
  1425 	for (TInt i=0; i < children->Count(); i++)
       
  1426 		{
       
  1427 		r = FindByNameL((*children)[i], aName, ETrue);
       
  1428 		if(r != KErrNotFound)
       
  1429 			break;
       
  1430 		}
       
  1431 
       
  1432 	CleanupStack::PopAndDestroy();
       
  1433 	return r;
       
  1434 	}
       
  1435 
       
  1436 // searches on Details or Description field and recurses
       
  1437 TMsvId CTestRefreshMBox::FindByNameL(TMsvId aSrcFolder, const TDesC& aName, TBool aSearchOnDetails)
       
  1438 	{
       
  1439 	CMsvEntrySelection* children = new (ELeave) CMsvEntrySelection;
       
  1440 	CleanupStack::PushL(children);
       
  1441 
       
  1442 	User::LeaveIfError(iEntry->SetEntry( aSrcFolder ));
       
  1443 	User::LeaveIfError(iEntry->GetChildren( *children ));
       
  1444 
       
  1445 	// isolate up to the first slash if any
       
  1446 	TPtrC match = aName;
       
  1447 	TPtrC remains = _L("");
       
  1448 	TInt slash = aName.Locate('/');
       
  1449 	if (slash != -1)
       
  1450 		{
       
  1451 		match.Set(aName.Left(slash));
       
  1452 		remains.Set(aName.Mid(slash+1));
       
  1453 		}
       
  1454 	
       
  1455 	TMsvId r = KErrNotFound;
       
  1456 	for (TInt i=0; i < children->Count(); i++)
       
  1457 		{
       
  1458 		User::LeaveIfError(iEntry->SetEntry( (*children)[i] ));
       
  1459 		if ( ( aSearchOnDetails && iEntry->Entry().iDetails.Compare(match) == 0 ) ||
       
  1460 			 (!aSearchOnDetails && iEntry->Entry().iDescription.Compare(match) == 0 ) )
       
  1461 			{
       
  1462 			r = (*children)[i];
       
  1463 			if (remains.Length())
       
  1464 				r = FindByNameL(r, remains, aSearchOnDetails);
       
  1465 			break;
       
  1466 			}
       
  1467 		}
       
  1468 
       
  1469 	CleanupStack::PopAndDestroy();
       
  1470 
       
  1471 	return r;
       
  1472 	}
       
  1473 
       
  1474 TMsvId CTestRefreshMBox::FindMessageByOpL(TMsvId aSrcFolder, TImap4OpType aOp)
       
  1475 	{
       
  1476 	TPtrC name = TestMsgName(aOp);
       
  1477 	return FindMessageByNameL(aSrcFolder, name);
       
  1478 	}
       
  1479 	
       
  1480 TMsvId CTestRefreshMBox::FindMessageByOpL(TMsvId aSrcFolder, TImap4OpType aOp, TImap4GetMailOptions aOptions)
       
  1481 	{
       
  1482 	TPtrC name = TestMsgName(aOp, aOptions);
       
  1483 	return FindMessageByNameL(aSrcFolder, name);
       
  1484 	}
       
  1485 	
       
  1486 TInt CTestRefreshMBox::CountMessagesByOpL(TMsvId aSrcFolder, TImap4OpType aOp)
       
  1487 	{
       
  1488 	TPtrC name = TestMsgName(aOp);
       
  1489 	return CountMessagesByNameL(aSrcFolder, name);
       
  1490 	}
       
  1491 	
       
  1492 /* ----------------------------------------------------------------------- */
       
  1493 
       
  1494 CImHeader* CTestRefreshMBox::GetHeaderLC()
       
  1495 	{
       
  1496 	CImHeader* messageheader=CImHeader::NewLC();
       
  1497 
       
  1498 	CMsvStore* entryStore=iEntry->ReadStoreL();
       
  1499 	CleanupStack::PushL(entryStore);
       
  1500 	
       
  1501 	messageheader->RestoreL(*entryStore);
       
  1502 	
       
  1503 	CleanupStack::PopAndDestroy(); // store
       
  1504 
       
  1505 	return messageheader;
       
  1506 	}
       
  1507 
       
  1508 
       
  1509 void CTestRefreshMBox::TestPriorityAndReceiptAddressL()
       
  1510 	{
       
  1511 	iTestUtils->TestStart(iTestNum, _L("TestPriorities"));
       
  1512 
       
  1513 	SetEntryL(iRemoteInbox, KMessageNamePriority);
       
  1514 	test(iEntry->Entry().Priority() == EMsvHighPriority );
       
  1515 	SetEntryL(iRemoteInbox, KMessageNameXPriority);
       
  1516 	test(iEntry->Entry().Priority() == EMsvHighPriority );
       
  1517 	SetEntryL(iRemoteInbox, KMessageNamePrecedence);
       
  1518 	test(iEntry->Entry().Priority() == EMsvHighPriority );
       
  1519 	SetEntryL(iRemoteInbox, KMessageNameImportance);
       
  1520 	test(iEntry->Entry().Priority() == EMsvHighPriority );
       
  1521 
       
  1522 	iTestUtils->TestFinish(iTestNum++);
       
  1523 
       
  1524 	iTestUtils->TestStart(iTestNum, _L("TestReceipts"));
       
  1525 
       
  1526 #if 0
       
  1527 	CImHeader *hdr;
       
  1528 
       
  1529 	SetEntryL(iRemoteInbox, KMessageNameReturnReceiptTo);
       
  1530 	hdr=GetHeaderLC();
       
  1531 	test( hdr->ReceiptAddress().Compare( KReceiptAddress ) == 0);
       
  1532 	CleanupStack::PopAndDestroy(); // hdr
       
  1533 	
       
  1534 	// these tests won't work anymore as the CImMailHeader store that
       
  1535 	// holds this information is not available at this point
       
  1536 	SetEntryL(iRemoteInbox, KMessageNameXReturnReceiptTo);
       
  1537 	hdr=GetHeaderLC();
       
  1538 	test( hdr->ReceiptAddress().Compare( KReceiptAddress ) == 0);
       
  1539 	CleanupStack::PopAndDestroy(); // hdr
       
  1540 
       
  1541 	SetEntryL(iRemoteInbox, KMessageNameDispositionNotificationTo);
       
  1542 	hdr=GetHeaderLC();
       
  1543 	test( hdr->ReceiptAddress().Compare( KReceiptAddress ) == 0 ||
       
  1544 		  hdr->ReceiptAddress().Compare( KReceiptAddress1 ) == 0);
       
  1545 	CleanupStack::PopAndDestroy(); // hdr
       
  1546 
       
  1547 #endif
       
  1548 	iTestUtils->TestFinish(iTestNum++);
       
  1549 
       
  1550 	iTestUtils->TestStart(iTestNum, _L("Test MHTML flags"));
       
  1551 
       
  1552 	// check mime html has mime and not attachment flag
       
  1553 	SetEntryL(iRemoteInbox, KMessageNameMimeHTML);
       
  1554 	TMsvEmailEntry entry = (TMsvEmailEntry)iEntry->Entry();
       
  1555 	test(entry.MHTMLEmail());
       
  1556 	test(!entry.Attachment());
       
  1557 
       
  1558 	iTestUtils->TestFinish(iTestNum++);
       
  1559 	
       
  1560 	iTestUtils->TestStart(iTestNum, _L("Test modified UTF7"));
       
  1561 
       
  1562 	// check the encoded folder name worked
       
  1563 	test(FindFolderByNameL(iServiceId, KFolderNameToEncode) != KErrNone);
       
  1564 
       
  1565 	iTestUtils->TestFinish(iTestNum++);
       
  1566 	}
       
  1567 
       
  1568 void CTestRefreshMBox::PerformSpecialOpL(TMsvId aId, TImap4Cmds aCommand)
       
  1569 	{
       
  1570 #if defined (_DEBUG_MTMCOMMAND_)
       
  1571 	TBuf<256> buf;
       
  1572 	buf.Format(_L("MTMCommand %d on id %d\n"), aCommand, aId);
       
  1573 	iTestUtils->WriteComment(buf);
       
  1574 #endif
       
  1575 
       
  1576 	iSourceId = aId;
       
  1577 
       
  1578 	TBuf8<128> paramBuf(_L8(""));
       
  1579 	iSelection->Reset();
       
  1580 	iSelection->AppendL(aId);
       
  1581 	iImppServerMtm->StartCommandL(*iSelection,aCommand,paramBuf,iStatus);
       
  1582 	SetActive();
       
  1583 	}
       
  1584 
       
  1585 /* ----------------------------------------------------------------------- */
       
  1586 
       
  1587 void CTestRefreshMBox::PerformOpL( TImap4OpType aOpType, const TDesC8& aParams)
       
  1588 	{
       
  1589 	TBuf<256> buf;
       
  1590 	buf.Format(_L("Command %d on id %d (total %d) to folder %d\n"), aOpType,
       
  1591 			   iSelection->Count() ? (*iSelection)[0] : 0,
       
  1592 			   iSelection->Count(), iDestFolder);
       
  1593 	iTestUtils->WriteComment(buf);
       
  1594 
       
  1595 	SetActive();
       
  1596 	switch (aOpType)
       
  1597 		{
       
  1598 	case EImap4OpCopyToLocal:
       
  1599 	case EImap4OpCopyToLocalAndDelete:
       
  1600 		iImppServerMtm->CopyToLocalL(*iSelection, iDestFolder, iStatus);
       
  1601 		break;
       
  1602 	case EImap4OpCopyFromLocal:
       
  1603 	case EImap4OpCopyFromLocalAndDelete:
       
  1604 		iImppServerMtm->CopyFromLocalL(*iSelection, iDestFolder, iStatus);
       
  1605 		break;
       
  1606 	case EImap4OpCopyWithinFolder:
       
  1607 	case EImap4OpCopyWithinService:
       
  1608 	case EImap4OpCopyWithinServiceAndDelete:
       
  1609 		iImppServerMtm->CopyWithinServiceL(*iSelection, iDestFolder, iStatus);
       
  1610 		break;	
       
  1611 		
       
  1612 	case EImap4OpMoveToLocal:
       
  1613 	case EImap4OpMoveToLocalAndDelete:
       
  1614 		iImppServerMtm->MoveToLocalL(*iSelection, iDestFolder, iStatus);
       
  1615 		break;
       
  1616 	case EImap4OpMoveFromLocal:
       
  1617 	case EImap4OpMoveFromLocalAndDelete:
       
  1618 		iImppServerMtm->MoveFromLocalL(*iSelection, iDestFolder, iStatus);
       
  1619 		break;
       
  1620 	case EImap4OpMoveWithinService:
       
  1621 	case EImap4OpMoveWithinServiceAndDelete:
       
  1622 	case EImap4OpMoveWithinServiceToInbox:
       
  1623 		iImppServerMtm->MoveWithinServiceL(*iSelection, iDestFolder, iStatus);
       
  1624 		break;
       
  1625 
       
  1626 	case EImap4OpDelete:
       
  1627 		iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  1628 		break;
       
  1629 
       
  1630 	case EImap4OpUndelete:
       
  1631 		iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMUndeleteAll,aParams,iStatus);
       
  1632 		break;
       
  1633 
       
  1634 	case EImap4OpPopulate:
       
  1635 		iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMPopulate,aParams,iStatus);
       
  1636 		break;
       
  1637 
       
  1638 	default:
       
  1639 		break;
       
  1640 		}
       
  1641 	}
       
  1642 
       
  1643 void CTestRefreshMBox::DoOpByIdL( TImap4OpType aOpType, TMsvId aId )
       
  1644 	{
       
  1645 	iSourceId = aId;
       
  1646 
       
  1647 	TBuf8<128> paramBuf(_L8(""));
       
  1648 
       
  1649 	iSelection->Reset();
       
  1650 	iSelection->AppendL(iSourceId);
       
  1651 
       
  1652 	TRAPD(err, PerformOpL(aOpType,paramBuf));
       
  1653 	if (err != KErrNone)
       
  1654 		test.Printf(_L("Op %d left with error %d\n"), aOpType, err);
       
  1655 	}
       
  1656 
       
  1657 void CTestRefreshMBox::DoOpByIdL( TImap4OpType aOpType, TMsvId aId, const TDesC8& aParams )
       
  1658 	{
       
  1659 	iSourceId = aId;
       
  1660 
       
  1661 	iSelection->Reset();
       
  1662 	iSelection->AppendL(iSourceId);
       
  1663 
       
  1664 	TRAPD(err, PerformOpL(aOpType,aParams));
       
  1665 	if (err != KErrNone)
       
  1666 		test.Printf(_L("Op %d left with error %d\n"), aOpType, err);
       
  1667 	}
       
  1668 
       
  1669 void CTestRefreshMBox::DoOpL( TImap4OpType aOpType, const TDesC& aName, TMsvId aSourceFolder, TMsvId aDestFolder, const TDesC8& aParams)
       
  1670 	{
       
  1671 	iSourceFolder = aSourceFolder;
       
  1672 	iDestFolder = aDestFolder;
       
  1673 	iSourceId = FindMessageByNameL(iSourceFolder, aName);
       
  1674 	if (iSourceId == KErrNotFound)
       
  1675 		{
       
  1676 		test.Printf(_L("Can't find message '%S'\n"), &aName);
       
  1677 		return;
       
  1678 		}
       
  1679 	
       
  1680 	iSelection->Reset();
       
  1681 	iSelection->AppendL(iSourceId);
       
  1682 
       
  1683 	TRAPD(err, PerformOpL(aOpType,aParams));
       
  1684 	if (err != KErrNone)
       
  1685 		test.Printf(_L("Op %d left with error %d\n"), aOpType, err);
       
  1686 	}
       
  1687 
       
  1688 void CTestRefreshMBox::DoOpL( TImap4OpType aOpType, TMsvId aSourceFolder, TMsvId aDestFolder, const TDesC8& aParams)
       
  1689 	{
       
  1690 	DoOpL(aOpType, KMessageNameTest, aSourceFolder, aDestFolder, aParams);
       
  1691 	}
       
  1692 
       
  1693 void CTestRefreshMBox::DoOpL( TImap4OpType aOpType, TMsvId aSourceFolder, TMsvId aDestFolder)
       
  1694 	{
       
  1695 	TBuf8<128> paramBuf(_L8(""));
       
  1696 	DoOpL( aOpType, aSourceFolder, aDestFolder, paramBuf );
       
  1697 	}
       
  1698 
       
  1699 void CTestRefreshMBox::DoOpL( TImap4OpType aOpType, TMsvId aSourceFolder, TMsvId aDestFolder, TImap4GetMailOptions aOptions)
       
  1700 	{
       
  1701 	TPckgBuf<TImap4GetMailOptions> package(aOptions);	
       
  1702 	DoOpL(aOpType, KMessageNameTest, aSourceFolder, aDestFolder, package);
       
  1703 	}
       
  1704 
       
  1705 void CTestRefreshMBox::DoOpNamedL( TImap4OpType aOpType, TMsvId aSrcFolder, TMsvId aDestFolder, const TDesC8& aParams)
       
  1706 	{
       
  1707 	TPtrC msgName = TestMsgName(aOpType);
       
  1708 	DoOpL(aOpType, msgName, aSrcFolder, aDestFolder, aParams);
       
  1709 	}
       
  1710 
       
  1711 void CTestRefreshMBox::DoOpNamedL( TImap4OpType aOpType, TMsvId aSrcFolder, TMsvId aDestFolder)
       
  1712 	{
       
  1713 	TBuf8<128> paramBuf(_L8(""));
       
  1714 	DoOpNamedL( aOpType, aSrcFolder, aDestFolder, paramBuf );
       
  1715 	}
       
  1716 
       
  1717 void CTestRefreshMBox::DoOpNamedL( TImap4OpType aOpType, TMsvId aSrcFolder, TMsvId aDestFolder, TImap4GetMailOptions aOptions)
       
  1718 	{
       
  1719 	TPckgBuf<TImap4GetMailOptions> package(aOptions);	
       
  1720 	TPtrC msgName = TestMsgName(aOpType, aOptions);
       
  1721 	DoOpL( aOpType, msgName, aSrcFolder, aDestFolder, package );
       
  1722 	}
       
  1723 
       
  1724 TBool CTestRefreshMBox::TestQueueL( TMsvId aFolder, CImOffLineOperation::TOffLineOpType aOpType,
       
  1725 									TMsvId aMessage, TMsvId aTarget,
       
  1726 									TInt aFnId,	const TDesC8& aParams )
       
  1727 	{
       
  1728 	if (iEntry->SetEntry( aFolder ) != KErrNone)
       
  1729 		{
       
  1730 		test.Printf(_L("Can't select folder %d\n"), aFolder);
       
  1731 		return EFalse;
       
  1732 		}
       
  1733 
       
  1734 	if (!iEntry->HasStoreL())
       
  1735 		return EFalse;
       
  1736 	
       
  1737 	CImOffLineOperationArray* ops=CImOffLineOperationArray::NewL();
       
  1738 	CleanupStack::PushL(ops);
       
  1739 
       
  1740 	CMsvStore* fileStore = iEntry->ReadStoreL();
       
  1741 	CleanupStack::PushL(fileStore);
       
  1742 	
       
  1743 	CImOffLineArrayStore arraystore(*ops);
       
  1744 	arraystore.RestoreL(*fileStore);
       
  1745 
       
  1746 	TBool found = EFalse;
       
  1747 	for (TInt opNum=0; opNum < ops->CountOperations() && !found; opNum++)
       
  1748 		{
       
  1749 		const CImOffLineOperation& op = ops->Operation(opNum);
       
  1750 
       
  1751 		if (op.OpType() == aOpType &&
       
  1752 			op.MessageId() == aMessage &&
       
  1753 			op.TargetMessageId() == aTarget)
       
  1754 			{
       
  1755 			if ( aOpType != CImOffLineOperation::EOffLineOpMtmSpecific )
       
  1756 				found = ETrue;
       
  1757 			else if ( op.MtmFunctionId() == aFnId && 
       
  1758 					  op.MtmParameters() == aParams )
       
  1759 				found = ETrue;
       
  1760 			}
       
  1761 		}
       
  1762 		
       
  1763 	CleanupStack::PopAndDestroy(2); // filestore, ops
       
  1764 
       
  1765 	return found;
       
  1766 	}
       
  1767 
       
  1768 TBool CTestRefreshMBox::TestQueueL( TMsvId aFolder, CImOffLineOperation::TOffLineOpType aOpType,
       
  1769 									TMsvId aMessage, TMsvId aTarget, TImap4GetMailOptions aOptions )
       
  1770 	{
       
  1771 	TPckgBuf<TImap4GetMailOptions> package(aOptions);	
       
  1772 	return TestQueueL( aFolder, aOpType, aMessage, aTarget, 1, package );
       
  1773 	}
       
  1774 
       
  1775 TBool CTestRefreshMBox::TestQueueL( TMsvId aFolder, CImOffLineOperation::TOffLineOpType aOpType,
       
  1776 									TMsvId aMessage, TMsvId aTarget )
       
  1777 	{
       
  1778 	TBuf8<128> params(_L8(""));
       
  1779 	return TestQueueL( aFolder, aOpType, aMessage, aTarget, 0, params );
       
  1780 	}
       
  1781 
       
  1782 TBool CTestRefreshMBox::TestQueueEmptyL( TMsvId aFolder )
       
  1783 	{
       
  1784 	if (iEntry->SetEntry( aFolder ) != KErrNone)
       
  1785 		{
       
  1786 		test.Printf(_L("Can't select folder %d\n"), aFolder);
       
  1787 		return EFalse;
       
  1788 		}
       
  1789 
       
  1790 	if (!iEntry->HasStoreL())
       
  1791 		return ETrue;
       
  1792 	
       
  1793 	CImOffLineOperationArray* ops=CImOffLineOperationArray::NewL();
       
  1794 	CleanupStack::PushL(ops);
       
  1795 
       
  1796 	CMsvStore* fileStore = iEntry->ReadStoreL();
       
  1797 	CleanupStack::PushL(fileStore);
       
  1798 	
       
  1799 	CImOffLineArrayStore arraystore(*ops);
       
  1800 	arraystore.RestoreL(*fileStore);
       
  1801 	
       
  1802 	TInt count = ops->CountOperations();
       
  1803 		
       
  1804 	CleanupStack::PopAndDestroy(2); // filestore, ops
       
  1805 
       
  1806 	return count == 0;
       
  1807 	}
       
  1808 
       
  1809 TMsvId CTestRefreshMBox::FindShadowL( TMsvId aFolder, TMsvId aSourceId )
       
  1810 	{
       
  1811 	if (iEntry->SetEntry( aFolder ) != KErrNone)
       
  1812 		{
       
  1813 		test.Printf(_L("Can't select folder %d\n"), aFolder);
       
  1814 		return KMsvNullIndexEntryId;
       
  1815 		}
       
  1816 
       
  1817 	CMsvEntrySelection *contents=new CMsvEntrySelection;
       
  1818 	CleanupStack::PushL(contents);
       
  1819 
       
  1820 	User::LeaveIfError(iEntry->GetChildren(*contents));
       
  1821 
       
  1822 	TMsvId id = KMsvNullIndexEntryId;
       
  1823 	for(TInt a=0;a<contents->Count();a++)
       
  1824 		{
       
  1825 		User::LeaveIfError(iEntry->SetEntry((*contents)[a]));
       
  1826 		if (iEntry->Entry().iRelatedId == aSourceId)
       
  1827 			{
       
  1828 			id = (*contents)[a];
       
  1829 			break;
       
  1830 			}
       
  1831 		}
       
  1832 	
       
  1833 	CleanupStack::PopAndDestroy(); // contents
       
  1834 
       
  1835 	return id;
       
  1836 	}
       
  1837 
       
  1838 TBool CTestRefreshMBox::TestShadowL( TMsvId aFolder, TMsvId aSourceId )
       
  1839 	{
       
  1840 	return FindShadowL(aFolder,aSourceId) != KMsvNullIndexEntryId;
       
  1841 	}
       
  1842 
       
  1843 TBool CTestRefreshMBox::TestComplete( TMsvId aSourceId )
       
  1844 	{
       
  1845 	if (iEntry->SetEntry( aSourceId ) != KErrNone)
       
  1846 		{
       
  1847 		test.Printf(_L("Can't select id %d\n"), aSourceId);
       
  1848 		return EFalse;
       
  1849 		}
       
  1850 	return iEntry->Entry().Complete();
       
  1851 	}
       
  1852 
       
  1853 TBool CTestRefreshMBox::TestVisible( TMsvId aSourceId )
       
  1854 	{
       
  1855 	if (iEntry->SetEntry( aSourceId ) != KErrNone)
       
  1856 		{
       
  1857 		test.Printf(_L("Can't select id %d\n"), aSourceId);
       
  1858 		return EFalse;
       
  1859 		}
       
  1860 	return iEntry->Entry().Visible();
       
  1861 	}
       
  1862 
       
  1863 TBool CTestRefreshMBox::TestInvisible( TMsvId aSourceId )
       
  1864 	{
       
  1865 	if (iEntry->SetEntry( aSourceId ) != KErrNone)
       
  1866 		{
       
  1867 		test.Printf(_L("Can't select id %d\n"), aSourceId);
       
  1868 		return EFalse;
       
  1869 		}
       
  1870 	return !iEntry->Entry().Visible();
       
  1871 	}
       
  1872 
       
  1873 TBool CTestRefreshMBox::TestSubscribed( TMsvId aSourceId )
       
  1874 	{
       
  1875 	if (iEntry->SetEntry( aSourceId ) != KErrNone)
       
  1876 		{
       
  1877 		test.Printf(_L("Can't select id %d\n"), aSourceId);
       
  1878 		return EFalse;
       
  1879 		}
       
  1880 	return ((TMsvEmailEntry)iEntry->Entry()).Subscribed();
       
  1881 	}
       
  1882 
       
  1883 TBool CTestRefreshMBox::TestNotSubscribed( TMsvId aSourceId )
       
  1884 	{
       
  1885 	if (iEntry->SetEntry( aSourceId ) != KErrNone)
       
  1886 		{
       
  1887 		test.Printf(_L("Can't select id %d\n"), aSourceId);
       
  1888 		return EFalse;
       
  1889 		}
       
  1890 	return !((TMsvEmailEntry)iEntry->Entry()).Subscribed();
       
  1891 	}
       
  1892 
       
  1893 TBool CTestRefreshMBox::TestLocalSubscription( TMsvId aSourceId )
       
  1894 	{
       
  1895 	if (iEntry->SetEntry( aSourceId ) != KErrNone)
       
  1896 		{
       
  1897 		test.Printf(_L("Can't select id %d\n"), aSourceId);
       
  1898 		return EFalse;
       
  1899 		}
       
  1900 	return ((TMsvEmailEntry)iEntry->Entry()).LocalSubscription();
       
  1901 	}
       
  1902 
       
  1903 TBool CTestRefreshMBox::TestNotLocalSubscription( TMsvId aSourceId )
       
  1904 	{
       
  1905 	if (iEntry->SetEntry( aSourceId ) != KErrNone)
       
  1906 		{
       
  1907 		test.Printf(_L("Can't select id %d\n"), aSourceId);
       
  1908 		return EFalse;
       
  1909 		}
       
  1910 	return !((TMsvEmailEntry)iEntry->Entry()).LocalSubscription();
       
  1911 	}
       
  1912 
       
  1913 TBool CTestRefreshMBox::TestExists( TMsvId aSourceId )
       
  1914 	{
       
  1915 	return iEntry->SetEntry( aSourceId ) == KErrNone;
       
  1916 	}
       
  1917 
       
  1918 TImDisconnectedOperationType CTestRefreshMBox::TestDisconnectedFlags( TMsvId aSourceId )
       
  1919 	{
       
  1920 	if (iEntry->SetEntry( aSourceId ) != KErrNone )
       
  1921 		return EDisconnectedUnknownOperation;
       
  1922 	return ((TMsvEmailEntry)iEntry->Entry()).DisconnectedOperation();
       
  1923 	}
       
  1924 
       
  1925 void CTestRefreshMBox::DoCancelOffLineOpsL()
       
  1926 	{
       
  1927 	test.Console()->SetPos(0, 13);
       
  1928 	test.Printf(_L("DoCancelOffLineOps %x %x %x\n"), iRemoteInbox, iRemoteFolder1, iRemoteFolder2);
       
  1929 
       
  1930 	iSelection->Reset();
       
  1931 	iSelection->AppendL(iRemoteInbox);
       
  1932 	iSelection->AppendL(iRemoteFolder1);
       
  1933 	iSelection->AppendL(iRemoteFolder2);
       
  1934 
       
  1935 	TBuf8<128> paramBuf(_L8(""));
       
  1936 	SetActive();
       
  1937 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMCancelOffLineOperations,paramBuf,iStatus);
       
  1938 	}
       
  1939 
       
  1940 void CTestRefreshMBox::NextState(TInt aInc)
       
  1941 	{
       
  1942 	iOpState /= aInc;
       
  1943 	iOpState += 1;
       
  1944 	iOpState *= aInc;
       
  1945 	}
       
  1946 
       
  1947 void CTestRefreshMBox::NextState()
       
  1948 	{
       
  1949 	NextState(1);
       
  1950 	}
       
  1951 
       
  1952 TBool CTestRefreshMBox::HandleOffLineStateL()
       
  1953 	{
       
  1954 	TBool more = ETrue;
       
  1955 	switch (iOpState)
       
  1956 		{
       
  1957 		// clear offline ops to start with
       
  1958 	case 0:
       
  1959 		DoCancelOffLineOpsL();
       
  1960 		NextState(10);
       
  1961 		break;
       
  1962 
       
  1963 		// COPYTOLOCAL tests   --------------------------------------------------
       
  1964 		// move from local and copy back, which converts to a copyfromlocal
       
  1965 	case 10:
       
  1966 		iTestUtils->TestStart(iTestNum, _L("MoveFromLocal + CopyTolocal == CopyFromLocal"));
       
  1967 
       
  1968 		DoOpL( EImap4OpMoveFromLocal, KMsvGlobalInBoxIndexEntryId, iRemoteFolder1 );
       
  1969 		iOrigSourceId = iSourceId;
       
  1970 		NextState();
       
  1971 		break;
       
  1972 
       
  1973 	case 11:
       
  1974 		test(TestQueueL( iRemoteFolder1, CImOffLineOperation::EOffLineOpMoveFromLocal, iOrigSourceId, iRemoteFolder1 ));
       
  1975 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  1976 		test(TestInvisible( iOrigSourceId ));
       
  1977 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedMoveFromOperation );
       
  1978 
       
  1979 		DoOpL( EImap4OpCopyToLocal, iRemoteFolder1, KMsvGlobalInBoxIndexEntryId );
       
  1980 		NextState();
       
  1981 		break;
       
  1982 
       
  1983 	case 12:
       
  1984 		test(TestQueueL( iRemoteFolder1, CImOffLineOperation::EOffLineOpCopyFromLocal, iOrigSourceId, iRemoteFolder1 ));
       
  1985 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  1986 		test(TestVisible( iOrigSourceId ));
       
  1987 		// failed
       
  1988 		//test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedCopyFromOperation );
       
  1989 		
       
  1990 		iTestUtils->TestFinish(iTestNum++);
       
  1991 
       
  1992 		DoCancelOffLineOpsL();
       
  1993 		NextState(10);
       
  1994 		break;
       
  1995 
       
  1996 		// copy from local and copy back to new folder, doing immediate copy
       
  1997 	case 20:
       
  1998 		iTestUtils->TestStart(iTestNum, _L("CopyFromLocal + CopyToLocal == Immediate Copy"));
       
  1999 
       
  2000 		DoOpL( EImap4OpCopyFromLocal, KMsvGlobalInBoxIndexEntryId, iRemoteFolder1 );
       
  2001 		iOrigSourceId = iSourceId;
       
  2002 		NextState();
       
  2003 		break;
       
  2004 
       
  2005 	case 21:
       
  2006 		test(TestQueueL( iRemoteFolder1, CImOffLineOperation::EOffLineOpCopyFromLocal, iOrigSourceId, iRemoteFolder1 ));
       
  2007 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2008 		test(TestVisible( iOrigSourceId ));
       
  2009 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedCopyFromOperation );
       
  2010 
       
  2011 		DoOpL( EImap4OpCopyToLocal, iRemoteFolder1, iLocalFolder1 );
       
  2012 		NextState();
       
  2013 		break;
       
  2014 		
       
  2015 	case 22:
       
  2016 		{
       
  2017 		// check message has been copied and then delete it, do this
       
  2018 		// first in case other test fail
       
  2019 		TMsvId newId = FindMessageByNameL( iLocalFolder1, KMessageNameTest );
       
  2020 		test(newId != KErrNotFound);
       
  2021 
       
  2022 		iEntry->SetEntry( newId );
       
  2023 		iEntry->SetEntry( iEntry->Entry().Parent() );
       
  2024 		iEntry->DeleteEntry( newId );
       
  2025 			
       
  2026 		test(TestQueueL( iRemoteFolder1, CImOffLineOperation::EOffLineOpCopyFromLocal, iOrigSourceId, iRemoteFolder1 ));
       
  2027 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2028 		test(TestVisible( iOrigSourceId ));
       
  2029 		// failed
       
  2030 		// test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedCopyFromOperation );
       
  2031 
       
  2032 		iTestUtils->TestFinish(iTestNum++);
       
  2033 
       
  2034 		DoCancelOffLineOpsL();
       
  2035 		NextState(100);
       
  2036 		break;
       
  2037 		}
       
  2038 		
       
  2039 		// copy back from local to service
       
  2040 		// COPYFROMLOCAL tests --------------------------------------------------
       
  2041 		
       
  2042 		// copy to local and copy back to new folder
       
  2043 		
       
  2044 	case 100:
       
  2045 		// copy fresh to local
       
  2046 		iTestUtils->TestStart(iTestNum, _L("CopyToLocal + CopyFromLocal == CopyToLocal + CopyWithinService"));
       
  2047 
       
  2048 		DoOpL( EImap4OpCopyToLocal, iRemoteInbox, iLocalFolder1 );
       
  2049 		iOrigSourceId = iSourceId;
       
  2050 		NextState();
       
  2051 		break;
       
  2052 
       
  2053 	case 101:
       
  2054 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpCopyToLocal, iSourceId, iLocalFolder1 ));
       
  2055 		test(TestShadowL( iLocalFolder1, iSourceId ));
       
  2056 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedCopyToOperation );
       
  2057 
       
  2058 		// copy back from local to service
       
  2059 		DoOpL( EImap4OpCopyFromLocal, iLocalFolder1, iRemoteFolder1 );
       
  2060 		NextState();
       
  2061 		break;
       
  2062 
       
  2063 	case 102:
       
  2064 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpCopyToLocal, iOrigSourceId, iLocalFolder1 ));
       
  2065 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpCopyWithinService, iOrigSourceId, iRemoteFolder1 ));
       
  2066 		test(TestShadowL( iLocalFolder1, iOrigSourceId ));
       
  2067 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2068 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedMultipleOperation );
       
  2069 
       
  2070 		iTestUtils->TestFinish(iTestNum++);
       
  2071 
       
  2072 		DoCancelOffLineOpsL();
       
  2073 		NextState(100);
       
  2074 		break;
       
  2075 
       
  2076 		// COPYWITHINSERVICE tests ----------------------------------------------
       
  2077 
       
  2078 		// copy within service and copy on to new folder
       
  2079 	case 200:
       
  2080 		// copy fresh within service
       
  2081 		iTestUtils->TestStart(iTestNum, _L("CopyWithinService + CopyWithinService"));
       
  2082 
       
  2083 		DoOpL( EImap4OpCopyWithinService, iRemoteInbox, iRemoteFolder1 );
       
  2084 		iOrigSourceId = iSourceId;
       
  2085 		NextState();
       
  2086 		break;
       
  2087 
       
  2088 	case 201:
       
  2089 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpCopyWithinService, iSourceId, iRemoteFolder1 ));
       
  2090 		test(TestShadowL( iRemoteFolder1, iSourceId ));
       
  2091 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedCopyWithinServiceOperation );
       
  2092 		
       
  2093 		// copy on to new location
       
  2094 		DoOpL( EImap4OpCopyWithinService, iRemoteFolder1, iRemoteFolder2 );
       
  2095 		NextState();
       
  2096 		break;
       
  2097 
       
  2098 	case 202:
       
  2099 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpCopyWithinService, iOrigSourceId, iRemoteFolder1 ));
       
  2100 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpCopyWithinService, iOrigSourceId, iRemoteFolder2 ));
       
  2101 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2102 		test(TestShadowL( iRemoteFolder2, iOrigSourceId ));
       
  2103 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedMultipleOperation );
       
  2104 
       
  2105 		iTestUtils->TestFinish(iTestNum++);
       
  2106 
       
  2107 		DoCancelOffLineOpsL();
       
  2108 		NextState();
       
  2109 		break;
       
  2110 
       
  2111 	case 203:
       
  2112 		// move item to folder1
       
  2113 		iTestUtils->TestStart(iTestNum, _L("MoveWithinService + CopyWithinService"));
       
  2114 
       
  2115 		DoOpL( EImap4OpMoveWithinService, iRemoteInbox, iRemoteFolder1 );
       
  2116 		iOrigSourceId = iSourceId;
       
  2117 		NextState();
       
  2118 		break;
       
  2119 
       
  2120 	case 204:
       
  2121 		// copy this ghost entry to folder2
       
  2122 		DoOpL( EImap4OpCopyWithinService, iRemoteFolder1, iRemoteFolder2 );
       
  2123 		NextState();
       
  2124 		break;
       
  2125 
       
  2126 	case 205:
       
  2127 		// check that the new ghost is visible and otherwise correct
       
  2128 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMoveWithinService, iOrigSourceId, iRemoteFolder1 ));
       
  2129 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpCopyWithinService, iOrigSourceId, iRemoteFolder2 ));
       
  2130 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2131 		test(TestShadowL( iRemoteFolder2, iOrigSourceId ));
       
  2132 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedMultipleOperation );
       
  2133 		test(TestInvisible( iOrigSourceId ));
       
  2134 		test(TestVisible( iSourceId ));
       
  2135 		test(TestVisible( FindMessageByNameL( iRemoteFolder2, KMessageNameTest ) ));
       
  2136 		
       
  2137 		iTestUtils->TestFinish(iTestNum++);
       
  2138 
       
  2139 		DoCancelOffLineOpsL();
       
  2140 		NextState(100);
       
  2141 		break;
       
  2142 
       
  2143 		// MOVETOLOCAL tests   --------------------------------------------------
       
  2144 
       
  2145 		// move from local and move back to undo
       
  2146 	case 300:
       
  2147 		iTestUtils->TestStart(iTestNum, _L("MoveFromLocal + MoveToLocal (same folder) == nothing"));
       
  2148 
       
  2149 		DoOpL( EImap4OpMoveFromLocal, KMsvGlobalInBoxIndexEntryId, iRemoteFolder1 );
       
  2150 		iOrigSourceId = iSourceId;
       
  2151 		NextState();
       
  2152 		break;
       
  2153 		
       
  2154 	case 301:
       
  2155 		test(TestQueueL( iRemoteFolder1, CImOffLineOperation::EOffLineOpMoveFromLocal, iOrigSourceId, iRemoteFolder1 ));
       
  2156 		test(TestInvisible( iOrigSourceId ));
       
  2157 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2158 
       
  2159 		// move back to local
       
  2160 		DoOpL( EImap4OpMoveToLocal, iRemoteFolder1, KMsvGlobalInBoxIndexEntryId );
       
  2161 		NextState();
       
  2162 		break;
       
  2163 		
       
  2164 	case 302:
       
  2165 		// check net result is nothing
       
  2166 		test(TestQueueEmptyL( iRemoteFolder1 ));
       
  2167 		test(TestDisconnectedFlags( iOrigSourceId ) == ENoDisconnectedOperations );
       
  2168 		test(!TestExists( iSourceId ));
       
  2169 		test(TestVisible( iOrigSourceId ));
       
  2170 
       
  2171 		iTestUtils->TestFinish(iTestNum++);
       
  2172 
       
  2173 		DoCancelOffLineOpsL();
       
  2174 		NextState(10);
       
  2175 		break;
       
  2176 
       
  2177 		// copy from local and move back to new folder, results in
       
  2178 		// direct local copy
       
  2179 	case 310:
       
  2180 		iTestUtils->TestStart(iTestNum, _L("CopyFromLocal + MoveToLocal == immediate copy"));
       
  2181 
       
  2182 		DoOpL( EImap4OpCopyFromLocal, KMsvGlobalInBoxIndexEntryId, iRemoteFolder1 );
       
  2183 		iOrigSourceId = iSourceId;
       
  2184 		NextState();
       
  2185 		break;
       
  2186 
       
  2187 	case 311:
       
  2188 		test(TestQueueL( iRemoteFolder1, CImOffLineOperation::EOffLineOpCopyFromLocal, iOrigSourceId, iRemoteFolder1 ));
       
  2189 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2190 		test(TestVisible( iOrigSourceId ));
       
  2191 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedCopyFromOperation );
       
  2192 
       
  2193 		DoOpL( EImap4OpMoveToLocal, iRemoteFolder1, iLocalFolder1 );
       
  2194 		NextState();
       
  2195 		break;
       
  2196 		
       
  2197 	case 312:
       
  2198 		{
       
  2199 		// check message has been copied and then delete it, do this
       
  2200 		// first in case other tests fail
       
  2201 		TMsvId newId = FindMessageByNameL( iLocalFolder1, KMessageNameTest );
       
  2202 		test(newId != KErrNotFound);
       
  2203 
       
  2204 		iEntry->SetEntry( newId );
       
  2205 		iEntry->SetEntry( iEntry->Entry().Parent() );
       
  2206 		iEntry->DeleteEntry( newId );
       
  2207 		
       
  2208 		test(TestQueueEmptyL( iRemoteFolder1 ));
       
  2209 		test(!TestExists( iSourceId ));
       
  2210 		test(TestVisible( iOrigSourceId ));
       
  2211 		test(TestDisconnectedFlags( iOrigSourceId ) == ENoDisconnectedOperations );
       
  2212 		
       
  2213 		iTestUtils->TestFinish(iTestNum++);
       
  2214 
       
  2215 		DoCancelOffLineOpsL();
       
  2216 		NextState(10);
       
  2217 		break;
       
  2218 		}
       
  2219 		
       
  2220 		// move from local and move back to new folder
       
  2221 	case 320:
       
  2222 		iTestUtils->TestStart(iTestNum, _L("MoveFromLocal + MoveToLocal == immediate move"));
       
  2223 
       
  2224 		DoOpL( EImap4OpMoveFromLocal, KMsvGlobalInBoxIndexEntryId, iRemoteFolder1 );
       
  2225 		iOrigSourceId = iSourceId;
       
  2226 		NextState();
       
  2227 		break;
       
  2228 		
       
  2229 	case 321:
       
  2230 		test(TestQueueL( iRemoteFolder1, CImOffLineOperation::EOffLineOpMoveFromLocal, iOrigSourceId, iRemoteFolder1 ));
       
  2231 		test(TestInvisible( iOrigSourceId ));
       
  2232 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2233 
       
  2234 		// move back to local
       
  2235 		DoOpL( EImap4OpMoveToLocal, iRemoteFolder1, iLocalFolder1 );
       
  2236 		NextState();
       
  2237 		break;
       
  2238 		
       
  2239 	case 322:
       
  2240 		{
       
  2241 		// check message has been moved and then move it back, do this
       
  2242 		// first in case other tests fail
       
  2243 		TMsvId newId = FindMessageByNameL( iLocalFolder1, KMessageNameTest );
       
  2244 		test(newId == iOrigSourceId);
       
  2245 
       
  2246 		iEntry->SetEntry( newId );
       
  2247 		iEntry->SetEntry( iEntry->Entry().Parent() );
       
  2248 		iEntry->MoveEntryWithinService( newId, KMsvGlobalInBoxIndexEntryId );
       
  2249 		
       
  2250 		test(TestQueueEmptyL( iRemoteFolder1 ));
       
  2251 		test(!TestExists( iSourceId ));
       
  2252 		test(TestExists( iOrigSourceId ));
       
  2253 		test(TestDisconnectedFlags( iOrigSourceId ) == ENoDisconnectedOperations );
       
  2254 
       
  2255 		iTestUtils->TestFinish(iTestNum++);
       
  2256 
       
  2257 		DoCancelOffLineOpsL();
       
  2258 		NextState(100);
       
  2259 		break;
       
  2260 		}		
       
  2261 		// MOVEFROMLOCAL tests --------------------------------------------------
       
  2262 
       
  2263 		// move to local and move back to undo
       
  2264 	case 400:
       
  2265 		// move fresh to local
       
  2266 		iTestUtils->TestStart(iTestNum, _L("MoveToLocal + MoveFromLocal (same folder) == nothing"));
       
  2267 
       
  2268 		DoOpL( EImap4OpMoveToLocal, iRemoteInbox, iLocalFolder1 );
       
  2269 		iOrigSourceId = iSourceId;
       
  2270 		NextState();
       
  2271 		break;
       
  2272 
       
  2273 	case 401:
       
  2274 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMoveToLocal, iSourceId, iLocalFolder1 ));
       
  2275 		test(TestShadowL( iLocalFolder1, iSourceId ));
       
  2276 		test(TestInvisible( iSourceId ));
       
  2277 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedMoveToOperation );
       
  2278 		
       
  2279 		// move back to original location
       
  2280 		DoOpL( EImap4OpMoveFromLocal, iLocalFolder1, iRemoteInbox );
       
  2281 		NextState();
       
  2282 		break;
       
  2283 
       
  2284 	case 402:
       
  2285 		test(TestQueueEmptyL( iRemoteInbox ));
       
  2286 		test(!TestShadowL( iLocalFolder1, iOrigSourceId ));
       
  2287 		test(TestVisible( iOrigSourceId ));
       
  2288 		test(TestDisconnectedFlags( iOrigSourceId ) == ENoDisconnectedOperations );
       
  2289 
       
  2290 		iTestUtils->TestFinish(iTestNum++);
       
  2291 
       
  2292 		DoCancelOffLineOpsL();
       
  2293 		NextState(10);
       
  2294 		break;
       
  2295 
       
  2296 		// move to local and move back to new folder
       
  2297 	case 410:
       
  2298 		// move fresh to local
       
  2299 		iTestUtils->TestStart(iTestNum, _L("MoveToLocal + MoveFromLocal == MoveWithinService"));
       
  2300 
       
  2301 		DoOpL( EImap4OpMoveToLocal, iRemoteInbox, iLocalFolder1 );
       
  2302 		iOrigSourceId = iSourceId;
       
  2303 		NextState();
       
  2304 		break;
       
  2305 
       
  2306 	case 411:
       
  2307 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMoveToLocal, iSourceId, iLocalFolder1 ));
       
  2308 		test(TestShadowL( iLocalFolder1, iSourceId ));
       
  2309 		test(TestInvisible( iSourceId ));
       
  2310 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedMoveToOperation );
       
  2311 		
       
  2312 		// move back to new folder
       
  2313 		DoOpL( EImap4OpMoveFromLocal, iLocalFolder1, iRemoteFolder1 );
       
  2314 		NextState();
       
  2315 		break;
       
  2316 
       
  2317 	case 412:
       
  2318 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMoveWithinService, iOrigSourceId, iRemoteFolder1 ));
       
  2319 		test(!TestShadowL( iLocalFolder1, iOrigSourceId ));
       
  2320 		test(TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2321 		test(TestInvisible( iOrigSourceId ));
       
  2322 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedMoveWithinServiceOperation );
       
  2323 
       
  2324 		iTestUtils->TestFinish(iTestNum++);
       
  2325 
       
  2326 		DoCancelOffLineOpsL();
       
  2327 		NextState(10);
       
  2328 		break;
       
  2329 
       
  2330 		// copy to local, delete original, and move back to undo
       
  2331 	case 420:
       
  2332 		// copy to local
       
  2333 		iTestUtils->TestStart(iTestNum, _L("CopyToLocal + Delete + MoveFromLocal == nothing"));
       
  2334 
       
  2335 		DoOpL( EImap4OpCopyToLocal, iRemoteInbox, iLocalFolder1 );
       
  2336 		iOrigSourceId = iSourceId;
       
  2337 		NextState();
       
  2338 		break;
       
  2339 
       
  2340 	case 421:
       
  2341 		// delete original
       
  2342 		DoOpL( EImap4OpDelete, iRemoteInbox, KMsvNullIndexEntryId );
       
  2343 		NextState();
       
  2344 		break;
       
  2345 		
       
  2346 	case 422:
       
  2347 		// move original back
       
  2348 		DoOpL( EImap4OpMoveFromLocal, iLocalFolder1, iRemoteInbox );
       
  2349 		NextState();
       
  2350 		break;
       
  2351 
       
  2352 	case 423:
       
  2353 		// check net result is nothing
       
  2354 		test(TestQueueEmptyL( iRemoteInbox ));
       
  2355 		test(TestDisconnectedFlags( iOrigSourceId ) == ENoDisconnectedOperations );
       
  2356 		test(!TestExists( iSourceId ));
       
  2357 		test(TestVisible( iOrigSourceId ));
       
  2358 
       
  2359 		iTestUtils->TestFinish(iTestNum++);
       
  2360 
       
  2361 		DoCancelOffLineOpsL();
       
  2362 		NextState(100);
       
  2363 		break;
       
  2364 
       
  2365 
       
  2366 		// MOVEWITHINSERVICE tests ----------------------------------------------
       
  2367 
       
  2368 		// move within sercice and move back to undo
       
  2369 	case 500:
       
  2370 		// move fresh within service
       
  2371 		iTestUtils->TestStart(iTestNum, _L("MoveWithinService + MoveWithinService (same folder) == nothing"));
       
  2372 
       
  2373 		DoOpL( EImap4OpMoveWithinService, iRemoteInbox, iRemoteFolder1 );
       
  2374 		iOrigSourceId = iSourceId;
       
  2375 		NextState();
       
  2376 		break;
       
  2377 
       
  2378 	case 501:
       
  2379 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMoveWithinService, iSourceId, iRemoteFolder1 ));
       
  2380 		test(TestShadowL( iRemoteFolder1, iSourceId ));
       
  2381 		test(TestInvisible( iSourceId ));
       
  2382 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedMoveWithinServiceOperation );
       
  2383 		
       
  2384 		// move back to original location -- undo
       
  2385 		DoOpL( EImap4OpMoveWithinService, iRemoteFolder1, iRemoteInbox );
       
  2386 		NextState();
       
  2387 		break;
       
  2388 
       
  2389 	case 502:
       
  2390 		test(TestQueueEmptyL( iRemoteInbox ));
       
  2391 		test(!TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2392 		test(TestVisible( iOrigSourceId ));
       
  2393 		test(TestDisconnectedFlags( iOrigSourceId ) == ENoDisconnectedOperations );
       
  2394 
       
  2395 		iTestUtils->TestFinish(iTestNum++);
       
  2396 
       
  2397 		DoCancelOffLineOpsL();
       
  2398 		NextState(10);
       
  2399 		break;
       
  2400 
       
  2401 		// move within service and move on to new folder
       
  2402 	case 510:
       
  2403 		// move fresh within service
       
  2404 		iTestUtils->TestStart(iTestNum, _L("MoveWithinService + MoveWithinService == MoveWithinService"));
       
  2405 
       
  2406 		DoOpL( EImap4OpMoveWithinService, iRemoteInbox, iRemoteFolder1 );
       
  2407 		iOrigSourceId = iSourceId;
       
  2408 		NextState();
       
  2409 		break;
       
  2410 
       
  2411 	case 511:
       
  2412 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMoveWithinService, iSourceId, iRemoteFolder1 ));
       
  2413 		test(TestShadowL( iRemoteFolder1, iSourceId ));
       
  2414 		test(TestInvisible( iSourceId ));
       
  2415 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedMoveWithinServiceOperation );
       
  2416 		
       
  2417 		// move back to new folder
       
  2418 		DoOpL( EImap4OpMoveWithinService, iRemoteFolder1, iRemoteFolder2 );
       
  2419 		NextState();
       
  2420 		break;
       
  2421 
       
  2422 	case 512:
       
  2423 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMoveWithinService, iOrigSourceId, iRemoteFolder2 ));
       
  2424 		test(!TestShadowL( iRemoteFolder1, iOrigSourceId ));
       
  2425 		test(TestShadowL( iRemoteFolder2, iOrigSourceId ));
       
  2426 		test(TestInvisible( iOrigSourceId ));
       
  2427 		test(TestDisconnectedFlags( iOrigSourceId ) == EDisconnectedMoveWithinServiceOperation );
       
  2428 
       
  2429 		iTestUtils->TestFinish(iTestNum++);
       
  2430 
       
  2431 		DoCancelOffLineOpsL();
       
  2432 		NextState(100);
       
  2433 		break;
       
  2434 		
       
  2435 		// DELETE/UNDELETE tests ----------------------------------------------
       
  2436 
       
  2437 		// DELETE tests
       
  2438 	case 600:
       
  2439 		iTestUtils->TestStart(iTestNum, _L("Delete + Undelete = nothing"));
       
  2440 
       
  2441 		DoOpL( EImap4OpDelete, iRemoteInbox, KMsvNullIndexEntryId );
       
  2442 		iOrigSourceId = iSourceId;
       
  2443 		NextState();
       
  2444 		break;
       
  2445 
       
  2446 	case 601:
       
  2447 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpDelete, iSourceId, KMsvNullIndexEntryId ));
       
  2448 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedDeleteOperation );
       
  2449 
       
  2450 		// undelete it
       
  2451 		DoOpL( EImap4OpUndelete, iRemoteInbox, KMsvNullIndexEntryId );
       
  2452 		NextState();
       
  2453 		break;
       
  2454 
       
  2455 	case 602:
       
  2456 		test(TestQueueEmptyL( iRemoteInbox ));
       
  2457 		test(TestDisconnectedFlags( iOrigSourceId ) == ENoDisconnectedOperations );
       
  2458 
       
  2459 		iTestUtils->TestFinish(iTestNum++);
       
  2460 
       
  2461 		DoCancelOffLineOpsL();
       
  2462 		NextState(100);
       
  2463 		break;
       
  2464 
       
  2465 		// ----------------------------------------------------------------------
       
  2466 		// other things we can do offline
       
  2467 	case 700:
       
  2468 		// check flags on messages in the mirror
       
  2469 		TestPriorityAndReceiptAddressL();		
       
  2470 
       
  2471 		iTestUtils->TestStart(iTestNum, _L("Offline op errors"));
       
  2472 
       
  2473 		// check the return codes from the some of the special functions
       
  2474 		PerformSpecialOpL(0, KIMAP4MTMIsConnected);
       
  2475 		NextState();
       
  2476 		break;
       
  2477 
       
  2478 	case 701:
       
  2479 		test(iStatus.Int() == KErrDisconnected);
       
  2480 
       
  2481 		PerformSpecialOpL(0, KIMAP4MTMSynchronise);
       
  2482 		NextState();
       
  2483 		break;
       
  2484 		
       
  2485 	case 702:
       
  2486 		test(iStatus.Int() == KErrDisconnected);
       
  2487 		PerformSpecialOpL(0, KIMAP4MTMFullSync);
       
  2488 		NextState();
       
  2489 		break;
       
  2490 		
       
  2491 	case 703:
       
  2492 		test(iStatus.Int() == KErrDisconnected);
       
  2493 		PerformSpecialOpL(0, KIMAP4MTMInboxNewSync);
       
  2494 		NextState();
       
  2495 		break;
       
  2496 		
       
  2497 	case 704:
       
  2498 		test(iStatus.Int() == KErrDisconnected);
       
  2499 		PerformSpecialOpL(0, KIMAP4MTMFolderFullSync);
       
  2500 		NextState();
       
  2501 		break;
       
  2502 		
       
  2503 	case 705:
       
  2504 		test(iStatus.Int() == KErrDisconnected);
       
  2505 		PerformSpecialOpL(0, KIMAP4MTMRenameFolder);
       
  2506 		NextState();
       
  2507 		break;
       
  2508 		
       
  2509 	case 706:
       
  2510 		test(iStatus.Int() == KErrDisconnected);
       
  2511 		PerformSpecialOpL(0, KIMAP4MTMDisconnect);
       
  2512 		NextState();
       
  2513 		break;
       
  2514 		
       
  2515 	case 707:
       
  2516 		test(iStatus.Int() == KErrDisconnected);
       
  2517 		PerformSpecialOpL(0, KIMAP4MTMSyncTree);
       
  2518 		NextState();
       
  2519 		break;
       
  2520 		
       
  2521 	case 708:
       
  2522 		test(iStatus.Int() == KErrDisconnected);
       
  2523 		PerformSpecialOpL(0, KIMAP4MTMBusy);
       
  2524 		NextState();
       
  2525 		break;
       
  2526 		
       
  2527 	case 709:
       
  2528  		test(iStatus.Int() == KErrNone);
       
  2529 		PerformSpecialOpL(0, KIMAP4MTMSelect);
       
  2530 		NextState();
       
  2531 		break;
       
  2532 		
       
  2533 	case 710:
       
  2534 		test(iStatus.Int() == KErrDisconnected);
       
  2535 		PerformSpecialOpL(0, KIMAP4MTMCancelBackgroundSynchronise);
       
  2536 		NextState(100);
       
  2537 		break;
       
  2538 #if 0
       
  2539 		// test local subscription code
       
  2540 	case 711:
       
  2541 		test(iStatus.Int() == KErrNone);
       
  2542 		PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("TestHier1")), KIMAP4MTMLocalSubscribe);
       
  2543 		NextState();
       
  2544 		break;
       
  2545 		
       
  2546 	case 712:
       
  2547 		test(iStatus.Int() == KErrNone);
       
  2548 		test(TestLocalSubscription(iSourceId));
       
  2549 		PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("TestHier1/TestHier2")), KIMAP4MTMLocalSubscribe);
       
  2550 		NextState();
       
  2551 		break;
       
  2552 		
       
  2553 	case 713:
       
  2554 		test(iStatus.Int() == KErrNone);
       
  2555 		test(TestLocalSubscription(iSourceId));
       
  2556 		PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("TestHier1/TestHier2/TestHier3")), KIMAP4MTMLocalSubscribe);
       
  2557 		NextState();
       
  2558 		break;
       
  2559 		
       
  2560 	case 714:
       
  2561 		test(iStatus.Int() == KErrNone);
       
  2562 		test(TestLocalSubscription(iSourceId));
       
  2563 		PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("TestHier1")), KIMAP4MTMLocalUnsubscribe);
       
  2564 		NextState();
       
  2565 		break;
       
  2566 		
       
  2567 	case 715:
       
  2568 		test(iStatus.Int() == KErrNone);
       
  2569 		test(TestNotLocalSubscription(iSourceId));
       
  2570 		test(TestVisible(iSourceId));
       
  2571 		PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("TestHier1/TestHier2")), KIMAP4MTMLocalUnsubscribe);
       
  2572 		NextState();
       
  2573 		break;
       
  2574 		
       
  2575 	case 716:
       
  2576 		test(iStatus.Int() == KErrNone);
       
  2577 		test(TestNotLocalSubscription(iSourceId));
       
  2578 		test(TestVisible(iSourceId));
       
  2579 		PerformSpecialOpL(FindFolderByNameL(iServiceId, _L("TestHier1/TestHier2/TestHier3")), KIMAP4MTMLocalUnsubscribe);
       
  2580 		NextState();
       
  2581 		break;
       
  2582 		
       
  2583 	case 717:
       
  2584 		test(iStatus.Int() == KErrNone);
       
  2585 		test(TestNotLocalSubscription(iSourceId));
       
  2586 		test(TestInvisible(iSourceId));
       
  2587 		test(TestInvisible(FindMessageByNameL(iSourceId, KMessageNameTest)));
       
  2588 		test(TestInvisible(FindFolderByNameL(iServiceId, _L("TestHier1/TestHier2"))));
       
  2589 		test(TestInvisible(FindFolderByNameL(iServiceId, _L("TestHier1"))));
       
  2590 
       
  2591 		iTestUtils->TestFinish(iTestNum++);
       
  2592 
       
  2593 		DoCancelOffLineOpsL();
       
  2594 		NextState(100);
       
  2595 		break;
       
  2596 #endif
       
  2597 		// POPULATE tests   --------------------------------------------------
       
  2598 
       
  2599 		// copy to mirror
       
  2600 	case 800:
       
  2601 		test(iStatus.Int() == KErrNone);
       
  2602 		iTestUtils->TestFinish(iTestNum++);
       
  2603 
       
  2604 		iTestUtils->TestStart(iTestNum, _L("Populate default"));
       
  2605 
       
  2606 		DoOpL( EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId );
       
  2607 		iOrigSourceId = iSourceId;
       
  2608 		NextState();
       
  2609 		break;
       
  2610 
       
  2611 	case 801:
       
  2612 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, iSourceId, KMsvNullIndexEntryId, EGetImap4EmailBodyTextAndAttachments ));
       
  2613 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedSpecialOperation );
       
  2614 
       
  2615 		iTestUtils->TestFinish(iTestNum++);
       
  2616 
       
  2617 		DoCancelOffLineOpsL();
       
  2618 		NextState();
       
  2619 		break;
       
  2620 
       
  2621 	case 802:
       
  2622 		iTestUtils->TestStart(iTestNum, _L("Populate headers"));
       
  2623 
       
  2624 		DoOpL( EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailHeaders );
       
  2625 		NextState();
       
  2626 		break;
       
  2627 
       
  2628 	case 803:
       
  2629 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, iSourceId, KMsvNullIndexEntryId, EGetImap4EmailHeaders ));
       
  2630 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedSpecialOperation );
       
  2631 
       
  2632 		iTestUtils->TestFinish(iTestNum++);
       
  2633 
       
  2634 		DoCancelOffLineOpsL();
       
  2635 		NextState();
       
  2636 		break;
       
  2637 
       
  2638 	case 804:
       
  2639 		iTestUtils->TestStart(iTestNum, _L("Populate BodyText"));
       
  2640 
       
  2641 		DoOpL( EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailBodyText );
       
  2642 		NextState();
       
  2643 		break;
       
  2644 
       
  2645 	case 805:
       
  2646 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, iSourceId, KMsvNullIndexEntryId, EGetImap4EmailBodyText ));
       
  2647 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedSpecialOperation );
       
  2648 
       
  2649 		iTestUtils->TestFinish(iTestNum++);
       
  2650 
       
  2651 		DoCancelOffLineOpsL();
       
  2652 		NextState();
       
  2653 		break;
       
  2654 
       
  2655 	case 806:
       
  2656 		iTestUtils->TestStart(iTestNum, _L("Populate Attachments"));
       
  2657 
       
  2658 		DoOpL( EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailAttachments );
       
  2659 		NextState();
       
  2660 		break;
       
  2661 
       
  2662 	case 807:
       
  2663 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, iSourceId, KMsvNullIndexEntryId, EGetImap4EmailAttachments ));
       
  2664 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedSpecialOperation );
       
  2665 
       
  2666 		iTestUtils->TestFinish(iTestNum++);
       
  2667 
       
  2668 		DoCancelOffLineOpsL();
       
  2669 		NextState();
       
  2670 		break;
       
  2671 
       
  2672 	case 808:
       
  2673 		iTestUtils->TestStart(iTestNum, _L("Populate All"));
       
  2674 
       
  2675 		DoOpL( EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailBodyTextAndAttachments );
       
  2676 		NextState();
       
  2677 		break;
       
  2678 
       
  2679 	case 809:
       
  2680 		test(TestQueueL( iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, iSourceId, KMsvNullIndexEntryId, EGetImap4EmailBodyTextAndAttachments ));
       
  2681 		test(TestDisconnectedFlags( iSourceId ) == EDisconnectedSpecialOperation );
       
  2682 
       
  2683 		iTestUtils->TestFinish(iTestNum++);
       
  2684 
       
  2685 		DoCancelOffLineOpsL();
       
  2686 		NextState(100);
       
  2687 		break;
       
  2688 
       
  2689 	case 900:
       
  2690 		// done
       
  2691 		iTestUtils->TestHarnessCompleted();
       
  2692 		EndOfTest();  
       
  2693 		
       
  2694 		// done
       
  2695 		test.Console()->SetPos(0, 13);
       
  2696 		test.Printf(_L("Finished offline tests\n"));
       
  2697 		more = EFalse;
       
  2698 		break;
       
  2699 		
       
  2700 	default:
       
  2701 		NextState(100);
       
  2702 		break;
       
  2703 		}
       
  2704 
       
  2705 	return more;
       
  2706 	}
       
  2707 
       
  2708 void CTestRefreshMBox::DoAutomatedOffLineOpsL()
       
  2709 	{
       
  2710 	if (iServiceId==NULL)
       
  2711 		{
       
  2712 		test.Printf(_L("No service ID\n"));
       
  2713 		return;
       
  2714 		}
       
  2715 
       
  2716 	if (iRemoteFolder1<=KMsvNullIndexEntryId)
       
  2717 		iRemoteFolder1=FindFolderByNameL(iServiceId,_L("Test1"));
       
  2718 		
       
  2719 	if (iRemoteFolder2<=KMsvNullIndexEntryId)	
       
  2720 		iRemoteFolder2=FindFolderByNameL(iServiceId,_L("Test2"));
       
  2721 
       
  2722 	if (iRemoteFolder1<=KMsvNullIndexEntryId ||
       
  2723 		iRemoteFolder2<=KMsvNullIndexEntryId)	
       
  2724 		{
       
  2725 		test.Printf(_L("Don't have both the remote folders\n"));
       
  2726 		}
       
  2727 	else
       
  2728 		{
       
  2729 		iOpState = 0;
       
  2730 		iState = EImapTestAutoOffLineOp;
       
  2731 		
       
  2732 		HandleOffLineStateL();
       
  2733 		}
       
  2734 	}
       
  2735 
       
  2736 TBool CTestRefreshMBox::HandleSyncStateL()
       
  2737 	{
       
  2738 	TBool more = ETrue;
       
  2739 
       
  2740 	switch (iOpState)
       
  2741 		{
       
  2742 		// test basic commands
       
  2743 	case 0:
       
  2744 		iTestUtils->TestStart(iTestNum, _L("Setup offline ops"));
       
  2745 
       
  2746 		DoOpNamedL(EImap4OpCopyToLocal, iRemoteInbox, iLocalFolder1);
       
  2747 		NextState();
       
  2748 		break;
       
  2749 
       
  2750 	case 1:
       
  2751 		test(iStatus.Int() == KErrNone);
       
  2752 		DoOpNamedL(EImap4OpCopyWithinService, iRemoteInbox, iRemoteFolder1);
       
  2753 		NextState();
       
  2754 		break;
       
  2755 		
       
  2756 	case 2:
       
  2757 		test(iStatus.Int() == KErrNone);
       
  2758 		DoOpNamedL(EImap4OpMoveToLocal, iRemoteInbox, iLocalFolder1);
       
  2759 		NextState();
       
  2760 		break;
       
  2761 		
       
  2762 	case 3:
       
  2763 		test(iStatus.Int() == KErrNone);
       
  2764 		DoOpNamedL(EImap4OpMoveWithinService, iRemoteInbox, iRemoteFolder1);
       
  2765 		NextState();
       
  2766 		break;
       
  2767 		
       
  2768 		// test populate options
       
  2769 	case 4:
       
  2770 		test(iStatus.Int() == KErrNone);
       
  2771 		DoOpNamedL(EImap4OpDelete, iRemoteInbox, KMsvNullIndexEntryId);
       
  2772 		NextState();
       
  2773 		break;
       
  2774 		
       
  2775 	case 5:
       
  2776 		test(iStatus.Int() == KErrNone);
       
  2777 		DoOpNamedL(EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailHeaders);
       
  2778 		NextState();
       
  2779 		break;
       
  2780 
       
  2781 	case 6:
       
  2782 		test(iStatus.Int() == KErrNone);
       
  2783 		DoOpNamedL(EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailBodyText);
       
  2784 		NextState();
       
  2785 		break;
       
  2786 		
       
  2787 	case 7:
       
  2788 		test(iStatus.Int() == KErrNone);
       
  2789 		DoOpNamedL(EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailBodyTextAndAttachments);
       
  2790 		NextState();
       
  2791 		break;
       
  2792 
       
  2793 	case 8:
       
  2794 		test(iStatus.Int() == KErrNone);
       
  2795 		DoOpNamedL(EImap4OpPopulate, iRemoteInbox, KMsvNullIndexEntryId, EGetImap4EmailAttachments);
       
  2796 		NextState();
       
  2797 		NextState();
       
  2798 		break;
       
  2799 
       
  2800 		// get one specific attachment
       
  2801 	case 9:
       
  2802 		{
       
  2803 		test(iStatus.Int() == KErrNone);
       
  2804 		TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailAttachments);	
       
  2805 		FindAttachmentL();
       
  2806 		DoOpByIdL(EImap4OpPopulate, (*iSelection)[0], package);
       
  2807 		NextState();
       
  2808 		break;
       
  2809 		}
       
  2810 
       
  2811 		// test multiple copies to the same folder as the source
       
  2812 	case 10:
       
  2813 		test(iStatus.Int() == KErrNone);
       
  2814 		DoOpNamedL(EImap4OpCopyWithinFolder, iRemoteInbox, iRemoteInbox);
       
  2815 		NextState();
       
  2816 		break;
       
  2817 		
       
  2818 	case 11:
       
  2819 		test(iStatus.Int() == KErrNone);
       
  2820 		DoOpNamedL(EImap4OpCopyWithinFolder, iRemoteInbox, iRemoteInbox);
       
  2821 		NextState();
       
  2822 		break;
       
  2823 
       
  2824 		// test out operations where the ghost gets deleted
       
  2825 	case 12:
       
  2826 		test(iStatus.Int() == KErrNone);
       
  2827 		iTestUtils->TestFinish(iTestNum++);
       
  2828 
       
  2829 		iTestUtils->TestStart(iTestNum, _L("Setup ghost deletes"));
       
  2830 		DoOpNamedL(EImap4OpCopyToLocalAndDelete, iRemoteInbox, iLocalFolder1);
       
  2831 		NextState();
       
  2832 		break;
       
  2833 
       
  2834 	case 13:
       
  2835 		{
       
  2836 		test(iStatus.Int() == KErrNone);
       
  2837 		TMsvId id = FindShadowL(iLocalFolder1, iSourceId);
       
  2838 		test(id!=KMsvNullIndexEntryId);
       
  2839 
       
  2840 		iEntry->SetEntry(iLocalFolder1);
       
  2841 		iEntry->DeleteEntry(id);
       
  2842 
       
  2843 		DoOpNamedL(EImap4OpCopyWithinServiceAndDelete, iRemoteInbox, iRemoteFolder1);
       
  2844 		NextState();
       
  2845 		break;
       
  2846 		}
       
  2847 		
       
  2848 	case 14:
       
  2849 		test(iStatus.Int() == KErrNone);
       
  2850 		DoOpByIdL(EImap4OpDelete, FindShadowL(iRemoteFolder1, iSourceId));
       
  2851 		NextState();
       
  2852 		break;
       
  2853 
       
  2854 	case 15:
       
  2855 		test(iStatus.Int() == KErrNone);
       
  2856 		DoOpNamedL(EImap4OpMoveToLocalAndDelete, iRemoteInbox, iLocalFolder1);
       
  2857 		NextState();
       
  2858 		break;
       
  2859 	case 16:
       
  2860 		{
       
  2861 		test(iStatus.Int() == KErrNone);
       
  2862 		TMsvId id = FindShadowL(iLocalFolder1, iSourceId);
       
  2863 		test(id!=KMsvNullIndexEntryId);
       
  2864 
       
  2865 		iEntry->SetEntry(iLocalFolder1);
       
  2866 		iEntry->DeleteEntry(id);
       
  2867 
       
  2868 		DoOpNamedL(EImap4OpMoveWithinServiceAndDelete, iRemoteInbox, iRemoteFolder1);
       
  2869 		NextState();
       
  2870 		break;
       
  2871 		}
       
  2872 		
       
  2873 	case 17:
       
  2874 		test(iStatus.Int() == KErrNone);
       
  2875 		DoOpByIdL(EImap4OpDelete, FindShadowL(iRemoteFolder1, iSourceId));
       
  2876 		NextState();
       
  2877 		break;
       
  2878 
       
  2879 		// delete a message from folder 2
       
  2880 	case 18:
       
  2881 		{
       
  2882 		test(iStatus.Int() == KErrNone);
       
  2883 
       
  2884 		TPtrC testMsg = TestMsgName(EImap4OpDelete);
       
  2885 		TMsvId id = FindMessageByNameL(iRemoteFolder2, testMsg);
       
  2886 		DoOpByIdL(EImap4OpDelete, id);
       
  2887 		NextState();
       
  2888 		break;
       
  2889 		}
       
  2890 		
       
  2891 		// and move a message out of folder2
       
  2892 	case 19:
       
  2893 		{
       
  2894 		test(iStatus.Int() == KErrNone);
       
  2895 
       
  2896 		// uses KMessageNameTest
       
  2897 		DoOpL(EImap4OpMoveWithinService, iRemoteFolder2, iRemoteFolder1 );
       
  2898 		NextState();
       
  2899 		break;
       
  2900 		}
       
  2901 		
       
  2902 	case 20:
       
  2903 		{
       
  2904 		test(iStatus.Int() == KErrNone);
       
  2905 		iTestUtils->TestFinish(iTestNum++);
       
  2906 
       
  2907 		TDateTime dateTime;
       
  2908 		dateTime.Set(2100, EJanuary, 1, 0, 0, 0, 0);
       
  2909 		TTime date(dateTime);
       
  2910 		if (!iLogClient)
       
  2911 			iLogClient = CLogClient::NewL(iTestUtils->FileSession());
       
  2912 		SetActive();
       
  2913 		iLogClient->ClearLog(date, iStatus);
       
  2914 		NextState(100);
       
  2915 		break;
       
  2916 		}
       
  2917 		
       
  2918 		// go online and check the results
       
  2919 	case 100:
       
  2920 		test(iStatus.Int() == KErrNone);
       
  2921 
       
  2922 		iTestUtils->TestStart(iTestNum, _L("Go online"));
       
  2923 		DoConnectAndSyncL();
       
  2924 		NextState();
       
  2925 		break;
       
  2926 
       
  2927 	case 101:
       
  2928 		test(iStatus.Int() == KErrNone);
       
  2929 		PerformSpecialOpL(0, KIMAP4MTMIsConnected);
       
  2930 		NextState();
       
  2931 		break;
       
  2932 		
       
  2933 	case 102:
       
  2934 		test(iStatus.Int() == KErrNone);
       
  2935 		PerformSpecialOpL(0, KIMAP4MTMWaitForBackground);
       
  2936 		NextState();
       
  2937 		break;
       
  2938 		
       
  2939 	case 103:
       
  2940 		{
       
  2941 		test(iStatus.Int() == KErrNone);
       
  2942 		iTestUtils->TestFinish(iTestNum++);
       
  2943 
       
  2944 		TMsvId copy;
       
  2945 		TMsvId orig;
       
  2946 
       
  2947 		// check out the CopyToLocal to see if it happened correctly
       
  2948 		iTestUtils->TestStart(iTestNum, _L("CopyToLocal"));
       
  2949 
       
  2950 		copy = FindMessageByOpL(iLocalFolder1, EImap4OpCopyToLocal);
       
  2951 		test(copy!=KErrNotFound);
       
  2952 		test(TestDisconnectedFlags(copy)==ENoDisconnectedOperations);
       
  2953 		test(TestComplete(copy));
       
  2954 
       
  2955 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpCopyToLocal);
       
  2956 		test(orig!=KErrNotFound);
       
  2957 		test(!TestShadowL(iLocalFolder1, orig));
       
  2958 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);
       
  2959 		test(TestComplete(orig));
       
  2960 
       
  2961 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpCopyToLocal, orig, iLocalFolder1 ));
       
  2962 
       
  2963 		iTestUtils->TestFinish(iTestNum++);
       
  2964 
       
  2965 		// check out the CopyWithinService to see if it happened correctly
       
  2966 		iTestUtils->TestStart(iTestNum, _L("CopyWithinService"));
       
  2967 
       
  2968 		copy = FindMessageByOpL(iRemoteFolder1, EImap4OpCopyWithinService);
       
  2969 		test(copy!=KErrNotFound);
       
  2970 		test(TestDisconnectedFlags(copy)==ENoDisconnectedOperations);
       
  2971 
       
  2972 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpCopyWithinService);
       
  2973 		test(orig!=KErrNotFound);
       
  2974 		test(!TestShadowL(iRemoteFolder1, orig));
       
  2975 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);
       
  2976 
       
  2977 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpCopyWithinService, orig, iRemoteFolder1 ));
       
  2978 		iTestUtils->TestFinish(iTestNum++);
       
  2979 
       
  2980 		// check out the MoveToLocal to see if it happened correctly
       
  2981 		iTestUtils->TestStart(iTestNum, _L("MoveToLocal"));
       
  2982 
       
  2983 		copy = FindMessageByOpL(iLocalFolder1, EImap4OpMoveToLocal);
       
  2984 		test(copy!=KErrNotFound);
       
  2985 		test(TestDisconnectedFlags(copy)==ENoDisconnectedOperations);
       
  2986 		test(TestComplete(copy));
       
  2987 
       
  2988 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpMoveToLocal);
       
  2989 		test(orig==KErrNotFound);
       
  2990 
       
  2991 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMoveToLocal, KMsvNullIndexEntryId, iLocalFolder1 ));
       
  2992 		iTestUtils->TestFinish(iTestNum++);
       
  2993 
       
  2994 		// check out the MoveWithinService to see if it happened correctly
       
  2995 		iTestUtils->TestStart(iTestNum, _L("MoveWithinService"));
       
  2996 
       
  2997 		copy = FindMessageByOpL(iRemoteFolder1, EImap4OpMoveWithinService);
       
  2998 		test(copy!=KErrNotFound);
       
  2999 		test(TestDisconnectedFlags(copy)==ENoDisconnectedOperations);
       
  3000 
       
  3001 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpMoveWithinService);
       
  3002 		test(orig==KErrNotFound);
       
  3003 
       
  3004 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMoveWithinService, KMsvNullIndexEntryId, iRemoteFolder1 ));
       
  3005 		iTestUtils->TestFinish(iTestNum++);
       
  3006 		
       
  3007 		// check out the populate tests
       
  3008 		iTestUtils->TestStart(iTestNum, _L("Populate"));
       
  3009 
       
  3010 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpPopulate, EGetImap4EmailHeaders);
       
  3011 		test(orig!=KErrNotFound);
       
  3012 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);	
       
  3013 		test(!TestComplete(orig));
       
  3014 			
       
  3015 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, orig, KMsvNullIndexEntryId, EGetImap4EmailHeaders ));
       
  3016 
       
  3017 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpPopulate, EGetImap4EmailBodyText);
       
  3018 		test(orig!=KErrNotFound);
       
  3019 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);	
       
  3020 		test(!TestComplete(orig));
       
  3021 
       
  3022 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, orig, KMsvNullIndexEntryId, EGetImap4EmailBodyText ));
       
  3023 
       
  3024 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpPopulate, EGetImap4EmailAttachments);
       
  3025 		test(orig!=KErrNotFound);
       
  3026 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);	
       
  3027 		test(!TestComplete(orig));
       
  3028 
       
  3029 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, orig, KMsvNullIndexEntryId, EGetImap4EmailAttachments ));
       
  3030 
       
  3031 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpPopulate, EGetImap4EmailBodyTextAndAttachments);
       
  3032 		test(orig!=KErrNotFound);
       
  3033 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);	
       
  3034 		test(TestComplete(orig));
       
  3035 		
       
  3036 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, orig, KMsvNullIndexEntryId, EGetImap4EmailBodyTextAndAttachments ));
       
  3037 #if 0
       
  3038 		// specific attachment
       
  3039 		FindAttachmentL();
       
  3040 		orig = (*iSelection)[0];
       
  3041 		test(orig!=KErrNotFound);
       
  3042 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);	
       
  3043 		test(TestComplete(orig));
       
  3044 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMtmSpecific, orig, KMsvNullIndexEntryId, EGetImap4EmailBodyTextAndAttachments ));
       
  3045 #endif		
       
  3046 
       
  3047 		iTestUtils->TestFinish(iTestNum++);
       
  3048 
       
  3049 		// check out the CopyWithinFolder to see if it happened
       
  3050 		// correctly, made 2 copies so there should be 3 of them in
       
  3051 		// total
       
  3052 		iTestUtils->TestStart(iTestNum, _L("CopyWithinFolder"));
       
  3053 
       
  3054 		test( CountMessagesByOpL(iRemoteInbox, EImap4OpCopyWithinFolder) == 3 );
       
  3055 
       
  3056 		// check each of the versions for the right flags
       
  3057 		CMsvEntrySelection* children = new (ELeave) CMsvEntrySelection;
       
  3058 		CleanupStack::PushL(children);
       
  3059 			
       
  3060 		User::LeaveIfError(iEntry->SetEntry( iRemoteInbox ));
       
  3061 		User::LeaveIfError(iEntry->GetChildren( *children ));
       
  3062 		
       
  3063 		TPtrC name = TestMsgName( EImap4OpCopyWithinFolder );
       
  3064 		for (TInt i=0; i < children->Count(); i++)
       
  3065 		{
       
  3066 			User::LeaveIfError(iEntry->SetEntry( (*children)[i] ));
       
  3067 			if ( iEntry->Entry().iDescription.Compare( name ) == 0 )
       
  3068 			{
       
  3069 				TMsvId id = (*children)[i];
       
  3070 				test(iEntry->Entry().iRelatedId == KMsvNullIndexEntryId);
       
  3071 				test(TestDisconnectedFlags(id)==ENoDisconnectedOperations);
       
  3072 			}
       
  3073 		}
       
  3074 		CleanupStack::PopAndDestroy();
       
  3075 		iTestUtils->TestFinish(iTestNum++);
       
  3076 
       
  3077 		// check out the ghost deletion tests
       
  3078 		iTestUtils->TestStart(iTestNum, _L("Ghost deletion"));
       
  3079 
       
  3080 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpCopyToLocalAndDelete);	
       
  3081 		test(orig!=KErrNotFound);
       
  3082 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);	
       
  3083 		
       
  3084 		copy = FindMessageByOpL(iLocalFolder1, EImap4OpCopyToLocalAndDelete);
       
  3085 		test(copy==KErrNotFound);
       
  3086 
       
  3087 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpCopyToLocal, orig, iLocalFolder1 ));
       
  3088 
       
  3089 
       
  3090 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpCopyWithinServiceAndDelete);	
       
  3091 		test(orig!=KErrNotFound);
       
  3092 		test(TestDisconnectedFlags(orig)==ENoDisconnectedOperations);
       
  3093 		
       
  3094 		copy = FindMessageByOpL(iRemoteFolder1, EImap4OpCopyWithinServiceAndDelete);
       
  3095 		test(copy==KErrNotFound);
       
  3096 
       
  3097 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpCopyWithinService, orig, iRemoteFolder1 ));
       
  3098 
       
  3099 		
       
  3100 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpMoveToLocalAndDelete);	
       
  3101 		test(orig==KErrNotFound);
       
  3102 		
       
  3103 		copy = FindMessageByOpL(iLocalFolder1, EImap4OpMoveToLocalAndDelete);
       
  3104 		test(copy==KErrNotFound);
       
  3105 
       
  3106 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMoveToLocal, orig, iLocalFolder1 ));
       
  3107 
       
  3108 
       
  3109 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpMoveWithinServiceAndDelete);	
       
  3110 		test(orig==KErrNotFound);
       
  3111 		
       
  3112 		copy = FindMessageByOpL(iRemoteFolder1, EImap4OpMoveWithinServiceAndDelete);
       
  3113 		test(copy==KErrNotFound);
       
  3114 
       
  3115 		test(!TestQueueL(iRemoteInbox, CImOffLineOperation::EOffLineOpMoveWithinService, orig, iRemoteFolder1 ));
       
  3116 
       
  3117 		test(iStatus.Int() == KErrNone);
       
  3118 		iTestUtils->TestFinish(iTestNum++);
       
  3119 
       
  3120 		// check the folder 2 operations
       
  3121 		iTestUtils->TestStart(iTestNum, _L("Move from non-Inbox folder"));
       
  3122 
       
  3123 		copy = FindMessageByNameL(iRemoteFolder1, KMessageNameTest);
       
  3124 		test(copy!=KErrNotFound);
       
  3125 
       
  3126 		//orig = FindMessageByNameL(iRemoteFolder2, KMessageNameTest);
       
  3127 		//test(orig==KErrNotFound);
       
  3128 		
       
  3129 		iTestUtils->TestFinish(iTestNum++);
       
  3130 
       
  3131 		// check the deleted item
       
  3132 		iTestUtils->TestStart(iTestNum, _L("Delete (on connect)"));
       
  3133 
       
  3134 		CImImap4Settings* settings = GetImap4SettingsLC();
       
  3135 
       
  3136 		orig = FindMessageByOpL(iRemoteInbox, EImap4OpDelete);
       
  3137 		test( settings->DeleteEmailsWhenDisconnecting() ?
       
  3138 			  orig!=KErrNotFound : orig==KErrNotFound );
       
  3139 
       
  3140 		CleanupStack::PopAndDestroy(); // settings
       
  3141 		iTestUtils->TestFinish(iTestNum++);
       
  3142 #if 0
       
  3143 		iTestUtils->TestStart(iTestNum, _L("Logging"));
       
  3144 
       
  3145 		// set up the logview to test the logging messages
       
  3146 		if (!iLogView)
       
  3147 			{
       
  3148 			iLogView = CLogViewEvent::NewL(*iLogClient);
       
  3149 			if (!iLogFilter)
       
  3150 				{
       
  3151 				iLogFilter = CLogFilter::NewL();
       
  3152 				iLogFilter->SetEventType(KLogMailEventTypeUid);
       
  3153 				}
       
  3154 			}
       
  3155 		SetActive();
       
  3156 		iLogView->SetFilterL(*iLogFilter, iStatus);
       
  3157 		NextState(100);
       
  3158 		break;
       
  3159 		}
       
  3160 
       
  3161 	case 200:
       
  3162 		// CopyToLocaL/MoveToLocal and 4 brands of Populate
       
  3163 		test.Printf(_L("LogEvent: %d\n"), iLogView->CountL());
       
  3164 		test(iLogView->CountL() == 6 );
       
  3165 
       
  3166 		SetActive();
       
  3167 		test(iLogView->FirstL(iStatus) != EFalse);
       
  3168 		NextState();
       
  3169 		break;
       
  3170 
       
  3171 		// IMAPOFFL rules say that the order is populate, copytolocal,
       
  3172 		// movetolocal, within that it is in order of usage. The
       
  3173 		// LogView events come out most recent first (ie reverse
       
  3174 		// order) thus leading to the order we see here.
       
  3175 	case 201:
       
  3176 		{
       
  3177 		// check MoveToLocal
       
  3178 		const CLogEvent& logEvent = iLogView->Event();
       
  3179 
       
  3180 		//TPtrC remoteParty = logEvent.RemoteParty();
       
  3181 		//TPtrC direction = logEvent.Direction();
       
  3182 		//TPtrC subject = logEvent.Subject();
       
  3183 		//test.Printf(_L("LogEvent: '%S' '%S' '%S'\n"), &remoteParty, &subject, &direction);
       
  3184 
       
  3185 		test(logEvent.RemoteParty() == KTestRemoteParty);
       
  3186 		test(logEvent.Subject() == TestMsgName(EImap4OpMoveToLocal));
       
  3187 		test(logEvent.Direction() == _L("Fetched"));
       
  3188 
       
  3189 		SetActive();
       
  3190 		test(iLogView->NextL(iStatus) != EFalse);
       
  3191 		NextState();
       
  3192 		break;
       
  3193 		}
       
  3194 		
       
  3195 	case 202:
       
  3196 		{
       
  3197 		// check CopyToLocal
       
  3198 		const CLogEvent& logEvent = iLogView->Event();
       
  3199 		test(logEvent.RemoteParty() == KTestRemoteParty);
       
  3200 		test(logEvent.Subject() == TestMsgName(EImap4OpCopyToLocal));
       
  3201 		test(logEvent.Direction() == _L("Fetched"));
       
  3202 
       
  3203 		SetActive();
       
  3204 		test(iLogView->NextL(iStatus) != EFalse);
       
  3205 		NextState();
       
  3206 		NextState();
       
  3207 		break;
       
  3208 		}
       
  3209 		
       
  3210 	case 203:
       
  3211 		{
       
  3212 		// check Populate single attachment
       
  3213 		const CLogEvent& logEvent = iLogView->Event();
       
  3214 		//test(logEvent.RemoteParty() == KTestRemoteParty);
       
  3215 		//test(logEvent.Subject() == TestMsgName(EImap4OpPopulate, EGetImap4EmailAttachments));
       
  3216 		test(logEvent.Direction() == _L("Fetched"));
       
  3217 
       
  3218 		SetActive();
       
  3219 		test(iLogView->NextL(iStatus) != EFalse);
       
  3220 		NextState();
       
  3221 		break;
       
  3222 		}
       
  3223 		
       
  3224 	case 204:
       
  3225 		{
       
  3226 		// check Populate
       
  3227 		const CLogEvent& logEvent = iLogView->Event();
       
  3228 		test(logEvent.RemoteParty() == KTestRemoteParty);
       
  3229 		test(logEvent.Subject() == TestMsgName(EImap4OpPopulate, EGetImap4EmailAttachments));
       
  3230 		test(logEvent.Direction() == _L("Fetched"));
       
  3231 
       
  3232 		SetActive();
       
  3233 		test(iLogView->NextL(iStatus) != EFalse);
       
  3234 		NextState();
       
  3235 		break;
       
  3236 		}
       
  3237 		
       
  3238 	case 205:
       
  3239 		{
       
  3240 		// check Populate
       
  3241 		const CLogEvent& logEvent = iLogView->Event();
       
  3242 		test(logEvent.RemoteParty() == KTestRemoteParty);
       
  3243 		test(logEvent.Subject() == TestMsgName(EImap4OpPopulate, EGetImap4EmailBodyTextAndAttachments));
       
  3244 		test(logEvent.Direction() == _L("Fetched"));
       
  3245 
       
  3246 		SetActive();
       
  3247 		test(iLogView->NextL(iStatus) != EFalse);
       
  3248 		NextState();
       
  3249 		break;
       
  3250 		}
       
  3251 		
       
  3252 	case 206:
       
  3253 		{
       
  3254 		// check Populate
       
  3255 		const CLogEvent& logEvent = iLogView->Event();
       
  3256 		test(logEvent.RemoteParty() == KTestRemoteParty);
       
  3257 		test(logEvent.Subject() == TestMsgName(EImap4OpPopulate, EGetImap4EmailBodyText));
       
  3258 		test(logEvent.Direction() == _L("Fetched"));
       
  3259 
       
  3260 		SetActive();
       
  3261 		test(iLogView->NextL(iStatus) != EFalse);
       
  3262 		NextState();
       
  3263 		break;
       
  3264 		}
       
  3265 
       
  3266 	case 207:
       
  3267 		{
       
  3268 		// check Populate
       
  3269 		const CLogEvent& logEvent = iLogView->Event();
       
  3270 		test(logEvent.RemoteParty() == KTestRemoteParty);
       
  3271 		test(logEvent.Subject() == TestMsgName(EImap4OpPopulate, EGetImap4EmailHeaders));
       
  3272 		test(logEvent.Direction() == _L("Fetched"));
       
  3273 
       
  3274 		iTestUtils->TestFinish(iTestNum++);
       
  3275 #endif
       
  3276 		// now disconnect and test deletion
       
  3277 		iTestUtils->TestStart(iTestNum, _L("Disconnect"));
       
  3278  		DoDisconnectL();
       
  3279 		NextState(100);
       
  3280 		break;
       
  3281 		}
       
  3282 		
       
  3283 	case 200:
       
  3284 		{
       
  3285 		test(iStatus.Int() == KErrNone);
       
  3286 		iTestUtils->TestFinish(iTestNum++);
       
  3287 
       
  3288 		// check the deleted item
       
  3289 		CImImap4Settings* settings = GetImap4SettingsLC();
       
  3290 
       
  3291 		iTestUtils->TestStart(iTestNum, _L("Delete (on disconnect)"));
       
  3292 
       
  3293 		if (settings->DeleteEmailsWhenDisconnecting())
       
  3294 			{
       
  3295 			TMsvId orig = FindMessageByOpL(iRemoteInbox, EImap4OpDelete);
       
  3296 			test( orig==KErrNotFound );
       
  3297 			}
       
  3298 
       
  3299 		iTestUtils->TestFinish(iTestNum++);
       
  3300 
       
  3301 		CleanupStack::PopAndDestroy(); // settings
       
  3302 
       
  3303 		// now setup for some further tests
       
  3304 		iTestUtils->TestStart(iTestNum, _L("MoveWithinServiceToInbox"));
       
  3305 		DoOpNamedL(EImap4OpMoveWithinServiceToInbox, iRemoteFolder1, iRemoteInbox);
       
  3306 		NextState();
       
  3307 		break;
       
  3308 		}
       
  3309 
       
  3310 	case 201:
       
  3311 		test(iStatus.Int() == KErrNone);
       
  3312 		DoConnectAndSyncL();
       
  3313 		NextState();
       
  3314 		break;
       
  3315 
       
  3316 	case 202:
       
  3317 		test(iStatus.Int() == KErrNone);
       
  3318 		PerformSpecialOpL(0, KIMAP4MTMWaitForBackground);
       
  3319 		NextState();
       
  3320 		break;
       
  3321 		
       
  3322 	case 203:
       
  3323 		test(iStatus.Int() == KErrNone);
       
  3324 		PerformSpecialOpL(iRemoteInbox, KIMAP4MTMSelect);
       
  3325 		NextState();
       
  3326 		break;
       
  3327 
       
  3328 	case 204:
       
  3329 		test(iStatus.Int() == KErrNone);
       
  3330 		PerformSpecialOpL(iRemoteInbox, KIMAP4MTMSynchronise);
       
  3331 		NextState();
       
  3332 		break;
       
  3333 		
       
  3334 	case 205:
       
  3335 		{
       
  3336 		test(iStatus.Int() == KErrNone);
       
  3337 
       
  3338 		// see if new message exists
       
  3339 		TMsvId orig = FindMessageByOpL(iRemoteInbox, EImap4OpMoveWithinServiceToInbox);
       
  3340 		test(orig!=KErrNotFound);
       
  3341 
       
  3342 		// check old message doesn't exist
       
  3343 		orig = FindMessageByOpL(iRemoteFolder1, EImap4OpMoveWithinServiceToInbox);
       
  3344 		test(orig==KErrNotFound);
       
  3345 
       
  3346 		iTestUtils->TestFinish(iTestNum++);
       
  3347 
       
  3348 		// done
       
  3349 		iTestUtils->TestHarnessCompleted();
       
  3350 		EndOfTest();  
       
  3351 		
       
  3352 		test.Console()->SetPos(0, 13);
       
  3353 		test.Printf(_L("Finished sync tests\n"));
       
  3354 		more = EFalse;
       
  3355 		break;
       
  3356 		}		
       
  3357 
       
  3358 	default:
       
  3359 		NextState(100);
       
  3360 		break;
       
  3361 		}
       
  3362 	return more; 
       
  3363 	}
       
  3364 
       
  3365 void CTestRefreshMBox::DoAutomatedSyncOpsL()
       
  3366 	{
       
  3367 	if (iServiceId==NULL)
       
  3368 		{
       
  3369 		test.Printf(_L("No service ID\n"));
       
  3370 		return;
       
  3371 		}
       
  3372 
       
  3373 	if (iRemoteFolder1<=KMsvNullIndexEntryId)
       
  3374 		iRemoteFolder1=FindFolderByNameL(iServiceId,_L("Test1"));
       
  3375 		
       
  3376 	if (iRemoteFolder2<=KMsvNullIndexEntryId)	
       
  3377 		iRemoteFolder2=FindFolderByNameL(iServiceId,_L("Test2"));
       
  3378 
       
  3379 	if (iRemoteFolder1<=KMsvNullIndexEntryId ||
       
  3380 		iRemoteFolder2<=KMsvNullIndexEntryId)	
       
  3381 		{
       
  3382 		test.Printf(_L("Don't have both the remote folders\n"));
       
  3383 		}
       
  3384 	else
       
  3385 		{
       
  3386 		iOpState = 0;
       
  3387 		iState = EImapTestAutoSyncOp;
       
  3388 		HandleSyncStateL();
       
  3389 		}
       
  3390 	}
       
  3391 
       
  3392 /* ----------------------------------------------------------------------- */
       
  3393 
       
  3394 void CTestRefreshMBox::DoAutomatedSecondaryConnectOpsL()
       
  3395 	{
       
  3396 	if (iServiceId==NULL)
       
  3397 		{
       
  3398 		test.Printf(_L("No service ID\n"));
       
  3399 		return;
       
  3400 		}
       
  3401 
       
  3402 	if (iRemoteFolder1<=KMsvNullIndexEntryId)
       
  3403 		iRemoteFolder1=FindFolderByNameL(iServiceId,_L("Test1"));
       
  3404 		
       
  3405 	if (iRemoteFolder2<=KMsvNullIndexEntryId)	
       
  3406 		iRemoteFolder2=FindFolderByNameL(iServiceId,_L("Test2"));
       
  3407 
       
  3408 	if (iRemoteFolder1<=KMsvNullIndexEntryId ||
       
  3409 		iRemoteFolder2<=KMsvNullIndexEntryId)	
       
  3410 		{
       
  3411 		test.Printf(_L("Don't have both the remote folders\n"));
       
  3412 		}
       
  3413 	else
       
  3414 		{
       
  3415 		iOpState = 0;
       
  3416 		iState = EImapTestAutoSecondaryConnect;
       
  3417 		
       
  3418 		TestSecondaryConnectStateMachineL();
       
  3419 		}
       
  3420 	}
       
  3421 
       
  3422 TBool CTestRefreshMBox::TestSecondaryConnectStateMachineL()
       
  3423 	{
       
  3424 	TBool more = ETrue;
       
  3425 	TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailBodyText);
       
  3426 	TMsvId id;
       
  3427 
       
  3428 	switch (iOpState)
       
  3429 		{
       
  3430 	case 0:
       
  3431 		iTestUtils->TestStart(iTestNum, _L("Test Secondary connection"));
       
  3432 
       
  3433 		// subscribe to the backup folder initially to lengthen the
       
  3434 		// background sync time
       
  3435 		id = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  3436 		PerformSpecialOpL(id, KIMAP4MTMLocalSubscribe);
       
  3437 		NextState();
       
  3438 		break;
       
  3439 		
       
  3440 	case 1:
       
  3441 		DoConnectAndSyncL();
       
  3442 		NextState(100);
       
  3443 		break;
       
  3444 
       
  3445 	case 100:
       
  3446 		test(iStatus.Int() == KErrNone);
       
  3447 
       
  3448 		id = FindMessageByNameL(iRemoteInbox, _L("Test: 3"));
       
  3449 		DoOpByIdL(EImap4OpPopulate, id, package);
       
  3450 		NextState();
       
  3451 		break;
       
  3452 
       
  3453 	case 101:
       
  3454 		test(iStatus.Int() == KErrNone);
       
  3455 
       
  3456 		id = FindMessageByNameL(iRemoteInbox, _L("Test: 4"));
       
  3457 		DoOpByIdL(EImap4OpPopulate, id, package);
       
  3458 		NextState();
       
  3459 		break;
       
  3460 
       
  3461 	case 102:
       
  3462 		test(iStatus.Int() == KErrNone);
       
  3463 
       
  3464 		id = FindMessageByNameL(iRemoteInbox, _L("Test: 5"));
       
  3465 		DoOpByIdL(EImap4OpPopulate, id, package);
       
  3466 		NextState();
       
  3467 		break;
       
  3468 
       
  3469 		// at this point the server should still be busy with the
       
  3470 		// background sync. So check that we get ServerBusy replies
       
  3471 		// from everyone. This tests that the ServerBusy check happens
       
  3472 		// correctly and also tht the 3 fetches above all happened
       
  3473 		// whilst background syncing
       
  3474 	case 103:
       
  3475 		test(iStatus.Int() == KErrNone);
       
  3476 		PerformSpecialOpL(0, KIMAP4MTMBusy);
       
  3477 		NextState();
       
  3478 		break;
       
  3479 
       
  3480 	case 104:
       
  3481 		test(iStatus.Int() == KErrServerBusy);
       
  3482 		PerformSpecialOpL(0, KIMAP4MTMFullSync);
       
  3483 		NextState();
       
  3484 		break;
       
  3485 
       
  3486 	case 105:
       
  3487 		test(iStatus.Int() == KErrServerBusy);
       
  3488 		PerformSpecialOpL(0, KIMAP4MTMSyncTree);
       
  3489 		NextState();
       
  3490 		break;
       
  3491 
       
  3492 	case 106:
       
  3493 		test(iStatus.Int() == KErrServerBusy);
       
  3494 		PerformSpecialOpL(0, KIMAP4MTMInboxNewSync);
       
  3495 		NextState();
       
  3496 		break;
       
  3497 		
       
  3498 	case 107:
       
  3499 		test(iStatus.Int() == KErrServerBusy);
       
  3500 
       
  3501 		// and then wait for the background sync to finish before
       
  3502 		// disconnecting
       
  3503 		PerformSpecialOpL(0, KIMAP4MTMCancelBackgroundSynchronise);
       
  3504 		NextState();
       
  3505 		break;
       
  3506 		
       
  3507 	case 108:
       
  3508 		test(iStatus.Int() == KErrCancel);
       
  3509 		// just check busy returns OK this time
       
  3510 		PerformSpecialOpL(0, KIMAP4MTMBusy);
       
  3511 		NextState(100);
       
  3512 		break;
       
  3513 		
       
  3514 	case 200:
       
  3515 		test(iStatus.Int() == KErrNone);
       
  3516 		DoDisconnectL();
       
  3517 		NextState();
       
  3518 		break;
       
  3519 		
       
  3520 	case 201:
       
  3521 		id = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  3522 		PerformSpecialOpL(id, KIMAP4MTMLocalUnsubscribe);
       
  3523 		NextState();
       
  3524 		break;
       
  3525 		
       
  3526 	case 202:
       
  3527 		iTestUtils->TestFinish(iTestNum++);
       
  3528 		iTestUtils->TestHarnessCompleted();
       
  3529 		EndOfTest();  
       
  3530 		// done
       
  3531 		test.Console()->SetPos(0, 13);
       
  3532 		test.Printf(_L("Finished sync tests\n"));
       
  3533 		more = EFalse;
       
  3534 		break;
       
  3535 		}
       
  3536 	return more;
       
  3537 	}
       
  3538 
       
  3539 /* ----------------------------------------------------------------------- */
       
  3540 
       
  3541 /*
       
  3542 
       
  3543   When we connect to the server the first time we will find that we
       
  3544   have all the messages we require in the INBOX and no other folders
       
  3545   present.
       
  3546 
       
  3547   So we copy the messages to the Backup folder and create our other
       
  3548   required test folders.
       
  3549 
       
  3550   On subsequent occasions we wish to copy any missing messages from
       
  3551   Backup to INBOX and delete any excess messages from inbox and from
       
  3552   the other test folders.
       
  3553 
       
  3554   */
       
  3555 
       
  3556 TBool CTestRefreshMBox::StateMachineCheckServerContentsL()
       
  3557 	{
       
  3558 	TBool more = ETrue;
       
  3559 	TMsvId id;
       
  3560 	
       
  3561 	while (!IsActive() && more)
       
  3562 		{
       
  3563 		switch (iOpState)
       
  3564 			{
       
  3565 		case 0:
       
  3566 			iTestUtils->TestStart(iTestNum, _L("Check server contents"));
       
  3567 			
       
  3568 			// start with nothing subscribed locally and update remote
       
  3569 			// to be the same
       
  3570 			SetSubscriptionsL( EUseLocal, EUpdateNeither );
       
  3571 	
       
  3572 			DoConnectL();
       
  3573 			NextState();
       
  3574 			break;
       
  3575 
       
  3576 		case 1:
       
  3577 			test(iStatus.Int() == KErrNone);
       
  3578 			DoSyncTreeL();
       
  3579 			NextState(10);
       
  3580 			break;
       
  3581 
       
  3582 			// create directories
       
  3583 		case 10:
       
  3584 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  3585 			if (id == KErrNotFound)
       
  3586 				DoFolderCreateL(iServiceId,_L("Backup"));
       
  3587 			NextState();
       
  3588 			break;
       
  3589 
       
  3590 		case 11:
       
  3591 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3592 			if (id == KErrNotFound)
       
  3593 				DoFolderCreateL(iServiceId,_L("Test1"));
       
  3594 			NextState();
       
  3595 			break;
       
  3596 
       
  3597 		case 12:
       
  3598 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3599 			if (id == KErrNotFound)
       
  3600 				DoFolderCreateL(iServiceId,_L("Test2"));
       
  3601 			NextState();
       
  3602 			break;
       
  3603 
       
  3604 		case 13:
       
  3605 			id = FindFolderByNameL(iServiceId, KFolderNameToEncode);
       
  3606 			if (id == KErrNotFound)
       
  3607 				DoFolderCreateL(iServiceId, KFolderNameToEncode);
       
  3608 			NextState();
       
  3609 			break;
       
  3610 
       
  3611 		case 14:
       
  3612 			DoFolderCreateL(iServiceId,_L("Test3"));
       
  3613 			NextState();
       
  3614 			break;
       
  3615 
       
  3616 		case 15:
       
  3617 			test( FindFolderByNameL(iServiceId,_L("Test3")) != KErrNotFound );
       
  3618 			DoFolderRemoveL(iServiceId,_L("Test3"));
       
  3619 			NextState();
       
  3620 			break;
       
  3621 
       
  3622 			// resync to see folder deletion
       
  3623 		case 16:
       
  3624 			DoSyncTreeL();
       
  3625 			NextState();
       
  3626 			break;
       
  3627 
       
  3628 		case 17:
       
  3629 			test( FindFolderByNameL(iServiceId,_L("Test3")) == KErrNotFound );
       
  3630 			NextState(10);
       
  3631 			break;
       
  3632 
       
  3633 #if 0
       
  3634 		case 13:
       
  3635 			id = FindFolderByNameL(iServiceId, _L("TestHier1"));
       
  3636 			if (id == KErrNotFound)
       
  3637 				DoFolderCreateL(iServiceId,_L("TestHier1/"));
       
  3638 			NextState();
       
  3639 			break;
       
  3640 
       
  3641 		case 14:
       
  3642 			{
       
  3643 			TMsvId id1 = FindFolderByNameL(iServiceId, _L("TestHier1"));
       
  3644 			id = FindFolderByNameL(id1, _L("TestHier2"));
       
  3645 			if (id == KErrNotFound)
       
  3646 				DoFolderCreateL(id1, _L("TestHier2/"));
       
  3647 			NextState();
       
  3648 			break;
       
  3649 			}
       
  3650 
       
  3651 		case 15:
       
  3652 			{
       
  3653 			TMsvId id1 = FindFolderByNameL(iServiceId, _L("TestHier1"));
       
  3654 			TMsvId id2 = FindFolderByNameL(id1, _L("TestHier2"));
       
  3655 			id = FindFolderByNameL(id2, _L("TestHier3"));
       
  3656 			if (id == KErrNotFound)
       
  3657 				DoFolderCreateL(id2, _L("TestHier3"));
       
  3658 			NextState();
       
  3659 			break;
       
  3660 			}
       
  3661 
       
  3662 		case 16:
       
  3663 			{
       
  3664 			TMsvId id1 = FindFolderByNameL(iServiceId, _L("TestHier1"));
       
  3665 			TMsvId id2 = FindFolderByNameL(id1, _L("TestHier2"));
       
  3666 			TMsvId id3 = FindFolderByNameL(id2, _L("TestHier3"));
       
  3667 
       
  3668 			TMsvId id = FindMessageByNameL(iRemoteInbox, KMessageNameTest);
       
  3669 			iSelection->Reset();
       
  3670 			iSelection->AppendL(id);
       
  3671 			iImppServerMtm->CopyWithinServiceL(*iSelection, id3, iStatus);
       
  3672 			SetActive();
       
  3673 			
       
  3674 			NextState();
       
  3675 			break;
       
  3676 			}
       
  3677 #endif
       
  3678 
       
  3679 			// Sync some folders
       
  3680 		case 20:
       
  3681 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  3682 			PerformSpecialOpL(id, KIMAP4MTMSelect);
       
  3683 			NextState();
       
  3684 			break;
       
  3685 
       
  3686 		case 21:
       
  3687 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  3688 			PerformSpecialOpL(id, KIMAP4MTMSynchronise);
       
  3689 			NextState();
       
  3690 			break;
       
  3691 
       
  3692 		case 22:
       
  3693 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3694 			PerformSpecialOpL(id, KIMAP4MTMSelect);
       
  3695 			NextState();
       
  3696 			break;
       
  3697 
       
  3698 		case 23:
       
  3699 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3700 			PerformSpecialOpL(id, KIMAP4MTMSynchronise);
       
  3701 			NextState();
       
  3702 			break;
       
  3703 
       
  3704 		case 24:
       
  3705 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3706 			PerformSpecialOpL(id, KIMAP4MTMSelect);
       
  3707 			NextState();
       
  3708 			break;
       
  3709 
       
  3710 		case 25:
       
  3711 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3712 			PerformSpecialOpL(id, KIMAP4MTMSynchronise);
       
  3713 			NextState();
       
  3714 			break;
       
  3715 
       
  3716 		case 26:
       
  3717 			PerformSpecialOpL(iRemoteInbox, KIMAP4MTMSelect);
       
  3718 			NextState();
       
  3719 			break;
       
  3720 
       
  3721 		case 27:
       
  3722 			PerformSpecialOpL(iRemoteInbox, KIMAP4MTMSynchronise);
       
  3723 			NextState(10);
       
  3724 			break;
       
  3725 
       
  3726 			// take copy of inbox into Backup
       
  3727 		case 30:
       
  3728 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  3729 			User::LeaveIfError(iEntry->SetEntry(id));
       
  3730 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  3731 			if (iSelection->Count() == 0)
       
  3732 				{
       
  3733 				User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  3734 				User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  3735 				iImppServerMtm->CopyWithinServiceL(*iSelection, id, iStatus);
       
  3736 				SetActive();
       
  3737 				}
       
  3738 			NextState();
       
  3739 			break;
       
  3740 			
       
  3741 			// clean out Test1 directory
       
  3742 		case 31:
       
  3743 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3744 			User::LeaveIfError(iEntry->SetEntry(id));
       
  3745 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  3746 			if (iSelection->Count() != 0)
       
  3747 				{
       
  3748 				iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  3749 				SetActive();
       
  3750 				}
       
  3751 			NextState();
       
  3752 			break;
       
  3753 
       
  3754 			// clean out Test2 directory
       
  3755 		case 32:
       
  3756 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3757 			User::LeaveIfError(iEntry->SetEntry(id));
       
  3758 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  3759 			if (iSelection->Count() != 0)
       
  3760 				{
       
  3761 				iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  3762 				SetActive();
       
  3763 				}
       
  3764 			NextState();
       
  3765 			break;
       
  3766 
       
  3767 			// clean out inbox
       
  3768 		case 33:
       
  3769 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  3770 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  3771 			if (iSelection->Count() != 0)
       
  3772 				{
       
  3773 				iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  3774 				SetActive();
       
  3775 				}
       
  3776 			NextState();
       
  3777 			break;
       
  3778 
       
  3779 			// take copy of backup into inbox
       
  3780 		case 34:
       
  3781 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  3782 			User::LeaveIfError(iEntry->SetEntry(id));
       
  3783 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  3784 			if (iSelection->Count() != 0)
       
  3785 				{
       
  3786 				iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  3787 				SetActive();
       
  3788 				}
       
  3789 			NextState(10);
       
  3790 			break;
       
  3791 
       
  3792 			// fetch Test message to Local
       
  3793 		case 40:
       
  3794 			id = FindMessageByNameL(KMsvGlobalInBoxIndexEntryId, KMessageNameTest);
       
  3795 			// fetch if not already present locally
       
  3796 			if (id == KErrNotFound)
       
  3797 				DoFetchTestL();
       
  3798 			NextState();
       
  3799 			break;
       
  3800 
       
  3801 			// fetch Test messages to Test2
       
  3802 		case 41:
       
  3803 			{
       
  3804 			TMsvId test2Id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3805 			iSelection->Reset();
       
  3806 
       
  3807 			id = FindMessageByNameL(test2Id, KMessageNameTest);
       
  3808 			if (id == KErrNotFound)
       
  3809 				{
       
  3810 				id = FindMessageByNameL(iRemoteInbox, KMessageNameTest);
       
  3811 				iSelection->AppendL(id);
       
  3812 				}
       
  3813 
       
  3814 			TPtrC testMsg = TestMsgName(EImap4OpDelete);
       
  3815 			id = FindMessageByNameL(test2Id, testMsg);
       
  3816 			if (id == KErrNotFound)
       
  3817 				{
       
  3818 				id = FindMessageByNameL(iRemoteInbox, testMsg);
       
  3819 				iSelection->AppendL(id);
       
  3820 				}
       
  3821 
       
  3822 			if (iSelection->Count())
       
  3823 				{
       
  3824 				SetActive();
       
  3825 				iImppServerMtm->CopyWithinServiceL(*iSelection, test2Id, iStatus);
       
  3826 				}
       
  3827 
       
  3828 			NextState();
       
  3829 			break;
       
  3830 			}
       
  3831 
       
  3832 			// fetch message with dodgy numeric id in it
       
  3833 		case 42:
       
  3834 			{
       
  3835 			iTestUtils->WriteComment(_L("Check message with numeric attachment"));
       
  3836 			
       
  3837 			TMsvId id = FindMessageByNameL(iRemoteInbox, _L("Test: 31"));
       
  3838 
       
  3839 			// first test that the size is small before fetching
       
  3840 			User::LeaveIfError(iEntry->SetEntry(id));
       
  3841 			test(iEntry->Entry().iSize > 0 );
       
  3842 			test(iEntry->Entry().iSize < 1024 );
       
  3843 			
       
  3844 			TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailBodyTextAndAttachments);	
       
  3845 			DoOpByIdL( EImap4OpPopulate, id, package );
       
  3846 			
       
  3847 			NextState();
       
  3848 			break;
       
  3849 			}
       
  3850 			
       
  3851 		case 43:
       
  3852 			{
       
  3853 			TMsvId id = FindMessageByNameL(iRemoteInbox, _L("Test: 31"));
       
  3854 
       
  3855 			// now test that the size is small after fetching
       
  3856 			User::LeaveIfError(iEntry->SetEntry(id));
       
  3857 			test(TestComplete(id));
       
  3858 			test(iEntry->Entry().iSize > 0 );
       
  3859 			test(iEntry->Entry().iSize < 1024 );
       
  3860 
       
  3861 			NextState();
       
  3862 			break;
       
  3863 			}
       
  3864 
       
  3865 			// Fetch message with attachment name > 256 chars
       
  3866 		case 44:
       
  3867 			{
       
  3868 			iTestUtils->WriteComment(_L("Check message with attachment name > 256 chars"));
       
  3869 
       
  3870 			TMsvId id = FindMessageByNameL(iRemoteInbox, _L("Test: 32"));
       
  3871 
       
  3872 			TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailBodyTextAndAttachments);	
       
  3873 			DoOpByIdL( EImap4OpPopulate, id, package );
       
  3874 
       
  3875 			NextState();
       
  3876 			break;
       
  3877 			}
       
  3878 
       
  3879 		case 45:
       
  3880 			{
       
  3881 			TMsvId id = FindMessageByNameL(iRemoteInbox, _L("Test: 32"));
       
  3882 
       
  3883 			test(TestComplete(id));
       
  3884 
       
  3885 			NextState();
       
  3886 			break;
       
  3887 			}
       
  3888 			
       
  3889 			// Fetch message with attachment name slightly < 256 chars
       
  3890 		case 46:
       
  3891 			{
       
  3892 			iTestUtils->WriteComment(_L("Check message with attachment name nearly 256 chars"));
       
  3893 			
       
  3894 			TMsvId id = FindMessageByNameL(iRemoteInbox, _L("Test: 33"));
       
  3895 
       
  3896 			TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailBodyTextAndAttachments);	
       
  3897 			DoOpByIdL( EImap4OpPopulate, id, package );
       
  3898 
       
  3899 			NextState();
       
  3900 			break;
       
  3901 			}
       
  3902 
       
  3903 		case 47:
       
  3904 			{
       
  3905 			TMsvId id = FindMessageByNameL(iRemoteInbox, _L("Test: 33"));
       
  3906 
       
  3907 			test(TestComplete(id));
       
  3908 
       
  3909 			NextState(100);
       
  3910 			break;
       
  3911 			}
       
  3912 			
       
  3913 			// check subscription code
       
  3914 			// all subscriptions should have been cleared by the previous connect
       
  3915 		case 100:
       
  3916 			DoDisconnectL();
       
  3917 			NextState();
       
  3918 			break;
       
  3919 
       
  3920 			// set Test1 locally subscribed and Test2 unsubscribed and
       
  3921 			// mirror this to the server
       
  3922 		case 101:
       
  3923 			iTestUtils->WriteComment(_L("Check subscriptions"));
       
  3924 			SetSubscriptionsL( EUseLocal, EUpdateRemote );
       
  3925 
       
  3926 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3927 			PerformSpecialOpL(id, KIMAP4MTMLocalSubscribe);
       
  3928 			NextState();
       
  3929 			break;
       
  3930 
       
  3931 		case 102:
       
  3932 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3933 			PerformSpecialOpL(id, KIMAP4MTMLocalUnsubscribe);
       
  3934 			NextState();
       
  3935 			break;
       
  3936 
       
  3937 		case 103:
       
  3938 			DoConnectL();
       
  3939 			NextState();
       
  3940 			break;
       
  3941 
       
  3942 		case 104:
       
  3943 			DoFullSyncL();
       
  3944 			NextState();
       
  3945 			break;
       
  3946 
       
  3947 		case 105:
       
  3948 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3949 			test( TestLocalSubscription(id) );
       
  3950 			test( TestSubscribed(id) );
       
  3951 
       
  3952 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3953 			test( TestNotLocalSubscription(id) );
       
  3954 			test( TestNotSubscribed(id) );
       
  3955 
       
  3956 			DoDisconnectL();
       
  3957 			NextState(10);
       
  3958 			break;
       
  3959 
       
  3960 
       
  3961 			// locally unsubscribe Test1 and subscribe Test2 and then
       
  3962 			// get the server versions
       
  3963 		case 110:
       
  3964 			SetSubscriptionsL( EUseRemote, EUpdateLocal );
       
  3965 
       
  3966 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3967 			PerformSpecialOpL(id, KIMAP4MTMLocalUnsubscribe);
       
  3968 			NextState();
       
  3969 			break;
       
  3970 			
       
  3971 		case 111:
       
  3972 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3973 			PerformSpecialOpL(id, KIMAP4MTMLocalSubscribe);
       
  3974 			NextState();
       
  3975 			break;
       
  3976 
       
  3977 		case 112:
       
  3978 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3979 			test( TestNotLocalSubscription(id) );
       
  3980 
       
  3981 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  3982 			test( TestLocalSubscription(id) );
       
  3983 
       
  3984 			DoConnectL();
       
  3985 			NextState();
       
  3986 			break;
       
  3987 
       
  3988 		case 113:
       
  3989 			DoFullSyncL();
       
  3990 			NextState();
       
  3991 			break;
       
  3992 
       
  3993 			// which should leave us back at Test1 subscribed and
       
  3994 			// Test2 unsubscribed
       
  3995 		case 114:
       
  3996 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  3997 			test( TestLocalSubscription(id) );
       
  3998 			test( TestSubscribed(id) );
       
  3999 
       
  4000 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  4001 			test( TestNotLocalSubscription(id) );
       
  4002 			test( TestNotSubscribed(id) );
       
  4003 
       
  4004 			DoDisconnectL();
       
  4005 			NextState(10);
       
  4006 			break;
       
  4007 
       
  4008 			// then locally subscribe Test2 (so both are now
       
  4009 			// subscribed) and update both
       
  4010 		case 120:
       
  4011 			SetSubscriptionsL( EUseCombination, EUpdateBoth );
       
  4012 
       
  4013 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  4014 			PerformSpecialOpL(id, KIMAP4MTMLocalSubscribe);
       
  4015 
       
  4016 			NextState();
       
  4017 			break;
       
  4018 
       
  4019 		case 121:
       
  4020 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  4021 			test( TestLocalSubscription(id) );
       
  4022 
       
  4023 			DoConnectL();
       
  4024 			NextState();
       
  4025 			break;
       
  4026 
       
  4027 		case 122:
       
  4028 			DoFullSyncL();
       
  4029 			NextState();
       
  4030 			break;
       
  4031 
       
  4032 			// which should leave us with both subscribed
       
  4033 		case 123:
       
  4034 			id = FindFolderByNameL(iServiceId, _L("Test1"));
       
  4035 			test( TestLocalSubscription(id) );
       
  4036 			test( TestSubscribed(id) );
       
  4037 
       
  4038 			id = FindFolderByNameL(iServiceId, _L("Test2"));
       
  4039 			test( TestLocalSubscription(id) );
       
  4040 			test( TestSubscribed(id) );
       
  4041 
       
  4042 			DoDisconnectL();
       
  4043 			NextState(100);
       
  4044 			break;
       
  4045 
       
  4046 		case 200:
       
  4047 			test(iStatus.Int() == KErrNone);
       
  4048 
       
  4049 			iTestUtils->TestFinish(iTestNum++);
       
  4050 
       
  4051 			// done
       
  4052 			iTestUtils->TestHarnessCompleted();
       
  4053 			EndOfTest();  
       
  4054 			
       
  4055 			// done
       
  4056 			test.Console()->SetPos(0, 13);
       
  4057 			test.Printf(_L("Finished check server contents\n"));
       
  4058 			more = EFalse;
       
  4059 			break;
       
  4060 
       
  4061 		default:
       
  4062 			NextState(100);
       
  4063 			break;
       
  4064 			}
       
  4065 		}
       
  4066 	return more; 
       
  4067 	}
       
  4068 
       
  4069 void CTestRefreshMBox::DoCheckServerContentsL()
       
  4070 	{
       
  4071 	if (iServiceId==NULL)
       
  4072 		{
       
  4073 		test.Printf(_L("No service ID\n"));
       
  4074 		return;
       
  4075 		}
       
  4076 
       
  4077 	iOpState = 0;
       
  4078 	iState = EImapTestCheckServerContents;
       
  4079 	StateMachineCheckServerContentsL();
       
  4080 	}
       
  4081 
       
  4082 /* ----------------------------------------------------------------------- */
       
  4083 
       
  4084 _LIT(KPerformFullSync,				"Performing full synchronisation"		);
       
  4085 _LIT(KConnectToRemoteServer,		"Connect to remote server"				);
       
  4086 _LIT(KDisconnectFromRemoteServer,	"Disconnect from remote server"			);
       
  4087 
       
  4088 const TInt KTestImapLimitedSyncSize1	=10;
       
  4089 const TInt KTestImapTestInboxSize		=20;
       
  4090 const TInt KTestImapTestBigFolderSize	=1200;
       
  4091 // much bigger increment due to having to switch back and forth between client and 
       
  4092 // server side which takes a lot of time
       
  4093 const TInt KTestImapSyncIncrementSize	=100;
       
  4094 
       
  4095 TBool CTestRefreshMBox::StateMachineNSynchronisationL()
       
  4096 	{
       
  4097 	TBool more = ETrue;
       
  4098 	TMsvId id;
       
  4099 	
       
  4100 	while (!IsActive() && more)
       
  4101 		{
       
  4102 		switch (iOpState)
       
  4103 			{
       
  4104 
       
  4105 		// ----------------------------------------------------------------------------------- //
       
  4106 
       
  4107 		case 0:			
       
  4108 			iTestUtils->TestStart(iTestNum, _L("N-Synchronisation tests: Regression tests (use cases SA1-SA5)"));
       
  4109 
       
  4110 
       
  4111 
       
  4112 			// Start with nothing subscribed locally updating neither.
       
  4113 			DebugFormatL(EDebugLevel2,_L("Sync Strategy=EUseLocal, Subscribe Stategy=EUpdateNeither"));
       
  4114 			SetSubscriptionsL( EUseLocal, EUpdateNeither );
       
  4115 
       
  4116 			// Set synchronisation settings to "sync to all".
       
  4117 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseAll,KImImapSynchroniseAll);
       
  4118 	
       
  4119 			// Connect to remote server.
       
  4120 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  4121 			DoConnectL();
       
  4122 			NextState();
       
  4123 			break;
       
  4124 
       
  4125 		case 1:			
       
  4126 			// Connection OK?
       
  4127 			DebugFormatL(EDebugLevel2,_L("Connection status=%d"),iStatus.Int());
       
  4128 			test(iStatus.Int() == KErrNone);
       
  4129 
       
  4130 			// Perform full synchronisation.
       
  4131 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4132 			DoFullSyncL();
       
  4133 			NextState(10);
       
  4134 			break;
       
  4135 
       
  4136 		case 10:
       
  4137 			// Check for backup folder and create it if it doesnt exist
       
  4138 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  4139 			if (id == KErrNotFound)
       
  4140 				{
       
  4141 				DebugFormatL(EDebugLevel2,_L("Creating folder 'backup'"));
       
  4142 				DoFolderCreateL(iServiceId,_L("Backup"));
       
  4143 				}
       
  4144 			else
       
  4145 				DebugFormatL(EDebugLevel2,_L("Found folder 'backup'"));
       
  4146 			NextState();
       
  4147 			break;
       
  4148 
       
  4149 		case 11:
       
  4150 			// Select remote backup folder
       
  4151 			DebugFormatL(EDebugLevel2,_L("Selecting folder 'backup'"));
       
  4152 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  4153 			PerformSpecialOpL(id, KIMAP4MTMSelect);
       
  4154 			NextState();
       
  4155 			break;
       
  4156 
       
  4157 		case 12:
       
  4158 			// Synchronise with remote backup folder
       
  4159 			DebugFormatL(EDebugLevel2,_L("Synchronising folder 'backup'"));
       
  4160 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  4161 			PerformSpecialOpL(id, KIMAP4MTMSynchronise);
       
  4162 			NextState();
       
  4163 			break;
       
  4164 
       
  4165 		case 13:
       
  4166 			// Delete contents of backup folder
       
  4167 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  4168 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4169 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4170 			if (iSelection->Count()>0)
       
  4171 				{
       
  4172 				DebugFormatL(EDebugLevel2,_L("Deleting folder 'backup' contents"));
       
  4173 				iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  4174 				SetActive();
       
  4175 				}
       
  4176 			NextState();
       
  4177 			break;
       
  4178 
       
  4179 		case 14:
       
  4180 			// Select remote inbox
       
  4181 			DebugFormatL(EDebugLevel2,_L("Selecting remote inbox"));
       
  4182 			PerformSpecialOpL(iRemoteInbox, KIMAP4MTMSelect);
       
  4183 			NextState();
       
  4184 			break;
       
  4185 
       
  4186 		case 15:
       
  4187 			// Sync with remote inbox
       
  4188 			DebugFormatL(EDebugLevel2,_L("Synchronising remote inbox"));
       
  4189 			PerformSpecialOpL(iRemoteInbox, KIMAP4MTMSynchronise);
       
  4190 			NextState(10);
       
  4191 			break;
       
  4192 				 
       
  4193 		case 20:	
       
  4194 			// Backup contents of inbox to backup folder
       
  4195 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  4196 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4197 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4198 			if (iSelection->Count())
       
  4199 				{
       
  4200 				DebugFormatL(EDebugLevel2,_L("Moving contents of inbox to 'backup'"));
       
  4201 				DebugUidListL(EDebugLevel3);
       
  4202 				iImppServerMtm->MoveWithinServiceL(*iSelection, id, iStatus);
       
  4203 				SetActive();
       
  4204 				}
       
  4205 			NextState();
       
  4206 			break;
       
  4207 
       
  4208 		case 21:	
       
  4209 			// Unsubscribe from "backup" folder.
       
  4210 			DebugFormatL(EDebugLevel2,_L("Unsubscribe from folder 'backup'"));
       
  4211 			id = FindFolderByNameL(iServiceId, _L("Backup"));
       
  4212 			PerformSpecialOpL(id, KIMAP4MTMLocalUnsubscribe);
       
  4213 			NextState();
       
  4214 			break;
       
  4215 
       
  4216 		//
       
  4217 		// Use case SA-1: Sync-to-all, with an empty local and remote mailbox
       
  4218 		//
       
  4219 		case 22:
       
  4220 			DebugFormatL(EDebugLevel0,_L("Use case SA-1: Sync-to-all, with an empty local and remote mailbox"));
       
  4221 
       
  4222 			// Perform a full synchronisation.
       
  4223 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4224 			DoFullSyncL();
       
  4225 			NextState();
       
  4226 			break;
       
  4227 
       
  4228 		case 23:
       
  4229 			// Check inbox for empty
       
  4230 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4231 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry,*iSelection));
       
  4232 			DebugFormatL(EDebugLevel1,_L("Checking inbox for empty - found %d messages"),iSelection->Count());
       
  4233 			test(iSelection->Count()==0);
       
  4234 			NextState(10);
       
  4235 
       
  4236 			DebugFormatL(EDebugLevel0,_L("Use case SA-1: Pass"));
       
  4237 			break;
       
  4238 
       
  4239 		//
       
  4240 		// Use case SA-2: Sync-to-all, with 1 email in the remote mailbox
       
  4241 		//
       
  4242 		case 30:
       
  4243 			DebugFormatL(EDebugLevel0,_L("Use case SA-2: Sync-to-all, with 1 email in remote mailbox"));
       
  4244 
       
  4245 			// Locate "TestInbox" in local folder list.
       
  4246 			id = FindFolderByNameL(iServiceId,_L("TestInbox"));
       
  4247 			DebugFormatL(EDebugLevel1,_L("Locating 'TestInbox' in local store (%d)"),id);
       
  4248 			test( id != KErrNotFound );
       
  4249 
       
  4250 			// Subscribe to "TestInbox"
       
  4251 			DebugFormatL(EDebugLevel2,_L("Subscribe to 'TestInbox'"));
       
  4252 	        PerformSpecialOpL(id, KIMAP4MTMLocalSubscribe);
       
  4253 			NextState();
       
  4254 			break;
       
  4255 
       
  4256 		case 31:
       
  4257 			// Perform a full synchronisation.
       
  4258 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4259 			DoFullSyncL();
       
  4260 			NextState();
       
  4261 			break;
       
  4262 
       
  4263 		case 32:	
       
  4264 			// Copy 1 new email into remote mailbox
       
  4265 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4266 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4267 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4268 
       
  4269 			// Check that there are 20 messages in the test inbox, if not then someone has
       
  4270 			// broken it!
       
  4271 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  4272 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  4273 
       
  4274 			// Trim the list of messages down to 1 message only
       
  4275 			DebugFormatL(EDebugLevel2,_L("Trim 'TestInbox' contents list to 1 messaged"));
       
  4276 			iSelection->Delete(1,iSelection->Count()-1);
       
  4277 			DebugUidListL(EDebugLevel3);
       
  4278 
       
  4279 			// Copy it over to the inbox.
       
  4280 			DebugFormatL(EDebugLevel2,_L("Copy 1 message from 'TestInbox' to remote inbox"));
       
  4281 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4282 			SetActive();
       
  4283 
       
  4284 			NextState();
       
  4285 			break;
       
  4286 
       
  4287 		case 33:
       
  4288 			// Perform a full sync
       
  4289 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4290 			DoFullSyncL();
       
  4291 			NextState();
       
  4292 			break;
       
  4293 
       
  4294 		case 34:
       
  4295 			// Check inbox for 1 new email
       
  4296 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4297 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry,*iSelection));
       
  4298 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 1 expected"),iSelection->Count());
       
  4299 			DebugUidListL(EDebugLevel3);
       
  4300 			test(iSelection->Count()==1);
       
  4301 			NextState();
       
  4302 			break;
       
  4303 
       
  4304 		case 35:
       
  4305 			// Perform a full sync
       
  4306 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4307 			DoFullSyncL();
       
  4308 			NextState();
       
  4309 			break;
       
  4310 
       
  4311 		case 36:
       
  4312 			// Check inbox for 1 new email (again)
       
  4313 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4314 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4315 			DebugFormatL(EDebugLevel1,_L("(recheck) Inbox contains %d messages when 1 expected"),iSelection->Count());
       
  4316 			DebugUidListL(EDebugLevel3);
       
  4317 			test(iSelection->Count()==1);
       
  4318 			NextState();
       
  4319 
       
  4320 			DebugFormatL(EDebugLevel0,_L("Use case SA-2: Pass"));
       
  4321 			break;
       
  4322 
       
  4323 		//
       
  4324 		// Use case SA-3: Sync-to-all, where mail has been deleted from remote mailbox by 
       
  4325 		// another client.
       
  4326 		//
       
  4327 		case 37:
       
  4328 			DebugFormatL(EDebugLevel0,_L("Use case SA-3: Sync-to-all, where mail has been deleted from remote mailbox"));
       
  4329 
       
  4330 			// Check inbox contains
       
  4331 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4332 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry,*iSelection));
       
  4333 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 1 expected"),iSelection->Count());
       
  4334 			DebugUidListL(EDebugLevel3);
       
  4335 			test(iSelection->Count()==1);
       
  4336 
       
  4337 			// Delete message from inbox.
       
  4338 			DebugFormatL(EDebugLevel1,_L("Deleting message from inbox"));
       
  4339 			iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  4340 			SetActive();
       
  4341 
       
  4342 			NextState();
       
  4343 			break;
       
  4344 
       
  4345 		case 38:
       
  4346 			// Perform a full sync
       
  4347 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4348 			DoFullSyncL();
       
  4349 			NextState();
       
  4350 			break;
       
  4351 
       
  4352 		case 39:
       
  4353 			// Check inbox for empty
       
  4354 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4355 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4356 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 0 expected"),iSelection->Count());
       
  4357 			test(iSelection->Count()==0);
       
  4358 			NextState(10);
       
  4359 
       
  4360 			DebugFormatL(EDebugLevel0,_L("Use case SA-3: Pass"));
       
  4361 			break;
       
  4362 
       
  4363 		//
       
  4364 		// Use case SA-4: Sync-to-all, with some new mail in remote inbox 
       
  4365 		//
       
  4366 		case 40:	
       
  4367 			DebugFormatL(EDebugLevel0,_L("Use case SA-4: Sync-to-all, with some new mail in remote inbox"));
       
  4368 
       
  4369 			// Copy contents of remote test inbox to remote inbox
       
  4370 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4371 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4372 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4373 
       
  4374 			// Check that there are 20 messages in the test inbox, if not then someone has
       
  4375 			// broken it!
       
  4376 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  4377 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  4378 
       
  4379 			// Trim list down to 5 oldest
       
  4380 			DebugFormatL(EDebugLevel2,_L("Select 5 messages from list"));
       
  4381 			iSelection->Delete(5,iSelection->Count()-5);
       
  4382 			DebugUidListL(EDebugLevel3);
       
  4383 
       
  4384 			// Copy messages to inbox.
       
  4385 			DebugFormatL(EDebugLevel2,_L("Copy 5 messages to remote inbox"));
       
  4386 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4387 			SetActive();
       
  4388 
       
  4389 			NextState();
       
  4390 			break;
       
  4391 
       
  4392 		case 41:
       
  4393 			// Perform a full sync
       
  4394 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4395 			DoFullSyncL();
       
  4396 			NextState();
       
  4397 			break;
       
  4398 
       
  4399 		case 42:
       
  4400 			// Check inbox for 5 new messages
       
  4401 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4402 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4403 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 5 expected"),iSelection->Count());
       
  4404 			test(iSelection->Count()==5);
       
  4405 
       
  4406 			NextState();
       
  4407 			break;
       
  4408 
       
  4409 		case 43:
       
  4410 			// Perform a full sync
       
  4411 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4412 			DoFullSyncL();
       
  4413 			NextState();
       
  4414 			break;
       
  4415 
       
  4416 		case 44:
       
  4417 			// Check inbox for 5 new messages (again)
       
  4418 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4419 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4420 			DebugFormatL(EDebugLevel1,_L("(recheck) Inbox contains %d messages when 5 expected"),iSelection->Count());
       
  4421 			test(iSelection->Count()==5);
       
  4422 
       
  4423 			NextState(10);
       
  4424 
       
  4425 			DebugFormatL(EDebugLevel0,_L("Use case SA-4: Pass"));
       
  4426 			break;
       
  4427 
       
  4428 		//
       
  4429 		// Use case SA-5: Sync-to-all, with new & old mail in the remote inbox, and some mail
       
  4430 		// deleted from remote inbox
       
  4431 		//
       
  4432 		case 50:
       
  4433 			DebugFormatL(EDebugLevel0,_L("Use case SA-5: Sync-to-all, with new & old mail in the remote inbox, and some mail deleted"));
       
  4434 
       
  4435 			// Check contents of inbox.
       
  4436 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4437 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4438 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 5 expected"),iSelection->Count());
       
  4439 			test(iSelection->Count()==5);
       
  4440 
       
  4441 			// Trim list down to 1 message
       
  4442 			DebugFormatL(EDebugLevel2,_L("Trim list to 1 message only"));
       
  4443 			iSelection->Delete(1,iSelection->Count()-1);
       
  4444 			DebugUidListL(EDebugLevel3);
       
  4445 
       
  4446 			// Delete message from inbox.
       
  4447 			DebugFormatL(EDebugLevel2,_L("Deleting 1 message from inbox"));
       
  4448 			iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  4449 			SetActive();
       
  4450 
       
  4451 			NextState();
       
  4452 			break;
       
  4453 
       
  4454 		case 51:	
       
  4455 			// Copy contents of remote test inbox to remote inbox.
       
  4456 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4457 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4458 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4459 
       
  4460 			// Check that there are 20 messages in the test inbox.
       
  4461 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  4462 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  4463 			DebugUidListL(EDebugLevel3);
       
  4464 
       
  4465 			// Get 2 newer messages from list.
       
  4466 			DebugFormatL(EDebugLevel2,_L("Trim list to 2 messages only"));
       
  4467 			iSelection->Delete(0,5);
       
  4468 			iSelection->Delete(2,iSelection->Count()-2);
       
  4469 			DebugUidListL(EDebugLevel3);
       
  4470 
       
  4471 			// Copy messages to inbox.
       
  4472 			DebugFormatL(EDebugLevel2,_L("Copy 2 messages from 'TestInbox' to remote inbox"));
       
  4473 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4474 			SetActive();
       
  4475 
       
  4476 			NextState();
       
  4477 			break;
       
  4478 
       
  4479 		case 52:
       
  4480 			// Perform a full sync.
       
  4481 			DebugFormatL(EDebugLevel2,_L("Perform a full synchronisation"));
       
  4482 			DoFullSyncL();
       
  4483 			NextState();
       
  4484 			break;
       
  4485 
       
  4486 		case 53:
       
  4487 			// Check inbox for 5 + 2 - 1 = 6 messages.
       
  4488 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4489 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4490 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 6 expected"),iSelection->Count());
       
  4491 			test(iSelection->Count()==6);
       
  4492 			DebugUidListL(EDebugLevel3);
       
  4493 			
       
  4494 			NextState(10);
       
  4495 
       
  4496 			DebugFormatL(EDebugLevel0,_L("Use case SA-5: Pass"));
       
  4497 			break;
       
  4498 
       
  4499 		case 60:
       
  4500 			// Disconnect
       
  4501 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  4502 			DoDisconnectL();
       
  4503 			NextState();
       
  4504 			break;
       
  4505 
       
  4506 		// ----------------------------------------------------------------------------------- //
       
  4507 
       
  4508 		case 100:
       
  4509 			iTestUtils->TestStart(iTestNum, _L("N-Synchronisation tests: New functionality tests (use cases SA10-SA16)"));
       
  4510 
       
  4511 			// Reset service settings to limit synchronisation.
       
  4512 			ModifyImap4SynchronisationLimitsL(KTestImapLimitedSyncSize1,KImImapSynchroniseAll);
       
  4513 
       
  4514 			// Connect to remote server.
       
  4515 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  4516 			DoConnectL();
       
  4517 
       
  4518 			NextState();
       
  4519 			break;
       
  4520 
       
  4521 		case 101:
       
  4522 			// Perform a full synchronisation with remote server.
       
  4523 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4524 			DoFullSyncL();
       
  4525 			NextState(10);
       
  4526 			break;
       
  4527 
       
  4528 		//
       
  4529 		// Use case SA-10: Sync-to-limit, with an empty local and remote mailbox
       
  4530 		//
       
  4531 		case 110:
       
  4532 			DebugFormatL(EDebugLevel0,_L("Use case SA-10: Sync-to-limit, with an empty local and remote mailbox"));
       
  4533 
       
  4534 			// Delete contents of inbox
       
  4535 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4536 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4537 			if (iSelection->Count())
       
  4538 				{
       
  4539 				DebugFormatL(EDebugLevel2,_L("Deleting messages from inbox"));
       
  4540 				iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  4541 				SetActive();
       
  4542 				}
       
  4543 			NextState();
       
  4544 			break;
       
  4545 
       
  4546 		case 111:
       
  4547 			// Perform a full synchronisation with remote server.
       
  4548 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4549 			DoFullSyncL();
       
  4550 			NextState();
       
  4551 			break;
       
  4552 
       
  4553 		case 112:
       
  4554 			// Check inbox for empty
       
  4555 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4556 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4557 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 0 expected"),iSelection->Count());
       
  4558 			test(iSelection->Count()==0);
       
  4559 
       
  4560 			NextState(10);
       
  4561 
       
  4562 			DebugFormatL(EDebugLevel0,_L("Use case SA-10: Pass"));
       
  4563 			break;
       
  4564 
       
  4565 		//
       
  4566 		// Use case SA-11: Sync-to-limit, with 1 email in the remote inbox
       
  4567 		//
       
  4568 		case 120:	
       
  4569 			DebugFormatL(EDebugLevel0,_L("Use case SA-11: Sync-to-limit, with 1 email in the remote inbox"));
       
  4570 
       
  4571 			// Copy 1 new email into remote mailbox
       
  4572 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4573 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4574 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4575 
       
  4576 			// Check that there are 20 messages in "TestInbox".
       
  4577 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  4578 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  4579 
       
  4580 			// Trim the list of messages down to 1 message only
       
  4581 			DebugFormatL(EDebugLevel2,_L("Trim list to 1 messages only"));
       
  4582 			iSelection->Delete(1,iSelection->Count()-1);
       
  4583 			DebugUidListL(EDebugLevel3);
       
  4584 
       
  4585 			// Copy it over to the inbox.
       
  4586 			DebugFormatL(EDebugLevel2,_L("Copy 1 messages to remote inbox"));
       
  4587 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4588 			SetActive();
       
  4589 
       
  4590 			NextState();
       
  4591 			break;
       
  4592 
       
  4593 		case 121:
       
  4594 			// Perform a full synchronisation with remote server.
       
  4595 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4596 			DoFullSyncL();
       
  4597 			NextState();
       
  4598 			break;
       
  4599 
       
  4600 		case 122:
       
  4601 			// Check inbox for 1 new message
       
  4602 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4603 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4604 			test(iSelection->Count()==1);
       
  4605 			DebugUidListL(EDebugLevel3);
       
  4606 			NextState();
       
  4607 			break;
       
  4608 
       
  4609 		case 123:
       
  4610 			// Perform a full synchronisation with remote server.
       
  4611 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4612 			DoFullSyncL();
       
  4613 			NextState();
       
  4614 			break;
       
  4615 
       
  4616 		case 124:
       
  4617 			// Build list of remote inbox messages.
       
  4618 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4619 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4620 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 1 expected"),iSelection->Count());
       
  4621 			// Check inbox for 1 new message.
       
  4622 			test(iSelection->Count()==1);
       
  4623 			DebugUidListL(EDebugLevel3);
       
  4624 
       
  4625 			NextState(10);
       
  4626 
       
  4627 			DebugFormatL(EDebugLevel0,_L("Use case SA-11: Pass"));
       
  4628 			break;
       
  4629 
       
  4630 		//
       
  4631 		// Use case SA-12: Sync-to-limit, where mail has been deleted from remote mailbox
       
  4632 		// by another mail client
       
  4633 		//
       
  4634 		case 130:
       
  4635 			DebugFormatL(EDebugLevel0,_L("Use case SA-12: Sync-to-limit, where mail has been deleted from remote mailbox"));
       
  4636 
       
  4637 			// Build a list of messages in remote inbox
       
  4638 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4639 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4640 
       
  4641 			// Check that inbox contains 1 message.
       
  4642 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 1 expected"),iSelection->Count());
       
  4643 			test(iSelection->Count()==1);
       
  4644 			DebugUidListL(EDebugLevel3);
       
  4645 			
       
  4646 			// Delete message from inbox
       
  4647 			DebugFormatL(EDebugLevel2,_L("Deleting messages from inbox"));
       
  4648 			iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  4649 			SetActive();
       
  4650 
       
  4651 			NextState();
       
  4652 			break;
       
  4653 
       
  4654 		case 131:
       
  4655 			// Perform a full sync
       
  4656 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4657 			DoFullSyncL();
       
  4658 			NextState();
       
  4659 			break;
       
  4660 
       
  4661 		case 132:
       
  4662 			// Check inbox for empty
       
  4663 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4664 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4665 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 0 expected"),iSelection->Count());
       
  4666 			test(iSelection->Count()==0);
       
  4667 
       
  4668 			NextState(10);
       
  4669 
       
  4670 			DebugFormatL(EDebugLevel0,_L("Use case SA-12: Pass"));
       
  4671 			break;
       
  4672 
       
  4673 		//
       
  4674 		// Use case SA-13: Sync-to-all, with some new mail in remote inbox 
       
  4675 		//
       
  4676 		case 140:	
       
  4677 			DebugFormatL(EDebugLevel0,_L("Use case SA-13: Sync-to-all, with some new mail in remote inbox"));
       
  4678 
       
  4679 			// Copy contents of remote test inbox to remote inbox
       
  4680 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4681 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4682 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4683 
       
  4684 			// Check that there are 20 messages in "TestInbox".
       
  4685 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  4686 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  4687 			DebugUidListL(EDebugLevel3);
       
  4688 
       
  4689 			// Trim list down to 5 oldest
       
  4690 			DebugFormatL(EDebugLevel2,_L("Trim list to 5 messages only"));
       
  4691 			iSelection->Delete(5,iSelection->Count()-5);
       
  4692 			DebugUidListL(EDebugLevel3);
       
  4693 
       
  4694 			// Copy 5 messages to inbox.
       
  4695 			DebugFormatL(EDebugLevel2,_L("Copy 5 messages from 'TestInbox' to remote inbox"));
       
  4696 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4697 
       
  4698 			SetActive();
       
  4699 			NextState();
       
  4700 			break;
       
  4701 
       
  4702 		case 141:
       
  4703 			// Perform a full sync
       
  4704 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4705 			DoFullSyncL();
       
  4706 			NextState();
       
  4707 			break;
       
  4708 
       
  4709 		case 142:
       
  4710 			// Check inbox for 5 new messages
       
  4711 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4712 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4713 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 5 expected"),iSelection->Count());
       
  4714 			test(iSelection->Count()==5);
       
  4715 			DebugUidListL(EDebugLevel3);
       
  4716 
       
  4717 			NextState();
       
  4718 			break;
       
  4719 
       
  4720 		case 143:
       
  4721 			// Perform a full sync
       
  4722 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4723 			DoFullSyncL();
       
  4724 			NextState();
       
  4725 			break;
       
  4726 
       
  4727 		case 144:
       
  4728 			// Check inbox for 5 new messages (again)
       
  4729 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4730 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4731 			DebugFormatL(EDebugLevel1,_L("(recheck) Inbox contains %d messages when 5 expected"),iSelection->Count());
       
  4732 			test(iSelection->Count()==5);
       
  4733 
       
  4734 			NextState(10);
       
  4735 
       
  4736 			DebugFormatL(EDebugLevel0,_L("Use case SA-13: Pass"));
       
  4737 			break;
       
  4738 
       
  4739 		//
       
  4740 		// Use case SA-14: Sync-to-all, with new & old mail in the remote mailbox, and
       
  4741 		// some mail deleted from remote mailbox
       
  4742 		//
       
  4743 		case 150:
       
  4744 			DebugFormatL(EDebugLevel0,_L("Use case SA-14: Sync-to-all, with new & old mail in the remote mailbox, and some mail deleted"));
       
  4745 
       
  4746 			// Build list of inbox messages
       
  4747 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4748 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4749 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 5 expected"),iSelection->Count());
       
  4750 			test(iSelection->Count()==5);
       
  4751 
       
  4752 			// Trim list down to 1 message
       
  4753 			DebugFormatL(EDebugLevel2,_L("Trim list to 1 message only"));
       
  4754 			iSelection->Delete(1,iSelection->Count()-1);
       
  4755 			DebugUidListL(EDebugLevel3);
       
  4756 
       
  4757 			// Delete message from inbox
       
  4758 			DebugFormatL(EDebugLevel2,_L("Deleting message from inbox"));
       
  4759 			iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  4760 			SetActive();
       
  4761 
       
  4762 			NextState();
       
  4763 			break;
       
  4764 
       
  4765 		case 151:	
       
  4766 			// Build a list of messages in "TestInbox"
       
  4767 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4768 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4769 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4770 
       
  4771 			// Check that there are 20 messages in the test inbox.
       
  4772 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  4773 
       
  4774 			// Get 2 newer messages from list
       
  4775 			DebugFormatL(EDebugLevel2,_L("Trim list to 2 messages only"));
       
  4776 			iSelection->Delete(0,5);
       
  4777 			iSelection->Delete(2,iSelection->Count()-2);
       
  4778 			DebugUidListL(EDebugLevel3);
       
  4779 
       
  4780 			// Copy 2 messages from "TestInbox" to remote inbox
       
  4781 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4782 			SetActive();
       
  4783 
       
  4784 			NextState();
       
  4785 			break;
       
  4786 
       
  4787 		case 152:
       
  4788 			// Perform a full sync
       
  4789 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4790 			DoFullSyncL();
       
  4791 			NextState();
       
  4792 			break;
       
  4793 
       
  4794 		case 153:
       
  4795 			// Check inbox for 5 + 2 - 1 = 6 messages
       
  4796 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4797 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4798 			DebugFormatL(EDebugLevel1,_L("Inbox contains %d messages when 6 expected"),iSelection->Count());
       
  4799 			test(iSelection->Count()==6);
       
  4800 			DebugUidListL(EDebugLevel3);
       
  4801 
       
  4802 			NextState(10);
       
  4803 
       
  4804 			DebugFormatL(EDebugLevel0,_L("Use case SA-14: Pass"));
       
  4805 			break;
       
  4806 
       
  4807 		//
       
  4808 		// Use case SA-15: Sync-to-all, with email > limit in remote mailbox
       
  4809 		//
       
  4810 		case 160:	
       
  4811 			DebugFormatL(EDebugLevel0,_L("Use case SA-15: Sync-to-all, with email > limit in remote mailbox"));
       
  4812 
       
  4813 			// Build list of messages in "TestInbox".
       
  4814 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4815 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4816 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4817 
       
  4818 			// Check that there are 20 messages in "TestInbox".
       
  4819 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  4820 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  4821 			DebugUidListL(EDebugLevel3);
       
  4822 
       
  4823 			// Get 5 newer messages from list
       
  4824 			// Trim the list of messages down to 1 message only
       
  4825 			DebugFormatL(EDebugLevel2,_L("Trim list to 5 messages only"));
       
  4826 			iSelection->Delete(0,7);
       
  4827 			iSelection->Delete(5,iSelection->Count()-5);
       
  4828 			DebugUidListL(EDebugLevel3);
       
  4829 
       
  4830 			// Copy messages to inbox.
       
  4831 			DebugFormatL(EDebugLevel2,_L("Copy 5 messages to remote inbox"));
       
  4832 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4833 			SetActive();
       
  4834 
       
  4835 			NextState();
       
  4836 			break;
       
  4837 
       
  4838 		case 161:
       
  4839 			// Perform a full sync
       
  4840 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4841 			DoFullSyncL();
       
  4842 			NextState();
       
  4843 			break;
       
  4844 
       
  4845 		case 162:
       
  4846 			{
       
  4847 			// Build list of messages in remote inbox.
       
  4848 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4849 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4850 
       
  4851 			// Check inbox for 10 messages.
       
  4852 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 10 expected"),iSelection->Count());
       
  4853 			test(iSelection->Count()==KTestImapLimitedSyncSize1);
       
  4854 			DebugUidListL(EDebugLevel3);
       
  4855 
       
  4856 			// Check that remote message count is what we expect it to be (= 11)
       
  4857 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4858 	//		TMsvEmailEntry message=iEntry->Entry();
       
  4859 	//		DebugFormatL(EDebugLevel1,_L("Remote Inbox contains %d messages when 11 expected"),message.RemoteFolderEntries());
       
  4860 	//		test(message.RemoteFolderEntries()==KTestImapLimitedSyncSize1+1);
       
  4861 
       
  4862 			NextState(10);
       
  4863 
       
  4864 			DebugFormatL(EDebugLevel0,_L("Use case SA-15: Pass"));
       
  4865 			break;
       
  4866 			}
       
  4867 
       
  4868 		//
       
  4869 		// Use case SA-16: Sync-to-all, with populated email > limit in remote mailbox
       
  4870 		//
       
  4871 		case 170:
       
  4872 			DebugFormatL(EDebugLevel0,_L("Use case SA-16: Sync-to-all, with populated email > limit in remote mailbox"));
       
  4873 
       
  4874 			// Check inbox for 10 messages
       
  4875 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4876 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4877 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 10 expected"),iSelection->Count());
       
  4878 			test(iSelection->Count()==KTestImapLimitedSyncSize1);
       
  4879 
       
  4880 			// Locate oldest message is inbox message list.
       
  4881 			DebugFormatL(EDebugLevel2,_L("Trim list to 1 message only"));
       
  4882 			iSelection->Delete(1,iSelection->Count()-1);
       
  4883 			DebugUidListL(EDebugLevel3);
       
  4884 
       
  4885 			// Download body parts for oldest message
       
  4886 			DebugFormatL(EDebugLevel2,_L("Populating message in inbox"));
       
  4887 			iImppServerMtm->CopyToLocalL(*iSelection, KMsvGlobalInBoxIndexEntryId, iStatus);
       
  4888 			SetActive();
       
  4889 
       
  4890 			NextState();
       
  4891 			break;
       
  4892 
       
  4893 		case 171:	
       
  4894 			// Copy contents of remote test inbox to remote inbox
       
  4895 
       
  4896 			// Build list of messages in "TestInbox".
       
  4897 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  4898 			User::LeaveIfError(iEntry->SetEntry(id));
       
  4899 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  4900 
       
  4901 			// Get 1 newer messages from list
       
  4902 			DebugFormatL(EDebugLevel2,_L("Trim list next newest message only"));
       
  4903 			iSelection->Delete(0,12);
       
  4904 			iSelection->Delete(1,iSelection->Count()-1);
       
  4905 			DebugUidListL(EDebugLevel3);
       
  4906 
       
  4907 			// Copy messages to inbox.
       
  4908 			DebugFormatL(EDebugLevel2,_L("Copy message to remote inbox"));
       
  4909 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  4910 			SetActive();
       
  4911 
       
  4912 			NextState();
       
  4913 			break;
       
  4914 
       
  4915 		case 172:
       
  4916 			// Perform a full sync
       
  4917 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4918 			DoFullSyncL();
       
  4919 			NextState();
       
  4920 			break;
       
  4921 
       
  4922 		case 173:
       
  4923 			{
       
  4924 			// Build list of messages in local inbox.
       
  4925 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4926 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  4927 			// Check inbox for 11 messages.
       
  4928 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 11 expected"),iSelection->Count());
       
  4929 			test(iSelection->Count()==KTestImapLimitedSyncSize1+1);
       
  4930 			DebugUidListL(EDebugLevel3);
       
  4931 
       
  4932 			// Check that remote message count is what we expect it to be (= 12)
       
  4933 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  4934 //			TMsvEmailEntry message=iEntry->Entry();
       
  4935 //			DebugFormatL(EDebugLevel1,_L("Remote Inbox contains %d messages when 12 expected"),message.RemoteFolderEntries());
       
  4936 //			test(message.RemoteFolderEntries()==KTestImapLimitedSyncSize1+2);
       
  4937 
       
  4938 			NextState(10);
       
  4939 
       
  4940 			DebugFormatL(EDebugLevel0,_L("Use case SA-16: Pass"));
       
  4941 			break;
       
  4942 			}
       
  4943 
       
  4944 		case 180:
       
  4945 			// Disconnect
       
  4946 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  4947 			DoDisconnectL();
       
  4948 			NextState();
       
  4949 			break;
       
  4950 
       
  4951 		// ----------------------------------------------------------------------------------- //
       
  4952 
       
  4953 		//
       
  4954 		// Special Case 1: Sync-to-limit, with large remote mailbox (1200 messages)
       
  4955 		//
       
  4956 		case 200:
       
  4957 			iTestUtils->TestStart(iTestNum, _L("N-Synchronisation tests: Special case tests"));
       
  4958 
       
  4959 			DebugFormatL(EDebugLevel0,_L("Special case 1: Sync-to-limit, with large remote mailbox (1200 messages)"));
       
  4960 
       
  4961 			// Reset service settings to limit synchronisation.
       
  4962 			DebugFormatL(EDebugLevel2,_L("Sync Strategy=EUseLocal, Subscribe Stategy=EUpdateNeither"));
       
  4963 			SetSubscriptionsL(EUseLocal, EUpdateNeither);
       
  4964 			ModifyImap4SynchronisationLimitsL(KTestImapLimitedSyncSize1,KTestImapLimitedSyncSize1);
       
  4965 
       
  4966 			// Connect to remote server.
       
  4967 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  4968 			DoConnectL();
       
  4969 			NextState();
       
  4970 			break;
       
  4971 
       
  4972 		case 201:
       
  4973 			// Perform a full synchronisation with remote server.
       
  4974 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  4975 			DoFullSyncL();
       
  4976 			NextState();
       
  4977 			break;
       
  4978 
       
  4979 		case 202:
       
  4980 			// Check for "big" folder in local folder list
       
  4981 			iRemoteFolder1 = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  4982 			if (iRemoteFolder1==KErrNotFound)
       
  4983 				iRemoteFolder1 = FindFolderByNameL(iServiceId, _L("INBOX/TestBigFolder"));
       
  4984 			if (iRemoteFolder1==KErrNotFound)
       
  4985 				iRemoteFolder1 = FindFolderByNameL(iServiceId, _L("Mail/TestBigFolder"));
       
  4986 			if (iRemoteFolder1 == KErrNotFound)
       
  4987 				DoFolderCreateL(iServiceId,_L("TestBigFolder"));
       
  4988 			iRemoteFolder1 = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  4989 
       
  4990 			DebugFormatL(EDebugLevel1,_L("Checking for 'TestBigFolder' in local folder list (%d)"),iRemoteFolder1);
       
  4991 			test(iRemoteFolder1!=KErrNotFound);
       
  4992 
       
  4993 			NextState();
       
  4994 			break;
       
  4995 
       
  4996 		case 203:
       
  4997 			// Select remote "big" folder
       
  4998 			DebugFormatL(EDebugLevel1,_L("Select remote 'TestBigFolder'"));
       
  4999 			PerformSpecialOpL(iRemoteFolder1, KIMAP4MTMSelect);
       
  5000 			NextState();
       
  5001 			break;
       
  5002 
       
  5003 		case 204:
       
  5004 			// Synchronise with remote "big" folder
       
  5005 			DebugFormatL(EDebugLevel1,_L("Synchronise with remote 'TestBigFolder'"));
       
  5006 			PerformSpecialOpL(iRemoteFolder1, KIMAP4MTMSynchronise);
       
  5007 			NextState();
       
  5008 			break;
       
  5009 
       
  5010 		case 205:
       
  5011 			{
       
  5012 			// Build list of messages in local "TestBigFolder".
       
  5013 			User::LeaveIfError(iEntry->SetEntry(iRemoteFolder1));
       
  5014 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  5015 			// Check big folder for 10 messages
       
  5016 			DebugFormatL(EDebugLevel1,_L("Local 'TestBigFolder' contains %d messages when 10 expected"),iSelection->Count());
       
  5017 			test(iSelection->Count()==KTestImapLimitedSyncSize1);
       
  5018 			DebugUidListL(EDebugLevel3);
       
  5019 
       
  5020 			// Check that remote message count is what we expect it to be (= 1200)
       
  5021 			TMsvEmailEntry message=iEntry->Entry();
       
  5022 			DebugFormatL(EDebugLevel1,_L("Remote 'TestBigFolder' contains %d messages when 1200 expected"),message.RemoteFolderEntries());
       
  5023 			test(message.RemoteFolderEntries()==KTestImapTestBigFolderSize);
       
  5024 
       
  5025 			NextState();
       
  5026 
       
  5027 			break;
       
  5028 			}
       
  5029 
       
  5030 		case 206:	
       
  5031 			// Unsubscribe from "big" folder
       
  5032 			DebugFormatL(EDebugLevel1,_L("Unsubscribe from 'TestBigFolder'"));
       
  5033 			PerformSpecialOpL(iRemoteFolder1, KIMAP4MTMLocalUnsubscribe);
       
  5034 
       
  5035 			NextState();
       
  5036 
       
  5037 			DebugFormatL(EDebugLevel0,_L("Special case 1: Pass"));
       
  5038 			break;
       
  5039 
       
  5040 		case 207:
       
  5041 			// Disconnect
       
  5042 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5043 			DoDisconnectL();
       
  5044 			NextState(10);
       
  5045 			break;
       
  5046 
       
  5047 		//
       
  5048 		// Special Case 2: Sync-to-limit changed to Sync-to-all.
       
  5049 		//
       
  5050 		case 210:
       
  5051 			DebugFormatL(EDebugLevel0,_L("Special case 2: Sync-to-limit changed to Sync-to-all"));
       
  5052 
       
  5053 			// Set synchronisation settings to "sync to all".
       
  5054 			SetSubscriptionsL( EUseLocal, EUpdateNeither );
       
  5055 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseAll,KImImapSynchroniseAll);
       
  5056 
       
  5057 			// Connect to remote server.			
       
  5058 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5059 			DoConnectL();
       
  5060 			NextState();
       
  5061 			break;
       
  5062 
       
  5063 		case 211:
       
  5064 			// Connected ok?
       
  5065 			DebugFormatL(EDebugLevel1,_L("Connected? (%d)"),iStatus.Int());
       
  5066 			test(iStatus.Int() == KErrNone);
       
  5067 
       
  5068 			// Perform a full synchronisation with remote server.
       
  5069 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5070 			DoFullSyncL();
       
  5071 			NextState();
       
  5072 			break;
       
  5073 
       
  5074 		case 212:
       
  5075 			// Build a list of local inbox messages.
       
  5076 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5077 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5078 
       
  5079 			// Only want messages in selection list.
       
  5080 			FindMessagesInSelectionL();
       
  5081 			if (iSelection->Count())
       
  5082 				{
       
  5083 				// Delete all messages from inbox.
       
  5084 				DebugFormatL(EDebugLevel2,_L("Deleting messages from inbox"));
       
  5085 				DebugUidListL(EDebugLevel3);
       
  5086 				iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  5087 				SetActive();
       
  5088 				}
       
  5089 			NextState();
       
  5090 			break;
       
  5091 
       
  5092 		case 213:
       
  5093 			// Locate "TestInbox" in local folder list.
       
  5094 			iRemoteFolder1 = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5095 			if (iRemoteFolder1==KErrNotFound)
       
  5096 				iRemoteFolder1 = FindFolderByNameL(iServiceId, _L("INBOX/TestInbox"));
       
  5097 			if (iRemoteFolder1==KErrNotFound)
       
  5098 				iRemoteFolder1 = FindFolderByNameL(iServiceId, _L("Mail/TestInbox"));
       
  5099 			DebugFormatL(EDebugLevel1,_L("Checking for 'TestInbox' in local folder list (%d)"),iRemoteFolder1);
       
  5100 			test(iRemoteFolder1!=KErrNotFound);
       
  5101 
       
  5102 			// Subscribe to "TestInbox".
       
  5103 	        PerformSpecialOpL(iRemoteFolder1, KIMAP4MTMLocalSubscribe);
       
  5104 			NextState();
       
  5105 			break;
       
  5106 
       
  5107 		case 214:
       
  5108 			// Perform a full sync to get contents of "TestInbox".
       
  5109 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5110 			DoFullSyncL();
       
  5111 			NextState();
       
  5112 			break;
       
  5113 
       
  5114 		case 215:	
       
  5115 			// Build list of messages in "TestInbox".
       
  5116 			User::LeaveIfError(iEntry->SetEntry(iRemoteFolder1));
       
  5117 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  5118 
       
  5119 			// Check for correct number of messages in "TestInbox".
       
  5120 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  5121 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  5122 			DebugUidListL(EDebugLevel3);
       
  5123 
       
  5124 			// Copy contents of remote "TestInbox" to remote inbox.
       
  5125 			DebugFormatL(EDebugLevel1,_L("Copying contents of 'TestInbox' to remote inbox"));
       
  5126 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  5127 			SetActive();
       
  5128 
       
  5129 			NextState();
       
  5130 			break;
       
  5131 
       
  5132 		case 216:
       
  5133 			// Perform a full synchronisation with remote server.
       
  5134 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5135 			DoFullSyncL();
       
  5136 			NextState();
       
  5137 			break;
       
  5138 
       
  5139 		case 217:
       
  5140 			// Build list of messages in local inbox.
       
  5141 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5142 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5143 
       
  5144 			// Check for correct number of messages in folder
       
  5145 			FindMessagesInSelectionL();
       
  5146 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 20 expected"),iSelection->Count());
       
  5147 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  5148 			DebugUidListL(EDebugLevel3);
       
  5149 
       
  5150 			// Disconnect from remote server.
       
  5151 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5152 			DoDisconnectL();
       
  5153 			NextState();
       
  5154 			break;
       
  5155 
       
  5156 		case 218:
       
  5157 			// Set synchronisation settings to "sync to N".
       
  5158 			ModifyImap4SynchronisationLimitsL(KTestImapLimitedSyncSize1,KTestImapLimitedSyncSize1);
       
  5159 
       
  5160 			// Connect to remote server.
       
  5161 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5162 			DoConnectL();
       
  5163 			NextState();
       
  5164 			break;
       
  5165 
       
  5166 		case 219:
       
  5167 			// Perform a full synchronisation with remote server.
       
  5168 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5169 			DoFullSyncL();
       
  5170 			NextState();
       
  5171 			break;
       
  5172 
       
  5173 		case 220:
       
  5174 			// Build list of messages in local inbox.
       
  5175 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5176 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5177 
       
  5178 			// Check for correct number of messages in folder
       
  5179 			FindMessagesInSelectionL();
       
  5180 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 10 expected"),iSelection->Count());
       
  5181 			test(iSelection->Count()==KTestImapLimitedSyncSize1);
       
  5182 			DebugUidListL(EDebugLevel3);
       
  5183 
       
  5184 			// Disconnect from remote server.
       
  5185 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5186 			DoDisconnectL();
       
  5187 			NextState();
       
  5188 			break;
       
  5189 
       
  5190 		case 221:
       
  5191 			// Set synchronisation settings to "sync to all".
       
  5192 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseAll,KImImapSynchroniseAll);
       
  5193 
       
  5194 			// Connect to remote server.
       
  5195 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5196 			DoConnectL();
       
  5197 			NextState();
       
  5198 			break;
       
  5199 
       
  5200 		case 222:
       
  5201 			// Perform a full synchronisation with remote server.
       
  5202 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5203 			DoFullSyncL();
       
  5204 			NextState();
       
  5205 			break;
       
  5206 
       
  5207 		case 223:
       
  5208 			// Build list of messages in local inbox.
       
  5209 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5210 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5211 
       
  5212 			// Check for correct number of messages in folder
       
  5213 			FindMessagesInSelectionL();
       
  5214 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 20 expected"),iSelection->Count());
       
  5215 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  5216 			DebugUidListL(EDebugLevel3);
       
  5217 
       
  5218 			// Disconnect from remote server.
       
  5219 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5220 			DoDisconnectL();
       
  5221 			NextState(10);
       
  5222 
       
  5223 			DebugFormatL(EDebugLevel0,_L("Special case 2: Pass"));
       
  5224 			break;
       
  5225 
       
  5226 		//
       
  5227 		// Special Case 3: Sync-to-all changed to Sync-to-limit.
       
  5228 		//
       
  5229 		case 230:
       
  5230 			DebugFormatL(EDebugLevel2,_L("Special case 3: Sync-to-all changed to Sync-to-limit"));
       
  5231 
       
  5232 			// Set synchronisation settings to "sync to N".
       
  5233 			ModifyImap4SynchronisationLimitsL(KTestImapLimitedSyncSize1,KTestImapLimitedSyncSize1);
       
  5234 
       
  5235 			// Connect to remote server.
       
  5236 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5237 			DoConnectL();
       
  5238 
       
  5239 			NextState();
       
  5240 			break;
       
  5241 
       
  5242 		case 231:
       
  5243 			// Perform a full synchronisation with remote server.
       
  5244 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5245 			DoFullSyncL();
       
  5246 			NextState();
       
  5247 			break;
       
  5248 
       
  5249 		case 232:
       
  5250 			// Build list of messages in local inbox.
       
  5251 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5252 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5253 
       
  5254 			// Check for correct number of messages in folder
       
  5255 			FindMessagesInSelectionL();
       
  5256 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 10 expected"),iSelection->Count());
       
  5257 			test(iSelection->Count()==KTestImapLimitedSyncSize1);
       
  5258 			DebugUidListL(EDebugLevel3);
       
  5259 
       
  5260 			// Disconnect from remote server.
       
  5261 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5262 			DoDisconnectL();
       
  5263 
       
  5264 			NextState(10);
       
  5265 
       
  5266 			DebugFormatL(EDebugLevel0,_L("Special case 3: Pass"));
       
  5267 			break;
       
  5268 
       
  5269 		//
       
  5270 		// Special Case 4: Sync-to-limit, limit increased
       
  5271 		//
       
  5272 		case 240:
       
  5273 			DebugFormatL(EDebugLevel0,_L("Special case 4: Sync-to-limit, limit increased"));
       
  5274 
       
  5275 			// Set synchronisation settings to "sync to N".
       
  5276 			ModifyImap4SynchronisationLimitsL(KTestImapLimitedSyncSize1+5,KTestImapLimitedSyncSize1+5);
       
  5277 
       
  5278 			// Connect to remote server.
       
  5279 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5280 			DoConnectL();
       
  5281 			NextState();
       
  5282 			break;
       
  5283 
       
  5284 		case 241:
       
  5285 			// Perform a full synchronisation with remote server.
       
  5286 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5287 			DoFullSyncL();
       
  5288 			NextState();
       
  5289 			break;
       
  5290 
       
  5291 		case 242:
       
  5292 			// Build list of messages in local inbox.
       
  5293 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5294 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5295 
       
  5296 			// Check for correct number of messages in folder
       
  5297 			FindMessagesInSelectionL();
       
  5298 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 15 expected"),iSelection->Count());
       
  5299 			test(iSelection->Count()==KTestImapLimitedSyncSize1+5);
       
  5300 			DebugUidListL(EDebugLevel3);
       
  5301 
       
  5302 			NextState(10);
       
  5303 						
       
  5304 			DebugFormatL(EDebugLevel0,_L("Special case 4: Pass"));
       
  5305 			break;
       
  5306 
       
  5307 		//
       
  5308 		// Special Case 5: Sync-to-limit, with populated message and limit decreased, then increased
       
  5309 		//
       
  5310 		case 250:
       
  5311 			{
       
  5312 			DebugFormatL(EDebugLevel0,_L("Special case 5: Sync-to-limit, with populated message and limit decreased, then increased"));
       
  5313 
       
  5314 			// Build list of messages in local inbox.
       
  5315 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5316 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5317 
       
  5318 			// Locate the oldest message.
       
  5319 			TMsvId msvId;
       
  5320 			iMessageUid=0;
       
  5321 			for (TInt i=0;i<iSelection->Count();i++)
       
  5322 				{
       
  5323 				TMsvEntry* entryPtr;
       
  5324 				User::LeaveIfError(iEntry->GetEntryFromId((*iSelection)[i],entryPtr));
       
  5325 				TUint32 uid=((TMsvEmailEntry)(*entryPtr)).UID();
       
  5326 				if (iMessageUid>uid || iMessageUid==0)
       
  5327 					{
       
  5328 					iMessageUid=uid;
       
  5329 					msvId=(*iSelection)[i];
       
  5330 					}
       
  5331 				}
       
  5332 
       
  5333 			// Download body parts for oldest message
       
  5334 			iSelection->Reset();
       
  5335 			iSelection->AppendL(msvId);
       
  5336 			DebugFormatL(EDebugLevel1,_L("Populating 1 message in inbox"));
       
  5337 			DebugUidListL(EDebugLevel3);
       
  5338 			iImppServerMtm->CopyToLocalL(*iSelection, KMsvGlobalInBoxIndexEntryId, iStatus);
       
  5339 			SetActive();
       
  5340 
       
  5341 			NextState();
       
  5342 			break;
       
  5343 			}
       
  5344 
       
  5345 		case 251:
       
  5346 			// Disconnect
       
  5347 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5348 			DoDisconnectL();
       
  5349 			NextState();
       
  5350 			break;
       
  5351 
       
  5352 		case 252:
       
  5353 			// Reset synchronisation settings limit
       
  5354 			ModifyImap4SynchronisationLimitsL(KTestImapLimitedSyncSize1,KTestImapLimitedSyncSize1);
       
  5355 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5356 			DoConnectL();
       
  5357 			NextState();
       
  5358 			break;
       
  5359 
       
  5360 		case 253:
       
  5361 			// Perform a full synchronisation with remote server.
       
  5362 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5363 			DoFullSyncL();
       
  5364 			NextState();
       
  5365 			break;
       
  5366 
       
  5367 		case 254:
       
  5368 			// Build list of messages in local inbox.
       
  5369 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5370 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5371 
       
  5372 			// Check for correct number of messages in folder
       
  5373 			FindMessagesInSelectionL();
       
  5374 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 11 expected"),iSelection->Count());
       
  5375 			test(iSelection->Count()==KTestImapLimitedSyncSize1+1);
       
  5376 			DebugUidListL(EDebugLevel3);
       
  5377 
       
  5378 			// Disconnect from remote server.
       
  5379 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5380 			DoDisconnectL();
       
  5381 			NextState();
       
  5382 			break;
       
  5383 
       
  5384 		case 255:
       
  5385 			// Reset synchronisation settings limit.
       
  5386 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseAll,KImImapSynchroniseAll);
       
  5387 
       
  5388 			// Connect to remote server.
       
  5389 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5390 			DoConnectL();
       
  5391 			NextState();
       
  5392 			break;
       
  5393 
       
  5394 		case 256:
       
  5395 			// Perform a full synchronisation with remote server.
       
  5396 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5397 			DoFullSyncL();
       
  5398 			NextState();
       
  5399 			break;
       
  5400 
       
  5401 		case 257:
       
  5402 			// Build list of messages in local inbox.
       
  5403 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5404 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5405 
       
  5406 			// Check for correct number of messages in folder
       
  5407 			FindMessagesInSelectionL();
       
  5408 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 20 expected"),iSelection->Count());
       
  5409 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  5410 			DebugUidListL(EDebugLevel3);
       
  5411 
       
  5412 			// Disconnect from remote server.
       
  5413 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5414 			DoDisconnectL();
       
  5415 
       
  5416 			NextState(10);
       
  5417 
       
  5418 			DebugFormatL(EDebugLevel0,_L("Special case 5: Pass"));
       
  5419 			break;
       
  5420 
       
  5421 		//
       
  5422 		// Special Case 6: Sync-to-limit, with populated message deleted from remote folder
       
  5423 		//
       
  5424 		case 260:
       
  5425 			DebugFormatL(EDebugLevel0,_L("Special case 6: Sync-to-limit, with populated message deleted from remote folder"));
       
  5426 
       
  5427 			// Connect to remote server.
       
  5428 			ModifyImap4SynchronisationLimitsL(KTestImapLimitedSyncSize1,KTestImapLimitedSyncSize1);
       
  5429 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5430 			DoConnectL();
       
  5431 
       
  5432 			NextState();
       
  5433 			break;
       
  5434 
       
  5435 		case 261:
       
  5436 			// Perform a full synchronisation with remote server.
       
  5437 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5438 			DoFullSyncL();
       
  5439 			NextState();
       
  5440 			break;
       
  5441 
       
  5442 		case 262:
       
  5443 			{
       
  5444 			// Build list of messages in local inbox.
       
  5445 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5446 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5447 
       
  5448 			// Check for correct number of messages in folder
       
  5449 			FindMessagesInSelectionL();
       
  5450 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 11 expected"),iSelection->Count());
       
  5451 			test(iSelection->Count()==KTestImapLimitedSyncSize1+1);
       
  5452 			DebugUidListL(EDebugLevel3);
       
  5453 
       
  5454 			// Locate the message with body parts
       
  5455 			TMsvId msvId=-1;
       
  5456 			for (TInt i=0;i<iSelection->Count();i++)
       
  5457 				{
       
  5458 				User::LeaveIfError(iEntry->SetEntry((*iSelection)[i]));
       
  5459 				TMsvEmailEntry entry(iEntry->Entry());
       
  5460 				if (entry.BodyTextComplete())
       
  5461 					{
       
  5462 					msvId=(*iSelection)[i];
       
  5463 					break;
       
  5464 					}
       
  5465 				}
       
  5466 			// Found?
       
  5467 			DebugFormatL(EDebugLevel1,_L("Populated message located (%d)"),msvId);
       
  5468 			test(msvId!=-1);
       
  5469 
       
  5470 			// Add message with body parts to deletion list.
       
  5471 			iSelection->Reset();
       
  5472 			iSelection->AppendL(msvId);
       
  5473 
       
  5474 			// Delete message.
       
  5475 			DebugFormatL(EDebugLevel1,_L("Delete populated message"),iSelection->Count());
       
  5476 			DebugUidListL(EDebugLevel3);
       
  5477 			iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  5478 			SetActive();
       
  5479 
       
  5480 			NextState();
       
  5481 			break;
       
  5482 			}
       
  5483 
       
  5484 		case 263:
       
  5485 			// Perform a full synchronisation with remote server.
       
  5486 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5487 			DoFullSyncL();
       
  5488 			NextState();
       
  5489 			break;
       
  5490 
       
  5491 		case 264:
       
  5492 			// Build list of messages in local inbox.
       
  5493 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5494 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5495 
       
  5496 			// Check for correct number of messages in folder
       
  5497 			FindMessagesInSelectionL();
       
  5498 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 10 expected"),iSelection->Count());
       
  5499 			test(iSelection->Count()==KTestImapLimitedSyncSize1);
       
  5500 			DebugUidListL(EDebugLevel3);
       
  5501 
       
  5502 			// Disconnect from remote server.
       
  5503 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5504 			DoDisconnectL();
       
  5505 
       
  5506 			NextState(10);
       
  5507 
       
  5508 			DebugFormatL(EDebugLevel0,_L("Special case 6: Pass"));
       
  5509 			break;
       
  5510 
       
  5511 		//
       
  5512 		// Special Case 7: Sync-to-none, with empty local folder & empty remote folder
       
  5513 		//
       
  5514 		case 270:
       
  5515 			DebugFormatL(EDebugLevel0,_L("Special case 7: Sync-to-none, with empty local folder & empty remote folder"));
       
  5516 
       
  5517 			// Reset synchronisation settings limit to "sync-to-all".
       
  5518 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseAll,KImImapSynchroniseAll);
       
  5519 
       
  5520 			// Connect to remote server.
       
  5521 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5522 			DoConnectL();
       
  5523 			NextState();
       
  5524 			break;
       
  5525 
       
  5526 		case 271:
       
  5527 			// Perform a full synchronisation with remote server.
       
  5528 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5529 			DoFullSyncL();
       
  5530 			NextState();
       
  5531 			break;
       
  5532 
       
  5533 		case 272:
       
  5534 			// Build list of messages in inbox.
       
  5535 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5536 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5537 			FindMessagesInSelectionL();
       
  5538 			if (iSelection->Count())
       
  5539 				{
       
  5540 				// Delete all messages from inbox.
       
  5541 				DebugFormatL(EDebugLevel1,_L("Delete messages in inbox"));
       
  5542 				DebugUidListL(EDebugLevel3);
       
  5543 				iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  5544 				SetActive();
       
  5545 				}
       
  5546 			NextState();
       
  5547 			break;
       
  5548 
       
  5549 		case 273:
       
  5550 			// Perform a full synchronisation with remote server.
       
  5551 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5552 			DoFullSyncL();
       
  5553 			NextState();
       
  5554 			break;
       
  5555 
       
  5556 		case 274:
       
  5557 			// Build list of messages in local inbox.
       
  5558 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5559 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5560 
       
  5561 			// Check for correct number of messages in folder
       
  5562 			FindMessagesInSelectionL();
       
  5563 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 0 expected"),iSelection->Count());
       
  5564 			test(iSelection->Count()==0);
       
  5565 
       
  5566 			// Disconnect from remote server.
       
  5567 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5568 			DoDisconnectL();
       
  5569 			NextState();
       
  5570 			break;
       
  5571 
       
  5572 		case 275:
       
  5573 			// Reset synchronisation settings limit
       
  5574 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseNone,KImImapSynchroniseAll);
       
  5575 
       
  5576 			// Connect to remote server.
       
  5577 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5578 			DoConnectL();
       
  5579 			NextState();
       
  5580 			break;
       
  5581 
       
  5582 		case 276:
       
  5583 			// Perform a full synchronisation with remote server.
       
  5584 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5585 			DoFullSyncL();
       
  5586 			NextState();
       
  5587 			break;
       
  5588 
       
  5589 		case 277:
       
  5590 			// Build list of messages in local inbox.
       
  5591 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5592 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5593 
       
  5594 			// Check for correct number of messages in folder.
       
  5595 			FindMessagesInSelectionL();
       
  5596 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 0 expected"),iSelection->Count());
       
  5597 			test(iSelection->Count()==0);
       
  5598 
       
  5599 			NextState(10);
       
  5600 
       
  5601 			DebugFormatL(EDebugLevel0,_L("Special case 7: Pass"));
       
  5602 			break;
       
  5603 
       
  5604 		//
       
  5605 		// Special Case 8: Sync-to-none, with new messages in remote folder
       
  5606 		//
       
  5607 		case 280:
       
  5608 			DebugFormatL(EDebugLevel0,_L("Special case 8: Sync-to-none, with new messages in remote folder"));
       
  5609 
       
  5610 			// Build a list of messages in "TestInbox".
       
  5611 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5612 			User::LeaveIfError(iEntry->SetEntry(id));
       
  5613 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  5614 
       
  5615 			// Check that there are 20 messages in the test inbox.
       
  5616 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  5617 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  5618 			DebugUidListL(EDebugLevel3);
       
  5619 
       
  5620 			// Get 5 messages from the list and copy to inbox.
       
  5621 			DebugFormatL(EDebugLevel2,_L("Select 5 messages from 'TestInbox' message list"));
       
  5622 			iSelection->Delete(5,iSelection->Count()-5);
       
  5623 			DebugUidListL(EDebugLevel3);
       
  5624 			DebugFormatL(EDebugLevel1,_L("Copy 5 messages from 'TestInbox' to remote inbox"));
       
  5625 			iImppServerMtm->CopyWithinServiceL(*iSelection, iRemoteInbox, iStatus);
       
  5626 			SetActive();
       
  5627 
       
  5628 			NextState();
       
  5629 			break;
       
  5630 
       
  5631 		case 281:
       
  5632 			// Perform a full synchronisation with remote server.
       
  5633 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5634 			DoFullSyncL();
       
  5635 			NextState();
       
  5636 			break;
       
  5637 
       
  5638 		case 282:
       
  5639 			// Build list of messages in local inbox.
       
  5640 			User::LeaveIfError(iEntry->SetEntry(iRemoteInbox));
       
  5641 			User::LeaveIfError(iEntry->GetChildrenWithType(KUidMsvMessageEntry, *iSelection));
       
  5642 
       
  5643 			// Check for correct number of messages in folder
       
  5644 			FindMessagesInSelectionL();
       
  5645 
       
  5646 #if 0
       
  5647 			// skip this test as we've set InboxSync to None which
       
  5648 			// means that the copied messages won't ever show up (due
       
  5649 			// to to the copy itself or due to the Sync after) this
       
  5650 			// looks like it might be a problem in the design of the sync
       
  5651 			// code but can't tell for sure
       
  5652 			DebugFormatL(EDebugLevel1,_L("Local Inbox contains %d messages when 5 expected"),iSelection->Count());
       
  5653 			test(iSelection->Count()==5);
       
  5654 #endif
       
  5655 			// Disconnect from remote server.
       
  5656 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5657 			DoDisconnectL();
       
  5658 
       
  5659 			NextState(10);
       
  5660 
       
  5661 			DebugFormatL(EDebugLevel0,_L("Special case 8: Pass"));
       
  5662 			break;
       
  5663 
       
  5664 		//
       
  5665 		// Special Case 9: Unsubscribed folder contents auto-deleted
       
  5666 		//
       
  5667 		case 290:
       
  5668 			DebugFormatL(EDebugLevel0,_L("Special case 9: Unsubscribed folder contents auto-deleted"));
       
  5669 
       
  5670 			// Reset synchronisation settings limit to sync-to-all
       
  5671 			SetSubscriptionsL(EUseLocal, EUpdateBoth);
       
  5672 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseAll,KImImapSynchroniseAll);
       
  5673 
       
  5674 			// Connect to remote server
       
  5675 			DebugFormatL(EDebugLevel2,KConnectToRemoteServer);
       
  5676 			DoConnectL();
       
  5677 			NextState();
       
  5678 			break;
       
  5679 
       
  5680 		case 291:
       
  5681 			// Perform a full synchronisation with remote server.
       
  5682 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5683 			DoFullSyncL();
       
  5684 			NextState();
       
  5685 			break;
       
  5686 
       
  5687 		case 292:
       
  5688 			// Build list of messages in "TestInbox"
       
  5689 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5690 			User::LeaveIfError(iEntry->SetEntry(id));
       
  5691 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  5692 
       
  5693 			// Check that there are 20 messages in "TestInbox"
       
  5694 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  5695 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  5696 			DebugUidListL(EDebugLevel2);
       
  5697 
       
  5698 			// Unsubscribe 
       
  5699 			DebugFormatL(EDebugLevel1,_L("Unsubscribe from 'TestInbox'"));
       
  5700 			PerformSpecialOpL(id, KIMAP4MTMLocalUnsubscribe);
       
  5701 			NextState();
       
  5702 			break;
       
  5703 
       
  5704 		case 293:
       
  5705 			// Perform a full synchronisation with remote server.
       
  5706 			DebugFormatL(EDebugLevel2,KPerformFullSync);
       
  5707 			DoFullSyncL();
       
  5708 			NextState();
       
  5709 			break;
       
  5710 
       
  5711 		case 294:
       
  5712 			// Build list of messages in "TestInbox".
       
  5713 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5714 			User::LeaveIfError(iEntry->SetEntry(id));
       
  5715 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  5716 
       
  5717 			// Check that "TestInbox" is empty.
       
  5718 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 0 expected"),iSelection->Count());
       
  5719 			test(iSelection->Count()==0);
       
  5720 
       
  5721 			// Disconnect from remote server.
       
  5722 			DebugFormatL(EDebugLevel2,KDisconnectFromRemoteServer);
       
  5723 			DoDisconnectL();
       
  5724 			NextState();
       
  5725 
       
  5726 			DebugFormatL(EDebugLevel0,_L("Special case 9: Pass"));
       
  5727 			break;
       
  5728 
       
  5729 		// ----------------------------------------------------------------------------------- //
       
  5730 
       
  5731 		//
       
  5732 		// Performance test
       
  5733 		//
       
  5734 		case 300:			
       
  5735 			// Connect and unsubscribe 
       
  5736 			iTestUtils->TestStart(iTestNum, _L("N-Synchronisation tests: Large mailbox sync performance test"));
       
  5737 
       
  5738 			SetSubscriptionsL( EUseCombination, EUpdateNeither );
       
  5739 
       
  5740 			// Set synchronisation settings to "sync to all".
       
  5741 			ModifyImap4SynchronisationLimitsL(iSyncLimit,iSyncLimit);
       
  5742 	
       
  5743 			DoConnectL();
       
  5744 			NextState();
       
  5745 			break;
       
  5746 
       
  5747 		case 301:			
       
  5748 			// Synchronise with remote inbox
       
  5749 			test(iStatus.Int()==KErrNone);
       
  5750 			DoFullSyncL();
       
  5751 			NextState();
       
  5752 			break;
       
  5753 
       
  5754 		case 302:
       
  5755 			// Check for "big" folder and create it if it doesnt exist
       
  5756 			id = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  5757 			if (id == KErrNotFound)
       
  5758 				DoFolderCreateL(iServiceId,_L("TestBigFolder"));
       
  5759 			NextState();
       
  5760 			break;
       
  5761 
       
  5762 		case 303:
       
  5763 			// Disconnect
       
  5764 			DoDisconnectL();
       
  5765 			NextState(10);
       
  5766 			break;
       
  5767 
       
  5768 		case 310:
       
  5769 			// Reset service settings to limit synchronisation.
       
  5770 			iTimeStamp.UniversalTime();
       
  5771 			ModifyImap4SynchronisationLimitsL(iSyncLimit,iSyncLimit);
       
  5772 			DoConnectL();
       
  5773 			NextState();
       
  5774 			break;
       
  5775 
       
  5776 		case 311:
       
  5777 			// Select remote "big" folder
       
  5778 			id = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  5779 			PerformSpecialOpL(id, KIMAP4MTMSelect);
       
  5780 			NextState();
       
  5781 			break;
       
  5782 
       
  5783 		case 312:
       
  5784 			// Synchronise with remote "big" folder
       
  5785 			id = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  5786 			PerformSpecialOpL(id, KIMAP4MTMSynchronise);
       
  5787 			NextState();
       
  5788 			break;
       
  5789 
       
  5790 		case 313:
       
  5791 			{
       
  5792 			// Check big folder for N messages
       
  5793 			id = FindFolderByNameL(iServiceId, _L("TestBigFolder"));
       
  5794 			User::LeaveIfError(iEntry->SetEntry(id));
       
  5795 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  5796 			if (iSelection->Count()!=iSyncLimit)
       
  5797 				{
       
  5798 				DebugFormatL(EDebugLevel0,_L("WARNING: %d messages detected in local folder when %d were expected"),iSelection->Count(),iSyncLimit);
       
  5799 				iOpState=399;
       
  5800 				break;
       
  5801 				}
       
  5802 
       
  5803 			// Check that remote message count is what we expect it to be (= 1200)
       
  5804 			User::LeaveIfError(iEntry->SetEntry(id));
       
  5805 //			TMsvEmailEntry message=iEntry->Entry();
       
  5806 //			test(message.RemoteFolderEntries()==KTestImapTestBigFolderSize);
       
  5807 			NextState();
       
  5808 			break;
       
  5809 			}
       
  5810 
       
  5811 		case 314:
       
  5812 			// Disconnect
       
  5813 			DoDisconnectL();
       
  5814 			NextState();
       
  5815 			break;
       
  5816 
       
  5817 		case 315:
       
  5818 			{
       
  5819 			TTime theCurrentTime;
       
  5820 			theCurrentTime.UniversalTime();
       
  5821 			TTimeIntervalSeconds interval;
       
  5822 			theCurrentTime.SecondsFrom(iTimeStamp,interval);
       
  5823 
       
  5824 			DebugFormatL(EDebugLevel0,_L("%d,%d"),iSyncLimit,interval.Int());
       
  5825 			if (iSyncLimit<KTestImapTestBigFolderSize)
       
  5826 				{
       
  5827 				iSyncLimit+=KTestImapSyncIncrementSize;
       
  5828 				iOpState=310;
       
  5829 				}
       
  5830 			else
       
  5831 				NextState(10);
       
  5832 			break;
       
  5833 			}
       
  5834 
       
  5835 
       
  5836 		case 399:
       
  5837 			// Disconnect
       
  5838 			DoDisconnectL();
       
  5839 			NextState();
       
  5840 			break;
       
  5841 
       
  5842 #if 0
       
  5843 			// ----------------------------------------------------------------------------------- //
       
  5844 
       
  5845 			// The following test case doesn't actually test anything
       
  5846 			// currently as it would fail. It was a testbed to
       
  5847 			// reproduce the problem and may become a test case if the
       
  5848 			// problem is fixed.
       
  5849 			
       
  5850 		case 400:			
       
  5851 			// Connect and unsubscribe 
       
  5852 			iTestUtils->TestStart(iTestNum, _L(""));
       
  5853 
       
  5854 			SetSubscriptionsL( EUseCombination, EUpdateNeither );
       
  5855 
       
  5856 			// Set synchronisation settings to "sync to all".
       
  5857 			ModifyImap4SynchronisationLimitsL(KImImapSynchroniseAll,KImImapSynchroniseAll);
       
  5858 	
       
  5859 			DoConnectL();
       
  5860 			NextState();
       
  5861 			break;
       
  5862 
       
  5863 		case 401:
       
  5864 			test(iStatus.Int()==KErrNone);
       
  5865 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5866 			PerformSpecialOpL(id, KIMAP4MTMSelect);
       
  5867 			NextState();
       
  5868 			break;
       
  5869 
       
  5870 		case 402:			
       
  5871 			// Synchronise with remote inbox
       
  5872 			test(iStatus.Int()==KErrNone);
       
  5873 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5874 			PerformSpecialOpL(id, KIMAP4MTMSynchronise);
       
  5875 			NextState();
       
  5876 			break;
       
  5877 
       
  5878 		case 403:
       
  5879 			// Disconnect
       
  5880 			DoDisconnectL();
       
  5881 			NextState();
       
  5882 			break;
       
  5883 
       
  5884 		case 404:			
       
  5885 			// Set synchronisation settings to 10
       
  5886 			ModifyImap4SynchronisationLimitsL(10,10);
       
  5887 
       
  5888 			DoConnectL();
       
  5889 			NextState();
       
  5890 			break;
       
  5891 
       
  5892 		case 405:
       
  5893 			test(iStatus.Int()==KErrNone);
       
  5894 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5895 			PerformSpecialOpL(id, KIMAP4MTMSelect);
       
  5896 			NextState();
       
  5897 			break;
       
  5898 
       
  5899 		case 406:			
       
  5900 			// Synchronise with remote inbox
       
  5901 			test(iStatus.Int()==KErrNone);
       
  5902 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5903 			PerformSpecialOpL(id, KIMAP4MTMSynchronise);
       
  5904 			NextState();
       
  5905 			break;
       
  5906 
       
  5907 		case 407:
       
  5908 			// Build list of messages in "TestInbox".
       
  5909 			id = FindFolderByNameL(iServiceId, _L("TestInbox"));
       
  5910 			User::LeaveIfError(iEntry->SetEntry(id));
       
  5911 			User::LeaveIfError(iEntry->GetChildren(*iSelection));
       
  5912 
       
  5913 			// Check that "TestInbox" is full
       
  5914 			DebugFormatL(EDebugLevel1,_L("'TestInbox' contains %d messages when 20 expected"),iSelection->Count());
       
  5915 			test(iSelection->Count()==KTestImapTestInboxSize);
       
  5916 
       
  5917 			// select first 3 only
       
  5918 			iSelection->Delete(3,iSelection->Count()-3);
       
  5919 
       
  5920 			// populate
       
  5921 				{
       
  5922 				TPckgBuf<TImap4GetMailOptions> package(EGetImap4EmailBodyTextAndAttachments);
       
  5923 				iDestFolder=0;
       
  5924 				PerformOpL( EImap4OpPopulate, package );
       
  5925 				}
       
  5926 			NextState();
       
  5927 			break;
       
  5928 			
       
  5929 
       
  5930 		case 408:
       
  5931 			// should check the 3 messages are populated correctly
       
  5932 			// however it will fail currently
       
  5933 
       
  5934 			// Disconnect
       
  5935 			DoDisconnectL();
       
  5936 			NextState(100);
       
  5937 			break;
       
  5938 #endif
       
  5939 			// ----------------------------------------------------------------------------------- //
       
  5940 
       
  5941 		case 400:
       
  5942 			test(iStatus.Int() == KErrNone);
       
  5943 
       
  5944 			iTestUtils->TestFinish(iTestNum++);
       
  5945 
       
  5946 			// done
       
  5947 			iTestUtils->TestHarnessCompleted();
       
  5948 			EndOfTest();  
       
  5949 			// done
       
  5950 			test.Console()->SetPos(0, 13);
       
  5951 			test.Printf(_L("Finished sync test\n"));
       
  5952 			more = EFalse;
       
  5953 			break;
       
  5954 
       
  5955 		default:
       
  5956 			iOpState=400;
       
  5957 			break;
       
  5958 			}
       
  5959 		}
       
  5960 	return more; 
       
  5961 	}
       
  5962 
       
  5963 void CTestRefreshMBox::DoNSynchronisationRegressionL()
       
  5964 	{
       
  5965 	if (iServiceId==NULL)
       
  5966 		{
       
  5967 		test.Printf(_L("No service ID\n"));
       
  5968 		return;
       
  5969 		}
       
  5970 
       
  5971 	iOpState = 0;
       
  5972 	iState = EImapTestNSynchronisation;
       
  5973 	StateMachineNSynchronisationL();
       
  5974 	}
       
  5975 
       
  5976 void CTestRefreshMBox::DoNSynchronisationTestsL()
       
  5977 	{
       
  5978 	if (iServiceId==NULL)
       
  5979 		{
       
  5980 		test.Printf(_L("No service ID\n"));
       
  5981 		return;
       
  5982 		}
       
  5983 
       
  5984 	iOpState = 100;
       
  5985 	iState = EImapTestNSynchronisation;
       
  5986 	StateMachineNSynchronisationL();
       
  5987 	}
       
  5988 
       
  5989 void CTestRefreshMBox::DoNSynchronisationSpecialTestsL()
       
  5990 	{
       
  5991 	if (iServiceId==NULL)
       
  5992 		{
       
  5993 		test.Printf(_L("No service ID\n"));
       
  5994 		return;
       
  5995 		}
       
  5996 
       
  5997 	iOpState = 200;
       
  5998 	iState = EImapTestNSynchronisation;
       
  5999 	StateMachineNSynchronisationL();
       
  6000 	}
       
  6001 
       
  6002 void CTestRefreshMBox::DoNSynchronisationPerformanceTestsL()
       
  6003 	{
       
  6004 	if (iServiceId==NULL)
       
  6005 		{
       
  6006 		test.Printf(_L("No service ID\n"));
       
  6007 		return;
       
  6008 		}
       
  6009 
       
  6010 	iOpState = 300;
       
  6011 	iState = EImapTestNSynchronisation;
       
  6012 	iSyncLimit = KTestImapSyncIncrementSize;
       
  6013 	StateMachineNSynchronisationL();
       
  6014 	}
       
  6015 
       
  6016 void CTestRefreshMBox::DoNSynchronisationOneOffTestsL()
       
  6017 	{
       
  6018 	if (iServiceId==NULL)
       
  6019 		{
       
  6020 		test.Printf(_L("No service ID\n"));
       
  6021 		return;
       
  6022 		}
       
  6023 
       
  6024 	iOpState = 400;
       
  6025 	iState = EImapTestNSynchronisation;
       
  6026 	iSyncLimit = KImImapSynchroniseAll;
       
  6027 	StateMachineNSynchronisationL();
       
  6028 	}
       
  6029 
       
  6030 /* ----------------------------------------------------------------------- */
       
  6031 
       
  6032 void CTestRefreshMBox::QueueOpL(TImap4OpType aOpType)
       
  6033 	{
       
  6034 	TMsvId srcFolder, destination;
       
  6035 	TestFolders(aOpType, srcFolder, destination);
       
  6036 	
       
  6037 	TPtrC msgName = TestMsgName(aOpType);
       
  6038 	TMsvId id = FindMessageByNameL(srcFolder, msgName);
       
  6039 	if (id == KErrNotFound)
       
  6040 		{
       
  6041 		test.Printf(_L("Can't find message %S\n"), &msgName);
       
  6042 		return;
       
  6043 		}
       
  6044 	
       
  6045 	iSelection->Reset();
       
  6046 	iSelection->InsertL(0, id);
       
  6047 	
       
  6048 	iState = EImapTestOffLineOp;
       
  6049 
       
  6050 	switch (aOpType)
       
  6051 		{
       
  6052 	case EImap4OpCopyToLocal:
       
  6053 		iImppServerMtm->CopyToLocalL(*iSelection, destination, iStatus);
       
  6054 		break;
       
  6055 	case EImap4OpCopyFromLocal:
       
  6056 		iImppServerMtm->CopyFromLocalL(*iSelection, destination, iStatus);
       
  6057 		break;
       
  6058 	case EImap4OpCopyWithinService:
       
  6059 	case EImap4OpCopyWithinFolder:
       
  6060 		iImppServerMtm->CopyWithinServiceL(*iSelection, destination, iStatus);
       
  6061 		break;
       
  6062 			
       
  6063 	case EImap4OpMoveToLocal:
       
  6064 		iImppServerMtm->MoveToLocalL(*iSelection, destination, iStatus);
       
  6065 		break;
       
  6066 	case EImap4OpMoveFromLocal:
       
  6067 		iImppServerMtm->MoveFromLocalL(*iSelection, destination, iStatus);
       
  6068 		break;
       
  6069 	case EImap4OpMoveWithinService:
       
  6070 	case EImap4OpMoveWithinServiceToInbox:
       
  6071 		iImppServerMtm->MoveWithinServiceL(*iSelection, destination, iStatus);
       
  6072 		break;
       
  6073 
       
  6074 	case EImap4OpDelete:
       
  6075 		iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  6076 		break;
       
  6077 
       
  6078 	case EImap4OpUndelete:
       
  6079 		break;
       
  6080 
       
  6081 	case EImap4OpPopulate:
       
  6082 		{
       
  6083 		TBuf8<128> paramBuf(_L8(""));
       
  6084 		iImppServerMtm->StartCommandL(*iSelection, KIMAP4MTMPopulate, paramBuf, iStatus);
       
  6085 		break;
       
  6086 		}
       
  6087 
       
  6088 	default:
       
  6089 		break;
       
  6090 		}
       
  6091 
       
  6092 	SetActive();
       
  6093 	}
       
  6094 
       
  6095 void CTestRefreshMBox::QueueLocalToLocalOpL(TImap4OpType aOpType)
       
  6096 	{
       
  6097 	TMsvId srcFolder, dummy;
       
  6098 
       
  6099 	TImap4OpType origOpType = aOpType == EImap4OpCopyToLocal ?
       
  6100 		EImap4OpCopyFromLocal :
       
  6101 		EImap4OpMoveFromLocal;
       
  6102 
       
  6103 	// source of the operation is the destination of the previous op
       
  6104 	TestFolders(origOpType, dummy, srcFolder);
       
  6105 
       
  6106 	// destination is the local test folder
       
  6107 	TMsvId destination = iLocalFolder1;
       
  6108 	
       
  6109 	TPtrC msgName = TestMsgName(origOpType);
       
  6110 	TMsvId id = FindMessageByNameL(srcFolder, msgName);
       
  6111 
       
  6112 	// park
       
  6113 	User::LeaveIfError(iEntry->SetEntry( NULL ));
       
  6114 	
       
  6115 	iSelection->Reset();
       
  6116 	iSelection->InsertL(0, id);
       
  6117 	
       
  6118 	// server mtm commands can complete before returning
       
  6119 	iState = EImapTestOffLineOp;
       
  6120 	SetActive();
       
  6121 
       
  6122 	switch (aOpType)
       
  6123 		{
       
  6124 	case EImap4OpCopyToLocal:
       
  6125 		iImppServerMtm->CopyToLocalL(*iSelection, destination, iStatus);
       
  6126 		break;
       
  6127 			
       
  6128 	case EImap4OpMoveToLocal:
       
  6129 		iImppServerMtm->MoveToLocalL(*iSelection, destination, iStatus);
       
  6130 		break;
       
  6131 
       
  6132 	default:
       
  6133 		break;
       
  6134 		}
       
  6135 	}
       
  6136 
       
  6137 void CTestRefreshMBox::UnQueueOpL(TImap4OpType aOpType)
       
  6138 	{
       
  6139 	TMsvId srcFolder, destination;
       
  6140 	TestFolders(aOpType, destination, srcFolder);
       
  6141 
       
  6142 	TPtrC msgName = TestMsgName(aOpType);
       
  6143 	TMsvId id = FindMessageByNameL(srcFolder, msgName);
       
  6144 	
       
  6145 	iSelection->Reset();
       
  6146 	iSelection->InsertL(0, id);
       
  6147 	
       
  6148 	// server mtm commands can complete before returning
       
  6149 	iState = EImapTestOffLineOp;
       
  6150 	SetActive();
       
  6151 
       
  6152 	switch (aOpType)
       
  6153 		{
       
  6154 	case EImap4OpCopyToLocal:
       
  6155 		iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  6156 		break;
       
  6157 	case EImap4OpCopyFromLocal:
       
  6158 		iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  6159 		break;
       
  6160 	case EImap4OpCopyWithinService:
       
  6161 		iImppServerMtm->DeleteAllL(*iSelection, iStatus);
       
  6162 		break;
       
  6163 			
       
  6164 	case EImap4OpMoveToLocal:
       
  6165 		iImppServerMtm->MoveFromLocalL(*iSelection, destination, iStatus);
       
  6166 		break;
       
  6167 	case EImap4OpMoveFromLocal:
       
  6168 		iImppServerMtm->MoveToLocalL(*iSelection, destination, iStatus);
       
  6169 		break;
       
  6170 	case EImap4OpMoveWithinService:
       
  6171 		iImppServerMtm->MoveWithinServiceL(*iSelection, destination, iStatus);
       
  6172 		break;
       
  6173 
       
  6174 	case EImap4OpDelete:
       
  6175 		{
       
  6176 		TBuf8<128> paramBuf(_L8(""));
       
  6177 		iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMUndeleteAll,paramBuf,iStatus);
       
  6178 		break;
       
  6179 		}
       
  6180 
       
  6181 	case EImap4OpPopulate:
       
  6182 	case EImap4OpUndelete:
       
  6183 		break;
       
  6184 
       
  6185 	default:
       
  6186 		break;
       
  6187 		}
       
  6188 
       
  6189 	// park
       
  6190 	User::LeaveIfError(iEntry->SetEntry( NULL ));
       
  6191 	}
       
  6192 
       
  6193 void CTestRefreshMBox::DoRenameFolderL()
       
  6194 	{
       
  6195 	TImap4RenameFolder cmd;
       
  6196 	cmd.iNewName = iRenamedFolder ? _L("Test1") : _L("Test1Renamed");
       
  6197 
       
  6198 	test.Console()->SetPos(0, 13);
       
  6199 	test.Console()->Printf(_L("DoRenamefolder to %S\n"), &cmd.iNewName);
       
  6200 
       
  6201 	iSelection->Reset();
       
  6202 	iSelection->InsertL(0, iRemoteFolder1);
       
  6203 
       
  6204 	iState = EImapTestRenameFolder;
       
  6205 	SetActive();
       
  6206 
       
  6207 	TPckgBuf<TImap4RenameFolder> package(cmd);
       
  6208 	iImppServerMtm->StartCommandL(*iSelection,KIMAP4MTMRenameFolder,package,iStatus);
       
  6209 
       
  6210 	iRenamedFolder = !iRenamedFolder;
       
  6211 	}
       
  6212 
       
  6213 void CTestRefreshMBox::RunL()
       
  6214 	{
       
  6215 	TInt anError=iStatus.Int();
       
  6216 
       
  6217 	test.Console()->SetPos(0, 13);
       
  6218 	test.Console()->Printf(_L("                                           "));
       
  6219 	test.Console()->SetPos(0, 13);
       
  6220 	
       
  6221 	switch(iState)
       
  6222 		{
       
  6223 	case EImapTestConnectAndSync:
       
  6224 		test.Console()->Printf(_L("Connected: err %d (%d)\n"),anError);
       
  6225 		if (anError == KErrNone)
       
  6226 			{
       
  6227 			iState = EImapTestWaitForBackground;
       
  6228 			StartL();
       
  6229 			}
       
  6230 		else
       
  6231 			ClearTimer();
       
  6232 		break;
       
  6233 
       
  6234 	case EImapTestFetchInbox:
       
  6235 		test.Console()->Printf(_L("FetchedInbox: err %d\n"),anError);
       
  6236 		
       
  6237 		ClearTimer();
       
  6238 		break;
       
  6239 			
       
  6240 	case EImapTestDisconnect:
       
  6241 		test.Console()->Printf(_L("Disconnected: err %d\n"),anError);
       
  6242 
       
  6243 		ClearTimer();
       
  6244 		break;
       
  6245 
       
  6246 	case EImapTestOffLineOp:
       
  6247 		test.Console()->Printf(_L("Done OffLineOp %d\n"),anError);
       
  6248 		break;
       
  6249 
       
  6250 	case EImapTestWaitForBackground:
       
  6251 		test.Console()->Printf(_L("Background Sync finished %d\n"),anError);
       
  6252 		
       
  6253 		ClearTimer();
       
  6254 		break;
       
  6255 		
       
  6256 	case EImapTestFetchAttachment:
       
  6257 		test.Console()->Printf(_L("Fetch attachment finished %d\n"),anError);
       
  6258 		
       
  6259 		ClearTimer();
       
  6260 		break;
       
  6261 
       
  6262 	case EImapTestFetchAttachedMessage:
       
  6263 		test.Console()->Printf(_L("Fetch attached message finished %d\n"),anError);
       
  6264 		
       
  6265 		ClearTimer();
       
  6266 		break;
       
  6267 
       
  6268 	case EImapTestCancelOffLineOps:
       
  6269 		test.Console()->Printf(_L("Cancelled offline ops %d\n"),anError);
       
  6270 		break;
       
  6271 		
       
  6272 	case EImapTestRenameFolder:
       
  6273 		test.Console()->Printf(_L("Renamed folder %d\n"),anError);
       
  6274 		break;
       
  6275 		
       
  6276 	case EImapTestAutoOffLineOp:
       
  6277 		{
       
  6278 		test.Console()->Printf(_L("Done Op %d next state %d\n"),anError,iOpState);
       
  6279 
       
  6280 		TBool more = EFalse;
       
  6281 		TRAPD(err, more = HandleOffLineStateL());
       
  6282 		if (err != KErrNone)
       
  6283 			test.Console()->Printf(_L("Op left with error %d\n"), err);
       
  6284 		if (!more)
       
  6285 			test.Console()->Printf(_L("Completed Offline tests %d\n"),anError);
       
  6286 		break;
       
  6287 		}
       
  6288 	
       
  6289 	case EImapTestAutoSyncOp:
       
  6290 		{
       
  6291 		test.Console()->Printf(_L("Done Op %d next state %d\n"),anError,iOpState);
       
  6292 
       
  6293 		TBool more = EFalse;
       
  6294 		TRAPD(err, more = HandleSyncStateL());
       
  6295 		if (err != KErrNone)
       
  6296 			test.Console()->Printf(_L("Op left with error %d\n"), err);
       
  6297 		if (!more)
       
  6298 			{
       
  6299 			test.Console()->Printf(_L("Completed Sync tests %d\n"),anError);
       
  6300 			ClearTimer();
       
  6301 			}
       
  6302 		break;
       
  6303 		}
       
  6304 	
       
  6305 	case EImapTestAutoSecondaryConnect:
       
  6306 		{
       
  6307 		test.Console()->Printf(_L("Done Op %d next state %d\n"),anError,iOpState);
       
  6308 
       
  6309 		TBool more = EFalse;
       
  6310 		TRAPD(err, more = TestSecondaryConnectStateMachineL());
       
  6311 		if (err != KErrNone)
       
  6312 			test.Console()->Printf(_L("Op left with error %d\n"), err);
       
  6313 		if (!more)
       
  6314 			{
       
  6315 			test.Console()->Printf(_L("Completed SecondaryConnect tests %d\n"),anError);
       
  6316 			ClearTimer();
       
  6317 			}
       
  6318 		break;
       
  6319 		}
       
  6320 	
       
  6321 	case EImapTestCheckServerContents:
       
  6322 		{
       
  6323 		test.Console()->Printf(_L("Done Op %d next state %d\n"),anError,iOpState);
       
  6324 
       
  6325 		TBool more = EFalse;
       
  6326 		TRAPD(err, more = StateMachineCheckServerContentsL());
       
  6327 		if (err != KErrNone)
       
  6328 			test.Console()->Printf(_L("Op left with error %d\n"), err);
       
  6329 		if (!more)
       
  6330 			{
       
  6331 			test.Console()->Printf(_L("Completed CheckServerContents tests %d\n"),anError);
       
  6332 			ClearTimer();
       
  6333 			}
       
  6334 		break;
       
  6335 		}
       
  6336 
       
  6337 	case EImapTestNSynchronisation:
       
  6338 		{
       
  6339 		test.Console()->Printf(_L("Done Op %d next state %d\n"),anError,iOpState);
       
  6340 
       
  6341 		TBool more = EFalse;
       
  6342 		TRAPD(err, more = StateMachineNSynchronisationL());
       
  6343 		if (err != KErrNone)
       
  6344 			test.Console()->Printf(_L("Op left with error %d\n"), err);
       
  6345 		if (!more)
       
  6346 			{
       
  6347 			test.Console()->Printf(_L("Completed N-Synchronisation Tests %d\n"),anError);
       
  6348 			ClearTimer();
       
  6349 			}
       
  6350 		break;
       
  6351 		}
       
  6352 	
       
  6353 	case EImapTestFetchTest:
       
  6354 		test.Console()->Printf(_L("Fetched test message: err %d\n"),anError);
       
  6355 		ClearTimer();
       
  6356 		break;
       
  6357 
       
  6358 	case EImapTestFolderDelete:
       
  6359 		test.Console()->Printf(_L("Folder deleted: err %d\n"),anError);
       
  6360 		ClearTimer();
       
  6361 		break;
       
  6362 		
       
  6363 	case EImapTestFolderCreate:
       
  6364 		test.Console()->Printf(_L("Folder created: err %d\n"),anError);
       
  6365 		ClearTimer();
       
  6366 		break;
       
  6367 		
       
  6368 	default:
       
  6369 		test.Console()->Printf(_L("Command in state %d completed: err %d\n"),iState,anError);
       
  6370 		ClearTimer();
       
  6371 		break;
       
  6372 		}
       
  6373 	}
       
  6374 
       
  6375 
       
  6376 // --------------------------------------------------------------------------
       
  6377 
       
  6378 CImImap4Settings* CTestRefreshMBox::GetImap4SettingsLC()
       
  6379 	{
       
  6380 	SelectServiceIdL();
       
  6381 
       
  6382 	TBool setTimer = (iTimer != NULL);
       
  6383 	ClearTimer();	
       
  6384 	iTestUtils->GoClientSideL();
       
  6385 	
       
  6386 	CImImap4Settings* settings = new (ELeave)CImImap4Settings();
       
  6387 	CleanupStack::PushL(settings);
       
  6388 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
  6389 	TImapAccount imapAccountId;
       
  6390 	accounts->GetImapAccountL(iServiceId, imapAccountId);
       
  6391 	accounts->LoadImapSettingsL(imapAccountId, *settings);
       
  6392 	CleanupStack::PopAndDestroy(); // fileStore/accounts
       
  6393 
       
  6394 	// go server side
       
  6395 	iTestUtils->GoServerSideL();
       
  6396 	iEntry = iTestUtils->iServerEntry;
       
  6397 	iTestUtils->InstantiateImapServerMtmL();
       
  6398 	iImppServerMtm = iTestUtils->iImapServerMtm;
       
  6399 	User::LeaveIfError(iEntry->SetEntry(iServiceId));
       
  6400 	
       
  6401 	// start the display timer	
       
  6402 	if (setTimer)
       
  6403 		StartTimerL();	
       
  6404 
       
  6405 	return settings;
       
  6406 	}
       
  6407 	
       
  6408 void CTestRefreshMBox::SetSubscriptionsL( TFolderSyncType aSync, TFolderSubscribeType aSubscribe )
       
  6409 	{
       
  6410 	SelectServiceIdL();
       
  6411 
       
  6412 	TBool setTimer = (iTimer != NULL);
       
  6413 	ClearTimer();	
       
  6414 	iTestUtils->GoClientSideL();
       
  6415 	
       
  6416 	CImImap4Settings* settings = new (ELeave)CImImap4Settings();
       
  6417 	CleanupStack::PushL(settings);
       
  6418 
       
  6419 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
  6420 	TImapAccount imapAccountId;
       
  6421 	accounts->GetImapAccountL(iServiceId, imapAccountId);
       
  6422 	accounts->LoadImapSettingsL(imapAccountId, *settings);
       
  6423 
       
  6424 	settings->SetSynchronise(aSync);
       
  6425 	settings->SetSubscribe(aSubscribe);
       
  6426 
       
  6427 	accounts->SaveImapSettingsL(imapAccountId, *settings);
       
  6428 
       
  6429 	CleanupStack::PopAndDestroy(2, settings); // fileStore/accounts, settings
       
  6430 	
       
  6431 	// go server side
       
  6432 	iTestUtils->GoServerSideL();
       
  6433 	iEntry = iTestUtils->iServerEntry;
       
  6434 	iTestUtils->InstantiateImapServerMtmL();
       
  6435 	iImppServerMtm = iTestUtils->iImapServerMtm;
       
  6436 	User::LeaveIfError(iEntry->SetEntry(iServiceId));
       
  6437 
       
  6438 	// start the display timer	
       
  6439 	if (setTimer)
       
  6440 		StartTimerL();	
       
  6441 	}
       
  6442 
       
  6443 // --------------------------------------------------------------------------
       
  6444 
       
  6445 void CTestRefreshMBox::ModifyImap4SynchronisationLimitsL(TInt aInboxSyncLimit,TInt aMailboxSyncLimit)
       
  6446 	{
       
  6447 	DebugFormatL(EDebugLevel2,_L("  Modifying synchronisation limits: Inbox=%d, Folders=%d"),aInboxSyncLimit,aMailboxSyncLimit);
       
  6448 
       
  6449 	// Already have a service id
       
  6450 	User::LeaveIfError(iEntry->SetEntry(iServiceId));
       
  6451 
       
  6452 	TBool setTimer = (iTimer != NULL);
       
  6453 	ClearTimer();	
       
  6454 	iTestUtils->GoClientSideL();
       
  6455 
       
  6456 	CImImap4Settings* settings = new CImImap4Settings();
       
  6457 	CleanupStack::PushL(settings);
       
  6458 
       
  6459 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
  6460 	TImapAccount imapAccountId;
       
  6461 	accounts->GetImapAccountL(iServiceId, imapAccountId);
       
  6462 	accounts->LoadImapSettingsL(imapAccountId, *settings);
       
  6463 
       
  6464 	settings->SetInboxSynchronisationLimit(aInboxSyncLimit);
       
  6465 	settings->SetMailboxSynchronisationLimit(aMailboxSyncLimit);
       
  6466 
       
  6467 	accounts->SaveImapSettingsL(imapAccountId, *settings);
       
  6468 
       
  6469 	CleanupStack::PopAndDestroy(2, settings); // entryStore/accounts, settings
       
  6470 	
       
  6471 	// go server side
       
  6472 	iTestUtils->GoServerSideL();
       
  6473 	iEntry = iTestUtils->iServerEntry;
       
  6474 	iTestUtils->InstantiateImapServerMtmL();
       
  6475 	iImppServerMtm = iTestUtils->iImapServerMtm;
       
  6476 	User::LeaveIfError(iEntry->SetEntry(iServiceId));
       
  6477 
       
  6478 	// start the display timer	
       
  6479 	if (setTimer)
       
  6480 		StartTimerL();	
       
  6481 	}
       
  6482 
       
  6483 void CTestRefreshMBox::FindImap4SettingsL()
       
  6484 	{
       
  6485 	TMsvId serviceId = 0;
       
  6486 	TMsvId inboxId = 0;
       
  6487 	TMsvId test1Id = 0;
       
  6488 	TMsvId test2Id = 0;
       
  6489 	TMsvId localtestId = 0;
       
  6490 
       
  6491 	// Search for first IMAP service entry
       
  6492 	CMsvEntrySelection *contents=new CMsvEntrySelection;
       
  6493 	CleanupStack::PushL(contents);
       
  6494 
       
  6495  	iEntry->SetEntry( KMsvRootIndexEntryId );
       
  6496 	
       
  6497 	iEntry->GetChildren(*contents);
       
  6498 	TInt a,noofchildren=contents->Count();
       
  6499 	if (noofchildren==0)
       
  6500 		{
       
  6501 		test.Printf(_L("No root children to examine\n"));
       
  6502 		}
       
  6503 	else
       
  6504 		{
       
  6505 		// Scan children to find first last service entry
       
  6506 		for(a=0;a<noofchildren;a++)
       
  6507 			{
       
  6508 			iEntry->SetEntry((*contents)[a]);
       
  6509 			if (iEntry->Entry().iType==KUidMsvServiceEntry &&
       
  6510 				iEntry->Entry().iMtm==KUidMsgTypeIMAP4)
       
  6511 				{
       
  6512 				// Found it!
       
  6513 				serviceId=(*contents)[a];
       
  6514 				}
       
  6515 			}
       
  6516 
       
  6517 		if (serviceId)
       
  6518 			{
       
  6519 			// Find inbox
       
  6520 			iEntry->GetChildren(*contents);
       
  6521 			noofchildren=contents->Count();
       
  6522 			for(a=0;a<noofchildren;a++)
       
  6523 				{
       
  6524 				iEntry->SetEntry((*contents)[a]);
       
  6525 				if (iEntry->Entry().iDetails.Compare(_L("Inbox"))==0)
       
  6526 					inboxId=(*contents)[a];
       
  6527 				
       
  6528 				if (iEntry->Entry().iDetails.Compare(_L("Test1"))==0)
       
  6529 					test1Id=(*contents)[a];
       
  6530 
       
  6531 				if (iEntry->Entry().iDetails.Compare(_L("Test2"))==0)
       
  6532 					test2Id=(*contents)[a];
       
  6533 				}
       
  6534 			}
       
  6535 		
       
  6536 		iEntry->SetEntry( KMsvLocalServiceIndexEntryId );
       
  6537 		iEntry->GetChildren(*contents);
       
  6538 		noofchildren=contents->Count();
       
  6539 		for(a=0;a<noofchildren;a++)
       
  6540 			{
       
  6541 			iEntry->SetEntry((*contents)[a]);
       
  6542 			if (iEntry->Entry().iDetails.Compare(_L("LocalTest"))==0)
       
  6543 				localtestId=(*contents)[a];
       
  6544 			}
       
  6545 		}
       
  6546 
       
  6547 	if (serviceId && inboxId/* && localtestId*/)
       
  6548 		{
       
  6549 		iServiceId = serviceId;
       
  6550 		iRemoteInbox = inboxId;
       
  6551 		iRemoteFolder1 = test1Id;
       
  6552 		iRemoteFolder2 = test2Id;
       
  6553 		iLocalFolder1 = localtestId;
       
  6554 		test.Printf(_L("Service 0x%x inbox 0x%x Test1 0x%x Test2 0x%x"), iServiceId, iRemoteInbox, iRemoteFolder1, iRemoteFolder2);
       
  6555 		}
       
  6556 	else
       
  6557 		{
       
  6558 		test.Printf(_L("Couldn't find one of IMAP service entry, INBOX or Test Folders\nPress any key..."));
       
  6559 		test.Getch();
       
  6560 		}
       
  6561 
       
  6562 	CleanupStack::PopAndDestroy(); // contents
       
  6563 
       
  6564 	User::LeaveIfError(iEntry->SetEntry(NULL));
       
  6565 	}
       
  6566 
       
  6567 
       
  6568 void CTestRefreshMBox::CreateDefaultServiceL(CImImap4Settings* aSettings)
       
  6569 	{
       
  6570 	// need to be client side
       
  6571 	iTestUtils->GoClientSideL();
       
  6572 
       
  6573 	// to create email accounts
       
  6574 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
  6575 
       
  6576 	// use test utilities to create 'default' service
       
  6577 	iServiceId = iTestUtils->CreateImapServiceL();
       
  6578 
       
  6579 	// load default settings
       
  6580 	TImapAccount imapAccountId;
       
  6581 	accounts->GetImapAccountL(iServiceId, imapAccountId);
       
  6582 	accounts->LoadImapSettingsL(imapAccountId, *aSettings);
       
  6583 	
       
  6584 	// cleanup
       
  6585 	CleanupStack::PopAndDestroy(accounts);
       
  6586 	}
       
  6587 
       
  6588 void CTestRefreshMBox::CreateServiceL(const CImImap4Settings* aSettings,
       
  6589 									  const TDesC& aDetails, 
       
  6590 									  const TDesC& aDescription,
       
  6591 									  const TBool aLocalOnly)
       
  6592 	{
       
  6593 	// this has to go before the Set's apparently
       
  6594 	iTestUtils->iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
       
  6595 
       
  6596 	if (!aLocalOnly)
       
  6597 		{
       
  6598 		// to create email accounts
       
  6599 		CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
  6600 		
       
  6601 		// use test utilities to find 'default' service
       
  6602 		iServiceId = iTestUtils->FindImapServiceL();
       
  6603 
       
  6604 		// update details/description
       
  6605 		iTestUtils->iMsvEntry->SetEntryL(iServiceId);		
       
  6606 		TMsvEntry entry = iTestUtils->iMsvEntry->Entry();
       
  6607 		entry.iDetails.Set(aDetails);
       
  6608 		entry.iDescription.Set(aDescription);
       
  6609 		iTestUtils->iMsvEntry->ChangeL(entry);		
       
  6610 
       
  6611 		// update settings
       
  6612 		TImapAccount imapAccountId;
       
  6613 		accounts->GetImapAccountL(iServiceId, imapAccountId);
       
  6614 		accounts->SaveImapSettingsL(imapAccountId, *aSettings);
       
  6615 		CleanupStack::PopAndDestroy(accounts);
       
  6616 		}
       
  6617 
       
  6618 	// go back to server side
       
  6619 	iTestUtils->GoServerSideL();
       
  6620 	iEntry = iTestUtils->iServerEntry;
       
  6621 	iTestUtils->InstantiateImapServerMtmL();
       
  6622 	iImppServerMtm = iTestUtils->iImapServerMtm;
       
  6623 	User::LeaveIfError(iEntry->SetEntry(iServiceId));
       
  6624 
       
  6625 	// Create inbox
       
  6626 	TMsvEmailEntry msg;
       
  6627 	msg.iType=KUidMsvFolderEntry;
       
  6628 	msg.iMtm=KUidMsgTypeIMAP4;
       
  6629 	msg.iServiceId=iServiceId;
       
  6630 	msg.SetMtmData1(0);
       
  6631 	msg.SetMtmData2(0);
       
  6632 	msg.SetMtmData3(0);
       
  6633 	msg.iSize=0;
       
  6634 	msg.SetUID(0);
       
  6635 	msg.SetValidUID(EFalse);
       
  6636 	msg.SetMailbox(ETrue);
       
  6637 	if (!aLocalOnly)
       
  6638 		{
       
  6639 		msg.iDetails.Set(_L("INBOX"));
       
  6640 		User::LeaveIfError(iEntry->CreateEntry(msg));
       
  6641 		iRemoteInbox=msg.Id();
       
  6642 		}
       
  6643 	
       
  6644 	User::LeaveIfError(iEntry->SetEntry(KMsvLocalServiceIndexEntryId));
       
  6645 	msg.iDetails.Set(_L("LocalTest"));
       
  6646 	User::LeaveIfError(iEntry->CreateEntry(msg));
       
  6647 	iLocalFolder1=msg.Id();
       
  6648 
       
  6649 	// park
       
  6650 	User::LeaveIfError(iEntry->SetEntry(KMsvNullIndexEntryId));	
       
  6651 	}
       
  6652 	
       
  6653 
       
  6654 
       
  6655 // --------------------------------------------------------------------------
       
  6656 
       
  6657 
       
  6658 // ActiveConsole definitions
       
  6659 
       
  6660 CActiveConsole* CActiveConsole::NewLC(CTestRefreshMBox *aRefresher,CCommandLineArguments* aCmdLineArgs)
       
  6661 	{
       
  6662 	CActiveConsole* self = new(ELeave) CActiveConsole();
       
  6663 	CleanupStack::PushL(self);
       
  6664 	self->iRefresher = aRefresher;
       
  6665 	self->iCmdLineArgs = aCmdLineArgs;
       
  6666 	self->iLevel = EArgMainMenu;
       
  6667 	self->iIssueCancel = TRUE;
       
  6668 	self->ConstructL();
       
  6669 	return self;
       
  6670 	}
       
  6671 
       
  6672 CActiveConsole::CActiveConsole()
       
  6673 	:CActive(0)
       
  6674 	{
       
  6675 	}
       
  6676 
       
  6677 void CActiveConsole::ConstructL()
       
  6678 	{
       
  6679 	// add any other initialisation here
       
  6680 	CActiveScheduler::Add(this);
       
  6681 	DisplayMainMenu();
       
  6682 	}
       
  6683 
       
  6684 CActiveConsole::~CActiveConsole()
       
  6685 	{
       
  6686 	Cancel();
       
  6687 	}
       
  6688 
       
  6689 void CActiveConsole::DoCancel()
       
  6690 	{
       
  6691 	test.Console()->ReadCancel();
       
  6692 	}
       
  6693 
       
  6694 void CActiveConsole::RequestCharacter()
       
  6695     {
       
  6696 	test.Console()->Read(iStatus); 
       
  6697     SetActive();
       
  6698     }
       
  6699 
       
  6700 LOCAL_C TBool MatchSubscribed(CMsvServerEntry* aEntry)
       
  6701 	{
       
  6702 	TMsvEmailEntry entry = aEntry->Entry();
       
  6703 	return entry.Subscribed() || entry.LocalSubscription();
       
  6704 	}
       
  6705 
       
  6706 LOCAL_C TBool MatchQueue(CMsvServerEntry* aEntry)
       
  6707 	{
       
  6708 	TBool match = EFalse;
       
  6709 	if (aEntry->HasStoreL())
       
  6710 		{
       
  6711 		CMsvStore* fileStore = aEntry->ReadStoreL();
       
  6712 		CleanupStack::PushL(fileStore);
       
  6713 
       
  6714 		match = fileStore->IsPresentL(KUidImQueuedOperationList);
       
  6715 
       
  6716 		CleanupStack::PopAndDestroy();
       
  6717 		}
       
  6718 	return match;
       
  6719 	}
       
  6720 
       
  6721 void CActiveConsole::ProcessKeyPressL(TChar aChar) 
       
  6722 	{
       
  6723 	if (iCmdLineArgs)
       
  6724 		{
       
  6725 		TLex lex(iCmdLineArgs->Arg(iLevel++));
       
  6726 		aChar=lex.Get();
       
  6727 		}
       
  6728 	switch (iMenuState)
       
  6729 		{
       
  6730 	case EMainMenu:
       
  6731 		switch (aChar)
       
  6732 			{
       
  6733 		case '1':
       
  6734 			DisplayImap4ServerMenu();
       
  6735 			break;
       
  6736 		case '2':
       
  6737 			if (iRefresher->iServiceId)
       
  6738 				DisplayImap4SettingsMenu();
       
  6739 			break;
       
  6740 		case '3':
       
  6741 			if (iRefresher->iServiceId)
       
  6742 				DisplayConnectMenu();
       
  6743 			break;
       
  6744 		case '4':
       
  6745 			if (iRefresher->iServiceId)
       
  6746 				DisplayOffLineOpMenu();
       
  6747 			break;
       
  6748 		case '5':
       
  6749 			DisplayImap4DumpMenu();
       
  6750 			break;
       
  6751 		case '6':
       
  6752 			DisplayHousekeepingMenu();
       
  6753 			break;
       
  6754 		case '7':
       
  6755 			DisplayAutomationMenu();
       
  6756 			break;
       
  6757 		case '8':
       
  6758 			DisplaySynchroniseMenu();
       
  6759 			break;
       
  6760 		case '9':
       
  6761 			DisplayDebugMenu();
       
  6762 			break;
       
  6763 
       
  6764 		case 'r':
       
  6765 		case 'R':
       
  6766 			DisplayMainMenu();
       
  6767 			break;
       
  6768 			
       
  6769 		case 'X':
       
  6770 		case 'x':
       
  6771 			iMenuState=EExit;
       
  6772 			break;
       
  6773 			}
       
  6774 		break;
       
  6775 
       
  6776 	case EImap4DumpMenu:
       
  6777 		switch (aChar)
       
  6778 			{
       
  6779 		case '1':
       
  6780 			DumpMessageStructureL( KMsvRootIndexEntryId,
       
  6781 								  CMsgOutputter::EToOneFile,
       
  6782 								  CMsgOutputter::ENone,
       
  6783 								  ETrue, ETrue );
       
  6784 			break;
       
  6785 		case '2':
       
  6786 			if (iRefresher->iServiceId)
       
  6787 				DumpMessageStructureL( iRefresher->iServiceId,
       
  6788 									  CMsgOutputter::EToScreen,
       
  6789 									  CMsgOutputter::ENone,
       
  6790 									  ETrue, ETrue,
       
  6791 									  MatchSubscribed );
       
  6792 			break;
       
  6793 		case '3':
       
  6794 			if (iRefresher->iServiceId)
       
  6795 				DumpMessageStructureL( iRefresher->iServiceId,
       
  6796 									  CMsgOutputter::EToScreen,
       
  6797 									  CMsgOutputter::EToOneFile,
       
  6798 									  ETrue, ETrue,
       
  6799 									  MatchQueue );
       
  6800 			break;
       
  6801 		case 'r':
       
  6802 		case 'R':
       
  6803 			DisplayImap4DumpMenu();
       
  6804 			break;
       
  6805 			
       
  6806 		case 'X':
       
  6807 		case 'x':
       
  6808 			DisplayMainMenu();
       
  6809 			break;
       
  6810 			}
       
  6811 		break;
       
  6812 
       
  6813 	case EImap4ServerMenu:
       
  6814 		switch (aChar)
       
  6815 			{
       
  6816 		case 'r':
       
  6817 		case 'R':
       
  6818 			DisplayImap4ServerMenu();
       
  6819 			break;
       
  6820 			
       
  6821 		case 'X':
       
  6822 		case 'x':
       
  6823 			DisplayMainMenu();
       
  6824 			break;
       
  6825 
       
  6826 		default:
       
  6827 			SelectImap4ServerEntryL(aChar);	
       
  6828 			break;
       
  6829 			}
       
  6830 		break;
       
  6831 
       
  6832 	case EImap4SettingsMenu:
       
  6833 		switch (aChar)
       
  6834 			{
       
  6835 		case 'r':
       
  6836 		case 'R':
       
  6837 			DisplayImap4SettingsMenu();
       
  6838 			break;
       
  6839 			
       
  6840 		case 'X':
       
  6841 		case 'x':
       
  6842 			DisplayMainMenu();
       
  6843 			break;
       
  6844 
       
  6845 		case '0':
       
  6846 			DumpMessageStructureL( iRefresher->iServiceId,
       
  6847 								  CMsgOutputter::ENone,
       
  6848 								  CMsgOutputter::EToScreen,
       
  6849 								  EFalse, ETrue );
       
  6850 			break;
       
  6851 			
       
  6852 		default:
       
  6853 			SelectImap4SettingsEntryL(aChar);	
       
  6854 			break;
       
  6855 			}			
       
  6856 		break;
       
  6857 
       
  6858 	case EHousekeepingMenu:
       
  6859 		switch (aChar)
       
  6860 			{
       
  6861 		case 'r':
       
  6862 		case 'R':
       
  6863 			DisplayHousekeepingMenu();
       
  6864 			break;
       
  6865 			
       
  6866 		case 'X':
       
  6867 		case 'x':
       
  6868 			DisplayMainMenu();
       
  6869 			break;
       
  6870 			
       
  6871 		default:
       
  6872 			SelectImap4SettingsEntryL(aChar);	
       
  6873 			break;
       
  6874 			}			
       
  6875 		break;
       
  6876 
       
  6877 	case EOffLineOpMenu:
       
  6878 		switch (aChar)
       
  6879 			{
       
  6880 		case 'r':
       
  6881 		case 'R':
       
  6882 			DisplayOffLineOpMenu();
       
  6883 			break;
       
  6884 			
       
  6885 		case 'X':
       
  6886 		case 'x':
       
  6887 			DisplayMainMenu();
       
  6888 			break;
       
  6889 
       
  6890 		case '1':
       
  6891 			DisplayOffLineOpQueueMenu();
       
  6892 			break;
       
  6893 		case '2':
       
  6894 			DisplayOffLineOpUnQueueMenu();
       
  6895 			break;
       
  6896 		case '3':
       
  6897 			DisplayOffLineOpQueueLocalToLocalMenu();
       
  6898 			break;
       
  6899 		case '4':
       
  6900 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestCancelOffLineOps);
       
  6901 			break;
       
  6902 		case '5':
       
  6903 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestAutoOffLineOp);
       
  6904 			break;
       
  6905 			
       
  6906 		case '6':
       
  6907 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestAutoSyncOp);
       
  6908 			break;
       
  6909 			
       
  6910 		default:
       
  6911 			break;
       
  6912 			}			
       
  6913 		break;
       
  6914 
       
  6915 	case EOffLineOpQueueMenu:
       
  6916 		switch (aChar)
       
  6917 			{
       
  6918 		case 'r':
       
  6919 		case 'R':
       
  6920 			DisplayOffLineOpQueueMenu();
       
  6921 			break;
       
  6922 			
       
  6923 		case 'X':
       
  6924 		case 'x':
       
  6925 			DisplayOffLineOpMenu();
       
  6926 			break;
       
  6927 
       
  6928 		case '1':
       
  6929 			iRefresher->QueueOpL(EImap4OpCopyToLocal);
       
  6930 			break;
       
  6931 		case '2':
       
  6932 			iRefresher->QueueOpL(EImap4OpCopyFromLocal);
       
  6933 			break;
       
  6934 		case '3':
       
  6935 			iRefresher->QueueOpL(EImap4OpCopyWithinService);
       
  6936 			break;
       
  6937 			
       
  6938 		case '4':
       
  6939 			iRefresher->QueueOpL(EImap4OpMoveToLocal);
       
  6940 			break;
       
  6941 		case '5':
       
  6942 			iRefresher->QueueOpL(EImap4OpMoveFromLocal);
       
  6943 			break;
       
  6944 		case '6':
       
  6945 			iRefresher->QueueOpL(EImap4OpMoveWithinService);
       
  6946 			break;
       
  6947 
       
  6948 		case '7':
       
  6949 			iRefresher->QueueOpL(EImap4OpDelete);
       
  6950 			break;
       
  6951 		case '8':
       
  6952 			iRefresher->QueueOpL(EImap4OpCopyWithinFolder);
       
  6953 			break;
       
  6954 			
       
  6955 		default:
       
  6956 			break;
       
  6957 			}			
       
  6958 		break;
       
  6959 
       
  6960 	case EOffLineOpQueueLocalToLocalMenu:
       
  6961 		switch (aChar)
       
  6962 			{
       
  6963 		case 'r':
       
  6964 		case 'R':
       
  6965 			DisplayOffLineOpQueueLocalToLocalMenu();
       
  6966 			break;
       
  6967 			
       
  6968 		case 'X':
       
  6969 		case 'x':
       
  6970 			DisplayOffLineOpMenu();
       
  6971 			break;
       
  6972 
       
  6973 		case '1':
       
  6974 			iRefresher->QueueLocalToLocalOpL(EImap4OpCopyToLocal);
       
  6975 			break;
       
  6976 		case '2':
       
  6977 			iRefresher->QueueLocalToLocalOpL(EImap4OpMoveToLocal);
       
  6978 			break;
       
  6979 
       
  6980 		default:
       
  6981 			break;
       
  6982 			}			
       
  6983 		break;
       
  6984 
       
  6985 	case EOffLineOpUnQueueMenu:
       
  6986 		switch (aChar)
       
  6987 			{
       
  6988 		case 'r':
       
  6989 		case 'R':
       
  6990 			DisplayOffLineOpUnQueueMenu();
       
  6991 			break;
       
  6992 			
       
  6993 		case 'X':
       
  6994 		case 'x':
       
  6995 			DisplayOffLineOpMenu();
       
  6996 			break;
       
  6997 
       
  6998 		case '1':
       
  6999 			iRefresher->UnQueueOpL(EImap4OpCopyToLocal);
       
  7000 			break;
       
  7001 		case '2':
       
  7002 			iRefresher->UnQueueOpL(EImap4OpCopyFromLocal);
       
  7003 			break;
       
  7004 		case '3':
       
  7005 			iRefresher->UnQueueOpL(EImap4OpCopyWithinService);
       
  7006 			break;
       
  7007 			
       
  7008 		case '4':
       
  7009 			iRefresher->UnQueueOpL(EImap4OpMoveToLocal);
       
  7010 			break;
       
  7011 		case '5':
       
  7012 			iRefresher->UnQueueOpL(EImap4OpMoveFromLocal);
       
  7013 			break;
       
  7014 		case '6':
       
  7015 			iRefresher->UnQueueOpL(EImap4OpMoveWithinService);
       
  7016 			break;
       
  7017 
       
  7018 		case '7':
       
  7019 			iRefresher->UnQueueOpL(EImap4OpDelete);
       
  7020 			break;
       
  7021 			
       
  7022 		default:
       
  7023 			break;
       
  7024 			}			
       
  7025 		break;
       
  7026 
       
  7027 	case EConnectMenu:
       
  7028 		switch (aChar)
       
  7029 			{
       
  7030 		case 'r':
       
  7031 		case 'R':
       
  7032 			DisplayConnectMenu();
       
  7033 			break;
       
  7034 			
       
  7035 		case 'X':
       
  7036 		case 'x':
       
  7037 			DisplayMainMenu();
       
  7038 			break;
       
  7039 
       
  7040 		case '1':
       
  7041 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestConnect);
       
  7042 			break;
       
  7043 		case '2':
       
  7044 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestDisconnect);
       
  7045 			break;
       
  7046 		case '3':
       
  7047 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestConnectAndSync);
       
  7048 			break;
       
  7049 		case '4':
       
  7050 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestFullSync);
       
  7051 			break;
       
  7052 		case '5':
       
  7053 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestSyncTree);
       
  7054 			break;
       
  7055 		case '6':
       
  7056 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestFetchTest);
       
  7057 			break;
       
  7058         case '7':
       
  7059 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestLocalSubscribe);
       
  7060 			break;
       
  7061         case '8':
       
  7062 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestLocalUnsubscribe);
       
  7063 			break;
       
  7064 		case '0':
       
  7065 			DisplayConnect2Menu();
       
  7066 			break;
       
  7067 			
       
  7068 		default:
       
  7069 			break;
       
  7070 			}
       
  7071 		break;
       
  7072 			
       
  7073 	case EConnect2Menu:
       
  7074 		switch (aChar)
       
  7075 			{
       
  7076 		case 'r':
       
  7077 		case 'R':
       
  7078 			DisplayConnect2Menu();
       
  7079 			break;
       
  7080 			
       
  7081 		case 'X':
       
  7082 		case 'x':
       
  7083 			DisplayConnectMenu();
       
  7084 			break;
       
  7085 
       
  7086 		case '1':
       
  7087 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestFetchInbox);
       
  7088 			break;
       
  7089 		case '2':
       
  7090 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestFetchAttachment);
       
  7091 			break;
       
  7092 		case '3':
       
  7093 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestRenameFolder);
       
  7094 			break;
       
  7095 		case '4':
       
  7096 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestFolderDelete);
       
  7097 			break;
       
  7098 		case '5':
       
  7099 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestFolderCreate);
       
  7100 			break;
       
  7101 		case '6':
       
  7102 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestInboxNewSync);
       
  7103 			break;
       
  7104 		case '7':
       
  7105 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestFetchAttachedMessage);
       
  7106 			break;
       
  7107 		case '8':
       
  7108 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestCopyMessages);
       
  7109 			break;
       
  7110 		default:
       
  7111 			break;
       
  7112 			}			
       
  7113 		break;
       
  7114 
       
  7115 	case EAutomationMenu:
       
  7116 		switch (aChar)
       
  7117 			{
       
  7118 		case 'r':
       
  7119 		case 'R':
       
  7120 			DisplayAutomationMenu();
       
  7121 			break;
       
  7122 			
       
  7123 		case 'X':
       
  7124 		case 'x':
       
  7125 			DisplayMainMenu();
       
  7126 			break;
       
  7127 
       
  7128 		case '1':
       
  7129 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestCheckServerContents);
       
  7130 			break;
       
  7131 			
       
  7132 		case '2':
       
  7133 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestAutoOffLineOp);
       
  7134 			break;
       
  7135 			
       
  7136 		case '3':
       
  7137 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestAutoSyncOp);
       
  7138 			break;
       
  7139 
       
  7140 		case '4':
       
  7141 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestAutoSecondaryConnect);
       
  7142 			break;
       
  7143 			
       
  7144 		default:
       
  7145 			break;
       
  7146 			}			
       
  7147 		break;
       
  7148 
       
  7149 	case ESynchroniseMenu:
       
  7150 		switch (aChar)
       
  7151 			{
       
  7152 		case 'r':
       
  7153 		case 'R':
       
  7154 			DisplaySynchroniseMenu();
       
  7155 			break;
       
  7156 			
       
  7157 		case 'X':
       
  7158 		case 'x':
       
  7159 			DisplayMainMenu();
       
  7160 			break;
       
  7161 
       
  7162 		case '1':
       
  7163 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestNSynchronisation);
       
  7164 			break;
       
  7165 			
       
  7166 		case '2':
       
  7167 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestNSynchronisationTests);
       
  7168 			break;
       
  7169 			
       
  7170 		case '3':
       
  7171 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestNSynchronisationSpecialTests);
       
  7172 			break;
       
  7173 
       
  7174 		case '4':
       
  7175 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestNSynchronisationPerformanceTests);
       
  7176 			break;
       
  7177 			
       
  7178 		case '5':
       
  7179 			iRefresher->EnterStateL(CTestRefreshMBox::EImapTestNSynchronisationOneOffTests);
       
  7180 			break;
       
  7181 			
       
  7182 		default:
       
  7183 			break;
       
  7184 			}			
       
  7185 		break;
       
  7186 
       
  7187 	case EDebugMenu:
       
  7188 		switch (aChar)
       
  7189 			{
       
  7190 		case 'r':
       
  7191 		case 'R':
       
  7192 			DisplayDebugMenu();
       
  7193 			break;
       
  7194 			
       
  7195 		case 'X':
       
  7196 		case 'x':
       
  7197 			DisplayMainMenu();
       
  7198 			break;
       
  7199 
       
  7200 		case '1':
       
  7201 			iRefresher->iDebugLevel=(iRefresher->iDebugLevel<EDebugLevel9?iRefresher->iDebugLevel+1:iRefresher->iDebugLevel);
       
  7202 			DisplayDebugMenu();
       
  7203 			break;
       
  7204 			
       
  7205 		case '2':
       
  7206 			iRefresher->iDebugLevel=(iRefresher->iDebugLevel>EDebugLevel0?iRefresher->iDebugLevel-1:iRefresher->iDebugLevel);
       
  7207 			DisplayDebugMenu();
       
  7208 			break;
       
  7209 
       
  7210 		default:
       
  7211 			break;
       
  7212 			}			
       
  7213 		break;
       
  7214 		}
       
  7215 	}
       
  7216 
       
  7217 void CActiveConsole::RunL() 
       
  7218 	{
       
  7219  	TRAPD(err,ProcessKeyPressL(TChar(test.Console()->KeyCode())));
       
  7220 	if ( err != KErrNone )
       
  7221 		test.Printf(_L("Something left with error %d\n"), err);
       
  7222 	test(err == KErrNone);
       
  7223 
       
  7224 	if (iMenuState==EExit)
       
  7225 		CActiveScheduler::Stop();
       
  7226 	else
       
  7227 		{
       
  7228  		RequestCharacter();
       
  7229 		if (iCmdLineArgs && iIssueCancel)
       
  7230 			DoCancel();
       
  7231 		}
       
  7232 	}
       
  7233 
       
  7234 // --------------------------------------------------------------------------
       
  7235 
       
  7236 // Menu display functions
       
  7237 
       
  7238 void CActiveConsole::DisplayMainMenu()	
       
  7239 	{
       
  7240 	iMenuState=EMainMenu;
       
  7241 	
       
  7242 	test.Console()->ClearScreen();
       
  7243 	test.Console()->SetPos(0, 0);
       
  7244 	
       
  7245 	test.Printf(_L("Options :\n\n"));
       
  7246 	test.Printf(_L(" 1 : IMAP Server menu\n"));
       
  7247 	if (iRefresher->iServiceId)
       
  7248 		{
       
  7249 		test.Printf(_L(" 2 : IMAP Settings menu\n"));
       
  7250 		test.Printf(_L(" 3 : Connect\n"));
       
  7251 		test.Printf(_L(" 4 : OffLine Ops\n"));
       
  7252 		}
       
  7253 	else
       
  7254 		test.Printf(_L("\n\n\n"));
       
  7255 	test.Printf(_L(" 5 : Dump menu\n"));
       
  7256 	test.Printf(_L(" 6 : Housekeeping\n"));
       
  7257 	if (iRefresher->iServiceId)
       
  7258 		{
       
  7259 		test.Printf(_L(" 7 : Automation\n"));
       
  7260 		test.Printf(_L(" 8 : Synchronisation\n"));
       
  7261 		}
       
  7262 	test.Printf(_L(" 9 : Debug logging\n"));
       
  7263 	test.Console()->SetPos(0, 12);
       
  7264 	test.Printf(_L(" X : Exit\n"));
       
  7265 	}
       
  7266 
       
  7267 void CActiveConsole::DisplayImap4ServerMenu()
       
  7268 	{
       
  7269 	if (iMenuState != EImap4ServerMenu)
       
  7270 		{
       
  7271 		iPrevState = iMenuState;
       
  7272 		iMenuState = EImap4ServerMenu;
       
  7273 		}
       
  7274 	
       
  7275 	test.Console()->ClearScreen();
       
  7276 	test.Console()->SetPos(0,0);
       
  7277 	test.Printf(_L("Options :\n\n"));
       
  7278 	test.Printf(_L(" 0 : Trmai01 server uding SSLTLS\n"));
       
  7279 	test.Printf(_L(" 1 : Use a previously created service entry\n"));
       
  7280 	test.Printf(_L(" 2 : ANT IMAP server\n"));
       
  7281 	test.Printf(_L(" 3 : Chaos IMAP server\n"));
       
  7282 	test.Printf(_L(" 4 : Symbian PIPEX IMAP server\n"));
       
  7283 	test.Printf(_L(" 5 : Dale's Totalise IMAP server\n"));
       
  7284 	test.Printf(_L(" 6 : Innosoft TLS IMAP server\n"));
       
  7285 	test.Printf(_L(" 7 : MS Imap test\n"));
       
  7286 	test.Printf(_L(" 8 : NTMail test\n"));
       
  7287 	test.Printf(_L(" a : lon-msgtest06.intra for Synchronise Tests\n"));
       
  7288 	test.Console()->SetPos(0, 12);
       
  7289 	test.Printf(_L(" X : Main menu\n"));
       
  7290 	}
       
  7291 
       
  7292 void CActiveConsole::DisplayImap4DumpMenu()
       
  7293 	{
       
  7294 	if (iMenuState != EImap4DumpMenu)
       
  7295 		{
       
  7296 		iPrevState = iMenuState;
       
  7297 		iMenuState = EImap4DumpMenu;
       
  7298 		}
       
  7299 
       
  7300 	test.Console()->ClearScreen();
       
  7301 	test.Console()->SetPos(0,0);
       
  7302 	test.Printf(_L("Options :\n\n"));
       
  7303 	test.Printf(_L(" 1 : Dump structure\n"));
       
  7304 	test.Printf(_L(" 2 : Dump subscribed\n"));
       
  7305 	test.Printf(_L(" 3 : Dump queued\n"));
       
  7306 	test.Console()->SetPos(0, 12);
       
  7307 	test.Printf(_L(" X : Main menu\n"));
       
  7308 	}
       
  7309 
       
  7310 void CActiveConsole::DisplayImap4SettingsMenu()
       
  7311 	{
       
  7312 	if (iMenuState != EImap4SettingsMenu)
       
  7313 		{
       
  7314 		iPrevState = iMenuState;
       
  7315 		iMenuState = EImap4SettingsMenu;
       
  7316 		}
       
  7317 	
       
  7318 	test.Console()->ClearScreen();
       
  7319 	test.Console()->SetPos(0,0);
       
  7320 	test.Printf(_L("Options :\n\n"));
       
  7321 	test.Printf(_L(" 1 : Set DisconnectedUserMode\n"));
       
  7322 	test.Printf(_L(" 2 : Set SynchroniseStrategy\n"));
       
  7323 	test.Printf(_L(" 3 : Set SubscribeStrategy\n"));
       
  7324 	test.Printf(_L(" 4 : Set IAP index\n"));
       
  7325 	test.Printf(_L(" 5 : Set Delete emails\n"));
       
  7326 	test.Printf(_L(" 6 : Set Get Mail Options\n"));
       
  7327 	test.Printf(_L(" 7 : Set SecureSockets\n"));
       
  7328 	test.Printf(_L(" 8 : Set FolderPath\n"));
       
  7329 	test.Printf(_L(" 9 : Set Password\n"));
       
  7330 	test.Printf(_L(" 0 : Show settings\n"));
       
  7331 	test.Console()->SetPos(0, 12);
       
  7332 	test.Printf(_L(" X : Main menu\n"));
       
  7333 	}
       
  7334 
       
  7335 void CActiveConsole::DisplayHousekeepingMenu()
       
  7336 	{
       
  7337 	if (iMenuState != EHousekeepingMenu)
       
  7338 		{
       
  7339 		iPrevState = iMenuState;
       
  7340 		iMenuState = EHousekeepingMenu;
       
  7341 		}
       
  7342 
       
  7343 	test.Console()->ClearScreen();
       
  7344 	test.Console()->SetPos(0,0);
       
  7345 	test.Printf(_L("Options :\n\n"));
       
  7346 	test.Console()->SetPos(0, 12);
       
  7347 	test.Printf(_L(" X : Main menu\n"));
       
  7348 	}
       
  7349 
       
  7350 void CActiveConsole::DisplayOffLineOpMenu()
       
  7351 	{
       
  7352 	if (iMenuState != EOffLineOpMenu)
       
  7353 		{
       
  7354 		iPrevState = iMenuState;
       
  7355 		iMenuState = EOffLineOpMenu;
       
  7356 		}
       
  7357 
       
  7358 	test.Console()->ClearScreen();
       
  7359 	test.Console()->SetPos(0,0);
       
  7360 	test.Printf(_L("Options :\n\n"));
       
  7361 	test.Printf(_L(" 1 : Queue Op\n"));
       
  7362 	test.Printf(_L(" 2 : UnQueue Op\n"));
       
  7363 	test.Printf(_L(" 3 : Queue back to local\n"));
       
  7364 	test.Printf(_L(" 4 : Cancel all ops\n"));
       
  7365 	test.Printf(_L(" 5 : Automated OffLine ops\n"));
       
  7366 	test.Printf(_L(" 6 : Automated Sync ops\n"));
       
  7367 	test.Console()->SetPos(0, 12);
       
  7368 	test.Printf(_L(" X : Main menu\n"));
       
  7369 	}
       
  7370 
       
  7371 void CActiveConsole::DisplayOffLineOpQueueMenu()
       
  7372 	{
       
  7373 	if (iMenuState != EOffLineOpQueueMenu)
       
  7374 		{
       
  7375 		iPrevState = iMenuState;
       
  7376 		iMenuState = EOffLineOpQueueMenu;
       
  7377 		}
       
  7378 
       
  7379 	test.Console()->ClearScreen();
       
  7380 	test.Console()->SetPos(0,0);
       
  7381 	test.Printf(_L("Options :\n\n"));
       
  7382 	test.Printf(_L(" 1 : Queue CopyToLocal\n"));
       
  7383 	test.Printf(_L(" 2 : Queue CopyFromLocal\n"));
       
  7384 	test.Printf(_L(" 3 : Queue CopyWithinService\n"));
       
  7385 	test.Printf(_L(" 4 : Queue MoveToLocal\n"));
       
  7386 	test.Printf(_L(" 5 : Queue MoveFromLocal\n"));
       
  7387 	test.Printf(_L(" 6 : Queue MoveWithinService\n"));
       
  7388 	test.Printf(_L(" 7 : Queue Delete\n"));
       
  7389 	test.Printf(_L(" 8 : Queue CopyWithinFolder\n"));
       
  7390 	test.Console()->SetPos(0, 12);
       
  7391 	test.Printf(_L(" X : Main menu\n"));
       
  7392 	}
       
  7393 
       
  7394 void CActiveConsole::DisplayOffLineOpQueueLocalToLocalMenu()
       
  7395 	{
       
  7396 	if (iMenuState != EOffLineOpQueueLocalToLocalMenu)
       
  7397 		{
       
  7398 		iPrevState = iMenuState;
       
  7399 		iMenuState = EOffLineOpQueueLocalToLocalMenu;
       
  7400 		}
       
  7401 
       
  7402 	test.Console()->ClearScreen();
       
  7403 	test.Console()->SetPos(0,0);
       
  7404 	test.Printf(_L("Options :\n\n"));
       
  7405 	test.Printf(_L(" 1 : Queue CopyToLocal\n"));
       
  7406 	test.Printf(_L(" 2 : Queue MoveToLocal\n"));
       
  7407 	test.Console()->SetPos(0, 12);
       
  7408 	test.Printf(_L(" X : Main menu\n"));
       
  7409 	}
       
  7410 
       
  7411 void CActiveConsole::DisplayOffLineOpUnQueueMenu()
       
  7412 	{
       
  7413 	if (iMenuState != EOffLineOpUnQueueMenu)
       
  7414 		{
       
  7415 		iPrevState = iMenuState;
       
  7416 		iMenuState = EOffLineOpUnQueueMenu;
       
  7417 		}
       
  7418 
       
  7419 	test.Console()->ClearScreen();
       
  7420 	test.Console()->SetPos(0,0);
       
  7421 	test.Printf(_L("Options :\n\n"));
       
  7422 	test.Printf(_L(" 1 : UnQueue CopyToLocal\n"));
       
  7423 	test.Printf(_L(" 2 : UnQueue CopyFromLocal\n"));
       
  7424 	test.Printf(_L(" 3 : UnQueue CopyWithinService\n"));
       
  7425 	test.Printf(_L(" 4 : UnQueue MoveToLocal\n"));
       
  7426 	test.Printf(_L(" 5 : UnQueue MoveFromLocal\n"));
       
  7427 	test.Printf(_L(" 6 : UnQueue MoveWithinService\n"));
       
  7428 	test.Printf(_L(" 7 : UnQueue Delete\n"));
       
  7429 	test.Console()->SetPos(0, 12);
       
  7430 	test.Printf(_L(" X : Main menu\n"));
       
  7431 	}
       
  7432 
       
  7433 void CActiveConsole::DisplayConnectMenu()
       
  7434 	{
       
  7435 	if (iMenuState != EConnectMenu)
       
  7436 		{
       
  7437 		iPrevState = iMenuState;
       
  7438 		iMenuState = EConnectMenu;
       
  7439 		}
       
  7440 
       
  7441 	test.Console()->ClearScreen();
       
  7442 	test.Console()->SetPos(0,0);
       
  7443 	test.Printf(_L("Options :\n\n"));
       
  7444 	test.Printf(_L(" 1 : Connect\n"));
       
  7445 	test.Printf(_L(" 2 : Disconnect\n"));
       
  7446 	test.Printf(_L(" 3 : ConnectAndSync\n"));
       
  7447 	test.Printf(_L(" 4 : FullSync\n"));
       
  7448 	test.Printf(_L(" 5 : SyncTree\n"));
       
  7449 	test.Printf(_L(" 6 : Fetch Test message\n"));
       
  7450 	test.Printf(_L(" 7 : Subscribe Test1\n"));
       
  7451 	test.Printf(_L(" 8 : UnSubscribe Test1\n"));
       
  7452 	test.Printf(_L("\n"));
       
  7453 	test.Printf(_L(" 0 : More options\n"));
       
  7454 	test.Console()->SetPos(0, 12);
       
  7455 	test.Printf(_L(" X : Main menu\n"));
       
  7456 	}
       
  7457 
       
  7458 
       
  7459 void CActiveConsole::DisplayConnect2Menu()
       
  7460 	{
       
  7461 	if (iMenuState != EConnect2Menu)
       
  7462 		{
       
  7463 		iPrevState = iMenuState;
       
  7464 		iMenuState = EConnect2Menu;
       
  7465 		}
       
  7466 
       
  7467 	test.Console()->ClearScreen();
       
  7468 	test.Console()->SetPos(0,0);
       
  7469 	test.Printf(_L("Options :\n\n"));
       
  7470 	test.Printf(_L(" 1 : Fetch inbox\n"));
       
  7471 	test.Printf(_L(" 2 : Fetch attachment\n"));
       
  7472 	test.Printf(_L(" 3 : Rename folder\n"));
       
  7473 	test.Printf(_L(" 4 : Delete folder\n"));
       
  7474 	test.Printf(_L(" 5 : Create folder\n"));
       
  7475 	test.Printf(_L(" 6 : InboxNewSync\n"));
       
  7476 	test.Printf(_L(" 7 : Fetch attached message\n"));
       
  7477 	test.Printf(_L(" 8 : Copy messages\n"));
       
  7478 	test.Console()->SetPos(0, 12);
       
  7479 	test.Printf(_L(" X : Connect menu\n"));
       
  7480 	}
       
  7481 
       
  7482 void CActiveConsole::DisplayAutomationMenu()
       
  7483 	{
       
  7484 	if (iMenuState != EAutomationMenu)
       
  7485 		{
       
  7486 		iPrevState = iMenuState;
       
  7487 		iMenuState = EAutomationMenu;
       
  7488 		}
       
  7489 
       
  7490 	test.Console()->ClearScreen();
       
  7491 	test.Console()->SetPos(0,0);
       
  7492 	test.Printf(_L("Options :\n\n"));
       
  7493 	test.Printf(_L(" 1 : Check server contents\n"));
       
  7494 	test.Printf(_L(" 2 : Test offline operations\n"));
       
  7495 	test.Printf(_L(" 3 : Test online operations\n"));
       
  7496 	test.Printf(_L(" 4 : Check Secondary Connect\n"));
       
  7497 	test.Console()->SetPos(0, 12);
       
  7498 	test.Printf(_L(" X : Main menu\n"));
       
  7499 	}
       
  7500 
       
  7501 void CActiveConsole::DisplaySynchroniseMenu()
       
  7502 	{
       
  7503 	if (iMenuState != ESynchroniseMenu)
       
  7504 		{
       
  7505 		iPrevState = iMenuState;
       
  7506 		iMenuState = ESynchroniseMenu;
       
  7507 		}
       
  7508 
       
  7509 	test.Console()->ClearScreen();
       
  7510 	test.Console()->SetPos(0,0);
       
  7511 	test.Printf(_L("Options :\n\n"));
       
  7512 	test.Printf(_L(" 1 : N-Synchronisation regression tests (use cases SA-1 - SA5)\n"));
       
  7513 	test.Printf(_L(" 2 : N-Synchronisation new functionality (use cases SA-10 - SA16)\n"));
       
  7514 	test.Printf(_L(" 3 : N-Synchronisation special cases\n"));
       
  7515 	test.Printf(_L(" 4 : N-Synchronisation performance tests\n"));
       
  7516 	test.Printf(_L(" 5 : N-Synchronisation one off tests\n"));
       
  7517 	test.Console()->SetPos(0, 12);
       
  7518 	test.Printf(_L(" X : Main menu\n"));
       
  7519 	}
       
  7520 
       
  7521 void CActiveConsole::DisplayDebugMenu()
       
  7522 	{
       
  7523 	if (iMenuState != EDebugMenu)
       
  7524 		{
       
  7525 		iPrevState = iMenuState;
       
  7526 		iMenuState = EDebugMenu;
       
  7527 		}
       
  7528 
       
  7529 	test.Console()->ClearScreen();
       
  7530 	test.Console()->SetPos(0,0);
       
  7531 	test.Printf(_L("Options :\n\n"));
       
  7532 	test.Printf(_L("Debug log level = %d\n\n"),iRefresher->iDebugLevel);
       
  7533 	test.Printf(_L(" 1 : Increase debug level\n"));
       
  7534 	test.Printf(_L(" 2 : Decrease debug level\n"));
       
  7535 	test.Console()->SetPos(0, 12);
       
  7536 	test.Printf(_L(" X : Main menu\n"));
       
  7537 	}
       
  7538 
       
  7539 // --------------------------------------------------------------------------
       
  7540 
       
  7541 // Complex menu selection functions
       
  7542 
       
  7543 
       
  7544 // Set up iServiceId;
       
  7545 void CActiveConsole::SelectImap4ServerEntryL(TChar aChar)
       
  7546 	{
       
  7547 	CImImap4Settings* settings = new CImImap4Settings();
       
  7548 	
       
  7549 	CleanupStack::PushL(settings);
       
  7550 
       
  7551 	iRefresher->CreateDefaultServiceL(settings);
       
  7552 
       
  7553 	switch(aChar)
       
  7554 		{
       
  7555 	case '0':	// trmai01.  using secure sockets
       
  7556 		settings->SetServerAddressL(_L("trmai01.it.cellulardata.com"));
       
  7557 		settings->SetLoginNameL(_L8("rahman"));
       
  7558 		settings->SetPasswordL(_L8("ibrSym"));
       
  7559 		settings->SetFolderPathL(_L8(""));
       
  7560 		settings->SetPort(143);
       
  7561 		settings->SetPathSeparator('/');
       
  7562 		settings->SetDisconnectedUserMode(ETrue);
       
  7563 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7564 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7565 		settings->SetSecureSockets(ETrue);
       
  7566 		settings->SetSubscribe(EUpdateNeither);
       
  7567 		settings->SetSynchronise(EUseCombination);
       
  7568 		iRefresher->CreateServiceL( settings, _L("trmai01"), _L("trmai01") );
       
  7569 		break;	
       
  7570 	case '1':	// Existing entry in database
       
  7571 		iRefresher->FindImap4SettingsL();
       
  7572 		iRefresher->CreateServiceL( settings, _L(""), _L(""), ETrue );
       
  7573 		break;
       
  7574 
       
  7575 	case '2':	// Gi
       
  7576 		settings->SetServerAddressL(_L("serv.ant.co.uk"));
       
  7577 		settings->SetLoginNameL(_L8("imaptest"));
       
  7578 		settings->SetPasswordL(_L8("imap.ant"));
       
  7579 		settings->SetFolderPathL(_L8("Mail"));
       
  7580 		settings->SetPort(143);
       
  7581 		settings->SetPathSeparator('/');
       
  7582 		settings->SetDisconnectedUserMode(ETrue);
       
  7583 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7584 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7585 		settings->SetSecureSockets(EFalse);
       
  7586 		settings->SetSubscribe(EUpdateNeither);
       
  7587 		settings->SetSynchronise(EUseCombination);
       
  7588 		iRefresher->CreateServiceL( settings, _L("UW IMAP"), _L("imaptest@serv") );
       
  7589 
       
  7590 		break;
       
  7591 
       
  7592 	case '3':	// Chaos
       
  7593 		settings->SetServerAddressL(_L("utter.chaos.org.uk"));
       
  7594 		settings->SetLoginNameL(_L8("test"));
       
  7595 		settings->SetPasswordL(_L8("testtest"));
       
  7596 		settings->SetFolderPathL(_L8("~/mail"));
       
  7597 		settings->SetPort(143);
       
  7598 		settings->SetPathSeparator('/');
       
  7599 		settings->SetDisconnectedUserMode(ETrue);
       
  7600 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7601 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7602 		settings->SetSecureSockets(EFalse);
       
  7603 		settings->SetSubscribe(EUpdateNeither);
       
  7604 		settings->SetSynchronise(EUseLocal);
       
  7605 		iRefresher->CreateServiceL( settings, _L("Chaos server"), _L("test@Chaos") );
       
  7606 
       
  7607 		break;
       
  7608 
       
  7609 	case '4':	// pipex
       
  7610 		settings->SetServerAddressL(_L("imap.dial.pipex.com"));
       
  7611 		settings->SetLoginNameL(_L8("mdgi05"));
       
  7612 		settings->SetPasswordL(_L8("charexaz"));
       
  7613 		settings->SetFolderPathL(_L8(""));
       
  7614 		settings->SetPort(143);
       
  7615 		settings->SetPathSeparator('/');
       
  7616 		settings->SetDisconnectedUserMode(ETrue);
       
  7617 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7618 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7619 		settings->SetSecureSockets(EFalse);
       
  7620 		settings->SetSubscribe(EUpdateNeither);
       
  7621 		settings->SetSynchronise(EUseCombination);
       
  7622 		iRefresher->CreateServiceL( settings, _L("pipex"), _L("pipex") );
       
  7623 		break;
       
  7624 
       
  7625 	case '5':	// totalise
       
  7626 		settings->SetServerAddressL(_L("mail.totalise.co.uk"));
       
  7627 		settings->SetLoginNameL(_L8("dale.self"));
       
  7628 		settings->SetPasswordL(_L8("plimsole"));
       
  7629 		settings->SetFolderPathL(_L8(""));
       
  7630 		settings->SetPort(143);
       
  7631 		settings->SetPathSeparator('/');
       
  7632 		settings->SetDisconnectedUserMode(ETrue);
       
  7633 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7634 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7635 		settings->SetSecureSockets(EFalse);
       
  7636 		settings->SetSubscribe(EUpdateNeither);
       
  7637 		settings->SetSynchronise(EUseCombination);
       
  7638 		iRefresher->CreateServiceL( settings, _L("totalise"), _L("totalise") );
       
  7639 		break;
       
  7640 
       
  7641 	case '6':	// innosoft TLS
       
  7642 		settings->SetServerAddressL(_L("eljefe.innosoft.com"));
       
  7643 		settings->SetLoginNameL(_L8("symbian"));
       
  7644 		settings->SetPasswordL(_L8("simon"));
       
  7645 		settings->SetFolderPathL(_L8(""));
       
  7646 		settings->SetPort(143);
       
  7647 		settings->SetPathSeparator('/');
       
  7648 		settings->SetDisconnectedUserMode(ETrue);
       
  7649 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7650 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7651 		settings->SetSecureSockets(ETrue);
       
  7652 		settings->SetSubscribe(EUpdateNeither);
       
  7653 		settings->SetSynchronise(EUseCombination);
       
  7654 		iRefresher->CreateServiceL( settings, _L("innosoft"), _L("innosoft") );
       
  7655 		break;
       
  7656 
       
  7657 	case '7':	// MS IMap
       
  7658 		settings->SetServerAddressL(_L("10.22.64.6"));
       
  7659 		settings->SetLoginNameL(iRefresher->iTestUtils->MachineName());
       
  7660 		settings->SetPasswordL(iRefresher->iTestUtils->MachineName());
       
  7661 		settings->SetFolderPathL(_L8(""));
       
  7662 		settings->SetPort(143);
       
  7663 		settings->SetPathSeparator('/');
       
  7664 		settings->SetDisconnectedUserMode(ETrue);
       
  7665 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7666 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7667 		settings->SetSecureSockets(EFalse);
       
  7668 		settings->SetSubscribe(EUpdateNeither);
       
  7669 		settings->SetSynchronise(EUseCombination);
       
  7670 		iRefresher->CreateServiceL( settings, _L("peterc"), _L("peterc") );
       
  7671 		break;
       
  7672 
       
  7673 	case '8':	// Gordanotest
       
  7674 		settings->SetServerAddressL(_L("mail.ntmailtest.com"));
       
  7675 		settings->SetLoginNameL(_L8("Simon.Middleton"));
       
  7676 		settings->SetPasswordL(_L8("password"));
       
  7677 		settings->SetFolderPathL(_L8(""));
       
  7678 		settings->SetPort(143);
       
  7679 		settings->SetPathSeparator('/');
       
  7680 		settings->SetDisconnectedUserMode(ETrue);
       
  7681 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7682 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7683 		settings->SetSecureSockets(EFalse);
       
  7684 		settings->SetSubscribe(EUpdateNeither);
       
  7685 		settings->SetSynchronise(EUseCombination);
       
  7686 		iRefresher->CreateServiceL( settings, _L("ntmail"), _L("ntmail") );
       
  7687 		break;
       
  7688 
       
  7689 	case '9':	// SendMail Inc		// Works with new sync menu
       
  7690 		settings->SetServerAddressL(_L("mailconnect.sendmail.com"));
       
  7691 		settings->SetLoginNameL(_L8("user4@mailconnect.sendmail.com"));
       
  7692 		settings->SetPasswordL(_L8("user4"));
       
  7693 		settings->SetFolderPathL(_L8(""));
       
  7694 		settings->SetPort(143);
       
  7695 		settings->SetPathSeparator('/');
       
  7696 		settings->SetDisconnectedUserMode(ETrue);
       
  7697 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7698 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7699 		settings->SetSecureSockets(EFalse);
       
  7700 		settings->SetSubscribe(EUpdateNeither);
       
  7701 		settings->SetSynchronise(EUseLocal);
       
  7702 		iRefresher->CreateServiceL( settings, _L("Sendmail"), _L("Sendmail") );
       
  7703 		break;
       
  7704 	
       
  7705 	case 'a':  // Fast mail reliable server for testing.
       
  7706 		settings->SetServerAddressL(_L("lon-cn-exchng2k.msexchange2k.closedtest.intra"));
       
  7707 		settings->SetFolderPathL(_L8(""));
       
  7708 		settings->SetLoginNameL(iRefresher->iTestUtils->MachineName());
       
  7709 		settings->SetPasswordL(iRefresher->iTestUtils->MachineName());
       
  7710 		settings->SetPort(143);
       
  7711 		settings->SetPathSeparator('/');
       
  7712 		settings->SetDisconnectedUserMode(ETrue);
       
  7713 		settings->SetDeleteEmailsWhenDisconnecting(ETrue);
       
  7714 		settings->SetGetMailOptions(EGetImap4EmailBodyTextAndAttachments);
       
  7715 		settings->SetSecureSockets(EFalse);
       
  7716 		settings->SetSubscribe(EUpdateNeither);
       
  7717 		settings->SetSynchronise(EUseCombination);
       
  7718 		iRefresher->CreateServiceL( settings, _L("lon-cn-exchng2k.msexchange2k.closedtest.intra"), 
       
  7719 		                            _L("lon-toqirk01@msexchange2k.closedtest.intra") );
       
  7720 
       
  7721 		break;
       
  7722 
       
  7723 	default:
       
  7724 		iMenuState=EImap4ServerMenu;
       
  7725 		break;
       
  7726 		}
       
  7727 
       
  7728 	CleanupStack::PopAndDestroy();	// settings
       
  7729 	
       
  7730 
       
  7731 	DisplayMainMenu();
       
  7732 	}
       
  7733 
       
  7734 
       
  7735 
       
  7736 void CActiveConsole::SelectImap4SettingsEntryL(TChar aChar)
       
  7737 	{
       
  7738 	iRefresher->SelectServiceIdL();
       
  7739 
       
  7740 	iRefresher->iTestUtils->GoClientSideL();
       
  7741 	CMsvEntry* entry = iRefresher->iTestUtils->iMsvEntry; 
       
  7742 	entry->SetEntryL(iRefresher->iServiceId);
       
  7743 
       
  7744 	CImImap4Settings* settings = new (ELeave)CImImap4Settings();
       
  7745 	CleanupStack::PushL(settings);
       
  7746 
       
  7747 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
  7748 	TImapAccount imapAccountId;
       
  7749 	accounts->GetImapAccountL(iRefresher->iServiceId, imapAccountId);
       
  7750 	accounts->LoadImapSettingsL(imapAccountId, *settings);
       
  7751 
       
  7752 	TInt choice;
       
  7753 	switch (aChar)
       
  7754 		{
       
  7755 	case '1':
       
  7756 		test.Printf(_L("DisconnectedUserMode: 0=Off 1=On [%d]"), settings->DisconnectedUserMode()?1:0);
       
  7757 		choice = test.Getch();
       
  7758 		settings->SetDisconnectedUserMode(choice=='0'?EFalse:
       
  7759 										  choice=='1'?ETrue:
       
  7760 										  settings->DisconnectedUserMode());
       
  7761 		break;
       
  7762 
       
  7763 	case '2':
       
  7764 		test.Printf(_L("Synchronise: Use 0=Combination 1=Local 2=Remote [%d]"), settings->Synchronise());
       
  7765 		choice = test.Getch();
       
  7766 		settings->SetSynchronise(choice=='0'?EUseCombination:
       
  7767 								 choice=='1'?EUseLocal:
       
  7768 								 choice=='2'?EUseRemote:
       
  7769 								 settings->Synchronise());
       
  7770 		break;
       
  7771 
       
  7772 	case '3':
       
  7773 		test.Printf(_L("Subscribe: Update 0=Neither 1=Local 2=Remote 3=Both [%d]"), settings->Subscribe());
       
  7774 		choice = test.Getch();
       
  7775 		settings->SetSubscribe(choice=='0'?EUpdateNeither:
       
  7776 							   choice=='1'?EUpdateLocal:
       
  7777 							   choice=='2'?EUpdateRemote:
       
  7778 							   choice=='2'?EUpdateBoth:
       
  7779 							   settings->Subscribe());
       
  7780 		break;
       
  7781 
       
  7782 	case '4':
       
  7783 		test.Printf(_L("IAP index: [%d]"), entry->Entry().MtmData1());
       
  7784 		choice = test.Getch();
       
  7785 		if (choice >= '0' && choice <= '9')
       
  7786 			{
       
  7787 			TMsvEmailEntry e = entry->Entry();
       
  7788 			e.SetMtmData1(choice-'0');
       
  7789 			entry->ChangeL(e);
       
  7790 			}
       
  7791 		break;
       
  7792 
       
  7793 	case '5':
       
  7794 		test.Printf(_L("Delete emails: When 0=Connecting 1=Disconnecting [%d]"),
       
  7795 					settings->DeleteEmailsWhenDisconnecting()?1:0);
       
  7796 		choice = test.Getch();
       
  7797 		settings->SetDeleteEmailsWhenDisconnecting(choice=='0'?EFalse:
       
  7798 												   choice=='1'?ETrue:
       
  7799 												   settings->DeleteEmailsWhenDisconnecting());
       
  7800 		break;
       
  7801 
       
  7802 	case '6':
       
  7803 		test.Printf(_L("Get Mail Options: 0=Headers 1=BodyText 2=Everything 3=Attachments [%d]"),
       
  7804 					settings->GetMailOptions());
       
  7805 		choice = test.Getch();
       
  7806 		settings->SetGetMailOptions(choice=='0'?EGetImap4EmailHeaders:
       
  7807 									choice=='1'?EGetImap4EmailBodyText:
       
  7808 									choice=='2'?EGetImap4EmailBodyTextAndAttachments:
       
  7809 									choice=='3'?EGetImap4EmailAttachments:
       
  7810 									settings->GetMailOptions());
       
  7811 		break;
       
  7812 
       
  7813 	case '7':
       
  7814 		test.Printf(_L("SecureSockets: 0=Off 1=On [%d]"), settings->SecureSockets()?1:0);
       
  7815 		choice = test.Getch();
       
  7816 		settings->SetSecureSockets(choice=='0'?EFalse:
       
  7817 								   choice=='1'?ETrue:
       
  7818 								   settings->SecureSockets());
       
  7819 		break;
       
  7820 
       
  7821 	case '8':
       
  7822 		{
       
  7823 		const TPtrC8 path = settings->FolderPath();
       
  7824 		test.Printf(_L("FolderPath: 0=\"\" 1=\"Mail\" [%S]"), &path);
       
  7825 		choice = test.Getch();
       
  7826 		if (choice=='0'||choice=='1')
       
  7827 			settings->SetFolderPathL(choice=='0'?_L8(""):_L8("Mail"));
       
  7828 		break;
       
  7829 		}
       
  7830 
       
  7831 	case '9':
       
  7832 		{
       
  7833 		const TPtrC8 password = settings->Password();
       
  7834 		test.Printf(_L("Password: 0=!foobar 1=rubbish [%S]"), &password);
       
  7835 		choice = test.Getch();
       
  7836 		if (choice=='0'||choice=='1')
       
  7837 			settings->SetPasswordL(choice=='0'?_L8("!foobar"):_L8("rubbish"));
       
  7838 		break;
       
  7839 		}
       
  7840 		}
       
  7841 
       
  7842 	accounts->SaveImapSettingsL(imapAccountId, *settings);
       
  7843 
       
  7844 	test.Printf(_L("\nUpdated settings\n"));
       
  7845 	
       
  7846 	CleanupStack::PopAndDestroy(2, settings); // fileStore/accounts, settings
       
  7847 	
       
  7848 	// go server side
       
  7849 	iRefresher->iTestUtils->GoServerSideL();
       
  7850 	iRefresher->iTestUtils->InstantiateImapServerMtmL();
       
  7851 	}
       
  7852 
       
  7853 // --------------------------------------------------------------------------
       
  7854 
       
  7855 void CActiveConsole::DumpMessageStructureL( TMsvId aId,
       
  7856 										   TInt aSummary,
       
  7857 										   TInt aParts,
       
  7858 										   TBool aRecurse,
       
  7859 										   TBool aShowIds,
       
  7860 										   MsgMatchFn aMatch )
       
  7861 	{
       
  7862 	COutputter* putter = COutputter::NewL( &test );
       
  7863 	CleanupStack::PushL(putter);
       
  7864 
       
  7865 	putter->SetRFs( &theFs );
       
  7866 	theFs.SetSessionPath( KFilePathMailTest );
       
  7867 
       
  7868 	CMsgOutputter* dumper = CMsgOutputter::NewL( putter, iRefresher->ServerEntry() );
       
  7869 	CleanupStack::PushL(dumper);
       
  7870 	
       
  7871 	dumper->DumpL( aId, aSummary, aParts, aRecurse, aShowIds, aMatch );
       
  7872 
       
  7873 	CleanupStack::PopAndDestroy(2); // dumper, putter
       
  7874 	}
       
  7875 
       
  7876 // --------------------------------------------------------------------------
       
  7877 
       
  7878 LOCAL_C void doMainL()
       
  7879 	{
       
  7880 	// Handle command line arguments
       
  7881 	CCommandLineArguments* cmdLineArg=CCommandLineArguments::NewLC();
       
  7882 	TInt count = cmdLineArg->Count();
       
  7883 	TBool isCmdLine=FALSE;
       
  7884 	if (count>2)	// Command line arguments?
       
  7885 		{
       
  7886 		if (!(cmdLineArg->Arg(EArgTestParams).Compare(KTestParams)))
       
  7887 			isCmdLine=TRUE;
       
  7888 		}	
       
  7889 
       
  7890 	TestScheduler* theScheduler = new (ELeave) TestScheduler;
       
  7891 	CleanupStack::PushL(theScheduler);
       
  7892 
       
  7893 	CActiveScheduler::Install( theScheduler );
       
  7894 
       
  7895 	User::LeaveIfError(theFs.Connect());
       
  7896 	theFs.SetSessionPath(_L("C:\\"));
       
  7897 
       
  7898 	
       
  7899 	// Load the serial comms device drivers.  If this is not done,
       
  7900 	// connecting to a IMAP4 server returns KErrNotFound (-1).
       
  7901 	TInt err;
       
  7902 	err=User::LoadPhysicalDevice(PDD_NAME);
       
  7903 	if (err!=KErrNone && err!=KErrAlreadyExists)
       
  7904 		User::Leave(err);
       
  7905 	err=User::LoadLogicalDevice(LDD_NAME);
       
  7906 	if (err!=KErrNone && err!=KErrAlreadyExists)
       
  7907 		User::Leave(err);
       
  7908 	
       
  7909 	
       
  7910 	CTestRefreshMBox* refresher = CTestRefreshMBox::NewLC(isCmdLine ? cmdLineArg:NULL);
       
  7911 
       
  7912 
       
  7913 
       
  7914 	test((refresher->ServerEntry())->Entry().Id()==KMsvRootIndexEntryId);
       
  7915 	test.Console()->SetPos(0, 17);
       
  7916 
       
  7917 	// Create and start the active console
       
  7918 	CActiveConsole* activeConsole = CActiveConsole::NewLC(refresher,isCmdLine ? cmdLineArg:NULL);
       
  7919 	refresher->SetConsole(activeConsole);
       
  7920 	activeConsole->RequestCharacter();
       
  7921 	if (isCmdLine)
       
  7922 		activeConsole->DoCancel();
       
  7923 
       
  7924 	// Main program
       
  7925 	CActiveScheduler::Start();
       
  7926 
       
  7927 	// Cleanup exit
       
  7928 	test.Printf(_L("---------------------\n"));
       
  7929 	test.Printf(_L("      Going down     \n"));
       
  7930 	test.Printf(_L("---------------------\n"));
       
  7931 
       
  7932 	test.Printf(_L("Deleting activeconsole\n"));
       
  7933 	CleanupStack::PopAndDestroy();	// activeConsole
       
  7934 	
       
  7935 	test.Printf(_L("Deleting Refresher\n"));
       
  7936 	CleanupStack::PopAndDestroy();	// refresher
       
  7937 
       
  7938 	test.Printf(_L("Deleting scheduler\n"));
       
  7939 	CleanupStack::PopAndDestroy();	// scheduler
       
  7940 
       
  7941 	test.Printf(_L("Deleting command line args\n"));
       
  7942 	CleanupStack::PopAndDestroy();	// cmdLineArg
       
  7943 
       
  7944 	test.Printf(_L("Closing FS\n"));
       
  7945 	theFs.Close();
       
  7946 	}
       
  7947 
       
  7948 
       
  7949 _LIT(KMessage, "T_IMPS01 - Test Harness");
       
  7950 
       
  7951 GLDEF_C TInt E32Main()
       
  7952 	{
       
  7953 	__UHEAP_MARK;
       
  7954 
       
  7955 	test.Start(KMessage);
       
  7956 	CTrapCleanup* theCleanup=CTrapCleanup::New();
       
  7957 	
       
  7958 	TRAPD(ret,doMainL());		
       
  7959 	
       
  7960 	test(ret==KErrNone);
       
  7961 	
       
  7962 	delete theCleanup;	
       
  7963 	
       
  7964 	test.Console()->SetPos(0, 13);
       
  7965 	test.End();
       
  7966 	test.Close();
       
  7967 	
       
  7968 	__UHEAP_MARKEND;
       
  7969 	return(KErrNone);
       
  7970 	}
       
  7971 
       
  7972 // --------------------------------------------------------------------------