ipsservices/ipssosplugin/src/ipsplgimap4connectop.cpp
branchRCL_3
changeset 64 3533d4323edc
parent 63 d189ee25cf9d
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
    14 * Description:  IMAP4 connect operation
    14 * Description:  IMAP4 connect operation
    15 *
    15 *
    16 *
    16 *
    17 */
    17 */
    18 
    18 
       
    19 
    19 #include "emailtrace.h"
    20 #include "emailtrace.h"
    20 #include "ipsplgheaders.h"
    21 #include "ipsplgheaders.h"
    21 
    22 
    22 // <qmail> removed
    23 
    23 
    24 _LIT( KIpsPlgIpsConnPanic, "IpsConn" ); 
    24 // <qmail> KIpsPlgIpsConnPanic removed
       
    25 
    25 
    26 // ----------------------------------------------------------------------------
    26 // ----------------------------------------------------------------------------
    27 // CIpsPlgImap4ConnectOp::NewL()
    27 // CIpsPlgImap4ConnectOp::NewL()
    28 // ----------------------------------------------------------------------------
    28 // ----------------------------------------------------------------------------
    29 // <qmail> priority parameter has been removed
    29 // 
    30 // <qmail> MFSMailRequestObserver& changed it to pointer
       
    31 // <qmail> aSignallingAllowed parameter has been removed
       
    32 CIpsPlgImap4ConnectOp* CIpsPlgImap4ConnectOp::NewL(
    30 CIpsPlgImap4ConnectOp* CIpsPlgImap4ConnectOp::NewL(
    33     CMsvSession& aMsvSession,
    31     CMsvSession& aMsvSession,
       
    32 	TInt aPriority,
    34     TRequestStatus& aObserverRequestStatus,
    33     TRequestStatus& aObserverRequestStatus,
    35     TMsvId aService,
    34     TMsvId aService,
    36     CIpsPlgTimerOperation& aActivityTimer,
    35     CIpsPlgTimerOperation& aActivityTimer,
    37     TFSMailMsgId aFSMailBoxId,
    36     TFSMailMsgId aFSMailBoxId,
    38     MFSMailRequestObserver* aFSOperationObserver,
    37     MFSMailRequestObserver& aFSOperationObserver,
    39     TInt aFSRequestId,
    38     TInt aFSRequestId,
    40     CIpsPlgEventHandler* aEventHandler,
    39     CIpsPlgEventHandler* aEventHandler,
    41     TBool aDoPlainConnect )
    40     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, 
    46         aObserverRequestStatus,
    47         aObserverRequestStatus,
    47         aService, 
    48         aService, 
    48         aActivityTimer,
    49         aActivityTimer,
    49         aFSMailBoxId, 
    50         aFSMailBoxId, 
    50         aFSOperationObserver,
    51         aFSOperationObserver,
    51         aFSRequestId,
    52         aFSRequestId,
    52         aDoPlainConnect,
    53         aDoPlainConnect,
       
    54         aSignallingAllowed,
    53         aEventHandler );
    55         aEventHandler );
    54         
    56         
    55     CleanupStack::PushL( self );
    57     CleanupStack::PushL( self );
    56     self->ConstructL();
    58     self->ConstructL();
    57     CleanupStack::Pop( self );
    59     CleanupStack::Pop( self );
    59     }
    61     }
    60 
    62 
    61 // ----------------------------------------------------------------------------
    63 // ----------------------------------------------------------------------------
    62 // CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp()
    64 // CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp()
    63 // ----------------------------------------------------------------------------
    65 // ----------------------------------------------------------------------------
    64 // <qmail> priority parameter has been removed
    66 // 
    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,
    69     TRequestStatus& aObserverRequestStatus,
    70     TRequestStatus& aObserverRequestStatus,
    70     TMsvId aService,
    71     TMsvId aService,
    71     CIpsPlgTimerOperation& aActivityTimer,
    72     CIpsPlgTimerOperation& aActivityTimer,
    72     TFSMailMsgId aFSMailBoxId,
    73     TFSMailMsgId aFSMailBoxId,
    73     MFSMailRequestObserver* aFSOperationObserver,
    74     MFSMailRequestObserver& aFSOperationObserver,
    74     TInt aFSRequestId,
    75     TInt aFSRequestId,
    75     TBool aDoPlainConnect,
    76     TBool aDoPlainConnect,
       
    77     TBool aSignallingAllowed,
    76     CIpsPlgEventHandler* aEventHandler)
    78     CIpsPlgEventHandler* aEventHandler)
    77     :
    79     :
    78     CIpsPlgOnlineOperation(
    80     CIpsPlgOnlineOperation(
    79 	    aMsvSession,
    81 	    aMsvSession,
       
    82 	    aPriority,
    80 	    aObserverRequestStatus,
    83 	    aObserverRequestStatus,
    81 	    aActivityTimer,
    84 	    aActivityTimer,
    82 	    aFSMailBoxId,
    85 	    aFSMailBoxId,
    83 	    aFSOperationObserver,
    86 	    aFSOperationObserver,
    84 	    aFSRequestId ),
    87 	    aFSRequestId,
    85     iState( EStateIdle ),
    88     	aSignallingAllowed ),
    86     iSelection( NULL ),
       
    87     iDoPlainConnect( aDoPlainConnect ),
    89     iDoPlainConnect( aDoPlainConnect ),
    88     iEventHandler( aEventHandler ),
    90     iEventHandler( aEventHandler ),
    89     iIsSyncStartedSignaled( EFalse )
    91     iIsSyncStartedSignaled( EFalse ),
       
    92     iAlreadyConnected( EFalse )
    90     {
    93     {
    91     FUNC_LOG;
    94     FUNC_LOG;
    92     iService = aService;
    95     iService = aService;
    93     }
    96     }
    94 
    97 
    99 CIpsPlgImap4ConnectOp::~CIpsPlgImap4ConnectOp()
   102 CIpsPlgImap4ConnectOp::~CIpsPlgImap4ConnectOp()
   100     {
   103     {
   101     FUNC_LOG;
   104     FUNC_LOG;
   102     Cancel();
   105     Cancel();
   103     delete iSelection;
   106     delete iSelection;
   104     // <qmail> setting state in destructor makes no sense
   107     iState = EStateIdle;
   105     }
   108     }
   106 
   109 
   107 // ----------------------------------------------------------------------------
   110 // ----------------------------------------------------------------------------
   108 // CIpsPlgImap4ConnectOp::ConstructL()
   111 // CIpsPlgImap4ConnectOp::ConstructL()
   109 // ----------------------------------------------------------------------------
   112 // ----------------------------------------------------------------------------
   121     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
   124     if ( tentry.iType.iUid != KUidMsvServiceEntryValue )
   122         {
   125         {
   123         User::Panic( KIpsPlgIpsConnPanic, KErrNotSupported );
   126         User::Panic( KIpsPlgIpsConnPanic, KErrNotSupported );
   124         }
   127         }
   125     
   128     
   126     // <qmail> moved here from StartL which was removed
   129     if ( tentry.Connected() )
   127     if ( Connected() && iDoPlainConnect )
   130         {      
   128         {
   131         iState = EStateCompleted; 
   129         // trivial case: connect requested, but already connected
   132         iAlreadyConnected = ETrue;
   130         // (sync is done automatically on background)
   133         SetActive();
   131         iState = EStateIdle;
   134         CompleteThis();
   132         }
   135         }
   133     else
   136     else
   134         {
   137         {
   135         iState = EStateStartConnect;
   138         iState = EStateStartConnect;
   136         }
   139         iStatus = KRequestPending;    
   137     iStatus = KRequestPending;    
   140         SetActive();
   138     // <qmail> SetActive(); moved inside CompleteThis();
   141        CompleteThis();
   139     CompleteThis();
   142         }    
   140     }
   143     }
   141 
   144 
   142 // ----------------------------------------------------------------------------
   145 // ----------------------------------------------------------------------------
   143 // CIpsPlgImap4ConnectOp::ProgressL()
   146 // CIpsPlgImap4ConnectOp::ProgressL()
   144 // ----------------------------------------------------------------------------
   147 // ----------------------------------------------------------------------------
   148     FUNC_LOG;
   151     FUNC_LOG;
   149     if( iError != KErrNone )
   152     if( iError != KErrNone )
   150         {
   153         {
   151         return GetErrorProgressL( iError );
   154         return GetErrorProgressL( iError );
   152         }
   155         }
   153     else if( iSubOperation )
   156     else if(iOperation)
   154         {
   157         {
   155         return iSubOperation->ProgressL();
   158         return iOperation->ProgressL();
   156         }
   159         }
   157         
   160         
   158     TImap4CompoundProgress& prog = iProgressBuf();
   161     TImap4CompoundProgress& prog = iProgressBuf();
   159     prog.iGenericProgress.iErrorCode = KErrNone;
   162     prog.iGenericProgress.iErrorCode = KErrNone;
   160     return iProgressBuf;
   163     return iProgressBuf;
   182     // might not never called, but gives something reasonable if called
   185     // might not never called, but gives something reasonable if called
   183     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   186     TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
   184     result.iError = KErrNone;
   187     result.iError = KErrNone;
   185     switch( iState )
   188     switch( iState )
   186         {
   189         {
   187         // <qmail> cases EStateQueryingDetails/EStateQueryingDetailsBusy removed
   190         case EStateQueryingDetails:
       
   191         case EStateQueryingDetailsBusy:
       
   192             result.iProgressStatus = TFSProgress::EFSStatus_Authenticating;
       
   193             break;
   188         case EStateStartConnect:
   194         case EStateStartConnect:
   189             result.iProgressStatus = TFSProgress::EFSStatus_Started;
   195             result.iProgressStatus = TFSProgress::EFSStatus_Started;
   190             break;
   196             break;
   191         case EStateConnectAndSync:
   197         case EStateConnectAndSync:
   192             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   198             result.iProgressStatus = TFSProgress::EFSStatus_Connecting;
   205     }
   211     }
   206 
   212 
   207 // ----------------------------------------------------------------------------
   213 // ----------------------------------------------------------------------------
   208 // CIpsPlgImap4ConnectOp::IpsOpType()
   214 // CIpsPlgImap4ConnectOp::IpsOpType()
   209 // ----------------------------------------------------------------------------
   215 // ----------------------------------------------------------------------------
   210 // <qmail> return type
   216 // 
   211 TIpsOpType CIpsPlgImap4ConnectOp::IpsOpType() const
   217 TInt CIpsPlgImap4ConnectOp::IpsOpType() const
   212     {
   218     {
   213     FUNC_LOG;
   219     FUNC_LOG;
   214     return EIpsOpTypeImap4SyncOp;
   220     return EIpsOpTypeImap4SyncOp;
   215     }
   221     }
   216 
   222 
   217 // <qmail> Connected() moved to baseclass
   223 // ----------------------------------------------------------------------------
       
   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 
   218 // ----------------------------------------------------------------------------
   237 // ----------------------------------------------------------------------------
   219 // CIpsPlgImap4ConnectOp::DoCancel()
   238 // CIpsPlgImap4ConnectOp::DoCancel()
   220 // ----------------------------------------------------------------------------
   239 // ----------------------------------------------------------------------------
   221 // 
   240 // 
   222 void CIpsPlgImap4ConnectOp::DoCancel()
   241 void CIpsPlgImap4ConnectOp::DoCancel()
   223     {
   242     {
   224     FUNC_LOG;
   243     FUNC_LOG;
   225     if( iSubOperation )
   244     if( iOperation )
   226         {
   245         {
   227         iSubOperation->Cancel();
   246         iOperation->Cancel();
   228         }
   247         }
   229     SignalSyncCompleted( KErrCancel );
   248     SignalSyncCompleted( KErrCancel );
   230     CompleteObserver( KErrCancel );
   249     CompleteObserver( KErrCancel );
   231     }
   250     }
   232 
   251 
   235 // ----------------------------------------------------------------------------    
   254 // ----------------------------------------------------------------------------    
   236 //  
   255 //  
   237 void CIpsPlgImap4ConnectOp::DoRunL()
   256 void CIpsPlgImap4ConnectOp::DoRunL()
   238     {
   257     {
   239     FUNC_LOG;
   258     FUNC_LOG;
   240     TInt err( KErrNone );
   259     TInt err = KErrNone;
   241     __ASSERT_DEBUG( !(iSubOperation && iSubOperation->IsActive()),
   260     __ASSERT_DEBUG( !(iOperation && iOperation->IsActive()), 
   242         User::Panic( KIpsPlgPanicCategory, KErrGeneral ) );
   261             User::Panic( KIpsPlgPanicCategory, KErrGeneral ) );
   243     if ( iSubOperation )
   262     if ( iOperation )
   244         {
   263         {
   245         err = iSubOperation->iStatus.Int();
   264         err = iOperation->iStatus.Int();
   246         delete iSubOperation;
   265         delete iOperation;
   247         iSubOperation = NULL;
   266         iOperation = NULL;
   248         }
   267         }
   249     
   268     
   250     switch( iState )
   269     switch( iState )
   251         {
   270         {
   252         // <qmail> removing case EStateQueryingDetails
   271         case EStateQueryingDetails:
       
   272             // querying pass finished - try to reconnect
       
   273             DoConnectOpL();
       
   274             break;
   253         case EStateStartConnect:
   275         case EStateStartConnect:
   254             // <qmail> remove StartL() func and replace it directly with DoConnectOpL
   276         	StartL();
   255             DoConnectOpL();
   277         	break;
   256             break;
       
   257         case EStateConnectAndSync:
   278         case EStateConnectAndSync:
   258             // Connection completed
   279             // Connection completed
   259                 
   280 
   260             // <qmail> all errors should fail the op
   281             if ( err == KErrImapBadLogon )
   261             if( err )
       
   262                 {
   282                 {
   263                 iState = EStateIdle;
   283                 // Login details are wrong. Trying to ask for password
   264                 // <qmail> SetActive(); moved inside CompleteThis();
   284                 if ( QueryUserPassL() )
   265                 CompleteThis();
   285                     {
       
   286                     err = KErrNone;
       
   287                     }
   266                 }
   288                 }
   267             else
   289             else if ( err == KErrNone )
   268                 {
   290                 {
   269                 // no errors in connection
   291                 // no errors in connection
   270                 if( !iDoPlainConnect )
   292                 if( !iDoPlainConnect )
   271                     {
   293                     {
   272                     DoPopulateAllL();
   294                     DoPopulateAllL();
   273                     }
   295                     }
   274                 else
   296                 else
   275                     {
   297                     {
   276                     // Get on with others using this class for connection only
   298                     // Get on with others using this class for connection only
   277                     iState = EStateIdle;
   299                     iState = EStateIdle;
   278                     // <qmail> SetActive(); moved inside CompleteThis();
   300                     SetActive();
   279                     CompleteThis();
   301                     CompleteThis();
   280                     }
   302                     }
   281                 }
   303                 }
   282             break;
   304             break;
   283         case EStatePopulateAllCompleted:
   305         case EStatePopulateAllCompleted:
   284             CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( iMsvSession, iService );
   306             CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL(
       
   307                     iMsvSession, iService );
   285             // break command is intentially left out
   308             // break command is intentially left out
   286         case EStateCompleted:
   309         case EStateCompleted:
   287             if ( err == KErrNone )
   310             if ( err == KErrNone )
   288                 {
   311                 {
   289                 iState = EStateIdle;
   312                 iState = EStateIdle;
   290                 // <qmail> SetActive(); moved inside CompleteThis();
   313                 SetActive();
   291                 CompleteThis();
   314                 CompleteThis();
   292                 }
   315                 }
   293             break;
   316             break;
   294         case EStateIdle:
   317         case EStateIdle:
   295         default:
   318         default:
   296             if ( iSubOperation )
   319             if ( iOperation )
   297                 {
   320                 {
   298                 delete iSubOperation;
   321                 delete iOperation;
   299                 iSubOperation = NULL;
   322                 iOperation = NULL;
   300                 }
   323                 }
   301             CompleteObserver();
   324             CompleteObserver();
   302             break;
   325             break;
   303         }
   326         }
   304    
   327    
   308         {
   331         {
   309         SignalSyncCompleted( err );
   332         SignalSyncCompleted( err );
   310         }
   333         }
   311     }
   334     }
   312 
   335 
   313 // <qmail> CIpsPlgImap4ConnectOp::HandleImapConnectionEvent() removed
   336 // ----------------------------------------------------------------------------
       
   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     }
   314 
   363 
   315 // ----------------------------------------------------------------------------
   364 // ----------------------------------------------------------------------------
   316 // CIpsPlgImap4ConnectOp::RequestResponseL()
   365 // CIpsPlgImap4ConnectOp::RequestResponseL()
   317 // ----------------------------------------------------------------------------    
   366 // ----------------------------------------------------------------------------    
   318 //   
   367 //   
   332     iBaseMtm->SwitchCurrentEntryL( iService );
   381     iBaseMtm->SwitchCurrentEntryL( iService );
   333 
   382 
   334     iSelection->ResizeL(0);
   383     iSelection->ResizeL(0);
   335     iSelection->AppendL(iService);
   384     iSelection->AppendL(iService);
   336     
   385     
   337     // <qmail>
       
   338     iStatus = KRequestPending;
       
   339     if ( iDoPlainConnect && !Connected() )
   386     if ( iDoPlainConnect && !Connected() )
   340         {
   387         {
   341         TBuf8<1> parameter;
   388         TBuf8<1> parameter;
   342         NM_COMMENT("CIpsPlgImap4ConnectOp: do plain connect");
   389         iStatus = KRequestPending;
   343         // connect and synchronise starts background sync or idle
   390         // connect and synchronise starts background sync or idle
   344         iSubOperation = iBaseMtm->InvokeAsyncFunctionL(
   391         iOperation = iBaseMtm->InvokeAsyncFunctionL(
   345             KIMAP4MTMConnect, *iSelection, parameter, iStatus);
   392                 KIMAP4MTMConnect, *iSelection, parameter, iStatus);
       
   393         iState = EStateConnectAndSync;
       
   394         SetActive();
   346         }
   395         }
   347     else if ( Connected() )
   396     else if ( Connected() )
   348         {
   397         {
   349         // in this point cant use "connect and do something" commands,
   398         // in this point cant use "connect and do something" commands,
   350         // use regular sync, when new mails is populated elsewhere.
   399         // use regular sync, when new mails is populated elsewhere.
   351         TBuf8<1> parameter;
   400         TBuf8<1> parameter;
   352         NM_COMMENT("CIpsPlgImap4ConnectOp: full sync starting");
   401         iStatus = KRequestPending;
   353         iSubOperation = iBaseMtm->InvokeAsyncFunctionL(
   402         iOperation = iBaseMtm->InvokeAsyncFunctionL(
   354             KIMAP4MTMFullSync, *iSelection, parameter, iStatus);
   403                 KIMAP4MTMFullSync, *iSelection, parameter, iStatus);
       
   404         // also set sync started
       
   405         SignalSyncStarted();
       
   406         iState = EStateConnectAndSync;
       
   407         SetActive();
   355         }
   408         }
   356     else
   409     else
   357         {
   410         {
   358         // the used command requires an observer to be given even though we're not using it
   411         TPckg<MMsvImapConnectionObserver*> parameter(this);
   359         NM_COMMENT("CIpsPlgImap4ConnectOp: connect and sync");
   412         // connect and synchronise starts background sync or idle
   360         TPckg<MMsvImapConnectionObserver*> parameter( NULL );
   413         iStatus = KRequestPending;
   361         iSubOperation = iBaseMtm->InvokeAsyncFunctionL(
   414         iOperation = iBaseMtm->InvokeAsyncFunctionL(
   362             KIMAP4MTMConnectAndSyncCompleteAfterFullSync, 
   415                 KIMAP4MTMConnectAndSyncCompleteAfterFullSync, 
   363             *iSelection, parameter, iStatus );
   416                 *iSelection, parameter, iStatus);
   364         }
   417         iState = EStateConnectAndSync;
   365     SignalSyncStarted();
   418         SetActive();
   366     iState = EStateConnectAndSync;
   419         }
   367     SetActive();
       
   368     // </qmail>
       
   369 	}
   420 	}
   370 
   421 
   371 // ----------------------------------------------------------------------------
   422 // ----------------------------------------------------------------------------
   372 // CIpsPlgImap4ConnectOp::DoPopulateAll()
   423 // CIpsPlgImap4ConnectOp::DoPopulateAll()
   373 // ---------------------------------------------------------------------------- 
   424 // ---------------------------------------------------------------------------- 
   374 void CIpsPlgImap4ConnectOp::DoPopulateAllL()
   425 void CIpsPlgImap4ConnectOp::DoPopulateAllL()
   375     {
   426     {
   376     FUNC_LOG;
   427     FUNC_LOG;
   377     
   428     
   378     NM_COMMENT("CIpsPlgImap4ConnectOp: populate all");
       
   379     // construct partial fetch info according to imap settings
   429     // 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;
       
   507     CImImap4Settings* settings = new ( ELeave ) CImImap4Settings();
   430     CImImap4Settings* settings = new ( ELeave ) CImImap4Settings();
   508     CleanupStack::PushL( settings );
   431     CleanupStack::PushL( settings );
   509     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   432     CEmailAccounts* accounts = CEmailAccounts::NewLC();
   510     TImapAccount imapAcc;
   433     TImapAccount imapAcc;
   511     accounts->GetImapAccountL(iService, imapAcc );
   434     accounts->GetImapAccountL(iService, imapAcc );
   512     accounts->LoadImapSettingsL( imapAcc, *settings );
   435     accounts->LoadImapSettingsL( imapAcc, *settings );
   513     CleanupStack::PopAndDestroy( accounts );
   436     TImImap4GetPartialMailInfo info;
   514     return settings;
   437     CIpsSetDataApi::ConstructImapPartialFetchInfo( info, *settings );
   515     }
   438     TPckgBuf<TImImap4GetPartialMailInfo> package(info);
   516 
   439     CleanupStack::PopAndDestroy( 2, settings );
   517 // ----------------------------------------------------------------------------
   440     
   518 // ----------------------------------------------------------------------------
   441     if ( info.iTotalSizeLimit != KIpsSetDataHeadersOnly )
   519 void CIpsPlgImap4ConnectOp::CreateInboxMessagesSelectionL()
   442         {
   520     {
   443         SignalSyncStarted();
   521     FUNC_LOG;
   444         CMsvEntry* cEntry = iMsvSession.GetEntryL( iService );
   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
       
   534         CleanupStack::PushL( cEntry );
   445         CleanupStack::PushL( cEntry );
   535         delete iSelection;
   446         CMsvEntrySelection* childrenSelection = cEntry->ChildrenL();
   536         iSelection = NULL;
   447         CleanupStack::PushL( childrenSelection );
   537         // get message-type children of inbox
   448         if ( childrenSelection->Count() )
   538         iSelection = cEntry->ChildrenWithTypeL( KUidMsvMessageEntry );
   449             {
       
   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();
   539         CleanupStack::PopAndDestroy( cEntry );
   479         CleanupStack::PopAndDestroy( cEntry );
   540         }
   480         }
   541     CleanupStack::PopAndDestroy( childrenSelection );
   481     else
   542     }
   482         {
   543 
   483         SetActive();
   544 // </qmail>
   484         CompleteThis();
       
   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