emailservices/emailstore/base_plugin/src/baseplugindelayedops.cpp
changeset 18 578830873419
parent 0 8466d47a6819
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Email interface implementation.
    14 * Description:  Email interface implementation.
    15 *
    15 *
    16 */
    16 */
       
    17 #include <utf.h>
       
    18 
    17 #include "MsgStoreWritablePropertyContainer.h"
    19 #include "MsgStoreWritablePropertyContainer.h"
    18 
    20 
    19 #include "baseplugindelayedops.h"
    21 #include "baseplugindelayedops.h"
    20 #include "baseplugindelayedopsprivate.h"
    22 #include "baseplugindelayedopsprivate.h"
    21 
    23 
    25 ///////////////////////////////////////////////////
    27 ///////////////////////////////////////////////////
    26 
    28 
    27 /**
    29 /**
    28  * 
    30  * 
    29  */
    31  */
    30 /*public virtual*/ EXPORT_C CDelayedOp::~CDelayedOp()
    32 /*public virtual*/  CDelayedOp::~CDelayedOp()
    31     {
    33     {
    32     Cancel();
    34     Cancel();
    33     __LOG_DESTRUCT
    35     __LOG_DESTRUCT
    34     }
    36     }
    35 
    37 
    36 /**
    38 /**
    37  * 
    39  * 
    38  */
    40  */
    39 /*public*/ EXPORT_C void CDelayedOp::SetContext(
    41 /*public*/  void CDelayedOp::SetContext(
    40     CBasePlugin& aPlugin, MDelayedOpsManager& aManager )
    42     CBasePlugin& aPlugin, MDelayedOpsManager& aManager )
    41     {
    43     {
    42     iPlugin = &aPlugin;
    44     iPlugin = &aPlugin;
    43     iManager = &aManager;
    45     iManager = &aManager;
    44     } 
    46     } 
    45 
    47 
    46 /**
    48 /**
    47  * 
    49  * 
    48  */
    50  */
    49 /*protected*/ EXPORT_C CDelayedOp::CDelayedOp()
    51 /*protected*/  CDelayedOp::CDelayedOp()
    50     : CAsyncOneShot( CActive::EPriorityIdle )
    52     : CAsyncOneShot( CActive::EPriorityIdle )
    51     {    
    53     {    
    52     }
    54     }
    53     
    55     
    54 /**
    56 /**
    55  * 
    57  * 
    56  */
    58  */
    57 /*private virtual*/ EXPORT_C void CDelayedOp::RunL()
    59 /*private virtual*/  void CDelayedOp::RunL()
    58     {
    60     {
    59     __LOG_ENTER_SUPPRESS( "Run" );
    61     __LOG_ENTER_SUPPRESS( "Run" );
    60     TRAPD( err, ExecuteOpL() );
    62     TRAPD( err, ExecuteOpL() );
    61     
    63     
    62     if ( KErrNone != err )
    64     if ( KErrNone != err )
    71     }
    73     }
    72     
    74     
    73 /**
    75 /**
    74  * 
    76  * 
    75  */
    77  */
    76 /*protected*/ EXPORT_C CBasePlugin& CDelayedOp::GetPlugin()
    78 /*protected*/  CBasePlugin& CDelayedOp::GetPlugin()
    77     {
    79     {
    78     return *iPlugin;
    80     return *iPlugin;
    79     }
    81     }
    80 
    82 
    81 /**
    83 /**
    82  * 
    84  * 
    83  */
    85  */
    84 /*private virtual*/ EXPORT_C void CDelayedOp::DoCancel()
    86 /*private virtual*/  void CDelayedOp::DoCancel()
    85     {
    87     {
    86     }
    88     }
    87 
    89 
    88 
    90 
    89 ///////////////////////////////////////////////////
    91 ///////////////////////////////////////////////////
   171 /**
   173 /**
   172  * 
   174  * 
   173  */
   175  */
   174 /*private*/ void CDelayedOpsManager::ExecutePendingOps()
   176 /*private*/ void CDelayedOpsManager::ExecutePendingOps()
   175     {
   177     {
   176     //check the count on every iteration to avoid missing operations being
   178     TInt count = iDelayedOps.Count();
   177     //enqueued by another operations.
   179     for ( TInt i = 0; i < count; ++i )
   178     for ( TInt i = 0; i < iDelayedOps.Count(); ++i )
       
   179         {
   180         {
   180         CDelayedOp* op = iDelayedOps[i];
   181         CDelayedOp* op = iDelayedOps[i];
   181         
   182         
   182         op->Cancel();
   183         op->Cancel();
   183         TRAP_IGNORE( op->ExecuteOpL() );
   184         TRAP_IGNORE( op->ExecuteOpL() );
   474     : iMailBoxId( aMailBoxId ), iMessageId( aMessageId ),
   475     : iMailBoxId( aMailBoxId ), iMessageId( aMessageId ),
   475       iMessagePartId( aMessagePartId ), iContentLength( aContentLength ),
   476       iMessagePartId( aMessagePartId ), iContentLength( aContentLength ),
   476       iStepOne( EFalse )
   477       iStepOne( EFalse )
   477     {
   478     {
   478     }
   479     }
       
   480 
       
   481 ///////////////////////////////////////////////////
       
   482 // CDelayedMessageStorerOp                      //
       
   483 ///////////////////////////////////////////////////
       
   484 
       
   485 /**
       
   486  * 
       
   487  */
       
   488 /*public static */ CDelayedMessageStorerOp* CDelayedMessageStorerOp::NewLC(
       
   489         const TFSMailMsgId& aMailBox,
       
   490         RPointerArray<CFSMailMessage> &messages,
       
   491         MFSMailRequestObserver& aOperationObserver,
       
   492         const TInt aRequestId)
       
   493     {
       
   494     CDelayedMessageStorerOp* self = new (ELeave) CDelayedMessageStorerOp(
       
   495             aMailBox, messages, aOperationObserver,aRequestId);
       
   496     CleanupStack::PushL( self );
       
   497     self->ConstructL(  );
       
   498     return self;
       
   499     }
       
   500 
       
   501 /**
       
   502  * 
       
   503  */
       
   504 /*public static */ CDelayedMessageStorerOp* CDelayedMessageStorerOp::NewLC(
       
   505         RPointerArray<CFSMailMessagePart>& aMessageParts,
       
   506         MFSMailRequestObserver& aOperationObserver,
       
   507         const TInt aRequestId)
       
   508     {
       
   509     CDelayedMessageStorerOp* self = new (ELeave) CDelayedMessageStorerOp(
       
   510             aMessageParts, aOperationObserver, aRequestId);
       
   511     CleanupStack::PushL( self );
       
   512     self->ConstructL(  );
       
   513     return self;
       
   514     }
       
   515 
       
   516 /**
       
   517  * 
       
   518  */
       
   519 /*public virtual*/ CDelayedMessageStorerOp::~CDelayedMessageStorerOp()
       
   520     {
       
   521     __LOG_DESTRUCT
       
   522     iMessages.Reset();
       
   523     iMessageParts.Reset();
       
   524     if (iDataBuffer)
       
   525         {
       
   526         delete iDataBuffer;
       
   527         iDataBuffer = NULL;
       
   528         }
       
   529     }
       
   530 
       
   531 /**
       
   532  * 
       
   533  */
       
   534 /*private*/
       
   535 void CDelayedMessageStorerOp::ConstructL( )
       
   536     {
       
   537     __LOG_CONSTRUCT( "baseplugin", "CDelayedMessageStorerOp" );
       
   538         
       
   539     }
       
   540 
       
   541 /**
       
   542  * 
       
   543  */
       
   544 /*private*/ CDelayedMessageStorerOp::CDelayedMessageStorerOp(
       
   545     const TFSMailMsgId& aMailBox,
       
   546     RPointerArray<CFSMailMessage> &messages,
       
   547     MFSMailRequestObserver& aOperationObserver,
       
   548     const TInt aRequestId)
       
   549     : iMailBox( aMailBox ), 
       
   550       iOperationObserver( aOperationObserver ),
       
   551       iRequestId( aRequestId ),
       
   552       iType(EHeaders)
       
   553     {
       
   554     for(TInt i=0; i < messages.Count(); i++)
       
   555         {
       
   556         iMessages.Append(messages[i]);
       
   557         }
       
   558     }
       
   559 
       
   560 /**
       
   561  * 
       
   562  */
       
   563 /*private*/ CDelayedMessageStorerOp::CDelayedMessageStorerOp(
       
   564     RPointerArray<CFSMailMessagePart>& aMessageParts,
       
   565     MFSMailRequestObserver& aOperationObserver,
       
   566     const TInt aRequestId)
       
   567     :iOperationObserver( aOperationObserver ),
       
   568     iRequestId( aRequestId ),
       
   569     iType(EParts)
       
   570     {
       
   571     for(TInt i=0; i < aMessageParts.Count(); i++)
       
   572         {
       
   573         iMessageParts.Append(aMessageParts[i]);
       
   574         }
       
   575     }
       
   576 
       
   577 /**
       
   578  * 
       
   579  */
       
   580 /*private*/ void CDelayedMessageStorerOp::ExecuteOpL()
       
   581     {
       
   582     __LOG_ENTER( "ExecuteOpL" );
       
   583    
       
   584     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
       
   585     progress.iError = KErrNotFound;
       
   586     TInt err(KErrNone);
       
   587     
       
   588     switch( iType )
       
   589         {
       
   590         case EHeaders: 
       
   591             {
       
   592             for ( TInt i = 0; i < iMessages.Count(); i++ )
       
   593                 {
       
   594                 TRAP(err, GetPlugin().StoreMessageL(iMailBox, *iMessages[i] ));
       
   595                 if(err!=KErrNone)
       
   596                     {
       
   597                     break;
       
   598                     }
       
   599                 }
       
   600             break;
       
   601             }
       
   602             
       
   603         case EParts:
       
   604             {
       
   605                 for ( TInt i = 0; i < iMessageParts.Count(); i++ )
       
   606                 {
       
   607                 CFSMailMessagePart& part= *iMessageParts[i];
       
   608                 TFSMailMsgId messageId= part.GetMessageId();
       
   609                 TFSMailMsgId folderId= part.GetFolderId();
       
   610                 
       
   611                 if (part.GetContentType().Compare(KFSMailContentTypeTextPlain) == 0 ||
       
   612                         part.GetContentType().Compare(KFSMailContentTypeTextHtml) == 0)
       
   613                     {
       
   614                     TRAP(err,StorePartL(&part));
       
   615                     if(err!=KErrNone)
       
   616                         {
       
   617                         break;
       
   618                         }
       
   619                     TRAP(err, GetPlugin().StoreMessagePartL( part.GetMailBoxId(), folderId, messageId, part ));
       
   620                     }
       
   621                 else
       
   622                     {
       
   623                     TRAP(err, GetPlugin().StoreMessagePartL( part.GetMailBoxId(), folderId, messageId, part ));
       
   624                     }
       
   625                if(err!=KErrNone)
       
   626                     {
       
   627                     break;
       
   628                     }
       
   629                 }
       
   630             }
       
   631         
       
   632         default:
       
   633         break;
       
   634         }
       
   635     
       
   636     if( err == KErrNone )
       
   637         {
       
   638         progress.iError = KErrNone;
       
   639         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
   640         }
       
   641 
       
   642     iOperationObserver.RequestResponseL( progress, iRequestId );
       
   643     
       
   644     __LOG_EXIT;
       
   645     }
       
   646 
       
   647 
       
   648 /**
       
   649  * 
       
   650  */
       
   651 void CDelayedMessageStorerOp::StorePartL(
       
   652         CFSMailMessagePart* aPart)
       
   653     {
       
   654     User::LeaveIfNull(aPart);
       
   655     
       
   656     // Text buffer for html text content
       
   657     HBufC* data16 = aPart->GetLocalTextContentLC();
       
   658 
       
   659     TPtrC8 ptr8(reinterpret_cast<const TUint8*>( data16->Ptr() ),
       
   660             data16->Size() );
       
   661     
       
   662     //get msgstore part
       
   663     CMailboxInfo& mailBox = GetPlugin().GetMailboxInfoL( aPart->GetMailBoxId().Id() );
       
   664     
       
   665     CMsgStoreMessage* msg = mailBox().FetchMessageL(
       
   666             aPart->GetMessageId().Id(), KMsgStoreInvalidId );
       
   667     CleanupStack::PushL( msg );
       
   668     
       
   669     CMsgStoreMessagePart* part= msg->ChildPartL( aPart->GetPartId().Id(), ETrue );
       
   670     
       
   671     CleanupStack::PopAndDestroy( msg );
       
   672     CleanupStack::PushL( part );
       
   673 
       
   674     //replace content
       
   675     part->ReplaceContentL(ptr8);
       
   676     
       
   677     CleanupStack::PopAndDestroy( part );
       
   678     CleanupStack::PopAndDestroy( data16 );
       
   679        
       
   680     }
       
   681 
       
   682 
       
   683 ///////////////////////////////////////////////////
       
   684 // CDelayedMessageToSendOp                      //
       
   685 ///////////////////////////////////////////////////
       
   686 
       
   687 /**
       
   688  * 
       
   689  */
       
   690 /*public static */ CDelayedMessageToSendOp* CDelayedMessageToSendOp::NewLC(
       
   691         CBasePlugin& aPlugin,
       
   692         const TFSMailMsgId& aMailBox,
       
   693         MFSMailRequestObserver& aOperationObserver,
       
   694         const TInt aRequestId)
       
   695     {
       
   696     CDelayedMessageToSendOp* self = new (ELeave) CDelayedMessageToSendOp(
       
   697             aPlugin,aMailBox, aOperationObserver,aRequestId);
       
   698     CleanupStack::PushL( self );
       
   699     self->ConstructL(  );
       
   700     return self;
       
   701     }
       
   702 
       
   703 
       
   704 /**
       
   705  * 
       
   706  */
       
   707 /*public virtual*/ CDelayedMessageToSendOp::~CDelayedMessageToSendOp()
       
   708     {
       
   709     __LOG_DESTRUCT
       
   710     }
       
   711 
       
   712 /**
       
   713  * 
       
   714  */
       
   715 /*private*/
       
   716 void CDelayedMessageToSendOp::ConstructL( )
       
   717     {
       
   718     __LOG_CONSTRUCT( "baseplugin", "CDelayedMessageToSendOp" );
       
   719         
       
   720     }
       
   721 
       
   722 /**
       
   723  * 
       
   724  */
       
   725 /*private*/ CDelayedMessageToSendOp::CDelayedMessageToSendOp(
       
   726     CBasePlugin& aPlugin,
       
   727     const TFSMailMsgId& aMailBox,
       
   728     MFSMailRequestObserver& aOperationObserver,
       
   729     const TInt aRequestId)
       
   730     : iBasePlugin(aPlugin), 
       
   731       iMailBox( aMailBox ), 
       
   732       iOperationObserver( aOperationObserver ),
       
   733       iRequestId( aRequestId )
       
   734     {
       
   735 
       
   736     }
       
   737 
       
   738 
       
   739 /**
       
   740  * 
       
   741  */
       
   742 /*private*/ void CDelayedMessageToSendOp::ExecuteOpL()
       
   743     {
       
   744     __LOG_ENTER( "ExecuteOpL" );
       
   745    
       
   746     TFSProgress progress = { TFSProgress::EFSStatus_RequestCancelled, 0, 0, 0 };
       
   747     progress.iError = KErrNotFound;
       
   748     TInt err(KErrNone);
       
   749 
       
   750     TRAP(err, progress.iParam = iBasePlugin.CreateMessageToSendL( iMailBox ));
       
   751     
       
   752     if( err == KErrNone  )
       
   753         {
       
   754         progress.iError = KErrNone;
       
   755         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
   756         }
       
   757 
       
   758     iOperationObserver.RequestResponseL( progress, iRequestId );
       
   759     
       
   760     __LOG_EXIT;
       
   761     }