|
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 "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 // __ACTION_INFO_BEGIN__ |
|
15 // [Action Name] |
|
16 // VerifyReplyToAddress |
|
17 // [Action Parameters] |
|
18 // 0) CMsvSession& session <input> :Reference to the session. |
|
19 // 1) CMsvEntrySelection& SentMailSelection <input> : Reference to the sent mail selection. |
|
20 // 2) CMsvEntrySelection& RecvMailSelection <input> : Reference to the received mail selection. |
|
21 // 3) TInt Number of mails under test. |
|
22 // 4) HBufC& Full Epoc32 file path of sample email txt file used. |
|
23 // 5) TInt Whether the sample email contains a Reply-To address field or not? (1 = ETrue, 0 = EFalse) |
|
24 // [Action Description] |
|
25 // Implements the action to compare the Reply-To address set in header of email from txt file to |
|
26 // that of the email actual sent as stored in the Message store as a TMsvEntry object. |
|
27 // [APIs Used] |
|
28 // __ACTION_INFO_END__ |
|
29 // |
|
30 // |
|
31 |
|
32 /** |
|
33 @file CMtfTestActionVerifyReplyToAddress.cpp |
|
34 */ |
|
35 |
|
36 #include <e32std.h> |
|
37 #include <txtrich.h> |
|
38 #include <mtclreg.h> |
|
39 #include <imcm.rsg> |
|
40 |
|
41 #include <msvstore.h> |
|
42 #include "CMtfTestActionVerifyReplyToAddress.h" |
|
43 #include <cemailaccounts.h> |
|
44 #include <iapprefs.h> |
|
45 #include "CMtfTestActionUtilsPopScripts.h" |
|
46 |
|
47 #include "CMtfTestActionUtils.h" |
|
48 #include "CMtfTestCase.h" |
|
49 #include "CMtfTestActionParameters.h" |
|
50 #include "MtfTestActionUtilsUser.h" |
|
51 #include "TMtfTestParameterType.h" |
|
52 #include "CPop3MailInfo.h" |
|
53 |
|
54 // Expected Reply-To field to be used in sample emails |
|
55 _LIT8(KReplyToField, "Reply-To: matthewf@msexchange2k.closedtest.intra\r\n"); |
|
56 |
|
57 _LIT(KSettingsFile, "c:\\msgtest\\TestFramework\\Configurations\\EmailSettings\\Pop3Tests-lon-cn-exchng2k.txt"); |
|
58 |
|
59 #ifdef _UNICODE |
|
60 _LIT(KSmtpEmailAddressAndAliasFmtStr,"\"%S\" <%S>"); |
|
61 #else |
|
62 _LIT8(KSmtpEmailAddressAndAliasFmtStr,"\"%S\" <%S>"); |
|
63 #endif |
|
64 |
|
65 /** |
|
66 Function : NewL |
|
67 Description : Standard symbian 2 phase constructor |
|
68 @internalTechnology |
|
69 @param aMtfTestCase - CMtfTestCase test case reference for base class constructor |
|
70 @param aActionParameters - pointer to the parameters for this test action |
|
71 @return A CMtfTestAction pointer to the newly created CMtfTestActionVerifyReplyToAddress object |
|
72 @precondition none |
|
73 @postcondition none |
|
74 */ |
|
75 CMtfTestAction* CMtfTestActionVerifyReplyToAddress::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters) |
|
76 { |
|
77 CMtfTestActionVerifyReplyToAddress* self = new (ELeave) CMtfTestActionVerifyReplyToAddress(aTestCase); |
|
78 CleanupStack::PushL(self); |
|
79 self->ConstructL(aActionParameters); |
|
80 CleanupStack::Pop(self); |
|
81 return self; |
|
82 } |
|
83 |
|
84 /** |
|
85 Function : CMtfTestActionVerifyReplyToAddress constructor |
|
86 Description : Private constructor - must not leave |
|
87 @internalTechnology |
|
88 @param aTestCase - CMtfTestCase reference for the base class constructor |
|
89 @return N/A |
|
90 @precondition none |
|
91 @postcondition none |
|
92 */ |
|
93 CMtfTestActionVerifyReplyToAddress::CMtfTestActionVerifyReplyToAddress(CMtfTestCase& aTestCase) |
|
94 : CMtfSynchronousTestAction(aTestCase), iSession(NULL), iSentSelectionList(NULL), iInboxSelectionList(NULL) |
|
95 { |
|
96 } |
|
97 |
|
98 /** |
|
99 Function : CMtfTestActionVerifyReplyToAddress destructor |
|
100 Description : Destructor |
|
101 @internalTechnology |
|
102 @param N/A |
|
103 @return N/A |
|
104 @precondition none |
|
105 @postcondition none |
|
106 */ |
|
107 CMtfTestActionVerifyReplyToAddress::~CMtfTestActionVerifyReplyToAddress() |
|
108 { |
|
109 } |
|
110 |
|
111 /** |
|
112 Function : LoadParametersL |
|
113 Description : Loads the test action parameters |
|
114 @internalTechnology |
|
115 @param none |
|
116 @return ETrue if parameters loaded Efalse on failure |
|
117 @precondition none |
|
118 @postcondition Upon failure TestCase status is EFail |
|
119 */ |
|
120 TBool CMtfTestActionVerifyReplyToAddress::LoadParametersL() |
|
121 { |
|
122 iSession = ObtainParameterReferenceL<CMsvSession> (TestCase(),ActionParameters().Parameter(0)); |
|
123 if(! iSession) |
|
124 { |
|
125 TestCase().ERR_PRINTF1(_L("Invalid session object")); |
|
126 TestCase().SetTestStepResult(EFail); |
|
127 return EFalse; |
|
128 } |
|
129 iSentSelectionList = ObtainParameterReferenceL<CMsvEntrySelection> (TestCase(), ActionParameters().Parameter(1)); |
|
130 if(! iSentSelectionList) |
|
131 { |
|
132 TestCase().ERR_PRINTF1(_L("Invalid sentSelectionList")); |
|
133 TestCase().SetTestStepResult(EFail); |
|
134 return EFalse; |
|
135 } |
|
136 iInboxSelectionList = ObtainParameterReferenceL<CMsvEntrySelection> (TestCase(), ActionParameters().Parameter(2)); |
|
137 if(! iInboxSelectionList) |
|
138 { |
|
139 TestCase().ERR_PRINTF1(_L("Invalid inboxSelectionList")); |
|
140 TestCase().SetTestStepResult(EFail); |
|
141 return EFalse; |
|
142 } |
|
143 |
|
144 if(iInboxSelectionList->Count() != iSentSelectionList->Count()) |
|
145 { |
|
146 TestCase().ERR_PRINTF3(_L("iInboxSelectionList->Count(%d) != iSentSelectionList->Count(%d)"), |
|
147 iInboxSelectionList->Count(), iSentSelectionList->Count() ); |
|
148 TestCase().SetTestStepResult(EFail); |
|
149 return EFalse; |
|
150 } |
|
151 |
|
152 TInt numTests = ObtainValueParameterL<TInt> (TestCase(),ActionParameters().Parameter(3)); |
|
153 if(numTests != iInboxSelectionList->Count()) |
|
154 { |
|
155 TestCase().ERR_PRINTF2(_L("NumTests != iInboxSelectionList->Count(%d)"), iInboxSelectionList->Count()); |
|
156 TestCase().SetTestStepResult(EFail); |
|
157 return EFalse; |
|
158 } |
|
159 |
|
160 iEmailFilePath = ObtainParameterReferenceL<HBufC> (TestCase(),ActionParameters().Parameter(4)); |
|
161 TPtr ptrEmailFilePath = iEmailFilePath->Des(); |
|
162 TestCase().INFO_PRINTF2(_L("Email path: %S"), &ptrEmailFilePath); |
|
163 |
|
164 iReplyToAddress = ObtainValueParameterL<TInt> (TestCase(),ActionParameters().Parameter(5)); |
|
165 TestCase().INFO_PRINTF2(_L("ReplyToField flag: %d"), iReplyToAddress); |
|
166 |
|
167 return ETrue; |
|
168 } |
|
169 |
|
170 /** |
|
171 Function : ExecuteActionL |
|
172 Description : Test framework entry point for CMtfTestActionVerifyReplyToAddress test action |
|
173 @internalTechnology |
|
174 @param none |
|
175 @return void |
|
176 @precondition none |
|
177 @postcondition TestCase status EPass if tests passed otherwise EFail |
|
178 */ |
|
179 void CMtfTestActionVerifyReplyToAddress::ExecuteActionL() |
|
180 { |
|
181 TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionVerifyReplyToAddress); |
|
182 if(LoadParametersL()) |
|
183 { |
|
184 User::LeaveIfError(iFs.Connect()); |
|
185 CleanupClosePushL(iFs); |
|
186 // Normally do not push an object that is a data member of another object. |
|
187 // But in this case we want to close early if we get a leave. |
|
188 // Otherwise the iFs would be open till the thread had begun to die. |
|
189 |
|
190 if(TestCase().TestStepResult() == EPass) |
|
191 { |
|
192 CMsvEntry* recvMsvEntry = iSession->GetEntryL(KMsvRootIndexEntryId); |
|
193 CleanupStack::PushL(recvMsvEntry); |
|
194 CMsvEntry* sentMsvEntry = iSession->GetEntryL(KMsvRootIndexEntryId); |
|
195 CleanupStack::PushL(sentMsvEntry); |
|
196 |
|
197 for(TInt i=0; i<iInboxSelectionList->Count(); i++) |
|
198 { |
|
199 recvMsvEntry->SetEntryL(iInboxSelectionList->At(i)); |
|
200 TMsvEntry recvEntry = recvMsvEntry->Entry(); |
|
201 for(TInt j=0; j<iSentSelectionList->Count(); j++) |
|
202 { |
|
203 sentMsvEntry->SetEntryL(iSentSelectionList->At(j)); |
|
204 TMsvEntry sentEntry = sentMsvEntry->Entry(); |
|
205 if(recvEntry.iDescription.Compare(sentEntry.iDescription) == 0) |
|
206 { |
|
207 if(! ReplyToHeaderFieldCompareL(sentEntry, iEmailFilePath->Des(), iSession)) |
|
208 { |
|
209 TestCase().INFO_PRINTF2(_L("Test %d failed"), j+1); |
|
210 TestCase().SetTestStepResult(EFail); |
|
211 } |
|
212 } |
|
213 } |
|
214 } |
|
215 CleanupStack::PopAndDestroy(2, recvMsvEntry); // recvMsvEntry, sentMsvEntry |
|
216 } |
|
217 CleanupStack::PopAndDestroy(&iFs); |
|
218 } |
|
219 |
|
220 TestCase().INFO_PRINTF1( _L("Test Action CMtfTestActionVerifyEmail Completed") ); |
|
221 TestCase().ActionCompletedL(*this); |
|
222 } |
|
223 |
|
224 TBool CMtfTestActionVerifyReplyToAddress::ReplyToHeaderFieldCompareL(TMsvEntry& aSentEntry, const TDesC& aFileName, CMsvSession* aSession) |
|
225 { |
|
226 TBool ret = ETrue; |
|
227 |
|
228 // If Reply-To address exists in email header then... |
|
229 if(iReplyToAddress) |
|
230 { |
|
231 // Read Reply-To field from sample email txt file |
|
232 RFileReadStream rdStream; |
|
233 User::LeaveIfError(rdStream.Open(iFs, aFileName, EFileRead|EFileStreamText)); |
|
234 |
|
235 if(IsEofL(rdStream)) |
|
236 { |
|
237 ret = EFalse; |
|
238 return ret; |
|
239 } |
|
240 |
|
241 TBuf8<256> line; |
|
242 TChar char_LF('\n'); |
|
243 line.Zero(); |
|
244 |
|
245 do |
|
246 { |
|
247 rdStream.ReadL(line, char_LF); |
|
248 if(line.Compare(KReplyToField)==0) |
|
249 { |
|
250 // Break from loop if expected Reply-To field found |
|
251 break; |
|
252 } |
|
253 } |
|
254 while(!IsEofL(rdStream)); |
|
255 |
|
256 rdStream.Close(); // End of reading stream |
|
257 |
|
258 // aSentEntry - Identifier of the original sent email identified by TMsvEntry |
|
259 CMsvEntry* msvEntry = aSession->GetEntryL(aSentEntry.Id()); |
|
260 CleanupStack::PushL(msvEntry); |
|
261 |
|
262 msvEntry->SetEntryL(aSentEntry.Id()); |
|
263 |
|
264 CMsvStore* store = msvEntry->ReadStoreL(); |
|
265 CleanupStack::PushL(store); |
|
266 |
|
267 CImHeader* header = CImHeader::NewLC(); |
|
268 |
|
269 header->RestoreL(*store); |
|
270 // Read Reply-To address from email header |
|
271 TPtrC line2 = header->ReplyTo(); |
|
272 |
|
273 TestCase().INFO_PRINTF2(_L("Reply-To address from actual sent message as stored in the Message store: %S"), &line2); |
|
274 |
|
275 TBuf16<256> tmp; |
|
276 tmp.Copy(line); |
|
277 |
|
278 TBuf16<256> line_16; |
|
279 |
|
280 // Extract just the Reply-To address without the initial tag and trailing CR-LF characters |
|
281 for(TInt n=10; n<tmp.Length()-2; n++) |
|
282 { |
|
283 line_16.Append(tmp[n]); |
|
284 } |
|
285 |
|
286 // Compare if user-set Reply-To address in sample email txt file equals the one set by system in email header |
|
287 if(line_16.Compare(line2) != 0) |
|
288 { |
|
289 ret = EFalse; |
|
290 } |
|
291 |
|
292 CleanupStack::PopAndDestroy(header); |
|
293 CleanupStack::PopAndDestroy(store); |
|
294 CleanupStack::PopAndDestroy(msvEntry); |
|
295 |
|
296 } |
|
297 // else no Reply-To address exists in email header... |
|
298 else |
|
299 { |
|
300 // Check if Reply-To address is set correctly from default settings |
|
301 CEmailAccounts* accounts = CEmailAccounts::NewL(); |
|
302 CleanupStack::PushL(accounts); |
|
303 CImSmtpSettings* settings = new(ELeave) CImSmtpSettings(); |
|
304 CleanupStack::PushL(settings); |
|
305 CImIAPPreferences* smtpIAP = CImIAPPreferences::NewLC(); |
|
306 |
|
307 TSmtpAccount smtpAccountId = accounts->CreateSmtpAccountL(_L("SMTP"),*settings, *smtpIAP, EFalse); |
|
308 accounts->SetDefaultSmtpAccountL(smtpAccountId); |
|
309 accounts->PopulateDefaultSmtpSettingsL(*settings, *smtpIAP); |
|
310 |
|
311 CImIAPPreferences *popPrefs = CImIAPPreferences::NewLC(); |
|
312 CImPop3Settings *popSettings = new (ELeave) CImPop3Settings; |
|
313 CleanupStack::PushL(popSettings); |
|
314 |
|
315 accounts->PopulateDefaultPopSettingsL(*popSettings, *popPrefs); |
|
316 |
|
317 // TestAction CreatePop3Service doesn't save settings to central repository, |
|
318 // so default settings are reloaded |
|
319 CMtfTestActionUtilsPopScripts::ReadPopSettingsFromConfigurationFileL( |
|
320 TestCase(), KSettingsFile, *popSettings, *popPrefs, *settings, *smtpIAP); |
|
321 |
|
322 TPtrC defaultReplyToAddress = settings->ReplyToAddress(); |
|
323 |
|
324 TestCase().INFO_PRINTF2(_L("Default ReplyTo Address: %S"), &defaultReplyToAddress); |
|
325 |
|
326 // Format the Reply-To address field |
|
327 HBufC* formatedAddress = CreateFormattedAddressLC(defaultReplyToAddress, settings->EmailAlias()); |
|
328 TPtr ptrFormatedAddress = formatedAddress->Des(); |
|
329 TestCase().INFO_PRINTF2(_L("Formated ReplyTo Address: %S"), &ptrFormatedAddress); |
|
330 |
|
331 // aSentEntry - Identifier of the original sent email identified by TMsvEntry |
|
332 CMsvEntry* msvEntry = aSession->GetEntryL(aSentEntry.Id()); |
|
333 CleanupStack::PushL(msvEntry); |
|
334 |
|
335 msvEntry->SetEntryL(aSentEntry.Id()); |
|
336 CMsvStore* store = msvEntry->ReadStoreL(); |
|
337 CleanupStack::PushL(store); |
|
338 |
|
339 CImHeader* header = CImHeader::NewLC(); |
|
340 |
|
341 header->RestoreL(*store); |
|
342 // Read Reply-To address from email header |
|
343 TPtrC usedReplyToAddress = header->ReplyTo(); |
|
344 |
|
345 TestCase().INFO_PRINTF2(_L("Reply-To address from actual sent message as stored in the Message store: %S"), &usedReplyToAddress); |
|
346 |
|
347 // Compare if default Reply-To address equals the one set by system in email header |
|
348 if(ptrFormatedAddress.Compare(usedReplyToAddress) !=0) |
|
349 { |
|
350 ret = EFalse; |
|
351 } |
|
352 |
|
353 CleanupStack::PopAndDestroy(header); |
|
354 CleanupStack::PopAndDestroy(store); |
|
355 CleanupStack::PopAndDestroy(msvEntry); |
|
356 CleanupStack::PopAndDestroy(formatedAddress); |
|
357 CleanupStack::PopAndDestroy(popSettings); |
|
358 CleanupStack::PopAndDestroy(popPrefs); |
|
359 CleanupStack::PopAndDestroy(smtpIAP); |
|
360 CleanupStack::PopAndDestroy(settings); |
|
361 CleanupStack::PopAndDestroy(accounts); |
|
362 } |
|
363 return ret; |
|
364 } |
|
365 |
|
366 /** |
|
367 IsEofL() |
|
368 Checks if the current position of read stream reached end of file |
|
369 */ |
|
370 TBool CMtfTestActionVerifyReplyToAddress::IsEofL(RReadStream& aReadStream) |
|
371 { |
|
372 TStreamPos streamPos = aReadStream.Source()->TellL(MStreamBuf::ERead); |
|
373 TInt streamSize = aReadStream.Source()->SizeL(); |
|
374 |
|
375 if(streamPos >= streamSize) |
|
376 return ETrue; |
|
377 |
|
378 return EFalse; |
|
379 } |
|
380 |
|
381 /** |
|
382 CreateFormattedAddressL() |
|
383 Re-used code from src/common/generic/messaging/email/smtpservermtm/src/imsmsend.cpp#057 |
|
384 Creates a new HBufC* containing the concateneatd alias and address strings |
|
385 */ |
|
386 HBufC* CMtfTestActionVerifyReplyToAddress::CreateFormattedAddressLC(const TDesC& aString, const TDesC& aAlias) |
|
387 { |
|
388 TImMessageField msgField; |
|
389 |
|
390 // Make a buffer... |
|
391 TInt strLen = aString.Length(); |
|
392 TInt aliasLen = aAlias.Length(); |
|
393 |
|
394 HBufC* outString = HBufC::NewLC(strLen+aliasLen+5); |
|
395 HBufC* buffer = HBufC::NewL(strLen); |
|
396 |
|
397 *buffer = msgField.GetValidInternetEmailAddressFromString(aString); |
|
398 |
|
399 if (aliasLen) |
|
400 { |
|
401 outString->Des().Format(KSmtpEmailAddressAndAliasFmtStr,&aAlias,buffer); |
|
402 } |
|
403 else |
|
404 { |
|
405 *outString = *buffer; // just copy email address; as there's no alias to be added |
|
406 } |
|
407 |
|
408 delete buffer; |
|
409 return outString; |
|
410 } |
|
411 |