ipsservices/ipssosplugin/src/ipsplgimap4fetchattachmentop.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 76 38bf5461e270
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    18 
    18 
    19 
    19 
    20 #include "emailtrace.h"
    20 #include "emailtrace.h"
    21 #include "ipsplgheaders.h"
    21 #include "ipsplgheaders.h"
    22 
    22 
    23 // <qmail> priority const has been removed
    23 // <qmail> priority const has been removed, interval changed to 0.2 sec
    24 const TInt KIpsAttaFetchProgressReportInterval = 200000; // 0.2 sec
    24 const TInt KIpsAttaFetchProgressReportInterval = 200000; // 0.2 sec
       
    25 const TInt KIpsAttaFetchRetryInterval = 1000000; // 1 sec
       
    26 const TInt KIpsAttaFetchRetryCount = 30;
    25 
    27 
    26 // ----------------------------------------------------------------------------
    28 // ----------------------------------------------------------------------------
    27 // ----------------------------------------------------------------------------
    29 // ----------------------------------------------------------------------------
    28 CIpsFetchProgReport* CIpsFetchProgReport::NewL( 
    30 CIpsFetchProgReport* CIpsFetchProgReport::NewL( 
    29     CIpsPlgImap4FetchAttachmentOp& aAttaOp )
    31     CIpsPlgImap4FetchAttachmentOp& aAttaOp )
    96     }
    98     }
    97 
    99 
    98 // ----------------------------------------------------------------------------
   100 // ----------------------------------------------------------------------------
    99 // CIpsPlgImap4FetchAttachmentOp
   101 // CIpsPlgImap4FetchAttachmentOp
   100 // ----------------------------------------------------------------------------
   102 // ----------------------------------------------------------------------------
       
   103 // <qmail> aFunctionId removed, CMsvEntrySelection& changed to pointer
       
   104 // <qmail> MFSMailRequestObserver& changed to pointer
   101 CIpsPlgImap4FetchAttachmentOp* CIpsPlgImap4FetchAttachmentOp::NewL(
   105 CIpsPlgImap4FetchAttachmentOp* CIpsPlgImap4FetchAttachmentOp::NewL(
   102     CMsvSession& aMsvSession,
   106     CMsvSession& aMsvSession,
   103     TRequestStatus& aObserverRequestStatus,
   107     TRequestStatus& aObserverRequestStatus,
   104     TMsvId aService,
   108     TMsvId aService,
   105     CIpsPlgTimerOperation& aActivityTimer,
   109     CIpsPlgTimerOperation& aActivityTimer,
   127     }
   131     }
   128 
   132 
   129 // ----------------------------------------------------------------------------
   133 // ----------------------------------------------------------------------------
   130 // ----------------------------------------------------------------------------
   134 // ----------------------------------------------------------------------------
   131 // <qmail> priority parameter has been removed
   135 // <qmail> priority parameter has been removed
       
   136 // <qmail> MFSMailRequestObserver& changed to pointer
   132 CIpsPlgImap4FetchAttachmentOp::CIpsPlgImap4FetchAttachmentOp(
   137 CIpsPlgImap4FetchAttachmentOp::CIpsPlgImap4FetchAttachmentOp(
   133     CMsvSession& aMsvSession,
   138     CMsvSession& aMsvSession,
   134     TRequestStatus& aObserverRequestStatus,
   139     TRequestStatus& aObserverRequestStatus,
   135     TMsvId aService,
   140     TMsvId aService,
   136     CIpsPlgTimerOperation& aActivityTimer,
   141     CIpsPlgTimerOperation& aActivityTimer,
   144         aObserverRequestStatus,
   149         aObserverRequestStatus,
   145         aActivityTimer,
   150         aActivityTimer,
   146         aFSMailBoxId,
   151         aFSMailBoxId,
   147         aFSOperationObserver,
   152         aFSOperationObserver,
   148         aFSRequestId ),
   153         aFSRequestId ),
   149     iSelection( aSelection )
   154     	iSelection( aSelection ),
       
   155     	iRetryCount( 0 )
   150     {
   156     {
   151     FUNC_LOG;
   157     FUNC_LOG;
   152     iService = aService;
   158     iService = aService;
       
   159     iRetryTimer.CreateLocal();
   153     }
   160     }
   154 
   161 
   155 // ----------------------------------------------------------------------------
   162 // ----------------------------------------------------------------------------
   156 // ----------------------------------------------------------------------------
   163 // ----------------------------------------------------------------------------
   157 CIpsPlgImap4FetchAttachmentOp::~CIpsPlgImap4FetchAttachmentOp()
   164 CIpsPlgImap4FetchAttachmentOp::~CIpsPlgImap4FetchAttachmentOp()
   158     {
   165     {
   159     FUNC_LOG;
   166     FUNC_LOG;
       
   167     iRetryTimer.Close();
   160     delete iSelection;
   168     delete iSelection;
   161     delete iProgReport;
   169     delete iProgReport;
   162     delete iFetchErrorProgress;
   170     delete iFetchErrorProgress;
   163     }
   171     }
   164 
   172 
   182     // <qmail> priority parameter has been removed
   190     // <qmail> priority parameter has been removed
   183     CIpsPlgImap4ConnectOp* connOp = CIpsPlgImap4ConnectOp::NewL(
   191     CIpsPlgImap4ConnectOp* connOp = CIpsPlgImap4ConnectOp::NewL(
   184         iMsvSession,
   192         iMsvSession,
   185         iStatus, 
   193         iStatus, 
   186         iService,
   194         iService,
   187         iActivityTimer,
   195         *iActivityTimer,
   188         iFSMailboxId,
   196         iFSMailboxId,
   189         NULL, // no observer for subopertaion
   197         NULL, // no observer for subopertaion
   190         0,    // no requestId needed
   198         0,    // no requestId needed
   191         NULL, // event handler not needed whin plain connect
   199         NULL, // event handler not needed whin plain connect
   192         ETrue );
   200         ETrue );
   223             if ( !Connected() )
   231             if ( !Connected() )
   224                 {
   232                 {
   225                 CompleteObserver( KErrCouldNotConnect );
   233                 CompleteObserver( KErrCouldNotConnect );
   226                 return;
   234                 return;
   227                 }
   235                 }
       
   236             iRetryCount = 0;
       
   237             DoFetchAttachmentL();
       
   238             break;
       
   239             }
       
   240         case EStateWaiting:
       
   241             {
   228             DoFetchAttachmentL();
   242             DoFetchAttachmentL();
   229             break;
   243             break;
   230             }
   244             }
   231         case EStateFetching:         
   245         case EStateFetching:         
   232             {
   246             {
   233             delete iProgReport;
   247             delete iProgReport;
   234             iProgReport = NULL;
   248             iProgReport = NULL;
   235             
   249             
   236             TInt err( iStatus.Int() );
   250             TInt err = iStatus.Int();
   237             if( err != KErrNone && iSubOperation )
   251 
       
   252             // If the server was busy, try again after a short delay, up to
       
   253             // some retry limit.
       
   254             if ( err == KErrServerBusy && iRetryCount < KIpsAttaFetchRetryCount )
   238                 {
   255                 {
   239                 iFetchErrorProgress = iSubOperation->ProgressL().AllocL();
   256                 iRetryCount++;
       
   257                 INFO_1( "CIpsPlgImap4FetchAttachmentOp::DoRunL: iRetryCount = %d", iRetryCount );
       
   258                 iState = EStateWaiting;
       
   259                 iStatus = KRequestPending;
       
   260                 iRetryTimer.After( iStatus, KIpsAttaFetchRetryInterval );
       
   261                 SetActive();
   240                 }
   262                 }
   241             
   263             else
   242             iState = EStateIdle;
   264                 {
   243             CompleteObserver( err );
   265                 if( err != KErrNone && iSubOperation )
       
   266                     {
       
   267                     iFetchErrorProgress = iSubOperation->ProgressL().AllocL();
       
   268                     }
       
   269                 
       
   270                 iState = EStateIdle;
       
   271                 CompleteObserver( err );
       
   272                 }
   244             break;
   273             break;
   245             }
   274             }
   246         default:
   275         default:
   247             break;
   276             break;
   248         }
   277         }
   277 // ----------------------------------------------------------------------------
   306 // ----------------------------------------------------------------------------
   278 // ----------------------------------------------------------------------------
   307 // ----------------------------------------------------------------------------
   279 void CIpsPlgImap4FetchAttachmentOp::ReportProgressL()
   308 void CIpsPlgImap4FetchAttachmentOp::ReportProgressL()
   280     {
   309     {
   281     FUNC_LOG;
   310     FUNC_LOG;
   282     TInt error( KErrNone );
   311     TInt error = KErrNone;
   283     TFSProgress fsProgress = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   312     TFSProgress fsProgress = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   284     if ( iSubOperation && iState == EStateFetching )
   313     if ( iSubOperation && iState == EStateFetching )
   285         {
   314         {
   286         TRAP(error, iProgress.Copy( iSubOperation->ProgressL() ) );
   315         TRAP(error, iProgress.Copy( iSubOperation->ProgressL() ) );
   287         }
   316         }
   305         }
   334         }
   306     else
   335     else
   307         {
   336         {
   308         User::Leave( error );
   337         User::Leave( error );
   309         }
   338         }
   310     
   339 
       
   340 // <qmail>
   311     // signal observer if it exists
   341     // signal observer if it exists
   312     if ( iFSOperationObserver )
   342     if ( iFSOperationObserver )
   313         {
   343         {
   314         iFSOperationObserver->RequestResponseL( fsProgress, iFSRequestId );
   344         iFSOperationObserver->RequestResponseL( fsProgress, iFSRequestId );
   315         }
   345         }
       
   346 // </qmail>
   316     }
   347     }
   317 
   348 
   318 // ----------------------------------------------------------------------------
   349 // ----------------------------------------------------------------------------
   319 // ----------------------------------------------------------------------------
   350 // ----------------------------------------------------------------------------
   320 const TDesC8& CIpsPlgImap4FetchAttachmentOp::GetErrorProgressL(TInt /*aError*/ )
   351 const TDesC8& CIpsPlgImap4FetchAttachmentOp::GetErrorProgressL(TInt /*aError*/ )
   368     iState = EStateFetching;
   399     iState = EStateFetching;
   369 
   400 
   370     // Switch operations.
   401     // Switch operations.
   371     delete iSubOperation;
   402     delete iSubOperation;
   372     iSubOperation = NULL;
   403     iSubOperation = NULL;
       
   404     iStatus = KRequestPending;
   373 
   405 
   374     iProgReport = CIpsFetchProgReport::NewL( *this );
   406     iProgReport = CIpsFetchProgReport::NewL( *this );
   375 
   407 
   376     // Filters are not used when performing 'fetch' operation, 
   408     // Filters are not used when performing 'fetch' operation, 
   377     // use normal getmail info instead
   409     // use normal getmail info instead
       
   410 // <qmail>
   378     TPckgBuf<TImImap4GetMailInfo> param;
   411     TPckgBuf<TImImap4GetMailInfo> param;
   379     TImImap4GetMailInfo& options = param();
   412     TImImap4GetMailInfo& options = param();
   380     options.iMaxEmailSize = KMaxTInt32;
   413     options.iMaxEmailSize = KMaxTInt32;
   381     options.iGetMailBodyParts = EGetImap4EmailAttachments;
   414     options.iGetMailBodyParts = EGetImap4EmailAttachments;
   382     options.iDestinationFolder = 0; // not used
   415     options.iDestinationFolder = 0; // not used
   383 
   416 
   384     InvokeClientMtmAsyncFunctionL( KIMAP4MTMPopulate, *iSelection, param ); // <qmail> 1 param removed
   417     InvokeClientMtmAsyncFunctionL( KIMAP4MTMPopulate, *iSelection, param ); // <qmail> 1 param removed
       
   418 // </qmail>
   385     SetActive();
   419     SetActive();
   386     }
   420     }
   387     
   421     
       
   422 // <qmail> GetEngineProgress function removed
       
   423 
   388 // <qmail> new func to this op
   424 // <qmail> new func to this op
   389 // ----------------------------------------------------------------------------
   425 // ----------------------------------------------------------------------------
   390 // ----------------------------------------------------------------------------    
   426 // ----------------------------------------------------------------------------    
   391 TIpsOpType CIpsPlgImap4FetchAttachmentOp::IpsOpType() const
   427 TIpsOpType CIpsPlgImap4FetchAttachmentOp::IpsOpType() const
   392     {
   428     {
   393     FUNC_LOG;
   429     FUNC_LOG;
   394     return EIpsOpTypeFetchAttachmentOp;
   430     return EIpsOpTypeFetchAttachmentOp;
   395     }
   431     }
       
   432 // </qmail>
       
   433 
       
   434 
       
   435 // End of File
       
   436