email/imum/Mtms/Src/SmtpMtmUi.cpp
branchRCL_3
changeset 60 7fdbb852d323
parent 0 72b543305e3a
equal deleted inserted replaced
57:ebe688cedc25 60:7fdbb852d323
       
     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 *       SMTP MTM UI
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // MODULE - SMTP MTM UI
       
    21 
       
    22 // Standard includes
       
    23 #include <apacmdln.h>   //CApaCommandLine
       
    24 #include <apgcli.h>
       
    25 #include <apaid.h>
       
    26 #include <txtrich.h>    //CRichText
       
    27 #include <eikdialg.h>   //CEikDialog
       
    28 #include <eikenv.h>     //CEikonEnv
       
    29 #include <eikrutil.h>   //EikResourceUtils
       
    30 #include <MtmExtendedCapabilities.hrh>
       
    31 #include <akninputblock.h> // CAknInputBlock
       
    32 #include <StringLoader.h>
       
    33 #include <avkon.mbg> // bitmaps for progress
       
    34 #include <etelpckt.h>
       
    35 #include <aknViewAppUi.h> //CAknViewAppUi
       
    36 #include <eikapp.h>     //CEikApplication
       
    37 #include <aknclearer.h> // CAknLocalScreenClearer
       
    38 
       
    39 
       
    40 // SMTP & POP includes
       
    41 #include <smtcmtm.h>
       
    42 #include <smtpset.h>
       
    43 #include <pop3set.h>
       
    44 #include <imapset.h>
       
    45 #include <etel.h> // KErrEtelBusyDetected
       
    46 
       
    47 // Messaging includes
       
    48 #include <MuiuMsgEditorLauncher.h>
       
    49 #include <muiumsvuiserviceutilitiesinternal.h>
       
    50 #include <mtmuidef.hrh>
       
    51 #include <imum.rsg>
       
    52 #include <MuiuMsvProgressReporterOperation.h>
       
    53 #include <iapprefs.h>
       
    54 #include <ImumInternalApi.h>                        // CImumInternalApi
       
    55 
       
    56 // Specific includes
       
    57 #include "SmtpMtmUi.h"
       
    58 #include "ImumMtmLogging.h"
       
    59 #include "ImumPanic.h"
       
    60 #include <imum.rsg>
       
    61 #include "EmailPreCreation.h"
       
    62 #include "SmtpCreateNewOp.h"
       
    63 #include "SmtpCancelSendingOp.h"
       
    64 #include "SmtpCopyMoveOp.h"
       
    65 #include "SmtpResetPreCreationOp.h"
       
    66 
       
    67 #include "EmailFeatureUtils.h"
       
    68 #include "EmailUtils.H"
       
    69 #include "MsvEmailConnectionProgressProvider.h"
       
    70 #include "EmailEditorViewerUids.h"
       
    71 
       
    72 #include "SenduiMtmUids.h"
       
    73 #include "ComDbUtl.h"
       
    74 
       
    75 #include <Muiumsginfo.h>
       
    76 #include <Muiumsginfo.hrh>
       
    77 #include <MuiuOperationWait.h> // CMuiuOperationWait
       
    78 #include <messagingvariant.hrh>
       
    79 #include "IMSSettingsNoteUi.h"
       
    80 #include <ImumInSettingsData.h>             // CImumInSettingsData
       
    81 #include <ImumInSettingsDataCollection.h>   // CImumInSettingsDataCollection
       
    82 #include <ImumInMailboxServices.h>          // MImumInMailboxServices
       
    83 #include <ImumInHealthServices.h>           // MImumInHealthServices
       
    84 #include "ImumMboxSettingsUtils.h"          // ImumMboxSettingsUtils
       
    85 #include "ImumCreatorPredefinedMailbox.h"   // CImumCreatorPredefinedMailbox
       
    86 
       
    87 // CONSTANTS
       
    88 const TInt KImumEntriesDoneReplaceIndex     = 0;
       
    89 const TInt KImumTotalEntriesReplaceIndex    = 1;
       
    90 const TInt KImumMessageInfoDateBufferLength = 30;
       
    91 const TInt KImumMessageInfoSizeBufferLength = 20;
       
    92 const TInt KImumMessagePriorityBufferLength = 32;
       
    93 _LIT(KSmtpuMtmUiResourceFile,"IMUM");
       
    94 
       
    95 const TUid KMceMessageListViewId    = { 0x02 };
       
    96 const TUid KMceMainViewListViewId   = { 0x01 };
       
    97 const TInt KMceUid = 0x100058C5;
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // CSmtpMtmUi::NewSMTUMtmUiL()
       
   101 // ----------------------------------------------------------------------------
       
   102 EXPORT_C CBaseMtmUi* NewSMTUMtmUiL(CBaseMtm& aMtm, CRegisteredMtmDll& aRegisteredDll)
       
   103     {
       
   104     return CSmtpMtmUi::NewL(aMtm, aRegisteredDll);
       
   105     }
       
   106 
       
   107 // ----------------------------------------------------------------------------
       
   108 // CSmtpMtmUi::NewL()
       
   109 // ----------------------------------------------------------------------------
       
   110 CSmtpMtmUi* CSmtpMtmUi::NewL(CBaseMtm& aBaseMtm, CRegisteredMtmDll& aRegisteredMtmDll)
       
   111     {
       
   112     IMUM_STATIC_CONTEXT( CSmtpMtmUi::NewL, 0, mtm, KImumMtmLog );
       
   113     IMUM_IN();
       
   114 
       
   115     CSmtpMtmUi* self=new(ELeave) CSmtpMtmUi(aBaseMtm, aRegisteredMtmDll);
       
   116     CleanupStack::PushL(self);
       
   117     self->ConstructL();
       
   118     CleanupStack::Pop();
       
   119     IMUM_OUT();
       
   120     return self;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // CSmtpMtmUi::CSmtpMtmUi()
       
   125 // ----------------------------------------------------------------------------
       
   126 CSmtpMtmUi::CSmtpMtmUi(CBaseMtm& aBaseMtm, CRegisteredMtmDll& aRegisteredMtmDll)
       
   127     :
       
   128     CImumMtmBaseMtmUi( aBaseMtm, aRegisteredMtmDll )
       
   129     {
       
   130     IMUM_CONTEXT( CSmtpMtmUi::CSmtpMtmUi, 0, KImumMtmLog );
       
   131     IMUM_IN();
       
   132 
       
   133     //don't wait for msg editors to exit.
       
   134     iFlags = EMtmUiFlagEditorNoWaitForExit;
       
   135     IMUM_OUT();
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // CSmtpMtmUi::ConstructL()
       
   140 // ----------------------------------------------------------------------------
       
   141 void CSmtpMtmUi::ConstructL()
       
   142     {
       
   143     IMUM_CONTEXT( CSmtpMtmUi::ConstructL, 0, KImumMtmLog );
       
   144     IMUM_IN();
       
   145 
       
   146     // Construct own base MTM UI
       
   147     CImumMtmBaseMtmUi::ConstructL();
       
   148 
       
   149     // Create a 'message pre-creator'.
       
   150     iPreCreate = CEmailPreCreation::NewL( *iMailboxApi );
       
   151 
       
   152     //VARIATION START
       
   153     iNewSecureSettingOn =
       
   154         MsvEmailMtmUiFeatureUtils::LocalFeatureL(
       
   155             KCRUidMuiuVariation, KMuiuEmailConfigFlags,
       
   156             KEmailFeatureIdSecureSettings );
       
   157     //VARIATION END
       
   158     IMUM_OUT();
       
   159 
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------------------------------
       
   163 // CSmtpMtmUi::ResolveEditorFileNameL()
       
   164 // ----------------------------------------------------------------------------
       
   165 void CSmtpMtmUi::ResolveEditorFileNameL()
       
   166     {
       
   167     IMUM_CONTEXT( CSmtpMtmUi::ResolveEditorFileNameL, 0, KImumMtmLog );
       
   168     IMUM_IN();
       
   169 
       
   170     __ASSERT_DEBUG(
       
   171         iEditorFilename == NULL,
       
   172             User::Panic(KImumMtmUiPanic, ESmtpMtmUiEditorFilenameDuplicate ) );
       
   173     iEditorFilename = MsvUiEditorUtilities::ResolveAppFileNameL(
       
   174         KUidMsgInternetMailEditor );
       
   175     IMUM_OUT();
       
   176     }
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CSmtpMtmUi::ResolveViewerFileNameL()
       
   180 // ----------------------------------------------------------------------------
       
   181 void CSmtpMtmUi::ResolveViewerFileNameL()
       
   182     {
       
   183     IMUM_CONTEXT( CSmtpMtmUi::ResolveViewerFileNameL, 0, KImumMtmLog );
       
   184     IMUM_IN();
       
   185 
       
   186     __ASSERT_DEBUG(
       
   187         iViewerFilename == NULL,
       
   188             User::Panic(KImumMtmUiPanic, ESmtpMtmUiEditorFilenameDuplicate ) );
       
   189     iViewerFilename = MsvUiEditorUtilities::ResolveAppFileNameL(
       
   190         KUidMsgInternetMailViewer );
       
   191     IMUM_OUT();
       
   192     }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CSmtpMtmUi::GetResourceFileName()
       
   196 // ----------------------------------------------------------------------------
       
   197 void CSmtpMtmUi::GetResourceFileName( TFileName& aFileName ) const
       
   198     {
       
   199     IMUM_CONTEXT( CSmtpMtmUi::GetResourceFileName, 0, KImumMtmLog );
       
   200     IMUM_IN();
       
   201 
       
   202     aFileName=KSmtpuMtmUiResourceFile;
       
   203     IMUM_OUT();
       
   204     }
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CSmtpMtmUi::~CSmtpMtmUi()
       
   208 // ----------------------------------------------------------------------------
       
   209 CSmtpMtmUi::~CSmtpMtmUi()
       
   210     {
       
   211     IMUM_CONTEXT( CSmtpMtmUi::~CSmtpMtmUi, 0, KImumMtmLog );
       
   212     IMUM_IN();
       
   213 
       
   214     delete iPreCreate;
       
   215     iPreCreate = NULL;
       
   216     delete iEditorFilename;
       
   217     iEditorFilename = NULL;
       
   218     delete iViewerFilename;
       
   219     iViewerFilename = NULL;
       
   220     IMUM_OUT();
       
   221     }
       
   222 
       
   223 // ----------------------------------------------------------------------------
       
   224 // CSmtpMtmUi::QueryCapability()
       
   225 // ----------------------------------------------------------------------------
       
   226 TInt CSmtpMtmUi::QueryCapability(TUid aCapability, TInt& aResponse)
       
   227     {
       
   228     IMUM_CONTEXT( CSmtpMtmUi::QueryCapability, 0, KImumMtmLog );
       
   229     IMUM_IN();
       
   230 
       
   231     if ( aCapability.iUid == KUidMsvMtmUiQueryMessagingInitialisation )
       
   232         {
       
   233         aResponse=ETrue;
       
   234         IMUM_OUT();
       
   235         return KErrNone;
       
   236         }
       
   237     else if( aCapability.iUid == KUidMsvMtmQuerySupportValidateService )
       
   238         {
       
   239         aResponse=ETrue;
       
   240         IMUM_OUT();
       
   241         return KErrNone;
       
   242         }
       
   243     else if ( aCapability.iUid == KUidMsvMtmQuerySupportValidateSelection )
       
   244         {
       
   245         aResponse=ETrue;
       
   246         IMUM_OUT();
       
   247         return KErrNone;
       
   248         }
       
   249     else
       
   250         {
       
   251         IMUM_OUT();
       
   252         return CBaseMtmUi::QueryCapability( aCapability, aResponse );
       
   253         }
       
   254     }
       
   255 
       
   256 // ----------------------------------------------------------------------------
       
   257 // CSmtpMtmUi::InvokeAsyncFunctionL()
       
   258 // ----------------------------------------------------------------------------
       
   259 CMsvOperation* CSmtpMtmUi::InvokeAsyncFunctionL(
       
   260     TInt aFunctionId,
       
   261     const CMsvEntrySelection& aSelection,
       
   262     TRequestStatus& aStatus,
       
   263     TDes8& aParameter )
       
   264     {
       
   265     IMUM_CONTEXT( CSmtpMtmUi::InvokeAsyncFunctionL, 0, KImumMtmLog );
       
   266     IMUM_IN();
       
   267 
       
   268     if(aFunctionId == KMtmUiFunctionMessageInfo)
       
   269         {
       
   270         return ShowMessageInfoL(aStatus, aParameter);
       
   271         }
       
   272     if ( aFunctionId == KMtmUiFunctionPreCreateMessage )
       
   273         {
       
   274         CEmailPreCreation* preCreate = CEmailPreCreation::NewL( *iMailboxApi );
       
   275         CleanupStack::PushL( preCreate );
       
   276         CMsvOperation* op =
       
   277             preCreate->DeleteAllPreCreatedEmailsL( aSelection.At(0), aStatus );
       
   278         CleanupStack::PopAndDestroy( preCreate );
       
   279         IMUM_OUT();
       
   280 
       
   281         return op;
       
   282         }
       
   283     IMUM_OUT();
       
   284     return CBaseMtmUi::InvokeAsyncFunctionL( aFunctionId,
       
   285                                              aSelection,
       
   286                                              aStatus,
       
   287                                              aParameter);
       
   288     }
       
   289 
       
   290 // ----------------------------------------------------------------------------
       
   291 // CSmtpMtmUi::ShowMessageInfoL()
       
   292 // ----------------------------------------------------------------------------
       
   293 CMsvOperation* CSmtpMtmUi::ShowMessageInfoL(
       
   294     TRequestStatus& aCompletionStatus,
       
   295     TDes8& /*aParameter*/ )
       
   296     {
       
   297     IMUM_CONTEXT( CSmtpMtmUi::ShowMessageInfoL, 0, KImumMtmLog );
       
   298     IMUM_IN();
       
   299 
       
   300     TMsgInfoMessageInfoData infoData;
       
   301     TBuf<KImumMessageInfoDateBufferLength> dateBuf;
       
   302     TBuf<KImumMessageInfoDateBufferLength> timeBuf;
       
   303     TBuf<KImumMessageInfoSizeBufferLength> sizeBuf;
       
   304     TBuf<KImumMessagePriorityBufferLength> priorityBuf;
       
   305     MsvEmailMtmUiUtils::SetMessageInfoDataLCCCCC(
       
   306         infoData,BaseMtm(),
       
   307         *iEikonEnv,
       
   308         dateBuf,
       
   309         timeBuf,
       
   310         sizeBuf,
       
   311         priorityBuf
       
   312         );
       
   313 
       
   314     TBuf<KImumMessageInfoDateBufferLength> type;
       
   315     StringLoader::Load( type, R_SMTP_MESSAGE_INFO_MAIL_TYPE, iCoeEnv );
       
   316     infoData.iType.Set( type );
       
   317 
       
   318     CMsgInfoMessageInfoDialog* infoDialog = CMsgInfoMessageInfoDialog::NewL();
       
   319     infoDialog->ExecuteLD( infoData, CMsgInfoMessageInfoDialog::EEmailEditor );
       
   320     CleanupStack::PopAndDestroy( 5 ); // CSI: 47 # 5 C's on end of SetMessageInfoDataLCCCCC
       
   321     IMUM_OUT();
       
   322 
       
   323     return CMsvCompletedOperation::NewL(
       
   324         Session(),
       
   325         KUidMsvLocalServiceMtm,
       
   326         KNullDesC8,
       
   327         KMsvLocalServiceIndexEntryId,
       
   328         aCompletionStatus,
       
   329         KErrNone
       
   330         );
       
   331     }
       
   332 
       
   333 // ----------------------------------------------------------------------------
       
   334 // CSmtpMtmUi::InvokeSyncFunctionL()
       
   335 // ----------------------------------------------------------------------------
       
   336 void CSmtpMtmUi::InvokeSyncFunctionL(
       
   337     TInt aFunctionId,
       
   338     const CMsvEntrySelection& aSelection,
       
   339     TDes8& aParameter)
       
   340     {
       
   341     IMUM_CONTEXT( CSmtpMtmUi::InvokeSyncFunctionL, 0, KImumMtmLog );
       
   342     IMUM_IN();
       
   343 
       
   344     // Context is dependant on function ID.
       
   345 
       
   346     switch (aFunctionId)
       
   347         {
       
   348         case KMtmUiMessagingInitialisation:
       
   349             HandlePredefinedMailboxCreationL();
       
   350             break;
       
   351 
       
   352         case KMtmUiFunctionValidateService://servicevalidation
       
   353             ValidateServiceL( aParameter );
       
   354             break;
       
   355 
       
   356         case KUidMsvMtmQuerySupportValidateSelection:
       
   357             ValidateServiceL( aSelection, aParameter );
       
   358             break;
       
   359 
       
   360         default:
       
   361             CBaseMtmUi::InvokeSyncFunctionL(aFunctionId, aSelection, aParameter);
       
   362             break;
       
   363         };
       
   364     IMUM_OUT();
       
   365     }
       
   366 
       
   367 // ----------------------------------------------------------------------------
       
   368 // CSmtpMtmUi::CreateExecutePreCreationL()
       
   369 // ----------------------------------------------------------------------------
       
   370 //
       
   371 CMsvOperation* CSmtpMtmUi::CreateExecutePreCreationL(
       
   372     const TMsvId aSmtpService, TRequestStatus& aStatus ) const
       
   373     {
       
   374     IMUM_CONTEXT( CSmtpMtmUi::CreateExecutePreCreationL, 0, KImumMtmLog );
       
   375     IMUM_IN();
       
   376 
       
   377 
       
   378     if ( aSmtpService != KMsvNullIndexEntryId )
       
   379         {
       
   380         TMsvEntry mailbox = iUtils->GetMailboxEntryL( aSmtpService );
       
   381 
       
   382         // Precreate email only for regular mailboxes
       
   383         if ( iUtils->IsMailMtm( mailbox.iMtm ) )
       
   384             {
       
   385             // Create waiter operation and precreation operation
       
   386             CMsvOperation* op = CSmtpResetPreCreationOp::NewL(
       
   387                 iMailboxApi->MsvSession(), aStatus, aSmtpService );
       
   388             IMUM_OUT();
       
   389 
       
   390             return op;
       
   391             }
       
   392         }
       
   393     IMUM_OUT();
       
   394     return NULL;
       
   395     }
       
   396 
       
   397 // ----------------------------------------------------------------------------
       
   398 // CSmtpMtmUi::CreateEmailServiceL()
       
   399 // ----------------------------------------------------------------------------
       
   400 //
       
   401 CMsvOperation* CSmtpMtmUi::CreateEmailServiceL(
       
   402     const TMsvEntry& aEntry,
       
   403     TRequestStatus& aStatus )
       
   404     {
       
   405     IMUM_CONTEXT( CSmtpMtmUi::CreateEmailServiceL, 0, KImumMtmLog );
       
   406     IMUM_IN();
       
   407 
       
   408 
       
   409 
       
   410     // Prepare creation of the email
       
   411     TInt exitCode = KErrCancel; // JYKA: Changed from EEikCmdExit to allow proper error handling
       
   412     TSmtpMtmUiCreateNewServiceParameters saveParameters = ESmtpMtmUiCreateNewServiceExit;
       
   413     TMsvId smtpService = CreateNewServiceL( aEntry, saveParameters );
       
   414     CMsvOperation* preCreationOperation = NULL;
       
   415 
       
   416     // Return value decided the continuation
       
   417     switch ( saveParameters )
       
   418         {
       
   419         default:
       
   420         case ESmtpMtmUiCreateNewServiceNotCreated:
       
   421             exitCode = KErrCancel;
       
   422             break;
       
   423 
       
   424         case ESmtpMtmUiCreateNewServiceSave:
       
   425             preCreationOperation = CreateExecutePreCreationL( smtpService, aStatus );
       
   426             exitCode = KErrNone;
       
   427             break;
       
   428 
       
   429         case ESmtpMtmUiCreateNewServiceSaveAndExit:
       
   430             preCreationOperation = CreateExecutePreCreationL( smtpService, aStatus );
       
   431 
       
   432         //lint -fallthrough
       
   433         case ESmtpMtmUiCreateNewServiceExit:
       
   434             exitCode = EEikCmdExit;
       
   435             break;
       
   436         }
       
   437 
       
   438     IMUM_OUT();
       
   439 
       
   440     if ( preCreationOperation )
       
   441         {
       
   442         return preCreationOperation;
       
   443         }
       
   444 
       
   445     // Finally return the completed operation
       
   446     return CMsvCompletedOperation::NewL(
       
   447         Session(), Type(), KNullDesC8,
       
   448         KMsvLocalServiceIndexEntryId,
       
   449         aStatus, exitCode );
       
   450     }
       
   451 
       
   452 // ----------------------------------------------------------------------------
       
   453 // CSmtpMtmUi::CreateL()
       
   454 // ----------------------------------------------------------------------------
       
   455 CMsvOperation* CSmtpMtmUi::CreateL(
       
   456     const TMsvEntry& aEntry,
       
   457     CMsvEntry& /* aParent */,
       
   458     TRequestStatus& aStatus )
       
   459     {
       
   460     IMUM_CONTEXT( CSmtpMtmUi::CreateL, 0, KImumMtmLog );
       
   461     IMUM_IN();
       
   462 
       
   463 
       
   464     // Context is irrelevant.
       
   465     __ASSERT_ALWAYS( aEntry.iMtm==Type(),
       
   466         User::Panic(KImumMtmUiPanic, ESmtpMtmUiWrongMtm ) );
       
   467 
       
   468     TMsvId smtpService = KMsvNullIndexEntryId;
       
   469 
       
   470     // If service value provided, create the new mailbox
       
   471     if ( aEntry.iType.iUid == KUidMsvServiceEntryValue )
       
   472         {
       
   473 
       
   474         CMsvOperation* op = CreateEmailServiceL( aEntry, aStatus );
       
   475 
       
   476 
       
   477         IMUM_OUT();
       
   478 
       
   479         return op;
       
   480         }
       
   481     else if ( aEntry.iType.iUid != KUidMsvMessageEntryValue )
       
   482         {
       
   483         User::Leave( KErrNotSupported );
       
   484         }
       
   485 
       
   486     smtpService = aEntry.iServiceId;
       
   487     if( smtpService == KMsvNullIndexEntryId ||
       
   488         smtpService == KMsvUnknownServiceIndexEntryId )
       
   489         {
       
   490         // No accounts, offer to create one.
       
   491         TSmtpMtmUiCreateNewServiceParameters saveParameters;
       
   492         smtpService = HandleNoAccountsL( saveParameters );
       
   493         if(  saveParameters == ESmtpMtmUiCreateNewServiceNotCreated )
       
   494             {
       
   495 
       
   496             IMUM_OUT();
       
   497 
       
   498             // User cancelled.
       
   499             return CMsvCompletedOperation::NewL(
       
   500                 Session(), Type(), KNullDesC8,
       
   501                 KMsvLocalServiceIndexEntryId,
       
   502                 aStatus, KErrCancel);
       
   503             }
       
   504         else if(  saveParameters == ESmtpMtmUiCreateNewServiceExit )
       
   505             {
       
   506 
       
   507             IMUM_OUT();
       
   508 
       
   509             // User pressed Exit
       
   510             return CMsvCompletedOperation::NewL(
       
   511                 Session(), Type(),
       
   512                 KNullDesC8, KMsvLocalServiceIndexEntryId,
       
   513                 aStatus, EEikCmdExit);
       
   514             }
       
   515         }
       
   516     else
       
   517         {
       
   518 
       
   519         // Pass to the editor the service Id of the SMTP service to use to send the new message.
       
   520         // The message centre will pass a POP3 or IMAP4 service id in aEntry.iServiceId,
       
   521         // if so find the SMTP service associated with it.
       
   522         TMsvEntry entry;
       
   523         TInt findService = Session().GetEntry(aEntry.iServiceId, smtpService, entry);
       
   524         if ( findService == KErrNone )
       
   525             {
       
   526             if ( entry.iMtm != KUidMsgTypeSMTP )
       
   527                 {
       
   528                 // mce passed pop3 or imap4 service, so we need to find related smtp service
       
   529                 findService = Session().GetEntry(entry.iRelatedId, smtpService, entry);
       
   530                 }
       
   531             }
       
   532 
       
   533         if ( findService == KErrNotFound )
       
   534             {
       
   535 
       
   536             // this will dispay 'check email settings' note
       
   537             User::Leave( KSmtpUnknownErr );
       
   538             }
       
   539         else
       
   540             {
       
   541             User::LeaveIfError( findService );
       
   542             }
       
   543 
       
   544 
       
   545         //smtp auth fix 23092002
       
   546         CheckAndRestoreSmtpUserAndPasswordL( smtpService );
       
   547         //fix end
       
   548         }
       
   549 
       
   550 
       
   551     TEditorParameters editorParams;
       
   552     editorParams.iFlags |= EMsgCreateMessageToService;
       
   553     editorParams.iId = smtpService;
       
   554     TPckgC<TInt> paramPack(ESmtpMtmUiEditing);
       
   555     if(!iEditorFilename)
       
   556         ResolveEditorFileNameL();
       
   557     const TUint preferences = Preferences();
       
   558     editorParams.iFlags &= ~(EMsgLaunchEditorEmbedded | EMsgLaunchEditorThenWait);
       
   559     if(preferences & EMtmUiFlagEditorPreferEmbedded)
       
   560         {
       
   561         editorParams.iFlags |= EMsgLaunchEditorEmbedded;
       
   562         }
       
   563     if(!(preferences & EMtmUiFlagEditorNoWaitForExit))
       
   564         {
       
   565         editorParams.iFlags |= EMsgLaunchEditorThenWait;
       
   566         }
       
   567 
       
   568     IMUM_OUT();
       
   569 
       
   570     return CSmtpCreateNewOp::NewL(*iMailboxApi, aStatus, editorParams, *iEditorFilename, paramPack);
       
   571     }
       
   572 
       
   573 // ----------------------------------------------------------------------------
       
   574 // CSmtpMtmUi::OpenL()
       
   575 // ----------------------------------------------------------------------------
       
   576 CMsvOperation* CSmtpMtmUi::OpenL(TRequestStatus& aStatus)
       
   577     {
       
   578     IMUM_CONTEXT( CSmtpMtmUi::OpenL, 0, KImumMtmLog );
       
   579     IMUM_IN();
       
   580 
       
   581     // Context is entry to open.
       
   582     const TMsvEntry& context=iBaseMtm.Entry().Entry();
       
   583     __ASSERT_ALWAYS(context.iMtm==Type(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiWrongMtm));
       
   584 
       
   585     const TUid type(context.iType);
       
   586     __ASSERT_ALWAYS(type!=KUidMsvFolderEntry, User::Panic(KImumMtmUiPanic, ESmtpMtmUiFoldersNotSupported));
       
   587 
       
   588     //check that message is not corrupted and open
       
   589     CMsvEntry& tmpEntry = iBaseMtm.Entry();
       
   590     TBool hasStore = tmpEntry.HasStoreL();
       
   591 
       
   592     if( hasStore )
       
   593         {
       
   594         IMUM_OUT();
       
   595         return EditL(aStatus);
       
   596         }
       
   597     else//if corrupt
       
   598         {
       
   599         User::Leave( KErrCorrupt );
       
   600         IMUM_OUT();
       
   601         return NULL;//execution never gets here...but complier will
       
   602         }
       
   603     }
       
   604 
       
   605 // ----------------------------------------------------------------------------
       
   606 // CSmtpMtmUi::OpenL()
       
   607 // ----------------------------------------------------------------------------
       
   608 CMsvOperation* CSmtpMtmUi::OpenL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
       
   609     {
       
   610     IMUM_CONTEXT( CSmtpMtmUi::OpenL, 0, KImumMtmLog );
       
   611     IMUM_IN();
       
   612 
       
   613     // Context is irrelevant.
       
   614     __ASSERT_ALWAYS(aSelection.Count(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiEmptySelection));
       
   615     iBaseMtm.Entry().SetEntryL(aSelection[0]);
       
   616     IMUM_OUT();
       
   617     return OpenL(aStatus);
       
   618     }
       
   619 
       
   620 // ----------------------------------------------------------------------------
       
   621 // CSmtpMtmUi::CloseL()
       
   622 // ----------------------------------------------------------------------------
       
   623 CMsvOperation* CSmtpMtmUi::CloseL(TRequestStatus& aStatus)
       
   624     {
       
   625     IMUM_CONTEXT( CSmtpMtmUi::CloseL, 0, KImumMtmLog );
       
   626     IMUM_IN();
       
   627 
       
   628     // Context is entry to close.
       
   629     __ASSERT_DEBUG(iBaseMtm.Entry().Entry().iMtm==Type(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiWrongMtm));
       
   630     __ASSERT_DEBUG(iBaseMtm.Entry().Entry().iType!=KUidMsvFolderEntry, User::Panic(KImumMtmUiPanic, ESmtpMtmUiFoldersNotSupported));
       
   631     // No explicit close of SMTP entries.
       
   632     CMsvCompletedOperation* op=CMsvCompletedOperation::NewL( Session(), Type(), KNullDesC8, KMsvLocalServiceIndexEntryId, aStatus);
       
   633     IMUM_OUT();
       
   634     return op;
       
   635     }
       
   636 
       
   637 // ----------------------------------------------------------------------------
       
   638 // CSmtpMtmUi::CloseL()
       
   639 // ----------------------------------------------------------------------------
       
   640 CMsvOperation* CSmtpMtmUi::CloseL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
       
   641     {
       
   642     IMUM_CONTEXT( CSmtpMtmUi::CloseL, 0, KImumMtmLog );
       
   643     IMUM_IN();
       
   644 
       
   645     // Context is irrelevant.
       
   646     __ASSERT_ALWAYS(aSelection.Count(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiEmptySelection));
       
   647     iBaseMtm.Entry().SetEntryL(aSelection.At(0));
       
   648     IMUM_OUT();
       
   649     return CloseL(aStatus);
       
   650     }
       
   651 
       
   652 // ----------------------------------------------------------------------------
       
   653 // CSmtpMtmUi::EditL()
       
   654 // ----------------------------------------------------------------------------
       
   655 CMsvOperation* CSmtpMtmUi::EditL(TRequestStatus& aStatus)
       
   656     {
       
   657     IMUM_CONTEXT( CSmtpMtmUi::EditL, 0, KImumMtmLog );
       
   658     IMUM_IN();
       
   659 
       
   660     // Context is entry to edit.
       
   661     __ASSERT_ALWAYS(iBaseMtm.Entry().Entry().iMtm==Type(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiWrongMtm));
       
   662     __ASSERT_DEBUG(iBaseMtm.Entry().Entry().iType!=KUidMsvFolderEntry, User::Panic(KImumMtmUiPanic, ESmtpMtmUiFoldersNotSupported));
       
   663 
       
   664     switch (iBaseMtm.Entry().Entry().iType.iUid)
       
   665         {
       
   666     case KUidMsvMessageEntryValue:
       
   667         IMUM_OUT();
       
   668         return LaunchEditorApplicationL(aStatus, EFalse, EFalse, iBaseMtm.Entry().Session() );
       
   669         //break;    // Unreachable
       
   670     case KUidMsvServiceEntryValue:
       
   671         IMUM_OUT();
       
   672         return LaunchSettingsDialogL(aStatus);
       
   673         //break;    // Unreachable
       
   674     default:
       
   675         User::Leave(KErrNotSupported);
       
   676         break;
       
   677         };
       
   678     IMUM_OUT();
       
   679     return NULL;    // Unreachable in practice.
       
   680     }
       
   681 
       
   682 // ----------------------------------------------------------------------------
       
   683 // CSmtpMtmUi::EditL()
       
   684 // ----------------------------------------------------------------------------
       
   685 CMsvOperation* CSmtpMtmUi::EditL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
       
   686     {
       
   687     IMUM_CONTEXT( CSmtpMtmUi::EditL, 0, KImumMtmLog );
       
   688     IMUM_IN();
       
   689 
       
   690     // Context is irrelevant.
       
   691     __ASSERT_ALWAYS(aSelection.Count(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiEmptySelection));
       
   692     iBaseMtm.Entry().SetEntryL(aSelection[0]);
       
   693     IMUM_OUT();
       
   694     return EditL(aStatus);
       
   695     }
       
   696 
       
   697 // ----------------------------------------------------------------------------
       
   698 // CSmtpMtmUi::ViewL()
       
   699 // ----------------------------------------------------------------------------
       
   700 CMsvOperation* CSmtpMtmUi::ViewL(TRequestStatus& aStatus)
       
   701     {
       
   702     IMUM_CONTEXT( CSmtpMtmUi::ViewL, 0, KImumMtmLog );
       
   703     IMUM_IN();
       
   704 
       
   705     // Context is message to view.
       
   706     __ASSERT_ALWAYS(iBaseMtm.Entry().Entry().iMtm==Type(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiWrongMtm));
       
   707     __ASSERT_ALWAYS(iBaseMtm.Entry().Entry().iType!=KUidMsvFolderEntry, User::Panic(KImumMtmUiPanic, ESmtpMtmUiFoldersNotSupported));
       
   708 
       
   709     IMUM_OUT();
       
   710     return LaunchEditorApplicationL(aStatus, ETrue, EFalse, Session());
       
   711     }
       
   712 
       
   713 // ----------------------------------------------------------------------------
       
   714 // CSmtpMtmUi::ViewL()
       
   715 // ----------------------------------------------------------------------------
       
   716 CMsvOperation* CSmtpMtmUi::ViewL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
       
   717     {
       
   718     IMUM_CONTEXT( CSmtpMtmUi::ViewL, 0, KImumMtmLog );
       
   719     IMUM_IN();
       
   720 
       
   721     // Context is irrelevant.
       
   722     __ASSERT_ALWAYS(aSelection.Count(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiEmptySelection));
       
   723     iBaseMtm.Entry().SetEntryL(aSelection[0]);
       
   724     IMUM_OUT();
       
   725     return ViewL(aStatus);
       
   726     }
       
   727 
       
   728 // ----------------------------------------------------------------------------
       
   729 // CSmtpMtmUi::CancelL()
       
   730 // ----------------------------------------------------------------------------
       
   731 CMsvOperation* CSmtpMtmUi::CancelL(TRequestStatus& aStatus, const CMsvEntrySelection& aSelection)
       
   732     {
       
   733     IMUM_CONTEXT( CSmtpMtmUi::CancelL, 0, KImumMtmLog );
       
   734     IMUM_IN();
       
   735 
       
   736     // Context is irrelevant.
       
   737     __ASSERT_ALWAYS(aSelection.Count(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiEmptySelection));
       
   738     IMUM_OUT();
       
   739     return CSmtpCancelSendingOp::NewL( *iMailboxApi, aStatus, aSelection.CopyL());
       
   740     }
       
   741 
       
   742 // ----------------------------------------------------------------------------
       
   743 // CSmtpMtmUi::CopyFromL()
       
   744 // ----------------------------------------------------------------------------
       
   745 CMsvOperation* CSmtpMtmUi::CopyFromL(const CMsvEntrySelection& /*aSelection*/, TMsvId /*aTargetId*/, TRequestStatus& /*aStatus*/)
       
   746     {
       
   747     IMUM_CONTEXT( CSmtpMtmUi::CopyFromL, 0, KImumMtmLog );
       
   748     IMUM_IN();
       
   749 
       
   750     User::Panic(KImumMtmUiPanic, ESmtpMtmUiCannotCopyOrMoveFromSmtpServiceOrFolder);
       
   751     IMUM_OUT();
       
   752     return NULL;
       
   753     }
       
   754 
       
   755 // ----------------------------------------------------------------------------
       
   756 // CSmtpMtmUi::MoveFromL()
       
   757 // ----------------------------------------------------------------------------
       
   758 CMsvOperation* CSmtpMtmUi::MoveFromL(const CMsvEntrySelection& /*aSelection*/, TMsvId /*aTargetId*/, TRequestStatus& /*aStatus*/)
       
   759     {
       
   760     IMUM_CONTEXT( CSmtpMtmUi::MoveFromL, 0, KImumMtmLog );
       
   761     IMUM_IN();
       
   762 
       
   763     User::Panic(KImumMtmUiPanic, ESmtpMtmUiCannotCopyOrMoveFromSmtpServiceOrFolder);
       
   764     IMUM_OUT();
       
   765     return NULL;
       
   766     }
       
   767 
       
   768 // ----------------------------------------------------------------------------
       
   769 // MoveToL()
       
   770 // ----------------------------------------------------------------------------
       
   771 CMsvOperation* CSmtpMtmUi::MoveToL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus)
       
   772     {
       
   773     IMUM_CONTEXT( CSmtpMtmUi::MoveToL, 0, KImumMtmLog );
       
   774     IMUM_IN();
       
   775     IMUM_OUT();
       
   776 
       
   777     return DoCopyMoveToL(aSelection, aStatus, ETrue);
       
   778     }
       
   779 
       
   780 // ----------------------------------------------------------------------------
       
   781 // CSmtpMtmUi::CopyToL()
       
   782 // ----------------------------------------------------------------------------
       
   783 CMsvOperation* CSmtpMtmUi::CopyToL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus)
       
   784     {
       
   785     IMUM_CONTEXT( CSmtpMtmUi::CopyToL, 0, KImumMtmLog );
       
   786     IMUM_IN();
       
   787     IMUM_OUT();
       
   788 
       
   789     return DoCopyMoveToL(aSelection, aStatus, EFalse);
       
   790     }
       
   791 
       
   792 // ----------------------------------------------------------------------------
       
   793 // CSmtpMtmUi::DoCopyMoveToL()
       
   794 // ----------------------------------------------------------------------------
       
   795 CMsvOperation* CSmtpMtmUi::DoCopyMoveToL(const CMsvEntrySelection& aSelection, TRequestStatus& aStatus, TBool aMoving)
       
   796     {
       
   797     IMUM_CONTEXT( CSmtpMtmUi::DoCopyMoveToL, 0, KImumMtmLog );
       
   798     IMUM_IN();
       
   799 
       
   800     // Context is service to send to.
       
   801     const TMsvEntry& context=BaseMtm().Entry().Entry();
       
   802     __ASSERT_ALWAYS(context.iMtm==Type(), User::Panic(KImumMtmUiPanic, ESmtpMtmUiWrongMtm));
       
   803     __ASSERT_ALWAYS(context.iType==KUidMsvServiceEntry, User::Panic(KImumMtmUiPanic, ESmtpMtmUiNotAService));
       
   804 
       
   805     //smtp auth fix 23092002
       
   806     CheckAndRestoreSmtpUserAndPasswordL( BaseMtm().Entry().EntryId() );
       
   807     //fix end
       
   808 
       
   809     TInt cc = aSelection.Count();
       
   810     if(!cc)
       
   811         {
       
   812         // Nothing to do.
       
   813         return CMsvCompletedOperation::NewL(Session(), Type(), KNullDesC8, KMsvLocalServiceIndexEntryId, aStatus);
       
   814         }
       
   815     // Iterate entries in selection and check them.
       
   816     TBool changed = EFalse;
       
   817     TMsvEntry entry;
       
   818     TMsvId id = KMsvNullIndexEntryId;
       
   819     User::LeaveIfError(Session().GetEntry(aSelection[0], id, entry));
       
   820     CMsvEntry* parent = Session().GetEntryL(entry.Parent());
       
   821     CleanupStack::PushL(parent);
       
   822     CMsvEntry* centry = Session().GetEntryL(entry.Id());
       
   823     CleanupStack::PushL(centry);
       
   824     while(cc--)
       
   825         {
       
   826         id = aSelection[cc];
       
   827         entry = parent->ChildDataL(id);
       
   828         if(entry.iServiceId != context.Id())
       
   829             {
       
   830             // If service ID does not match context, set to context ID.
       
   831             entry.iServiceId = context.Id();
       
   832             changed = ETrue;
       
   833             }
       
   834         if(entry.SendingState() == KMsvSendStateSuspended)
       
   835             {
       
   836             // If the entry is suspended, set it to scheduled, or it will not be sent.
       
   837             entry.SetSendingState(KMsvSendStateWaiting);
       
   838             changed = ETrue;
       
   839             }
       
   840         if(changed)
       
   841             {
       
   842             if(centry->EntryId() != entry.Id())
       
   843                 {
       
   844                 centry->SetEntryL(entry.Id());
       
   845                 }
       
   846             centry->ChangeL(entry);
       
   847             changed = EFalse;
       
   848             }
       
   849         }
       
   850     CleanupStack::PopAndDestroy(2, parent); // CSI: 47 # centry, parent.
       
   851 
       
   852     // Create send operation.
       
   853     CMsvProgressReporterOperation* reporter =
       
   854         CMsvProgressReporterOperation::NewL(
       
   855             EFalse,
       
   856             ETrue,
       
   857             Session(),
       
   858             aStatus,
       
   859             EMbmAvkonQgn_note_mail );
       
   860     CleanupStack::PushL(reporter);
       
   861     CMsvOperation* op = CSmtpCopyMoveOp::NewL(*iMailboxApi, reporter->RequestStatus(),
       
   862         *reporter, context.Id(), aSelection, aMoving);
       
   863     reporter->SetOperationL(op); // Takes immediate ownership
       
   864     CleanupStack::Pop();    // reporter
       
   865     IMUM_OUT();
       
   866     return reporter;
       
   867     }
       
   868 
       
   869 // ----------------------------------------------------------------------------
       
   870 // CSmtpMtmUi::DisplayProgressSummary()
       
   871 // ----------------------------------------------------------------------------
       
   872 TInt CSmtpMtmUi::DisplayProgressSummary(const TDesC8& aProgress) const
       
   873     {
       
   874     IMUM_CONTEXT( CSmtpMtmUi::DisplayProgressSummary, 0, KImumMtmLog );
       
   875     IMUM_IN();
       
   876 
       
   877     // Context is irrelevent.
       
   878     if( (!aProgress.Length()) || (aProgress.Size() == sizeof(TMsvLocalOperationProgress)) )
       
   879         {
       
   880         IMUM_OUT();
       
   881         return KErrCancel;
       
   882         }
       
   883 
       
   884     if( aProgress.Size() == sizeof(TMsvId) )
       
   885         {
       
   886         // reason for this is that for CImEmailOperation did not fill iMtm correctly (it was always 0)
       
   887         // and that caused that in mce app's CMceUi::DoOperationCompletedL leaves
       
   888         // when trying to create mtm for displaying progress summary and execution
       
   889         // never came here. Now CImEmailOperation sets its iMtm correctly and
       
   890         // now CMceUi::DoOperationCompletedL works correcly and execution comes here.
       
   891         // problem now is that how to make difference between imum's internal progress
       
   892         // and CImEmailOperation progress since CImEmailOperation's progress is just
       
   893         // TMsvId of the created mail message. This needs to be solved.
       
   894         IMUM_OUT();
       
   895         return KErrNone;
       
   896         }
       
   897 
       
   898 
       
   899     // First element of progress should be identifier of the operation type
       
   900     TPckgC<TInt> progressType(0);
       
   901     progressType.Set(aProgress.Left(sizeof(TInt)));
       
   902     if(progressType()==ESmtpMtmUiEditing)
       
   903         {
       
   904         IMUM_OUT();
       
   905         return KErrNone;
       
   906         }
       
   907 
       
   908     // SMTP MTM operations
       
   909     __ASSERT_ALWAYS(aProgress.Size() == sizeof(TImSmtpProgress), User::Panic(KImumMtmUiPanic, ESmtpMtmUiBadProgress));
       
   910     TPckgBuf<TImSmtpProgress> paramPack;
       
   911     paramPack.Copy(aProgress);
       
   912     const TImSmtpProgress& progress = paramPack();
       
   913     TInt err = progress.Error();
       
   914     if( err != KErrNone && err != KErrCancel && err != KErrGeneral &&
       
   915         err != KErrEtelBusyDetected && err != KErrAbort )
       
   916         {
       
   917         if( err == KErrGprsServicesNotAllowed )
       
   918             {
       
   919             err = KImskErrorActiveSettingIsDifferent;
       
   920             }
       
   921         TRAP_IGNORE( iErrorResolver->ShowGlobalErrorNoteL( err ) );
       
   922         }
       
   923     IMUM_OUT();
       
   924     return err;
       
   925     }
       
   926 
       
   927 // ----------------------------------------------------------------------------
       
   928 // CSmtpMtmUi::GetProgress()
       
   929 // ----------------------------------------------------------------------------
       
   930 TInt CSmtpMtmUi::GetProgress(
       
   931     const TDesC8& aProgress,
       
   932     TBuf<EProgressStringMaxLen>& aReturnString,
       
   933     TInt& aTotalEntryCount,
       
   934     TInt& aEntriesDone,
       
   935     TInt& aCurrentEntrySize,
       
   936     TInt& aCurrentBytesTrans) const
       
   937     {
       
   938     IMUM_CONTEXT( CSmtpMtmUi::GetProgress, 0, KImumMtmLog );
       
   939     IMUM_IN();
       
   940 
       
   941     aEntriesDone=0;
       
   942     aTotalEntryCount=0;
       
   943     aCurrentBytesTrans=0;
       
   944     aCurrentEntrySize=0;
       
   945     aReturnString.Zero();
       
   946 
       
   947     if( (!aProgress.Length()) ||
       
   948         (aProgress.Size() == sizeof(TMsvLocalOperationProgress)) )
       
   949         {
       
   950         IMUM_OUT();
       
   951         return KErrNone;
       
   952         }
       
   953 
       
   954     // First element of progress should be identifier of the operation type
       
   955     TPckgC<TInt> type( 0 );
       
   956     type.Set( aProgress.Left( sizeof( TInt ) ) );
       
   957     switch ( type() )
       
   958         {
       
   959         case ESmtpMtmUiEditing:
       
   960             IMUM_OUT();
       
   961             // Editor operation
       
   962             return KErrNone;
       
   963 
       
   964         case EUiProgTypeConnecting:
       
   965             IMUM_OUT();
       
   966             // Connecting progress
       
   967             return GetConnectionProgress(aProgress, aReturnString);
       
   968 
       
   969         default:
       
   970             break;
       
   971         }
       
   972 
       
   973     // SMTP MTM operations
       
   974     __ASSERT_ALWAYS(aProgress.Size() == sizeof(TImSmtpProgress), User::Panic(KImumMtmUiPanic, ESmtpMtmUiBadProgress));
       
   975     TPckgBuf<TImSmtpProgress> paramPack;
       
   976     paramPack.Copy(aProgress);
       
   977     const TImSmtpProgress& progress = paramPack();
       
   978 
       
   979     aTotalEntryCount = progress.SendTotal();
       
   980     aEntriesDone = Min(aTotalEntryCount, progress.MsgNo()+1);
       
   981     aCurrentEntrySize = progress.iSendFileProgress.iBytesToSend;
       
   982     aCurrentBytesTrans = progress.iSendFileProgress.iBytesSent;
       
   983 
       
   984     TInt err = progress.Error();
       
   985     switch(progress.Status())
       
   986         {
       
   987         case EMsgOutboxProgressSending:
       
   988             {
       
   989             TInt resId = (aTotalEntryCount == 1) ? (R_SMTP_SENDING_PROGRESS) : (R_SMTP_SENDING_PROGRESS_MULTIPLE);
       
   990             StringLoader::Load( aReturnString, resId, iCoeEnv);
       
   991             if ( aTotalEntryCount>1 )
       
   992                 {
       
   993                 TBuf<EProgressStringMaxLen> tempBuffer;
       
   994                 StringLoader::Format(
       
   995                     tempBuffer,
       
   996                     aReturnString,
       
   997                     KImumEntriesDoneReplaceIndex,
       
   998                     aEntriesDone );
       
   999                 StringLoader::Format(
       
  1000                     aReturnString,
       
  1001                     tempBuffer,
       
  1002                     KImumTotalEntriesReplaceIndex,
       
  1003                     aTotalEntryCount );
       
  1004                 }
       
  1005             err = progress.Error();
       
  1006             }
       
  1007             break;
       
  1008         case EMsgOutboxProgressWaiting:
       
  1009         case EMsgOutboxProgressConnecting:
       
  1010         default:
       
  1011             // Should not get any other statuses, get UI connection progress instead.
       
  1012             aReturnString.Zero();
       
  1013             break;
       
  1014         }
       
  1015     IMUM_OUT();
       
  1016     return err;
       
  1017     }
       
  1018 
       
  1019 // ----------------------------------------------------------------------------
       
  1020 // CSmtpMtmUi::GetConnectionProgress()
       
  1021 // ----------------------------------------------------------------------------
       
  1022 TInt CSmtpMtmUi::GetConnectionProgress(const TDesC8& aProgress, TBuf<EProgressStringMaxLen>& aReturnString) const
       
  1023     {
       
  1024     IMUM_CONTEXT( CSmtpMtmUi::GetConnectionProgress, 0, KImumMtmLog );
       
  1025     IMUM_IN();
       
  1026 
       
  1027     __ASSERT_ALWAYS(aProgress.Size() == sizeof(TMsvEmailConnectionProgress), User::Panic(KImumMtmUiPanic, ESmtpMtmUiBadProgress));
       
  1028     TPckgBuf<TMsvEmailConnectionProgress> paramPack;
       
  1029     paramPack.Copy(aProgress);
       
  1030     const TMsvEmailConnectionProgress& connectProgress = paramPack();
       
  1031 
       
  1032     MsvEmailMtmUiUtils::CreateConnectingToText( aReturnString,
       
  1033         Session(), connectProgress.iService );
       
  1034     IMUM_OUT();
       
  1035 
       
  1036     return KErrNone;
       
  1037     }
       
  1038 
       
  1039 // ----------------------------------------------------------------------------
       
  1040 // CSmtpMtmUi::DoExitL()
       
  1041 // ----------------------------------------------------------------------------
       
  1042 CMsvOperation* CSmtpMtmUi::DoExitL(
       
  1043     TRequestStatus& aStatus,
       
  1044     const TBool aIssueQuit )
       
  1045     {
       
  1046     IMUM_CONTEXT( CSmtpMtmUi::DoExitL, 0, KImumMtmLog );
       
  1047     IMUM_IN();
       
  1048 
       
  1049     TInt err = aIssueQuit ? EEikCmdExit : EEikCmdCanceled;
       
  1050     IMUM_OUT();
       
  1051 
       
  1052     // Nothing to do, so return a completed operation.
       
  1053     return CMsvCompletedOperation::NewL(
       
  1054         Session(), Type(), KNullDesC8,
       
  1055         KMsvLocalServiceIndexEntryId, aStatus, err );
       
  1056     }
       
  1057 
       
  1058 // ----------------------------------------------------------------------------
       
  1059 // CSmtpMtmUi::LaunchEditorApplicationL()
       
  1060 // ----------------------------------------------------------------------------
       
  1061 CMsvOperation* CSmtpMtmUi::LaunchEditorApplicationL(
       
  1062     TRequestStatus& aStatus,
       
  1063     TBool aReadOnly,
       
  1064     TBool aNewMsg,
       
  1065     CMsvSession& aSession,
       
  1066     TMsvId aNewMsgServiceId)
       
  1067     {
       
  1068     IMUM_CONTEXT( CSmtpMtmUi::LaunchEditorApplicationL, 0, KImumMtmLog );
       
  1069     IMUM_IN();
       
  1070 
       
  1071     // Context is irrelevant.
       
  1072 
       
  1073     // Create the parameters necessary for the editor
       
  1074     TEditorParameters editorParams;
       
  1075     TMsvEntry entry = BaseMtm().Entry().Entry();
       
  1076     if ( entry.Parent() != KMsvDraftEntryId )
       
  1077         {
       
  1078         aReadOnly = ETrue;
       
  1079         }
       
  1080     if (aReadOnly)
       
  1081         {
       
  1082         editorParams.iFlags|=EMsgReadOnly;
       
  1083         }
       
  1084 
       
  1085     if ( !aReadOnly )
       
  1086         {
       
  1087         // we are opening the editor, check that there is at least one mail service defined
       
  1088         TMsvId serviceId = entry.iServiceId;
       
  1089         TSmtpMtmUiCreateNewServiceParameters aSaveParameters;
       
  1090 
       
  1091         if ( !CheckMailboxesBeforeEditL( serviceId, aSaveParameters ) )
       
  1092             {
       
  1093             if ( aSaveParameters == ESmtpMtmUiCreateNewServiceExit )
       
  1094                 {
       
  1095                 return CMsvCompletedOperation::NewL(Session(), Type(), KNullDesC8, KMsvLocalServiceIndexEntryId, aStatus, EEikCmdExit );
       
  1096                 }
       
  1097             else
       
  1098                 {
       
  1099                 return CMsvCompletedOperation::NewL(Session(), Type(), KNullDesC8, KMsvLocalServiceIndexEntryId, aStatus);
       
  1100                 }
       
  1101             }
       
  1102         if ( serviceId != entry.iServiceId )
       
  1103             {
       
  1104             // service has been changed, change it to the entry too...
       
  1105             entry.iServiceId = serviceId;
       
  1106             BaseMtm().Entry().ChangeL( entry );
       
  1107             }
       
  1108         }
       
  1109 
       
  1110     if (aNewMsg)
       
  1111         {
       
  1112         // Creating new message. The EMsgCreateMessageToService flag specifies that
       
  1113         // editorParams.iId is the SMTP service to use for the message.
       
  1114         __ASSERT_DEBUG(aNewMsgServiceId != KMsvNullIndexEntryIdValue, User::Panic(KImumMtmUiPanic, ESmtpMtmUiNullNewMsgService));
       
  1115         editorParams.iFlags |= EMsgCreateMessageToService;
       
  1116         editorParams.iId = aNewMsgServiceId;
       
  1117         }
       
  1118     else
       
  1119         {
       
  1120         editorParams.iId=BaseMtm().Entry().EntryId();
       
  1121         }
       
  1122 
       
  1123     //
       
  1124     // --- This is a MTM UI operation only, so make an appropriate progress package ---
       
  1125     // --- Editor progress is blank, except for the opreation identifier ---
       
  1126     TPckgC<TInt> paramPack(ESmtpMtmUiEditing);
       
  1127     HBufC* appName = NULL;
       
  1128     if(aReadOnly)
       
  1129         {
       
  1130         if(!iViewerFilename)
       
  1131             ResolveViewerFileNameL();
       
  1132         appName = iViewerFilename;
       
  1133         }
       
  1134     else
       
  1135         {
       
  1136         if(!iEditorFilename)
       
  1137             ResolveEditorFileNameL();
       
  1138         appName = iEditorFilename;
       
  1139         }
       
  1140 
       
  1141     const TUint preferences = Preferences();
       
  1142     editorParams.iFlags &= ~(EMsgLaunchEditorEmbedded | EMsgLaunchEditorThenWait);
       
  1143     if(preferences & EMtmUiFlagEditorPreferEmbedded)
       
  1144         {
       
  1145         editorParams.iFlags |= EMsgLaunchEditorEmbedded;
       
  1146         }
       
  1147     if(!(preferences & EMtmUiFlagEditorNoWaitForExit))
       
  1148         {
       
  1149         editorParams.iFlags |= EMsgLaunchEditorThenWait;
       
  1150         }
       
  1151     IMUM_OUT();
       
  1152 
       
  1153     return MsgEditorLauncher::LaunchEditorApplicationL(
       
  1154         aSession, Type(), aStatus, editorParams, *appName, paramPack );
       
  1155     }
       
  1156 
       
  1157 // ----------------------------------------------------------------------------
       
  1158 // CSmtpMtmUi::HandleNoAccountsL()
       
  1159 // ----------------------------------------------------------------------------
       
  1160 TMsvId CSmtpMtmUi::HandleNoAccountsL(TSmtpMtmUiCreateNewServiceParameters& aSaveParameters )
       
  1161     {
       
  1162     IMUM_CONTEXT( CSmtpMtmUi::HandleNoAccountsL, 0, KImumMtmLog );
       
  1163     IMUM_IN();
       
  1164 
       
  1165     // Context is irrelevant.
       
  1166     if ( !CIMSSettingsNoteUi::ShowQueryL(
       
  1167         R_SMTP_CREATE_NEED_MAILBOX_TITLE, R_EMAIL_CONFIRMATION_QUERY ) )
       
  1168         {
       
  1169         // User cancelled.
       
  1170         aSaveParameters = ESmtpMtmUiCreateNewServiceNotCreated;
       
  1171         return KMsvNullIndexEntryId;
       
  1172         }
       
  1173 
       
  1174     //Show empty navipane
       
  1175     CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
       
  1176     CAknNavigationControlContainer* naviPane = static_cast<CAknNavigationControlContainer*>(
       
  1177         sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
  1178     CAknNavigationDecorator* naviDecorator = naviPane->CreateNavigationLabelL();
       
  1179     CleanupStack::PushL(naviDecorator);
       
  1180     naviPane->PushL( *naviDecorator );
       
  1181 
       
  1182     TMsvEntry nentry;
       
  1183     nentry.iMtm = Type();
       
  1184     nentry.iType = KUidMsvServiceEntry;
       
  1185     nentry.iDate.HomeTime();
       
  1186     nentry.iServiceId = KMsvNullIndexEntryId;
       
  1187 
       
  1188     // Note that we don't pre-create a message for this account here since we will
       
  1189     // be launching an editor immediately afterwards.
       
  1190     IMUM_OUT();
       
  1191 
       
  1192     // Newly created service will be the default.
       
  1193     TMsvId serviceId = CreateNewServiceL(nentry, aSaveParameters);
       
  1194     //Remove empty navipane
       
  1195     naviPane->Pop( naviDecorator );
       
  1196     CleanupStack::PopAndDestroy( naviDecorator );
       
  1197     return serviceId;
       
  1198     }
       
  1199 
       
  1200 // ----------------------------------------------------------------------------
       
  1201 // CSmtpMtmUi::PrepareCommandL()
       
  1202 // ----------------------------------------------------------------------------
       
  1203 //
       
  1204 CMsvOperation* CSmtpMtmUi::PrepareCommandL(
       
  1205     TEditorParameters& aParameters,
       
  1206     TMsvId aDestination,
       
  1207     TMsvPartList aPartlist,
       
  1208     TRequestStatus& aCompletionStatus )
       
  1209     {
       
  1210     IMUM_CONTEXT( CSmtpMtmUi::PrepareCommandL, 0, KImumMtmLog );
       
  1211     IMUM_IN();
       
  1212 
       
  1213     const TMsvEntry& entry = BaseMtm().Entry().Entry();
       
  1214 
       
  1215     if ( entry.iType.iUid != KUidMsvMessageEntryValue )
       
  1216         {
       
  1217         User::Leave( KErrNotSupported );
       
  1218         }
       
  1219 
       
  1220     // Set editor name
       
  1221     HBufC* appName = NULL;
       
  1222     if(!iEditorFilename)
       
  1223         {
       
  1224         ResolveEditorFileNameL();
       
  1225         }
       
  1226     appName = iEditorFilename;
       
  1227 
       
  1228     // Set params
       
  1229     aParameters.iId=entry.Id();
       
  1230     aParameters.iPartList = aPartlist;
       
  1231     aParameters.iDestinationFolderId = aDestination;
       
  1232 
       
  1233     // Mark as read
       
  1234     ChangeUnreadFlagL( entry.Id(), EFalse );
       
  1235 
       
  1236     // Handle preferences
       
  1237     const TUint preferences = Preferences();
       
  1238     aParameters.iFlags &=
       
  1239         ~( EMsgLaunchEditorEmbedded | EMsgLaunchEditorThenWait );
       
  1240 
       
  1241     if ( preferences & EMtmUiFlagEditorPreferEmbedded )
       
  1242         {
       
  1243         aParameters.iFlags |= EMsgLaunchEditorEmbedded;
       
  1244         }
       
  1245     if ( !( preferences & EMtmUiFlagEditorNoWaitForExit ) )
       
  1246         {
       
  1247         aParameters.iFlags |= EMsgLaunchEditorThenWait;
       
  1248         }
       
  1249 
       
  1250     // Launch editor
       
  1251     TPckgC<TInt> paramPack( ESmtpMtmUiEditing );
       
  1252     IMUM_OUT();
       
  1253     return MsgEditorLauncher::LaunchEditorApplicationL(
       
  1254         Session(), Type(), aCompletionStatus, aParameters,
       
  1255         *appName, paramPack);
       
  1256     }
       
  1257 
       
  1258 
       
  1259 // ----------------------------------------------------------------------------
       
  1260 // CSmtpMtmUi::ReplyL()
       
  1261 // ----------------------------------------------------------------------------
       
  1262 //
       
  1263 CMsvOperation* CSmtpMtmUi::ReplyL(
       
  1264     TMsvId aDestination,
       
  1265     TMsvPartList aPartlist,
       
  1266     TRequestStatus& aCompletionStatus )
       
  1267     {
       
  1268     IMUM_CONTEXT( CSmtpMtmUi::ReplyL, 0, KImumMtmLog );
       
  1269     IMUM_IN();
       
  1270 
       
  1271     TEditorParameters editorParams;
       
  1272     editorParams.iFlags |= EMsgReplyToMessageAll;
       
  1273     IMUM_OUT();
       
  1274 
       
  1275     return PrepareCommandL(
       
  1276         editorParams, aDestination, aPartlist, aCompletionStatus );
       
  1277     }
       
  1278 
       
  1279 // ----------------------------------------------------------------------------
       
  1280 // CSmtpMtmUi::ForwardL()
       
  1281 // ----------------------------------------------------------------------------
       
  1282 //
       
  1283 CMsvOperation* CSmtpMtmUi::ForwardL(
       
  1284     TMsvId aDestination,
       
  1285     TMsvPartList aPartlist,
       
  1286     TRequestStatus& aCompletionStatus)
       
  1287     {
       
  1288     IMUM_CONTEXT( CSmtpMtmUi::ForwardL, 0, KImumMtmLog );
       
  1289     IMUM_IN();
       
  1290 
       
  1291     TEditorParameters editorParams;
       
  1292     editorParams.iFlags |= EMsgForwardMessage;
       
  1293     IMUM_OUT();
       
  1294 
       
  1295     return PrepareCommandL(
       
  1296         editorParams, aDestination, aPartlist, aCompletionStatus );
       
  1297     }
       
  1298 
       
  1299 // ----------------------------------------------------------------------------
       
  1300 // CSmtpMtmUi::GetMailboxNameL()
       
  1301 // ----------------------------------------------------------------------------
       
  1302 HBufC* CSmtpMtmUi::GetMailboxNameL(TMsvId aServiceId) const
       
  1303     {
       
  1304     IMUM_CONTEXT( CSmtpMtmUi::GetMailboxNameL, 0, KImumMtmLog );
       
  1305     IMUM_IN();
       
  1306 
       
  1307     TMsvEntry serviceEntry =
       
  1308         iMailboxApi->MailboxUtilitiesL().GetMailboxEntryL( aServiceId );
       
  1309     IMUM_OUT();
       
  1310     return serviceEntry.iDetails.AllocL();
       
  1311     }
       
  1312 
       
  1313 // ----------------------------------------------------------------------------
       
  1314 // CSmtpMtmUi::CheckMailboxesBeforeEditL()
       
  1315 // ----------------------------------------------------------------------------
       
  1316 TBool CSmtpMtmUi::CheckMailboxesBeforeEditL( TMsvId& aServiceId, TSmtpMtmUiCreateNewServiceParameters& aSaveParameters )
       
  1317     {
       
  1318     IMUM_CONTEXT( CSmtpMtmUi::CheckMailboxesBeforeEditL, 0, KImumMtmLog );
       
  1319     IMUM_IN();
       
  1320 
       
  1321     // checks if aServiceId exists and if not checks that there is default service and
       
  1322     // if no services, then asks to create one
       
  1323     TMsvEntry serviceEntry;
       
  1324     TMsvId serviceId;
       
  1325     aSaveParameters = ESmtpMtmUiCreateNewServiceNotCreated;
       
  1326     if ( Session().GetEntry( aServiceId, serviceId, serviceEntry ) == KErrNone )
       
  1327         {
       
  1328         IMUM_OUT();
       
  1329         // given service exists
       
  1330         return ETrue;
       
  1331         }
       
  1332 
       
  1333     // given service does not exists, check if there is default one:
       
  1334     serviceId = MsvUiServiceUtilitiesInternal::DefaultServiceForMTML(
       
  1335         Session(),
       
  1336         Type(),
       
  1337         ETrue );
       
  1338 
       
  1339     if ( serviceId != KMsvUnknownServiceIndexEntryId )
       
  1340         {
       
  1341         // default exists!
       
  1342         aServiceId = serviceId;
       
  1343         IMUM_OUT();
       
  1344         return ETrue;
       
  1345         }
       
  1346 
       
  1347     // no mailboxes, ask to create one
       
  1348     serviceId = HandleNoAccountsL( aSaveParameters );
       
  1349 
       
  1350     if ( serviceId != KMsvUnknownServiceIndexEntryId &&
       
  1351          serviceId != KMsvNullIndexEntryId &&
       
  1352          aSaveParameters == ESmtpMtmUiCreateNewServiceSave )
       
  1353         {
       
  1354         aServiceId = serviceId;
       
  1355         IMUM_OUT();
       
  1356         return ETrue;
       
  1357         }
       
  1358     IMUM_OUT();
       
  1359     return EFalse;
       
  1360     }
       
  1361 
       
  1362 // ----------------------------------------------------------------------------
       
  1363 // CSmtpMtmUi::ChangeUnreadFlagL()
       
  1364 // ----------------------------------------------------------------------------
       
  1365 //
       
  1366 void CSmtpMtmUi::ChangeUnreadFlagL(
       
  1367     const TMsvId aEmailId,
       
  1368     const TBool aNewState )
       
  1369     {
       
  1370     IMUM_CONTEXT( CSmtpMtmUi::ChangeUnreadFlagL, 0, KImumMtmLog );
       
  1371     IMUM_IN();
       
  1372 
       
  1373     // Prepare the entry
       
  1374     CMsvEntry* entry = ( CMsvEntry::NewL(
       
  1375         *iMsvSession, aEmailId, TMsvSelectionOrdering() ) );
       
  1376     CleanupStack::PushL( entry );
       
  1377     TMsvEntry email = entry->Entry();
       
  1378 
       
  1379     // Set the unread flag
       
  1380     email.SetUnread( aNewState );
       
  1381     entry->ChangeL( email );
       
  1382 
       
  1383     CleanupStack::PopAndDestroy( entry );
       
  1384     entry = NULL;
       
  1385     IMUM_OUT();
       
  1386     }
       
  1387 
       
  1388 
       
  1389 // ----------------------------------------------------------------------------
       
  1390 // CSmtpMtmUi::LaunchSettingsDialogL
       
  1391 // ----------------------------------------------------------------------------
       
  1392 CMsvOperation* CSmtpMtmUi::LaunchSettingsDialogL(
       
  1393     TRequestStatus& aStatus )
       
  1394     {
       
  1395     IMUM_CONTEXT( CSmtpMtmUi::LaunchSettingsDialogL, 0, KImumMtmLog );
       
  1396     IMUM_IN();
       
  1397 
       
  1398     // Get the TMsvEntry for the service.
       
  1399     TMsvEntry msvEntry( BaseMtm().Entry().Entry() );
       
  1400     TMsvEntry rcvEntry = iUtils->GetMailboxEntryL( msvEntry.iRelatedId );
       
  1401 
       
  1402     // Do this earlies phase possible, to guarrentee there won't be any
       
  1403     // useless mailboxes around
       
  1404     iMailboxApi->HealthServicesL().CleanupUnhealthyMailboxes();
       
  1405 
       
  1406     TBool quit( EFalse );
       
  1407 
       
  1408     // Mailbox should not be connected when settings are edited
       
  1409     if ( !rcvEntry.Connected() ||
       
  1410         MsvEmailMtmUiUtils::DisconnectMailboxL( rcvEntry, Session() ) )
       
  1411         {
       
  1412         // Create and load email account
       
  1413         CImumInSettingsData* accountSettings =
       
  1414             iMailboxApi->MailboxServicesL().LoadMailboxSettingsL(
       
  1415                 msvEntry.Id() );
       
  1416         CleanupStack::PushL( accountSettings );
       
  1417 
       
  1418         // Create message for receiving protocol and send it to Always Online
       
  1419         TPckgBuf<TMsvId> param = msvEntry.iRelatedId;
       
  1420         TRAP_IGNORE( iAOClient.SendSinglePacketL(
       
  1421             EServerAPIEmailTurnOff, param ) );
       
  1422 
       
  1423         // Bring the settings to user
       
  1424         TImumUiExitCodes exitcode = EImumUiNoChanges;
       
  1425         CIMSSettingsUi::EditAccountL( exitcode, *accountSettings, *iMsvSession );
       
  1426 
       
  1427         // Create completed operation to finish the settings
       
  1428         quit = SettingsDialogExitL( *accountSettings, exitcode );
       
  1429 
       
  1430         // Get the emn setting
       
  1431         TInt emn = TImumDaSettings::EValueNotificationsOff;
       
  1432         accountSettings->GetAttr(
       
  1433             TImumDaSettings::EKeyAutoNotifications, emn );
       
  1434 
       
  1435         // Get the always online setting
       
  1436         TInt alwaysOnline = TImumDaSettings::EValueAutoOff;
       
  1437         accountSettings->GetAttr(
       
  1438             TImumDaSettings::EKeyAutoRetrieval, alwaysOnline );
       
  1439 
       
  1440         // Send turn on message to plugin, if either AO or EMN is turned on.
       
  1441         TAlwaysOnlineServerAPICommands command =
       
  1442             ( alwaysOnline != EMailAoOff || emn != EMailEmnOff ) ?
       
  1443             EServerAPIEmailTurnOn : EServerAPIEmailAgentRemove;
       
  1444 
       
  1445         CleanupStack::PopAndDestroy( accountSettings );
       
  1446         accountSettings = NULL;
       
  1447 
       
  1448         // Turn on the Always Online to current mailbox
       
  1449         iAOClient.SendSinglePacketL( command, param );
       
  1450         }
       
  1451     if ( quit )
       
  1452         {
       
  1453         // Delete precreated emails because they might contain old signature.
       
  1454         // Since we're in a hurry to exit, we don't recreate them.
       
  1455         iPreCreate->DeleteAllPreCreatedEmailsL( msvEntry.Id() );
       
  1456         
       
  1457         IMUM_OUT();
       
  1458         return DoExitL( aStatus, quit );
       
  1459         }
       
  1460     else
       
  1461         {
       
  1462         IMUM_OUT();
       
  1463         //Let's start the empty email creation
       
  1464         return CSmtpResetPreCreationOp::NewL(
       
  1465             Session(), aStatus, msvEntry.Id() );
       
  1466         }
       
  1467     }
       
  1468 
       
  1469 // ----------------------------------------------------------------------------
       
  1470 // CSmtpMtmUi::SettingsDialogExitL()
       
  1471 // ----------------------------------------------------------------------------
       
  1472 //
       
  1473 TBool CSmtpMtmUi::SettingsDialogExitL(
       
  1474     CImumInSettingsData& aSettings,
       
  1475     const TImumUiExitCodes& aExitCode )
       
  1476     {
       
  1477     IMUM_CONTEXT( CSmtpMtmUi::SettingsDialogExitL, 0, KImumMtmLog );
       
  1478     IMUM_IN();
       
  1479 
       
  1480     TBool quit = EFalse;
       
  1481     // Check the exit code
       
  1482     switch( aExitCode )
       
  1483         {
       
  1484         // Save the settings
       
  1485         case EImumUiSaveAndClose:
       
  1486             SettingsDialogExitSaveAndExitL( aSettings );
       
  1487             break;
       
  1488 
       
  1489         // Save the settings and quit
       
  1490         case EImumUiSaveAndExit:
       
  1491             SettingsDialogExitSaveAndExitL( aSettings );
       
  1492 
       
  1493         //lint -fallthrough
       
  1494         case EImumUiExit:
       
  1495             quit = ETrue;
       
  1496             break;
       
  1497 
       
  1498         default:
       
  1499             // Nothing to do
       
  1500             break;
       
  1501         }
       
  1502     IMUM_OUT();
       
  1503 
       
  1504     return quit;
       
  1505     }
       
  1506 
       
  1507 // ----------------------------------------------------------------------------
       
  1508 // CSmtpMtmUi::SettingsDialogExitSaveAndExitL()
       
  1509 // ----------------------------------------------------------------------------
       
  1510 //
       
  1511 void CSmtpMtmUi::SettingsDialogExitSaveAndExitL(
       
  1512     CImumInSettingsData& aSettings )
       
  1513     {
       
  1514     IMUM_CONTEXT( CSmtpMtmUi::SettingsDialogExitSaveAndExitL, 0, KImumMtmLog );
       
  1515     IMUM_IN();
       
  1516 
       
  1517     TInt ao = ImumMboxSettingsUtils::QuickGetL<TInt>(
       
  1518         aSettings, TImumDaSettings::EKeyAutoRetrieval );
       
  1519 
       
  1520     //restore original alwaysonline setting
       
  1521     if ( ImumMboxSettingsUtils::IsImap4( aSettings ) &&
       
  1522          ao == TImumDaSettings::EValueAutoOff )
       
  1523         {
       
  1524         //switching off, set default syncrate
       
  1525         aSettings.GetInSetL( 0 ).Reset( TImumInSettings::EKeySyncRate );
       
  1526         }
       
  1527 
       
  1528     // Save the settings
       
  1529     iMailboxApi->MailboxServicesL().SaveMailboxSettingsL( aSettings );
       
  1530     TMsvId id = ImumMboxSettingsUtils::QuickGetL<TMsvId>(
       
  1531         aSettings, TImumDaSettings::EKeyMailboxId, 0 );
       
  1532     IMUM_OUT();
       
  1533     }
       
  1534 
       
  1535 // ----------------------------------------------------------------------------
       
  1536 // CSmtpMtmUi::CreateNewServiceL
       
  1537 // ----------------------------------------------------------------------------
       
  1538 TMsvId CSmtpMtmUi::CreateNewServiceL(
       
  1539     const TMsvEntry& aEntry,
       
  1540     TSmtpMtmUiCreateNewServiceParameters& aSaveParameters )
       
  1541     {
       
  1542     IMUM_CONTEXT( CSmtpMtmUi::CreateNewServiceL, 0, KImumMtmLog );
       
  1543     IMUM_IN();
       
  1544 
       
  1545     // This function is called, when new account is to be created. The account
       
  1546     // is created, after user has succesfully finished the mailbox settings
       
  1547     // wizard.
       
  1548     // Do this earlies phase possible, to guarrentee there won't be any
       
  1549     // useless mailboxes around
       
  1550     iMailboxApi->HealthServicesL().CleanupUnhealthyMailboxes();
       
  1551 
       
  1552     // Make sure empty index has been given
       
  1553     if ( aEntry.iServiceId != KMsvNullIndexEntryId &&
       
  1554          aEntry.iServiceId != KMsvUnknownServiceIndexEntryId )
       
  1555         {
       
  1556         User::Leave( KErrUnknown );
       
  1557         }
       
  1558 
       
  1559     // Run the mailbox settings
       
  1560     TMsvId id = 0;
       
  1561     TImumUiExitCodes exitcode = EImumUiNoChanges;
       
  1562 
       
  1563     //Check if mail settings are locked
       
  1564     if( iMailboxApi->IsEmailFeatureSupportedL(
       
  1565         CImumInternalApi::EMailLockedSettings, R_QTN_SELEC_PROTECTED_SETTING ) )
       
  1566         {
       
  1567         aSaveParameters = ESmtpMtmUiCreateNewServiceNotCreated;
       
  1568         }
       
  1569     else
       
  1570         {
       
  1571         // Settings wizard fills in the settings object
       
  1572         CImumInSettingsData* accountSettings =
       
  1573             iMailboxApi->MailboxServicesL().CreateSettingsDataL( TUid::Uid( 0 ) );
       
  1574         CleanupStack::PushL( accountSettings );
       
  1575 
       
  1576         // lets clear the screen so that MCE is not seen on the background after wizard is
       
  1577         // finished and new view is activated
       
  1578         CAknLocalScreenClearer* localScreenClearer = 
       
  1579         	CAknLocalScreenClearer::NewLC( EFalse );
       
  1580         
       
  1581         // Add ScreenClearer to control stack
       
  1582         CEikonEnv::Static()->EikAppUi()->AddToStackL( 
       
  1583         	localScreenClearer, ECoeStackPriorityDefault, 
       
  1584         	ECoeStackFlagRefusesAllKeys|ECoeStackFlagRefusesFocus );
       
  1585         
       
  1586         // If application leaves make sure the screen clearer is removed
       
  1587         // from control stack.
       
  1588         CleanupStack::PushL( TCleanupItem( &ScreenClearerCleanupOperation, 
       
  1589         	localScreenClearer ) );
       
  1590         
       
  1591         
       
  1592          // Run wizard, run!
       
  1593         id = CIMSSettingsUi::NewAccountL(
       
  1594             exitcode, *accountSettings, *iMsvSession );
       
  1595         aSaveParameters = SaveParams( exitcode );
       
  1596 
       
  1597         TMsvEntry tentry;
       
  1598 
       
  1599         if( exitcode != EImumUiExtWizardCreated )
       
  1600         	{
       
  1601             if ( aSaveParameters == ESmtpMtmUiCreateNewServiceSave ||
       
  1602                 aSaveParameters == ESmtpMtmUiCreateNewServiceSaveAndExit )
       
  1603                 {
       
  1604                 id = iMailboxApi->MailboxServicesL().CreateMailboxL(
       
  1605                      *accountSettings );
       
  1606                 }
       
  1607         	}
       
  1608 
       
  1609         if ( exitcode == EImumUiExtWizardCreated ||
       
  1610             aSaveParameters == ESmtpMtmUiCreateNewServiceSave ||
       
  1611             aSaveParameters == ESmtpMtmUiCreateNewServiceSaveAndExit )
       
  1612             {
       
  1613             // check that there is actually a mailbox generated
       
  1614             if( iMailboxApi->MailboxUtilitiesL().IsMailbox( id ) )
       
  1615             	{
       
  1616                 tentry = iMailboxApi->MailboxUtilitiesL().GetMailboxEntryL( id );
       
  1617             	}
       
  1618             }
       
  1619 
       
  1620         // If view is activated when EImumUiExit, MCE will be reopened which
       
  1621         // is not desirable.
       
  1622         if ( exitcode != EImumUiExit )
       
  1623         	{
       
  1624 	        // check which view should be activated after wizard is run
       
  1625 	        if( tentry.iMtm.iUid == KErrNone )
       
  1626 	        	{
       
  1627 	        	/*
       
  1628 	        	 * No actual mailbox was defined, so activate MCE
       
  1629 	        	 * main view.
       
  1630 	        	 *
       
  1631 	        	 * This could be the case for example with webmail
       
  1632 	        	 * accounts that don't actually create an actual
       
  1633 	        	 * mailbox entry.
       
  1634 	        	 */
       
  1635 	            ActivateViewL( EImumUiNoChanges, id );
       
  1636 	        	}
       
  1637 			else
       
  1638 				{
       
  1639 				// POP/IMAP mailbox entry created, open correct view
       
  1640 				ActivateViewL( exitcode, tentry.iRelatedId );
       
  1641 				}
       
  1642         	}
       
  1643         
       
  1644         // Pop and destroy TCleanupItem, localScreenClearer and accountSettings
       
  1645         // TCleanupItem calls ScreenClearerCleanupOperation that removes 
       
  1646         // ScreenClearer from control stack.
       
  1647         CleanupStack::PopAndDestroy( 3, accountSettings );
       
  1648         localScreenClearer = NULL;
       
  1649         accountSettings = NULL;
       
  1650         }
       
  1651     IMUM_OUT();
       
  1652 
       
  1653     // Return the mailbox id
       
  1654     return id;
       
  1655     }
       
  1656 
       
  1657 // ---------------------------------------------------------------------------.
       
  1658 // CSmtpMtmUi::SaveParams()
       
  1659 // ---------------------------------------------------------------------------
       
  1660 //
       
  1661 CSmtpMtmUi::TSmtpMtmUiCreateNewServiceParameters CSmtpMtmUi::SaveParams(
       
  1662     const TImumUiExitCodes& aUiExitCode )
       
  1663     {
       
  1664     IMUM_CONTEXT( CSmtpMtmUi::TSmtpMtmUiCreateNewServiceParameters, 0, KImumMtmLog );
       
  1665     IMUM_IN();
       
  1666 
       
  1667     TSmtpMtmUiCreateNewServiceParameters params =
       
  1668         ESmtpMtmUiCreateNewServiceNotCreated;
       
  1669 
       
  1670     // Map account settings exit values to save parameters
       
  1671     switch ( aUiExitCode )
       
  1672         {
       
  1673         case EImumUiNoChanges: // Nothing has changed, no need for save
       
  1674         case EImumUiClose: // After back key has been pressed, exit settings
       
  1675         default:
       
  1676             params = ESmtpMtmUiCreateNewServiceNotCreated;
       
  1677             break;
       
  1678 
       
  1679         // After back key has been pressed, save and exit settings
       
  1680         case EImumUiSaveAndClose:
       
  1681         // External wizard created a new mailbox. ESmtpMtmUiCreateNewServiceSave
       
  1682         // must be set to param because we have to inform that the mailbox is
       
  1683         // created. So in this case we must not save the mailbox because
       
  1684         // External Wizard is already saved it.
       
  1685         case EImumUiExtWizardCreated:
       
  1686             params = ESmtpMtmUiCreateNewServiceSave;
       
  1687             break;
       
  1688 
       
  1689         // After options->exit has been chose, exit settings
       
  1690         case EImumUiExit:
       
  1691             params = ESmtpMtmUiCreateNewServiceExit;
       
  1692             break;
       
  1693 
       
  1694         // After options->exit has been chose, save and exit settings
       
  1695         case EImumUiSaveAndExit:
       
  1696             params = ESmtpMtmUiCreateNewServiceSaveAndExit;
       
  1697             break;
       
  1698 
       
  1699         }
       
  1700     IMUM_OUT();
       
  1701 
       
  1702     return params;
       
  1703     }
       
  1704 
       
  1705 // ----------------------------------------------------------------------------
       
  1706 // CSmtpMtmUi::HandlePredefinedMailboxCreationL
       
  1707 // ----------------------------------------------------------------------------
       
  1708 void CSmtpMtmUi::HandlePredefinedMailboxCreationL()
       
  1709     {
       
  1710     IMUM_CONTEXT( CSmtpMtmUi::HandlePredefinedMailboxCreationL, 0, KImumMtmLog );
       
  1711     IMUM_IN();
       
  1712 
       
  1713     // First, it needs to be check, does the system contain previously defined
       
  1714     // mailboxes. This is to prevent failure cases, when mtm attempts to
       
  1715     // initialise email mtm's several times in row.
       
  1716     MImumInHealthServices::RMailboxIdArray mailboxes;
       
  1717     iMailboxApi->HealthServicesL().GetMailboxList( mailboxes );
       
  1718     TBool allowCreation = ETrue;
       
  1719 
       
  1720     // Check if there's any predefined mailboxes available
       
  1721     for ( TInt mailbox = mailboxes.Count();
       
  1722         allowCreation && --mailbox >= 0; )
       
  1723         {
       
  1724         // If the key is not set, the mailbox is propably created by the
       
  1725         // user
       
  1726         TRAP_IGNORE( allowCreation = !ImumMboxSettingsUtils::QuickLoadL<TInt>( // CSI: 59 # codescanner gives critical error for some reason
       
  1727             *iMailboxApi,
       
  1728             mailboxes[mailbox],
       
  1729             TImumInSettings::EKeyIsPredefinedMailbox ) );
       
  1730         }
       
  1731     mailboxes.Reset();
       
  1732 
       
  1733     // The mailbox creation can start
       
  1734     if ( allowCreation )
       
  1735         {
       
  1736         // Create the mailbox creator unit
       
  1737         CImumCreatorPredefinedMailbox* creator =
       
  1738             CImumCreatorPredefinedMailbox::NewLC( *iMailboxApi );
       
  1739         TUid protocol = TUid::Uid( 0 );
       
  1740 
       
  1741         // Create all possible mailboxes
       
  1742         for ( TInt i=0; i<KImumMaxMailboxes; i++)
       
  1743             {
       
  1744             // Define
       
  1745             CImumInSettingsData* account =
       
  1746                 iMailboxApi->MailboxServicesL().CreateSettingsDataL(
       
  1747                     protocol );
       
  1748             CleanupStack::PushL( account );
       
  1749 
       
  1750             if ( creator->DefinePredefinedMailboxL( i, *account ) )
       
  1751                 {
       
  1752                 iMailboxApi->MailboxServicesL().CreateMailboxL( *account );
       
  1753                 }
       
  1754 
       
  1755             // Mailbox has been saved, remove the object
       
  1756             CleanupStack::PopAndDestroy( account );
       
  1757             account = NULL;
       
  1758             }
       
  1759 
       
  1760         CleanupStack::PopAndDestroy( creator );
       
  1761         }
       
  1762     IMUM_OUT();
       
  1763     }
       
  1764 
       
  1765 // ----------------------------------------------------------------------------
       
  1766 // CSmtpMtmUi::CheckAndRestoreSmtpUserAndPasswordL
       
  1767 // ----------------------------------------------------------------------------
       
  1768 void CSmtpMtmUi::CheckAndRestoreSmtpUserAndPasswordL( TMsvId aSmtpServiceId )
       
  1769     {
       
  1770     IMUM_CONTEXT( CSmtpMtmUi::CheckAndRestoreSmtpUserAndPasswordL, 0, KImumMtmLog );
       
  1771     IMUM_IN();
       
  1772 
       
  1773     // Get settings.
       
  1774     TBuf8<KImasLoginLength> username8;
       
  1775     TBuf8<KImasPasswordLength> password8;
       
  1776     TBool isPasswordTemporary = EFalse;
       
  1777 
       
  1778     // Load login information
       
  1779     ImumMboxSettingsUtils::GetLoginInformationL(
       
  1780         *iMailboxApi,
       
  1781         username8,
       
  1782         password8,
       
  1783         isPasswordTemporary,
       
  1784         aSmtpServiceId );
       
  1785 
       
  1786         // Temporary information is not accepted as valid data
       
  1787     if ( isPasswordTemporary )
       
  1788         {
       
  1789         // Have a valid password.
       
  1790         password8.Zero();
       
  1791 
       
  1792         // Save login information
       
  1793         ImumMboxSettingsUtils::SetLoginInformationL(
       
  1794             *iMailboxApi,
       
  1795             username8,
       
  1796             password8,
       
  1797             isPasswordTemporary,
       
  1798             aSmtpServiceId );
       
  1799         }
       
  1800     IMUM_OUT();
       
  1801     }
       
  1802 
       
  1803 
       
  1804 // ----------------------------------------------------------------------------
       
  1805 // CSmtpMtmUi::ValidateServiceL
       
  1806 // ----------------------------------------------------------------------------
       
  1807 void CSmtpMtmUi::ValidateServiceL( TDes8& aParameter )
       
  1808     {
       
  1809     IMUM_CONTEXT( CSmtpMtmUi::ValidateServiceL, 0, KImumMtmLog );
       
  1810     IMUM_IN();
       
  1811 
       
  1812     DoValidateServiceL( iUtils->DefaultMailboxId(), aParameter );
       
  1813     IMUM_OUT();
       
  1814     }
       
  1815 
       
  1816 // ---------------------------------------------------------------------------
       
  1817 // CSmtpMtmUi::ValidateServiceL()
       
  1818 // ---------------------------------------------------------------------------
       
  1819 //
       
  1820 void CSmtpMtmUi::ValidateServiceL(
       
  1821     const CMsvEntrySelection& aSelection,
       
  1822     TDes8& aParameter )
       
  1823     {
       
  1824     IMUM_CONTEXT( CSmtpMtmUi::ValidateServiceL, 0, KImumMtmLog );
       
  1825     IMUM_IN();
       
  1826 
       
  1827     if ( aSelection.Count() )
       
  1828         {
       
  1829         DoValidateServiceL( aSelection[0], aParameter );
       
  1830         }
       
  1831     IMUM_OUT();
       
  1832     }
       
  1833 
       
  1834 // ---------------------------------------------------------------------------
       
  1835 // CSmtpMtmUi::DoValidateServiceL()
       
  1836 // ---------------------------------------------------------------------------
       
  1837 //
       
  1838 void CSmtpMtmUi::DoValidateServiceL(
       
  1839     const TMsvId aMailboxId,
       
  1840     TDes8& aParameter )
       
  1841     {
       
  1842     IMUM_CONTEXT( CSmtpMtmUi::DoValidateServiceL, 0, KImumMtmLog );
       
  1843     IMUM_IN();
       
  1844 
       
  1845     TInt result =
       
  1846         iMailboxApi->HealthServicesL().IsMailboxHealthy( aMailboxId );
       
  1847     // 0 = KErrNone, other values indicate error
       
  1848     TPckgBuf<TInt> resultPackage( !result );
       
  1849     aParameter.Copy( resultPackage );
       
  1850     IMUM_OUT();
       
  1851     }
       
  1852 // ---------------------------------------------------------------------------
       
  1853 // CSmtpMtmUi::ActivateViewL()
       
  1854 // Activates right view after email wizard
       
  1855 // ---------------------------------------------------------------------------
       
  1856 //
       
  1857 void CSmtpMtmUi::ActivateViewL( TImumUiExitCodes aExitCode, TMsvId aId )
       
  1858     {
       
  1859     IMUM_CONTEXT( CSmtpMtmUi::DoValidateServiceL, 0, KImumMtmLog );
       
  1860     IMUM_IN();
       
  1861     CAknViewAppUi* appUi = reinterpret_cast<CAknViewAppUi*>
       
  1862         (CEikonEnv::Static()->EikAppUi());
       
  1863 
       
  1864     // If launched oustide of MCE, mce-view shouldn't be activated
       
  1865     if ( appUi->Application()->AppDllUid() == TUid::Uid( KMceUid ) )
       
  1866        {
       
  1867         switch( aExitCode )
       
  1868             {
       
  1869             // If no mailbox created, let's return to main view
       
  1870             case EImumUiNoChanges:
       
  1871             case EImumUiClose:
       
  1872             case EImumUiExit:
       
  1873             	appUi->ActivateLocalViewL( KMceMainViewListViewId );
       
  1874                 break;
       
  1875             // If mailbox created, let's open it
       
  1876             case EImumUiSaveAndExit:
       
  1877             case EImumUiSaveAndClose:
       
  1878             case EImumUiExtWizardCreated:
       
  1879                 appUi->ActivateLocalViewL( KMceMessageListViewId,
       
  1880                     TUid::Uid( aId ), KNullDesC8 );
       
  1881                 break;
       
  1882             default:
       
  1883                 break;
       
  1884             }
       
  1885         }
       
  1886     IMUM_OUT();
       
  1887     }
       
  1888 
       
  1889 // ----------------------------------------------------------------------------
       
  1890 // CSmtpMtmUi::ScreenClearerCleanupOperation
       
  1891 // ----------------------------------------------------------------------------
       
  1892 //
       
  1893 void CSmtpMtmUi::ScreenClearerCleanupOperation( TAny* aScreenClearer )
       
  1894 	{
       
  1895 	CEikonEnv::Static()->EikAppUi()->RemoveFromStack( 
       
  1896 		static_cast<CAknLocalScreenClearer*>( aScreenClearer ) );
       
  1897 	}
       
  1898 
       
  1899 // End of File
       
  1900 
       
  1901 
       
  1902