email/imum/Mtms/Src/Imap4FetchOp.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *       Populate a selection of incomplete remote messages
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <eikenv.h>
       
    22 #include <eikrutil.h>
       
    23 #include <imapcmds.h>
       
    24 #include <imapset.h>
       
    25 
       
    26 #include "Imap4FetchOp.h"
       
    27 #include "EmailMsgSizerOperation.h"
       
    28 #include "EmailUtils.H"
       
    29 #include "ImumDisconnectOperation.h"
       
    30 #include "IMAPPRGR.H"
       
    31 #include "ImumMtmLogging.h"
       
    32 #include "ImumPanic.h"
       
    33 #include "ImapPopulateOperation.h"
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CImap4FetchOp::NewL()
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 CImap4FetchOp* CImap4FetchOp::NewL(
       
    42     CImumInternalApi& aMailboxApi,
       
    43     TRequestStatus& aObserverRequestStatus,
       
    44     MMsvProgressReporter& aReporter,
       
    45     TMsvId aService,
       
    46     TInt aFunctionId,
       
    47     const TImImap4GetMailInfo& aGetMailInfo,
       
    48     const CMsvEntrySelection& aSel )
       
    49     {
       
    50     IMUM_STATIC_CONTEXT( CImap4FetchOp::NewL, 0, mtm, KImumMtmLog );
       
    51     IMUM_IN();
       
    52     
       
    53     __ASSERT_DEBUG(aSel.Count(),
       
    54         User::Panic(KImumMtmUiPanic,EPanicSelectionEmpty));
       
    55     if ( aSel.Count() == 0 )
       
    56         {
       
    57         User::Leave( KErrNotSupported );
       
    58         }
       
    59     CImap4FetchOp* op = new(ELeave) CImap4FetchOp(
       
    60         aMailboxApi, aObserverRequestStatus, aReporter,
       
    61         aService, aFunctionId, aGetMailInfo);
       
    62     CleanupStack::PushL(op);
       
    63     op->ConstructL(aSel);
       
    64     CleanupStack::Pop();
       
    65     IMUM_OUT();
       
    66     return op;
       
    67     }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CImap4FetchOp::NewL()
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 CImap4FetchOp* CImap4FetchOp::NewL(
       
    74     CImumInternalApi& aMailboxApi,
       
    75     TRequestStatus& aObserverRequestStatus,
       
    76     MMsvProgressReporter& aReporter,
       
    77     TMsvId aService,
       
    78     TInt aFunctionId,
       
    79     const TImImap4GetPartialMailInfo& aPartialGetMailInfo,
       
    80     const CMsvEntrySelection& aSel )
       
    81     {
       
    82     IMUM_STATIC_CONTEXT( CImap4FetchOp::NewL, 0, mtm, KImumMtmLog );
       
    83     IMUM_IN();
       
    84     
       
    85     __ASSERT_DEBUG(aSel.Count(),
       
    86         User::Panic(KImumMtmUiPanic,EPanicSelectionEmpty));
       
    87     if ( aSel.Count() == 0 )
       
    88         {
       
    89         User::Leave( KErrNotSupported );
       
    90         }
       
    91     CImap4FetchOp* op = new(ELeave) CImap4FetchOp(
       
    92         aMailboxApi, aObserverRequestStatus, aReporter,
       
    93         aService, aFunctionId, aPartialGetMailInfo );
       
    94     CleanupStack::PushL(op);
       
    95     op->ConstructL(aSel);
       
    96     CleanupStack::Pop();
       
    97     IMUM_OUT();
       
    98     return op;
       
    99     }
       
   100 
       
   101 // ----------------------------------------------------------------------------
       
   102 // CImap4FetchOp::~CImap4FetchOp()()
       
   103 // ----------------------------------------------------------------------------
       
   104 //
       
   105 CImap4FetchOp::~CImap4FetchOp()
       
   106     {
       
   107     IMUM_CONTEXT( CImap4FetchOp::~CImap4FetchOp, 0, KImumMtmLog );
       
   108     IMUM_IN();
       
   109     
       
   110     delete iSelection;
       
   111     IMUM_OUT();
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CImap4FetchOp::CImap4FetchOp()
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 CImap4FetchOp::CImap4FetchOp(
       
   119     CImumInternalApi& aMailboxApi,
       
   120     TRequestStatus& aStatus,
       
   121     MMsvProgressReporter& aReporter,
       
   122     TMsvId aServiceId,
       
   123     TInt aFunctionId,
       
   124     const TImImap4GetMailInfo& aGetMailInfo )
       
   125     :
       
   126     CImap4ConnectedOp(aMailboxApi, aStatus, aReporter, aServiceId),
       
   127     iFunctionId(aFunctionId),
       
   128     iGetMailInfo( aGetMailInfo ),
       
   129     iPopulate( EFalse )
       
   130     {
       
   131     IMUM_CONTEXT( CImap4FetchOp::CImap4FetchOp, 0, KImumMtmLog );
       
   132     IMUM_IN();
       
   133     IMUM_OUT();
       
   134     
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // CImap4FetchOp::CImap4FetchOp()
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 CImap4FetchOp::CImap4FetchOp(
       
   142     CImumInternalApi& aMailboxApi,
       
   143     TRequestStatus& aStatus,
       
   144     MMsvProgressReporter& aReporter,
       
   145     TMsvId aServiceId,
       
   146     TInt aFunctionId,
       
   147     const TImImap4GetPartialMailInfo& aPartialGetMailInfo )
       
   148     :
       
   149     CImap4ConnectedOp( aMailboxApi, aStatus, aReporter, aServiceId ),
       
   150     iFunctionId(aFunctionId),
       
   151     iGetMailInfo( aPartialGetMailInfo ),
       
   152     iPartialGetMailInfo( aPartialGetMailInfo ),
       
   153     iPopulate( ETrue )
       
   154     {
       
   155     IMUM_CONTEXT( CImap4FetchOp::CImap4FetchOp, 0, KImumMtmLog );
       
   156     IMUM_IN();
       
   157     IMUM_OUT();
       
   158     
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // CImap4FetchOp::ConstructL()
       
   163 // ----------------------------------------------------------------------------
       
   164 //
       
   165 void CImap4FetchOp::ConstructL( const CMsvEntrySelection& aSel )
       
   166     {
       
   167     IMUM_CONTEXT( CImap4FetchOp::ConstructL, 0, KImumMtmLog );
       
   168     IMUM_IN();
       
   169     
       
   170     iSelection = aSel.CopyL();
       
   171     iSelection->InsertL(0, iService);
       
   172     // For Get Mail API, first selection element must be service.
       
   173     CImap4ConnectedOp::ConstructL( iFunctionId );
       
   174     if ( iFunctionId != KIMAP4MTMCopyMailSelectionWhenAlreadyConnected &&
       
   175          iFunctionId != KIMAP4MTMMoveMailSelectionWhenAlreadyConnected )
       
   176         {
       
   177         iDisconnect = EFalse;
       
   178         }
       
   179     IMUM_OUT();
       
   180     }
       
   181 
       
   182 // ----------------------------------------------------------------------------
       
   183 // CImap4FetchOp::DoConnectedOpL()
       
   184 // ----------------------------------------------------------------------------
       
   185 //
       
   186 void CImap4FetchOp::DoConnectedOpL()
       
   187     {
       
   188     IMUM_CONTEXT( CImap4FetchOp::DoConnectedOpL, 0, KImumMtmLog );
       
   189     IMUM_IN();
       
   190     
       
   191     iStatus = KRequestPending;
       
   192     if ( iPopulate )
       
   193         {
       
   194         delete iOperation;
       
   195         iOperation = NULL;
       
   196         DoPopulateL();
       
   197         }
       
   198     else
       
   199         {
       
   200         TPckg<TImImap4GetMailInfo> param( iGetMailInfo );
       
   201         delete iOperation;
       
   202         iOperation = NULL;
       
   203         InvokeClientMtmAsyncFunctionL(
       
   204             iFunctionId, *iSelection, iService, param);
       
   205         }
       
   206     SetActive();
       
   207     IMUM_OUT();
       
   208     }
       
   209 
       
   210 // ----------------------------------------------------------------------------
       
   211 // CImap4FetchOp::ConnectedOpErrorProgressL()
       
   212 // ----------------------------------------------------------------------------
       
   213 //
       
   214 const TDesC8& CImap4FetchOp::ConnectedOpErrorProgressL(TInt aError)
       
   215     {
       
   216     IMUM_CONTEXT( CImap4FetchOp::ConnectedOpErrorProgressL, 0, KImumMtmLog );
       
   217     IMUM_IN();
       
   218     
       
   219     TImap4CompoundProgress& prog = iProgressBuf();
       
   220     prog.iGenericProgress.iOperation = TImap4GenericProgress::EPopulate;
       
   221     prog.iGenericProgress.iState = TImap4GenericProgress::EFetching;
       
   222     prog.iGenericProgress.iErrorCode = aError;
       
   223     IMUM_OUT();
       
   224     return iProgressBuf;
       
   225     }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // CImap4FetchOp::DoPopulateL()
       
   229 // ----------------------------------------------------------------------------
       
   230 //
       
   231 void CImap4FetchOp::DoPopulateL()
       
   232     {
       
   233     IMUM_CONTEXT( CImap4FetchOp::DoPopulateL, 0, KImumMtmLog );
       
   234     IMUM_IN();
       
   235     
       
   236     TPckg<TImImap4GetPartialMailInfo> param( iPartialGetMailInfo );
       
   237 
       
   238     CMsvEntry* cEntry = iMsvSession.GetEntryL(iService);
       
   239     CleanupStack::PushL( cEntry );
       
   240 
       
   241     CMsvEntrySelection* selection = new(ELeave) CMsvEntrySelection;
       
   242     CleanupStack::PushL( selection );
       
   243     selection->AppendL( iService );
       
   244 
       
   245     TMsvId inbox = FindInboxL( *cEntry );
       
   246     selection->AppendL( inbox );
       
   247 
       
   248     InvokeClientMtmAsyncFunctionL(
       
   249         KIMAP4MTMPopulateNewMailWhenAlreadyConnected,
       
   250         //KIMAP4MTMPopulateAllMailWhenAlreadyConnected,
       
   251         *selection,
       
   252         iService,
       
   253         param);
       
   254 
       
   255     CleanupStack::PopAndDestroy( 2, cEntry ); // CSI: 47 # selection, centry
       
   256     IMUM_OUT();
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------------------------------
       
   260 // CImap4FetchOp::FindInboxL()
       
   261 // ----------------------------------------------------------------------------
       
   262 //
       
   263 TMsvId CImap4FetchOp::FindInboxL( CMsvEntry& aEntry )
       
   264     {
       
   265     IMUM_CONTEXT( CImap4FetchOp::FindInboxL, 0, KImumMtmLog );
       
   266     IMUM_IN();
       
   267     
       
   268     TMsvId inboxId = KErrNotFound;
       
   269     TMsvEntry child;
       
   270     const TInt count = aEntry.Count();
       
   271     _LIT( KTMceUiInboxName, "INBOX");
       
   272     for (TInt loop = 0; loop < count && inboxId == KErrNotFound; loop++)
       
   273         {
       
   274         child = (aEntry)[loop];
       
   275         if ( child.iType == KUidMsvFolderEntry  &&
       
   276              child.iDetails.CompareF( KTMceUiInboxName ) == 0 )
       
   277             {
       
   278             inboxId = child.Id();
       
   279             }
       
   280         }
       
   281     IMUM_OUT();
       
   282 
       
   283     return inboxId;
       
   284     }
       
   285 
       
   286