|
1 // Copyright (c) 2007-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 // CreateSmtpMobilityAccount |
|
16 // [Parameters] |
|
17 // EmailAddress: Email address for mobility account / linked SMTP account |
|
18 // ConfigFileName: Configuration file name to read for account settings |
|
19 // Linked: Create a linked mobility account |
|
20 // AP ID: Access point identifier (eg. IAP number) |
|
21 // [TestStep Description] |
|
22 // Creates a mobility account under the default SMTP account |
|
23 // If linked account option is chosen, also creates a new SMTP account |
|
24 // and links the mobility account to it. |
|
25 // |
|
26 // |
|
27 |
|
28 #include "T_CreateSmtpMobilityAccount.h" |
|
29 #include <t_utilsreademailsettingsfromconfigfile.h> |
|
30 #include <cemailaccounts.h> |
|
31 #include <iapprefs.h> |
|
32 #include <smtpset.h> |
|
33 #include <imapset.h> |
|
34 #include <cimsmtpmobilitysettings.h> |
|
35 |
|
36 _LIT(KMobilityAccountName, "Mobility Account"); |
|
37 _LIT(KLinkedAccountName, "Linked Account"); |
|
38 |
|
39 _LIT(KEmailAddress, "EmailAddress"); |
|
40 _LIT(KLinked, "Linked"); |
|
41 _LIT(KConfigFileName, "ConfigFileName"); |
|
42 _LIT(KAccessPoint, "AccessPoint"); |
|
43 |
|
44 /** |
|
45 Function : NewL() |
|
46 Description : Static factory constructor. |
|
47 |
|
48 @param aSharedDataSMTP |
|
49 |
|
50 @return A pointer to the newly created CT_MsgCreateSmtpMobilityAccount object. |
|
51 */ |
|
52 CT_MsgCreateSmtpMobilityAccount* CT_MsgCreateSmtpMobilityAccount::NewL(CT_MsgSharedDataSmtp& aSharedDataSMTP) |
|
53 { |
|
54 CT_MsgCreateSmtpMobilityAccount* self = new(ELeave) CT_MsgCreateSmtpMobilityAccount(aSharedDataSMTP); |
|
55 return self; |
|
56 } |
|
57 |
|
58 /** |
|
59 Function : CT_MsgCreateSmtpMobilityAccount |
|
60 Description : Constructor |
|
61 @return : N/A |
|
62 */ |
|
63 CT_MsgCreateSmtpMobilityAccount::CT_MsgCreateSmtpMobilityAccount(CT_MsgSharedDataSmtp& aSharedDataSMTP) |
|
64 : CT_MsgSyncStepSMTP(aSharedDataSMTP) |
|
65 { |
|
66 SetTestStepName(KCreateSmtpMobilityAccount); |
|
67 } |
|
68 |
|
69 /** |
|
70 Function : doTestStepL |
|
71 Description : Creates SMTP mobility account |
|
72 @return : TVerdict - Test step result |
|
73 */ |
|
74 TVerdict CT_MsgCreateSmtpMobilityAccount::doTestStepL() |
|
75 { |
|
76 INFO_PRINTF1(_L("Test Step: Create Smtp Mobility Account")); |
|
77 |
|
78 TPtrC emailAddress; |
|
79 if(!GetStringFromConfig(ConfigSection(), KEmailAddress, emailAddress)) |
|
80 { |
|
81 ERR_PRINTF1(_L("Email address is not specified")); |
|
82 SetTestStepResult(EFail); |
|
83 return TestStepResult(); |
|
84 } |
|
85 |
|
86 TPtrC configFileName; |
|
87 if(!GetStringFromConfig(ConfigSection(), KConfigFileName, configFileName)) |
|
88 { |
|
89 ERR_PRINTF1(_L("Configuration file path is not specified")); |
|
90 SetTestStepResult(EFail); |
|
91 return TestStepResult(); |
|
92 } |
|
93 |
|
94 TBool linked = EFalse; |
|
95 GetBoolFromConfig(ConfigSection(), KLinked, linked); |
|
96 |
|
97 TInt accessPoint = 0; |
|
98 GetIntFromConfig(ConfigSection(), KAccessPoint, accessPoint); |
|
99 |
|
100 CEmailAccounts* emailAccounts = CEmailAccounts::NewLC(); |
|
101 |
|
102 CImIAPPreferences* smtpIapPrefs = CImIAPPreferences::NewLC(); |
|
103 CImSmtpSettings* smtpSettings = new (ELeave) CImSmtpSettings; |
|
104 CleanupStack::PushL(smtpSettings); |
|
105 |
|
106 if (linked || accessPoint == 0) |
|
107 { |
|
108 emailAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *smtpIapPrefs); |
|
109 |
|
110 if( configFileName.CompareF( _L("none") ) != 0 ) |
|
111 { |
|
112 TRAPD(err, CT_MsgUtilsReadEmailSettingsFromConfigFile::ReadSmtpSettingsFromConfigurationFileL(configFileName, *smtpSettings, *smtpIapPrefs)); |
|
113 |
|
114 if (err == KErrNone) |
|
115 { |
|
116 if (accessPoint == 0) |
|
117 { |
|
118 if (smtpIapPrefs->NumberOfIAPs() > 0) |
|
119 { |
|
120 TImIAPChoice iapChoice = smtpIapPrefs->IAPPreference(0); |
|
121 accessPoint = iapChoice.iIAP; |
|
122 } |
|
123 } |
|
124 } |
|
125 else |
|
126 { |
|
127 ERR_PRINTF2(_L("Failure while setting the SMTP setting parameters, failed with error %d"), err); |
|
128 SetTestStepResult(EFail); |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 RArrayIAP iapList; |
|
134 CleanupClosePushL(iapList); |
|
135 if (TestStepResult() == EPass) |
|
136 { |
|
137 if (accessPoint != 0) |
|
138 { |
|
139 iapList.AppendL(accessPoint); |
|
140 } |
|
141 else |
|
142 { |
|
143 ERR_PRINTF1(_L("Access point not specified")); |
|
144 SetTestStepResult(EFail); |
|
145 } |
|
146 } |
|
147 |
|
148 TSmtpAccount parentSmtpAccount; |
|
149 |
|
150 if (TestStepResult() == EPass) |
|
151 { |
|
152 if (emailAccounts->DefaultSmtpAccountL(parentSmtpAccount) != KErrNone) |
|
153 { |
|
154 ERR_PRINTF1(_L("Default SMTP account not found")); |
|
155 SetTestStepResult(EFail); |
|
156 } |
|
157 } |
|
158 |
|
159 if (TestStepResult() == EPass) |
|
160 { |
|
161 if (linked) |
|
162 { |
|
163 /* Creates objects requried for IMAP account */ |
|
164 CImIAPPreferences* imapIapPrefs = CImIAPPreferences::NewLC(); |
|
165 CImImap4Settings* imapSettings = new (ELeave) CImImap4Settings; |
|
166 CleanupStack::PushL(imapSettings); |
|
167 emailAccounts->PopulateDefaultImapSettingsL(*imapSettings, *imapIapPrefs); |
|
168 |
|
169 if( configFileName.CompareF( _L("none") ) != 0 ) |
|
170 { |
|
171 TRAPD(err, CT_MsgUtilsReadEmailSettingsFromConfigFile::ReadImapSettingsFromConfigurationFileL(configFileName, *imapSettings, *imapIapPrefs)); |
|
172 |
|
173 if (err != KErrNone) |
|
174 { |
|
175 ERR_PRINTF2(_L("Failure while setting the IMAP setting parameters, failed with error %d"), err); |
|
176 SetTestStepResult(EFail); |
|
177 } |
|
178 } |
|
179 |
|
180 if( TestStepResult() == EPass ) |
|
181 { |
|
182 smtpSettings->SetEmailAddressL(emailAddress); |
|
183 |
|
184 /* Creates the IMAP account for the name specified and for the settings objects */ |
|
185 TImapAccount linkedImapAccount = emailAccounts->CreateImapAccountL(KLinkedAccountName, *imapSettings, *imapIapPrefs, EFalse); |
|
186 |
|
187 /* Creates the SMTP account for the name specified and for the settings objects */ |
|
188 TSmtpAccount linkedSmtpAccount = emailAccounts->CreateSmtpAccountL(linkedImapAccount, *smtpSettings, *smtpIapPrefs, EFalse); |
|
189 |
|
190 emailAccounts->CreateSmtpMobilityAccountL(KMobilityAccountName, iapList, parentSmtpAccount, linkedSmtpAccount, EFalse); |
|
191 } |
|
192 CleanupStack::PopAndDestroy(2, imapIapPrefs); |
|
193 } |
|
194 else |
|
195 { |
|
196 CImSmtpMobilitySettings* mobilitySettings = CImSmtpMobilitySettings::NewLC(); |
|
197 emailAccounts->PopulateDefaultSmtpMobilitySettingsL(*mobilitySettings); |
|
198 mobilitySettings->SetEmailAddressL(emailAddress); |
|
199 emailAccounts->CreateSmtpMobilityAccountL(KMobilityAccountName, iapList, parentSmtpAccount, *mobilitySettings, EFalse); |
|
200 CleanupStack::PopAndDestroy(mobilitySettings); |
|
201 } |
|
202 } |
|
203 |
|
204 CleanupStack::PopAndDestroy(4, emailAccounts); |
|
205 |
|
206 return TestStepResult(); |
|
207 } |