64 _LIT(KBccField, BCC_FIELD); |
64 _LIT(KBccField, BCC_FIELD); |
65 _LIT(KFromField, FROM_FIELD); |
65 _LIT(KFromField, FROM_FIELD); |
66 _LIT(KFolderField, FOLDER_FIELD); |
66 _LIT(KFolderField, FOLDER_FIELD); |
67 _LIT(KBodyField, BODY_FIELD); |
67 _LIT(KBodyField, BODY_FIELD); |
68 _LIT(KSubjectField, SUBJECT_FIELD); |
68 _LIT(KSubjectField, SUBJECT_FIELD); |
69 |
69 _LIT(KAttachmentField, ATTACHMENT_FIELD); |
|
70 _LIT(KValueAttachment, "Attachment"); |
70 // ============================ MEMBER FUNCTIONS =============================== |
71 // ============================ MEMBER FUNCTIONS =============================== |
71 |
72 |
72 // --------------------------------------------------------------------------- |
73 // --------------------------------------------------------------------------- |
73 // CMessageDataHandler::NewL |
74 // CMessageDataHandler::NewL |
74 // --------------------------------------------------------------------------- |
75 // --------------------------------------------------------------------------- |
195 TBuf<20> docid_str; |
196 TBuf<20> docid_str; |
196 docid_str.AppendNum(aMsvId); |
197 docid_str.AppendNum(aMsvId); |
197 if (iMessagePlugin.GetIndexer()) |
198 if (iMessagePlugin.GetIndexer()) |
198 { |
199 { |
199 TRAPD(err, iMessagePlugin.GetIndexer()->DeleteL(docid_str)); |
200 TRAPD(err, iMessagePlugin.GetIndexer()->DeleteL(docid_str)); |
200 if (err == KErrNone) |
201 OstTrace1( TRACE_NORMAL, DUP7_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL():DeleteL;err=%d", err ); |
201 { |
|
202 OstTrace0( TRACE_NORMAL, DUP1_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): Document deleted." ); |
|
203 CPIXLOGSTRING("CMessageDataHandler::CreateMessageIndexItemL(): Document deleted."); |
|
204 } |
|
205 else |
|
206 { |
|
207 OstTrace1( TRACE_NORMAL, DUP2_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL;Error in deleting the doc=%d", err ); |
|
208 CPIXLOGSTRING2("CMessageDataHandler::CreateMessageIndexItemL(): Error %d in deleting the document.", err); |
|
209 } |
|
210 } |
202 } |
211 return; |
203 return; |
212 } |
204 } |
213 |
205 |
214 // Check message type |
206 // Check message type |
221 switch (messageType) |
213 switch (messageType) |
222 { |
214 { |
223 case EMsgTypeSms: |
215 case EMsgTypeSms: |
224 { |
216 { |
225 TRAPD(err, index_item = CreateSmsDocumentL(aMsvId, aFolderId)); |
217 TRAPD(err, index_item = CreateSmsDocumentL(aMsvId, aFolderId)); |
226 if (err == KErrNone) |
218 OstTrace1( TRACE_NORMAL, DUP1_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): SMS document creation;err=%d", err ); |
227 { |
|
228 OstTrace0( TRACE_NORMAL, DUP3_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): SMS document created." ); |
|
229 CPIXLOGSTRING("CMessageDataHandler::CreateMessageIndexItemL(): SMS document created."); |
|
230 } |
|
231 else |
|
232 { |
|
233 OstTrace1( TRACE_NORMAL, DUP4_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL;Error in creating the sms doc=%d", err ); |
|
234 CPIXLOGSTRING2("CMessageDataHandler::CreateMessageIndexItemL(): Error %d in creating SMS document.", err); |
|
235 } |
|
236 break; |
219 break; |
237 } |
220 } |
238 case EMsgTypeMms: |
221 case EMsgTypeMms: |
239 { |
222 { |
240 TRAPD(err, index_item = CreateMmsDocumentL(aMsvId, aFolderId)); |
223 TRAPD(err, index_item = CreateMmsDocumentL(aMsvId, aFolderId)); |
241 if (err == KErrNone) |
224 OstTrace1( TRACE_NORMAL, DUP2_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): MMS document created;err=%d", err ); |
242 { |
|
243 OstTrace0( TRACE_NORMAL, DUP5_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): MMS document created." ); |
|
244 CPIXLOGSTRING("CMessageDataHandler::CreateMessageIndexItemL(): MMS document created."); |
|
245 } |
|
246 else |
|
247 { |
|
248 OstTrace1( TRACE_NORMAL, DUP6_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL;Error in creating the mms doc=%d", err ); |
|
249 CPIXLOGSTRING2("CMessageDataHandler::CreateMessageIndexItemL(): Error %d in creating MMS document.", err); |
|
250 } |
|
251 break; |
|
252 } |
|
253 case EMsgTypeEmailPop3: |
|
254 case EMsgTypeEmailImap4: |
|
255 case EMsgTypeEmailSmtp: |
|
256 { |
|
257 TRAPD(err, index_item = CreateEmailDocumentL(aMsvId, aFolderId)); |
|
258 if (err == KErrNone) |
|
259 { |
|
260 OstTrace0( TRACE_NORMAL, DUP7_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): E-mail document created." ); |
|
261 CPIXLOGSTRING("CMessageDataHandler::CreateMessageIndexItemL(): E-mail document created."); |
|
262 } |
|
263 else |
|
264 { |
|
265 OstTrace1( TRACE_NORMAL, DUP8_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL;Error in ccreating the email doc=%d", err ); |
|
266 CPIXLOGSTRING2("CMessageDataHandler::CreateMessageIndexItemL(): Error %d in creating e-mail document.", err); |
|
267 } |
|
268 break; |
225 break; |
269 } |
226 } |
270 case EMsgTypeInvalid: |
227 case EMsgTypeInvalid: |
271 // For EMsgTypeDraft there is no way to tell if it was a SMS, MMS or email, |
228 // For EMsgTypeDraft there is no way to tell if it was a SMS, MMS , |
272 // so don't create index_item. |
229 // so don't create index_item. |
273 case EMsgTypeDraft: |
230 case EMsgTypeDraft: |
274 default: |
231 default: |
275 // Error occurred |
232 // Error occurred |
276 break; |
233 break; |
299 if (iMessagePlugin.GetIndexer()) |
256 if (iMessagePlugin.GetIndexer()) |
300 { |
257 { |
301 if (aActionType == ECPixAddAction) |
258 if (aActionType == ECPixAddAction) |
302 { |
259 { |
303 TRAPD(err, iMessagePlugin.GetIndexer()->AddL(*index_item)); |
260 TRAPD(err, iMessagePlugin.GetIndexer()->AddL(*index_item)); |
304 if (err == KErrNone) |
261 OstTrace1( TRACE_NORMAL, DUP3_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): Added;err=%d", err ); |
305 { |
|
306 OstTrace0( TRACE_NORMAL, DUP10_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): Added." ); |
|
307 CPIXLOGSTRING("CMessageDataHandler::CreateMessageIndexItemL(): Added."); |
|
308 } |
|
309 else |
|
310 { |
|
311 OstTrace1( TRACE_NORMAL, DUP11_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL;Error in Adding=%d", err ); |
|
312 CPIXLOGSTRING2("CMessageDataHandler::CreateMessageIndexItemL(): Error %d in adding.", err); |
|
313 } |
|
314 } |
262 } |
315 else if (aActionType == ECPixUpdateAction) |
263 else if (aActionType == ECPixUpdateAction) |
316 { |
264 { |
317 TRAPD(err, iMessagePlugin.GetIndexer()->UpdateL(*index_item)); |
265 TRAPD(err, iMessagePlugin.GetIndexer()->UpdateL(*index_item)); |
318 if (err == KErrNone) |
266 OstTrace1( TRACE_NORMAL, DUP4_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): Updated;err=%d", err ); |
319 { |
|
320 OstTrace0( TRACE_NORMAL, DUP12_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL(): Updated." ); |
|
321 CPIXLOGSTRING("CMessageDataHandler::CreateMessageIndexItemL(): Updated."); |
|
322 } |
|
323 else |
|
324 { |
|
325 OstTrace1( TRACE_NORMAL, DUP13_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "CMessageDataHandler::CreateMessageIndexItemL;Error in Updating=%d", err ); |
|
326 CPIXLOGSTRING2("CMessageDataHandler::CreateMessageIndexItemL(): Error %d in updating.", err); |
|
327 } |
|
328 } |
267 } |
329 } |
268 } |
330 else |
269 else |
331 { |
270 { |
332 OstTrace0( TRACE_NORMAL, DUP14_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "END CMessageDataHandler::CreateMessageIndexItemL(): No indexer present." ); |
271 OstTrace0( TRACE_NORMAL, DUP14_CMESSAGEDATAHANDLER_CREATEMESSAGEINDEXITEML, "END CMessageDataHandler::CreateMessageIndexItemL(): No indexer present." ); |
356 // (iSmsMtm->SmsHeader().FromAddress() - only returns the number) |
295 // (iSmsMtm->SmsHeader().FromAddress() - only returns the number) |
357 TMsvEntry entry; |
296 TMsvEntry entry; |
358 TMsvId service = 0; |
297 TMsvId service = 0; |
359 iMsvSession.GetEntry(aMsvId, service, entry); |
298 iMsvSession.GetEntry(aMsvId, service, entry); |
360 HBufC *fromNameOrNumberBuf = entry.iDetails.AllocLC(); |
299 HBufC *fromNameOrNumberBuf = entry.iDetails.AllocLC(); |
361 index_item->AddFieldL(KFromField, *fromNameOrNumberBuf); |
300 index_item->AddFieldL(KFromField, *fromNameOrNumberBuf, |
|
301 CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText); |
362 |
302 |
363 // Add the recipients as content items |
303 // Add the recipients as content items |
364 TBuf<64> to_field; |
304 TBuf<64> to_field; |
365 const CDesCArray |
305 const CDesCArray |
366 & recipientArray = |
306 & recipientArray = |
368 for (TInt i = 0; i < recipientArray.MdcaCount(); i++) |
308 for (TInt i = 0; i < recipientArray.MdcaCount(); i++) |
369 { |
309 { |
370 to_field = KToField; |
310 to_field = KToField; |
371 if (i>0) |
311 if (i>0) |
372 to_field.AppendNum(i); |
312 to_field.AppendNum(i); |
373 index_item->AddFieldL(to_field, recipientArray.MdcaPoint(i)); |
313 index_item->AddFieldL(to_field, recipientArray.MdcaPoint(i), |
|
314 CDocumentField::EStoreYes | CDocumentField::EIndexTokenized | CDocumentField::EIndexFreeText); |
374 } |
315 } |
375 |
316 |
376 // Add the body text as a content item |
317 // Add the body text as a content item |
377 TInt msgLength = iSmsMtm->Body().DocumentLength(); |
318 TInt msgLength = iSmsMtm->Body().DocumentLength(); |
378 HBufC* bodyText = HBufC::NewLC(msgLength); |
319 HBufC* bodyText = HBufC::NewLC(msgLength); |
434 TBool excerptFieldAdded(EFalse); |
375 TBool excerptFieldAdded(EFalse); |
435 TInt bodycount = 0; |
376 TInt bodycount = 0; |
436 CMsvStore* msvStore = iMmsMtm->Entry().ReadStoreL(); |
377 CMsvStore* msvStore = iMmsMtm->Entry().ReadStoreL(); |
437 CleanupStack::PushL( msvStore ); |
378 CleanupStack::PushL( msvStore ); |
438 MMsvAttachmentManager& attManager = msvStore->AttachmentManagerL(); |
379 MMsvAttachmentManager& attManager = msvStore->AttachmentManagerL(); |
|
380 //Add attachment value field |
|
381 TInt count = attManager.AttachmentCount(); |
|
382 if (count > 0) |
|
383 index_item->AddFieldL(KAttachmentField, KValueAttachment); |
|
384 |
439 for ( TInt i = 0; i < attManager.AttachmentCount(); i++ ) |
385 for ( TInt i = 0; i < attManager.AttachmentCount(); i++ ) |
440 { |
386 { |
441 CMsvAttachment* attInfo = attManager.GetAttachmentInfoL(i); |
387 CMsvAttachment* attInfo = attManager.GetAttachmentInfoL(i); |
442 CleanupStack::PushL( attInfo ); |
388 CleanupStack::PushL( attInfo ); |
443 |
389 |
530 |
476 |
531 // Pop the item |
477 // Pop the item |
532 CleanupStack::Pop(index_item); |
478 CleanupStack::Pop(index_item); |
533 return index_item; |
479 return index_item; |
534 } |
480 } |
535 |
|
536 // --------------------------------------------------------------------------- |
|
537 // CMessageDataHandler::CreateEmailDocumentL |
|
538 // --------------------------------------------------------------------------- |
|
539 // |
|
540 CSearchDocument* CMessageDataHandler::CreateEmailDocumentL(const TMsvId& aMsvId, const TMsvId& aFolderId) |
|
541 { |
|
542 // creating CSearchDocument object with unique ID for this application |
|
543 TBuf<KMaxDocId> docid_str; |
|
544 docid_str.AppendNum(aMsvId); |
|
545 CSearchDocument* index_item = CSearchDocument::NewLC(docid_str, _L(EMAILAPPCLASS)); |
|
546 |
|
547 // Open the message entry |
|
548 CMsvEntry* message_entry = CMsvEntry::NewL(iMsvSession, aMsvId, TMsvSelectionOrdering()); |
|
549 CleanupStack::PushL(message_entry); |
|
550 |
|
551 // Get body |
|
552 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
553 CleanupStack::PushL(paraFormatLayer); |
|
554 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
555 CleanupStack::PushL(charFormatLayer); |
|
556 CRichText* richtext = CRichText::NewL(paraFormatLayer, charFormatLayer); |
|
557 CleanupStack::PushL(richtext); |
|
558 CImEmailMessage* message_body = CImEmailMessage::NewLC(*message_entry); |
|
559 message_body->GetBodyTextL(aMsvId, CImEmailMessage::EThisMessageOnly, *richtext, *paraFormatLayer, *charFormatLayer); |
|
560 |
|
561 // Read the message header |
|
562 CMsvStore* message_store = message_entry->ReadStoreL(); |
|
563 CleanupStack::PushL(message_store); |
|
564 CImHeader* header = CImHeader::NewLC(); |
|
565 header->RestoreL(*message_store); |
|
566 |
|
567 // Add from field |
|
568 index_item->AddFieldL(KFromField, header->From()); |
|
569 |
|
570 // Add the ToRecipients as content items |
|
571 TBuf<64> to_field; |
|
572 for (TInt i = 0; i < header->ToRecipients().MdcaCount(); i++) |
|
573 { |
|
574 to_field = KToField; |
|
575 if (i>0) |
|
576 to_field.AppendNum(i); |
|
577 index_item->AddFieldL(to_field, header->ToRecipients().MdcaPoint(i)); |
|
578 } |
|
579 |
|
580 // Add the CcRecipients as content items |
|
581 TBuf<64> cc_field; |
|
582 for (TInt i = 0; i < header->CcRecipients().MdcaCount(); i++) |
|
583 { |
|
584 cc_field = KCcField; |
|
585 if (i>0) |
|
586 cc_field.AppendNum(i); |
|
587 index_item->AddFieldL(cc_field, header->CcRecipients().MdcaPoint(i)); |
|
588 } |
|
589 |
|
590 // Add the BccRecipients as content items |
|
591 TBuf<64> bcc_field; |
|
592 for (TInt i = 0; i < header->BccRecipients().MdcaCount(); i++) |
|
593 { |
|
594 bcc_field = KBccField; |
|
595 if (i>0) |
|
596 bcc_field.AppendNum(i); |
|
597 index_item->AddFieldL(bcc_field, header->BccRecipients().MdcaPoint(i)); |
|
598 } |
|
599 |
|
600 const TInt richTxtLen = (richtext->DocumentLength() < KMaxDocumentSize) ? richtext->DocumentLength() : KMaxDocumentSize; |
|
601 HBufC* body_text = richtext->Read(0).Left(richTxtLen).AllocLC(); |
|
602 |
|
603 // Add subject |
|
604 TPtrC subject(header->Subject()); |
|
605 index_item->AddFieldL(KSubjectField, subject); |
|
606 |
|
607 // Add message body |
|
608 index_item->AddFieldL(KBodyField, *body_text); |
|
609 |
|
610 // Add excerpt |
|
611 HBufC* excerpt = CreateExcerptLC(header->From(), header->ToRecipients(), subject, *body_text, aFolderId); |
|
612 index_item->AddExcerptL(*excerpt); |
|
613 CleanupStack::PopAndDestroy(excerpt); |
|
614 |
|
615 // Cleanup everything last item message entry |
|
616 CleanupStack::PopAndDestroy(8, message_entry); |
|
617 |
|
618 // Pop the item |
|
619 CleanupStack::Pop(index_item); |
|
620 return index_item; |
|
621 } |
|
622 |
|
623 // --------------------------------------------------------------------------- |
481 // --------------------------------------------------------------------------- |
624 // CMessageDataHandler::CreateExcerptLC |
482 // CMessageDataHandler::CreateExcerptLC |
625 // --------------------------------------------------------------------------- |
483 // --------------------------------------------------------------------------- |
626 // |
484 // |
627 HBufC* CMessageDataHandler::CreateExcerptLC(const TDesC& aFromAddress, |
485 HBufC* CMessageDataHandler::CreateExcerptLC(const TDesC& aFromAddress, |