LOCAL_C void OverwriteSmtpSettingsL(TBool aRequestReceipt)
	{
	testUtils->iMsvEntry->SetEntryL(smtpService);
	//overwrite the setings with test code one.  Don't want the default settings.
	CEmailAccounts* accounts = CEmailAccounts::NewLC();

	CImSmtpSettings* settings = new(ELeave) CImSmtpSettings();
	CleanupStack::PushL(settings);
	settings->Reset();
	_LIT(KSmtpServer, "msg6"); 
	// globel address for msg6 is fe80::2c0:4fff:fe84:61f7
	// link local address fe80::1111:1111:dead:beef
	settings->SetServerAddressL(KSmtpServer);
	settings->SetEmailAliasL(_L("SMTP_IPV6 Test"));
	_LIT(KSmtpEmailAddress, "<kashifn@msg4>");
	settings->SetEmailAddressL(KSmtpEmailAddress);
	settings->SetReplyToAddressL(KSmtpEmailAddress);
	settings->SetBodyEncoding(EMsgOutboxMIME);
	settings->SetReceiptAddressL(KSmtpEmailAddress);
	settings->SetRequestReceipts(aRequestReceipt);
	settings->SetPort(25);
	
	TSmtpAccount smtpAccountId;
	accounts->GetSmtpAccountL(smtpService, smtpAccountId);
	accounts->SaveSmtpSettingsL(smtpAccountId, *settings);
	CleanupStack::PopAndDestroy(2); //settings, store/account

	CTestTimer* timer = CTestTimer::NewL();
	timer->After(5000000);
	CActiveScheduler::Start();
	delete timer;
	}
LOCAL_C void ResetSettingsL(TBool aSecureSocket)
	{
	_LIT(KSmtpServer, "smtp.demon.co.uk");
	_LIT(KSmtpEmailAlias, "SMTP STARTTLS");
	_LIT(KSmtpEmailAddress, "<a@b>");

	// Overwrite the setings with test code one.  Don't want the default settings.
	CImSmtpSettings* settings = new(ELeave) CImSmtpSettings();
	CleanupStack::PushL(settings);
	
	CEmailAccounts* accounts = CEmailAccounts::NewLC();
	
	TSmtpAccount smtpAccountId;
	accounts->GetSmtpAccountL(smtpService,smtpAccountId); 
	accounts->LoadSmtpSettingsL(smtpAccountId, *settings);

	settings->SetServerAddressL(KSmtpServer);
	settings->SetEmailAliasL(KSmtpEmailAlias);
	settings->SetEmailAddressL(KSmtpEmailAddress);
	settings->SetReplyToAddressL(KSmtpEmailAddress);
	settings->SetBodyEncoding(EMsgOutboxMIME);
	settings->SetReceiptAddressL(KSmtpEmailAddress);
	settings->SetSecureSockets(aSecureSocket);
	settings->SetPort(25);
	
	accounts->SaveSmtpSettingsL(smtpAccountId, *settings);

	CleanupStack::PopAndDestroy(2, settings); //settings, store/accounts
	}
EXPORT_C void CSmtpClientMtm::CreateMessageL(TMsvId aServiceId)
/** Creates a new message entry as a child of the current context.

@param aServiceId ID of the service to own the entry. */
	{
	// fix for DEF051564 - SMTP client MTM CreateMessageL not creating message in correct state
	TMsvEmailTypeList emailTypeList = KMsvEmailTypeListInvisibleMessage | KMsvEmailTypeListMessageInPreparation;

	CEmailAccounts* account = CEmailAccounts::NewLC();
	
	CImSmtpSettings* smtpSettings = new (ELeave) CImSmtpSettings;
	CleanupStack::PushL(smtpSettings);
  	TSmtpAccount id;
	account->GetSmtpAccountL(aServiceId, id);
	account->LoadSmtpSettingsL(id, *smtpSettings);
	
	switch (smtpSettings->BodyEncoding())
		{
		case EMsgOutboxMHTMLAsMIME:
		case EMsgOutboxMHTMLAlternativeAsMIME:
			emailTypeList |= KMsvEmailTypeListMHTMLMessage;
			break;
		case EMsgOutboxDefault:
		case EMsgOutboxNoAlgorithm:
		case EMsgOutboxMIME:
			break;
		}
	CleanupStack::PopAndDestroy(2, account); // smtpSettings, account
	
	// Now invoke the create new mail operation.
	// Note that it is wrapped up to make the asynchronous call synchronous.
	CMsvOperationActiveSchedulerWait* waiter=CMsvOperationActiveSchedulerWait::NewLC();
	CImEmailOperation* createNewMailOp = CImEmailOperation::CreateNewL(waiter->iStatus, iMsvEntry->Session(), iMsvEntry->Entry().Id(), aServiceId, KMsvMessagePartBody|KMsvMessagePartAttachments, emailTypeList, KUidMsgTypeSMTP);
	CleanupStack::PushL(createNewMailOp);
	waiter->Start();

	// The the entry is expected to be set to the new message.
	TMsvId temp;	
	TPckgC<TMsvId> paramPack(temp);
	const TDesC8& progBuf = createNewMailOp->ProgressL();	
	paramPack.Set(progBuf);
	TMsvId messageId = paramPack();
	iMsvEntry->SetEntryL(messageId);
	
	CMsvStore* store = iMsvEntry->ReadStoreL();
	CleanupStack::PushL(store);
	iHeader->RestoreL(*store);

	CleanupStack::PopAndDestroy(3, waiter); // waiter, createNewMailOp, store	
	}
LOCAL_C void SetAddVCardToEmailL(TBool addVCard, TMsvId serviceId)
	{
	CImSmtpSettings* smtpSettings = new (ELeave) CImSmtpSettings;
	CleanupStack::PushL(smtpSettings);

	CEmailAccounts* accounts = CEmailAccounts::NewLC();
	TSmtpAccount smtpAccount;
	accounts->GetSmtpAccountL(serviceId, smtpAccount);
	accounts->LoadSmtpSettingsL(smtpAccount, *smtpSettings);

	smtpSettings->SetAddVCardToEmail(addVCard);
	
	accounts->SaveSmtpSettingsL(smtpAccount, *smtpSettings);

	CleanupStack::PopAndDestroy(2); // smtpSettings, accounts
	}
LOCAL_C void SetSignatureToEmailL(TBool addSignature, TMsvId serviceId)
	{
	CImSmtpSettings* smtpSettings = new (ELeave) CImSmtpSettings;
	CleanupStack::PushL(smtpSettings);

	CEmailAccounts* accounts = CEmailAccounts::NewLC();
	TSmtpAccount smtpAccount;
	accounts->GetSmtpAccountL(serviceId, smtpAccount);
	accounts->LoadSmtpSettingsL(smtpAccount, *smtpSettings);

	smtpSettings->SetAddSignatureToEmail(addSignature);
	
	accounts->SaveSmtpSettingsL(smtpAccount, *smtpSettings);

	CleanupStack::PopAndDestroy(2); // smtpSettings, accounts

	if (addSignature)
		testUtils->WriteComment(_L("\tAdd VCard"));
	}
LOCAL_C void CreateNewSmtpSettingsL()
	{
	testUtils->iMsvEntry->SetEntryL(smtpService);
	TMsvId serviceId = smtpService;
	//overwrite the settings with test code one.  Don't want the default settings.
	CImSmtpSettings* settings = new(ELeave) CImSmtpSettings();
	CleanupStack::PushL(settings);
	CEmailAccounts* accounts = CEmailAccounts::NewLC();
	TSmtpAccount smtpAccountId;
	accounts->GetSmtpAccountL( serviceId, smtpAccountId);
	accounts->LoadSmtpSettingsL(smtpAccountId, *settings);
	TInt serverLength = testUtils->MachineName().Length();
	HBufC* serverad = HBufC::NewL(serverLength + 7 ); // 7 is the length of KServerAddress
	CleanupStack::PushL(serverad);
	serverad->Des().Copy(testUtils->MachineName());
	serverad->Des().Append(KServer);	
    settings->SetServerAddressL(*serverad);
    HBufC* emailaddress = HBufC::NewL(serverLength + 8 + serverad->Des().Length() + 1 );
   	CleanupStack::PushL(emailaddress);
   	emailaddress->Des().Copy(testUtils->MachineName());
   	emailaddress->Des().Append(KAt);
   	emailaddress->Des().Append(*serverad);
   	settings->SetEmailAddressL(*emailaddress);
	settings->SetReplyToAddressL(*emailaddress);
	settings->SetReceiptAddressL(*emailaddress);
	settings->SetEmailAliasL(_L("Test Account"));
	settings->SetBodyEncoding(EMsgOutboxMIME);
	settings->SetRequestReceipts(EFalse);
	settings->SetPort(25);
	TSmtpAccount smtpAccount;
 	accounts->GetSmtpAccountL(smtpService, smtpAccount);
	accounts->SaveSmtpSettingsL(smtpAccount, *settings);
	CleanupStack::PopAndDestroy(emailaddress);
	CleanupStack::PopAndDestroy(serverad);
	CleanupStack::PopAndDestroy(2,settings);
	testUtils->WriteComment(_L("Created New SmtpSettings  "));	
		
	}
/**
  ExecuteActionL
	Obtain the input parameters
	1.	sendAsMessage
	2.	recipientAddress
	3.	alias  (Default value implies empty string)
	4. recipientAddress1
	5.	recipientType 
	IF alias for recipient address is provided as input 
	Call RSendAsMessage::AddRecipient (const TDesC& aAddress, const TDesC& aAlias, 
	TSendAsRecipientType aRecipientType) passing recipientAddress, alias and
	recipientType as input parameters
    ELSE 
	Call RSendAsMessage::AddRecipient (const TDesC& aAddress, TSendAsRecipientType aRecipientType) passing recipientAddress and recipientType as input parameters

  @internalTechnology 
  @pre    None
  @post   None
  @leave  System wide errors
*/
void CMtfTestActionSendAsAddMultipleRecipient::ExecuteActionL()
	{
	if((TestCase().TestStepResult()) == EPass)
		{
		TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSendAsAddMultipleRecipient);

		// Get test action input parameters
		RSendAsMessage sendAsMessage = ObtainValueParameterL<RSendAsMessage>(TestCase(),
											ActionParameters().Parameter(0));

		HBufC*  recipientAddress	 = ObtainParameterReferenceL<HBufC>(TestCase(),
											ActionParameters().Parameter(1), NULL);


		HBufC* alias				 = ObtainParameterReferenceL<HBufC>(TestCase(),
											ActionParameters().Parameter(2), NULL);

		
		RSendAsMessage::TSendAsRecipientType recipientType	
									 = ObtainValueParameterL<RSendAsMessage::TSendAsRecipientType>(TestCase(),
											ActionParameters().Parameter(3));

		TUid msgTypeId				 =  ObtainValueParameterL<TUid>(TestCase(),
											ActionParameters().Parameter(4));
											
		TInt expectedErr			 =  ObtainValueParameterL<TInt>(TestCase(),
											ActionParameters().Parameter(5));
		//Get the second recipient address
		HBufC*  recipientAddress1	 = ObtainParameterReferenceL<HBufC>(TestCase(),
											ActionParameters().Parameter(6), NULL);
										
		TInt err = KErrNone;
		TBuf16<3> btAddress;
						

		if(recipientAddress == NULL)
			{
			if( msgTypeId.operator == (KUidMsgTypeSMTP))
				{
				TMsvId paramServiceId = ObtainValueParameterL<TMsvId>(TestCase(), ActionParameters().Parameter(7), 0);
				CImSmtpSettings* settings = new(ELeave) CImSmtpSettings();
				CleanupStack::PushL(settings);
		 		
		 		CEmailAccounts* accounts = CEmailAccounts::NewLC();
		 		TSmtpAccount smtpAccount;
		 		accounts->GetSmtpAccountL(paramServiceId, smtpAccount);
				accounts->LoadSmtpSettingsL(smtpAccount, *settings);
				CleanupStack::PopAndDestroy(accounts);
				
				recipientAddress=settings->EmailAddress().AllocL();
				CleanupStack::PopAndDestroy(settings);
				}
			else
				{
				TestCase().ERR_PRINTF1(_L("Recipient address is not provided"));
				TestCase().SetTestStepResult(EFail);
				}
			}
		else
			{
			if( msgTypeId.operator == (KUidMsgTypeBt))
				{
				CMtfTestActionUtilsMessage::FormatBtRecipientAddress(*recipientAddress, btAddress);
				}
			}
		if((TestCase().TestStepResult()) == EPass)
			{
			if(alias == NULL )
				{
				if( msgTypeId.operator == (KUidMsgTypeBt))
					{
					TRAP(err,sendAsMessage.AddRecipientL(btAddress, recipientType));
					}
				else
					{
					TRAP(err,sendAsMessage.AddRecipientL(*recipientAddress, recipientType));
					TRAP(err, sendAsMessage.AddRecipientL(*recipientAddress1,  recipientType));
					}
				if(err == expectedErr)
					{
					TestCase().INFO_PRINTF1(_L("Recipient address added successfully"));	
					}
				else
					{
					TestCase().ERR_PRINTF2(_L("Add Recipient address failed with error %d"), err);
					}
				}
			else
				{
				if( msgTypeId.operator == (KUidMsgTypeBt))
					{
					TRAP(err,sendAsMessage.AddRecipientL(btAddress, alias->Des(), recipientType));
					}
				else
					{
					TRAP(err, sendAsMessage.AddRecipientL(recipientAddress->Des(), alias->Des(), recipientType));
					}

				if (err == expectedErr)
					{
					if(err == KErrNone)
						{
						TestCase().INFO_PRINTF1(_L("Recipient address with alias added successfully"));						
						}
					else
						{
						TestCase().INFO_PRINTF1(_L("Recipient address with alias failed with expected error"));
						}
					}
				else
					{
					TestCase().ERR_PRINTF2(_L("Add Recipient address with alias failed with error %d"), err);
					}
				}
				
			}
									
			TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSendAsAddMultipleRecipient);
		}
	TestCase().ActionCompletedL(*this);
	}
/**
ReadSmtpSettingsFromConfigurationFileL()
Modifies the POP related default setting and IAP objects.

@param  aSettingsFile
Configuration/setting file path. 

@param  aSmtpSet
@param  aSmtpIapPref
*/	
EXPORT_C void CT_MsgUtilsReadEmailSettingsFromConfigFile::ReadSmtpSettingsFromConfigurationFileL(TDesC& aSettingsFile, 
										CImSmtpSettings& aSmtpSet, CImIAPPreferences& aSmtpIapPref,const TDesC&/* aPtrEmailAdd*/)
	{
	// Parses the setting file
	CT_MsgUtilsConfigFileParserUtility* scriptFileParser = CT_MsgUtilsConfigFileParserUtility::NewL(aSettingsFile);
	CleanupStack::PushL(scriptFileParser);	
	
	TPtrC8 string8Ptr; 
	TPtrC stringPtr = KNone(); 
	TInt intValue;

	if(scriptFileParser->GetFieldAsString(KCfgSmtpServerAddress, stringPtr) == KErrNone)
		{
		aSmtpSet.SetServerAddressL(stringPtr);
		}
	
	CT_MsgUtilsConfigFileMachineName* machineNameFile = CT_MsgUtilsConfigFileMachineName::NewLC(stringPtr);
	TPtrC emailAddr(machineNameFile->MachineNameEmail());
	TPtrC8 machineName(machineNameFile->MachineName());
	
	if(scriptFileParser->GetFieldAsString(KCfgSmtpEmailAddress, stringPtr) == KErrNone)
		{
		aSmtpSet.SetEmailAddressL(stringPtr);
		}
		
	else
		{
		aSmtpSet.SetEmailAddressL(emailAddr);
		}

	if(scriptFileParser->GetFieldAsString(KCfgSmtpBodyEncoding, stringPtr) == KErrNone)
		{
		TMsgOutboxBodyEncoding setBodyEncoding = CT_MsgUtilsEnumConverter::ConvertDesToTMsgOutboxBodyEncoding(stringPtr);
		aSmtpSet.SetBodyEncoding(setBodyEncoding);
		}
	
	if(scriptFileParser->GetFieldAsString(KCfgSmtpReceiptAddress, stringPtr) == KErrNone)
		{
		aSmtpSet.SetReceiptAddressL(stringPtr);
		}
		
	else
		{
		aSmtpSet.SetReceiptAddressL(emailAddr);
		}
		
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpRequestReceipts, intValue) == KErrNone)
		{		
		aSmtpSet.SetRequestReceipts((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsString(KCfgSmtpSendMessageOption, stringPtr) == KErrNone)
		{
		TImSMTPSendMessageOption setSendMessageOption = CT_MsgUtilsEnumConverter::ConvertDesToTImSMTPSendMessageOption(stringPtr);
		aSmtpSet.SetSendMessageOption(setSendMessageOption);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetPort, intValue) == KErrNone)
		{
		aSmtpSet.SetPort(intValue);
		}
	
	if(scriptFileParser->GetFieldAsString(KCfgSmtpEmailAlias, stringPtr) == KErrNone)
		{
		aSmtpSet.SetEmailAliasL(stringPtr);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpDefaultMsgCharSet, intValue) == KErrNone)
		{
		TUid tmp = { intValue };
		aSmtpSet.SetDefaultMsgCharSet(tmp);
		}
	
	if(scriptFileParser->GetFieldAsString(KCfgSmtpSetReplyToAddress, stringPtr) == KErrNone)
		{
		aSmtpSet.SetReplyToAddressL(stringPtr);
		}
		
	else
		{
		aSmtpSet.SetReplyToAddressL(emailAddr);
		}
			
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetAddVCardToEmail, intValue) == KErrNone)
		{		
		aSmtpSet.SetAddVCardToEmail((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetAddSignatureToEmail, intValue) == KErrNone)
		{		
		aSmtpSet.SetAddSignatureToEmail((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsString(KCfgSmtpSetSendCopyToSelf, stringPtr) == KErrNone)
		{
		TImSMTPSendCopyToSelf setSMTPSendCopyToSelf = CT_MsgUtilsEnumConverter::ConvertDesToTImSMTPSendCopyToSelf(stringPtr);
		aSmtpSet.SetSendCopyToSelf(setSMTPSendCopyToSelf);
		}
	
	if(scriptFileParser->GetFieldAsString8(KCfgSmtpSetLoginName, string8Ptr) == KErrNone)
		{
		aSmtpSet.SetLoginNameL(string8Ptr);
		}
		
	else
		{
		aSmtpSet.SetLoginNameL(machineName);	
		}
			
	if(scriptFileParser->GetFieldAsString8(KCfgSmtpSetPassword, string8Ptr) == KErrNone)
		{
		aSmtpSet.SetPasswordL(string8Ptr);
		}

	else
		{
		aSmtpSet.SetPasswordL(machineName);	
		}
			
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetSMTPAuth, intValue) == KErrNone)
		{		
		aSmtpSet.SetSMTPAuth((TBool) intValue);
		}

	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetInboxLoginDetails, intValue) == KErrNone)
		{		
		aSmtpSet.SetInboxLoginDetails((TBool) intValue);
		}

	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSecureSockets, intValue) == KErrNone)
		{		
		aSmtpSet.SetSecureSockets((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSSLWrapper, intValue) == KErrNone)
		{		
		aSmtpSet.SetSSLWrapper((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsString(KCfgSmtpIapList, stringPtr) == KErrNone)
		{
		ReadSmtpIAPAndAddL(scriptFileParser, KCfgSmtpIapList, aSmtpIapPref);
		}
		
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSNAPId, intValue) == KErrNone)
		{		
		aSmtpIapPref.SetSNAPL(intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpBearerMobility, intValue) == KErrNone)
		{		
		aSmtpSet.SetBearerMobility((TBool) intValue);
		}	
	
	CleanupStack::PopAndDestroy(2,scriptFileParser);
	
	}