|
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 // User include |
|
21 #include "CMtfTestActionUtilsEmailMessage.h" |
|
22 #include "CMtfTestCase.h" |
|
23 |
|
24 const TInt INVALID_MSGPART_ID = -1; |
|
25 |
|
26 |
|
27 |
|
28 /** |
|
29 NewL() |
|
30 Constructs a CMtfTestActionUtilsEmailMessage object. |
|
31 Uses two phase construction and leaves nothing on the CleanupStack. |
|
32 @internalTechnology |
|
33 @param aMsvEntry Message server entry for the message being accessed |
|
34 @param aTestCase Reference to the test case. |
|
35 @return Created object of type CMtfTestActionUtilsEmailMessage object |
|
36 @pre None |
|
37 @post |
|
38 */ |
|
39 CMtfTestActionUtilsEmailMessage* CMtfTestActionUtilsEmailMessage::NewL(CMsvEntry& aMsvEntry, |
|
40 CMtfTestCase& aTestCase) |
|
41 { |
|
42 CMtfTestActionUtilsEmailMessage* self = new (ELeave) |
|
43 CMtfTestActionUtilsEmailMessage(aMsvEntry, aTestCase); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 |
|
51 /** |
|
52 Constructor |
|
53 Constructs a CMtfTestActionUtilsEmailMessage object. |
|
54 @internalTechnology |
|
55 @pre None |
|
56 @post None |
|
57 */ |
|
58 CMtfTestActionUtilsEmailMessage::CMtfTestActionUtilsEmailMessage( |
|
59 CMsvEntry& aMsvEntry, |
|
60 CMtfTestCase& aTestCase) |
|
61 :iEmailEntry(aMsvEntry), imEmailMessage(NULL),iBodyTextId(INVALID_MSGPART_ID), |
|
62 iBodyTextSize(0), iHtmlEntryId(INVALID_MSGPART_ID),iHtmlSize(0), iTestCase(aTestCase) |
|
63 { |
|
64 } |
|
65 |
|
66 |
|
67 /** |
|
68 Destructor |
|
69 Destructor for the class CMtfTestActionUtilsEmailMessage. |
|
70 @internalTechnology |
|
71 @param None |
|
72 @pre None |
|
73 @post None |
|
74 */ |
|
75 CMtfTestActionUtilsEmailMessage::~CMtfTestActionUtilsEmailMessage() |
|
76 { |
|
77 delete imEmailMessage; |
|
78 } |
|
79 |
|
80 |
|
81 /** |
|
82 ConstructL |
|
83 Constructs a CImEmailMessage object and initializes the member variables |
|
84 to default values |
|
85 @internalTechnology |
|
86 @pre None |
|
87 @post None |
|
88 */ |
|
89 void CMtfTestActionUtilsEmailMessage::ConstructL() |
|
90 { |
|
91 // Create a email message |
|
92 if(&iEmailEntry == NULL) |
|
93 { |
|
94 iTestCase.ERR_PRINTF1(_L("Error: Email Entry has a NULL Value")); |
|
95 User::Leave(KErrBadHandle); |
|
96 } |
|
97 imEmailMessage = CImEmailMessage::NewLC(iEmailEntry); |
|
98 |
|
99 ProcessMessageInfoL(); |
|
100 |
|
101 iTestCase.INFO_PRINTF1(_L("Created CImEmailMessage object")); |
|
102 |
|
103 CleanupStack::Pop(imEmailMessage); |
|
104 } |
|
105 |
|
106 |
|
107 /** |
|
108 ProcessMessageInfoL |
|
109 Extracts the information about the Body text, and Html part |
|
110 @internalTechnology |
|
111 @param None |
|
112 @return KErrNone if successful |
|
113 @pre Successful creation of CImEmailMessage object |
|
114 @post None |
|
115 */ |
|
116 TInt CMtfTestActionUtilsEmailMessage::ProcessMessageInfoL() |
|
117 { |
|
118 TInt retValue = KErrNone; |
|
119 |
|
120 if(imEmailMessage != NULL) |
|
121 { |
|
122 // Set the information for the body text |
|
123 retValue = StoreBodyTextInfoL() ; |
|
124 |
|
125 // Set the information for the Html part |
|
126 if (retValue == KErrNone) |
|
127 { |
|
128 retValue = StoreHtmlInfoL(); |
|
129 } |
|
130 } |
|
131 else |
|
132 { |
|
133 iTestCase.ERR_PRINTF1(_L("Invalid CImEmailMessage object in function ProcessMessageInfoL")); |
|
134 retValue = KErrBadHandle; |
|
135 } |
|
136 return retValue; |
|
137 } |
|
138 |
|
139 /** |
|
140 StoreBodyTextInfoL |
|
141 Extract the body text information from CImEailMessage object and store it |
|
142 in the member variables |
|
143 @internalTechnology |
|
144 @param None |
|
145 @return TInt KErrNone if successful |
|
146 @pre None |
|
147 @post None |
|
148 */ |
|
149 TInt CMtfTestActionUtilsEmailMessage::StoreBodyTextInfoL() |
|
150 { |
|
151 // Get message body text in a CRichText object |
|
152 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
153 CleanupStack::PushL(paraFormatLayer); |
|
154 |
|
155 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
156 CleanupStack::PushL(charFormatLayer); |
|
157 |
|
158 CRichText* bodyText = CRichText::NewL( paraFormatLayer, charFormatLayer, |
|
159 CEditableText::EFlatStorage, 256); |
|
160 CleanupStack::PushL(bodyText); |
|
161 |
|
162 TInt retValue = KErrNone; |
|
163 |
|
164 // Get the Body text contents into a CRichText object |
|
165 if(imEmailMessage != NULL) |
|
166 { |
|
167 imEmailMessage->GetBodyTextL(iEmailEntry.EntryId(), CImEmailMessage::EThisMessageOnly, *bodyText, *paraFormatLayer, *charFormatLayer); |
|
168 |
|
169 // Get the selection of body text entries |
|
170 TInt count = imEmailMessage->Selection().Count(); |
|
171 |
|
172 // Check if any body text entry was present |
|
173 if( count > 0) |
|
174 { |
|
175 // Get the Id of the body text |
|
176 // The body text part Id is present at index 0. Not checking for other |
|
177 // Ids, as currently only Plain text part is verified. |
|
178 iBodyTextId = imEmailMessage->Selection().At(0); |
|
179 |
|
180 // Store the size of the message body text |
|
181 iBodyTextSize = bodyText->DocumentLength(); |
|
182 } |
|
183 retValue = KErrNone; |
|
184 } |
|
185 else |
|
186 { |
|
187 iTestCase.ERR_PRINTF1(_L("Invalid CImEmailMessage object in function StoreBodyTextInfoL")); |
|
188 retValue = KErrBadHandle; |
|
189 } |
|
190 |
|
191 iTestCase.INFO_PRINTF2(_L("Body Text Id: %d"),iBodyTextId); |
|
192 iTestCase.INFO_PRINTF2(_L("Body Text Size: %d"),iBodyTextSize); |
|
193 |
|
194 // Clean the stack |
|
195 CleanupStack::PopAndDestroy(bodyText); |
|
196 CleanupStack::PopAndDestroy(charFormatLayer); |
|
197 CleanupStack::PopAndDestroy(paraFormatLayer); |
|
198 |
|
199 return retValue; |
|
200 } |
|
201 |
|
202 |
|
203 /** |
|
204 StoreHtmlInfoL |
|
205 Extract the information for Htnl part from CImEailMessage object and store it |
|
206 in the member variables |
|
207 @internalTechnology |
|
208 @param None |
|
209 @return KErrNone if successful |
|
210 @pre None |
|
211 @post None |
|
212 */ |
|
213 TInt CMtfTestActionUtilsEmailMessage::StoreHtmlInfoL() |
|
214 { |
|
215 TInt retValue = KErrNone; |
|
216 |
|
217 if(imEmailMessage) |
|
218 { |
|
219 // Need to make a asynchronous function call to find the first html page |
|
220 // Create a active object |
|
221 CMsvOperationActiveSchedulerWait* waiter = CMsvOperationActiveSchedulerWait::NewLC(); |
|
222 |
|
223 // Call asynchronous operation to get the first html |
|
224 imEmailMessage->FindFirstHTMLPageL( iEmailEntry.EntryId(),waiter->iStatus); |
|
225 |
|
226 // Wait for the asynchronous operation to complete |
|
227 waiter->Start(); |
|
228 |
|
229 retValue = (waiter->iStatus).Int(); |
|
230 |
|
231 // Destroy the active object |
|
232 CleanupStack::PopAndDestroy(waiter); |
|
233 |
|
234 if( retValue == KErrNone) |
|
235 { |
|
236 // Asynchronous operation is completed, get the Id and the name of the Html |
|
237 // The complete path of the Html file will be received. |
|
238 TBool found = EFalse; |
|
239 HBufC* htmlFileName = imEmailMessage->GetUniversalResourceIdentifierL(iHtmlEntryId, found); |
|
240 |
|
241 // If Html part was found, look for the html file in the message store and get its size |
|
242 // Assumption: Not verifying relative URIs, since message with only one Html part considered |
|
243 TInt htmlSize = 0; |
|
244 if ((found) && (htmlFileName != NULL)) |
|
245 { |
|
246 iHtmlFileName.Set(htmlFileName->Des()); |
|
247 |
|
248 RFs fs; |
|
249 User::LeaveIfError(fs.Connect()); |
|
250 |
|
251 RFile htmlFile; |
|
252 |
|
253 // Open the Html file in the read only mode |
|
254 TInt ret = htmlFile.Open(fs, iHtmlFileName, EFileRead|EFileShareReadersOnly); |
|
255 if( ret == KErrNone) |
|
256 { |
|
257 // Get the size of the Html file |
|
258 if ( htmlFile.Size(htmlSize) != KErrNone) |
|
259 { |
|
260 // Html file not present |
|
261 htmlSize = 0; |
|
262 } |
|
263 htmlFile.Close(); |
|
264 } |
|
265 else |
|
266 { |
|
267 // Failure while opening the html file, set the size to 0 |
|
268 htmlSize = 0; |
|
269 } |
|
270 fs.Close(); |
|
271 } |
|
272 else |
|
273 { |
|
274 iTestCase.INFO_PRINTF1(_L("Html part was not found")); |
|
275 } |
|
276 // Set html size |
|
277 iHtmlSize = htmlSize; |
|
278 |
|
279 iTestCase.INFO_PRINTF2(_L("Html Part Entry Id: %d"),iHtmlEntryId); |
|
280 iTestCase.INFO_PRINTF2(_L("Html Part Size: %d"),iHtmlSize); |
|
281 iTestCase.INFO_PRINTF2(_L("Html Part Path: %S"),&iHtmlFileName); |
|
282 } |
|
283 } |
|
284 else |
|
285 { |
|
286 iTestCase.ERR_PRINTF1(_L("Invalid CImEmailMessage object in function StoreHtmlInfoL")); |
|
287 retValue = KErrBadHandle; |
|
288 } |
|
289 return retValue; |
|
290 } |
|
291 |
|
292 /** |
|
293 GetMessageAttachmentListL |
|
294 Calls the asynchronous function CImEmailMessage::GetAttachmentsListL() to |
|
295 get the list of attachments present in the message. The function |
|
296 CImEmailMessage::AttachmentSelection() needs to be called after this function |
|
297 call to get the list of attachments |
|
298 @internalTechnology |
|
299 @return KErrNone if successful |
|
300 @pre None |
|
301 @post CImEmailMessage::AttachmentSelection() needs to be called |
|
302 */ |
|
303 TInt CMtfTestActionUtilsEmailMessage::GetMessageAttachmentListL() |
|
304 { |
|
305 TInt retValue = KErrNone; |
|
306 |
|
307 if(imEmailMessage != NULL) |
|
308 { |
|
309 // Need to make a asynchronous function call to get the attachment list |
|
310 // Create an active object |
|
311 CMsvOperationActiveSchedulerWait* waiter = CMsvOperationActiveSchedulerWait::NewLC(); |
|
312 |
|
313 // Call asynchronous operation to get the list of attachments to this message |
|
314 // Embedded messages not considered |
|
315 |
|
316 // Assumption: CImEmailMessage::EThisMessageOnly is set as the parameter, because, |
|
317 // currently, messages with out any embedded messages are considered |
|
318 |
|
319 imEmailMessage->GetAttachmentsListL( waiter->iStatus, iEmailEntry.Entry().Id(), |
|
320 CImEmailMessage::EAllAttachments, |
|
321 CImEmailMessage::EThisMessageOnly); |
|
322 |
|
323 // Wait for the asynchronous operation to complete |
|
324 waiter->Start(); |
|
325 |
|
326 retValue = (waiter->iStatus).Int(); |
|
327 |
|
328 // Destroy the active object |
|
329 CleanupStack::PopAndDestroy(waiter); |
|
330 } |
|
331 else |
|
332 { |
|
333 iTestCase.ERR_PRINTF1(_L("Invalid CImEmailMessage object in function GetMessageAttachmentListL")); |
|
334 retValue = KErrBadHandle; |
|
335 } |
|
336 return retValue; |
|
337 } |
|
338 |
|
339 |
|
340 |
|
341 /** |
|
342 GetBodyTextL |
|
343 Get body text information by calling the CImEmailMessage::GetBodyTextL() function. |
|
344 The calling function is responsible to delete the CRichText, CParaFormatLayer and |
|
345 aCharFormatLayer objects. |
|
346 @internalTechnology |
|
347 @param aRichText CRichText object containing the Body text contents |
|
348 @param aParaFormatLayer CParaFormatLayer object of the Body text |
|
349 @param aParaFormatLayer CCharFormatLayer object of the Bodt text |
|
350 @pre None |
|
351 @post None |
|
352 */ |
|
353 void CMtfTestActionUtilsEmailMessage::GetBodyTextL(CRichText& aRichText, |
|
354 CParaFormatLayer& aParaFormatLayer, |
|
355 CCharFormatLayer& aCharFormatLayer) |
|
356 { |
|
357 // Get the Body text contents into a CRichText object |
|
358 imEmailMessage->GetBodyTextL(iEmailEntry.EntryId(), CImEmailMessage::EThisMessageOnly, |
|
359 aRichText, aParaFormatLayer, aCharFormatLayer); |
|
360 |
|
361 } |
|
362 |
|
363 |
|
364 /** |
|
365 GetMessageId |
|
366 TMsvId of the message |
|
367 @internalTechnology |
|
368 @param aMsvId - Reference to the Id of the message |
|
369 @return TInt KErrNone if successful. |
|
370 @pre None |
|
371 @post None |
|
372 */ |
|
373 TInt CMtfTestActionUtilsEmailMessage::GetMessageId(TMsvId& aMsvId) |
|
374 { |
|
375 TInt retValue = KErrNone; |
|
376 if(&iEmailEntry != NULL) |
|
377 { |
|
378 aMsvId = iEmailEntry.EntryId(); |
|
379 retValue = KErrNone; |
|
380 } |
|
381 else |
|
382 { |
|
383 iTestCase.ERR_PRINTF1(_L("Invalid message entry object in function GetMessageId")); |
|
384 retValue = KErrBadHandle; |
|
385 } |
|
386 return retValue; |
|
387 } |
|
388 |
|
389 |
|
390 /** |
|
391 GetMessageSize |
|
392 Size of the message |
|
393 @internalTechnology |
|
394 @param aMsgSize Reference to size of the message |
|
395 @return TInt KErrNone if successful |
|
396 @pre None |
|
397 @post None |
|
398 */ |
|
399 TInt CMtfTestActionUtilsEmailMessage::GetMessageSize(TInt32& aMsgSize) |
|
400 { |
|
401 if(&iEmailEntry != NULL) |
|
402 { |
|
403 aMsgSize = iEmailEntry.Entry().iSize; |
|
404 return KErrNone; |
|
405 } |
|
406 else |
|
407 { |
|
408 iTestCase.ERR_PRINTF1(_L("Invalid message entry object in function GetMessageSize")); |
|
409 return KErrBadHandle; |
|
410 } |
|
411 } |
|
412 |
|
413 /** |
|
414 GetEmailMessageL |
|
415 Returns the pointer to CImEmailMessage object |
|
416 @internalTechnology |
|
417 @param None |
|
418 @return Pointer to CImEmailMessage object |
|
419 @pre None |
|
420 @post None |
|
421 */ |
|
422 CImEmailMessage* CMtfTestActionUtilsEmailMessage::GetEmailMessageL() |
|
423 { |
|
424 if(imEmailMessage == NULL) |
|
425 { |
|
426 iTestCase.ERR_PRINTF1(_L("Invalid email message object in function GetEmailMessageL")); |
|
427 User::Leave(KErrBadHandle); |
|
428 } |
|
429 return imEmailMessage; |
|
430 } |
|
431 |
|
432 |
|
433 /** |
|
434 GetBodyTextId |
|
435 Returns the TMsvId of the Body Text |
|
436 @internalTechnology |
|
437 @param None |
|
438 @return TMsvId of the Body Text |
|
439 @pre None |
|
440 @post None |
|
441 */ |
|
442 TMsvId CMtfTestActionUtilsEmailMessage::GetBodyTextId() |
|
443 { |
|
444 return iBodyTextId; |
|
445 } |
|
446 |
|
447 |
|
448 /** |
|
449 GetBodyTextSize |
|
450 Returns the size of the Body Text |
|
451 @internalTechnology |
|
452 @param None |
|
453 @return Size of the Body Text |
|
454 @pre None |
|
455 @post None |
|
456 */ |
|
457 TInt32 CMtfTestActionUtilsEmailMessage::GetBodyTextSize() |
|
458 { |
|
459 return iBodyTextSize; |
|
460 } |
|
461 |
|
462 |
|
463 |
|
464 /** |
|
465 GetHtmlEntryId |
|
466 Returns the TMsvId of the Html part |
|
467 @internalTechnology |
|
468 @param None |
|
469 @return TMsvId of the Html part |
|
470 @pre None |
|
471 @post None |
|
472 */ |
|
473 TInt32 CMtfTestActionUtilsEmailMessage::GetHtmlEntryId() |
|
474 { |
|
475 return iHtmlEntryId; |
|
476 } |
|
477 |
|
478 |
|
479 /** |
|
480 GetHtmlSize |
|
481 Returns the size of the Html file |
|
482 @internalTechnology |
|
483 @param None |
|
484 @return Size of the Html file |
|
485 @pre None |
|
486 @post None |
|
487 */ |
|
488 TInt32 CMtfTestActionUtilsEmailMessage::GetHtmlSize() |
|
489 { |
|
490 return iHtmlSize; |
|
491 } |
|
492 |
|
493 |
|
494 /** |
|
495 HtmlFileName |
|
496 Provides the Html file name |
|
497 @internalTechnology |
|
498 @param aHtmlFileName Reference to the buffer contianing Html file name |
|
499 @return TInt Error value |
|
500 @pre None |
|
501 @post None |
|
502 */ |
|
503 TInt CMtfTestActionUtilsEmailMessage::HtmlFileName(TPtrC& aHtmlFileName) |
|
504 { |
|
505 // Set the Html file name if the file path is present, else return error |
|
506 TInt error = KErrNotFound; |
|
507 |
|
508 if (iHtmlFileName.Ptr()) |
|
509 { |
|
510 aHtmlFileName.Set(iHtmlFileName); |
|
511 error = KErrNone; |
|
512 } |
|
513 return error; |
|
514 } |
|
515 |
|
516 |
|
517 |
|
518 /** |
|
519 CheckCompleteFlagL |
|
520 Check if the complete flag of the message part is set |
|
521 @internalTechnology |
|
522 @param aMsgId - Id of the message part |
|
523 @return ETrue if complete flag is set, EFalse otherwise |
|
524 @pre None |
|
525 @post None |
|
526 */ |
|
527 TInt CMtfTestActionUtilsEmailMessage::CheckCompleteFlagL ( |
|
528 TMsvId aMsgId, |
|
529 TBool& aCompleteFlag) |
|
530 { |
|
531 TInt retValue = KErrNone; |
|
532 |
|
533 // Check if the message Id is valid |
|
534 if(aMsgId == INVALID_MSGPART_ID) |
|
535 { |
|
536 // Invalid Id passed to the function |
|
537 retValue = KErrBadHandle; |
|
538 } |
|
539 else |
|
540 { |
|
541 CMsvEntry* msgEntry = iEmailEntry.Session().GetEntryL(aMsgId); |
|
542 CleanupStack::PushL(msgEntry); |
|
543 |
|
544 if(msgEntry) |
|
545 { |
|
546 msgEntry->SetEntryL(aMsgId); |
|
547 TMsvEntry msvEntry = msgEntry->Entry(); |
|
548 |
|
549 aCompleteFlag = msvEntry.Complete(); |
|
550 } |
|
551 else |
|
552 { |
|
553 retValue = KErrBadHandle; |
|
554 } |
|
555 CleanupStack::PopAndDestroy(msgEntry); |
|
556 } |
|
557 return retValue; |
|
558 } |
|
559 |
|
560 /** |
|
561 CheckPartialDownloadFlagL |
|
562 Check if the partial download flag for the message part is set |
|
563 @internalTechnology |
|
564 @param aEntry - Id of the message part |
|
565 @return ETrue if partial download flag is set, EFalse otherwise |
|
566 @pre None |
|
567 @post None |
|
568 */ |
|
569 TInt CMtfTestActionUtilsEmailMessage::CheckPartialDownloadFlagL( |
|
570 TMsvId aMsgId, |
|
571 TBool& aPartialDownloadFlag) |
|
572 { |
|
573 TInt retValue = KErrNone; |
|
574 |
|
575 // Check if the message Id is valid |
|
576 if(aMsgId == INVALID_MSGPART_ID) |
|
577 { |
|
578 // Invalid Id passed to the function |
|
579 retValue = KErrBadHandle; |
|
580 } |
|
581 else |
|
582 { |
|
583 CMsvEntry* msgEntry = iEmailEntry.Session().GetEntryL(aMsgId); |
|
584 CleanupStack::PushL(msgEntry); |
|
585 |
|
586 if(msgEntry) |
|
587 { |
|
588 msgEntry->SetEntryL(aMsgId); |
|
589 |
|
590 TMsvEmailEntry msvEntry = msgEntry->Entry(); |
|
591 |
|
592 aPartialDownloadFlag = msvEntry.PartialDownloaded(); |
|
593 } |
|
594 else |
|
595 { |
|
596 retValue = KErrBadHandle; |
|
597 } |
|
598 CleanupStack::PopAndDestroy(msgEntry); |
|
599 } |
|
600 return retValue; |
|
601 } |