240 |
240 |
241 // release store |
241 // release store |
242 CleanupStack::PopAndDestroy( 3, cEntry ); // >>> cEntry, header, store |
242 CleanupStack::PopAndDestroy( 3, cEntry ); // >>> cEntry, header, store |
243 } |
243 } |
244 |
244 |
245 // --------------------------------------------------------------------------- |
245 // <qmail> removing unused functions |
246 // CIpsPlgSmtpService::CreateNewSmtpMessageL |
246 // CreateNewSmtpMessageL |
247 // --------------------------------------------------------------------------- |
247 // CreateForwardSmtpMessageL |
248 // |
248 // CreateReplySmtpMessageL |
249 CFSMailMessage* CIpsPlgSmtpService::CreateNewSmtpMessageL( |
249 // </qmail> |
250 const TFSMailMsgId& aMailBoxId ) |
|
251 { |
|
252 FUNC_LOG; |
|
253 TMsvPartList partList( KMsvMessagePartBody ); |
|
254 |
|
255 CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC( ); |
|
256 |
|
257 TMsvEntry mboxEntry; |
|
258 TMsvId service; |
|
259 iSession.GetEntry( aMailBoxId.Id(), service, mboxEntry ); |
|
260 |
|
261 // new mail creating operation. Mail is created asynchronously |
|
262 CImEmailOperation* newMailOp = CImEmailOperation::CreateNewL( |
|
263 wait->iStatus, |
|
264 iSession, |
|
265 KMsvDraftEntryId, |
|
266 mboxEntry.iRelatedId, |
|
267 partList, |
|
268 0, |
|
269 KUidMsgTypeSMTP ); |
|
270 |
|
271 CleanupStack::PushL( newMailOp ); |
|
272 |
|
273 // wait until new mail is created |
|
274 wait->Start(); |
|
275 |
|
276 TMsvId msgId = GetIdFromProgressL( newMailOp->FinalProgress() ); |
|
277 |
|
278 CleanupStack::PopAndDestroy( 2, wait ); |
|
279 |
|
280 return CreateFSMessageAndSetFlagsL( |
|
281 msgId, KErrNotFound, aMailBoxId.Id() ); |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // CIpsPlgSmtpService::CreateForwardSmtpMessageL |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 CFSMailMessage* CIpsPlgSmtpService::CreateForwardSmtpMessageL( |
|
289 const TFSMailMsgId& aMailBoxId, |
|
290 const TFSMailMsgId& aOriginalMessageId ) |
|
291 { |
|
292 FUNC_LOG; |
|
293 // 1. part of function checs that body text and all |
|
294 // attachments are fetched |
|
295 TMsvEntry orgMsg; |
|
296 TMsvId service; |
|
297 User::LeaveIfError( iSession.GetEntry( |
|
298 aOriginalMessageId.Id(), service, orgMsg ) ); |
|
299 |
|
300 if ( orgMsg.Id() == KMsvNullIndexEntryIdValue ) |
|
301 { |
|
302 User::Leave(KErrNotFound); |
|
303 } |
|
304 |
|
305 // In case original message is in Sent folder, it's serviceId must be |
|
306 // changed before starting forward/reply msg creation operation |
|
307 // (after forward msg is created, this is changed back) |
|
308 TMsvId orgServiceId( 0 ); |
|
309 if ( ( orgMsg.Parent() == KMsvSentEntryIdValue ) && |
|
310 ( orgMsg.iMtm == KSenduiMtmSmtpUid ) ) |
|
311 { |
|
312 orgServiceId = orgMsg.iServiceId; |
|
313 ChangeServiceIdL( orgMsg ); |
|
314 } |
|
315 |
|
316 TMsvPartList partList( KMsvMessagePartBody | KMsvMessagePartAttachments ); |
|
317 |
|
318 CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC( ); |
|
319 CImEmailOperation* forwMailOp = CImEmailOperation::CreateForwardL( |
|
320 wait->iStatus, |
|
321 iSession, |
|
322 orgMsg.Id(), |
|
323 KMsvDraftEntryId, |
|
324 partList, |
|
325 0, |
|
326 KUidMsgTypeSMTP ); |
|
327 |
|
328 CleanupStack::PushL( forwMailOp ); |
|
329 |
|
330 wait->Start(); |
|
331 |
|
332 TMsvId msgId = GetIdFromProgressL( forwMailOp->FinalProgress() ); |
|
333 |
|
334 CleanupStack::PopAndDestroy( 2, wait ); |
|
335 |
|
336 // If original message's serviceId was changed prior to forward/reply msg |
|
337 // creation op, changing it back to the original |
|
338 if ( orgServiceId ) |
|
339 { |
|
340 ChangeServiceIdL( orgMsg, orgServiceId ); |
|
341 } |
|
342 |
|
343 return CreateFSMessageAndSetFlagsL( msgId, orgMsg.Id(), aMailBoxId.Id() ); |
|
344 } |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // CIpsPlgSmtpService::CreateReplySmtpMessageL |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 CFSMailMessage* CIpsPlgSmtpService::CreateReplySmtpMessageL( |
|
351 const TFSMailMsgId& aMailBoxId, |
|
352 const TFSMailMsgId& aOriginalMessageId, |
|
353 TBool aReplyToAll ) |
|
354 { |
|
355 FUNC_LOG; |
|
356 // find orginal message header and check that body is fetched |
|
357 TMsvEntry orgMsg; |
|
358 TMsvId service; |
|
359 User::LeaveIfError( |
|
360 iSession.GetEntry( aOriginalMessageId.Id(), service, orgMsg ) ); |
|
361 |
|
362 if ( orgMsg.Id() == KMsvNullIndexEntryIdValue ) |
|
363 { |
|
364 User::Leave(KErrNotFound); |
|
365 } |
|
366 |
|
367 // In case original message is in Sent folder, it's serviceId must be |
|
368 // changed before starting forward/reply msg creation operation |
|
369 // (after forward msg is created, this is changed back) |
|
370 TMsvId orgServiceId( 0 ); |
|
371 if ( ( orgMsg.Parent() == KMsvSentEntryIdValue ) && |
|
372 ( orgMsg.iMtm == KSenduiMtmSmtpUid ) ) |
|
373 { |
|
374 orgServiceId = orgMsg.iServiceId; |
|
375 ChangeServiceIdL( orgMsg ); |
|
376 } |
|
377 |
|
378 // partList flags control e.g. what kind of recipient set is created |
|
379 TMsvPartList partList = KMsvMessagePartBody | KMsvMessagePartDescription |
|
380 | KMsvMessagePartOriginator; |
|
381 if( aReplyToAll ) |
|
382 { |
|
383 partList |= KMsvMessagePartRecipient; |
|
384 } |
|
385 |
|
386 // Ask Symbian messaging fw to create reply message "skeleton" |
|
387 CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC( ); |
|
388 CImEmailOperation* replMailOp = CImEmailOperation::CreateReplyL( |
|
389 wait->iStatus, |
|
390 iSession, |
|
391 orgMsg.Id(), |
|
392 KMsvDraftEntryId, |
|
393 partList, |
|
394 0, |
|
395 KUidMsgTypeSMTP ); |
|
396 CleanupStack::PushL( replMailOp ); |
|
397 wait->Start(); |
|
398 TMsvId msgId = GetIdFromProgressL( replMailOp->FinalProgress() ); |
|
399 CleanupStack::PopAndDestroy( 2, wait ); |
|
400 |
|
401 // If original message's serviceId was changed prior to forward/reply msg |
|
402 // creation op, changing it back to the original |
|
403 if ( orgServiceId ) |
|
404 { |
|
405 ChangeServiceIdL( orgMsg, orgServiceId ); |
|
406 } |
|
407 |
|
408 // Start finalising new FS style message |
|
409 CFSMailMessage* fsMsg = CreateFSMessageAndSetFlagsL( |
|
410 msgId, orgMsg.Id(), aMailBoxId.Id() ); |
|
411 CleanupStack::PushL( fsMsg ); // *** |
|
412 |
|
413 // dig out new reply message's header |
|
414 CMsvEntry* cEntry = iSession.GetEntryL( msgId ); |
|
415 CleanupStack::PushL( cEntry ); // *** |
|
416 CMsvStore* store = cEntry->ReadStoreL(); |
|
417 CleanupStack::PushL( store ); // *** |
|
418 if( store->IsPresentL( KUidMsgFileIMailHeader ) == EFalse ) |
|
419 { |
|
420 User::Leave(KErrCorrupt); |
|
421 } |
|
422 CImHeader* header = CImHeader::NewLC(); // *** |
|
423 header->RestoreL( *store ); |
|
424 |
|
425 // Start handling recipients |
|
426 HBufC* emailAddr( NULL ); |
|
427 CFSMailAddress* fsAddr( NULL ); |
|
428 // copy to recipients |
|
429 for( TInt i = 0; i < header->ToRecipients().Count(); i++ ) |
|
430 { |
|
431 emailAddr = header->ToRecipients()[i].AllocLC(); // *** |
|
432 fsAddr = CFSMailAddress::NewLC(); // *** |
|
433 fsAddr->SetEmailAddress( *emailAddr ); // Copy created |
|
434 fsMsg->AppendToRecipient( fsAddr ); // No copy |
|
435 CleanupStack::Pop( fsAddr ); // fsAddr belong now to fsMsg |
|
436 CleanupStack::PopAndDestroy( emailAddr ); // emailAddr not used |
|
437 } |
|
438 // copy cc recipients |
|
439 // <cmail> |
|
440 TFSMailMsgId folderId; |
|
441 TFSMailDetails details( EFSMsgDataEnvelope ); |
|
442 CFSMailMessage* originalMessage = iPlugin.GetMessageByUidL( aMailBoxId, |
|
443 folderId, aOriginalMessageId, details ); |
|
444 CleanupStack::PushL( originalMessage ); |
|
445 // <qmail> return by value, because Qt types are used for internal CFSMailAddress data storage |
|
446 const RPointerArray<CFSMailAddress>& originalToRecipients = |
|
447 originalMessage->GetToRecipients(); |
|
448 // </qmail> |
|
449 TInt originalToRecipientsCount = originalToRecipients.Count(); |
|
450 TBool present = EFalse; |
|
451 // </cmail> |
|
452 for( TInt i = 0; i < header->CcRecipients().Count(); i++ ) |
|
453 { |
|
454 emailAddr = header->CcRecipients()[i].AllocLC(); // *** |
|
455 fsAddr = CFSMailAddress::NewLC(); // *** |
|
456 fsAddr->SetEmailAddress( *emailAddr ); // Copy created |
|
457 // <cmail> |
|
458 if( aReplyToAll ) |
|
459 { |
|
460 // check if CC recipient read from header was present in To field |
|
461 // of original message. If so, copy it into To recipietns |
|
462 present = EFalse; |
|
463 for( TInt j = 0; j < originalToRecipientsCount; j++ ) |
|
464 { |
|
465 if( emailAddr->Find( originalToRecipients[j]->GetEmailAddress()) |
|
466 != KErrNotFound ) |
|
467 { |
|
468 present = ETrue; |
|
469 break; |
|
470 } |
|
471 } |
|
472 if( present ) |
|
473 { |
|
474 fsMsg->AppendToRecipient( fsAddr ); // No copy |
|
475 } |
|
476 else |
|
477 { |
|
478 fsMsg->AppendCCRecipient( fsAddr ); // No copy |
|
479 } |
|
480 } |
|
481 else |
|
482 { |
|
483 fsMsg->AppendCCRecipient( fsAddr ); // No copy |
|
484 } |
|
485 // </cmail> |
|
486 CleanupStack::Pop( fsAddr ); // fsAddr belong now to fsMsg |
|
487 CleanupStack::PopAndDestroy( emailAddr ); // emailAddr not used |
|
488 } |
|
489 // <cmail> |
|
490 CleanupStack::PopAndDestroy( originalMessage ); |
|
491 // </cmail> |
|
492 // copy bcc recipients |
|
493 for( TInt i = 0; i < header->BccRecipients().Count(); i++ ) |
|
494 { |
|
495 emailAddr = header->BccRecipients()[i].AllocLC(); // *** |
|
496 fsAddr = CFSMailAddress::NewLC(); // *** |
|
497 fsAddr->SetEmailAddress( *emailAddr ); // Copy created |
|
498 fsMsg->AppendBCCRecipient( fsAddr ); // No copy |
|
499 CleanupStack::Pop( fsAddr ); // fsAddr belong now to fsMsg |
|
500 CleanupStack::PopAndDestroy( emailAddr ); // emailAddr not used |
|
501 } |
|
502 |
|
503 CleanupStack::PopAndDestroy( 3, cEntry ); // header, store, cEntry |
|
504 CleanupStack::Pop( fsMsg ); // fsMsg is given to client |
|
505 return fsMsg; |
|
506 } |
|
507 |
250 |
508 // --------------------------------------------------------------------------- |
251 // --------------------------------------------------------------------------- |
509 // CIpsPlgSmtpService::ChangeServiceIdL |
252 // CIpsPlgSmtpService::ChangeServiceIdL |
510 // --------------------------------------------------------------------------- |
253 // --------------------------------------------------------------------------- |
511 // |
254 // |