messagingfw/msgtest/testutils/email/src/emailtestutils.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 "emailtestutils.h"
       
    17 
       
    18 #include <c32comm.h>
       
    19 #include <e32test.h>
       
    20 #include <f32fsys.h>
       
    21 #include <s32file.h>
       
    22 #include <e32uid.h>
       
    23 #include <txtrich.h>
       
    24 #include <txtfmlyr.h>
       
    25 #include <msvids.h>
       
    26 #include <msvuids.h>
       
    27 #include <msvruids.h>
       
    28 #include <e32std.h>
       
    29 #include <mtclbase.h>
       
    30 #include <mtclreg.h>
       
    31 #include <msvapi.h>
       
    32 #include <mtmuids.h>
       
    33 #include <smuthdr.h>
       
    34 #include <miutset.h>
       
    35 #include <es_sock.h>
       
    36 #include <in_sock.h>
       
    37 #include <commdbconnpref.h>
       
    38 #include <cemailaccounts.h>
       
    39 #include <iapprefs.h>
       
    40 
       
    41 #include <mmsvattachmentmanager.h>
       
    42 #include <cmsvattachment.h>
       
    43 #include <centralrepository.h>
       
    44 
       
    45 _LIT(KComputerNamePath, "c:\\msgtest\\MachineName.txt");
       
    46 
       
    47 EXPORT_C CEmailTestUtils* CEmailTestUtils::NewL(RTest& aRTest, TUint aCreationFlags)
       
    48 	{
       
    49 	CEmailTestUtils* self = NewLC(aRTest, aCreationFlags);
       
    50 	CleanupStack::Pop();
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 EXPORT_C CEmailTestUtils* CEmailTestUtils::NewLC(RTest& aRTest, TUint aCreationFlags)
       
    55 	{
       
    56 	CEmailTestUtils* self = new (ELeave) CEmailTestUtils(aRTest);
       
    57 	CleanupStack::PushL(self);
       
    58 	self->ConstructL(aCreationFlags);
       
    59 	return self;
       
    60 	}
       
    61 
       
    62 EXPORT_C void CEmailTestUtils::InstantiateImapClientMtmL()
       
    63 	{
       
    64 	// client side
       
    65 	iImapClientMtm = (CImap4ClientMtm*) InstantiateClientMtmL(KUidMsgTypeIMAP4, iImapServiceId);
       
    66 	}
       
    67 
       
    68 EXPORT_C void CEmailTestUtils::InstantiatePopClientMtmL()
       
    69 	{
       
    70 	iPopClientMtm = (CPop3ClientMtm*) InstantiateClientMtmL(KUidMsgTypePOP3, iPopServiceId);
       
    71 	}
       
    72 
       
    73 EXPORT_C void CEmailTestUtils::InstantiateSmtpClientMtmL()
       
    74 	{
       
    75 	iSmtpClientMtm = (CSmtpClientMtm*) InstantiateClientMtmL(KUidMsgTypeSMTP, iSmtpServiceId);
       
    76 	}
       
    77 
       
    78 EXPORT_C void CEmailTestUtils::InstantiateImapServerMtmL()
       
    79 	{
       
    80 	iImapServerMtm = (CBaseServerMtm*) InstantiateServerMtmL(KUidMsgTypeIMAP4, iImapServiceId);
       
    81 	}
       
    82 
       
    83 EXPORT_C void CEmailTestUtils::InstantiatePopServerMtmL()
       
    84 	{
       
    85 	iPopServerMtm = (CBaseServerMtm*) InstantiateServerMtmL(KUidMsgTypePOP3, iPopServiceId);
       
    86 	}
       
    87 
       
    88 EXPORT_C void CEmailTestUtils::InstantiateSmtpServerMtmL()
       
    89 	{
       
    90 	iSmtpServerMtm = (CBaseServerMtm*) InstantiateServerMtmL(KUidMsgTypeSMTP, iSmtpServiceId);
       
    91 	}
       
    92 
       
    93 EXPORT_C void CEmailTestUtils::CreateImapServerMtmRegL()
       
    94 	{
       
    95 	CreateServerMtmRegL(KUidMsgTypeIMAP4, _L("IMAP4"), KImap4ServerMtmFileName(), TMsvTestDllInfo(KImap4ClientMtmFileName, 3), KImap4DataLayerFileName(), KImap4DataLayerFileName(), KUidMsvTechnologyGroupEmail, imap4DatFile);
       
    96 	}
       
    97 
       
    98 EXPORT_C void CEmailTestUtils::CreateSmtpServerMtmRegL()
       
    99 	{
       
   100 	CreateServerMtmRegL(KUidMsgTypeSMTP, _L("SMTP"), KSmtpServerMtmFileName(), TMsvTestDllInfo(KSmtpClientMtmFileName,2), KSmtpDataLayerFileName(), KSmtpDataLayerFileName(), KUidMsvTechnologyGroupEmail, smtpDatFile);
       
   101 	}
       
   102 
       
   103 EXPORT_C void CEmailTestUtils::CreatePopServerMtmRegL()
       
   104 	{
       
   105 	CreateServerMtmRegL(KUidMsgTypePOP3, _L("POP3"), KPop3ServerMtmFileName(), KPop3ClientMtmFileName(), KPop3DataLayerFileName(), KPop3DataLayerFileName(), KUidMsvTechnologyGroupEmail, pop3DatFile);
       
   106 	}
       
   107 
       
   108 EXPORT_C TMsvId CEmailTestUtils::CreateImapServiceL()
       
   109 	{
       
   110 	TInt err = KErrNone;
       
   111 	iImapServiceId = 0;
       
   112 	TRAP(err, ServiceIdL(KUidMsgTypeIMAP4, iImapServiceId));
       
   113 
       
   114 	if (err)
       
   115 		{
       
   116 		CEmailAccounts* account = CEmailAccounts::NewLC();
       
   117 
       
   118 		CImImap4Settings* imapSettings = new(ELeave) CImImap4Settings();
       
   119 		CleanupStack::PushL(imapSettings);
       
   120 
       
   121 		CImIAPPreferences* imapIAP = CImIAPPreferences::NewLC();
       
   122 				
       
   123 		account->PopulateDefaultImapSettingsL(*imapSettings, *imapIAP);
       
   124 
       
   125 		_LIT(KImapServer, "imap.dial.pipex.com");
       
   126 		imapSettings->SetServerAddressL(KImapServer);
       
   127 		_LIT8(KImapLoginName, "abf75");
       
   128 		imapSettings->SetLoginNameL(KImapLoginName);
       
   129 		_LIT8(KImapPassword, "oodifama");
       
   130 		imapSettings->SetPasswordL(KImapPassword);
       
   131 		imapSettings->SetPort(143);
       
   132 		
       
   133 		_LIT(KTxtAccountName, "ImapAccount");
       
   134 		TImapAccount imapAccount = account->CreateImapAccountL(KTxtAccountName, *imapSettings, *imapIAP, EFalse);
       
   135 
       
   136 		CleanupStack::PopAndDestroy(3, account); // imapIAP, imapSettings, account
       
   137 
       
   138 		ServiceIdL(KUidMsgTypeIMAP4, iImapServiceId);
       
   139 		}
       
   140 	else
       
   141 		{
       
   142 		Printf(_L("Imap Service Already Exists. You should delete the existing service first!\n"));
       
   143 		}
       
   144 
       
   145 
       
   146 	return iImapServiceId;
       
   147 	}
       
   148 
       
   149 EXPORT_C TMsvId CEmailTestUtils::CreateSmtpServiceL()
       
   150 	{
       
   151 	TInt err = KErrNone;
       
   152 	iSmtpServiceId = 0;
       
   153 	TRAP(err, ServiceIdL(KUidMsgTypeSMTP, iSmtpServiceId));
       
   154 
       
   155 	if (err)
       
   156 		{
       
   157 		CEmailAccounts* account = CEmailAccounts::NewLC();
       
   158 
       
   159 		CImSmtpSettings* smtpSettings = new(ELeave) CImSmtpSettings();
       
   160 		CleanupStack::PushL(smtpSettings);
       
   161 		
       
   162 		CImIAPPreferences* smtpIAP = CImIAPPreferences::NewLC();
       
   163 				
       
   164 		account->PopulateDefaultSmtpSettingsL(*smtpSettings, *smtpIAP);
       
   165 
       
   166 		_LIT(KSmtpServer, "smtp.dial.pipex.com");
       
   167 		smtpSettings->SetServerAddressL(KSmtpServer);
       
   168 		smtpSettings->SetEmailAliasL(_L("Messaging Test1"));
       
   169 		_LIT(KSmtpEmailAddress, "msgtest1@internet-test.plc.psion.com");
       
   170 		smtpSettings->SetEmailAddressL(KSmtpEmailAddress);
       
   171 		smtpSettings->SetReplyToAddressL(KSmtpEmailAddress);
       
   172 		smtpSettings->SetBodyEncoding(EMsgOutboxMIME);
       
   173 		smtpSettings->SetReceiptAddressL(KSmtpEmailAddress);
       
   174 		smtpSettings->SetPort(25);
       
   175 		
       
   176 		_LIT(KTxtAccountName, "SmtpAccount");
       
   177 		TSmtpAccount smtpAccount = account->CreateSmtpAccountL(KTxtAccountName, *smtpSettings, *smtpIAP, EFalse);
       
   178 
       
   179 		CleanupStack::PopAndDestroy(3, account); // smtpIAP, smtpSettings, account
       
   180 
       
   181 		ServiceIdL(KUidMsgTypeSMTP, iSmtpServiceId);
       
   182 		}
       
   183 	else
       
   184 		{
       
   185 		Printf(_L("Smtp Service Already Exists\n"));	
       
   186 		}
       
   187 
       
   188 	return iSmtpServiceId;
       
   189 	}
       
   190 
       
   191 EXPORT_C TMsvId CEmailTestUtils::CreatePopServiceL()
       
   192 	{
       
   193 	TInt err = KErrNone;
       
   194 	iPopServiceId = 0;
       
   195 	TRAP(err, ServiceIdL(KUidMsgTypePOP3, iPopServiceId));
       
   196 
       
   197 	if (err)
       
   198 		{
       
   199 		CEmailAccounts* account = CEmailAccounts::NewLC();
       
   200 
       
   201 		CImPop3Settings* popSettings = new(ELeave) CImPop3Settings();
       
   202 		CleanupStack::PushL(popSettings);
       
   203 
       
   204 		CImIAPPreferences* popIAP = CImIAPPreferences::NewLC();
       
   205 				
       
   206 		account->PopulateDefaultPopSettingsL(*popSettings, *popIAP);
       
   207 		
       
   208 		_LIT(KTxtAccountName, "PopAccount");
       
   209 		TPopAccount popAccount = account->CreatePopAccountL(KTxtAccountName, *popSettings, *popIAP, EFalse);
       
   210 
       
   211 		CleanupStack::PopAndDestroy(3, account); // popIAP,popSettings, account
       
   212 
       
   213 		ServiceIdL(KUidMsgTypePOP3, iPopServiceId);
       
   214 		}
       
   215 	else
       
   216 		{
       
   217 		Printf(_L("Pop Service Already Exists. You should delete the existing service first!\n"));
       
   218 		}
       
   219 
       
   220 
       
   221 	return iPopServiceId;
       
   222 	}
       
   223 
       
   224 EXPORT_C void CEmailTestUtils::DeleteImapServiceL()
       
   225 	{
       
   226 	DeleteServiceL(KUidMsgTypeIMAP4);
       
   227 	}
       
   228 
       
   229 EXPORT_C void CEmailTestUtils::DeleteSmtpServiceL()
       
   230 	{
       
   231 	DeleteServiceL(KUidMsgTypeSMTP);
       
   232 	}
       
   233 
       
   234 EXPORT_C void CEmailTestUtils::DeleteScriptFilesFromLogsDirL()
       
   235 	{
       
   236 	// Deletes any *.scr file from C:\logs\email directory 
       
   237 	// to enable dialup connection
       
   238 
       
   239 	TBuf<5> buf(_L("*.scr"));
       
   240 	TFileName deleteFile; 
       
   241 	deleteFile.Append(KEmailDataDir);
       
   242 	deleteFile.Append(buf);
       
   243 	
       
   244 	TFindFile finder(iFs);
       
   245 	CDir* dirs = NULL;
       
   246 	TInt err = finder.FindWildByDir(deleteFile, KEmailDataDir, dirs);
       
   247 
       
   248 	__ASSERT_ALWAYS((err == KErrNone) || (err == KErrNotFound), Panic(KErrGeneral));
       
   249 	
       
   250 	CFileMan* fileMan = CFileMan::NewL(iFs);
       
   251 	CleanupStack::PushL(fileMan);
       
   252 	fileMan->Delete(deleteFile);
       
   253 	
       
   254 	CleanupStack::PopAndDestroy(); // fileMan
       
   255 	delete dirs;
       
   256 	}
       
   257 
       
   258 EXPORT_C void CEmailTestUtils::DeletePopServiceL()
       
   259 	{
       
   260 	DeleteServiceL(KUidMsgTypePOP3);
       
   261 	}
       
   262 
       
   263 EXPORT_C TMsvId CEmailTestUtils::FindImapServiceL()
       
   264 	{
       
   265 	TMsvId firstId = 0;
       
   266 	ServiceIdL(KUidMsgTypeIMAP4, firstId);
       
   267 	return firstId;
       
   268 	}
       
   269 
       
   270 EXPORT_C TMsvId CEmailTestUtils::FindSmtpServiceL()
       
   271 	{
       
   272 	TMsvId firstId = 0;
       
   273 	ServiceIdL(KUidMsgTypeSMTP, firstId);
       
   274 	return firstId;
       
   275 	}
       
   276 
       
   277 EXPORT_C TMsvId CEmailTestUtils::FindPopServiceL()
       
   278 	{
       
   279 	TMsvId firstId = 0;
       
   280 	ServiceIdL(KUidMsgTypePOP3, firstId);
       
   281 	return firstId;
       
   282 	}
       
   283 
       
   284 EXPORT_C void CEmailTestUtils::Reset()
       
   285 	{
       
   286 	DeleteCurrentMtm();
       
   287 
       
   288 	CMsvTestUtils::Reset();
       
   289 	}
       
   290 
       
   291 EXPORT_C void CEmailTestUtils::ClearEmailAccountsL()
       
   292 	{
       
   293 	TBool isServerSide = EFalse;
       
   294 	if( iClientServer == EServerSide )
       
   295 		{
       
   296 		isServerSide = ETrue;
       
   297 		GoClientSideL();
       
   298 		}
       
   299 
       
   300 	CRepository* popRepository = CRepository::NewL(KUidMsgTypePOP3);
       
   301 	popRepository->Reset();
       
   302 	delete popRepository;
       
   303 	CRepository* imapRepository = CRepository::NewL(KUidMsgTypeIMAP4);
       
   304 	imapRepository->Reset();
       
   305 	delete imapRepository;
       
   306 	CRepository* smtpRepository = CRepository::NewL(KUidMsgTypeSMTP);
       
   307 	smtpRepository->Reset();
       
   308 	delete smtpRepository;
       
   309 	
       
   310 	if( isServerSide )
       
   311 		{
       
   312 		GoServerSideL();
       
   313 		}
       
   314 	}
       
   315 
       
   316 void CEmailTestUtils::DeleteCurrentMtm()
       
   317 	{
       
   318 	if (iImapClientMtm)
       
   319 		{
       
   320 		delete iImapClientMtm;
       
   321 		iImapClientMtm = NULL;
       
   322 		}
       
   323 	if (iPopClientMtm)
       
   324 		{
       
   325 		delete iPopClientMtm;
       
   326 		iPopClientMtm = NULL;
       
   327 		}
       
   328 	if (iSmtpClientMtm)
       
   329 		{
       
   330 		delete iSmtpClientMtm;
       
   331 		iSmtpClientMtm = NULL;
       
   332 		}
       
   333 	if (iImapServerMtm)
       
   334 		{
       
   335 		delete iImapServerMtm;
       
   336 		iImapServerMtm = NULL;
       
   337 		iServerEntry=NULL;
       
   338 		}
       
   339 	if (iPopServerMtm)
       
   340 		{
       
   341 		delete iPopServerMtm;
       
   342 		iPopServerMtm = NULL;
       
   343 		iServerEntry=NULL;
       
   344 		}
       
   345 	if (iSmtpServerMtm)
       
   346 		{
       
   347 		delete iSmtpServerMtm;
       
   348 		iSmtpServerMtm = NULL;
       
   349 		iServerEntry=NULL;
       
   350 		}
       
   351 	}
       
   352 
       
   353 EXPORT_C const TDesC8& CEmailTestUtils::MachineName()
       
   354     {
       
   355     return *iMachineName;
       
   356     }
       
   357     
       
   358 EXPORT_C CEmailTestUtils::~CEmailTestUtils()
       
   359 	{
       
   360 	Reset();
       
   361 	delete iMachineName;
       
   362 	}
       
   363 
       
   364 CEmailTestUtils::CEmailTestUtils(RTest& aRTest)
       
   365 : CMsvTestUtils(aRTest), iSmtpServiceId(KMsvNullIndexEntryId)
       
   366 	{
       
   367 	StartC32();
       
   368 	}
       
   369 
       
   370 void CEmailTestUtils::ConstructL(TUint aCreationFlags)
       
   371 	{
       
   372 	CMsvTestUtils::ConstructL(aCreationFlags);
       
   373 	CMsvTestUtils::SpecifyLogsDir(KEmailDataDir);
       
   374 
       
   375     // Read the machine name and assign to iMachineName.	
       
   376 	RFile file;
       
   377 	User::LeaveIfError(file.Open(iFs, KComputerNamePath, EFileRead));
       
   378 	CleanupClosePushL(file);
       
   379 
       
   380     TInt  fileSize;
       
   381 	User::LeaveIfError(file.Size(fileSize));
       
   382 	iMachineName = HBufC8::NewL(fileSize);
       
   383 	TPtr8 bufferPtr = iMachineName->Des();
       
   384 	User::LeaveIfError(file.Read(bufferPtr));
       
   385 
       
   386 	CleanupStack::PopAndDestroy(&file);
       
   387 	}
       
   388 
       
   389 void CEmailTestUtils::Panic(TInt aPanic)
       
   390 	{
       
   391 	User::Panic(EmailTEST_PANIC, aPanic);
       
   392 	}
       
   393 
       
   394 void CEmailTestUtils::Panic(TEmailTestUtilsPanic aPanic)
       
   395 	{
       
   396 	Panic((TInt) aPanic);
       
   397 	}
       
   398 
       
   399 EXPORT_C void CEmailTestUtils::InstallSmtpMtmGroupL()
       
   400 	{
       
   401 	InstallMtmGroupL(smtpDatFile);
       
   402 	}
       
   403 
       
   404 EXPORT_C void CEmailTestUtils::InstallPopMtmGroupL()
       
   405 	{
       
   406 	InstallMtmGroupL(pop3DatFile);
       
   407 	}
       
   408 
       
   409 EXPORT_C void CEmailTestUtils::InstallImapMtmGroupL()
       
   410 	{
       
   411 	InstallMtmGroupL(imap4DatFile);
       
   412 	}
       
   413 
       
   414 void CEmailTestUtils::SetFolderType(TMsvEntry& aMsvEntry, TPtrC& type)
       
   415 	{
       
   416 	TMsvEmailEntry& entry = (TMsvEmailEntry&)aMsvEntry;
       
   417 
       
   418 	if(entry.iType == KUidMsvRootEntry)
       
   419 		type.Set(_L("ROOT"));
       
   420 	else if(entry.iType == KUidMsvServiceEntry)
       
   421 		type.Set(_L("SERVICE"));
       
   422 	else if(entry.iType == KUidMsvFolderEntry)
       
   423 		{
       
   424 		if (entry.MessageFolderType() == EFolderTypeAlternative)
       
   425 			type.Set(_L("FOLDER_ALT"));
       
   426 		else if (entry.MessageFolderType() == EFolderTypeMixed)
       
   427 			type.Set(_L("FOLDER_MIX"));
       
   428 		else if (entry.MessageFolderType() == EFolderTypeRelated)
       
   429 			type.Set(_L("FOLDER_REL"));
       
   430 		else if (entry.MessageFolderType() == EFolderTypeRFC822)
       
   431 			type.Set(_L("FOLDER_RFC"));
       
   432 		else if (entry.MessageFolderType() == EFolderTypeUnknown)
       
   433 			type.Set(_L("FOLDER_UNKWN"));
       
   434 		else if (entry.MessageFolderType() == EFolderTypeParallel)
       
   435 			type.Set(_L("FOLDER_PLL"));
       
   436 		else if (entry.MessageFolderType() == EFolderTypeDigest)
       
   437 			type.Set(_L("FOLDER_DGST"));
       
   438 		else if (entry.MessageFolderType() == EFolderTypePartial)
       
   439 			type.Set(_L("FOLDER_PARTL"));
       
   440 		else if (entry.MessageFolderType() == EFolderTypeDirectory)
       
   441 			type.Set(_L("FOLDER_DIR"));
       
   442 		else if (entry.MessageFolderType() == EFolderTypeExternal)
       
   443 			type.Set(_L("FOLDER_EXT"));
       
   444 		else
       
   445 			type.Set(_L("FOLDER"));
       
   446 		}
       
   447 	else if(entry.iType == KUidMsvMessageEntry)
       
   448 		type.Set(_L("MESSAGE"));
       
   449 	else if(entry.iType == KUidMsvEmailTextEntry)
       
   450 		type.Set(_L("TEXT"));
       
   451 	else if(entry.iType == KUidMsvEmailHtmlEntry)
       
   452 		type.Set(_L("HTML"));
       
   453 	else if(entry.iType == KUidMsvAttachmentEntry)
       
   454 		type.Set(_L("ATTACHMENT"));
       
   455 	else
       
   456 		type.Set(_L("UNKNOWN"));
       
   457 	}
       
   458 
       
   459 EXPORT_C void CEmailTestUtils::ListChildrenL(RFile& aFile, CDir& rfcFileList, TInt& aCount, TInt& aEntryCount, TBool aReplace, TBool aOtherFiles)
       
   460 	{
       
   461 	// Check details of attachments on current context entry
       
   462 
       
   463 
       
   464 	CMsvEntrySelection* msvSelection = NULL;
       
   465 	TMsvEmailEntry entry;
       
   466 
       
   467 	if (iClientServer==EClientSide)
       
   468 		{
       
   469 		entry = (TMsvEmailEntry&) iMsvEntry->Entry(); 
       
   470 		msvSelection = iMsvEntry->ChildrenL();
       
   471 		}
       
   472 	else
       
   473 		{
       
   474 		entry = (TMsvEmailEntry&) iServerEntry->Entry(); 
       
   475 		msvSelection = new (ELeave) CMsvEntrySelection;
       
   476 		iServerEntry->GetChildren(*msvSelection);
       
   477 		}
       
   478 	CleanupStack::PushL(msvSelection);
       
   479 	
       
   480 	TInt attachCount = msvSelection->Count(); 	// For each child ..
       
   481 	TInt bodySize=0;
       
   482 
       
   483 	TPtrC type;
       
   484 
       
   485 	SetFolderType(entry, type);
       
   486 
       
   487 	TPtrC priority;
       
   488 
       
   489 	TMsvPriority temp=entry.Priority();
       
   490 	if(temp==EMsvHighPriority)
       
   491 		priority.Set(_L("High  "));
       
   492 	else if(temp==EMsvMediumPriority)
       
   493 		priority.Set(_L("Medium"));
       
   494 	else if(temp==EMsvLowPriority)
       
   495 		priority.Set(_L("Low   "));
       
   496 	else
       
   497 		priority.Set(_L("None  "));
       
   498 
       
   499 
       
   500 	TBuf<6> streams=_L("------");
       
   501 
       
   502 	if ((iClientServer==EClientSide && iMsvEntry->HasStoreL()) ||
       
   503 		(iClientServer==EServerSide && iServerEntry->HasStoreL()))
       
   504 		{
       
   505 		CMsvStore* fileStore;
       
   506 		fileStore = (iClientServer==EClientSide) ? iMsvEntry->ReadStoreL() : iServerEntry->ReadStoreL();
       
   507 		
       
   508 		if(fileStore->IsPresentL(KUidMsgFileIMailHeader))
       
   509 			{
       
   510 			if (aOtherFiles)
       
   511 				DisplayHeaderL(entry.Id(), *fileStore, iLogsDir, aReplace);
       
   512 			streams.Replace(0, 1, _L("H"));
       
   513 			}
       
   514 		if(fileStore->IsPresentL(KUidMsgFileMimeHeader))
       
   515 			{
       
   516 			if (aOtherFiles)
       
   517 				DisplayMimeHeaderL(entry.Id(), *fileStore, iLogsDir, aReplace);
       
   518 			streams.Replace(1, 1, _L("M"));
       
   519 			}
       
   520 		if(fileStore->HasBodyTextL())
       
   521 			{
       
   522 			if (aOtherFiles)
       
   523 				WriteBodyDataL(entry.Id(), iLogsDir, *fileStore, aReplace);
       
   524 			streams.Replace(2, 1, _L("B"));
       
   525 			CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
       
   526 			CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
       
   527 			CRichText* body = CRichText::NewL(paraLayer,charLayer);
       
   528 			fileStore->RestoreBodyTextL(*body);
       
   529 			bodySize=body->DocumentLength();
       
   530 			delete paraLayer;
       
   531 			delete charLayer;
       
   532 			delete body;
       
   533 			}
       
   534 		delete fileStore;
       
   535 		}
       
   536 
       
   537 	if((entry.iType==KUidMsvAttachmentEntry || entry.iType==KUidMsvEmailHtmlEntry))
       
   538 		{
       
   539 		TFileName filepath;
       
   540 
       
   541 		TBool storePresent;
       
   542 		if(iClientServer==EClientSide)
       
   543 			{
       
   544 			storePresent=iMsvEntry->HasStoreL();
       
   545 			}
       
   546 		else
       
   547 			{
       
   548 			storePresent=iServerEntry->HasStoreL();
       
   549 			}
       
   550 			
       
   551 		if(storePresent)
       
   552 			{			
       
   553 			CMsvStore* store;
       
   554 			if (iClientServer==EClientSide)
       
   555 				{
       
   556 				store = iMsvEntry->ReadStoreL();
       
   557 				CleanupStack::PushL(store);
       
   558 				}
       
   559 			else
       
   560 				{
       
   561 				store = iServerEntry->ReadStoreL();
       
   562 				CleanupStack::PushL(store);
       
   563 				}
       
   564 				
       
   565 			MMsvAttachmentManager& manager = store->AttachmentManagerL();
       
   566 			if( manager.AttachmentCount()>0 )
       
   567 				{
       
   568 				// there should only be one attachment per entry
       
   569 				CMsvAttachment* attachmentInfo = manager.GetAttachmentInfoL(0);
       
   570 				filepath = attachmentInfo->FilePath();
       
   571 				delete attachmentInfo;
       
   572 				}
       
   573 				
       
   574 			CleanupStack::PopAndDestroy(store);
       
   575 			}
       
   576 		
       
   577 		if(storePresent)
       
   578 		if (aOtherFiles)
       
   579 			WriteFileDataL(entry.Id(), filepath, iLogsDir, aReplace);
       
   580 		}
       
   581 
       
   582 	if(entry.Attachment())
       
   583 		streams.Replace(3, 1, _L("A"));
       
   584 	if(entry.Receipt())
       
   585 		streams.Replace(4, 1, _L("R"));
       
   586 
       
   587 	TBuf<16> other=_L("------ ------");
       
   588 	if(entry.VCalendar())
       
   589 		other.Replace(7, 2, _L("CAL"));
       
   590 	if(entry.ICalendar())
       
   591 		other.Replace(7, 2, _L("ICS"));
       
   592 	if(entry.VCard())
       
   593 		other.Replace(10, 2, _L("CAR"));
       
   594 
       
   595 	if (entry.New())
       
   596 		other.Replace(0, 1, _L("N"));
       
   597 	if (entry.Unread())
       
   598 		other.Replace(1, 1, _L("U"));
       
   599 	if (entry.Complete())
       
   600 		other.Replace(2, 1, _L("C"));
       
   601 	if (entry.BodyTextComplete())
       
   602 		other.Replace(3, 1, _L("B"));
       
   603 	if (entry.MHTMLEmail())
       
   604 		other.Replace(4, 1, _L("H"));
       
   605 	if (entry.Visible())
       
   606 		other.Replace(5, 1, _L("V"));
       
   607 
       
   608 	HBufC* outputL = HBufC::NewLC(600);
       
   609 	TPtr outputLine = outputL->Des();
       
   610 
       
   611 	// Put details into output string buffer
       
   612 	TMsvId current=entry.Id();
       
   613 	TMsvEntry parent;
       
   614 	if (entry.Parent() > 0)
       
   615 		{
       
   616 		if (iClientServer==EClientSide) 
       
   617 			{
       
   618 			iMsvEntry->SetEntryL(entry.Parent());
       
   619 			parent=iMsvEntry->Entry();
       
   620 			}
       
   621 		else
       
   622 			{
       
   623 			iServerEntry->SetEntry(entry.Parent());
       
   624 			parent=iServerEntry->Entry();
       
   625 			}
       
   626 		}
       
   627 	
       
   628 	if((parent.iType==KUidMsvFolderEntry)&&(parent.iDetails.Compare(_L("Outbox"))>=0)
       
   629 										&& &rfcFileList && iFileCount < rfcFileList.Count())
       
   630 		{
       
   631 		TFileName filename = (rfcFileList)[iFileCount].iName;
       
   632 		filename.SetLength(8);
       
   633 		outputLine.Append(filename);
       
   634 		iFileCount++;
       
   635 		}
       
   636 	else
       
   637 		outputLine.AppendFormat(_L("        "));
       
   638 
       
   639 	if (iClientServer==EClientSide)
       
   640 		{
       
   641 		iMsvEntry->SetEntryL(current);
       
   642 		entry = iMsvEntry->Entry();
       
   643 		}
       
   644 	else
       
   645 		{
       
   646 		iServerEntry->SetEntry(current);
       
   647 		entry = iServerEntry->Entry();
       
   648 		}
       
   649 	
       
   650 	for(TInt i=0; i < aCount; i++)
       
   651 		outputLine.AppendFormat(_L("  "));
       
   652 		
       
   653 	if (entry.iType == KUidMsvEmailTextEntry)
       
   654 		outputLine.AppendFormat(TRefByValue<const TDesC>_L("%S, 00%x, Children=%d, Size=%d, Store=%S, P=%S, Other=%S, Det:%S, Desc:%S, TxtSize:%d\r\n"),
       
   655 							&type, 
       
   656 							entry.Id(),
       
   657 							attachCount, 
       
   658 							entry.iSize,
       
   659 							&streams,
       
   660 							&priority,
       
   661 							&other,
       
   662 							&entry.iDetails,
       
   663 							&entry.iDescription,
       
   664 							bodySize);
       
   665 	else
       
   666 		outputLine.AppendFormat(TRefByValue<const TDesC>_L("%S, 00%x, Children=%d, Size=%d, Store=%S, P=%S, Other=%S, Det:%S, Desc:%S\r\n"),
       
   667 							&type, 
       
   668 							entry.Id(),
       
   669 							attachCount, 
       
   670 							entry.iSize,
       
   671 							&streams,
       
   672 							&priority,
       
   673 							&other,
       
   674 							&entry.iDetails,
       
   675 							&entry.iDescription);
       
   676 	
       
   677 	HBufC8* pOutputLine8 = HBufC8::NewLC(outputLine.Length());
       
   678 	pOutputLine8->Des().Copy(outputLine);
       
   679 	aFile.Write(pOutputLine8->Des());
       
   680 	CleanupStack::PopAndDestroy(); // pBuf16
       
   681 
       
   682 	for(TInt j=0; j<attachCount; j++)
       
   683 		{
       
   684 		// Get Context of current message
       
   685 		if (iClientServer==EClientSide) 
       
   686 			iMsvEntry->SetEntryL((*msvSelection)[j]);
       
   687 		else
       
   688 			iServerEntry->SetEntry((*msvSelection)[j]);
       
   689 		
       
   690 		aEntryCount++;
       
   691 		aCount++;
       
   692 		ListChildrenL(aFile, rfcFileList, aCount, aEntryCount, EFalse, aOtherFiles);
       
   693 		aCount--;
       
   694 		}	
       
   695 
       
   696 	CleanupStack::PopAndDestroy(2); // msvSelection, outputL
       
   697 	}
       
   698 
       
   699 void CEmailTestUtils::DisplayMimeHeaderL(TMsvId aId, CMsvStore& fileStore, const TFileName& aFilepath, TBool aReplace)
       
   700 	{
       
   701 	TFileName filename(aFilepath);
       
   702 	filename.Append(KFileNameMimeHeaders);
       
   703 
       
   704 	RFile file;
       
   705 
       
   706 	TInt err = KErrNone;
       
   707 	if (aReplace)
       
   708 		err = file.Replace(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
       
   709 	else
       
   710 		err = file.Open(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
       
   711 	if(err==KErrNotFound) // file does not exist - create it
       
   712 		err=file.Create(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
       
   713 	
       
   714 	TInt offset=0;
       
   715 	iRTest(file.Seek(ESeekEnd, offset)==KErrNone);
       
   716 
       
   717 	TBuf8<600> buf;
       
   718 	buf.Zero();
       
   719 	buf.AppendFormat(_L8("*** 00%x ************* Mime Header ******************\n"), aId);
       
   720 
       
   721 	CImMimeHeader* mimeHeader = CImMimeHeader::NewL();
       
   722 	mimeHeader->RestoreL(fileStore);
       
   723 	
       
   724 	TBuf<300> buf2;
       
   725 	
       
   726 	buf.AppendFormat(_L8("Version: %d\r\n"),mimeHeader->Version());
       
   727 	file.Write(buf);
       
   728 
       
   729 	buf.Zero();
       
   730 	buf.AppendFormat(_L8("MimeCharset: %d\r\n"),mimeHeader->MimeCharset());
       
   731 	file.Write(buf);
       
   732 	if(mimeHeader->ContentType().Length())
       
   733 		{
       
   734 		buf2.Copy(mimeHeader->ContentType());
       
   735 		DoBuf(buf, _L("Content-Type: "), buf2);
       
   736 		}
       
   737 	else buf.Zero();
       
   738 	file.Write(buf);
       
   739 
       
   740 	if(mimeHeader->ContentSubType().Length())
       
   741 		{
       
   742 		buf2.Copy(mimeHeader->ContentSubType());
       
   743 		DoBuf(buf, _L("Content-Type,SubType: "), buf2);
       
   744 		}
       
   745 	else buf.Zero(); 
       
   746 	file.Write(buf);
       
   747 
       
   748 	if(mimeHeader->ContentDisposition().Length())
       
   749 		{
       
   750 		buf2.Copy(mimeHeader->ContentDisposition());
       
   751 		DoBuf(buf, _L("Content-Disposition: "), buf2);
       
   752 		}
       
   753 	else buf.Zero();
       
   754 	file.Write(buf);
       
   755 
       
   756 	if(mimeHeader->ContentDescription().Length())
       
   757 		{
       
   758 		buf2.Copy(mimeHeader->ContentDescription());
       
   759 		DoBuf(buf, _L("Content-Description: "), buf2);
       
   760 		}
       
   761 	else buf.Zero();
       
   762 	file.Write(buf);
       
   763 
       
   764 	if(mimeHeader->ContentBase().Length())
       
   765 		{
       
   766 		buf2.Copy(mimeHeader->ContentBase());
       
   767 		DoBuf(buf, _L("Content-Base: "), buf2);
       
   768 		}
       
   769 	else buf.Zero();
       
   770 	file.Write(buf);
       
   771 
       
   772 	if(mimeHeader->ContentID().Length())
       
   773 		{
       
   774 		buf2.Copy(mimeHeader->ContentID());
       
   775 		DoBuf(buf, _L("Content-ID: "), buf2);
       
   776 		}
       
   777 	else buf.Zero();
       
   778 	file.Write(buf);
       
   779 
       
   780 	if(mimeHeader->ContentLocation().Length())
       
   781 		{
       
   782 		buf2.Copy(mimeHeader->ContentLocation());
       
   783 		DoBuf(buf, _L("Content-Location: "), buf2);
       
   784 		}
       
   785 	else buf.Zero();
       
   786 	file.Write(buf);
       
   787 
       
   788 	if(mimeHeader->ContentTransferEncoding())
       
   789 		{
       
   790 		buf.AppendFormat(_L8("Content-Transfer-Encoding: %d\r\n"),mimeHeader->ContentTransferEncoding());
       
   791 		file.Write(buf);
       
   792 		}
       
   793 
       
   794 	PrintRecipients( mimeHeader->ContentTypeParams(), _L("ContentTypeParams:"), file);
       
   795 	PrintRecipients( mimeHeader->ContentDispositionParams(), _L("ContentDispositionParams:"), file);
       
   796 
       
   797 	file.Write(_L8("\n******************** end of MIME Header ****************\n"));
       
   798 	file.Close();
       
   799 	delete mimeHeader;
       
   800 	}
       
   801 
       
   802 void CEmailTestUtils::PrintRecipients(CDesC8Array& list, const TDesC& label, RFile file)
       
   803 	{
       
   804 	TBuf8<300> buf;
       
   805 	
       
   806 	for(int i=0; i < list.Count(); i++)
       
   807 		{
       
   808 		buf.Zero();
       
   809 		buf.Copy(label); 
       
   810 		buf.Append(list[i]);
       
   811 		buf.Append(_L("\r\n"));
       
   812 		file.Write(buf);
       
   813 		}
       
   814 	}
       
   815 
       
   816 void CEmailTestUtils::PrintRecipientsL(CDesC16Array& list, const TDesC& label, RFile file)
       
   817 	{
       
   818 	TBuf8<300> buf;
       
   819 	
       
   820 	for(int i=0; i < list.Count(); i++)
       
   821 		{
       
   822 		buf.Zero();
       
   823 		buf.Copy(label); 
       
   824 
       
   825 		HBufC8* liststr=HBufC8::NewLC(list[i].Length());
       
   826 		liststr->Des().Copy(list[i]);
       
   827 
       
   828 		buf.Append(*liststr);
       
   829 		buf.Append(_L("\r\n"));
       
   830 		file.Write(buf);
       
   831 
       
   832 		CleanupStack::PopAndDestroy();
       
   833 		}
       
   834 	}
       
   835 
       
   836 
       
   837 void CEmailTestUtils::DisplayHeaderL(TMsvId aId, CMsvStore& fileStore, const TFileName& aFilepath, TBool aReplace)
       
   838 	{
       
   839 	TFileName filename(aFilepath);
       
   840 	filename.Append(KFileNameHeaders);
       
   841 
       
   842 	RFile file;
       
   843 	
       
   844 	TInt err = KErrNone;
       
   845 	
       
   846 	if (aReplace)
       
   847 		err = file.Replace(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
       
   848 	else
       
   849 		err = file.Open(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
       
   850 	if(err==KErrNotFound) // file does not exist - create it
       
   851 		err=file.Create(iFs, filename, EFileShareAny | EFileStreamText | EFileWrite);
       
   852 	
       
   853 	TInt offset=0;
       
   854 	iRTest(file.Seek(ESeekEnd, offset)==KErrNone);
       
   855 	
       
   856 	TBuf8<300> buf;
       
   857 	buf.Zero();
       
   858 	buf.AppendFormat(_L8("*** 00%x ************* Rfc822 Header ****************\n"), aId);
       
   859 	file.Write(buf);
       
   860 
       
   861 	CImHeader* header = CImHeader::NewLC();	// PushL(header)
       
   862 	CleanupStack::Pop();					// header
       
   863 	
       
   864 	TUint emptySize = header->DataSize();
       
   865 	header->RestoreL(fileStore);
       
   866 
       
   867 	TUint size = header->DataSize()-emptySize;
       
   868 	buf.Zero();
       
   869 	buf.AppendFormat(_L8("Size >>> %d\n"), size);
       
   870 	file.Write(buf);
       
   871 
       
   872 	if(header->Subject().Length())
       
   873 		DoBuf(buf, _L("Subject: "), header->Subject());
       
   874 	else buf.Zero();
       
   875 	file.Write(buf);
       
   876 
       
   877 	if(header->From().Length())
       
   878 		DoBuf(buf, _L("From: "), header->From());
       
   879 	else buf.Zero();
       
   880 	file.Write(buf);
       
   881 
       
   882 	if(header->ReplyTo().Length())
       
   883 		DoBuf(buf, _L("Return-Path: "), header->ReplyTo());
       
   884 	else buf.Zero();
       
   885 	file.Write(buf);
       
   886 
       
   887 	if(header->ImMsgId().Length())
       
   888 		DoBuf(buf, _L("ID: "), header->ImMsgId());
       
   889 	else buf.Zero();
       
   890 	file.Write(buf);
       
   891 
       
   892 	if(header->ReceiptAddress().Length())
       
   893 		DoBuf(buf, _L("Return-Receipt-To: "), header->ReceiptAddress());
       
   894 	else buf.Zero();
       
   895 	file.Write(buf);
       
   896 
       
   897 	PrintRecipientsL(header->ToRecipients(), _L("To:"), file);
       
   898 	PrintRecipientsL(header->CcRecipients(), _L("Cc:"), file);
       
   899 	PrintRecipientsL(header->BccRecipients(), _L("Bcc:"), file);
       
   900 	
       
   901 	file.Write(_L8("\n******************** end of RFC822 header **************\n"));
       
   902 	file.Close();
       
   903 	delete header;
       
   904 	}
       
   905 
       
   906 
       
   907 EXPORT_C void CEmailTestUtils::CopyScriptFileL(const TDesC& aSourceFile, const TDesC& aDestPath, const TDesC& aPortNumber)
       
   908 	{
       
   909 	TFileName destPath = aDestPath;
       
   910 	// Make the destination file name.
       
   911 	destPath.Append(_L("imsk"));
       
   912 	destPath.Append(aPortNumber);
       
   913 	destPath.Append(_L(".scr"));
       
   914 
       
   915 	// Delete the existing script file if it is there.
       
   916 	TInt err = iFs.Delete(destPath);
       
   917 	__ASSERT_ALWAYS((err == KErrNone) || (err == KErrNotFound), Panic(KErrGeneral));
       
   918 
       
   919 	// Copy the file.
       
   920 	CFileMan* fileMan = CFileMan::NewL(iFs);
       
   921 	CleanupStack::PushL(fileMan);
       
   922 	User::LeaveIfError(fileMan->Copy(aSourceFile, destPath));
       
   923 	CleanupStack::PopAndDestroy(); // fileMan
       
   924 	}
       
   925 
       
   926 EXPORT_C void CEmailTestUtils::CopyScriptFileL(const TDesC& aSourceFile, const TDesC& aPortNumber)
       
   927 	{
       
   928 	CopyScriptFileL(aSourceFile, _L("c:\\logs\\email\\"), aPortNumber);
       
   929 	}
       
   930 
       
   931 
       
   932 EXPORT_C void CEmailTestUtils::CreateMessageFilesL(TMsvId aFinalServiceId, TMsvId aCreateInFolderId)
       
   933 	{
       
   934 	CreateMessageFilesL(aFinalServiceId,aCreateInFolderId,KRfc822Dir);
       
   935 	}
       
   936 
       
   937 EXPORT_C void CEmailTestUtils::CreateMessageFilesL(TMsvId aFinalServiceId, TMsvId aCreateInFolderId,const TDesC& aPath)
       
   938 	{
       
   939 	iServerEntry->SetEntry(aFinalServiceId);
       
   940 	TInt counter=0;
       
   941 	TInt numberOfFiles=0;
       
   942 
       
   943 	// Call this function to convert each text file found in \rfc822\ directory into
       
   944 	// message files in \mail\ directory
       
   945 
       
   946 	iFs.SetSessionPath(aPath);
       
   947 
       
   948 	iRTest.Printf(_L("Generating files :"));
       
   949 
       
   950 	CDir* rfcFileList;
       
   951 	// Loads the any test files into an EntryList
       
   952 	TInt error=iFs.GetDir(_L("RFC822*.TXT"), KEntryAttNormal, ESortByName, rfcFileList);
       
   953 	if(!error)
       
   954 		{
       
   955 		numberOfFiles = rfcFileList->Count();
       
   956 		if(numberOfFiles)
       
   957 			{
       
   958 			do	{
       
   959 				iRTest.Printf(_L("."));
       
   960 				TFileName filename = (*rfcFileList)[counter].iName;
       
   961 				CreateMessageL(filename, aFinalServiceId, aCreateInFolderId);
       
   962 				counter++;
       
   963 				}
       
   964 			while(counter<numberOfFiles);
       
   965 			}
       
   966 		else
       
   967 			iRTest.Printf(_L("WARNING - There are no RFC files in test file source directory\n"));
       
   968 		}
       
   969 	else
       
   970 		iRTest.Printf(TRefByValue<const TDesC>_L("\r\nFile error %d"), error);
       
   971 
       
   972 	delete rfcFileList;
       
   973 	}
       
   974 
       
   975 EXPORT_C void CEmailTestUtils::CreateMessageL(const TDesC& filename, TMsvId aFinalServiceId, TMsvId aCreateInFolderId)
       
   976 	{
       
   977 	User::LeaveIfError(iServerEntry->SetEntry(aFinalServiceId));
       
   978 	CImRecvConvert* recvConvert = CImRecvConvert::NewLC(iFs, iServerEntry, iServerEntry->Entry().iMtm, aFinalServiceId);
       
   979 	recvConvert->SetMsvId(aCreateInFolderId); //Set the TMsvServerEntry to correct context 
       
   980 
       
   981 	TRAPD(error,ReadDataL(recvConvert, filename)); // Do the stuff
       
   982 	CleanupStack::PopAndDestroy();  //recvConvert
       
   983 	}
       
   984 
       
   985 void CEmailTestUtils::ReadDataL(CImRecvConvert* recvConvert, TFileName fileName)
       
   986 	{
       
   987 	// open the file
       
   988 	RFile file;
       
   989 
       
   990 	TInt anError = file.Open(iFs, fileName, EFileShareAny);
       
   991 	if(anError != KErrNone)
       
   992 		{
       
   993 		iRTest.Printf(TRefByValue<const TDesC>_L("\r\nFile open error %d"), anError);
       
   994 		iRTest.Getch();
       
   995 		User::Leave(KErrNotFound);
       
   996 		}
       
   997 
       
   998 	// read the file into the conversion object
       
   999 	TBuf8<1024> line;
       
  1000 	TBuf8<1> aChar;
       
  1001 	TBool finished = FALSE;
       
  1002 
       
  1003 	recvConvert->ResetL();
       
  1004 	// supply a new attachment path since previous one is discarded by call to Reset()
       
  1005 
       
  1006 	do {
       
  1007 		line.FillZ();
       
  1008 		line.SetLength(0);
       
  1009 		// compile a line one char at a time
       
  1010 		do {
       
  1011 			file.Read(aChar, 1);
       
  1012 			if(aChar.Length())
       
  1013 				line.Append(aChar);
       
  1014 			else
       
  1015 				finished = TRUE;
       
  1016 			// stop at the end of line or no more data
       
  1017 			} while(aChar.Length() && aChar[0] != 0x0A);
       
  1018 			if(!line.Length())
       
  1019 				break;
       
  1020 			/***********************************************/
       
  1021 			/* -- This is where we actually do the work -- */
       
  1022 			/***********************************************/
       
  1023 			recvConvert->ParseNextField(line); // This function doesnt actually leave, any leaves are relayed to the MessageCompleteL() function
       
  1024 		} while(!finished);
       
  1025 
       
  1026 	TRAPD(err, recvConvert->MessageCompleteL());
       
  1027 	if(err!=KErrNone)
       
  1028 		{
       
  1029 		// At this point the message should be deleted and CImRecvConvert should be Reset()
       
  1030 		iRTest.Printf(TRefByValue<const TDesC>_L("\r\nError %d occured during the conversion of Message %d"), err, recvConvert->EntryId());
       
  1031 		iRTest.Getch();
       
  1032 		}
       
  1033 	
       
  1034 	file.Close();
       
  1035 	}
       
  1036 
       
  1037 
       
  1038 EXPORT_C void CEmailTestUtils::CreateAllTestDirectories()
       
  1039 	{
       
  1040 	CMsvTestUtils::CreateAllTestDirectories();
       
  1041 
       
  1042 	iFs.SetSessionPath(_L("c:\\"));
       
  1043 
       
  1044 	if (!iFs.MkDir(KMailtestPath))
       
  1045 		{
       
  1046 		Printf(_L("Created c:\\mailtest\\ directory\n"));
       
  1047 		}
       
  1048 
       
  1049 	TUint AttValue;
       
  1050 
       
  1051 	if (iFs.Att(KImcmResourceLocation, AttValue))
       
  1052 		{
       
  1053 		if (iFs.Att(_L("z:\\resource\\messaging\\imcm.rsc"),AttValue))
       
  1054 			{
       
  1055 			Printf(_L("WARNING - IMCM.RSC cannot be found\n"));
       
  1056 			}			
       
  1057 		}
       
  1058 
       
  1059 	if (!iFs.MkDir(KEmailDataDir))
       
  1060 		{
       
  1061 		Printf(_L("Created c:\\logs\\email directory\n"));
       
  1062 		}
       
  1063 	
       
  1064 	if (!iFs.MkDir(KRfc822Dir))
       
  1065 		{
       
  1066 		Printf(_L("Created empty c:\\mailtest\\rfc822 directory. Nb. No messages to send\n"));
       
  1067 		Printf(_L("Put RFC822*.TXT files into c:\\mailtest\\rfc822 directory to run test harness\n"));
       
  1068 		}
       
  1069 	}
       
  1070 
       
  1071 
       
  1072 EXPORT_C void CEmailTestUtils::InstantiateClientMtmsL()
       
  1073 	{
       
  1074 	InstantiateImapClientMtmL();
       
  1075 	InstantiatePopClientMtmL();
       
  1076 	InstantiateSmtpClientMtmL();
       
  1077 	}
       
  1078 
       
  1079 EXPORT_C void CEmailTestUtils::InstantiateServerMtmsL()
       
  1080 	{
       
  1081 	InstantiateImapServerMtmL();
       
  1082 	InstantiatePopServerMtmL();
       
  1083 	InstantiateSmtpServerMtmL();
       
  1084 	}
       
  1085 
       
  1086 EXPORT_C void CEmailTestUtils::DeleteServicesL()
       
  1087 	{
       
  1088 	DeleteImapServiceL();
       
  1089 	DeleteSmtpServiceL();
       
  1090 	DeletePopServiceL();
       
  1091 	}
       
  1092 
       
  1093 EXPORT_C void CEmailTestUtils::CreateServicesL()
       
  1094 	{
       
  1095 	CreateImapServiceL();
       
  1096 	CreatePopServiceL();
       
  1097 	CreateSmtpServiceL();	
       
  1098 	}
       
  1099 
       
  1100 EXPORT_C void CEmailTestUtils::FindExistingServicesL()
       
  1101 	{
       
  1102 	TRAPD(err, iImapServiceId = FindImapServiceL());
       
  1103 
       
  1104 	if (err)
       
  1105 		Printf(_L("Imap Service Not Found\n"));
       
  1106 
       
  1107 	TRAP(err, iSmtpServiceId = FindSmtpServiceL());
       
  1108 
       
  1109 	if (err)
       
  1110 		Printf(_L("Smtp Service Not Found\n"));
       
  1111 
       
  1112 	TRAP(err, iPopServiceId = FindPopServiceL());
       
  1113 
       
  1114 	if (err)
       
  1115 		Printf(_L("Pop Service Not Found\n"));
       
  1116 	}
       
  1117 
       
  1118 EXPORT_C void CEmailTestUtils::InstallMtmGroupsL()
       
  1119 	{
       
  1120 	InstallSmtpMtmGroupL();
       
  1121 	InstallPopMtmGroupL();
       
  1122 	InstallImapMtmGroupL();
       
  1123 	}
       
  1124 
       
  1125 EXPORT_C void CEmailTestUtils::CreateServerMtmRegsL()
       
  1126 	{
       
  1127 	CreateImapServerMtmRegL();
       
  1128 	CreateSmtpServerMtmRegL();
       
  1129 	CreatePopServerMtmRegL();
       
  1130 	}
       
  1131 
       
  1132 
       
  1133 EXPORT_C void CEmailTestUtils::StartConnectionL(TUint32 aIAP)
       
  1134 	{
       
  1135 	RSocketServ serv;
       
  1136 	User::LeaveIfError(serv.Connect());
       
  1137 	RConnection conn;
       
  1138 	User::LeaveIfError(conn.Open(serv));
       
  1139 	TCommDbConnPref prefs;
       
  1140 	prefs.SetDirection(ECommDbConnectionDirectionOutgoing);
       
  1141 	prefs.SetBearerSet(KCommDbBearerWcdma | KCommDbBearerCSD);
       
  1142 	prefs.SetIapId(aIAP);
       
  1143 	prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  1144 	TRequestStatus status;
       
  1145 	conn.Start(prefs, status);
       
  1146 	User::WaitForRequest(status);
       
  1147 	
       
  1148 	if (status.Int() != KErrNone && status.Int() != KErrAlreadyExists && status.Int() != KErrInUse)
       
  1149 		User::Leave(status.Int());
       
  1150 	}
       
  1151