email/imum/Mtms/Src/Imap4FetchAttachmentOp.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 *       Fetch attachments
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <eikenv.h>
       
    21 #include <eikrutil.h>
       
    22 
       
    23 #include "Imap4FetchAttachmentOp.h"
       
    24 #include "EmailMsgSizerOperation.h"
       
    25 #include "EmailUtils.H"
       
    26 #include "ImumDisconnectOperation.h"
       
    27 #include <imapcmds.h>
       
    28 #include "IMAPPRGR.H"
       
    29 #include "ImumMtmLogging.h"
       
    30 #include "ImumPanic.h"
       
    31 
       
    32 
       
    33 CImap4FetchAttachmentOp* CImap4FetchAttachmentOp::NewL(
       
    34     CImumInternalApi& aMailboxApi,
       
    35     TRequestStatus& aStatus,
       
    36     MMsvProgressReporter& aReporter,
       
    37     TMsvId aService,
       
    38     const CMsvEntrySelection& aSel)
       
    39     {
       
    40     IMUM_STATIC_CONTEXT( CImap4FetchAttachmentOp::NewL, 0, mtm, KImumMtmLog );
       
    41     IMUM_IN();
       
    42     
       
    43     CImap4FetchAttachmentOp* op = new(ELeave) CImap4FetchAttachmentOp(
       
    44         aMailboxApi, aStatus, aReporter, aService);
       
    45     CleanupStack::PushL(op);
       
    46     op->ConstructL(aSel);
       
    47     CleanupStack::Pop();
       
    48     IMUM_OUT();
       
    49     return op;
       
    50     }
       
    51 
       
    52 CImap4FetchAttachmentOp::~CImap4FetchAttachmentOp()
       
    53     {
       
    54     IMUM_CONTEXT( CImap4FetchAttachmentOp::~CImap4FetchAttachmentOp, 0, KImumMtmLog );
       
    55     IMUM_IN();
       
    56     IMUM_OUT();
       
    57     
       
    58     delete iSelection;
       
    59     }
       
    60 
       
    61 void CImap4FetchAttachmentOp::DoConnectedOpL()
       
    62     {
       
    63     IMUM_CONTEXT( CImap4FetchAttachmentOp::DoConnectedOpL, 0, KImumMtmLog );
       
    64     IMUM_IN();
       
    65     
       
    66     delete iOperation;
       
    67     iOperation = NULL;
       
    68     // iOperation is set in base class function InvokeClientMtmAsyncFunctionL
       
    69     TPckgBuf<TImImap4GetMailInfo> optionsBuf;
       
    70     TImImap4GetMailInfo& options = optionsBuf();
       
    71     options.iMaxEmailSize = KMaxTInt32;
       
    72     options.iGetMailBodyParts = EGetImap4EmailAttachments;
       
    73     options.iDestinationFolder = 0; // not used with fetch attachment operation
       
    74     InvokeClientMtmAsyncFunctionL(
       
    75         KIMAP4MTMPopulate, *iSelection, iService, optionsBuf);
       
    76     SetActive();
       
    77     IMUM_OUT();
       
    78     }
       
    79 
       
    80 const TDesC8& CImap4FetchAttachmentOp::ConnectedOpErrorProgressL(TInt aError)
       
    81     {
       
    82     IMUM_CONTEXT( CImap4FetchAttachmentOp::ConnectedOpErrorProgressL, 0, KImumMtmLog );
       
    83     IMUM_IN();
       
    84     
       
    85     __ASSERT_DEBUG(iState==EStateDoingOp || iState==EStateIdle,
       
    86         User::Panic(KImumMtmUiPanic,EPanicWrongStateForOpErrorProgress));
       
    87     iUiProgress().iError=aError;
       
    88     IMUM_OUT();
       
    89     return iUiProgress;
       
    90     }
       
    91 
       
    92 const TDesC8& CImap4FetchAttachmentOp::ProgressL()
       
    93     {
       
    94     IMUM_CONTEXT( CImap4FetchAttachmentOp::ProgressL, 0, KImumMtmLog );
       
    95     IMUM_IN();
       
    96     
       
    97     if(iState!=EStateDoingOp)
       
    98         {
       
    99         IMUM_OUT();
       
   100         return CImap4ConnectedOp::ProgressL();
       
   101         }
       
   102     else
       
   103         {
       
   104         TPckgBuf<TImap4CompoundProgress> fetchProgressBuf;
       
   105         fetchProgressBuf.Copy(iOperation->ProgressL());
       
   106         const TImap4CompoundProgress& opProgress=fetchProgressBuf();
       
   107         TImap4UiProgress& uiProgress=iUiProgress();
       
   108         uiProgress.iBytesToDo=opProgress.iGenericProgress.iBytesToDo;
       
   109         uiProgress.iBytesDone=opProgress.iGenericProgress.iBytesDone;
       
   110         uiProgress.iError=fetchProgressBuf().iGenericProgress.iErrorCode;
       
   111         IMUM_OUT();
       
   112         return iUiProgress;
       
   113         }
       
   114     }
       
   115 
       
   116 CImap4FetchAttachmentOp::CImap4FetchAttachmentOp(
       
   117     CImumInternalApi& aMailboxApi,
       
   118     TRequestStatus& aStatus,
       
   119     MMsvProgressReporter& aReporter,
       
   120     TMsvId aService)
       
   121     :
       
   122     CImap4ConnectedOp(aMailboxApi, aStatus, aReporter, aService)
       
   123     {
       
   124     IMUM_CONTEXT( CImap4FetchAttachmentOp::CImap4FetchAttachmentOp, 0, KImumMtmLog );
       
   125     IMUM_IN();
       
   126     
       
   127     iConnectionCompletionState = CImapConnectionOp::ECompleteAfterConnect;
       
   128     // Don't do a sync.
       
   129     TImap4UiProgress uiProgress;
       
   130     uiProgress.iUiOperation=TImap4UiProgress::EFetchingAttachment;
       
   131     //  Used during fetch stage to differentiate from
       
   132     iUiProgress()=uiProgress;
       
   133     //  standard message fetch.
       
   134     IMUM_OUT();
       
   135     }
       
   136 
       
   137 void CImap4FetchAttachmentOp::ConstructL(const CMsvEntrySelection& aSel)
       
   138     {
       
   139     IMUM_CONTEXT( CImap4FetchAttachmentOp::ConstructL, 0, KImumMtmLog );
       
   140     IMUM_IN();
       
   141     
       
   142     __ASSERT_DEBUG(aSel.Count(),
       
   143         User::Panic(KImumMtmUiPanic,EPanicSelectionEmpty));
       
   144     if ( aSel.Count() == 0 )
       
   145         {
       
   146         User::Leave( KErrNotSupported );
       
   147         }
       
   148     iSelection = aSel.CopyL();
       
   149     BaseConstructL(KUidMsgTypeIMAP4);
       
   150 
       
   151     // Get message size.
       
   152     CMsvEntry* centry = iMsvSession.GetEntryL(aSel[0]);
       
   153     TInt32 msgSize = centry->Entry().iSize;
       
   154     delete centry;
       
   155 
       
   156     // Check message size.
       
   157     if ( MsvEmailMtmUiUtils::CheckAvailableDiskSpaceForDownloadL(
       
   158         msgSize, *iEikEnv, iMsvSession ) )
       
   159         {
       
   160         StartL();
       
   161         }
       
   162     else
       
   163         {
       
   164         // Not enough disk space or memory.
       
   165         // User already notified, so 'this' op completes without error.           
       
   166         CompleteThis();
       
   167         iState = EStateDisconnecting;
       
   168         
       
   169         SetActive();
       
   170         }
       
   171     IMUM_OUT();
       
   172     }
       
   173 
       
   174