email/imum/Mtms/Src/SmtpCopyMoveOp.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 *       Class implementation file
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <miut_err.h>
       
    22 #include "SmtpCopyMoveOp.h"
       
    23 #include "MsvEmailConnectionProgressProvider.h"
       
    24 #include "ImumPanic.h"
       
    25 #include "ImumMtmLogging.h"
       
    26 #include "EmailUtils.H"
       
    27 #include "MsvConnectionValidation.h"
       
    28 #include "ImumMboxSettingsUtils.h"
       
    29 #include "ImumInMailboxUtilities.h"
       
    30 #include "SendUiConsts.h"
       
    31 
       
    32 const TInt KCopyMoveOpPriority = CActive::EPriorityStandard;
       
    33 const TInt KImumMaxLoginRetries = 3;
       
    34 
       
    35 
       
    36 // ----------------------------------------------------------------------------
       
    37 // CSmtpCopyMoveOp::NewL()
       
    38 // ----------------------------------------------------------------------------
       
    39 //
       
    40 CSmtpCopyMoveOp* CSmtpCopyMoveOp::NewL(
       
    41     CImumInternalApi& aMailboxApi,
       
    42     TRequestStatus& aObserverRequestStatus,
       
    43     MMsvProgressReporter& aReporter,
       
    44     TMsvId aTarget,
       
    45     const CMsvEntrySelection& aSel,
       
    46     TBool aMoving )
       
    47     {
       
    48     IMUM_STATIC_CONTEXT( CSmtpCopyMoveOp::NewL, 0, mtm, KImumMtmLog );
       
    49     IMUM_IN();
       
    50 
       
    51     CSmtpCopyMoveOp* op = new ( ELeave ) CSmtpCopyMoveOp(
       
    52         aMailboxApi, aObserverRequestStatus, aReporter, aTarget, aMoving );
       
    53     CleanupStack::PushL( op );
       
    54     op->ConstructL( aSel );
       
    55     CleanupStack::Pop( op );
       
    56     IMUM_OUT();
       
    57     return op;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CSmtpCopyMoveOp::~CSmtpCopyMoveOp()
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 CSmtpCopyMoveOp::~CSmtpCopyMoveOp()
       
    65     {
       
    66     IMUM_CONTEXT( CSmtpCopyMoveOp::~CSmtpCopyMoveOp, 0, KImumMtmLog );
       
    67     IMUM_IN();
       
    68 
       
    69     delete iEntry;
       
    70     delete iSelection;
       
    71     delete iProgProvider;
       
    72     IMUM_OUT();
       
    73     }
       
    74 
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CSmtpCopyMoveOp::ProgressL()
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 const TDesC8& CSmtpCopyMoveOp::ProgressL()
       
    81     {
       
    82     IMUM_CONTEXT( CSmtpCopyMoveOp::ProgressL, 0, KImumMtmLog );
       
    83     IMUM_IN();
       
    84 
       
    85     if(!iOperation)
       
    86         {
       
    87         if ( iValidIap )
       
    88             {
       
    89             IMUM_OUT();
       
    90             return iDummyProg;
       
    91             }
       
    92         else
       
    93             {
       
    94             TImSmtpProgress& progress = iProgress();
       
    95             progress.SetError( KSmtpUnknownErr );
       
    96             IMUM_OUT();
       
    97             return iProgress;
       
    98             }
       
    99         }
       
   100     TRAPD( err, iProgress.Copy( iOperation->ProgressL() ) );
       
   101     // If message is already being sent, ProgressL will leave with KErrNotReady
       
   102     // Ignore this error, otherwise progress bar of the second sending
       
   103     // will be missing 'Connecting to mailbox...' texts.
       
   104     if ( err != KErrNotReady && err != KErrNone )
       
   105     	{
       
   106 		User::Leave( err );
       
   107 		}
       
   108     if ( ( iStatus == KRequestPending ) &&
       
   109          ( iProgress().Status() != EMsgOutboxProgressSending ) )
       
   110         {
       
   111         IMUM_OUT();
       
   112         return iProgProvider->GetConnectionProgressL(iError);
       
   113         }
       
   114 
       
   115     IMUM_OUT();
       
   116     return iProgress;
       
   117     }
       
   118 
       
   119 
       
   120 // ----------------------------------------------------------------------------
       
   121 // CSmtpCopyMoveOp::GetErrorProgressL()
       
   122 // ----------------------------------------------------------------------------
       
   123 //
       
   124 const TDesC8& CSmtpCopyMoveOp::GetErrorProgressL(TInt /*aError*/)
       
   125     {
       
   126     IMUM_CONTEXT( CSmtpCopyMoveOp::GetErrorProgressL, 0, KImumMtmLog );
       
   127     IMUM_IN();
       
   128     IMUM_OUT();
       
   129 
       
   130     // Never called.
       
   131     return iProgress;
       
   132     }
       
   133 
       
   134 
       
   135 // ----------------------------------------------------------------------------
       
   136 // CSmtpCopyMoveOp::DoRunL()
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CSmtpCopyMoveOp::DoRunL()
       
   140     {
       
   141     IMUM_CONTEXT( CSmtpCopyMoveOp::DoRunL, 0, KImumMtmLog );
       
   142     IMUM_IN();
       
   143 
       
   144     if ( ContinueSendingL() )
       
   145         {
       
   146         InitiateSendingOperationL();
       
   147         }
       
   148     else
       
   149         {
       
   150         CompleteObserver( iValidIap ? KErrNone : KSmtpUnknownErr );
       
   151         }
       
   152     IMUM_OUT();
       
   153     }
       
   154 
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CSmtpCopyMoveOp::CSmtpCopyMoveOp()
       
   158 // ----------------------------------------------------------------------------
       
   159 //
       
   160 CSmtpCopyMoveOp::CSmtpCopyMoveOp(
       
   161     CImumInternalApi& aMailboxApi,
       
   162     TRequestStatus& aObserverRequestStatus,
       
   163     MMsvProgressReporter& aReporter,
       
   164     TMsvId aTarget,
       
   165     TBool aMoving)
       
   166     :
       
   167     CImumOnlineOperation(
       
   168         aMailboxApi, KCopyMoveOpPriority, aObserverRequestStatus, aReporter ),
       
   169     iTarget(aTarget),
       
   170     iMoving(aMoving),
       
   171     iValidIap( ETrue ), // valid until otherwise stated
       
   172     iLoginRetryCounter( 0 )
       
   173     {
       
   174     IMUM_CONTEXT( CSmtpCopyMoveOp::CSmtpCopyMoveOp, 0, KImumMtmLog );
       
   175     IMUM_IN();
       
   176     IMUM_OUT();
       
   177 
       
   178     }
       
   179 
       
   180 
       
   181 // ----------------------------------------------------------------------------
       
   182 // CSmtpCopyMoveOp::ConstructL()
       
   183 // ----------------------------------------------------------------------------
       
   184 //
       
   185 void CSmtpCopyMoveOp::ConstructL(
       
   186     const CMsvEntrySelection& aSel )
       
   187     {
       
   188     IMUM_CONTEXT( CSmtpCopyMoveOp::ConstructL, 0, KImumMtmLog );
       
   189     IMUM_IN();
       
   190 
       
   191     __ASSERT_ALWAYS( aSel.Count(),
       
   192         User::Panic( KImumMtmUiPanic,ESmtpMtmUiEmptySelection ) );
       
   193     BaseConstructL( KUidMsgTypeSMTP );
       
   194 
       
   195     iEntry = iMsvSession.GetEntryL(aSel[0]);
       
   196     iService = iEntry->Entry().iServiceId;
       
   197     const TMsvId parent = iEntry->Entry().Parent();
       
   198 
       
   199     // To speed up connection establishment, avoid loading settings multiple
       
   200     // times. Get all the info needed at once.
       
   201     CImumInSettingsData* settings =
       
   202         iMailboxApi.MailboxServicesL().LoadMailboxSettingsL( iService );
       
   203     CleanupStack::PushL( settings );
       
   204 
       
   205     // Get iap name
       
   206     TBuf<KImasImailMaxSettingsLength> iapName;
       
   207     MsvConnectionValidation::GetServiceIapNameL( *settings,
       
   208         KSenduiMtmSmtpUid, iapName);
       
   209 
       
   210     TBool ok = ValidateL( *settings );
       
   211     CleanupStack::PopAndDestroy(); // settings
       
   212 
       
   213     if ( !ok )
       
   214         {
       
   215         // Will be unable to connect. Complete now.
       
   216         SetActive();
       
   217         CompleteThis();
       
   218         IMUM_OUT();
       
   219         return;
       
   220         }
       
   221 
       
   222     iSelection = aSel.CopyL();
       
   223 
       
   224     iProgProvider = CMsvEmailConnectionProgressProvider::NewL( iapName,
       
   225         iService );
       
   226 
       
   227     iEntry->SetEntryL(parent);
       
   228     InitiateSendingOperationL();
       
   229     IMUM_OUT();
       
   230     }
       
   231 
       
   232 // ----------------------------------------------------------------------------
       
   233 // CSmtpCopyMoveOp::ValidateL()
       
   234 // ----------------------------------------------------------------------------
       
   235 //
       
   236 TBool CSmtpCopyMoveOp::ValidateL( CImumInSettingsData& aSettings )
       
   237     {
       
   238     IMUM_CONTEXT( CSmtpCopyMoveOp::ValidateL, 0, KImumMtmLog );
       
   239     IMUM_IN();
       
   240 
       
   241     TBool ok = ETrue;
       
   242     iEntry->SetEntryL(iService);
       
   243     if(!iEntry->Entry().Connected())
       
   244         {
       
   245         ok = iValidIap = ( aSettings.Validate() == KErrNone );
       
   246         }
       
   247     IMUM_OUT();
       
   248     return ok;
       
   249     }
       
   250 
       
   251 // ----------------------------------------------------------------------------
       
   252 // CSmtpCopyMoveOp::InitiateSendingOperationL()
       
   253 // ----------------------------------------------------------------------------
       
   254 //
       
   255 void CSmtpCopyMoveOp::InitiateSendingOperationL()
       
   256     {
       
   257     IMUM_CONTEXT( CSmtpCopyMoveOp::InitiateSendingOperationL, 0, KImumMtmLog );
       
   258     IMUM_IN();
       
   259 
       
   260     if ( iOperation )
       
   261         {
       
   262         delete iOperation;
       
   263         iOperation = NULL;
       
   264         }
       
   265 
       
   266     iOperation = MsvEmailMtmUiUtils::DoCEntryCopyMoveL(
       
   267         *iEntry, *iSelection, iTarget, iStatus, !iMoving );
       
   268 
       
   269     iStatus = KRequestPending;
       
   270     SetActive();
       
   271     IMUM_OUT();
       
   272     }
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 // CSmtpCopyMoveOp::GetProgressErrorL()
       
   276 // ----------------------------------------------------------------------------
       
   277 //
       
   278 TInt CSmtpCopyMoveOp::GetProgressErrorL()
       
   279     {
       
   280     IMUM_CONTEXT( CSmtpCopyMoveOp::GetProgressErrorL, 0, KImumMtmLog );
       
   281     IMUM_IN();
       
   282 
       
   283     const TPckgBuf<TImSmtpProgress>& progress =
       
   284         static_cast<const TPckgBuf<TImSmtpProgress>&>( ProgressL() );
       
   285     IMUM_OUT();
       
   286     return progress().Error();
       
   287     }
       
   288 
       
   289 // ----------------------------------------------------------------------------
       
   290 // CSmtpCopyMoveOp::ContinueSendingL()
       
   291 // ----------------------------------------------------------------------------
       
   292 //
       
   293 TBool CSmtpCopyMoveOp::ContinueSendingL()
       
   294     {
       
   295     IMUM_CONTEXT( CSmtpCopyMoveOp::ContinueSendingL, 0, KImumMtmLog );
       
   296     IMUM_IN();
       
   297 
       
   298     TInt error = GetProgressErrorL();
       
   299 
       
   300     TBool continueSending =
       
   301         !( error != KSmtpLoginRefused && error != KSmtpUnknownErr );
       
   302 
       
   303     // If login is refused we can try again
       
   304     if ( continueSending )
       
   305         {
       
   306         continueSending = ( iLoginRetryCounter++ < KImumMaxLoginRetries );
       
   307         }
       
   308 
       
   309     if ( continueSending )
       
   310         {
       
   311         continueSending =
       
   312             MsvConnectionValidation::ShowLoginDetailsRejectionDlgL(
       
   313                 iMailboxApi, iService );
       
   314         }
       
   315     IMUM_OUT();
       
   316 
       
   317     return continueSending;
       
   318     }
       
   319 
       
   320 
       
   321