emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp
branchRCL_3
changeset 24 d189ee25cf9d
parent 16 b5fbb9b25d57
child 25 3533d4323edc
equal deleted inserted replaced
23:dcf0eedfc1a3 24:d189ee25cf9d
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Email interface implementation.
    14 * Description:  Email interface implementation.
    15 *
    15 *
    16 */
    16 */
    17 #include "msgstorewritablepropertycontainer.h"
    17 
       
    18 //<qmail>
       
    19 #include <utf.h>
       
    20 //<//qmail>
       
    21 
       
    22 #include "MsgStoreWritablePropertyContainer.h"
    18 
    23 
    19 #include "baseplugindelayedops.h"
    24 #include "baseplugindelayedops.h"
    20 #include "baseplugindelayedopsprivate.h"
    25 #include "baseplugindelayedopsprivate.h"
    21 
    26 
    22 ///////////////////////////////////////////////////
    27 ///////////////////////////////////////////////////
    24 ///////////////////////////////////////////////////
    29 ///////////////////////////////////////////////////
    25 
    30 
    26 /**
    31 /**
    27  * 
    32  * 
    28  */
    33  */
    29 /*public virtual*/ EXPORT_C CDelayedOp::~CDelayedOp()
    34 /*public virtual*/  CDelayedOp::~CDelayedOp()
    30     {
    35     {
    31     Cancel();
    36     Cancel();
    32     __LOG_DESTRUCT
    37     __LOG_DESTRUCT
    33     }
    38     }
    34 
    39 
    35 /**
    40 /**
    36  * 
    41  * 
    37  */
    42  */
    38 /*public*/ EXPORT_C void CDelayedOp::SetContext(
    43 /*public*/  void CDelayedOp::SetContext(
    39     CBasePlugin& aPlugin, MDelayedOpsManager& aManager )
    44     CBasePlugin& aPlugin, MDelayedOpsManager& aManager )
    40     {
    45     {
    41     iPlugin = &aPlugin;
    46     iPlugin = &aPlugin;
    42     iManager = &aManager;
    47     iManager = &aManager;
    43     } 
    48     } 
    44 
    49 
    45 /**
    50 /**
    46  * 
    51  * 
    47  */
    52  */
    48 /*public*/ EXPORT_C void CDelayedOp::StartOp()
    53 /*public*/  void CDelayedOp::StartOp()
    49     {
    54     {
    50     iStatus = KRequestPending;
    55     iStatus = KRequestPending;
    51     SetActive();
    56     SetActive();
    52     TRequestStatus* pStatus = &iStatus;
    57     TRequestStatus* pStatus = &iStatus;
    53     User::RequestComplete( pStatus, KErrNone );
    58     User::RequestComplete( pStatus, KErrNone );
    54     } 
    59     } 
    55 
    60 /*protected*/  CDelayedOp::CDelayedOp()
    56 /**
       
    57  * 
       
    58  */
       
    59 /*protected*/ EXPORT_C CDelayedOp::CDelayedOp()
       
    60     : CActive( CActive::EPriorityIdle )
    61     : CActive( CActive::EPriorityIdle )
    61     {    
    62     {    
    62     CActiveScheduler::Add( this );
    63     CActiveScheduler::Add( this );
    63     }
    64     }
    64     
    65     
    65 /**
    66 /**
    66  * 
    67  * 
    67  */
    68  */
    68 /*private virtual*/ EXPORT_C void CDelayedOp::RunL()
    69 /*private virtual*/  void CDelayedOp::RunL()
    69     {
    70     {
    70     __LOG_ENTER_SUPPRESS( "Run" );
    71     __LOG_ENTER_SUPPRESS( "Run" );
    71     TBool again( EFalse );
    72     TBool again( EFalse );
    72     
    73     
    73     TRAPD( err, again = ExecuteOpL() );
    74     TRAPD( err, again = ExecuteOpL() );
    84         }
    85         }
    85     else
    86     else
    86         {
    87         {
    87         //self-destroy.
    88         //self-destroy.
    88         iManager->DequeueOp( *this );
    89         iManager->DequeueOp( *this );
       
    90 //<qmail>		
       
    91 		    //Remove this from iDelayedOpReqs as well.
       
    92 	    for ( TInt i = 0; i < iPlugin->iDelayedOpReqs.Count(); i++ )
       
    93 	        {
       
    94 	        if ( iPlugin->iDelayedOpReqs[i] == this )
       
    95 	            {
       
    96 	            iPlugin->iDelayedOpReqs.Remove( i );
       
    97 	            break;
       
    98 	            }
       
    99 	        }
       
   100 //</qmail>			
    89         delete this;
   101         delete this;
    90         }
   102         }
    91     }
   103     }
    92     
   104     
    93 /**
   105 /**
    94  * 
   106  * 
    95  */
   107  */
    96 /*protected*/ EXPORT_C CBasePlugin& CDelayedOp::GetPlugin()
   108 /*protected*/  CBasePlugin& CDelayedOp::GetPlugin()
    97     {
   109     {
    98     return *iPlugin;
   110     return *iPlugin;
    99     }
   111     }
   100 
   112 
   101 /**
   113 /**
   102  * 
   114  * 
   103  */
   115  */
   104 /*private virtual*/ EXPORT_C void CDelayedOp::DoCancel()
   116 /*private virtual*/  void CDelayedOp::DoCancel()
   105     {
   117     {
   106     }
   118     }
   107 
   119 
   108 
   120 
   109 ///////////////////////////////////////////////////
   121 ///////////////////////////////////////////////////
   295     __LOG_ENTER( "ExecuteOpL" );
   307     __LOG_ENTER( "ExecuteOpL" );
   296 
   308 
   297     //Maximum number of messages deleted in one go
   309     //Maximum number of messages deleted in one go
   298     const TInt KNumOfDeletesBeforeYield = 30;
   310     const TInt KNumOfDeletesBeforeYield = 30;
   299 
   311 
       
   312     //<qmail>
       
   313     TInt result(KErrNone);
       
   314 
   300     TBool runAgain = ETrue;
   315     TBool runAgain = ETrue;
   301     TInt  endIndex = iIndex + KNumOfDeletesBeforeYield;
   316     TInt endIndex = iIndex + KNumOfDeletesBeforeYield;
   302 
   317 
   303     if( endIndex >= iMessages.Count() )
   318     if (endIndex >= iMessages.Count())
   304         {
   319         {
   305         endIndex = iMessages.Count();   
   320         endIndex = iMessages.Count();
   306         runAgain = EFalse;  // last time, no need to run again.
   321         runAgain = EFalse; // last time, no need to run again.
   307         }
   322         }
   308 
   323 
   309     CMailboxInfo& mailBoxInfo = GetPlugin().GetMailboxInfoL( iMailBoxId );
   324     CMailboxInfo& mailBoxInfo = GetPlugin().GetMailboxInfoL(iMailBoxId);
   310     CMsgStoreMailBox& mailBox = mailBoxInfo();
   325     CMsgStoreMailBox& mailBox = mailBoxInfo();
   311 
   326 
   312     for ( ; iIndex < endIndex; iIndex++ )
   327     for (; iIndex < endIndex; iIndex++)
   313         {
   328         {
   314         TMsgStoreId msgId = iMessages[iIndex];
   329         TMsgStoreId msgId = iMessages[iIndex];
   315         
   330 
   316         if ( EFalse == iImmediateDelete )
   331         if (EFalse == iImmediateDelete)
   317             {
   332             {
   318             //try to find the message in the deleted items folder.
   333             //try to find the message
   319             CMsgStoreMessage* theMessage = NULL;
   334             CMsgStoreMessage* theMessage = NULL;
   320             TRAP_IGNORE( theMessage = mailBox.FetchMessageL(
   335             theMessage = mailBox.FetchMessageL(msgId, KMsgStoreInvalidId);
   321                     msgId, mailBoxInfo.iRootFolders.iFolders[ EFSDeleted ] ) );
   336             //save parentId
   322             
   337             TMsgStoreId msgParentId;
   323             if ( NULL == theMessage )
   338             msgParentId = theMessage->ParentId();
       
   339             //check if message is in deleted or drafts folder or not.
       
   340             if (msgParentId != mailBoxInfo.iRootFolders.iFolders[EFSDeleted] &&
       
   341                 msgParentId != mailBoxInfo.iRootFolders.iFolders[EFSDraftsFolder])
   324                 {
   342                 {
   325                 //if not in deleted items then move it there.
   343                 //if not in deleted items then move it there.
   326                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   344                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   327                 mailBox.MoveMessageL( msgId, KMsgStoreInvalidId,
   345                 TRAP(result,mailBox.MoveMessageL(
   328                                       mailBoxInfo.iRootFolders.iFolders[ EFSDeleted ] );
   346                                 msgId, KMsgStoreInvalidId,
       
   347                                 mailBoxInfo.iRootFolders.iFolders[EFSDeleted] ));
       
   348                 if (result == KErrNone)
       
   349                     {
       
   350                     GetPlugin().NotifyEventL(iMailBoxId, msgId,
       
   351                             KMsgStoreInvalidId, TFSEventMailMoved,
       
   352                             msgParentId);
       
   353                     }
       
   354                 else
       
   355                     {
       
   356                     User::Leave(result);
       
   357                     }
       
   358 
   329                 }
   359                 }
   330             else
   360             else
   331                 {
   361                 {
   332                 //in deleted items, really delete it.
   362                 //in deleted items, really delete it.
   333                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   363                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   334 
   364 
   335                 delete theMessage;
   365                 delete theMessage;
   336                 mailBox.DeleteMessageL( msgId, iFolderId );
   366                 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
       
   367                 if (result == KErrNone)
       
   368                     {
       
   369                     GetPlugin().NotifyEventL(iMailBoxId, msgId,
       
   370                             KMsgStoreInvalidId, TFSEventMailDeleted,
       
   371                             iFolderId);
       
   372                     }
       
   373                 else
       
   374                     {
       
   375                     User::Leave(result);
       
   376                     }
   337                 }
   377                 }
   338             }
   378             }
   339         else
   379         else
   340             {
   380             {
   341             mailBox.DeleteMessageL( msgId, iFolderId );
   381             TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
       
   382             if (result == KErrNone)
       
   383                 {
       
   384                 GetPlugin().NotifyEventL(iMailBoxId, msgId,
       
   385                         KMsgStoreInvalidId, TFSEventMailDeleted, iFolderId);
       
   386                 }
       
   387             else
       
   388                 {
       
   389                 User::Leave(result);
       
   390                 }
   342             }
   391             }
   343         }
   392         //</qmail>
   344 
   393         } 
   345     __LOG_EXIT;
   394 		__LOG_EXIT;
   346     return runAgain;
   395     return runAgain;
   347     }
   396     }
   348 
   397 
   349 
   398 
   350 ///////////////////////////////////////////////////
   399 ///////////////////////////////////////////////////
   441         part->StorePropertiesL();
   490         part->StorePropertiesL();
   442         __LOG_WRITE8_FORMAT1_INFO(
   491         __LOG_WRITE8_FORMAT1_INFO(
   443             "Updated the properties of part 0x%X.", part->Id() )
   492             "Updated the properties of part 0x%X.", part->Id() )
   444         }
   493         }
   445     
   494     
   446     CleanupStack::PopAndDestroy( part );
   495     CleanupStack::PopAndDestroy( part );    
   447 
       
   448     __LOG_EXIT
   496     __LOG_EXIT
   449     return EFalse;
   497     return EFalse;
   450     }
   498     }
   451 
   499 
   452 /**
   500 /**
   503     : iMailBoxId( aMailBoxId ), iMessageId( aMessageId ),
   551     : iMailBoxId( aMailBoxId ), iMessageId( aMessageId ),
   504       iMessagePartId( aMessagePartId ), iContentLength( aContentLength ),
   552       iMessagePartId( aMessagePartId ), iContentLength( aContentLength ),
   505       iStepOne( EFalse )
   553       iStepOne( EFalse )
   506     {
   554     {
   507     }
   555     }
       
   556 
       
   557 //<qmail>
       
   558 ///////////////////////////////////////////////////
       
   559 // CDelayedMessageStorerOp                      //
       
   560 ///////////////////////////////////////////////////
       
   561 
       
   562 /**
       
   563  * 
       
   564  */
       
   565 /*public static */ CDelayedMessageStorerOp* CDelayedMessageStorerOp::NewLC(
       
   566         const TFSMailMsgId& aMailBox,
       
   567         RPointerArray<CFSMailMessage> &messages,
       
   568         MFSMailRequestObserver& aOperationObserver,
       
   569         const TInt aRequestId)
       
   570     {
       
   571     CDelayedMessageStorerOp* self = new (ELeave) CDelayedMessageStorerOp(
       
   572             aMailBox, messages, aOperationObserver,aRequestId);
       
   573     CleanupStack::PushL( self );
       
   574     self->ConstructL(  );
       
   575     return self;
       
   576     }
       
   577 
       
   578 /**
       
   579  * 
       
   580  */
       
   581 /*public static */ CDelayedMessageStorerOp* CDelayedMessageStorerOp::NewLC(
       
   582         RPointerArray<CFSMailMessagePart>& aMessageParts,
       
   583         MFSMailRequestObserver& aOperationObserver,
       
   584         const TInt aRequestId)
       
   585     {
       
   586     CDelayedMessageStorerOp* self = new (ELeave) CDelayedMessageStorerOp(
       
   587             aMessageParts, aOperationObserver, aRequestId);
       
   588     CleanupStack::PushL( self );
       
   589     self->ConstructL(  );
       
   590     return self;
       
   591     }
       
   592 
       
   593 /**
       
   594  * 
       
   595  */
       
   596 /*public virtual*/ CDelayedMessageStorerOp::~CDelayedMessageStorerOp()
       
   597     {
       
   598     __LOG_DESTRUCT
       
   599     iMessages.Reset();
       
   600     iMessageParts.Reset();
       
   601     if (iDataBuffer)
       
   602         {
       
   603         delete iDataBuffer;
       
   604         iDataBuffer = NULL;
       
   605         }
       
   606     }
       
   607 
       
   608 /**
       
   609  * 
       
   610  */
       
   611 /*private*/
       
   612 void CDelayedMessageStorerOp::ConstructL( )
       
   613     {
       
   614     __LOG_CONSTRUCT( "baseplugin", "CDelayedMessageStorerOp" );
       
   615         
       
   616     }
       
   617 
       
   618 /**
       
   619  * 
       
   620  */
       
   621 /*private*/ CDelayedMessageStorerOp::CDelayedMessageStorerOp(
       
   622     const TFSMailMsgId& aMailBox,
       
   623     RPointerArray<CFSMailMessage> &messages,
       
   624     MFSMailRequestObserver& aOperationObserver,
       
   625     const TInt aRequestId)
       
   626     : iMailBox( aMailBox ), 
       
   627       iType(EHeaders)
       
   628     {
       
   629     
       
   630     CDelayedOp::iOperationObserver = &aOperationObserver ;
       
   631     CDelayedOp::iRequestId =  aRequestId ;
       
   632        
       
   633     for(TInt i=0; i < messages.Count(); i++)
       
   634         {
       
   635         iMessages.Append(messages[i]);
       
   636         }
       
   637     }
       
   638 
       
   639 /**
       
   640  * 
       
   641  */
       
   642 /*private*/ CDelayedMessageStorerOp::CDelayedMessageStorerOp(
       
   643     RPointerArray<CFSMailMessagePart>& aMessageParts,
       
   644     MFSMailRequestObserver& aOperationObserver,
       
   645     const TInt aRequestId)
       
   646     :iType(EParts)
       
   647     {
       
   648     
       
   649     CDelayedOp::iOperationObserver = &aOperationObserver ;
       
   650     CDelayedOp::iRequestId =  aRequestId ;
       
   651     
       
   652     for(TInt i=0; i < aMessageParts.Count(); i++)
       
   653         {
       
   654         iMessageParts.Append(aMessageParts[i]);
       
   655         }
       
   656     }
       
   657 
       
   658 /**
       
   659  * 
       
   660  */
       
   661 /*private*/ TBool CDelayedMessageStorerOp::ExecuteOpL()
       
   662     {
       
   663     __LOG_ENTER( "ExecuteOpL" );
       
   664    
       
   665     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
       
   666     progress.iError = KErrNotFound;
       
   667     TInt err(KErrNone);
       
   668     
       
   669     switch( iType )
       
   670         {
       
   671         case EHeaders: 
       
   672             {
       
   673             for ( TInt i = 0; i < iMessages.Count(); i++ )
       
   674                 {
       
   675                 TRAP(err, GetPlugin().StoreMessageL(iMailBox, *iMessages[i] ));
       
   676                 if(err!=KErrNone)
       
   677                     {
       
   678                     break;
       
   679                     }
       
   680                 }
       
   681             break;
       
   682             }
       
   683             
       
   684         case EParts:
       
   685             {
       
   686                 for ( TInt i = 0; i < iMessageParts.Count(); i++ )
       
   687                 {
       
   688                 CFSMailMessagePart& part= *iMessageParts[i];
       
   689                 TFSMailMsgId messageId= part.GetMessageId();
       
   690                 TFSMailMsgId folderId= part.GetFolderId();
       
   691                 
       
   692                 if (part.GetContentType().Compare(KFSMailContentTypeTextPlain) == 0 ||
       
   693                         part.GetContentType().Compare(KFSMailContentTypeTextHtml) == 0)
       
   694                     {
       
   695                     TRAP(err,StorePartL(&part));
       
   696                     if(err!=KErrNone)
       
   697                         {
       
   698                         break;
       
   699                         }
       
   700                     TRAP(err, GetPlugin().StoreMessagePartL( part.GetMailBoxId(), folderId, messageId, part ));
       
   701                     }
       
   702                 else
       
   703                     {
       
   704                     TRAP(err, GetPlugin().StoreMessagePartL( part.GetMailBoxId(), folderId, messageId, part ));
       
   705                     }
       
   706                if(err!=KErrNone)
       
   707                     {
       
   708                     break;
       
   709                     }
       
   710                 }
       
   711             }
       
   712         
       
   713         default:
       
   714         break;
       
   715         }
       
   716     
       
   717     if( err == KErrNone )
       
   718         {
       
   719         progress.iError = KErrNone;
       
   720         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
   721         }
       
   722 		
       
   723 		if(iOperationObserver)
       
   724 			{
       
   725 				iOperationObserver->RequestResponseL( progress, iRequestId );
       
   726 			}
       
   727     
       
   728     
       
   729     __LOG_EXIT;
       
   730 	return EFalse;
       
   731     }
       
   732 
       
   733 
       
   734 /**
       
   735  * 
       
   736  */
       
   737 void CDelayedMessageStorerOp::StorePartL(CFSMailMessagePart* aPart)
       
   738     {
       
   739     User::LeaveIfNull(aPart);
       
   740 
       
   741     // Text buffer for html text content
       
   742     HBufC* data16 = aPart->GetLocalTextContentLC();
       
   743 
       
   744     // Convert from 16 to 8 bit data -
       
   745     HBufC8* dataBuffer = HBufC8::NewLC((data16->Length() * 2) + 1);
       
   746     TPtr8 ptr8(dataBuffer->Des());
       
   747     CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr8, *data16);
       
   748 
       
   749     //get msgstore part
       
   750     CMailboxInfo& mailBox = GetPlugin().GetMailboxInfoL(
       
   751             aPart->GetMailBoxId().Id());
       
   752 
       
   753     CMsgStoreMessage* msg = mailBox().FetchMessageL(
       
   754             aPart->GetMessageId().Id(), KMsgStoreInvalidId);
       
   755     CleanupStack::PushL(msg);
       
   756 
       
   757     CMsgStoreMessagePart* part = msg->ChildPartL(aPart->GetPartId().Id(),
       
   758             ETrue);
       
   759 
       
   760     CleanupStack::PopAndDestroy(msg);
       
   761     CleanupStack::PushL(part);
       
   762 
       
   763     //replace content
       
   764     part->ReplaceContentL(ptr8);
       
   765 
       
   766     CleanupStack::PopAndDestroy(part);
       
   767     CleanupStack::PopAndDestroy(dataBuffer);
       
   768     CleanupStack::PopAndDestroy(data16);
       
   769 
       
   770     }
       
   771 
       
   772 
       
   773 ///////////////////////////////////////////////////
       
   774 // CDelayedMessageToSendOp                      //
       
   775 ///////////////////////////////////////////////////
       
   776 
       
   777 /**
       
   778  * 
       
   779  */
       
   780 /*public static */ CDelayedMessageToSendOp* CDelayedMessageToSendOp::NewLC(
       
   781         CBasePlugin& aPlugin,
       
   782         const TFSMailMsgId& aMailBox,
       
   783         MFSMailRequestObserver& aOperationObserver,
       
   784         const TInt aRequestId)
       
   785     {
       
   786     CDelayedMessageToSendOp* self = new (ELeave) CDelayedMessageToSendOp(
       
   787             aPlugin,aMailBox, aOperationObserver,aRequestId);
       
   788     CleanupStack::PushL( self );
       
   789     self->ConstructL(  );
       
   790     return self;
       
   791     }
       
   792 
       
   793 
       
   794 /**
       
   795  * 
       
   796  */
       
   797 /*public virtual*/ CDelayedMessageToSendOp::~CDelayedMessageToSendOp()
       
   798     {
       
   799     __LOG_DESTRUCT
       
   800     }
       
   801 
       
   802 /**
       
   803  * 
       
   804  */
       
   805 /*private*/
       
   806 void CDelayedMessageToSendOp::ConstructL( )
       
   807     {
       
   808     __LOG_CONSTRUCT( "baseplugin", "CDelayedMessageToSendOp" );
       
   809         
       
   810     }
       
   811 
       
   812 /**
       
   813  * 
       
   814  */
       
   815 /*private*/ CDelayedMessageToSendOp::CDelayedMessageToSendOp(
       
   816     CBasePlugin& aPlugin,
       
   817     const TFSMailMsgId& aMailBox,
       
   818     MFSMailRequestObserver& aOperationObserver,
       
   819     const TInt aRequestId)
       
   820     : iBasePlugin(aPlugin), 
       
   821       iMailBox( aMailBox )
       
   822     {
       
   823     
       
   824     CDelayedOp::iOperationObserver = &aOperationObserver ;
       
   825     CDelayedOp::iRequestId =  aRequestId ;
       
   826 
       
   827     }
       
   828 
       
   829 
       
   830 /**
       
   831  * 
       
   832  */
       
   833 /*private*/ TBool CDelayedMessageToSendOp::ExecuteOpL()
       
   834     {
       
   835     __LOG_ENTER( "ExecuteOpL" );
       
   836    
       
   837     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
       
   838     progress.iError = KErrNotFound;
       
   839     TInt err(KErrNone);
       
   840 
       
   841     TRAP(err, progress.iParam = iBasePlugin.CreateMessageToSendL( iMailBox ));
       
   842     
       
   843     if( err == KErrNone  )
       
   844         {
       
   845         progress.iError = KErrNone;
       
   846         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
   847         }
       
   848 
       
   849 		if(iOperationObserver)
       
   850 			{
       
   851 				iOperationObserver->RequestResponseL( progress, iRequestId );
       
   852 			}
       
   853     
       
   854     __LOG_EXIT;
       
   855 	return EFalse;
       
   856     }
       
   857 
       
   858 
       
   859 ///////////////////////////////////////////////////
       
   860 // CDelayedAddNewOrRemoveChildPartOp             //
       
   861 ///////////////////////////////////////////////////
       
   862 
       
   863 /**
       
   864  * 
       
   865  */
       
   866 /*public static */ CDelayedAddNewOrRemoveChildPartOp* CDelayedAddNewOrRemoveChildPartOp::NewLC(
       
   867     const TFSMailMsgId& aMailBoxId,
       
   868     const TFSMailMsgId& aParentFolderId ,
       
   869     const TFSMailMsgId& aMessageId,
       
   870     const TFSMailMsgId& aParentPartId ,
       
   871     const TDesC& aContentType,
       
   872     const TDesC& aFilePath,
       
   873     MFSMailRequestObserver& aOperationObserver,
       
   874     const TInt aRequestId)
       
   875     {
       
   876     CDelayedAddNewOrRemoveChildPartOp* self = new (ELeave) CDelayedAddNewOrRemoveChildPartOp(
       
   877             aMailBoxId, aParentFolderId, aMessageId,aParentPartId,
       
   878             aOperationObserver,aRequestId);
       
   879     CleanupStack::PushL( self );
       
   880     self->ConstructL( aContentType, aFilePath );
       
   881     return self;
       
   882     }
       
   883 
       
   884 /**
       
   885  * 
       
   886  */
       
   887 /*public static */ CDelayedAddNewOrRemoveChildPartOp* CDelayedAddNewOrRemoveChildPartOp::NewLC(
       
   888     const TFSMailMsgId& aMailBoxId,
       
   889     const TFSMailMsgId& aParentFolderId ,
       
   890     const TFSMailMsgId& aMessageId,
       
   891     const TFSMailMsgId& aParentPartId ,
       
   892     const TFSMailMsgId& aPartId ,
       
   893     MFSMailRequestObserver& aOperationObserver,
       
   894     const TInt aRequestId)
       
   895     {
       
   896     CDelayedAddNewOrRemoveChildPartOp* self = new (ELeave) CDelayedAddNewOrRemoveChildPartOp(
       
   897             aMailBoxId, aParentFolderId, aMessageId,aParentPartId,
       
   898             aPartId,aOperationObserver, aRequestId);
       
   899     CleanupStack::PushL( self );
       
   900     return self;
       
   901     }
       
   902 
       
   903 /**
       
   904  * 
       
   905  */
       
   906 /*public virtual*/ CDelayedAddNewOrRemoveChildPartOp::CDelayedAddNewOrRemoveChildPartOp(
       
   907     const TFSMailMsgId& aMailBoxId,
       
   908     const TFSMailMsgId& aParentFolderId ,
       
   909     const TFSMailMsgId& aMessageId,
       
   910     const TFSMailMsgId& aParentPartId ,
       
   911     MFSMailRequestObserver& aOperationObserver,
       
   912     const TInt aRequestId) :
       
   913     iMailBoxId( aMailBoxId ),
       
   914     iParentFolderId( aParentFolderId ),
       
   915     iMessageId( aMessageId ),
       
   916     iParentPartId( aParentPartId ),
       
   917     iActionType( AddNewChild)
       
   918     {
       
   919     CDelayedOp::iOperationObserver = &aOperationObserver ;
       
   920     CDelayedOp::iRequestId =  aRequestId ;
       
   921     }
       
   922 
       
   923 /**
       
   924  * 
       
   925  */
       
   926 /*public virtual*/ CDelayedAddNewOrRemoveChildPartOp::CDelayedAddNewOrRemoveChildPartOp(
       
   927     const TFSMailMsgId& aMailBoxId,
       
   928     const TFSMailMsgId& aParentFolderId ,
       
   929     const TFSMailMsgId& aMessageId,
       
   930     const TFSMailMsgId& aParentPartId ,
       
   931     const TFSMailMsgId& aPartId ,
       
   932     MFSMailRequestObserver& aOperationObserver,
       
   933     const TInt aRequestId) :
       
   934     iMailBoxId( aMailBoxId ),
       
   935     iParentFolderId( aParentFolderId ),
       
   936     iMessageId( aMessageId ),
       
   937     iParentPartId( aParentPartId ),
       
   938     iPartId( aPartId ),
       
   939     iActionType( RemoveChild)
       
   940     {
       
   941     CDelayedOp::iOperationObserver = &aOperationObserver ;
       
   942     CDelayedOp::iRequestId =  aRequestId ;
       
   943     }
       
   944 
       
   945 /**
       
   946  * 
       
   947  */
       
   948 /*public virtual*/ CDelayedAddNewOrRemoveChildPartOp::~CDelayedAddNewOrRemoveChildPartOp()
       
   949     {
       
   950     __LOG_DESTRUCT
       
   951     if ( iContentType )
       
   952         {
       
   953         delete iContentType;
       
   954         }
       
   955     if ( iFilePath )
       
   956         {
       
   957         delete iFilePath;
       
   958         } 
       
   959     }
       
   960 	
       
   961 /**
       
   962  * 
       
   963  */
       
   964 /*private*/
       
   965 void CDelayedAddNewOrRemoveChildPartOp::ConstructL( const TDesC& aContentType, const TDesC& aFilePath )
       
   966     {
       
   967     __LOG_CONSTRUCT( "baseplugin", "CDelayedAddNewOrRemoveChildPartOp" );      
       
   968     iContentType = aContentType.AllocL();
       
   969     iFilePath = aFilePath.AllocL();                 
       
   970     }
       
   971 
       
   972 /**
       
   973  * 
       
   974  */
       
   975 /*private*/ TBool CDelayedAddNewOrRemoveChildPartOp::ExecuteOpL()
       
   976     {
       
   977     __LOG_ENTER( "ExecuteOpL" );
       
   978     
       
   979     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
       
   980     progress.iError = KErrNotFound;
       
   981     TInt err(KErrNone);
       
   982     
       
   983     if( iActionType == AddNewChild)
       
   984         {
       
   985         CFSMailMessagePart* tmp = NULL;
       
   986         TRAP(err, tmp = GetPlugin().NewChildPartFromFileL(iMailBoxId,iParentFolderId,
       
   987                     iMessageId,iParentPartId,iContentType->Des(),iFilePath->Des()));
       
   988         if(err == KErrNone )
       
   989             {
       
   990             tmp->SetAttachmentNameL( iFilePath->Des() );
       
   991             tmp->SaveL();
       
   992             }
       
   993         //iOperationObserver will make a copy of pointer "tmp" and will own the memory.
       
   994         progress.iParam = tmp;
       
   995         }
       
   996     else
       
   997         {
       
   998         TRAP(err, GetPlugin().RemoveChildPartL(iMailBoxId,iParentFolderId,
       
   999                     iMessageId,iParentPartId,iPartId)); 
       
  1000         }
       
  1001 
       
  1002     if( err == KErrNone )
       
  1003         {
       
  1004         //clear plugin cache so that childparts of message can be updated next time with proper count
       
  1005         GetPlugin().ResetCache();
       
  1006         progress.iError = KErrNone;
       
  1007         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
  1008         }
       
  1009 		
       
  1010 		if(iOperationObserver)
       
  1011 			{
       
  1012 				iOperationObserver->RequestResponseL( progress, iRequestId );
       
  1013 			}
       
  1014     
       
  1015     __LOG_EXIT;
       
  1016     return EFalse;
       
  1017     }
       
  1018 //</qmail>