ipsservices/ipssosplugin/src/ipsplgimap4connectop.cpp
branchRCL_3
changeset 63 d189ee25cf9d
parent 8 e1b6206813b4
child 64 3533d4323edc
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
    14 * Description:  IMAP4 connect operation
    14 * Description:  IMAP4 connect operation
    15 *
    15 *
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
       
    20 #include "emailtrace.h"
    19 #include "emailtrace.h"
    21 #include "ipsplgheaders.h"
    20 #include "ipsplgheaders.h"
    22 
    21 
    23 
    22 // <qmail> removed
    24 _LIT( KIpsPlgIpsConnPanic, "IpsConn" ); 
    23 
       
    24 // <qmail> KIpsPlgIpsConnPanic removed
    25 
    25 
    26 // ----------------------------------------------------------------------------
    26 // ----------------------------------------------------------------------------
    27 // CIpsPlgImap4ConnectOp::NewL()
    27 // CIpsPlgImap4ConnectOp::NewL()
    28 // ----------------------------------------------------------------------------
    28 // ----------------------------------------------------------------------------
    29 // 
    29 // <qmail> priority parameter has been removed
       
    30 // <qmail> MFSMailRequestObserver& changed it to pointer
       
    31 // <qmail> aSignallingAllowed parameter has been removed
    30 CIpsPlgImap4ConnectOp* CIpsPlgImap4ConnectOp::NewL(
    32 CIpsPlgImap4ConnectOp* CIpsPlgImap4ConnectOp::NewL(
    31     CMsvSession& aMsvSession,
    33     CMsvSession& aMsvSession,
    32 	TInt aPriority,
       
    33     TRequestStatus& aObserverRequestStatus,
    34     TRequestStatus& aObserverRequestStatus,
    34     TMsvId aService,
    35     TMsvId aService,
    35     CIpsPlgTimerOperation& aActivityTimer,
    36     CIpsPlgTimerOperation& aActivityTimer,
    36     TFSMailMsgId aFSMailBoxId,
    37     TFSMailMsgId aFSMailBoxId,
    37     MFSMailRequestObserver& aFSOperationObserver,
    38     MFSMailRequestObserver* aFSOperationObserver,
    38     TInt aFSRequestId,
    39     TInt aFSRequestId,
    39     CIpsPlgEventHandler* aEventHandler,
    40     CIpsPlgEventHandler* aEventHandler,
    40     TBool aDoPlainConnect,
    41     TBool aDoPlainConnect )
    41     TBool aSignallingAllowed )
       
    42     {
    42     {
    43     FUNC_LOG;
    43     FUNC_LOG;
    44     CIpsPlgImap4ConnectOp* self = new (ELeave) CIpsPlgImap4ConnectOp(
    44     CIpsPlgImap4ConnectOp* self = new (ELeave) CIpsPlgImap4ConnectOp(
    45         aMsvSession, 
    45         aMsvSession, 
    46         aPriority, 
       
    47         aObserverRequestStatus,
    46         aObserverRequestStatus,
    48         aService, 
    47         aService, 
    49         aActivityTimer,
    48         aActivityTimer,
    50         aFSMailBoxId, 
    49         aFSMailBoxId, 
    51         aFSOperationObserver,
    50         aFSOperationObserver,
    52         aFSRequestId,
    51         aFSRequestId,
    53         aDoPlainConnect,
    52         aDoPlainConnect,
    54         aSignallingAllowed,
       
    55         aEventHandler );
    53         aEventHandler );
    56         
    54         
    57     CleanupStack::PushL( self );
    55     CleanupStack::PushL( self );
    58     self->ConstructL();
    56     self->ConstructL();
    59     CleanupStack::Pop( self );
    57     CleanupStack::Pop( self );
    61     }
    59     }
    62 
    60 
    63 // ----------------------------------------------------------------------------
    61 // ----------------------------------------------------------------------------
    64 // CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp()
    62 // CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp()
    65 // ----------------------------------------------------------------------------
    63 // ----------------------------------------------------------------------------
    66 // 
    64 // <qmail> priority parameter has been removed
       
    65 // <qmail> MFSMailRequestObserver& changed it to pointer
       
    66 // <qmail> aSignallingAllowed parameter has been removed
    67 CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp(
    67 CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp(
    68     CMsvSession& aMsvSession,
    68     CMsvSession& aMsvSession,
    69 	TInt aPriority,
       
    70     TRequestStatus& aObserverRequestStatus,
    69     TRequestStatus& aObserverRequestStatus,
    71     TMsvId aService,
    70     TMsvId aService,
    72     CIpsPlgTimerOperation& aActivityTimer,
    71     CIpsPlgTimerOperation& aActivityTimer,
    73     TFSMailMsgId aFSMailBoxId,
    72     TFSMailMsgId aFSMailBoxId,
    74     MFSMailRequestObserver& aFSOperationObserver,
    73     MFSMailRequestObserver* aFSOperationObserver,
    75     TInt aFSRequestId,
    74     TInt aFSRequestId,
    76     TBool aDoPlainConnect,
    75     TBool aDoPlainConnect,
    77     TBool aSignallingAllowed,
       
    78     CIpsPlgEventHandler* aEventHandler)
    76     CIpsPlgEventHandler* aEventHandler)
    79     :
    77     :
    80     CIpsPlgOnlineOperation(
    78     CIpsPlgOnlineOperation(
    81 	    aMsvSession,
    79 	    aMsvSession,
    82 	    aPriority,
       
    83 	    aObserverRequestStatus,
    80 	    aObserverRequestStatus,
    84 	    aActivityTimer,
    81 	    aActivityTimer,
    85 	    aFSMailBoxId,
    82 	    aFSMailBoxId,
    86 	    aFSOperationObserver,
    83 	    aFSOperationObserver,
    87 	    aFSRequestId,
    84 	    aFSRequestId ),
    88     	aSignallingAllowed ),
    85     iState( EStateIdle ),
       
    86     iSelection( NULL ),
    89     iDoPlainConnect( aDoPlainConnect ),
    87     iDoPlainConnect( aDoPlainConnect ),
    90     iEventHandler( aEventHandler ),
    88     iEventHandler( aEventHandler ),
    91     iIsSyncStartedSignaled( EFalse ),
    89     iIsSyncStartedSignaled( EFalse )
    92     iAlreadyConnected( EFalse )
       
    93     {
    90     {
    94     FUNC_LOG;
    91     FUNC_LOG;
    95     iService = aService;
    92     iService = aService;
    96     }
    93     }
    97 
    94 
   102 CIpsPlgImap4ConnectOp::~CIpsPlgImap4ConnectOp()
    99 CIpsPlgImap4ConnectOp::~CIpsPlgImap4ConnectOp()
   103     {
   100     {
   104     FUNC_LOG;
   101     FUNC_LOG;
   105     Cancel();
   102     Cancel();
   106     delete iSelection;
   103     delete iSelection;
   107     iState = EStateIdle;
   104     // <qmail> setting state in destructor makes no sense
   108     }
   105     }
   109 
   106 
   110 // ----------------------------------------------------------------------------
   107 // ----------------------------------------------------------------------------
   111 // CIpsPlgImap4ConnectOp::ConstructL()
   108 // CIpsPlgImap4ConnectOp::ConstructL()
   112 // ----------------------------------------------------------------------------
   109 // ----------------------------------------------------------------------------
   124     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
   121     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
   125         {
   122         {
   126         User::Panic( KIpsPlgIpsConnPanic, KErrNotSupported );
   123         User::Panic( KIpsPlgIpsConnPanic, KErrNotSupported );
   127         }
   124         }
   128     
   125     
   129     if ( tentry.Connected() )
   126     // <qmail> moved here from StartL which was removed
   130         {      
   127     if ( Connected() && iDoPlainConnect )
   131         iState = EStateCompleted; 
   128         {
   132         iAlreadyConnected = ETrue;
   129         // trivial case: connect requested, but already connected
   133         SetActive();
   130         // (sync is done automatically on background)
   134         CompleteThis();
   131         iState = EStateIdle;
   135         }
   132         }
   136     else
   133     else
   137         {
   134         {
   138         iState = EStateStartConnect;
   135         iState = EStateStartConnect;
   139         iStatus = KRequestPending;    
   136         }
   140         SetActive();
   137     iStatus = KRequestPending;    
   141        CompleteThis();
   138     // <qmail> SetActive(); moved inside CompleteThis();
   142         }    
   139     CompleteThis();
   143     }
   140     }
   144 
   141 
   145 // ----------------------------------------------------------------------------
   142 // ----------------------------------------------------------------------------
   146 // CIpsPlgImap4ConnectOp::ProgressL()
   143 // CIpsPlgImap4ConnectOp::ProgressL()
   147 // ----------------------------------------------------------------------------
   144 // ----------------------------------------------------------------------------
   151     FUNC_LOG;
   148     FUNC_LOG;
   152     if( iError != KErrNone )
   149     if( iError != KErrNone )
   153         {
   150         {
   154         return GetErrorProgressL( iError );
   151         return GetErrorProgressL( iError );
   155         }
   152         }
   156     else if(iOperation)
   153     else if( iSubOperation )
   157         {
   154         {
   158         return iOperation->ProgressL();
   155         return iSubOperation->ProgressL();
   159         }
   156         }
   160         
   157         
   161     TImap4CompoundProgress& prog = iProgressBuf();
   158     TImap4CompoundProgress& prog = iProgressBuf();
   162     prog.iGenericProgress.iErrorCode = KErrNone;
   159     prog.iGenericProgress.iErrorCode = KErrNone;
   163     return iProgressBuf;
   160     return iProgressBuf;
   185     // might not never called, but gives something reasonable if called
   182     // might not never called, but gives something reasonable if called
   186     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   183     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   187     result.iError = KErrNone;
   184     result.iError = KErrNone;
   188     switch( iState )
   185     switch( iState )
   189         {
   186         {
   190         case EStateQueryingDetails:
   187         // <qmail> cases EStateQueryingDetails/EStateQueryingDetailsBusy removed
   191         case EStateQueryingDetailsBusy:
       
   192             result.iProgressStatus = TFSProgress::EFSStatus_Authenticating;
       
   193             break;
       
   194         case EStateStartConnect:
   188         case EStateStartConnect:
   195             result.iProgressStatus = TFSProgress::EFSStatus_Started;
   189             result.iProgressStatus = TFSProgress::EFSStatus_Started;
   196             break;
   190             break;
   197         case EStateConnectAndSync:
   191         case EStateConnectAndSync:
   198             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   192             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   211     }
   205     }
   212 
   206 
   213 // ----------------------------------------------------------------------------
   207 // ----------------------------------------------------------------------------
   214 // CIpsPlgImap4ConnectOp::IpsOpType()
   208 // CIpsPlgImap4ConnectOp::IpsOpType()
   215 // ----------------------------------------------------------------------------
   209 // ----------------------------------------------------------------------------
   216 // 
   210 // <qmail> return type
   217 TInt CIpsPlgImap4ConnectOp::IpsOpType() const
   211 TIpsOpType CIpsPlgImap4ConnectOp::IpsOpType() const
   218     {
   212     {
   219     FUNC_LOG;
   213     FUNC_LOG;
   220     return EIpsOpTypeImap4SyncOp;
   214     return EIpsOpTypeImap4SyncOp;
   221     }
   215     }
   222 
   216 
   223 // ----------------------------------------------------------------------------
   217 // <qmail> Connected() moved to baseclass
   224 // CIpsPlgImap4ConnectOp::Connected()
       
   225 // ----------------------------------------------------------------------------
       
   226 // 
       
   227 TBool CIpsPlgImap4ConnectOp::Connected() const
       
   228     {
       
   229     FUNC_LOG;
       
   230     TMsvEntry tentry;
       
   231     TMsvId service;
       
   232     iMsvSession.GetEntry(iService, service, tentry );
       
   233     return tentry.Connected();
       
   234     }
       
   235 
       
   236 
       
   237 // ----------------------------------------------------------------------------
   218 // ----------------------------------------------------------------------------
   238 // CIpsPlgImap4ConnectOp::DoCancel()
   219 // CIpsPlgImap4ConnectOp::DoCancel()
   239 // ----------------------------------------------------------------------------
   220 // ----------------------------------------------------------------------------
   240 // 
   221 // 
   241 void CIpsPlgImap4ConnectOp::DoCancel()
   222 void CIpsPlgImap4ConnectOp::DoCancel()
   242     {
   223     {
   243     FUNC_LOG;
   224     FUNC_LOG;
   244     if( iOperation )
   225     if( iSubOperation )
   245         {
   226         {
   246         iOperation->Cancel();
   227         iSubOperation->Cancel();
   247         }
   228         }
   248     SignalSyncCompleted( KErrCancel );
   229     SignalSyncCompleted( KErrCancel );
   249     CompleteObserver( KErrCancel );
   230     CompleteObserver( KErrCancel );
   250     }
   231     }
   251 
   232 
   254 // ----------------------------------------------------------------------------    
   235 // ----------------------------------------------------------------------------    
   255 //  
   236 //  
   256 void CIpsPlgImap4ConnectOp::DoRunL()
   237 void CIpsPlgImap4ConnectOp::DoRunL()
   257     {
   238     {
   258     FUNC_LOG;
   239     FUNC_LOG;
   259     TInt err = KErrNone;
   240     TInt err( KErrNone );
   260     __ASSERT_DEBUG( !(iOperation && iOperation->IsActive()), 
   241     __ASSERT_DEBUG( !(iSubOperation && iSubOperation->IsActive()),
   261             User::Panic( KIpsPlgPanicCategory, KErrGeneral ) );
   242         User::Panic( KIpsPlgPanicCategory, KErrGeneral ) );
   262     if ( iOperation )
   243     if ( iSubOperation )
   263         {
   244         {
   264         err = iOperation->iStatus.Int();
   245         err = iSubOperation->iStatus.Int();
   265         delete iOperation;
   246         delete iSubOperation;
   266         iOperation = NULL;
   247         iSubOperation = NULL;
   267         }
   248         }
   268     
   249     
   269     switch( iState )
   250     switch( iState )
   270         {
   251         {
   271         case EStateQueryingDetails:
   252         // <qmail> removing case EStateQueryingDetails
   272             // querying pass finished - try to reconnect
   253         case EStateStartConnect:
       
   254             // <qmail> remove StartL() func and replace it directly with DoConnectOpL
   273             DoConnectOpL();
   255             DoConnectOpL();
   274             break;
   256             break;
   275         case EStateStartConnect:
       
   276         	StartL();
       
   277         	break;
       
   278         case EStateConnectAndSync:
   257         case EStateConnectAndSync:
   279             // Connection completed
   258             // Connection completed
   280 
   259                 
   281             if ( err == KErrImapBadLogon )
   260             // <qmail> all errors should fail the op
       
   261             if( err )
   282                 {
   262                 {
   283                 // Login details are wrong. Trying to ask for password
   263                 iState = EStateIdle;
   284                 if ( QueryUserPassL() )
   264                 // <qmail> SetActive(); moved inside CompleteThis();
   285                     {
   265                 CompleteThis();
   286                     err = KErrNone;
       
   287                     }
       
   288                 }
   266                 }
   289             else if ( err == KErrNone )
   267             else
   290                 {
   268                 {
   291                 // no errors in connection
   269                 // no errors in connection
   292                 if( !iDoPlainConnect )
   270                 if( !iDoPlainConnect )
   293                     {
   271                     {
   294                     DoPopulateAllL();
   272                     DoPopulateAllL();
   295                     }
   273                     }
   296                 else
   274                 else
   297                     {
   275                     {
   298                     // Get on with others using this class for connection only
   276                     // Get on with others using this class for connection only
   299                     iState = EStateIdle;
   277                     iState = EStateIdle;
   300                     SetActive();
   278                     // <qmail> SetActive(); moved inside CompleteThis();
   301                     CompleteThis();
   279                     CompleteThis();
   302                     }
   280                     }
   303                 }
   281                 }
   304             break;
   282             break;
   305         case EStatePopulateAllCompleted:
   283         case EStatePopulateAllCompleted:
   306             CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL(
   284             CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( iMsvSession, iService );
   307                     iMsvSession, iService );
       
   308             // break command is intentially left out
   285             // break command is intentially left out
   309         case EStateCompleted:
   286         case EStateCompleted:
   310             if ( err == KErrNone )
   287             if ( err == KErrNone )
   311                 {
   288                 {
   312                 iState = EStateIdle;
   289                 iState = EStateIdle;
   313                 SetActive();
   290                 // <qmail> SetActive(); moved inside CompleteThis();
   314                 CompleteThis();
   291                 CompleteThis();
   315                 }
   292                 }
   316             break;
   293             break;
   317         case EStateIdle:
   294         case EStateIdle:
   318         default:
   295         default:
   319             if ( iOperation )
   296             if ( iSubOperation )
   320                 {
   297                 {
   321                 delete iOperation;
   298                 delete iSubOperation;
   322                 iOperation = NULL;
   299                 iSubOperation = NULL;
   323                 }
   300                 }
   324             CompleteObserver();
   301             CompleteObserver();
   325             break;
   302             break;
   326         }
   303         }
   327    
   304    
   331         {
   308         {
   332         SignalSyncCompleted( err );
   309         SignalSyncCompleted( err );
   333         }
   310         }
   334     }
   311     }
   335 
   312 
   336 // ----------------------------------------------------------------------------
   313 // <qmail> CIpsPlgImap4ConnectOp::HandleImapConnectionEvent() removed
   337 // CIpsPlgImap4ConnectOp::HandleImapConnectionEvent()
       
   338 // ----------------------------------------------------------------------------
       
   339 // 
       
   340 void CIpsPlgImap4ConnectOp::HandleImapConnectionEvent(
       
   341     TImapConnectionEvent aConnectionEvent )
       
   342     {
       
   343     FUNC_LOG;
       
   344     switch ( aConnectionEvent )
       
   345         {
       
   346         case EConnectingToServer:
       
   347             break;
       
   348         case ESynchronisingFolderList:
       
   349         case ESynchronisingInbox:
       
   350 		case ESynchronisingFolders:
       
   351 		    // send sync started event in any of these sync events
       
   352 		    SignalSyncStarted();
       
   353 		    break;
       
   354 		case ESynchronisationComplete:
       
   355 		    break;
       
   356 		case EDisconnecting:
       
   357 		    break;
       
   358 		case EConnectionCompleted:
       
   359 	    default:
       
   360 	        break;
       
   361         }
       
   362     }
       
   363 
   314 
   364 // ----------------------------------------------------------------------------
   315 // ----------------------------------------------------------------------------
   365 // CIpsPlgImap4ConnectOp::RequestResponseL()
   316 // CIpsPlgImap4ConnectOp::RequestResponseL()
   366 // ----------------------------------------------------------------------------    
   317 // ----------------------------------------------------------------------------    
   367 //   
   318 //   
   381     iBaseMtm->SwitchCurrentEntryL( iService );
   332     iBaseMtm->SwitchCurrentEntryL( iService );
   382 
   333 
   383     iSelection->ResizeL(0);
   334     iSelection->ResizeL(0);
   384     iSelection->AppendL(iService);
   335     iSelection->AppendL(iService);
   385     
   336     
       
   337     // <qmail>
       
   338     iStatus = KRequestPending;
   386     if ( iDoPlainConnect && !Connected() )
   339     if ( iDoPlainConnect && !Connected() )
   387         {
   340         {
   388         TBuf8<1> parameter;
   341         TBuf8<1> parameter;
   389         iStatus = KRequestPending;
   342         NM_COMMENT("CIpsPlgImap4ConnectOp: do plain connect");
   390         // connect and synchronise starts background sync or idle
   343         // connect and synchronise starts background sync or idle
   391         iOperation = iBaseMtm->InvokeAsyncFunctionL(
   344         iSubOperation = iBaseMtm->InvokeAsyncFunctionL(
   392                 KIMAP4MTMConnect, *iSelection, parameter, iStatus);
   345             KIMAP4MTMConnect, *iSelection, parameter, iStatus);
   393         iState = EStateConnectAndSync;
       
   394         SetActive();
       
   395         }
   346         }
   396     else if ( Connected() )
   347     else if ( Connected() )
   397         {
   348         {
   398         // in this point cant use "connect and do something" commands,
   349         // in this point cant use "connect and do something" commands,
   399         // use regular sync, when new mails is populated elsewhere.
   350         // use regular sync, when new mails is populated elsewhere.
   400         TBuf8<1> parameter;
   351         TBuf8<1> parameter;
   401         iStatus = KRequestPending;
   352         NM_COMMENT("CIpsPlgImap4ConnectOp: full sync starting");
   402         iOperation = iBaseMtm->InvokeAsyncFunctionL(
   353         iSubOperation = iBaseMtm->InvokeAsyncFunctionL(
   403                 KIMAP4MTMFullSync, *iSelection, parameter, iStatus);
   354             KIMAP4MTMFullSync, *iSelection, parameter, iStatus);
   404         // also set sync started
       
   405         SignalSyncStarted();
       
   406         iState = EStateConnectAndSync;
       
   407         SetActive();
       
   408         }
   355         }
   409     else
   356     else
   410         {
   357         {
   411         TPckg<MMsvImapConnectionObserver*> parameter(this);
   358         // the used command requires an observer to be given even though we're not using it
   412         // connect and synchronise starts background sync or idle
   359         NM_COMMENT("CIpsPlgImap4ConnectOp: connect and sync");
   413         iStatus = KRequestPending;
   360         TPckg<MMsvImapConnectionObserver*> parameter( NULL );
   414         iOperation = iBaseMtm->InvokeAsyncFunctionL(
   361         iSubOperation = iBaseMtm->InvokeAsyncFunctionL(
   415                 KIMAP4MTMConnectAndSyncCompleteAfterFullSync, 
   362             KIMAP4MTMConnectAndSyncCompleteAfterFullSync, 
   416                 *iSelection, parameter, iStatus);
   363             *iSelection, parameter, iStatus );
   417         iState = EStateConnectAndSync;
   364         }
   418         SetActive();
   365     SignalSyncStarted();
   419         }
   366     iState = EStateConnectAndSync;
       
   367     SetActive();
       
   368     // </qmail>
   420 	}
   369 	}
   421 
   370 
   422 // ----------------------------------------------------------------------------
   371 // ----------------------------------------------------------------------------
   423 // CIpsPlgImap4ConnectOp::DoPopulateAll()
   372 // CIpsPlgImap4ConnectOp::DoPopulateAll()
   424 // ---------------------------------------------------------------------------- 
   373 // ---------------------------------------------------------------------------- 
   425 void CIpsPlgImap4ConnectOp::DoPopulateAllL()
   374 void CIpsPlgImap4ConnectOp::DoPopulateAllL()
   426     {
   375     {
   427     FUNC_LOG;
   376     FUNC_LOG;
   428     
   377     
       
   378     NM_COMMENT("CIpsPlgImap4ConnectOp: populate all");
   429     // construct partial fetch info according to imap settings
   379     // construct partial fetch info according to imap settings
       
   380     // <qmail> new function to wrap settings loading
       
   381     CImImap4Settings* settings = GetImapSettingsLC();
       
   382     TImImap4GetPartialMailInfo info;
       
   383     ConstructImapPartialFetchInfo( info, *settings );
       
   384     TPckgBuf<TImImap4GetPartialMailInfo> package(info);
       
   385     CleanupStack::PopAndDestroy( settings );
       
   386     settings = NULL;
       
   387     
       
   388     // do populate operation unless only headers should be fetched
       
   389     if ( info.iTotalSizeLimit != KIpsSetDataHeadersOnly )
       
   390         {
       
   391         // Update iSelection (which will be given to populate op)
       
   392         // <qmail> new function to wrap iSelection populating
       
   393         CreateInboxMessagesSelectionL();
       
   394         
       
   395         iStatus = KRequestPending;
       
   396         iBaseMtm->SwitchCurrentEntryL( iService );
       
   397         // <qmail> priority parameter has been removed
       
   398         iSubOperation = CIpsPlgImap4PopulateOp::NewL(
       
   399             iMsvSession,
       
   400             iStatus,
       
   401             iService,
       
   402             // <qmail> passing in activity timer; only place where NULL "reference" was used
       
   403             // <qmail> -> can get rid of checking existence of a reference memeber...
       
   404             *iActivityTimer,
       
   405             info,
       
   406             *iSelection,
       
   407             iFSMailboxId,
       
   408             NULL, // no observer for suboperation
       
   409             0, // requestId can be 0
       
   410             iEventHandler );
       
   411         
       
   412         SetActive();
       
   413         // <qmail> SignalSyncStarted signal moved to happen later in case something goes wrong
       
   414         SignalSyncStarted();
       
   415         }
       
   416     else
       
   417         {
       
   418         // <qmail> SetActive(); moved inside CompleteThis();
       
   419         CompleteThis();
       
   420         }
       
   421     iState = EStatePopulateAllCompleted;
       
   422     }
       
   423 
       
   424 // <qmail> removed CIpsPlgImap4ConnectOp::StartL()
       
   425 // <qmail> removed CIpsPlgImap4ConnectOp::QueryUserPwdL()
       
   426 // <qmail> removed CIpsPlgImap4ConnectOp::GetOperationErrorCodeL()
       
   427 
       
   428 // ----------------------------------------------------------------------------
       
   429 // ----------------------------------------------------------------------------       
       
   430 void CIpsPlgImap4ConnectOp::SignalSyncStarted()
       
   431     {
       
   432     FUNC_LOG;
       
   433     if ( iEventHandler && !iIsSyncStartedSignaled )
       
   434         {
       
   435         // mark that sync is signaled to prevent 
       
   436         // sending necessary event
       
   437         iIsSyncStartedSignaled = ETrue;
       
   438         iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncStarted, KErrNone );
       
   439         }
       
   440     }
       
   441 
       
   442 // ----------------------------------------------------------------------------
       
   443 // ----------------------------------------------------------------------------       
       
   444 void CIpsPlgImap4ConnectOp::SignalSyncCompleted( TInt aError )
       
   445     {
       
   446     FUNC_LOG;
       
   447     // <qmail> don't test for aError code; all situations should complete op
       
   448     if ( iEventHandler )
       
   449         {
       
   450         iEventHandler->SetNewPropertyEvent( iService, KIpsSosEmailSyncCompleted, aError );
       
   451         iIsSyncStartedSignaled = EFalse;
       
   452         }
       
   453     }
       
   454 
       
   455 // <qmail> Removing CIpsPlgImap4ConnectOp::CredientialsSetL 
       
   456 
       
   457 // <qmail> new functions added
       
   458 // ----------------------------------------------------------------------------
       
   459 // ----------------------------------------------------------------------------
       
   460 void CIpsPlgImap4ConnectOp::ConstructImapPartialFetchInfo( 
       
   461     TImImap4GetPartialMailInfo& aInfo, 
       
   462     const CImImap4Settings& aImap4Settings )
       
   463     {
       
   464     FUNC_LOG;
       
   465     TInt sizeLimit = aImap4Settings.BodyTextSizeLimit();
       
   466     
       
   467     if ( sizeLimit == KIpsSetDataHeadersOnly )
       
   468         {
       
   469         aInfo.iTotalSizeLimit = KIpsSetDataHeadersOnly;
       
   470         }
       
   471     else if ( sizeLimit == KIpsSetDataFullBodyAndAttas )
       
   472         {        
       
   473         aInfo.iTotalSizeLimit = KMaxTInt;
       
   474         aInfo.iAttachmentSizeLimit = KMaxTInt;
       
   475         aInfo.iBodyTextSizeLimit = KMaxTInt;
       
   476         aInfo.iMaxEmailSize = KMaxTInt;
       
   477         aInfo.iPartialMailOptions = ENoSizeLimits;
       
   478         aInfo.iGetMailBodyParts = EGetImap4EmailBodyTextAndAttachments;
       
   479         }
       
   480     else if ( sizeLimit == KIpsSetDataFullBodyOnly )
       
   481         {
       
   482         aInfo.iTotalSizeLimit = KMaxTInt; 
       
   483         aInfo.iAttachmentSizeLimit = 0;
       
   484         aInfo.iBodyTextSizeLimit = KMaxTInt;
       
   485         aInfo.iMaxEmailSize = KMaxTInt;
       
   486         aInfo.iPartialMailOptions = EBodyAlternativeText;
       
   487         aInfo.iGetMailBodyParts = EGetImap4EmailBodyAlternativeText;
       
   488         }
       
   489     else
       
   490         {
       
   491     //<qmail> include html in body
       
   492         aInfo.iTotalSizeLimit = sizeLimit*1024; 
       
   493         aInfo.iAttachmentSizeLimit = 0;
       
   494         aInfo.iMaxEmailSize = sizeLimit*1024;
       
   495         aInfo.iBodyTextSizeLimit = sizeLimit*1024;
       
   496         aInfo.iPartialMailOptions = EBodyAlternativeText;
       
   497         aInfo.iGetMailBodyParts = EGetImap4EmailBodyAlternativeText;
       
   498     // </qmail>    
       
   499         }
       
   500     }
       
   501 
       
   502 // ----------------------------------------------------------------------------
       
   503 // ----------------------------------------------------------------------------
       
   504 CImImap4Settings* CIpsPlgImap4ConnectOp::GetImapSettingsLC()
       
   505     {
       
   506     FUNC_LOG;
   430     CImImap4Settings* settings = new ( ELeave ) CImImap4Settings();
   507     CImImap4Settings* settings = new ( ELeave ) CImImap4Settings();
   431     CleanupStack::PushL( settings );
   508     CleanupStack::PushL( settings );
   432     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   509     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   433     TImapAccount imapAcc;
   510     TImapAccount imapAcc;
   434     accounts->GetImapAccountL(iService, imapAcc );
   511     accounts->GetImapAccountL(iService, imapAcc );
   435     accounts->LoadImapSettingsL( imapAcc, *settings );
   512     accounts->LoadImapSettingsL( imapAcc, *settings );
   436     TImImap4GetPartialMailInfo info;
   513     CleanupStack::PopAndDestroy( accounts );
   437     CIpsSetDataApi::ConstructImapPartialFetchInfo( info, *settings );
   514     return settings;
   438     TPckgBuf<TImImap4GetPartialMailInfo> package(info);
   515     }
   439     CleanupStack::PopAndDestroy( 2, settings );
   516 
   440     
   517 // ----------------------------------------------------------------------------
   441     if ( info.iTotalSizeLimit != KIpsSetDataHeadersOnly )
   518 // ----------------------------------------------------------------------------
   442         {
   519 void CIpsPlgImap4ConnectOp::CreateInboxMessagesSelectionL()
   443         SignalSyncStarted();
   520     {
   444         CMsvEntry* cEntry = iMsvSession.GetEntryL( iService );
   521     FUNC_LOG;
       
   522     // get children of service entry 
       
   523     CMsvEntry* cEntry = iMsvSession.GetEntryL( iService );
       
   524     CleanupStack::PushL( cEntry );
       
   525     CMsvEntrySelection* childrenSelection = cEntry->ChildrenL();
       
   526     CleanupStack::PopAndDestroy( cEntry );
       
   527     cEntry = NULL;
       
   528     CleanupStack::PushL( childrenSelection );
       
   529 
       
   530     if ( childrenSelection->Count() )
       
   531         {
       
   532         TMsvId id = (*childrenSelection)[0]; // index 0 == inbox
       
   533         cEntry = iMsvSession.GetEntryL( id ); // reusing cEntry pointer for Inbox entry
   445         CleanupStack::PushL( cEntry );
   534         CleanupStack::PushL( cEntry );
   446         CMsvEntrySelection* childrenSelection = cEntry->ChildrenL();
   535         delete iSelection;
   447         CleanupStack::PushL( childrenSelection );
   536         iSelection = NULL;
   448         if ( childrenSelection->Count() )
   537         // get message-type children of inbox
   449             {
   538         iSelection = cEntry->ChildrenWithTypeL( KUidMsvMessageEntry );
   450             // only inbox is set, do we have to populate other folders also
       
   451             TMsvId id = (*childrenSelection)[0];
       
   452             CMsvEntry* cEntry2 = iMsvSession.GetEntryL( id );
       
   453             CleanupStack::PushL( cEntry2 );
       
   454             delete iSelection;
       
   455             iSelection = NULL;
       
   456             iSelection = cEntry2->ChildrenWithTypeL( KUidMsvMessageEntry );
       
   457             CleanupStack::PopAndDestroy( cEntry2 );
       
   458             
       
   459             }
       
   460         CleanupStack::PopAndDestroy( childrenSelection );
       
   461     
       
   462         iStatus = KRequestPending;
       
   463         CIpsPlgTimerOperation* dummy = NULL;
       
   464         iBaseMtm->SwitchCurrentEntryL( iService );
       
   465         iOperation = CIpsPlgImap4PopulateOp::NewL(
       
   466                 iMsvSession,
       
   467                 this->iStatus,
       
   468                 CActive::EPriorityLow,
       
   469                 iService,
       
   470                 *dummy,
       
   471                 info,
       
   472                 *iSelection,
       
   473                 iFSMailboxId,
       
   474                 *this,
       
   475                 0,
       
   476                 iEventHandler );
       
   477         
       
   478         SetActive();
       
   479         CleanupStack::PopAndDestroy( cEntry );
   539         CleanupStack::PopAndDestroy( cEntry );
   480         }
   540         }
   481     else
   541     CleanupStack::PopAndDestroy( childrenSelection );
   482         {
   542     }
   483         SetActive();
   543 
   484         CompleteThis();
   544 // </qmail>
   485         }
       
   486     iState = EStatePopulateAllCompleted;
       
   487     }
       
   488 
       
   489 // ----------------------------------------------------------------------------
       
   490 // CIpsPlgImap4ConnectOp::StartL()
       
   491 // ----------------------------------------------------------------------------    
       
   492 // 
       
   493 void CIpsPlgImap4ConnectOp::StartL()
       
   494     {
       
   495     FUNC_LOG;
       
   496     if ( Connected() && iDoPlainConnect )
       
   497         {
       
   498         // sync is done background, no explicit supported
       
   499         iState = EStateIdle;
       
   500         SetActive();
       
   501         CompleteThis();
       
   502         }
       
   503     else 
       
   504         {
       
   505         DoConnectOpL();
       
   506         }
       
   507     }    
       
   508 
       
   509 // ----------------------------------------------------------------------------
       
   510 // CIpsPlgImap4ConnectOp::QueryUserPwdL()
       
   511 // ----------------------------------------------------------------------------
       
   512 // 
       
   513 TBool CIpsPlgImap4ConnectOp::QueryUserPassL()
       
   514     {
       
   515     if ( iEventHandler )
       
   516         {
       
   517         // ask for credentials for imap account and wait for callback
       
   518         if ( iEventHandler->QueryUsrPassL( iService, this ) )
       
   519             {
       
   520             iState = EStateQueryingDetails;
       
   521             }
       
   522         else
       
   523             {
       
   524             // another operation is waiting for password
       
   525             iState = EStateQueryingDetailsBusy;
       
   526             }
       
   527 
       
   528         return ETrue;
       
   529         }
       
   530 
       
   531     return EFalse;
       
   532     }
       
   533 
       
   534     
       
   535 // ----------------------------------------------------------------------------
       
   536 // CIpsPlgImap4ConnectOp::GetOperationErrorCodeL()
       
   537 // ----------------------------------------------------------------------------    
       
   538 //     
       
   539 /*TInt CIpsPlgImap4ConnectOp::GetOperationErrorCodeL( )
       
   540     {
       
   541     if ( iAlreadyConnected )
       
   542         {
       
   543         // Connected state was set in CIpsPlgPop3ConnectOp::ConstructL()
       
   544         // so iOperation is null
       
   545         return KErrNone;
       
   546         }
       
   547         
       
   548     if ( !iOperation )
       
   549         {
       
   550         return KErrNotFound;
       
   551         }
       
   552     if ( !iOperation->IsActive() && iOperation->iStatus.Int() != KErrNone )
       
   553         {
       
   554         return iOperation->iStatus.Int();
       
   555         }
       
   556      
       
   557     TPckgBuf<TImap4CompoundProgress> paramPack;
       
   558     paramPack.Copy( iOperation->ProgressL() );
       
   559     const TImap4CompoundProgress& comProgg = paramPack();
       
   560 
       
   561     return comProgg.iGenericProgress.iErrorCode;
       
   562     }*/
       
   563 
       
   564 // ----------------------------------------------------------------------------
       
   565 // ----------------------------------------------------------------------------       
       
   566 void CIpsPlgImap4ConnectOp::SignalSyncStarted()
       
   567     {
       
   568     FUNC_LOG;
       
   569     if ( iEventHandler && !iIsSyncStartedSignaled )
       
   570         {
       
   571         // mark that sync is signaled to prevent 
       
   572         // sending necessary event
       
   573         iIsSyncStartedSignaled = ETrue;
       
   574         iEventHandler->SetNewPropertyEvent( 
       
   575                 iService, KIpsSosEmailSyncStarted, KErrNone );
       
   576         }
       
   577     }
       
   578 
       
   579 // ----------------------------------------------------------------------------
       
   580 // ----------------------------------------------------------------------------       
       
   581 void CIpsPlgImap4ConnectOp::SignalSyncCompleted( TInt aError )
       
   582     {
       
   583     FUNC_LOG;
       
   584     if ( iEventHandler && aError == KErrImapBadLogon )
       
   585         {
       
   586         /*
       
   587         iEventHandler->SetNewPropertyEvent( 
       
   588                 iService, KIpsSosEmailSyncCompleted, aError );
       
   589         */
       
   590         iIsSyncStartedSignaled = EFalse;
       
   591         }
       
   592     }
       
   593 
       
   594 
       
   595 // ----------------------------------------------------------------------------
       
   596 // ----------------------------------------------------------------------------
       
   597 void CIpsPlgImap4ConnectOp::CredientialsSetL( TInt aEvent )
       
   598     {
       
   599     FUNC_LOG;
       
   600 
       
   601     if ( iState == EStateQueryingDetails )
       
   602         {
       
   603         // response for our operation`s query
       
   604         if ( aEvent == EIPSSosCredientialsCancelled )
       
   605             {
       
   606             // user canceled operation
       
   607             CompleteObserver( KErrCancel );
       
   608             }
       
   609 
       
   610         // password has been set, continue with operation
       
   611         SetActive();
       
   612         CompleteThis();
       
   613         }
       
   614     else if ( iState == EStateQueryingDetailsBusy )
       
   615         {
       
   616         // response for other operation`s query
       
   617         // we could try to ask for password now,
       
   618         // but decision was made to cancel operation
       
   619         CompleteObserver( KErrCancel );
       
   620         SetActive();
       
   621         CompleteThis();
       
   622         }
       
   623     }
       
   624 // End of File
       
   625