emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp
branchRCL_3
changeset 64 3533d4323edc
parent 63 d189ee25cf9d
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Email interface implementation.
    14 * Description:  Email interface implementation.
    15 *
    15 *
    16 */
    16 */
    17 
    17 #include "msgstorewritablepropertycontainer.h"
    18 //<qmail>
       
    19 #include <utf.h>
       
    20 //<//qmail>
       
    21 
       
    22 #include "MsgStoreWritablePropertyContainer.h"
       
    23 
    18 
    24 #include "baseplugindelayedops.h"
    19 #include "baseplugindelayedops.h"
    25 #include "baseplugindelayedopsprivate.h"
    20 #include "baseplugindelayedopsprivate.h"
    26 
    21 
    27 ///////////////////////////////////////////////////
    22 ///////////////////////////////////////////////////
    29 ///////////////////////////////////////////////////
    24 ///////////////////////////////////////////////////
    30 
    25 
    31 /**
    26 /**
    32  * 
    27  * 
    33  */
    28  */
    34 /*public virtual*/  CDelayedOp::~CDelayedOp()
    29 /*public virtual*/ EXPORT_C CDelayedOp::~CDelayedOp()
    35     {
    30     {
    36     Cancel();
    31     Cancel();
    37     __LOG_DESTRUCT
    32     __LOG_DESTRUCT
    38     }
    33     }
    39 
    34 
    40 /**
    35 /**
    41  * 
    36  * 
    42  */
    37  */
    43 /*public*/  void CDelayedOp::SetContext(
    38 /*public*/ EXPORT_C void CDelayedOp::SetContext(
    44     CBasePlugin& aPlugin, MDelayedOpsManager& aManager )
    39     CBasePlugin& aPlugin, MDelayedOpsManager& aManager )
    45     {
    40     {
    46     iPlugin = &aPlugin;
    41     iPlugin = &aPlugin;
    47     iManager = &aManager;
    42     iManager = &aManager;
    48     } 
    43     } 
    49 
    44 
    50 /**
    45 /**
    51  * 
    46  * 
    52  */
    47  */
    53 /*public*/  void CDelayedOp::StartOp()
    48 /*public*/ EXPORT_C void CDelayedOp::StartOp()
    54     {
    49     {
    55     iStatus = KRequestPending;
    50     iStatus = KRequestPending;
    56     SetActive();
    51     SetActive();
    57     TRequestStatus* pStatus = &iStatus;
    52     TRequestStatus* pStatus = &iStatus;
    58     User::RequestComplete( pStatus, KErrNone );
    53     User::RequestComplete( pStatus, KErrNone );
    59     } 
    54     } 
    60 /*protected*/  CDelayedOp::CDelayedOp()
    55 
       
    56 /**
       
    57  * 
       
    58  */
       
    59 /*protected*/ EXPORT_C CDelayedOp::CDelayedOp()
    61     : CActive( CActive::EPriorityIdle )
    60     : CActive( CActive::EPriorityIdle )
    62     {    
    61     {    
    63     CActiveScheduler::Add( this );
    62     CActiveScheduler::Add( this );
    64     }
    63     }
    65     
    64     
    66 /**
    65 /**
    67  * 
    66  * 
    68  */
    67  */
    69 /*private virtual*/  void CDelayedOp::RunL()
    68 /*private virtual*/ EXPORT_C void CDelayedOp::RunL()
    70     {
    69     {
    71     __LOG_ENTER_SUPPRESS( "Run" );
    70     __LOG_ENTER_SUPPRESS( "Run" );
    72     TBool again( EFalse );
    71     TBool again( EFalse );
    73     
    72     
    74     TRAPD( err, again = ExecuteOpL() );
    73     TRAPD( err, again = ExecuteOpL() );
    85         }
    84         }
    86     else
    85     else
    87         {
    86         {
    88         //self-destroy.
    87         //self-destroy.
    89         iManager->DequeueOp( *this );
    88         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>			
       
   101         delete this;
    89         delete this;
   102         }
    90         }
   103     }
    91     }
   104     
    92     
   105 /**
    93 /**
   106  * 
    94  * 
   107  */
    95  */
   108 /*protected*/  CBasePlugin& CDelayedOp::GetPlugin()
    96 /*protected*/ EXPORT_C CBasePlugin& CDelayedOp::GetPlugin()
   109     {
    97     {
   110     return *iPlugin;
    98     return *iPlugin;
   111     }
    99     }
   112 
   100 
   113 /**
   101 /**
   114  * 
   102  * 
   115  */
   103  */
   116 /*private virtual*/  void CDelayedOp::DoCancel()
   104 /*private virtual*/ EXPORT_C void CDelayedOp::DoCancel()
   117     {
   105     {
   118     }
   106     }
   119 
   107 
   120 
   108 
   121 ///////////////////////////////////////////////////
   109 ///////////////////////////////////////////////////
   307     __LOG_ENTER( "ExecuteOpL" );
   295     __LOG_ENTER( "ExecuteOpL" );
   308 
   296 
   309     //Maximum number of messages deleted in one go
   297     //Maximum number of messages deleted in one go
   310     const TInt KNumOfDeletesBeforeYield = 30;
   298     const TInt KNumOfDeletesBeforeYield = 30;
   311 
   299 
   312     //<qmail>
       
   313     TInt result(KErrNone);
       
   314 
       
   315     TBool runAgain = ETrue;
   300     TBool runAgain = ETrue;
   316     TInt endIndex = iIndex + KNumOfDeletesBeforeYield;
   301     TInt  endIndex = iIndex + KNumOfDeletesBeforeYield;
   317 
   302 
   318     if (endIndex >= iMessages.Count())
   303     if( endIndex >= iMessages.Count() )
   319         {
   304         {
   320         endIndex = iMessages.Count();
   305         endIndex = iMessages.Count();   
   321         runAgain = EFalse; // last time, no need to run again.
   306         runAgain = EFalse;  // last time, no need to run again.
   322         }
   307         }
   323 
   308 
   324     CMailboxInfo& mailBoxInfo = GetPlugin().GetMailboxInfoL(iMailBoxId);
   309     CMailboxInfo& mailBoxInfo = GetPlugin().GetMailboxInfoL( iMailBoxId );
   325     CMsgStoreMailBox& mailBox = mailBoxInfo();
   310     CMsgStoreMailBox& mailBox = mailBoxInfo();
   326 
   311 
   327     for (; iIndex < endIndex; iIndex++)
   312     for ( ; iIndex < endIndex; iIndex++ )
   328         {
   313         {
   329         TMsgStoreId msgId = iMessages[iIndex];
   314         TMsgStoreId msgId = iMessages[iIndex];
   330 
   315         
   331         if (EFalse == iImmediateDelete)
   316         if ( EFalse == iImmediateDelete )
   332             {
   317             {
   333             //try to find the message
   318             //try to find the message in the deleted items folder.
   334             CMsgStoreMessage* theMessage = NULL;
   319             CMsgStoreMessage* theMessage = NULL;
   335             theMessage = mailBox.FetchMessageL(msgId, KMsgStoreInvalidId);
   320             TRAP_IGNORE( theMessage = mailBox.FetchMessageL(
   336             //save parentId
   321                     msgId, mailBoxInfo.iRootFolders.iFolders[ EFSDeleted ] ) );
   337             TMsgStoreId msgParentId;
   322             
   338             msgParentId = theMessage->ParentId();
   323             if ( NULL == theMessage )
   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])
       
   342                 {
   324                 {
   343                 //if not in deleted items then move it there.
   325                 //if not in deleted items then move it there.
   344                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   326                 __LOG_WRITE8_FORMAT1_INFO("Moving message 0x%X to the deleted items.", msgId );
   345                 TRAP(result,mailBox.MoveMessageL(
   327                 mailBox.MoveMessageL( msgId, KMsgStoreInvalidId,
   346                                 msgId, KMsgStoreInvalidId,
   328                                       mailBoxInfo.iRootFolders.iFolders[ EFSDeleted ] );
   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 
       
   359                 }
   329                 }
   360             else
   330             else
   361                 {
   331                 {
   362                 //in deleted items, really delete it.
   332                 //in deleted items, really delete it.
   363                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   333                 __LOG_WRITE8_FORMAT1_INFO( "Deleting message 0x%X.", msgId );
   364 
   334 
   365                 delete theMessage;
   335                 delete theMessage;
   366                 TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
   336                 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                     }
       
   377                 }
   337                 }
   378             }
   338             }
   379         else
   339         else
   380             {
   340             {
   381             TRAP(result,mailBox.DeleteMessageL( msgId, iFolderId ));
   341             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                 }
       
   391             }
   342             }
   392         //</qmail>
   343         }
   393         } 
   344 
   394 		__LOG_EXIT;
   345     __LOG_EXIT;
   395     return runAgain;
   346     return runAgain;
   396     }
   347     }
   397 
   348 
   398 
   349 
   399 ///////////////////////////////////////////////////
   350 ///////////////////////////////////////////////////
   490         part->StorePropertiesL();
   441         part->StorePropertiesL();
   491         __LOG_WRITE8_FORMAT1_INFO(
   442         __LOG_WRITE8_FORMAT1_INFO(
   492             "Updated the properties of part 0x%X.", part->Id() )
   443             "Updated the properties of part 0x%X.", part->Id() )
   493         }
   444         }
   494     
   445     
   495     CleanupStack::PopAndDestroy( part );    
   446     CleanupStack::PopAndDestroy( part );
       
   447 
   496     __LOG_EXIT
   448     __LOG_EXIT
   497     return EFalse;
   449     return EFalse;
   498     }
   450     }
   499 
   451 
   500 /**
   452 /**
   551     : iMailBoxId( aMailBoxId ), iMessageId( aMessageId ),
   503     : iMailBoxId( aMailBoxId ), iMessageId( aMessageId ),
   552       iMessagePartId( aMessagePartId ), iContentLength( aContentLength ),
   504       iMessagePartId( aMessagePartId ), iContentLength( aContentLength ),
   553       iStepOne( EFalse )
   505       iStepOne( EFalse )
   554     {
   506     {
   555     }
   507     }
   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>