serviceproviders/sapi_messaging/messagingservice/src/sendmessage.cpp
changeset 11 5c0037c72160
parent 5 989d2f495d90
child 23 50974a8b132e
equal deleted inserted replaced
10:fc9cf246af83 11:5c0037c72160
    18 
    18 
    19 #include <e32base.h>
    19 #include <e32base.h>
    20 #include <senduiconsts.h>
    20 #include <senduiconsts.h>
    21 #include <mmsconst.h>
    21 #include <mmsconst.h>
    22 #include <CMsvAttachment.h>
    22 #include <CMsvAttachment.h>
    23 
    23 #include <aknenv.h>
       
    24 #include <MTCLREG.H>
       
    25 #include <UTF.H>
       
    26 #include <mturutils.h>      
       
    27 #include <aknenv.h>
    24 #include <APGCLI.H>
    28 #include <APGCLI.H>
       
    29 #include <smsclnt.h>
       
    30 #include <TXTRICH.H>
       
    31 #include <smuthdr.h>
       
    32 #include <smscmds.h>
       
    33 #include <mtmuibas.h>
       
    34 #include <mtuireg.h>
       
    35 
       
    36 
       
    37 #include <s32mem.h>
       
    38 
    25 
    39 
    26 #include "messageheader.h"
    40 #include "messageheader.h"
    27 #include "sendmessage.h"
    41 #include "sendmessage.h"
    28 
    42 
       
    43 
       
    44 
       
    45 
       
    46 
       
    47 
    29 _LIT(KBodyTextFilePath,"C:\\");
    48 _LIT(KBodyTextFilePath,"C:\\");
    30 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    31 // Two-phased constructor.
    50 // Two-phased constructor.
    32 // ---------------------------------------------------------------------------
    51 // ---------------------------------------------------------------------------
    33 //
    52 //
    34 CSendMessage* CSendMessage::NewL( CMsvSession& aServerSession )
    53 CSendMessage* CSendMessage::NewL( CMsvSession& aServerSession )
    35 	{
    54 	{
    36 	CSendMessage* self = new (ELeave) CSendMessage( aServerSession );
    55 	CSendMessage* self = new (ELeave) CSendMessage( aServerSession );
       
    56 	
    37 	return self;
    57 	return self;
    38 	}
    58 	}
    39 
    59 
    40 // ---------------------------------------------------------------------------
    60 // ---------------------------------------------------------------------------
    41 // Destructor.
    61 // Destructor.
    49 		Cancel();
    69 		Cancel();
    50 		}
    70 		}
    51 	
    71 	
    52 	iMessage.Close();
    72 	iMessage.Close();
    53 	iSendAs.Close();
    73 	iSendAs.Close();
    54 	
       
    55 	delete iMessageParam;
    74 	delete iMessageParam;
    56 	delete iNotifyCallback;
    75 	delete iNotifyCallback;
    57 	delete iTemplateDetail;
    76 	delete iTemplateDetail;
    58 	}
    77 	}
    59 
    78 
    93 void CSendMessage::SendMessageL()
   112 void CSendMessage::SendMessageL()
    94 	{
   113 	{
    95 	if ( iNotifyCallback ) // making call as asynchronous
   114 	if ( iNotifyCallback ) // making call as asynchronous
    96 		{
   115 		{
    97 		CActiveScheduler::Add( this );
   116 		CActiveScheduler::Add( this );
    98 		iMessageState = EInitialize;
   117 		if ( iMessageParam->MessageType() == KSenduiMtmSmsUid )
       
   118 		    {
       
   119 		    iMessageState = ESend;
       
   120 		    }
       
   121 		else
       
   122 		    {
       
   123 		    iMessageState = EInitialize;
       
   124 		    }
    99 		ActivateRequest( KErrNone );
   125 		ActivateRequest( KErrNone );
   100 		}
   126 		}
   101 	else				// making call as synchronous
   127 	else				// making call as synchronous
   102 		{
   128 		{
   103 		InitializeL();
   129 		if ( iMessageParam->MessageType() == KSenduiMtmMmsUid )
   104 		ValidateL();
   130 		    {
       
   131             InitializeL();
       
   132             ValidateL();
       
   133 		    }
   105 		SendL();
   134 		SendL();
   106 		}
   135 		}
   107 	}
   136 	}
   108 	
   137 	
   109 // ---------------------------------------------------------------------------
   138 // ---------------------------------------------------------------------------
   120 // ---------------------------------------------------------------------------
   149 // ---------------------------------------------------------------------------
   121 //
   150 //
   122 void CSendMessage::RunL()
   151 void CSendMessage::RunL()
   123 	{
   152 	{
   124 	TInt err = iStatus.Int();
   153 	TInt err = iStatus.Int();
       
   154 	
   125 	if ( err == KErrNone )
   155 	if ( err == KErrNone )
   126 		{
   156 		{
   127 		switch ( iMessageState )
   157 		switch ( iMessageState )
   128 			{
   158 			{
   129 			case EInitialize: 
   159 			case EInitialize: 
   153 			case EComplete: 
   183 			case EComplete: 
   154 				{
   184 				{
   155 				NotifyRequestResult( err );
   185 				NotifyRequestResult( err );
   156 				}
   186 				}
   157 				break;
   187 				break;
   158 					
   188 						
   159 			default:
   189 			default:
   160 				NotifyRequestResult( KErrGeneral );	
   190 				NotifyRequestResult( KErrGeneral );	
   161 				break;	
   191 				break;	
   162 			}
   192 			}
   163 		}
   193 		}
   174 void CSendMessage::InitializeL()
   204 void CSendMessage::InitializeL()
   175 	{
   205 	{
   176 	TInt err;
   206 	TInt err;
   177 	
   207 	
   178 	err = iSendAs.Connect();
   208 	err = iSendAs.Connect();
   179 
   209 	
   180 	if ( err == KErrNone )
   210 	if ( err == KErrNone )
   181 		{
   211         {
   182 		iMessage.CreateL( iSendAs, iMessageParam->MessageType() );
   212         iMessage.CreateL( iSendAs, iMessageParam->MessageType() );
   183 		}
   213         }
   184 	else
   214     else
   185 		{
   215         {
   186 		User::Leave(err);	
   216         User::Leave(err);   
   187 		}
   217         }
   188 	
   218 
   189 	if ( iTemplateDetail )
   219 	if ( iTemplateDetail )
   190 		{
   220 		{
   191 		if ( iTemplateDetail->BodyText().Length() )
   221 		if ( iTemplateDetail->BodyText().Length() )
   192 			{
   222 			{
   193 			iMessageParam->AppendBodyTextL( iTemplateDetail->BodyText() );
   223 			iMessageParam->AppendBodyTextL( iTemplateDetail->BodyText() );
   204 				TBuf8<KMaxFileName> tmpMime;
   234 				TBuf8<KMaxFileName> tmpMime;
   205 				tmpMime.Copy( element->MimeType() );
   235 				tmpMime.Copy( element->MimeType() );
   206 				
   236 				
   207 				TRequestStatus stat;
   237 				TRequestStatus stat;
   208 				RFile fileHandle = element->FileHandle();
   238 				RFile fileHandle = element->FileHandle();
   209 				iMessage.AddAttachment( fileHandle, tmpMime, stat );
   239 				
       
   240 				if(tmpMime.CompareF(KMmsTextPlain))
       
   241 				   {
       
   242 				   iMessage.AddAttachment( fileHandle, tmpMime, 0, stat );
       
   243 				   }
       
   244 				else
       
   245 				   {
       
   246 				   iMessage.AddAttachment( fileHandle, tmpMime, stat );				
       
   247 				   }
   210 				User::WaitForRequest( stat );
   248 				User::WaitForRequest( stat );
   211 
   249 
   212 				}
   250 				}
   213 			}
   251 			}
   214 			
   252 			
   233 // Internal function 
   271 // Internal function 
   234 // ---------------------------------------------------------------------------
   272 // ---------------------------------------------------------------------------
   235 //
   273 //
   236 void CSendMessage::SendL()
   274 void CSendMessage::SendL()
   237 	{
   275 	{
   238 	if( iMessageParam->LaunchEditor() )
   276 	if ( iMessageParam->MessageType() == KSenduiMtmSmsUid )
   239 		{
   277 	    {
   240 		iMessage.LaunchEditorAndCloseL();
   278  	    SendSMSMessageL();
   241 		}
   279 	    }
   242 	else
   280 	else if ( iMessageParam->MessageType() == KSenduiMtmMmsUid )
   243 		{
   281 	    {
   244 		iMessage.SendMessageAndCloseL();	
   282         if( iMessageParam->LaunchEditor() )
   245 		}
   283             {
       
   284             iMessage.LaunchEditorAndCloseL();
       
   285             }
       
   286         else
       
   287             {
       
   288             iMessage.SendMessageAndCloseL();
       
   289             }
       
   290 	    }
       
   291 	
   246 	if( iBodyTextFileFlag )	//If the bodytext attach file is created for mms, delete it
   292 	if( iBodyTextFileFlag )	//If the bodytext attach file is created for mms, delete it
   247 		{
   293 		{
   248 		RFs rFs;
   294 		RFs rFs;
   249     	if( rFs.Connect() == KErrNone )
   295     	if( rFs.Connect() == KErrNone )
   250     		{
   296     		{
   251     		rFs.Delete( iBodyTextFileName ); //if found delete it b4 creating it
   297     		rFs.Delete( iBodyTextFileName ); //if found delete it b4 creating it
   252    			rFs.Close();	
   298    			rFs.Close();	
   253     		}
   299     		}
   254 		}	
   300 		}
   255 	}
   301 	}
   256 
   302 
   257 // ---------------------------------------------------------------------------
   303 // ---------------------------------------------------------------------------
   258 // Activates the asynchronous request
   304 // Activates the asynchronous request
   259 // ---------------------------------------------------------------------------
   305 // ---------------------------------------------------------------------------
   324 // Sets body text to message.
   370 // Sets body text to message.
   325 // ---------------------------------------------------------------------------
   371 // ---------------------------------------------------------------------------
   326 //
   372 //
   327 void CSendMessage::AddBodyTextL()
   373 void CSendMessage::AddBodyTextL()
   328 	{
   374 	{
       
   375 	
   329 	TPtrC filePath( KBodyTextFilePath );
   376 	TPtrC filePath( KBodyTextFilePath );
   330 	
   377 	
   331 	TPtrC bodyText = iMessageParam->BodyText();
   378 	TPtrC bodyText = iMessageParam->BodyText();
   332 	
   379 	
   333 	if ( bodyText.Length() )
   380 	if ( bodyText.Length() )
   340    			
   387    			
   341     		tmpfile.Temp(rFs, filePath, iBodyTextFileName, EFileShareExclusive|EFileWrite);
   388     		tmpfile.Temp(rFs, filePath, iBodyTextFileName, EFileShareExclusive|EFileWrite);
   342 			
   389 			
   343 			iBodyTextFileFlag = ETrue;
   390 			iBodyTextFileFlag = ETrue;
   344 			
   391 			
   345 			HBufC8* buffer=HBufC8::NewL( bodyText.Length() );
   392 			HBufC8* buffer=HBufC8::NewL( bodyText.Length()* 4  );
       
   393 			TPtr8 tmpBuffer = buffer->Des();
       
   394 			CnvUtfConverter::ConvertFromUnicodeToUtf8(tmpBuffer, bodyText);
   346 			CleanupStack::PushL( buffer );
   395 			CleanupStack::PushL( buffer );
   347 			buffer->Des().Copy( bodyText );
   396 			buffer->Des().Copy( tmpBuffer );
   348 			tmpfile.Write( *buffer ); 
   397 			tmpfile.Write( *buffer ); 
   349 			tmpfile.Flush();
   398 			tmpfile.Flush();
   350 			tmpfile.Close();			
   399 			tmpfile.Close();			
   351 			rFs.Close();
   400 			rFs.Close();
   352 			CleanupStack::PopAndDestroy( buffer );
   401 			CleanupStack::PopAndDestroy( buffer );
   353 			
       
   354 			TRequestStatus stat;
   402 			TRequestStatus stat;
   355 			iMessage.AddAttachment( iBodyTextFileName, KMmsTextPlain, stat );
   403 			iMessage.AddAttachment( iBodyTextFileName, KMmsTextPlain, 0, stat );
   356 			User::WaitForRequest( stat );
   404 			User::WaitForRequest( stat );
   357 			}
   405 			}
   358 		else
   406 		else
   359 			{
   407 			{
   360 			iMessage.SetBodyTextL( bodyText );	
   408 			iMessage.SetBodyTextL( bodyText );	
   393 			error = tmpfile.Open(rFs, ((*attachmentArray)[count])->AttachmentName(), EFileRead);
   441 			error = tmpfile.Open(rFs, ((*attachmentArray)[count])->AttachmentName(), EFileRead);
   394 			
   442 			
   395 			if( error == KErrNone )
   443 			if( error == KErrNone )
   396 				{
   444 				{
   397 				TBuf8<256> tmpbuf;
   445 				TBuf8<256> tmpbuf;
   398 				
       
   399 				tmpfile.Read(tmpbuf, 255 );
   446 				tmpfile.Read(tmpbuf, 255 );
   400 				
   447 				
   401 				tmpfile.Close();
   448 				tmpfile.Close();
   402 				
   449 				
   403 				TDataRecognitionResult aDataType;
   450 				TDataRecognitionResult aDataType;
   404 				
   451 				
   405 				error = rapaSesion.RecognizeData(((*attachmentArray)[count])->AttachmentName(), tmpbuf, aDataType);
   452 				error = rapaSesion.RecognizeData(((*attachmentArray)[count])->AttachmentName(), tmpbuf, aDataType);
   406 				
   453 				
       
   454 				               
       
   455 				                
   407 				if( error == KErrNone )
   456 				if( error == KErrNone )
   408 					{
   457 					{
   409 					TBuf8< KMaxDataTypeLength > tmp;
   458 					TBuf8< KMaxDataTypeLength > tmp;
   410 					tmp.Copy( aDataType.iDataType.Des() );
   459 					tmp.Copy( aDataType.iDataType.Des() );
   411 					
   460 					
   412 					iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(),
   461 					if(!(tmp.CompareF(KMmsTextPlain)))
       
   462                         {
       
   463                         iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(),
       
   464                                                                         tmp, 0,
       
   465                                                                         attachstatus ); 
       
   466                         }
       
   467 					else
       
   468 					    {
       
   469 					    iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(),
   413 												tmp,
   470 												tmp,
   414 												attachstatus );																										
   471 												attachstatus );								
       
   472 					    }
   415 					}
   473 					}
   416 				else
   474 				else
   417 					{					
   475 					{					
   418 					if ( ((*attachmentArray)[count])->MimeType().Length() )
   476 					if ( ((*attachmentArray)[count])->MimeType().Length() )
   419 						{
   477 						{
       
   478 						
   420 						iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(),
   479 						iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(),
   421 												((*attachmentArray)[count])->MimeType(),
   480 												((*attachmentArray)[count])->MimeType(),
   422 												attachstatus );
   481 												attachstatus );
   423 						}
   482 						}
   424 					else
   483 					else
   425 						{
   484 						{
       
   485 						
   426 						iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), 
   486 						iMessage.AddAttachment( ((*attachmentArray)[count])->AttachmentName(), 
   427 												attachstatus );
   487 												attachstatus );
   428 						}
   488 						}
   429 					}	
   489 					}	
   430 				
   490 				
   435 			else
   495 			else
   436 				{
   496 				{
   437 				User::Leave( error );				
   497 				User::Leave( error );				
   438 				}	
   498 				}	
   439 			}
   499 			}
       
   500 
   440 		CleanupStack::PopAndDestroy( &rFs );	
   501 		CleanupStack::PopAndDestroy( &rFs );	
   441 		CleanupStack::PopAndDestroy( &rapaSesion );
   502 		CleanupStack::PopAndDestroy( &rapaSesion );
   442 		}
   503 		}
   443 	}
   504 	}
   444 
   505 
   445 	
   506 // ---------------------------------------------------------------------------
       
   507 // Two-phased constructor.
       
   508 // ---------------------------------------------------------------------------
       
   509 //
       
   510 CAsyncWaiter* CAsyncWaiter::NewL(TInt aPriority)
       
   511     {
       
   512     CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority);
       
   513     return self;
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // Two-phased constructor.
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 CAsyncWaiter* CAsyncWaiter::NewLC(TInt aPriority)
       
   521     {
       
   522     CAsyncWaiter* self = new(ELeave) CAsyncWaiter(aPriority);
       
   523     CleanupStack::PushL(self);
       
   524     return self;
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // Two-phased constructor.
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 CAsyncWaiter::CAsyncWaiter(TInt aPriority) : CActive(aPriority)
       
   532     {
       
   533     CActiveScheduler::Add(this);
       
   534     }   
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // Destructor.
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 CAsyncWaiter::~CAsyncWaiter()
       
   541     {
       
   542     Cancel();
       
   543     }
       
   544 
       
   545 // ---------------------------------------------------------------------------
       
   546 // Starts the active scheduler.
       
   547 // ---------------------------------------------------------------------------
       
   548 //
       
   549 void CAsyncWaiter::StartAndWait()
       
   550     {
       
   551     iStatus = KRequestPending;
       
   552     SetActive();
       
   553     iWait.Start();
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // Returns the error
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 TInt CAsyncWaiter::Result() const
       
   561     {
       
   562     return iError;
       
   563     }
       
   564 
       
   565 // ---------------------------------------------------------------------------
       
   566 // Inherited from CActive class 
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 void CAsyncWaiter::RunL()
       
   570     {
       
   571     iError = iStatus.Int();
       
   572     iWait.AsyncStop();
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------------------------
       
   576 // Inherited from CActive class 
       
   577 // ---------------------------------------------------------------------------
       
   578 //
       
   579 void CAsyncWaiter::DoCancel()
       
   580     {
       
   581     iError = KErrCancel;
       
   582     if( iStatus == KRequestPending )
       
   583         {
       
   584         TRequestStatus* s=&iStatus;
       
   585         User::RequestComplete( s, KErrCancel );
       
   586         }
       
   587 
       
   588     iWait.AsyncStop();
       
   589     }
       
   590 
       
   591 // ---------------------------------------------------------------------------
       
   592 // Sends the sms.
       
   593 // ---------------------------------------------------------------------------
       
   594 //
       
   595 void CSendMessage::SendSMSMessageL()
       
   596     {
       
   597     if ( iTemplateDetail )
       
   598         {
       
   599         if ( iTemplateDetail->BodyText().Length() )
       
   600             {
       
   601             iMessageParam->AppendBodyTextL( iTemplateDetail->BodyText() );
       
   602             }
       
   603         delete iTemplateDetail;
       
   604         iTemplateDetail = NULL;
       
   605         }
       
   606 
       
   607     CClientMtmRegistry* registry = CClientMtmRegistry::NewL(iServerSession);
       
   608     CleanupStack::PushL(registry);
       
   609     
       
   610     // get the client mtm and return if it isn't supported in the system        
       
   611     CSmsClientMtm* clientMtm = NULL;
       
   612     TRAPD(err, clientMtm = static_cast<CSmsClientMtm*>(registry->NewMtmL(KUidMsgTypeSMS)));
       
   613     if (err || !clientMtm)
       
   614         {
       
   615         User::Leave(KErrNotFound);
       
   616         }  
       
   617     CleanupStack::PushL(clientMtm);   
       
   618     
       
   619     // create a new object to access an existing entry
       
   620     CMsvEntry* msvEntry = CMsvEntry::NewL(iServerSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
       
   621     CleanupStack::PushL(msvEntry);
       
   622     
       
   623     // get default service
       
   624     TMsvId defaultServiceId = 0;
       
   625     TRAP(err, defaultServiceId = clientMtm->DefaultServiceL());
       
   626     if (err)
       
   627         {
       
   628         User::Leave(KErrNotFound);
       
   629         } 
       
   630     
       
   631     if( iMessageParam->LaunchEditor() )
       
   632         {
       
   633         msvEntry->SetEntryL(KMsvDraftEntryId);
       
   634         }
       
   635     else
       
   636         {
       
   637         msvEntry->SetEntryL(KMsvGlobalOutBoxIndexEntryId);
       
   638         }
       
   639         
       
   640     // mtm takes ownership of entry context 
       
   641     CleanupStack::Pop(msvEntry);
       
   642     clientMtm->SetCurrentEntryL(msvEntry);    
       
   643     
       
   644     // create a new message
       
   645     clientMtm->CreateMessageL(defaultServiceId);
       
   646     
       
   647   
       
   648     // set body
       
   649     clientMtm->Body().Reset();
       
   650     clientMtm->Body().InsertL(0, iMessageParam->BodyText());        
       
   651     TPtrC subject( iMessageParam->Subject());
       
   652     if ( subject.Length() )
       
   653         clientMtm->SetSubjectL( iMessageParam->Subject() );
       
   654     // get the entry of the message
       
   655     TMsvEntry messageEntry = clientMtm->Entry().Entry();
       
   656     
       
   657     const CRecipientList* recipientArray = iMessageParam->RecipientArray();
       
   658     if ( recipientArray )
       
   659         {
       
   660         TInt count = recipientArray->Count();
       
   661         if(count)
       
   662            {
       
   663            messageEntry.iDetails.Set((*recipientArray)[0]);
       
   664            }
       
   665         for( TInt pos = 0; pos < count; pos++ )
       
   666             {
       
   667             clientMtm->AddAddresseeL(( *recipientArray)[pos]);
       
   668             }
       
   669          }
       
   670    
       
   671     // set the description field same as the first part of the message body
       
   672     messageEntry.iDescription.Set( iMessageParam->BodyText().Left(KSmsDescriptionLength) );
       
   673     
       
   674   
       
   675     CSmsHeader& smsHdr = clientMtm->SmsHeader();
       
   676     CSmsSettings* smsSetting = CSmsSettings::NewLC();
       
   677     smsSetting->CopyL(clientMtm->ServiceSettings());
       
   678     smsSetting->SetCharacterSet(TSmsDataCodingScheme::ESmsAlphabetUCS2);
       
   679     smsHdr.SetSmsSettingsL(*smsSetting);
       
   680     CleanupStack::PopAndDestroy(smsSetting);
       
   681 
       
   682     // save the changes done above
       
   683     clientMtm->Entry().ChangeL(messageEntry);
       
   684     
       
   685     // save the message     
       
   686     clientMtm->SaveMessageL();
       
   687     
       
   688     
       
   689     // final fine tuning
       
   690     messageEntry.SetAttachment(EFalse);
       
   691     messageEntry.iDate.DateTime().SetSecond( messageEntry.iDate.DateTime().Second()+1);
       
   692     messageEntry.SetVisible(ETrue);
       
   693     messageEntry.SetInPreparation(EFalse);
       
   694     messageEntry.SetComplete(ETrue);
       
   695     messageEntry.iServiceId = defaultServiceId;
       
   696     messageEntry.iRelatedId = 0;
       
   697     if( iMessageParam->LaunchEditor() )
       
   698         {
       
   699         messageEntry.SetSendingState( KMsvSendStateNotApplicable );
       
   700         }
       
   701     else
       
   702         {
       
   703         messageEntry.SetSendingState( KMsvSendStateWaiting );
       
   704         }
       
   705    
       
   706     clientMtm->Entry().ChangeL(messageEntry);
       
   707     clientMtm->SaveMessageL();
       
   708    
       
   709     if( iMessageParam->LaunchEditor() )
       
   710         {
       
   711         MturUtils::LaunchEditorAndWaitL(messageEntry.Id());
       
   712         }
       
   713     else
       
   714         {
       
   715         CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection;
       
   716         CleanupStack::PushL(sel);
       
   717         sel->AppendL(messageEntry.Id());
       
   718             
       
   719         TBuf8<1> dummy;
       
   720         CAsyncWaiter* waiter = CAsyncWaiter::NewL();
       
   721         CleanupStack::PushL(waiter);
       
   722         CMsvOperation* sndCall = clientMtm->InvokeAsyncFunctionL(ESmsMtmCommandScheduleCopy,*sel,dummy,waiter->iStatus);
       
   723         CleanupStack::PushL(sndCall);
       
   724         waiter->StartAndWait();
       
   725         CleanupStack::PopAndDestroy(2); //sndCall, waiter
       
   726         sel->Reset();
       
   727         CleanupStack::PopAndDestroy(sel);
       
   728        }
       
   729      CleanupStack::PopAndDestroy(2);//registry, clientMtm
       
   730      }
       
   731 
       
   732