messagingfw/msgtestfw/TestActionUtils/src/CMtfTestActionUtilsPopScripts.cpp
changeset 22 bde600d88860
parent 0 8e480a14352b
equal deleted inserted replaced
21:08008ce8a6df 22:bde600d88860
       
     1 // Copyright (c) 2004-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 /**
       
    17  @file
       
    18 */
       
    19  
       
    20  
       
    21 #include "CMtfTestActionUtilsPopScripts.h"
       
    22 
       
    23 #include <pop3set.h>
       
    24 #include <smtpset.h>
       
    25 #include <iapprefs.h>
       
    26 
       
    27 #include "CMtfTestActionUtilsConfigFileParser.h"
       
    28 #include "CMtfTestActionUtilsConfigFileMachineName.h"
       
    29 
       
    30 #include "CMtfTestCase.h"
       
    31 #include "CMtfTestActionParameters.h"
       
    32 
       
    33 // POP Settings 
       
    34 
       
    35 _LIT(KCfgPopServerAddress, "PopServerAddress"); //*
       
    36 _LIT(KEmailAddressExtension, "EmailAddressExtension");
       
    37 _LIT(KCfgPopLoginName, "PopLoginName"); //*
       
    38 _LIT(KCfgPopPassword, "PopPassword"); //*
       
    39 _LIT(KCfgPopMaxEmailSize, "PopMaxEmailSize"); //*
       
    40 _LIT(KCfgPopPort, "PopPort"); //*
       
    41 _LIT(KCfgPopInboxSynchronisationLimit, "PopInboxSynchronisationLimit"); //*
       
    42 _LIT(KCfgPopSecureSockets, "PopSecureSockets"); //*
       
    43 _LIT(KCfgPopSSLWrapper, "PopSSLWrapper"); //*
       
    44 _LIT(KCfgPopGetMailOptions, "PopGetMailOptions"); //*
       
    45 _LIT(KCfgPopPopulationLimit, "PopPopulationLimit"); //*
       
    46 _LIT(KCfgPopAutoSendOnConnect, "PopAutoSendOnConnect" ); //* 
       
    47 _LIT(KCfgPopDeleteEmailsWhenDisconnecting, "PopDeleteEmailsWhenDisconnecting" ); //*
       
    48 _LIT(KCfgPopAcknowledgeReceipts, "PopAcknowledgeReceipts" ); //*
       
    49 _LIT(KCfgPopDisconnectedUserMode, "PopDisconnectedUserMode" ); //*
       
    50 _LIT(KCfgPopAPOPEncryption, "PopAPOPEncryption" ); //*
       
    51 
       
    52 
       
    53 _LIT(KCfgPopIapList , "PopIapList" );
       
    54 
       
    55 // SMTP settings
       
    56 
       
    57 _LIT(KCfgSmtpServerAddress, "SmtpServerAddress");  //*
       
    58 _LIT(KCfgSmtpEmailAddress, "SmtpEmailAddress");  //*
       
    59 _LIT(KCfgSmtpBodyEncoding, "SmtpBodyEncoding");  //*
       
    60 _LIT(KCfgSmtpReceiptAddress, "SmtpReceiptAddress");  //*
       
    61 _LIT(KCfgSmtpRequestReceipts, "SmtpRequestReceipts");  //*
       
    62 _LIT(KCfgSmtpSendMessageOption, "SmtpSendMessageOption");  //* Constants Added
       
    63 _LIT(KCfgSmtpSetPort, "SmtpSetPort");  //*
       
    64 _LIT(KCfgSmtpEmailAlias, "SmtpEmailAlias");  //*
       
    65 _LIT(KCfgSmtpDefaultMsgCharSet, "SmtpMsgCharSet");  //*
       
    66 
       
    67 
       
    68 
       
    69 _LIT(KCfgSmtpSetReplyToAddress, "SmtpSetReplyToAddress");  //*
       
    70 _LIT(KCfgSmtpSetAddVCardToEmail, "SmtpSetAddVCardToEmail"); //*
       
    71 _LIT(KCfgSmtpSetAddSignatureToEmail, "SmtpSetAddSignatureToEmail");  //*
       
    72 _LIT(KCfgSmtpSetSendCopyToSelf, "SmtpSetSendCopyToSelf");  //* 
       
    73 _LIT(KCfgSmtpSetLoginName, "SmtpSetLoginName");  //*
       
    74 _LIT(KCfgSmtpSetPassword, "SmtpSetPassword");  //*
       
    75 _LIT(KCfgSmtpSetSMTPAuth, "SmtpSetSMTPAuth");  //*
       
    76 _LIT(KCfgSmtpSetInboxLoginDetails, "SmtpSetInboxLoginDetails");  //*
       
    77 
       
    78 
       
    79 _LIT(KCfgSmtpSecureSockets, "SmtpSetSecureSockets");  //*
       
    80 _LIT(KCfgSmtpSSLWrapper, "SmtpSetSSLWrapper");  //*
       
    81 	//???? Currently All in same file is this what is intended or are they intended to be in 
       
    82 	// seperate files, which would require more index's ?
       
    83 
       
    84 _LIT(KCfgSmtpIapList , "SmtpIapList" );
       
    85 
       
    86 
       
    87 void CMtfTestActionUtilsPopScripts::ReadPopSettingsFromConfigurationFileL(CMtfTestCase& aTestCase, const TDesC& aSettingsFile, 
       
    88 											CImPop3Settings& aPopSet, CImIAPPreferences& aPopIapPref, 
       
    89 											CImSmtpSettings& aSmtpSet, CImIAPPreferences& aSmtpIapPref)
       
    90 {
       
    91 	CMtfTestActionUtilsConfigFileParser* scriptFileParser = CMtfTestActionUtilsConfigFileParser::NewL(aSettingsFile);
       
    92 	CleanupStack::PushL(scriptFileParser);
       
    93 	
       
    94 	TPtrC8 string8Ptr; 
       
    95 	TPtrC stringPtr; 
       
    96 	TInt intValue;
       
    97 
       
    98 
       
    99 	// POP3 settings
       
   100 	if(scriptFileParser->GetFieldAsString(KCfgPopServerAddress, stringPtr) == KErrNone)
       
   101 	{	
       
   102 		aPopSet.SetServerAddressL(stringPtr);
       
   103 	}
       
   104 	
       
   105 	CMtfTestActionUtilsConfigFileMachineName* machineNameFile = NULL;
       
   106 
       
   107 	TPtrC emailAddressExtension;
       
   108 	if (scriptFileParser->GetFieldAsString(KEmailAddressExtension, emailAddressExtension) == KErrNone)
       
   109 		{
       
   110 		machineNameFile = CMtfTestActionUtilsConfigFileMachineName::NewLC(emailAddressExtension);
       
   111 		}
       
   112 	else
       
   113 		{
       
   114 		machineNameFile = CMtfTestActionUtilsConfigFileMachineName::NewLC(stringPtr);
       
   115 		}
       
   116 	
       
   117 	TPtrC8 machineName(machineNameFile->MachineName());
       
   118 
       
   119 	if(scriptFileParser->GetFieldAsString8(KCfgPopLoginName, string8Ptr) == KErrNone)
       
   120 	{
       
   121 		aPopSet.SetLoginNameL(string8Ptr);
       
   122 	}
       
   123 	else
       
   124 	{
       
   125 		aPopSet.SetLoginNameL(machineName);
       
   126 	}
       
   127 	
       
   128 	if(scriptFileParser->GetFieldAsString8(KCfgPopPassword, string8Ptr) == KErrNone)
       
   129 	{
       
   130 		aPopSet.SetPasswordL(string8Ptr);
       
   131 	}
       
   132 	else
       
   133 	{
       
   134 		aPopSet.SetPasswordL(machineName);
       
   135 	}
       
   136 
       
   137 	if(scriptFileParser->GetFieldAsInteger(KCfgPopMaxEmailSize, intValue) == KErrNone)
       
   138 	{
       
   139 		aPopSet.SetMaxEmailSize(intValue);
       
   140 	}
       
   141 	
       
   142 	if(scriptFileParser->GetFieldAsInteger(KCfgPopPort, intValue) == KErrNone)
       
   143 	{
       
   144 		aPopSet.SetPort(intValue);
       
   145 	}
       
   146 	
       
   147 	if(scriptFileParser->GetFieldAsInteger(KCfgPopInboxSynchronisationLimit, intValue) == KErrNone)
       
   148 	{
       
   149 		aPopSet.SetInboxSynchronisationLimit(intValue); // ??? should this be SetInboxSynchronisation?
       
   150 	}
       
   151 	
       
   152 	
       
   153 	if(scriptFileParser->GetFieldAsInteger(KCfgPopSecureSockets, intValue) == KErrNone)
       
   154 	{
       
   155 		aPopSet.SetSecureSockets((TBool)intValue);
       
   156 	}
       
   157 	
       
   158 	if(scriptFileParser->GetFieldAsInteger(KCfgPopSSLWrapper, intValue) == KErrNone)
       
   159 	{
       
   160 		aPopSet.SetSSLWrapper((TBool)intValue);
       
   161 	}
       
   162 	
       
   163 	if(scriptFileParser->GetFieldAsString(KCfgPopGetMailOptions, stringPtr) == KErrNone)
       
   164 	{
       
   165 		TPop3GetMailOptions options = ObtainValueParameterL<TPop3GetMailOptions>(aTestCase, stringPtr);
       
   166 		aPopSet.SetGetMailOptions(options);
       
   167 	}
       
   168 	
       
   169 	if(scriptFileParser->GetFieldAsInteger(KCfgPopPopulationLimit, intValue) == KErrNone)
       
   170 	{
       
   171 		aPopSet.SetPopulationLimitL(intValue);
       
   172 	}
       
   173 	
       
   174 	if(scriptFileParser->GetFieldAsInteger(KCfgPopAutoSendOnConnect, intValue) == KErrNone)
       
   175 	{	
       
   176 		aPopSet.SetAutoSendOnConnect((TBool) intValue);
       
   177 	}
       
   178 	
       
   179 	if(scriptFileParser->GetFieldAsInteger(KCfgPopDeleteEmailsWhenDisconnecting, intValue) == KErrNone)
       
   180 	{	
       
   181 		aPopSet.SetDeleteEmailsWhenDisconnecting((TBool) intValue);
       
   182 	}
       
   183 	
       
   184 	if(scriptFileParser->GetFieldAsInteger(KCfgPopAcknowledgeReceipts, intValue) == KErrNone)
       
   185 	{	
       
   186 		aPopSet.SetAcknowledgeReceipts((TBool) intValue);
       
   187 	}
       
   188 	
       
   189 	if(scriptFileParser->GetFieldAsInteger(KCfgPopDisconnectedUserMode, intValue) == KErrNone)
       
   190 	{	
       
   191 		aPopSet.SetDisconnectedUserMode((TBool) intValue);
       
   192 	}
       
   193 	
       
   194 	if(scriptFileParser->GetFieldAsInteger(KCfgPopAPOPEncryption, intValue) == KErrNone)
       
   195 	{	
       
   196 		aPopSet.SetApop((TBool) intValue);
       
   197 	}
       
   198 		
       
   199 	scriptFileParser->GetFieldAsString(KCfgPopIapList, stringPtr);
       
   200 	
       
   201 	ReadIAPAndAddL( aTestCase, scriptFileParser, KCfgPopIapList, aPopIapPref );
       
   202 	
       
   203 	
       
   204 	// SMTP settings
       
   205 	if(scriptFileParser->GetFieldAsString(KCfgSmtpServerAddress, stringPtr) == KErrNone)
       
   206 	{
       
   207 		aSmtpSet.SetServerAddressL(stringPtr);
       
   208 	}
       
   209 	
       
   210 	TPtrC emailAddr(machineNameFile->MachineNameEmail());
       
   211 	if(scriptFileParser->GetFieldAsString(KCfgSmtpEmailAddress, stringPtr) == KErrNone)
       
   212 	{
       
   213 		aSmtpSet.SetEmailAddressL(stringPtr);
       
   214 	}
       
   215 	else
       
   216 	{
       
   217 		aSmtpSet.SetEmailAddressL(emailAddr);
       
   218 	}
       
   219 	
       
   220 
       
   221 	if(scriptFileParser->GetFieldAsString(KCfgSmtpBodyEncoding, stringPtr) == KErrNone)
       
   222 	{
       
   223 		TMsgOutboxBodyEncoding setGetMailOptions = ObtainValueParameterL<TMsgOutboxBodyEncoding>(aTestCase, stringPtr);
       
   224 		aSmtpSet.SetBodyEncoding(setGetMailOptions);
       
   225 	}
       
   226 	
       
   227 	if(scriptFileParser->GetFieldAsString(KCfgSmtpReceiptAddress, stringPtr) == KErrNone)
       
   228 	{
       
   229 		aSmtpSet.SetReceiptAddressL(stringPtr);
       
   230 	}
       
   231 	else
       
   232 	{
       
   233 		aSmtpSet.SetReceiptAddressL(emailAddr);
       
   234 	}
       
   235 	
       
   236 
       
   237 	
       
   238 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpRequestReceipts, intValue) == KErrNone)
       
   239 	{		
       
   240 		aSmtpSet.SetRequestReceipts( (TBool) intValue );
       
   241 	}
       
   242 	
       
   243 	if(scriptFileParser->GetFieldAsString(KCfgSmtpSendMessageOption, stringPtr) == KErrNone)
       
   244 	{
       
   245 		TImSMTPSendMessageOption setSendMessageOption = ObtainValueParameterL<TImSMTPSendMessageOption>(aTestCase, stringPtr);
       
   246 		aSmtpSet.SetSendMessageOption(setSendMessageOption);
       
   247 	}
       
   248 	
       
   249 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetPort, intValue) == KErrNone)
       
   250 	{
       
   251 		aSmtpSet.SetPort(intValue);
       
   252 	}
       
   253 	
       
   254 	if(scriptFileParser->GetFieldAsString(KCfgSmtpEmailAlias, stringPtr) == KErrNone)
       
   255 	{
       
   256 		aSmtpSet.SetEmailAliasL(stringPtr);
       
   257 	}
       
   258 	
       
   259 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpDefaultMsgCharSet, intValue) == KErrNone)
       
   260 	{
       
   261 		TUid tmp = { intValue };
       
   262 		aSmtpSet.SetDefaultMsgCharSet( tmp );
       
   263 	}
       
   264 	
       
   265 	
       
   266 	if(scriptFileParser->GetFieldAsString(KCfgSmtpSetReplyToAddress, stringPtr) == KErrNone)
       
   267 	{
       
   268 		aSmtpSet.SetReplyToAddressL(stringPtr);
       
   269 	}
       
   270 	else
       
   271 	{
       
   272 		aSmtpSet.SetReplyToAddressL(emailAddr);
       
   273 	}
       
   274 	
       
   275 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetAddVCardToEmail, intValue) == KErrNone)
       
   276 	{		
       
   277 		aSmtpSet.SetAddVCardToEmail( (TBool) intValue );
       
   278 	}
       
   279 	
       
   280 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetAddSignatureToEmail, intValue) == KErrNone)
       
   281 	{		
       
   282 		aSmtpSet.SetAddSignatureToEmail( (TBool) intValue );
       
   283 	}
       
   284 	
       
   285 	if(scriptFileParser->GetFieldAsString(KCfgSmtpSetSendCopyToSelf, stringPtr) == KErrNone)
       
   286 	{
       
   287 		TImSMTPSendCopyToSelf setSMTPSendCopyToSelf = ObtainValueParameterL<TImSMTPSendCopyToSelf>(aTestCase, stringPtr);
       
   288 		aSmtpSet.SetSendCopyToSelf(setSMTPSendCopyToSelf);
       
   289 	}
       
   290 	
       
   291 	if(scriptFileParser->GetFieldAsString8(KCfgSmtpSetLoginName, string8Ptr) == KErrNone)
       
   292 	{
       
   293 		aSmtpSet.SetLoginNameL(string8Ptr);
       
   294 	}
       
   295 	else
       
   296 	{
       
   297 		aSmtpSet.SetLoginNameL(machineName);
       
   298 	}
       
   299 
       
   300 	if(scriptFileParser->GetFieldAsString8(KCfgSmtpSetPassword, string8Ptr) == KErrNone)
       
   301 	{
       
   302 		aSmtpSet.SetPasswordL(string8Ptr);
       
   303 	}
       
   304 	else
       
   305 	{
       
   306 		aSmtpSet.SetPasswordL(machineName);
       
   307 	}
       
   308 		
       
   309 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetSMTPAuth, intValue) == KErrNone)
       
   310 	{		
       
   311 		aSmtpSet.SetSMTPAuth( (TBool) intValue );
       
   312 	}
       
   313 
       
   314 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSetInboxLoginDetails, intValue) == KErrNone)
       
   315 	{		
       
   316 		aSmtpSet.SetInboxLoginDetails( (TBool) intValue );
       
   317 	}
       
   318 
       
   319 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSecureSockets, intValue) == KErrNone)
       
   320 	{		
       
   321 		aSmtpSet.SetSecureSockets( (TBool) intValue );
       
   322 	}
       
   323 	
       
   324 	if(scriptFileParser->GetFieldAsInteger(KCfgSmtpSSLWrapper, intValue) == KErrNone)
       
   325 	{		
       
   326 		aSmtpSet.SetSSLWrapper( (TBool) intValue );
       
   327 	}
       
   328 	
       
   329 	ReadIAPAndAddL( aTestCase, scriptFileParser, KCfgSmtpIapList, aSmtpIapPref );
       
   330 	
       
   331 	//Pop and destroy scriptfileParser and machineNameFile	
       
   332 	CleanupStack::PopAndDestroy(2,scriptFileParser);	
       
   333 }
       
   334 
       
   335 void CMtfTestActionUtilsPopScripts::ReadIAPAndAddL( CMtfTestCase& aTestCase, 
       
   336 	CMtfTestActionUtilsConfigFileParser* aScriptFileParser , 
       
   337 	const TDesC& aParamListName , CImIAPPreferences& aIapPref )
       
   338 {
       
   339 	TPtrC stringPtr; 	
       
   340 	TPtrC baseString; 
       
   341 	
       
   342 	if( aScriptFileParser->GetFieldAsString(aParamListName, stringPtr ) == KErrNone )
       
   343 	{
       
   344 		
       
   345 		TInt start=0;
       
   346 		TInt end=stringPtr.Length();
       
   347 		
       
   348 		while ( GetString( stringPtr , start, end , baseString ) )
       
   349 		{
       
   350 			_ReadIAPAndAddL( aTestCase, aScriptFileParser, baseString, aIapPref );
       
   351 		}
       
   352 	}		
       
   353 }
       
   354 
       
   355 TBool CMtfTestActionUtilsPopScripts::GetString( const TDesC& aStringPtr , TInt& aStart, TInt aEnd , TPtrC& aBaseString )
       
   356 {
       
   357 	TBool ret=EFalse;
       
   358 	
       
   359 	if (aStart==aEnd)
       
   360 	{
       
   361 		return EFalse;				
       
   362 	}
       
   363 	
       
   364 	TInt currPos=aStart;
       
   365 	
       
   366 
       
   367 	// strip out any starting spaces.
       
   368 	while (currPos<aEnd )
       
   369 	{
       
   370 		if ( aStringPtr[currPos] == ' ' || aStringPtr[currPos] == '\t' )
       
   371 		{			
       
   372 			currPos++;	
       
   373 		}
       
   374 		else
       
   375 		{			
       
   376 			break;	
       
   377 		}
       
   378 	}
       
   379 	TInt startTmp=currPos;
       
   380 	
       
   381 	while (currPos<aEnd )
       
   382 	{
       
   383 		if ( aStringPtr[currPos] == ' ' || aStringPtr[currPos] == '\t' )
       
   384 		{			
       
   385 			break;
       
   386 		}
       
   387 		else
       
   388 		{
       
   389 			currPos++;
       
   390 			ret=ETrue;
       
   391 		}
       
   392 	}
       
   393 	
       
   394 	if (ret)
       
   395 	{	// We have a string.
       
   396 		aBaseString.Set( aStringPtr.Mid( startTmp, currPos-startTmp) ); 
       
   397 	}
       
   398 		
       
   399 	aStart=currPos;
       
   400 	
       
   401 	return ret;
       
   402 }
       
   403 
       
   404 
       
   405 void CMtfTestActionUtilsPopScripts::_ReadIAPAndAddL( CMtfTestCase& aTestCase, 
       
   406 	CMtfTestActionUtilsConfigFileParser* aScriptFileParser , 
       
   407 	const TDesC& aFieldName , CImIAPPreferences& aIapPref )
       
   408 {
       
   409 	
       
   410 	TPtrC stringPtr; 
       
   411 	TInt intTmp;
       
   412 	
       
   413 	TImIAPChoice iapChoice;
       
   414 	iapChoice.iIAP = 0;
       
   415 	iapChoice.iDialogPref = ECommDbDialogPrefUnknown;
       
   416 	
       
   417 	TInt index=0;
       
   418 	TBool modified=EFalse;
       
   419 		
       
   420 	HBufC* buf = HBufC::NewLC(100);
       
   421 			
       
   422 	buf->Des() = aFieldName;
       
   423 	buf->Des().Append( _L("_PopIAP") );
       
   424 	
       
   425 			
       
   426 	if(aScriptFileParser->GetFieldAsInteger(buf->Des(), intTmp) == KErrNone)
       
   427 	{
       
   428 		iapChoice.iIAP = intTmp;
       
   429 		modified=ETrue;
       
   430 	}
       
   431 	
       
   432 
       
   433 	buf->Des() = aFieldName;
       
   434 	buf->Des().Append( _L("_PopCommDbDialogPref") );
       
   435 	if(aScriptFileParser->GetFieldAsString(buf->Des(), stringPtr) == KErrNone)
       
   436 	{
       
   437 		TCommDbDialogPref setCommDbDialogPref = ObtainValueParameterL<TCommDbDialogPref>(aTestCase, stringPtr);
       
   438 		iapChoice.iDialogPref= setCommDbDialogPref;
       
   439 		modified=ETrue;
       
   440 	}
       
   441 
       
   442 	
       
   443 	buf->Des() = aFieldName;
       
   444 	buf->Des().Append( _L("_PopIAPIndex") );
       
   445 	if(aScriptFileParser->GetFieldAsInteger(buf->Des(), intTmp) == KErrNone)
       
   446 	{
       
   447 		index = intTmp;
       
   448 		modified=ETrue;
       
   449 	}
       
   450 	
       
   451 	if (modified)
       
   452 	{	// Note only want to set the values if they are specified. Otherwise leave well alone.
       
   453 		// Really should specify iapChoice.iIAP and iapChoice.iDialogPref at the same time.
       
   454 		aIapPref.AddIAPL(iapChoice ,index );
       
   455 	}
       
   456 
       
   457 	CleanupStack::PopAndDestroy(buf);
       
   458 }
       
   459