email/email/smtp/src/T_ModifySmtpSettings.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // [TestStep Name]
       
    15 // ModifySmtpSettings
       
    16 // [Paramaters]
       
    17 // SmtpAccountName			:Name of the Smtp account
       
    18 // SmtpConfigFileName		:Config file from which the Smtp account settings are read 
       
    19 // ModifySmtpSettings Test Step is intended to modify existing settings and save to CenRep 
       
    20 // for the specified SMTP account Id
       
    21 // 
       
    22 //
       
    23 
       
    24 /* user includes */
       
    25 #include "T_ModifySmtpSettings.h"
       
    26 #include <t_utilsreademailsettingsfromconfigfile.h>
       
    27 #include <t_utilscentralrepository.h>
       
    28 
       
    29 /* epoc inlcudes */
       
    30 #include <cemailaccounts.h>
       
    31 #include <smtpset.h>
       
    32 #include <iapprefs.h>
       
    33 
       
    34 /* Literals used */
       
    35 _LIT(KSmtpAccountName,"SmtpAccountName");
       
    36 _LIT(KSmtpConfigFileName,"SmtpConfigFileName");
       
    37 
       
    38 /**
       
    39   Function : CT_MsgModifySmtpSettings
       
    40   Description : Constructor
       
    41   @param : aSharedDataSMTP Reference to CT_MsgSharedDataSmtp
       
    42   @return : N/A
       
    43 */
       
    44 CT_MsgModifySmtpSettings::CT_MsgModifySmtpSettings(CT_MsgSharedDataSmtp& aSharedDataSMTP)
       
    45 :	CT_MsgSyncStepSMTP(aSharedDataSMTP)
       
    46 	{
       
    47 	SetTestStepName(KModifySmtpSettings);
       
    48 	}
       
    49 	
       
    50 /**
       
    51   Function : ~CT_MsgModifySmtpSettings
       
    52   Description : Destructor
       
    53   @return : N/A
       
    54 */
       
    55 CT_MsgModifySmtpSettings::~CT_MsgModifySmtpSettings()
       
    56 	{
       
    57 	}
       
    58 
       
    59 /**
       
    60   Function : doTestStepL
       
    61   Description : Reads the Smtp account name and config file name from the .ini file
       
    62 				and it then modifies the account with the settings read from the config file.
       
    63   @return : TVerdict - Test step result
       
    64   @leave  : KMsvNullIndexEntryId	Invalid SMTP account name specified	
       
    65 */
       
    66 TVerdict CT_MsgModifySmtpSettings::doTestStepL()
       
    67 	{
       
    68 	INFO_PRINTF1(_L("Test Step: ModifySmtpSettings"));
       
    69 	// Read the SMTP account name from the ini file
       
    70 	TPtrC smtpAccountName;
       
    71 	if(!GetStringFromConfig(ConfigSection(), KSmtpAccountName, smtpAccountName))
       
    72 		{
       
    73 		ERR_PRINTF1(_L("SMTP account name is not specified"));
       
    74 		SetTestStepResult(EFail);
       
    75 		}
       
    76 	else
       
    77 		{
       
    78 		// Read the SMTP Config file name from the ini file
       
    79 		TPtrC configFileName;
       
    80 		if(!GetStringFromConfig(ConfigSection(), KSmtpConfigFileName, configFileName))
       
    81 			{
       
    82 			ERR_PRINTF1(_L("Configuration file path is not specified"));
       
    83 			SetTestStepResult(EFail);
       
    84 			}
       
    85 		else
       
    86 			{
       
    87 			// Retrieving the SMTP service Id for the given SMTP account
       
    88 			TMsvId smtpServiceId = CT_MsgUtilsCentralRepository::GetSmtpServiceIdL((TDes&)smtpAccountName);
       
    89 			INFO_PRINTF2(_L("SMTP service Id is %d"),smtpServiceId);
       
    90 			
       
    91 			if(smtpServiceId == KMsvNullIndexEntryId)
       
    92 				{
       
    93 				ERR_PRINTF1(_L("Invalid SMTP account name specified"));
       
    94 				SetTestStepResult(EFail);
       
    95 				}
       
    96 			// Creates the settings object
       
    97 			else
       
    98 				{
       
    99 				CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();
       
   100 
       
   101 				CImSmtpSettings* smtpSettings = new(ELeave) CImSmtpSettings();
       
   102 				CleanupStack::PushL(smtpSettings);
       
   103 				
       
   104 				CImIAPPreferences* smtpIapPrefs = CImIAPPreferences::NewLC();
       
   105 
       
   106 				// Loads the settings for the account with the current settings
       
   107 				TSmtpAccount smtpAccount;
       
   108 				emailAccounts->GetSmtpAccountL(smtpServiceId, smtpAccount);
       
   109 				emailAccounts->LoadSmtpSettingsL(smtpAccount, *smtpSettings);
       
   110 				emailAccounts->LoadSmtpIapSettingsL(smtpAccount, *smtpIapPrefs);
       
   111 
       
   112 				// Reads the settings from the config file
       
   113 				TRAPD(err, CT_MsgUtilsReadEmailSettingsFromConfigFile::ReadSmtpSettingsFromConfigurationFileL(configFileName, *smtpSettings, *smtpIapPrefs));
       
   114 				if(err)
       
   115 					{	
       
   116 					ERR_PRINTF2(_L("Failure while setting the SMTP setting parameters, failed with error %d"), err);
       
   117 					SetTestStepError(err);															  
       
   118 					}
       
   119 				else
       
   120 					{
       
   121 					// Saves the new settings
       
   122 					emailAccounts->SaveSmtpSettingsL(smtpAccount, *smtpSettings);
       
   123 					emailAccounts->SaveSmtpIapSettingsL(smtpAccount, *smtpIapPrefs);
       
   124 					}
       
   125 				CleanupStack::PopAndDestroy(3, emailAccounts);// smtpIapPrefs,smtpSettings,emailAccounts
       
   126 				}
       
   127 			}
       
   128 		}
       
   129 	return TestStepResult();
       
   130 	}