ipsservices/ipssosplugin/src/ipsplgpop3connectop.cpp
branchRCL_3
changeset 25 3533d4323edc
parent 24 d189ee25cf9d
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
    13 *
    13 *
    14 * Description:  POP3 connect operation
    14 * Description:  POP3 connect operation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 
    18 #include "emailtrace.h"
    19 #include "emailtrace.h"
    19 #include "ipsplgheaders.h"
    20 #include "ipsplgheaders.h"
    20 
    21 
    21 
       
    22 // Constants and defines
    22 // Constants and defines
    23 // <qmail> rename const
    23 const TInt KConnectOpPriority = CActive::EPriorityStandard;
    24 const TInt KDefaultPopulateLimit( 50 );
    24 const TInt KIpsPlgPop3PopulateLimitInitValue = 50;
    25 const TInt KPopulateAlgorithmBytesInKilo( 1024 );
    25 
    26 const TInt KPopulateAlgorithmRowLength( 75 );
    26 _LIT( KIpsPlgPopConnectPanic, "PopConnectOp" );
    27 
       
    28 
    27 
    29 // ----------------------------------------------------------------------------
    28 // ----------------------------------------------------------------------------
    30 // CIpsPlgPop3ConnectOp::NewL()
    29 // CIpsPlgPop3ConnectOp::NewL()
    31 // ----------------------------------------------------------------------------
    30 // ----------------------------------------------------------------------------
    32 // <qmail> MFSMailRequestObserver& changed to pointer
    31 //
    33 // <qmail> aSignallingAllowed parameter added
       
    34 // <qmail> aFetchWillFollow parameter added
       
    35 CIpsPlgPop3ConnectOp* CIpsPlgPop3ConnectOp::NewL(
    32 CIpsPlgPop3ConnectOp* CIpsPlgPop3ConnectOp::NewL(
    36     CMsvSession& aMsvSession,                           
    33     CMsvSession& aMsvSession,                           
    37     TRequestStatus& aObserverRequestStatus,
    34     TRequestStatus& aObserverRequestStatus,
    38     TMsvId aService,
    35     TMsvId aService,
    39     TBool aForcePopulate,
    36     TBool aForcePopulate,
    40     CIpsPlgTimerOperation& aActivityTimer,
    37     CIpsPlgTimerOperation& aActivityTimer,
    41     TFSMailMsgId aFSMailBoxId,
    38     TFSMailMsgId aFSMailBoxId,
    42     MFSMailRequestObserver* aFSOperationObserver,
    39     MFSMailRequestObserver& aFSOperationObserver,
    43     TInt aFSRequestId,
    40     TInt aFSRequestId,
    44     CIpsPlgEventHandler* aEventHandler,
    41     CIpsPlgEventHandler* aEventHandler,
    45     TBool aSignallingAllowed,
    42     TBool aSignallingAllowed )
    46     TBool aFetchWillFollow )
    43     {
    47     {
    44     FUNC_LOG;
    48     FUNC_LOG;
    45     CIpsPlgPop3ConnectOp* op = 
    49     CIpsPlgPop3ConnectOp* op = new(ELeave) CIpsPlgPop3ConnectOp(
    46         new(ELeave) CIpsPlgPop3ConnectOp( aMsvSession, aObserverRequestStatus, 
    50         aMsvSession,
    47             aService, aForcePopulate, aActivityTimer, aFSMailBoxId,
    51         aObserverRequestStatus,
    48             aFSOperationObserver, aFSRequestId, 
    52         aService,
    49             aEventHandler, aSignallingAllowed );
    53         aForcePopulate,
    50         
    54         aActivityTimer,
       
    55         aFSMailBoxId,
       
    56         aFSOperationObserver,
       
    57         aFSRequestId,
       
    58         aEventHandler,
       
    59         aSignallingAllowed,
       
    60         aFetchWillFollow );
       
    61 
       
    62     CleanupStack::PushL( op );
    51     CleanupStack::PushL( op );
    63     op->ConstructL();
    52     op->ConstructL();
    64     CleanupStack::Pop( op );
    53     CleanupStack::Pop( op );
    65     return op;
    54     return op;
    66     }
    55     }
    70 // ----------------------------------------------------------------------------
    59 // ----------------------------------------------------------------------------
    71 //
    60 //
    72 CIpsPlgPop3ConnectOp::~CIpsPlgPop3ConnectOp()
    61 CIpsPlgPop3ConnectOp::~CIpsPlgPop3ConnectOp()
    73     {
    62     {
    74     FUNC_LOG;
    63     FUNC_LOG;
    75     // <qmail> removed iEntry;
    64     delete iEntry;
    76     // <qmail> removed iSelection;
    65     delete iSelection;
    77     // <qmail> removed state setting
    66 
       
    67     iState = EIdle;
    78     }
    68     }
    79 
    69 
    80 // ----------------------------------------------------------------------------
    70 // ----------------------------------------------------------------------------
    81 // CIpsPlgPop3ConnectOp::ProgressL()
    71 // CIpsPlgPop3ConnectOp::ProgressL()
    82 // ----------------------------------------------------------------------------
    72 // ----------------------------------------------------------------------------
    86     FUNC_LOG;
    76     FUNC_LOG;
    87     if( iError != KErrNone )
    77     if( iError != KErrNone )
    88         {
    78         {
    89         return GetErrorProgressL( iError );
    79         return GetErrorProgressL( iError );
    90         }
    80         }
    91     else if( iSubOperation )
    81     else if( iOperation )
    92         {
    82         {
    93         return iSubOperation->ProgressL();
    83         return iOperation->ProgressL();
    94         }
    84         }
    95     
    85     
    96     iProgress().iErrorCode = KErrNone;
    86     iProgress().iErrorCode = KErrNone;
    97     return iProgress;    
    87     return iProgress;    
    98     }   
    88     }   
   101 // ----------------------------------------------------------------------------
    91 // ----------------------------------------------------------------------------
   102 //
    92 //
   103 void CIpsPlgPop3ConnectOp::DoCancel()
    93 void CIpsPlgPop3ConnectOp::DoCancel()
   104     {
    94     {
   105     FUNC_LOG;
    95     FUNC_LOG;
   106     if( iSubOperation )
    96     if( iOperation )
   107         {
    97         {
   108         iSubOperation->Cancel();
    98         iOperation->Cancel();
   109         }
    99         }
   110     CompleteObserver( KErrCancel );
   100     CompleteObserver( KErrCancel );
   111     }
   101     }
   112 
   102 
   113 // ----------------------------------------------------------------------------
   103 // ----------------------------------------------------------------------------
   115 // ----------------------------------------------------------------------------
   105 // ----------------------------------------------------------------------------
   116 //
   106 //
   117 void CIpsPlgPop3ConnectOp::DoRunL()
   107 void CIpsPlgPop3ConnectOp::DoRunL()
   118     {
   108     {
   119     FUNC_LOG;
   109     FUNC_LOG;
   120     TInt err( KErrNone );
   110     // handle these error situations properly, 
   121 
   111     // and report somehow back to framework
   122     // <qmail> remove EQueryingDetails state
   112     TInt err  = KErrNone;
   123     if ( iState == EStartConnect )
   113  
   124         {
   114     if ( iState == EQueryingDetails )
   125         if ( iSubOperation )
   115         {
       
   116         // Retry connect.
       
   117         DoConnectL();
       
   118         iState = EConnected;
       
   119         }       
       
   120     else if ( iState == EStartConnect )
       
   121         {
       
   122         
       
   123         if ( iOperation )
   126             {
   124             {
   127             // operation exist and it means 
   125             // operation exist and it means 
   128             // disconnect operation was ongoing.
   126             // disconnect operation was ongoing.
   129             delete iSubOperation;
   127             // How handle errors
   130             iSubOperation = NULL;
   128             delete iOperation;
       
   129             iOperation = NULL;
   131             }
   130             }
   132         
   131         
   133 // <qmail> ValidateL removed
   132         if ( ValidateL() )
   134         // Begin Connect.
   133             {
   135         DoConnectL();
   134             // Begin Connect.
   136         iState = EConnected;
   135             DoConnectL();
       
   136             iState = EConnected;
       
   137             }
       
   138         else
       
   139             {
       
   140             User::Leave( KErrCancel );    // User cancelled.
       
   141             }
   137         }
   142         }
   138     else if ( iState == EConnected )
   143     else if ( iState == EConnected )
   139         {
   144         {
   140         // Connect completed
   145         // Connect completed.
   141         // <qmail> Login details checking removed
       
   142         err = GetOperationErrorCodeL( );
   146         err = GetOperationErrorCodeL( );
   143         User::LeaveIfError( err );
   147             
   144 
   148         if ( ( err == KPop3InvalidUser ) ||
   145         if ( iForcePopulate && Connected() )
   149              ( err == KPop3InvalidLogin )  ||
   146             {
   150              ( err == KPop3InvalidApopLogin ) )
   147             iState = EPopulate;
   151             {
   148             DoPopulateL();
   152             // Login details are wrong. Trying to ask for password
   149             }
   153             if ( !QueryUserPassL() )
   150         // <qmail>
   154                 {
   151         else if( iFetchWillFollow && Connected() )
   155                 CompleteObserver( err );
   152             {
   156                 }
   153             // Leave connection open to make fetch
   157             }
   154             // operation possible
   158         else if ( err == KErrNone )
   155             iState = EIdle;
   159             {
   156             CompleteObserver( KErrNone );
   160             if ( iForcePopulate && Connected() )
   157             }
   161                 {
   158         // </qmail>
   162                 iState = EPopulate;
       
   163                 DoPopulateL();
       
   164                 }
       
   165             else
       
   166                 {
       
   167                 iState = EIdle;
       
   168                 CompleteObserver( KErrNone );
       
   169                 }
       
   170             }
   159         else
   171         else
   160             {
   172             {
   161             // <qmail>
   173             // We can't do this before, because 
   162             // start disconnecting
   174             // we want to handle KPop3InvalidUser,
   163             iState = EDisconnecting;
   175             // KPop3InvalidLogin and KPop3InvalidApopLogin separately.
   164             DoDisconnectL();
   176             User::Leave( err );
   165             // </qmail>
       
   166             }
   177             }
   167         }
   178         }
   168     else if ( iState == EPopulate )
   179     else if ( iState == EPopulate )
   169         {
   180         {
   170         err = GetOperationErrorCodeL( );
   181         err = GetOperationErrorCodeL( );
   171         if ( iEventHandler )
   182         if ( iEventHandler )
   172             {
   183             {
   173             iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncCompleted, err );
   184             iEventHandler->SetNewPropertyEvent( 
   174             }
   185                     iService, KIpsSosEmailSyncCompleted, err );
   175         CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( iMsvSession, iService );
   186             }
   176 
   187         CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL(
   177         // <qmail>
   188                 iMsvSession, iService );
   178         // start disconnecting
   189         CompleteObserver( err ); 
   179         iState = EDisconnecting;
   190         }
   180         DoDisconnectL();
       
   181         // </qmail>
       
   182         }
       
   183     // <qmail>
       
   184     else if ( iState == EDisconnecting )
       
   185         {
       
   186         // we're done here
       
   187         CompleteObserver( KErrNone );
       
   188         }
       
   189     // </qmail>
       
   190     // <qmail> removed state EErrInvalidDetails
       
   191     else
   191     else
   192         {
   192         {
   193         User::Panic( KIpsPlgPopConnectPanic ,KErrNotFound);
   193         User::Panic( KIpsPlgPopConnectPanic ,KErrNotFound);
   194         }
   194         }
       
   195     
   195     }
   196     }
   196 
   197 
   197 // ----------------------------------------------------------------------------
   198 // ----------------------------------------------------------------------------
   198 // CIpsPlgPop3ConnectOp::GetErrorProgressL
   199 // CIpsPlgPop3ConnectOp::GetErrorProgressL
   199 // ----------------------------------------------------------------------------
   200 // ----------------------------------------------------------------------------
   200 //
   201 //
   201 const TDesC8& CIpsPlgPop3ConnectOp::GetErrorProgressL( TInt aError )
   202 const TDesC8& CIpsPlgPop3ConnectOp::GetErrorProgressL( TInt aError )
   202     {
   203     {
   203     FUNC_LOG;
   204     FUNC_LOG;
   204     iError = aError;
   205     iError = aError;
   205     if ( iSubOperation && iError == KErrNone )
   206     if ( iOperation && iError == KErrNone )
   206         {
   207         {
   207         return iSubOperation->ProgressL();
   208         return iOperation->ProgressL();
   208         }
   209         }
   209     TPop3Progress& progress = iProgress();
   210     TPop3Progress& progress = iProgress();
   210     progress.iPop3Progress = TPop3Progress::EPopConnecting;
   211     progress.iPop3Progress = TPop3Progress::EPopConnecting;
   211     progress.iTotalMsgs = 0;
   212     progress.iTotalMsgs = 0;
   212     progress.iMsgsToProcess = 0;
   213     progress.iMsgsToProcess = 0;
   223 // ----------------------------------------------------------------------------
   224 // ----------------------------------------------------------------------------
   224 //
   225 //
   225 TFSProgress CIpsPlgPop3ConnectOp::GetFSProgressL() const
   226 TFSProgress CIpsPlgPop3ConnectOp::GetFSProgressL() const
   226     {
   227     {
   227     FUNC_LOG;
   228     FUNC_LOG;
       
   229     // might not never called, but gives something reasonable if called
   228     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   230     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
       
   231     result.iError = KErrNone;
   229     switch( iState )
   232     switch( iState )
   230         {
   233         {
   231         // <qmail> removed queryingdetails cases
   234         case EQueryingDetails:
       
   235         case EQueryingDetailsBusy:
       
   236             result.iProgressStatus = TFSProgress::EFSStatus_Authenticating;
       
   237             break;
   232         case EStartConnect:
   238         case EStartConnect:
   233         case EConnected:
   239         case EConnected:
   234             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   240             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   235             break;
   241             break;
   236         case EPopulate:
   242         case EPopulate:
   252 
   258 
   253 // ----------------------------------------------------------------------------
   259 // ----------------------------------------------------------------------------
   254 // CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp
   260 // CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp
   255 // ----------------------------------------------------------------------------
   261 // ----------------------------------------------------------------------------
   256 //
   262 //
   257 // <qmail> priority parameter has been removed
       
   258 // <qmail> MFSMailRequestObserver& changed to pointer
       
   259 // <qmail> aSignallingAllowed parameter added
       
   260 // <qmail> aFetchWillFollow parameter added
       
   261 // <qmail> iAlreadyConnected removed
       
   262 CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp(
   263 CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp(
   263     CMsvSession& aMsvSession,
   264     CMsvSession& aMsvSession,
   264     TRequestStatus& aObserverRequestStatus,
   265     TRequestStatus& aObserverRequestStatus,
   265     TMsvId aServiceId,
   266     TMsvId aServiceId,
   266     TBool aForcePopulate,
   267     TBool aForcePopulate,
   267     CIpsPlgTimerOperation& aActivityTimer,
   268     CIpsPlgTimerOperation& aActivityTimer,
   268     TFSMailMsgId aFSMailBoxId,
   269     TFSMailMsgId aFSMailBoxId,
   269     MFSMailRequestObserver* aFSOperationObserver,
   270     MFSMailRequestObserver& aFSOperationObserver,
   270     TInt aFSRequestId,
   271     TInt aFSRequestId,
   271     CIpsPlgEventHandler* aEventHandler,
   272     CIpsPlgEventHandler* aEventHandler,
   272     TBool aSignallingAllowed,
   273     TBool aSignallingAllowed )
   273     TBool aFetchWillFollow )
       
   274     :
   274     :
   275     CIpsPlgOnlineOperation(
   275     CIpsPlgOnlineOperation( aMsvSession, KConnectOpPriority,
   276         aMsvSession,
   276         aObserverRequestStatus, aActivityTimer, aFSMailBoxId,
   277         aObserverRequestStatus, 
   277         aFSOperationObserver, aFSRequestId, aSignallingAllowed ),
   278         aActivityTimer, 
       
   279         aFSMailBoxId,
       
   280         aFSOperationObserver, 
       
   281         aFSRequestId,
       
   282         aSignallingAllowed ),
       
   283     iState( EIdle ),
   278     iState( EIdle ),
       
   279     iEntry( NULL ),
       
   280     iPopulateLimit( KIpsPlgPop3PopulateLimitInitValue ),
   284     iForcePopulate( aForcePopulate ),
   281     iForcePopulate( aForcePopulate ),
       
   282     iSelection( NULL ),
   285     iEventHandler( aEventHandler ),
   283     iEventHandler( aEventHandler ),
   286     iFetchWillFollow( aFetchWillFollow )
   284     iAlreadyConnected( EFalse )
   287     {
   285     {
   288     iService = aServiceId; 
   286     iService = aServiceId; 
   289     }
   287     }
   290 
   288 
   291 // ----------------------------------------------------------------------------
   289 // ----------------------------------------------------------------------------
   294 //
   292 //
   295 void CIpsPlgPop3ConnectOp::ConstructL()
   293 void CIpsPlgPop3ConnectOp::ConstructL()
   296     {
   294     {
   297     FUNC_LOG;
   295     FUNC_LOG;
   298     BaseConstructL( KUidMsgTypePOP3 );
   296     BaseConstructL( KUidMsgTypePOP3 );
   299 
   297    	
   300     // <qmail> iSelection construction has been removed
   298     iEntry = iMsvSession.GetEntryL( iService );
   301 
   299     if ( !iEntry )
   302     CMsvEntry* cEntry = iMsvSession.GetEntryL( iService );
   300         {
   303     User::LeaveIfNull( cEntry );
   301         User::Leave( KErrGeneral );
   304     // NOTE: Not using cleanupStack as it is not needed in this situation:
   302         }
   305     const TMsvEntry tentry = cEntry->Entry();
   303     iSelection = new(ELeave) CMsvEntrySelection;
   306     delete cEntry;
   304     const TMsvEntry& tentry = iEntry->Entry();
   307     cEntry = NULL;
   305     
   308 
       
   309     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
   306     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
   310         {
   307         {
   311         // should we panic with own codes?
   308         // should we panic with own codes?
   312         User::Leave( KErrNotSupported );
   309         User::Leave( KErrNotSupported );
   313         }
   310         }
   314 
   311     
   315     // <qmail> no need to have population limit as member variable
   312     // get correct populate and sync limet values from settings
   316     // <qmail> it is read from settings when needed
       
   317     
       
   318     if ( tentry.Connected() )
       
   319         {      
       
   320         iState = EConnected;
       
   321         // <qmail> iAlreadyConnected removed
       
   322         }
       
   323     else
       
   324         {
       
   325         iState = EStartConnect;
       
   326         }
       
   327     // <qmail> SetActive(); moved inside CompleteThis();
       
   328     CompleteThis();
       
   329     }
       
   330 
       
   331 // ----------------------------------------------------------------------------
       
   332 // CIpsPlgPop3ConnectOp::DoConnectL()
       
   333 // ----------------------------------------------------------------------------
       
   334 //
       
   335 void CIpsPlgPop3ConnectOp::DoConnectL()
       
   336     {
       
   337     FUNC_LOG;
       
   338     // <qmail> unnecessary: iStatus = KRequestPending;
       
   339     NM_COMMENT("CIpsPlgPop3ConnectOp: connecting");
       
   340     InvokeClientMtmAsyncFunctionL( KPOP3MTMConnect, iService ); // <qmail> 1 param removed
       
   341     SetActive();
       
   342 
       
   343 // <qmail>
       
   344     if ( iEventHandler )
       
   345         {
       
   346         iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncStarted, KErrNone );
       
   347         }
       
   348 // </qmail>
       
   349     }
       
   350 
       
   351 // ----------------------------------------------------------------------------
       
   352 // CIpsPlgPop3ConnectOp::DoPopulateL()
       
   353 // ----------------------------------------------------------------------------
       
   354 //
       
   355 void CIpsPlgPop3ConnectOp::DoPopulateL()
       
   356     {
       
   357     FUNC_LOG;
       
   358     NM_COMMENT("CIpsPlgPop3ConnectOp: populating");
       
   359     // <qmail> unnecessary: iStatus = KRequestPending;
       
   360 
       
   361     // Prepare parameters and include filtering
       
   362     TImPop3PopulateOptions pop3GetMailInfo;
       
   363     pop3GetMailInfo.SetMaxEmailSize( KMaxTInt32 );
       
   364 // <qmail>
       
   365     pop3GetMailInfo.SetPopulationLimit( GetPopulateLimitFromSettingsL() );
       
   366     TPckgBuf<TImPop3PopulateOptions> params( pop3GetMailInfo );
       
   367 
       
   368     // <qmail> selection is no longer a member variable
       
   369     CMsvEntrySelection* selection = new(ELeave) CMsvEntrySelection;
       
   370     CleanupStack::PushL( selection );
       
   371     selection->InsertL( 0, iService );
       
   372     iBaseMtm->SwitchCurrentEntryL( iService );
       
   373     // Start the fetch operation
       
   374     InvokeClientMtmAsyncFunctionL( KPOP3MTMPopulateAll, *selection, params ); // <qmail> 1 param removed
       
   375     SetActive();
       
   376     CleanupStack::PopAndDestroy( selection );
       
   377 // <qmail> iEventHandler->SetNewPropertyEvent call removed from here
       
   378 // </qmail>
       
   379     }
       
   380 // <qmail> Connected() moved to baseclass
       
   381 
       
   382 // ----------------------------------------------------------------------------
       
   383 // ----------------------------------------------------------------------------
       
   384 // <qmail> return type
       
   385 TIpsOpType CIpsPlgPop3ConnectOp::IpsOpType() const
       
   386     {
       
   387     FUNC_LOG;
       
   388     return EIpsOpTypePop3SyncOp;
       
   389     }
       
   390 
       
   391 // <qmail> removed QueryUsrPassL() from here as unneeded
       
   392 // <qmail> removed ValidateL() (did nothing)
       
   393 
       
   394 // ----------------------------------------------------------------------------
       
   395 // ----------------------------------------------------------------------------    
       
   396 // 
       
   397 TInt CIpsPlgPop3ConnectOp::GetOperationErrorCodeL( )
       
   398     {
       
   399     FUNC_LOG;
       
   400     if ( !iSubOperation )
       
   401         {
       
   402         return KErrNotFound;
       
   403         }
       
   404     if ( !iSubOperation->IsActive() && iSubOperation->iStatus.Int() != KErrNone )
       
   405         {
       
   406         return iSubOperation->iStatus.Int();
       
   407         }
       
   408     
       
   409     TPckgBuf<TPop3Progress> paramPack;
       
   410     paramPack.Copy( iSubOperation->ProgressL() );
       
   411     const TPop3Progress& progress = paramPack();
       
   412     
       
   413     return progress.iErrorCode;
       
   414     }
       
   415 
       
   416 // <qmail> removed CIpsPlgImap4ConnectOp::CredientialsSetL
       
   417 
       
   418 //<qmail> new functions
       
   419 // ----------------------------------------------------------------------------
       
   420 // ----------------------------------------------------------------------------
       
   421 void CIpsPlgPop3ConnectOp::DoDisconnectL()
       
   422     {
       
   423     FUNC_LOG;
       
   424     // <qmail> unnecessary: iStatus = KRequestPending;
       
   425     NM_COMMENT("CIpsPlgPop3ConnectOp: disconnecting");
       
   426     InvokeClientMtmAsyncFunctionL( KPOP3MTMDisconnect, iService ); // <qmail> 1 param removed
       
   427     SetActive();
       
   428     }
       
   429 
       
   430 // ----------------------------------------------------------------------------
       
   431 // ----------------------------------------------------------------------------
       
   432 TInt CIpsPlgPop3ConnectOp::GetPopulateLimitFromSettingsL()
       
   433     {
       
   434     FUNC_LOG;
       
   435     TInt limit( KDefaultPopulateLimit );
       
   436         
       
   437     CImPop3Settings* settings = new(ELeave) CImPop3Settings();
   313     CImPop3Settings* settings = new(ELeave) CImPop3Settings();
   438     CleanupStack::PushL( settings );
   314     CleanupStack::PushL( settings );
   439     TPopAccount popAccountId;
   315     TPopAccount popAccountId;
   440     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   316     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   441     accounts->GetPopAccountL( iService , popAccountId );
   317     accounts->GetPopAccountL( iService , popAccountId );
   442     accounts->LoadPopSettingsL( popAccountId, *settings );
   318     accounts->LoadPopSettingsL( popAccountId, *settings );
   443     limit = settings->PopulationLimit();
   319     iPopulateLimit = settings->PopulationLimit();
   444     if ( limit > 0 )
   320     if ( iPopulateLimit > 0 )
   445         {
   321         {
   446         // basically doing a _very_rough_ conversion from kilobyte value to number-of-rows
   322         iPopulateLimit = ( iPopulateLimit * 1024 ) / 75;
   447         limit = ( limit * KPopulateAlgorithmBytesInKilo ) / KPopulateAlgorithmRowLength;
   323         }
   448         }
   324     else if ( iPopulateLimit == KIpsSetDataHeadersOnly )    
       
   325         {
       
   326         iPopulateLimit = 0;
       
   327         }
       
   328     else
       
   329         {
       
   330         iPopulateLimit = KMaxTInt;
       
   331         }
       
   332     
   449     CleanupStack::PopAndDestroy( 2, settings );
   333     CleanupStack::PopAndDestroy( 2, settings );
   450     return limit;
   334        
   451     }
   335     if ( tentry.Connected() )
   452 
   336         {      
   453 //</qmail>
   337         iState = EConnected; 
       
   338         iAlreadyConnected = ETrue;
       
   339         SetActive();
       
   340         CompleteThis();
       
   341         }
       
   342     else
       
   343         {
       
   344         iState = EStartConnect; 
       
   345         SetActive();
       
   346         CompleteThis();
       
   347         }    
       
   348     }
       
   349 
       
   350 // ----------------------------------------------------------------------------
       
   351 // CIpsPlgPop3ConnectOp::DoConnectL()
       
   352 // ----------------------------------------------------------------------------
       
   353 //
       
   354 void CIpsPlgPop3ConnectOp::DoConnectL()
       
   355     {
       
   356     FUNC_LOG;
       
   357     iStatus = KRequestPending;
       
   358     InvokeClientMtmAsyncFunctionL( KPOP3MTMConnect, iService, iService );
       
   359     SetActive();
       
   360     }
       
   361 
       
   362 // ----------------------------------------------------------------------------
       
   363 // CIpsPlgPop3ConnectOp::DoPopulateL()
       
   364 // ----------------------------------------------------------------------------
       
   365 //
       
   366 void CIpsPlgPop3ConnectOp::DoPopulateL()
       
   367     {
       
   368     FUNC_LOG;
       
   369     iStatus = KRequestPending;
       
   370 
       
   371     // Prepare parameters and include filtering
       
   372     TImPop3PopulateOptions pop3GetMailInfo;
       
   373     pop3GetMailInfo.SetMaxEmailSize( KMaxTInt32 );
       
   374     pop3GetMailInfo.SetPopulationLimit( iPopulateLimit );
       
   375     TPckgBuf<TImPop3PopulateOptions> params( pop3GetMailInfo );
       
   376 
       
   377     iSelection->InsertL(0, iService);
       
   378     iBaseMtm->SwitchCurrentEntryL( iService );
       
   379     // Start the fetch operation
       
   380     InvokeClientMtmAsyncFunctionL( KPOP3MTMPopulateAll, *iSelection,
       
   381         iService, params);
       
   382 
       
   383     SetActive();
       
   384 
       
   385     if ( iEventHandler )
       
   386         {
       
   387         iEventHandler->SetNewPropertyEvent( 
       
   388                 iService, KIpsSosEmailSyncStarted, KErrNone );
       
   389         } 
       
   390     }
       
   391 // ----------------------------------------------------------------------------
       
   392 // ----------------------------------------------------------------------------
       
   393 //
       
   394 TBool CIpsPlgPop3ConnectOp::Connected() const
       
   395     {
       
   396     FUNC_LOG;
       
   397     TMsvEntry tentry;
       
   398     TMsvId service;
       
   399     iMsvSession.GetEntry(iService, service, tentry );
       
   400     return tentry.Connected();
       
   401     }
       
   402 
       
   403 // ----------------------------------------------------------------------------
       
   404 // CIpsPlgImap4ConnectOp::IpsOpType()
       
   405 // ----------------------------------------------------------------------------
       
   406 // 
       
   407 TInt CIpsPlgPop3ConnectOp::IpsOpType() const
       
   408     {
       
   409     FUNC_LOG;
       
   410     return EIpsOpTypePop3SyncOp;
       
   411     }
       
   412 
       
   413 
       
   414 // ----------------------------------------------------------------------------
       
   415 // CIpsPlgPop3ConnectOp::ValidateL()
       
   416 // ----------------------------------------------------------------------------
       
   417 //
       
   418 TBool CIpsPlgPop3ConnectOp::ValidateL()
       
   419     {
       
   420     // do proper validation. OR: not needed?
       
   421     return ETrue;
       
   422     }
       
   423 
       
   424 // ----------------------------------------------------------------------------
       
   425 // CIpsPlgPop3ConnectOp::QueryUserPassL()
       
   426 // ----------------------------------------------------------------------------
       
   427 //
       
   428 TBool CIpsPlgPop3ConnectOp::QueryUserPassL()
       
   429     {
       
   430     FUNC_LOG;
       
   431 
       
   432     if ( iEventHandler )
       
   433         {
       
   434         // ask for credentials for pop3 account and wait for callback
       
   435         if ( iEventHandler->QueryUsrPassL( iEntry->EntryId(), this ) )
       
   436             {
       
   437             iState = EQueryingDetails;
       
   438             }
       
   439         else
       
   440             {
       
   441             // another operation is waiting for password
       
   442             iState = EQueryingDetailsBusy;
       
   443             }
       
   444 
       
   445         return ETrue;
       
   446         }
       
   447 
       
   448     return EFalse;
       
   449     }
       
   450 
       
   451 
       
   452 // ----------------------------------------------------------------------------
       
   453 // CIpsPlgPop3ConnectOp::GetOperationErrorCodeL()
       
   454 // ----------------------------------------------------------------------------    
       
   455 // 
       
   456 TInt CIpsPlgPop3ConnectOp::GetOperationErrorCodeL( )
       
   457     {
       
   458     FUNC_LOG;
       
   459     
       
   460     if ( iAlreadyConnected )
       
   461         {
       
   462         // Connected state was set in CIpsPlgPop3ConnectOp::ConstructL()
       
   463         // so iOperation is null
       
   464         return KErrNone;
       
   465         }
       
   466         
       
   467     if ( !iOperation )
       
   468         {
       
   469         return KErrNotFound;
       
   470         }
       
   471     if ( !iOperation->IsActive() && iOperation->iStatus.Int() != KErrNone )
       
   472         {
       
   473         return iOperation->iStatus.Int();
       
   474         }
       
   475     
       
   476     TPckgBuf<TPop3Progress> paramPack;
       
   477     paramPack.Copy( iOperation->ProgressL() );
       
   478     const TPop3Progress& progress = paramPack();
       
   479     
       
   480     return progress.iErrorCode;
       
   481     }
       
   482 
       
   483 // ----------------------------------------------------------------------------
       
   484 // ----------------------------------------------------------------------------
       
   485 void CIpsPlgPop3ConnectOp::CredientialsSetL( TInt aEvent )
       
   486     {
       
   487     FUNC_LOG;
       
   488 
       
   489     if ( iState == EQueryingDetails )
       
   490         {
       
   491         // response for our operation`s query
       
   492         if ( aEvent == EIPSSosCredientialsCancelled )
       
   493             {
       
   494             // user canceled operation
       
   495             CompleteObserver( KErrCancel );
       
   496             }
       
   497 
       
   498         // password has been set, continue with operation
       
   499         SetActive();
       
   500         CompleteThis();
       
   501         }
       
   502     else if ( iState == EQueryingDetailsBusy )
       
   503         {
       
   504         // response for other operation`s query
       
   505         // we could try to ask for password now,
       
   506         // but decision was made to cancel operation
       
   507         CompleteObserver( KErrCancel );
       
   508         SetActive();
       
   509         CompleteThis();
       
   510         }
       
   511     }
       
   512 //EOF
       
   513 
       
   514