email/imum/Utils/Src/ImumMboxManager.cpp
changeset 0 72b543305e3a
child 1 d09ac5c1e252
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *       Encapsulates saving and removing email accounts
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <msvapi.h>                     // CMsvEntry
       
    23 #include <cemailaccounts.h>             // CEmailAccounts
       
    24 #include <smtpset.h>                    // CImSmtpSettings
       
    25 #include <pop3set.h>                    // CImPop3Settings
       
    26 #include <imapset.h>                    // CImImap4Settings
       
    27 #include <iapprefs.h>                   // CImIAPPreferences
       
    28 #include <muiumsvuiserviceutilitiesinternal.h>
       
    29 #include <SendUiConsts.h>
       
    30 
       
    31 #include "ImumInternalApiImpl.h"
       
    32 #include "ImumMboxSymbianDataConverter.h"
       
    33 #include "ImumMboxInternalDataConverter.h"
       
    34 #include "ImumMboxManager.h"
       
    35 #include "ImumInHealthServicesImpl.h"
       
    36 #include "ImumMboxData.h"
       
    37 #include "ImumMboxSettingsCtrl.h"
       
    38 #include "IMSSettingsNoteUi.h"
       
    39 #include "ImumUtilsLogging.h"
       
    40 #include "EmailUtils.H"
       
    41 #include "ImumPanic.h"
       
    42 
       
    43 #include <mtudreg.h>
       
    44 #include <muiumsvuiserviceutilitiesinternal.h>
       
    45 #include <featmgr.h>
       
    46 
       
    47 // EXTERNAL DATA STRUCTURES
       
    48 // EXTERNAL FUNCTION PROTOTYPES
       
    49 // CONSTANTS
       
    50 const TInt KImumMboxQueryTextLength    = 100;
       
    51 const TInt KImumMboxArrayGranularity   = 4;
       
    52 
       
    53 // MACROS
       
    54 // LOCAL CONSTANTS AND MACROS
       
    55 // MODULE DATA STRUCTURES
       
    56 // LOCAL FUNCTION PROTOTYPES
       
    57 // FORWARD DECLARATIONS
       
    58 
       
    59 // ============================ MEMBER FUNCTIONS ===============================
       
    60 
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CImumMboxManager::CImumMboxManager()
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 CImumMboxManager::CImumMboxManager(
       
    67     CImumInternalApiImpl& aMailboxApi )
       
    68     :
       
    69     iMailboxApi( aMailboxApi ),
       
    70     iMboxSettingsCtrl( NULL ),
       
    71     iAccounts( NULL ),
       
    72     iCleaner( NULL )
       
    73     {
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CImumMboxManager::ConstructL()
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 void CImumMboxManager::ConstructL()
       
    81     {
       
    82     IMUM_CONTEXT( CImumMboxManager::ConstructL, 0, KLogData );
       
    83     IMUM_IN();
       
    84 
       
    85     FeatureManager::InitializeLibL();
       
    86 
       
    87     iAccounts = CEmailAccounts::NewL();
       
    88     iMboxSettingsCtrl = CImumMboxSettingsCtrl::NewL( iMailboxApi );
       
    89     iCleaner = CImumInHealthServicesImpl::NewL( iMailboxApi );
       
    90 
       
    91     IMUM_OUT();
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // CImumMboxManager::~CImumMboxManager()
       
    96 // ----------------------------------------------------------------------------
       
    97 //
       
    98 CImumMboxManager::~CImumMboxManager()
       
    99     {
       
   100     IMUM_CONTEXT( CImumMboxManager::~CImumMboxManager, 0, KLogData );
       
   101     IMUM_IN();
       
   102 
       
   103     FeatureManager::UnInitializeLib();
       
   104     delete iMboxSettingsCtrl;
       
   105     iMboxSettingsCtrl = NULL;
       
   106     delete iAccounts;
       
   107     iAccounts = NULL;
       
   108     delete iCleaner;
       
   109     iCleaner = NULL;
       
   110 
       
   111     IMUM_OUT();
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CImumMboxManager::NewL()
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 CImumMboxManager* CImumMboxManager::NewL(
       
   119     CImumInternalApiImpl& aMailboxApi )
       
   120     {
       
   121     IMUM_STATIC_CONTEXT( CImumMboxManager::NewL, 0, utils, KLogData );
       
   122     IMUM_IN();
       
   123 
       
   124     CImumMboxManager* self = NewLC( aMailboxApi );
       
   125     CleanupStack::Pop( self );
       
   126 
       
   127     IMUM_OUT();
       
   128 
       
   129     return self;
       
   130     }
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // CImumMboxManager::NewLC()
       
   134 // ----------------------------------------------------------------------------
       
   135 //
       
   136 CImumMboxManager* CImumMboxManager::NewLC(
       
   137     CImumInternalApiImpl& aMailboxApi )
       
   138     {
       
   139     IMUM_STATIC_CONTEXT( CImumMboxManager::NewLC, 0, utils, KLogData );
       
   140     IMUM_IN();
       
   141 
       
   142     CImumMboxManager* self =
       
   143         new ( ELeave ) CImumMboxManager( aMailboxApi );
       
   144     CleanupStack::PushL( self );
       
   145     self->ConstructL();
       
   146 
       
   147     IMUM_OUT();
       
   148 
       
   149     return self;
       
   150     }
       
   151 
       
   152 /******************************************************************************
       
   153 
       
   154     Static Functions
       
   155 
       
   156 ******************************************************************************/
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // CImumMboxManager::GetIapPreferencesL()
       
   160 // ----------------------------------------------------------------------------
       
   161 //
       
   162 TInt CImumMboxManager::GetIapPreferencesL(
       
   163     const TMsvId aMailboxId,
       
   164     CEmailAccounts& aAccounts,
       
   165     CImIAPPreferences& aIapPrefs,
       
   166     CImumInternalApiImpl& aMailboxApi,
       
   167     const TBool aSmtp )
       
   168     {
       
   169     IMUM_STATIC_CONTEXT( CImumMboxManager::GetIapPreferencesL, 0, utils, KLogData );
       
   170     IMUM_IN();
       
   171 
       
   172     TMsvEntry entry;
       
   173 
       
   174     // Get the correct part of the mailbox
       
   175     if ( aSmtp )
       
   176         {
       
   177         // Get SMTP part of the mailbox
       
   178         entry = aMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
   179             aMailboxId, MImumInMailboxUtilities::ERequestSending );
       
   180 
       
   181         // Define the account id
       
   182         TSmtpAccount smtpAccountId;
       
   183         smtpAccountId.iSmtpAccountId = entry.iMtmData2;
       
   184 
       
   185         // Load preferences
       
   186         aAccounts.LoadSmtpIapSettingsL( smtpAccountId, aIapPrefs );
       
   187         }
       
   188     else
       
   189         {
       
   190         // Get POP3 or IMAP4 part of the mailbox
       
   191         entry = aMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
   192             aMailboxId, MImumInMailboxUtilities::ERequestReceiving );
       
   193 
       
   194         // Load settings based on the mtm type
       
   195         if ( entry.iMtm.iUid == KSenduiMtmImap4UidValue )
       
   196             {
       
   197             // Define imap4 account id
       
   198             TImapAccount imapAccountId;
       
   199             imapAccountId.iImapAccountId = entry.iMtmData2;
       
   200 
       
   201             // Load preferences
       
   202             aAccounts.LoadImapIapSettingsL( imapAccountId, aIapPrefs );
       
   203             }
       
   204         else
       
   205             {
       
   206             // Define pop3 account id
       
   207             TPopAccount popAccountId;
       
   208             popAccountId.iPopAccountId = entry.iMtmData2;
       
   209 
       
   210             // Load preferences
       
   211             aAccounts.LoadPopIapSettingsL( popAccountId, aIapPrefs );
       
   212             }
       
   213         }
       
   214 
       
   215     IMUM_OUT();
       
   216 
       
   217     return KErrNone;
       
   218     }
       
   219 
       
   220 // ----------------------------------------------------------------------------
       
   221 // CImumMboxManager::SetIapPreferencesL()
       
   222 // ----------------------------------------------------------------------------
       
   223 //
       
   224 TInt CImumMboxManager::SetIapPreferencesL(
       
   225     const TMsvId aMailboxId,
       
   226     CEmailAccounts& aAccounts,
       
   227     const CImIAPPreferences& aIapPrefs,
       
   228     CImumInternalApiImpl& aMailboxApi,
       
   229     const TBool aSmtp )
       
   230     {
       
   231     IMUM_STATIC_CONTEXT( CImumMboxManager::SetIapPreferencesL, 0, utils, KLogData );
       
   232     IMUM_IN();
       
   233 
       
   234     TMsvEntry entry;
       
   235     TInt error = KErrNone;
       
   236 
       
   237     // Get the correct part of the mailbox
       
   238     if ( aSmtp )
       
   239         {
       
   240         // Get SMTP part of the mailbox
       
   241         entry = aMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
   242             aMailboxId, MImumInMailboxUtilities::ERequestSending );
       
   243 
       
   244         // Define the account id
       
   245         TSmtpAccount smtpAccountId;
       
   246         smtpAccountId.iSmtpAccountId = entry.iMtmData2;
       
   247 
       
   248         // Load preferences
       
   249         aAccounts.SaveSmtpIapSettingsL( smtpAccountId, aIapPrefs );
       
   250         }
       
   251     else
       
   252         {
       
   253         // Get POP3 or IMAP4 part of the mailbox
       
   254         entry = aMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
   255             aMailboxId, MImumInMailboxUtilities::ERequestReceiving );
       
   256 
       
   257         // Load settings based on the mtm type
       
   258         if ( entry.iMtm.iUid == KSenduiMtmImap4UidValue )
       
   259             {
       
   260             // Define imap4 account id
       
   261             TImapAccount imapAccountId;
       
   262             imapAccountId.iImapAccountId = entry.iMtmData2;
       
   263 
       
   264             // Load preferences
       
   265             aAccounts.SaveImapIapSettingsL( imapAccountId, aIapPrefs );
       
   266             }
       
   267         else
       
   268             {
       
   269             // Define pop3 account id
       
   270             TPopAccount popAccountId;
       
   271             popAccountId.iPopAccountId = entry.iMtmData2;
       
   272 
       
   273             // Load preferences
       
   274             aAccounts.SavePopIapSettingsL( popAccountId, aIapPrefs );
       
   275             }
       
   276         }
       
   277 
       
   278     IMUM_OUT();
       
   279 
       
   280     return error;
       
   281     }
       
   282 
       
   283 // ----------------------------------------------------------------------------
       
   284 // CImumMboxManager::ForceAlwaysAskL()
       
   285 // ----------------------------------------------------------------------------
       
   286 //
       
   287 void CImumMboxManager::ForceAlwaysAskL(
       
   288     const TMsvId aMailboxId,
       
   289     CEmailAccounts& aAccounts,
       
   290     CImIAPPreferences& aIapPrefs,
       
   291     CImumInternalApiImpl& aMailboxApi,
       
   292     const TBool aSmtp )
       
   293     {
       
   294     IMUM_STATIC_CONTEXT( CImumMboxManager::ForceAlwaysAskL, 0, utils, KLogData );
       
   295     IMUM_IN();
       
   296 
       
   297     aIapPrefs.RemoveIAPL( 0 );
       
   298     TImIAPChoice iap;
       
   299     iap.iDialogPref = ECommDbDialogPrefPrompt;
       
   300     iap.iIAP = 0;
       
   301     aIapPrefs.AddIAPL( iap );
       
   302     User::LeaveIfError( CImumMboxManager::SetIapPreferencesL(
       
   303         aMailboxId, aAccounts, aIapPrefs, aMailboxApi, aSmtp ) );
       
   304 
       
   305     IMUM_OUT();
       
   306     }
       
   307 
       
   308 /******************************************************************************
       
   309 
       
   310     Manager tools
       
   311 
       
   312 ******************************************************************************/
       
   313 
       
   314 // ----------------------------------------------------------------------------
       
   315 // CImumMboxManager::CreateAccountFillIapL()
       
   316 // ----------------------------------------------------------------------------
       
   317 //
       
   318 void CImumMboxManager::CreateAccountFillIapL(
       
   319     CImumMboxData& aSettings )
       
   320     {
       
   321     IMUM_CONTEXT( CImumMboxManager::CreateAccountFillIapL, 0, KLogData );
       
   322     IMUM_IN();
       
   323 
       
   324     // This is not ideal choice, but current situation forces to do this,
       
   325     // until Reset() funcion is exported from class CImIAPPreferences
       
   326     delete aSettings.iIncomingIapPref;
       
   327     aSettings.iIncomingIapPref = NULL;
       
   328     delete aSettings.iOutgoingIapPref;
       
   329     aSettings.iOutgoingIapPref = NULL;
       
   330 
       
   331     // Make sure the preferences are made
       
   332     if ( !aSettings.iIncomingIapPref )
       
   333         {
       
   334         aSettings.iIncomingIapPref = CImIAPPreferences::NewLC();
       
   335         CleanupStack::Pop( aSettings.iIncomingIapPref );
       
   336         }
       
   337 
       
   338     if ( !aSettings.iOutgoingIapPref )
       
   339         {
       
   340         aSettings.iOutgoingIapPref = CImIAPPreferences::NewLC();
       
   341         CleanupStack::Pop( aSettings.iOutgoingIapPref );
       
   342         }
       
   343 
       
   344     // Set incoming internet access point
       
   345     TImIAPChoice incomingIapChoice;
       
   346     incomingIapChoice.iIAP = aSettings.iIncomingIap;
       
   347     incomingIapChoice.iDialogPref = ECommDbDialogPrefDoNotPrompt;
       
   348     aSettings.iIncomingIapPref->AddIAPL( incomingIapChoice );
       
   349 
       
   350     // Set outgoing internet access point
       
   351     TImIAPChoice outgoingIapChoice;
       
   352     outgoingIapChoice.iIAP = aSettings.iOutgoingIap;
       
   353     outgoingIapChoice.iDialogPref = ECommDbDialogPrefDoNotPrompt;
       
   354     aSettings.iOutgoingIapPref->AddIAPL( outgoingIapChoice );
       
   355 
       
   356     IMUM_OUT();
       
   357     }
       
   358 
       
   359 // ----------------------------------------------------------------------------
       
   360 // CImumMboxManager::LoadAccountFillIapL()
       
   361 // ----------------------------------------------------------------------------
       
   362 //
       
   363 void CImumMboxManager::LoadAccountFillIapL(
       
   364     CImumMboxData& aSettings )
       
   365     {
       
   366     IMUM_CONTEXT( CImumMboxManager::LoadAccountFillIapL, 0, KLogData );
       
   367     IMUM_IN();
       
   368 
       
   369     // Set internet access point (incoming IAP)
       
   370     TImIAPChoice incomingIapChoice =
       
   371         aSettings.iIncomingIapPref->IAPPreference( 0 );
       
   372     aSettings.iIncomingIap = incomingIapChoice.iIAP;
       
   373 
       
   374     // Set internet access point (Outgoing IAP)
       
   375     TImIAPChoice outgoingIapChoice =
       
   376         aSettings.iOutgoingIapPref->IAPPreference( 0 );
       
   377     aSettings.iOutgoingIap = outgoingIapChoice.iIAP;
       
   378 
       
   379     IMUM_OUT();
       
   380     }
       
   381 
       
   382 // ----------------------------------------------------------------------------
       
   383 // CImumMboxManager::DetermineDefaultAccountL()
       
   384 // ----------------------------------------------------------------------------
       
   385 //
       
   386 void CImumMboxManager::DetermineDefaultAccountL(
       
   387     CImumMboxData& aSettings )
       
   388     {
       
   389     IMUM_CONTEXT( CImumMboxManager::DetermineDefaultAccountL, 0, KLogData );
       
   390     IMUM_IN();
       
   391 
       
   392     // First check if default account id is set
       
   393     aSettings.iDefaultAccountId =
       
   394         MsvUiServiceUtilitiesInternal::DefaultServiceForMTML(
       
   395             iMailboxApi.MsvSession(), KSenduiMtmSmtpUid, EFalse );
       
   396 
       
   397     // Set the newly created one as a default account
       
   398     if ( aSettings.iDefaultAccountId == KMsvUnknownServiceIndexEntryId )
       
   399         {
       
   400 		if( !FeatureManager::FeatureSupported( KFeatureIdSelectableEmail ) ||
       
   401 			!MsvUiServiceUtilitiesInternal::OtherEmailMTMExistL( 
       
   402 			iMailboxApi.MsvSession(), aSettings.iMailboxId ) )
       
   403 			{
       
   404             TSmtpAccount smtpAccountId;
       
   405             iAccounts->GetSmtpAccountL( aSettings.iMailboxId, smtpAccountId );
       
   406             iAccounts->SetDefaultSmtpAccountL( smtpAccountId );
       
   407 
       
   408 			MsvUiServiceUtilitiesInternal::SetDefaultServiceForMTML(
       
   409 					iMailboxApi.MsvSession(), KSenduiMtmSmtpUid, 
       
   410 					aSettings.iMailboxId );
       
   411 			aSettings.iDefaultAccountId = aSettings.iMailboxId;
       
   412 			}
       
   413 		}
       
   414     IMUM_OUT();
       
   415     }
       
   416 
       
   417 // ----------------------------------------------------------------------------
       
   418 // CImumMboxManager::RemoveAccountL()
       
   419 // ----------------------------------------------------------------------------
       
   420 //
       
   421 void CImumMboxManager::RemoveAccountL(
       
   422     const CImumMboxData& aSettings )
       
   423     {
       
   424     IMUM_CONTEXT( CImumMboxManager::RemoveAccountL, 0, KLogData );
       
   425     IMUM_IN();
       
   426 
       
   427     // Delete Imap4 or Pop3 account
       
   428     if ( aSettings.iIsImap4 )
       
   429         {
       
   430         DeleteExtendedSettings( TIMAStorerParams(
       
   431             aSettings.iImap4AccountId.iImapAccountId, KSenduiMtmImap4Uid ) );
       
   432 
       
   433         DeleteBaseSettingsL( aSettings );
       
   434         }
       
   435     else
       
   436         {
       
   437         DeleteExtendedSettings( TIMAStorerParams(
       
   438             aSettings.iPop3AccountId.iPopAccountId, KSenduiMtmPop3Uid ) );
       
   439 
       
   440         DeleteBaseSettingsL( aSettings );
       
   441         }
       
   442 
       
   443     IMUM_OUT();
       
   444     }
       
   445 
       
   446 // ----------------------------------------------------------------------------
       
   447 // CImumMboxManager::RemoveAccountL()
       
   448 // ----------------------------------------------------------------------------
       
   449 //
       
   450 void CImumMboxManager::RemoveAccountL(
       
   451     const TMsvEntry& aMailboxEntry, TBool aSilent )
       
   452     {
       
   453     IMUM_CONTEXT( CImumMboxManager::RemoveAccountL, 0, KLogData );
       
   454     IMUM_IN();
       
   455 
       
   456     if ( aSilent || AccountDeletionConditionsOkL( aMailboxEntry.Id() ) )
       
   457         {
       
   458         // Delete Imap4 or Pop3 account
       
   459         if ( aMailboxEntry.iMtm == KSenduiMtmImap4Uid )
       
   460             {
       
   461             DeleteExtendedSettings( TIMAStorerParams(
       
   462                 aMailboxEntry.iMtmData2, KSenduiMtmImap4Uid ) );
       
   463 
       
   464             DeleteBaseSettingsL( aMailboxEntry.iMtmData2, ETrue );
       
   465             }
       
   466         else
       
   467             {
       
   468             DeleteExtendedSettings( TIMAStorerParams(
       
   469                 aMailboxEntry.iMtmData2, KSenduiMtmPop3Uid ) );
       
   470 
       
   471             DeleteBaseSettingsL( aMailboxEntry.iMtmData2, EFalse );
       
   472             }
       
   473         }
       
   474 
       
   475     IMUM_OUT();
       
   476     }
       
   477 
       
   478 // ----------------------------------------------------------------------------
       
   479 // CImumMboxManager::RemoveAccountL()
       
   480 // ----------------------------------------------------------------------------
       
   481 //
       
   482 void CImumMboxManager::RemoveAccountL(
       
   483     const TUint32 aRelatedAccountId,
       
   484     const TUid& aMtmId )
       
   485     {
       
   486     IMUM_CONTEXT( CImumMboxManager::RemoveAccountL, 0, KLogData );
       
   487     IMUM_IN();
       
   488 
       
   489     // First remove the extended settings, as this cannot leave
       
   490     DeleteExtendedSettings(
       
   491         TIMAStorerParams( aRelatedAccountId, aMtmId ) );
       
   492 
       
   493     // Delete Imap4 or Pop3 account
       
   494     DeleteBaseSettingsL(
       
   495         aRelatedAccountId, aMtmId == KSenduiMtmImap4Uid );
       
   496 
       
   497     IMUM_OUT();
       
   498     }
       
   499 
       
   500 // ---------------------------------------------------------------------------
       
   501 // CImumMboxManager::RemoveAccount()
       
   502 // ---------------------------------------------------------------------------
       
   503 //
       
   504 void CImumMboxManager::RemoveAccount( const TMsvId aMailboxId, TBool aSilent )
       
   505     {
       
   506     IMUM_CONTEXT( CImumMboxManager::RemoveAccount, 0, KLogData );
       
   507     IMUM_IN();
       
   508 
       
   509     TMsvEntry entry;
       
   510     TRAPD( error, entry = iMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
   511         aMailboxId,
       
   512         MImumInMailboxUtilities::ERequestReceiving ) );
       
   513 
       
   514     if ( !error )
       
   515         {
       
   516         TRAP_IGNORE( RemoveAccountL( entry, aSilent ) );
       
   517         }
       
   518 
       
   519     IMUM_OUT();
       
   520     }
       
   521 
       
   522 
       
   523 /******************************************************************************
       
   524 
       
   525     Account creation
       
   526 
       
   527 ******************************************************************************/
       
   528 
       
   529 // ----------------------------------------------------------------------------
       
   530 // CImumMboxManager::CreateEmailAccount()
       
   531 // ----------------------------------------------------------------------------
       
   532 //
       
   533 void CImumMboxManager::CreateEmailAccount(
       
   534     CImumMboxData& aSettings,
       
   535     const TBool aPopulateDefaults )
       
   536     {
       
   537     IMUM_CONTEXT( CImumMboxManager::CreateEmailAccount, 0, KLogData );
       
   538     IMUM_IN();
       
   539 
       
   540     // If settings not ready, don't try to create
       
   541     if ( aSettings.IsOk() )
       
   542         {
       
   543         // Attempt to create the mailaccount
       
   544         TRAPD( error, CreateEmailAccountL( aSettings, aPopulateDefaults ) );
       
   545 
       
   546         // Creating mailbox has failed, delete entries and cenrep settings
       
   547         if ( error != KErrNone )
       
   548             {
       
   549             TRAP_IGNORE( RemoveAccountL( aSettings ) );
       
   550             __ASSERT_DEBUG( EFalse, User::Panic( KImumMtmUiPanic, error ) );
       
   551             }
       
   552         }
       
   553 
       
   554     IMUM_OUT();
       
   555     }
       
   556 
       
   557 // ---------------------------------------------------------------------------
       
   558 // CImumMboxManager::CreateEmailAccountL()
       
   559 // ---------------------------------------------------------------------------
       
   560 //
       
   561 TMsvId CImumMboxManager::CreateEmailAccountL(
       
   562     const CImumInSettingsData& aSettingsData )
       
   563     {
       
   564     IMUM_CONTEXT( CImumMboxManager::CreateEmailAccountL, 0, KLogData );
       
   565     IMUM_IN();
       
   566 
       
   567     CImumMboxData* settings =
       
   568         CImumMboxSymbianDataConverter::ConvertToSymbianMboxDataLC(
       
   569             iMailboxApi, aSettingsData );
       
   570 
       
   571     CreateEmailAccountL( *settings, EFalse );
       
   572 
       
   573     TMsvId mboxId = settings->iMailboxId;
       
   574     CleanupStack::PopAndDestroy( settings );
       
   575     settings = NULL;
       
   576 
       
   577     IMUM_OUT();
       
   578 
       
   579     return mboxId;
       
   580     }
       
   581 
       
   582 // ----------------------------------------------------------------------------
       
   583 // CImumMboxManager::CreateEmailAccountL()
       
   584 // ----------------------------------------------------------------------------
       
   585 //
       
   586 void CImumMboxManager::CreateEmailAccountL(
       
   587     CImumMboxData& aSettings,
       
   588     const TBool aPopulateDefaults )
       
   589     {
       
   590     IMUM_CONTEXT( CImumMboxManager::CreateEmailAccountL, 0, KLogData );
       
   591     IMUM_IN();
       
   592 
       
   593     TUint32 id = 0;
       
   594     TUid mtmId;
       
   595     TMsvId serviceId = 0;
       
   596     IMUM0(0, " ### Starting mailbox creation processs");
       
   597 
       
   598     // Check for imap4
       
   599     if ( aSettings.iIsImap4 )
       
   600         {
       
   601         IMUM0( 0, " # STEP1 : Create IMAP4 account" );
       
   602         // Catch all the problems with account creation
       
   603         id = CreateImap4AccountL( aSettings, aPopulateDefaults );
       
   604         serviceId = aSettings.iImap4AccountId.iImapService;
       
   605         mtmId = KSenduiMtmImap4Uid;
       
   606         }
       
   607     else
       
   608         {
       
   609         IMUM0( 0, " # STEP1 : Create POP3 account" );
       
   610 
       
   611         id = CreatePop3AccountL( aSettings, aPopulateDefaults );
       
   612         serviceId = aSettings.iPop3AccountId.iPopService;
       
   613         mtmId = KSenduiMtmPop3Uid;
       
   614         }
       
   615 
       
   616     IMUM0( 0, " # STEP1.5 : Store IMEI" );
       
   617     iCleaner->StoreIMEIToMailbox( aSettings.iMailboxId );
       
   618 
       
   619     IMUM0( 0, " # STEP2 : Create extended settings" );
       
   620     CreateExtendedSettingsL( aSettings.iMailboxId, id, mtmId, aSettings, aPopulateDefaults );
       
   621 
       
   622     IMUM0( 0, " # STEP3 : Store account ID to entry" );
       
   623     StoreAccountIdToEntryL( aSettings );
       
   624 
       
   625     IMUM0( 0, " # STEP4 : Choose default account" );
       
   626     DetermineDefaultAccountL( aSettings );
       
   627 
       
   628     IMUM0( 0, " # STEP5 : Store signature" );
       
   629     TRAP_IGNORE( StoreSignatureL( aSettings ) );
       
   630     
       
   631     IMUM0( 0, " # STEP6 : Activate AO Email plugin if needed" );
       
   632     if( serviceId && ( 
       
   633         EMailAoOff  != aSettings.iExtendedSettings->AlwaysOnlineState() ||
       
   634         EMailEmnOff != aSettings.iExtendedSettings->EmailNotificationState() ) )
       
   635         {
       
   636         TRAPD( error, MsvEmailMtmUiUtils::SendAOCommandL( EServerAPIEmailTurnOn, serviceId ) );
       
   637 		if ( error != KErrNotFound )
       
   638 			{
       
   639 			User::LeaveIfError( error );
       
   640 			}
       
   641         }
       
   642     IMUM0(0, " ### Finishing mailbox creation processs");
       
   643     IMUM_OUT();
       
   644     }
       
   645 
       
   646 // ----------------------------------------------------------------------------
       
   647 // CImumMboxManager::CreateImap4AccountL()
       
   648 // ----------------------------------------------------------------------------
       
   649 //
       
   650 TUint32 CImumMboxManager::CreateImap4AccountL(
       
   651     CImumMboxData& aSettings,
       
   652     const TBool aPopulateDefaults,
       
   653     const TBool aReadOnly )
       
   654     {
       
   655     IMUM_CONTEXT( CImumMboxManager::CreateImap4AccountL, 0, KLogData );
       
   656     IMUM_IN();
       
   657 
       
   658     // Populate defaults
       
   659     if ( aPopulateDefaults )
       
   660         {
       
   661         iAccounts->PopulateDefaultImapSettingsL(
       
   662             *aSettings.iImap4Settings, *aSettings.iIncomingIapPref );
       
   663         iAccounts->PopulateDefaultSmtpSettingsL(
       
   664             *aSettings.iSmtpSettings, *aSettings.iOutgoingIapPref );
       
   665         }
       
   666 
       
   667     // Fill iap preferences
       
   668     CreateAccountFillIapL( aSettings );
       
   669 
       
   670     // Create the account
       
   671     aSettings.iImap4AccountId = iAccounts->CreateImapAccountL(
       
   672         aSettings.iName, *aSettings.iImap4Settings,
       
   673         *aSettings.iIncomingIapPref, aReadOnly );
       
   674     iAccounts->CreateSmtpAccountL( aSettings.iImap4AccountId,
       
   675         *aSettings.iSmtpSettings, *aSettings.iOutgoingIapPref, aReadOnly );
       
   676 
       
   677     aSettings.iMailboxId = aSettings.iImap4AccountId.iSmtpService;
       
   678 
       
   679     IMUM_OUT();
       
   680 
       
   681     return aSettings.iImap4AccountId.iImapAccountId;
       
   682     }
       
   683 
       
   684 // ----------------------------------------------------------------------------
       
   685 // CImumMboxManager::CreatePop3AccountL()
       
   686 // ----------------------------------------------------------------------------
       
   687 //
       
   688 TUint32 CImumMboxManager::CreatePop3AccountL(
       
   689     CImumMboxData& aSettings,
       
   690     const TBool aPopulateDefaults,
       
   691     const TBool aReadOnly )
       
   692     {
       
   693     IMUM_CONTEXT( CImumMboxManager::CreatePop3AccountL, 0, KLogData );
       
   694     IMUM_IN();
       
   695 
       
   696     // Populate defaults
       
   697     if ( aPopulateDefaults )
       
   698         {
       
   699         iAccounts->PopulateDefaultPopSettingsL(
       
   700             *aSettings.iPop3Settings, *aSettings.iIncomingIapPref );
       
   701         iAccounts->PopulateDefaultSmtpSettingsL(
       
   702             *aSettings.iSmtpSettings, *aSettings.iOutgoingIapPref );
       
   703         }
       
   704 
       
   705     // Fill iap preferences
       
   706     CreateAccountFillIapL( aSettings );
       
   707 
       
   708     // Create the account
       
   709     aSettings.iPop3AccountId = iAccounts->CreatePopAccountL(
       
   710         aSettings.iName,
       
   711         *aSettings.iPop3Settings, *aSettings.iIncomingIapPref, aReadOnly );
       
   712     iAccounts->CreateSmtpAccountL( aSettings.iPop3AccountId,
       
   713         *aSettings.iSmtpSettings, *aSettings.iOutgoingIapPref, aReadOnly );
       
   714 
       
   715     aSettings.iMailboxId = aSettings.iPop3AccountId.iSmtpService;
       
   716 
       
   717     IMUM_OUT();
       
   718 
       
   719     return aSettings.iPop3AccountId.iPopAccountId;
       
   720     }
       
   721 
       
   722 // ----------------------------------------------------------------------------
       
   723 // CImumMboxManager::CreateExtendedSettingsL()
       
   724 // ----------------------------------------------------------------------------
       
   725 //
       
   726 void CImumMboxManager::CreateExtendedSettingsL(
       
   727     const TMsvId aMailboxId,
       
   728     const TUint32 aAccountId,
       
   729     const TUid& aProtocol,
       
   730     CImumMboxData& aSettings,
       
   731     const TBool aPopulateDefaults )
       
   732     {
       
   733     IMUM_CONTEXT( CImumMboxManager::CreateExtendedSettingsL, 0, KLogData );
       
   734     IMUM_IN();
       
   735 
       
   736     // If populating has been successful
       
   737     User::LeaveIfError( iMboxSettingsCtrl->CreateSettings(
       
   738         aMailboxId, aAccountId, aProtocol,
       
   739         *aSettings.iExtendedSettings, aPopulateDefaults ) );
       
   740 
       
   741     IMUM_OUT();
       
   742     }
       
   743 
       
   744 /******************************************************************************
       
   745 
       
   746     Account Deletion
       
   747 
       
   748 ******************************************************************************/
       
   749 
       
   750 // ----------------------------------------------------------------------------
       
   751 // CImumMboxManager::DeleteExtendedSettings()
       
   752 // ----------------------------------------------------------------------------
       
   753 //
       
   754 TInt CImumMboxManager::DeleteExtendedSettings(
       
   755     const TIMAStorerParams& aParams )
       
   756     {
       
   757     // Delete the settings
       
   758     return iMboxSettingsCtrl->DeleteExtendedSettings( aParams );
       
   759     }
       
   760 
       
   761 // ----------------------------------------------------------------------------
       
   762 // CImumMboxManager::DeleteRelatedSmtpAccountsL()
       
   763 // ----------------------------------------------------------------------------
       
   764 //
       
   765 void CImumMboxManager::DeleteRelatedSmtpAccountsL(
       
   766     const CImumMboxData& aSettings )
       
   767     {
       
   768     IMUM_CONTEXT( CImumMboxManager::DeleteRelatedSmtpAccountsL, 0, KLogData );
       
   769     IMUM_IN();
       
   770 
       
   771     // Get the available smtp accounts
       
   772     RArray<TSmtpAccount> smtpAccountArray;
       
   773     iAccounts->GetSmtpAccountsL( smtpAccountArray );
       
   774 
       
   775     // Get the related service id
       
   776     TMsvId relatedServiceId = aSettings.iIsImap4 ?
       
   777         aSettings.iImap4AccountId.iImapService :
       
   778         aSettings.iPop3AccountId.iPopService;
       
   779 
       
   780     // Delete the accounts
       
   781     DeleteSmtpAccountsL( relatedServiceId, smtpAccountArray );
       
   782 
       
   783     smtpAccountArray.Reset();
       
   784 
       
   785     IMUM_OUT();
       
   786     }
       
   787 
       
   788 // ----------------------------------------------------------------------------
       
   789 // CImumMboxManager::DeleteRelatedSmtpAccountsL()
       
   790 // ----------------------------------------------------------------------------
       
   791 //
       
   792 void CImumMboxManager::DeleteRelatedSmtpAccountsL(
       
   793     const TUint32 aRelatedAccountId,
       
   794     const TBool aIsImap4 )
       
   795     {
       
   796     IMUM_CONTEXT( CImumMboxManager::DeleteRelatedSmtpAccountsL, 0, KLogData );
       
   797     IMUM_IN();
       
   798 
       
   799     // Get the available imap accounts
       
   800     TMsvId relatedService = KMsvNullIndexEntryId;
       
   801 
       
   802     if ( aIsImap4 )
       
   803         {
       
   804         // Get Imap account
       
   805         RIMASImap4IdArray imapAccountArray;
       
   806         iAccounts->GetImapAccountsL( imapAccountArray );
       
   807 
       
   808         // Find the account from imap accounts
       
   809         for ( TInt mailbox = imapAccountArray.Count();
       
   810             --mailbox >= 0 && relatedService == KMsvNullIndexEntryId; )
       
   811             {
       
   812             TUint32 imapId = imapAccountArray[mailbox].iImapAccountId;
       
   813             if ( imapId == aRelatedAccountId )
       
   814                 {
       
   815                 relatedService = imapAccountArray[mailbox].iImapService;
       
   816                 }
       
   817             }
       
   818 
       
   819         imapAccountArray.Reset();
       
   820         }
       
   821     else
       
   822         {
       
   823         // Get pop account
       
   824         RIMASPop3IdArray popAccountArray;
       
   825         iAccounts->GetPopAccountsL( popAccountArray );
       
   826 
       
   827         // Find the account from pop accounts
       
   828         for ( TInt mailbox = popAccountArray.Count();
       
   829             --mailbox >= 0 && relatedService == KMsvNullIndexEntryId; )
       
   830             {
       
   831             TUint32 popId = popAccountArray[mailbox].iPopAccountId;
       
   832             if ( popId == aRelatedAccountId )
       
   833                 {
       
   834                 relatedService = popAccountArray[mailbox].iPopService;
       
   835                 }
       
   836             }
       
   837 
       
   838         popAccountArray.Reset();
       
   839         }
       
   840 
       
   841     // If found, remove the accounts
       
   842     if ( relatedService != KMsvNullIndexEntryId )
       
   843         {
       
   844         RIMASSmtpIdArray smtpAccountArray;
       
   845         iAccounts->GetSmtpAccountsL( smtpAccountArray );
       
   846 
       
   847         // Delete the accounts
       
   848         DeleteSmtpAccountsL( relatedService, smtpAccountArray );
       
   849         smtpAccountArray.Reset();
       
   850         }
       
   851 
       
   852     IMUM_OUT();
       
   853     }
       
   854 
       
   855 // ----------------------------------------------------------------------------
       
   856 // CImumMboxManager::DeleteSmtpAccountsL()
       
   857 // ----------------------------------------------------------------------------
       
   858 //
       
   859 void CImumMboxManager::DeleteSmtpAccountsL(
       
   860     const TMsvId aRelatedMailboxId,
       
   861     const RIMASSmtpIdArray& aSmtpAccountArray )
       
   862     {
       
   863     IMUM_CONTEXT( CImumMboxManager::DeleteSmtpAccountsL, 0, KLogData );
       
   864     IMUM_IN();
       
   865 
       
   866     TSmtpAccount smtpId;
       
   867 
       
   868     // Start checking the mailboxes
       
   869     for ( TInt mailbox = aSmtpAccountArray.Count(); --mailbox >= 0; )
       
   870         {
       
   871         smtpId = aSmtpAccountArray[mailbox];
       
   872 
       
   873         // If the related id matches with the smtp accounts related service
       
   874         // id, the account can be deleted.
       
   875         if ( aRelatedMailboxId == smtpId.iRelatedService )
       
   876             {
       
   877             iAccounts->DeleteSmtpAccountL( smtpId );
       
   878             }
       
   879         }
       
   880 
       
   881     IMUM_OUT();
       
   882     }
       
   883 
       
   884 // ----------------------------------------------------------------------------
       
   885 // CImumMboxManager::DeleteBaseSettingsL()
       
   886 // ----------------------------------------------------------------------------
       
   887 //
       
   888 void CImumMboxManager::DeleteBaseSettingsL(
       
   889     const TUint32 aRelatedAccountId,
       
   890     const TBool aIsImap4 )
       
   891     {
       
   892     IMUM_CONTEXT( CImumMboxManager::DeleteBaseSettingsL, 0, KLogData );
       
   893 
       
   894     // Remove the related smtp accounts
       
   895     DeleteRelatedSmtpAccountsL( aRelatedAccountId, aIsImap4 );
       
   896 
       
   897     // Determine the account type
       
   898     if ( aIsImap4 )
       
   899         {
       
   900         // Remove the Imap4 account
       
   901         TImapAccount imapId;
       
   902         imapId.iImapAccountId = aRelatedAccountId;
       
   903         iAccounts->DeleteImapAccountL( imapId );
       
   904         }
       
   905     else
       
   906         {
       
   907         // Remove the Pop3 account
       
   908         TPopAccount popId;
       
   909         popId.iPopAccountId = aRelatedAccountId;
       
   910         iAccounts->DeletePopAccountL( popId );
       
   911         }
       
   912 
       
   913     IMUM_OUT();
       
   914     }
       
   915 
       
   916 // ----------------------------------------------------------------------------
       
   917 // CImumMboxManager::DeleteBaseSettingsL()
       
   918 // ----------------------------------------------------------------------------
       
   919 //
       
   920 void CImumMboxManager::DeleteBaseSettingsL(
       
   921     const CImumMboxData& aSettings )
       
   922     {
       
   923     IMUM_CONTEXT( CImumMboxManager::DeleteBaseSettingsL, 0, KLogData );
       
   924     IMUM_IN();
       
   925 
       
   926     // Remove the related smtp accounts
       
   927     DeleteRelatedSmtpAccountsL( aSettings );
       
   928 
       
   929     // Determine the account type
       
   930     if ( aSettings.iIsImap4 )
       
   931         {
       
   932         // Remove the Imap4 account
       
   933         iAccounts->DeleteImapAccountL( aSettings.iImap4AccountId );
       
   934         }
       
   935     else
       
   936         {
       
   937         // Remove the Pop3 account
       
   938         iAccounts->DeletePopAccountL( aSettings.iPop3AccountId );
       
   939         }
       
   940 
       
   941     IMUM_OUT();
       
   942     }
       
   943 
       
   944 // ----------------------------------------------------------------------------
       
   945 // CImumMboxManager::DeleteAccountSettings()
       
   946 // ----------------------------------------------------------------------------
       
   947 //
       
   948 TInt CImumMboxManager::DeleteAccountSettings(
       
   949     const TUint32 aAccountId,
       
   950     const TUid& aMtmId )
       
   951     {
       
   952     IMUM_CONTEXT( CImumMboxManager::DeleteAccountSettings, 0, KLogData );
       
   953     IMUM_IN();
       
   954 
       
   955     TInt error = KErrNone;
       
   956 
       
   957     // Delete the related extended settings
       
   958     if ( aMtmId == KSenduiMtmImap4Uid )
       
   959         {
       
   960         // Delete Imap4 or Pop3 account
       
   961         TImapAccount imapId;
       
   962         imapId.iImapAccountId = aAccountId;
       
   963         TRAP( error, iAccounts->DeleteImapAccountL( imapId ) );
       
   964         }
       
   965     else if ( aMtmId == KSenduiMtmPop3Uid )
       
   966         {
       
   967         // Remove the Pop3 account
       
   968         TPopAccount popId;
       
   969         popId.iPopAccountId = aAccountId;
       
   970         TRAP( error, iAccounts->DeletePopAccountL( popId ) );
       
   971         }
       
   972     else
       
   973         {
       
   974         // Remove the Smtp account
       
   975         TSmtpAccount smtpId;
       
   976         smtpId.iSmtpAccountId = aAccountId;
       
   977         TRAP( error, iAccounts->DeleteSmtpAccountL( smtpId ) );
       
   978         }
       
   979 
       
   980     if ( aMtmId != KSenduiMtmSmtpUid )
       
   981         {
       
   982         DeleteExtendedSettings(
       
   983             TIMAStorerParams( aAccountId, aMtmId ) );
       
   984         }
       
   985 
       
   986     IMUM_OUT();
       
   987 
       
   988     return error;
       
   989     }
       
   990 
       
   991 // ---------------------------------------------------------------------------
       
   992 // CImumMboxManager::CheckAccountDeletionConditionsL()
       
   993 // ---------------------------------------------------------------------------
       
   994 //
       
   995 TBool CImumMboxManager::CheckAccountDeletionConditionsL(
       
   996     const TMsvId aMailboxId )
       
   997     {
       
   998     return AccountDeletionConditionsOkL( aMailboxId );
       
   999     }
       
  1000 
       
  1001 /******************************************************************************
       
  1002 
       
  1003     Account Saving
       
  1004 
       
  1005 ******************************************************************************/
       
  1006 
       
  1007 // ---------------------------------------------------------------------------
       
  1008 // CImumMboxManager::SaveEmailSettingsL()
       
  1009 // ---------------------------------------------------------------------------
       
  1010 //
       
  1011 void CImumMboxManager::SaveEmailSettingsL(
       
  1012     const CImumInSettingsData& aSettingsData )
       
  1013     {
       
  1014     IMUM_CONTEXT( CImumMboxManager::SaveEmailSettingsL, 0, KLogData );
       
  1015     IMUM_IN();
       
  1016 
       
  1017     CImumMboxData* settings =
       
  1018         CImumMboxSymbianDataConverter::ConvertToSymbianMboxDataLC(
       
  1019             iMailboxApi, aSettingsData );
       
  1020 
       
  1021     SaveEmailSettingsL( *settings );
       
  1022 
       
  1023     CleanupStack::PopAndDestroy( settings );
       
  1024     settings = NULL;
       
  1025 
       
  1026     IMUM_OUT();
       
  1027     }
       
  1028 
       
  1029 // ----------------------------------------------------------------------------
       
  1030 // CImumMboxManager::SaveEmailSettingsL()
       
  1031 // ----------------------------------------------------------------------------
       
  1032 //
       
  1033 TInt CImumMboxManager::SaveEmailSettingsL(
       
  1034     CImumMboxData& aSettings )
       
  1035     {
       
  1036     IMUM_CONTEXT( CImumMboxManager::SaveEmailSettingsL, 0, KLogData );
       
  1037     IMUM_IN();
       
  1038 
       
  1039     // If settings not ready, don't try to create
       
  1040     if ( !aSettings.IsOk() )
       
  1041         {
       
  1042         return KErrNotFound;
       
  1043         }
       
  1044 
       
  1045     TInt error = KErrNone;
       
  1046     CreateAccountFillIapL( aSettings );
       
  1047 
       
  1048     // Check for imap4
       
  1049     if ( aSettings.iIsImap4 )
       
  1050         {
       
  1051         // Catch all the problems with account creation
       
  1052         TRAP( error, SaveImap4SettingsL( aSettings ) );
       
  1053 
       
  1054         // Attempt to save the extended settings, even if other settings have
       
  1055         // failed to save
       
  1056         iMboxSettingsCtrl->SaveSettings( *aSettings.iExtendedSettings );
       
  1057         TRAP_IGNORE( StoreSignatureL( aSettings ) );
       
  1058         }
       
  1059     // It's a pop
       
  1060     else
       
  1061         {
       
  1062         // Catch all the problems with account creation
       
  1063         TRAP( error, SavePop3SettingsL( aSettings ) );
       
  1064 
       
  1065         // Attempt to save the extended settings, even if other settings have
       
  1066         // failed to save
       
  1067         iMboxSettingsCtrl->SaveSettings( *aSettings.iExtendedSettings );
       
  1068         TRAP_IGNORE( StoreSignatureL( aSettings ) );
       
  1069         }
       
  1070 
       
  1071     IMUM_OUT();
       
  1072 
       
  1073     return error;
       
  1074     }
       
  1075 
       
  1076 // ----------------------------------------------------------------------------
       
  1077 // CImumMboxManager::SavePop3SettingsL()
       
  1078 // ----------------------------------------------------------------------------
       
  1079 //
       
  1080 void CImumMboxManager::SavePop3SettingsL(
       
  1081     CImumMboxData& aSettings )
       
  1082     {
       
  1083     IMUM_CONTEXT( CImumMboxManager::SavePop3SettingsL, 0, KLogData );
       
  1084     IMUM_IN();
       
  1085 
       
  1086     TSmtpAccount smtpAccountId;
       
  1087     iAccounts->GetSmtpAccountL(
       
  1088         aSettings.iPop3AccountId.iSmtpService, smtpAccountId );
       
  1089 
       
  1090     // Store the mailbox name
       
  1091     aSettings.iPop3AccountId.iPopAccountName.Copy(
       
  1092         aSettings.iName );
       
  1093     smtpAccountId.iSmtpAccountName.Copy(
       
  1094         aSettings.iName );
       
  1095 
       
  1096     // Load mailbox settings
       
  1097     iAccounts->SavePopSettingsL(
       
  1098         aSettings.iPop3AccountId, *aSettings.iPop3Settings );
       
  1099     iAccounts->SavePopIapSettingsL(
       
  1100         aSettings.iPop3AccountId, *aSettings.iIncomingIapPref );
       
  1101     iAccounts->SaveSmtpSettingsL(
       
  1102         smtpAccountId, *aSettings.iSmtpSettings );
       
  1103     iAccounts->SaveSmtpIapSettingsL(
       
  1104         smtpAccountId, *aSettings.iOutgoingIapPref );
       
  1105 
       
  1106     IMUM_OUT();
       
  1107     }
       
  1108 
       
  1109 // ----------------------------------------------------------------------------
       
  1110 // CImumMboxManager::SaveImap4SettingsL()
       
  1111 // ----------------------------------------------------------------------------
       
  1112 //
       
  1113 void CImumMboxManager::SaveImap4SettingsL(
       
  1114     CImumMboxData& aSettings )
       
  1115     {
       
  1116     IMUM_CONTEXT( CImumMboxManager::SaveImap4SettingsL, 0, KLogData );
       
  1117     IMUM_IN();
       
  1118 
       
  1119     TSmtpAccount smtpAccountId;
       
  1120     iAccounts->GetSmtpAccountL(
       
  1121         aSettings.iImap4AccountId.iSmtpService, smtpAccountId );
       
  1122 
       
  1123     // Store the mailbox name
       
  1124     aSettings.iImap4AccountId.iImapAccountName.Copy(
       
  1125         aSettings.iName );
       
  1126     smtpAccountId.iSmtpAccountName.Copy(
       
  1127         aSettings.iName );
       
  1128 
       
  1129     // Load mailbox settings
       
  1130     iAccounts->SaveImapSettingsL(
       
  1131         aSettings.iImap4AccountId, *aSettings.iImap4Settings );
       
  1132     iAccounts->SaveImapIapSettingsL(
       
  1133         aSettings.iImap4AccountId, *aSettings.iIncomingIapPref );
       
  1134     iAccounts->SaveSmtpSettingsL(
       
  1135         smtpAccountId, *aSettings.iSmtpSettings );
       
  1136     iAccounts->SaveSmtpIapSettingsL(
       
  1137         smtpAccountId, *aSettings.iOutgoingIapPref );
       
  1138 
       
  1139     IMUM_OUT();
       
  1140     }
       
  1141 
       
  1142 // ----------------------------------------------------------------------------
       
  1143 // CImumMboxManager::StoreAccountIdToEntryL()
       
  1144 // ----------------------------------------------------------------------------
       
  1145 //
       
  1146 void CImumMboxManager::StoreAccountIdToEntryL(
       
  1147     const TMsvId aMailboxId,
       
  1148     const TUint32 aAccountId )
       
  1149     {
       
  1150     IMUM_CONTEXT( CImumMboxManager::StoreAccountIdToEntryL, 0, KLogData );
       
  1151     IMUM_IN();
       
  1152 
       
  1153     // Get the entry
       
  1154     CMsvEntry* cEntry = iMailboxApi.MsvSession().GetEntryL( aMailboxId );
       
  1155     CleanupStack::PushL( cEntry );
       
  1156 
       
  1157     // Store the value to the entry
       
  1158     TMsvEntry tEntry( cEntry->Entry() );
       
  1159     tEntry.iMtmData2 = aAccountId;
       
  1160     cEntry->ChangeL( tEntry );
       
  1161 
       
  1162     CleanupStack::PopAndDestroy( cEntry );
       
  1163     cEntry = NULL;
       
  1164 
       
  1165     IMUM_OUT();
       
  1166     }
       
  1167 
       
  1168 // ----------------------------------------------------------------------------
       
  1169 // CImumMboxManager::GetMailboxAccountIdsL()
       
  1170 // ----------------------------------------------------------------------------
       
  1171 //
       
  1172 void CImumMboxManager::GetMailboxAccountIdsL(
       
  1173     const TMsvId aMailboxId,
       
  1174     TMsvId& aReceivingMailboxId,
       
  1175     TUint32& aReceivingAccountId,
       
  1176     TMsvId& aSendingMailboxId,
       
  1177     TUint32& aSendingAccountId )
       
  1178     {
       
  1179     IMUM_CONTEXT( CImumMboxManager::GetMailboxAccountIdsL, 0, KLogData );
       
  1180     IMUM_IN();
       
  1181 
       
  1182     MImumInMailboxUtilities::RMsvEntryArray entries;
       
  1183     iMailboxApi.MailboxUtilitiesL().GetMailboxEntriesL(
       
  1184         aMailboxId, entries );
       
  1185     TMsvEntry receiving = entries[0];
       
  1186     TMsvEntry sending = entries[1];
       
  1187     entries.Reset();
       
  1188 
       
  1189     if ( receiving.iMtm == KSenduiMtmImap4Uid )
       
  1190         {
       
  1191         // Get Imap account id
       
  1192         TImapAccount imapAccountId;
       
  1193         iAccounts->GetImapAccountL( receiving.Id(), imapAccountId );
       
  1194 
       
  1195         aReceivingMailboxId = receiving.Id();
       
  1196         aReceivingAccountId = imapAccountId.iImapAccountId;
       
  1197         aSendingMailboxId = sending.Id();
       
  1198         }
       
  1199     else if ( receiving.iMtm == KSenduiMtmPop3Uid )
       
  1200         {
       
  1201         // Get Pop account id
       
  1202         TPopAccount popAccountId;
       
  1203         iAccounts->GetPopAccountL( receiving.Id(), popAccountId );
       
  1204 
       
  1205         aReceivingMailboxId = receiving.Id();
       
  1206         aReceivingAccountId = popAccountId.iPopAccountId;
       
  1207         aSendingMailboxId = sending.Id();
       
  1208         }
       
  1209     else
       
  1210         {
       
  1211         // This should not happen ever, but if it does for some reason
       
  1212         // then leave, as the leave will be trapped and the mailbox
       
  1213         // shall be removed after it
       
  1214         User::Leave( KErrUnknown );
       
  1215         }
       
  1216 
       
  1217     // Get smtp account id
       
  1218     TSmtpAccount smtpAccountId;
       
  1219     iAccounts->GetSmtpAccountL( aSendingMailboxId, smtpAccountId );
       
  1220 
       
  1221     aSendingAccountId = smtpAccountId.iSmtpAccountId;
       
  1222 
       
  1223     IMUM_OUT();
       
  1224     }
       
  1225 
       
  1226 // ----------------------------------------------------------------------------
       
  1227 // CImumMboxManager::StoreAccountIdToEntryL()
       
  1228 // ----------------------------------------------------------------------------
       
  1229 //
       
  1230 void CImumMboxManager::StoreAccountIdToEntryL(
       
  1231     CImumMboxData& aSettings )
       
  1232     {
       
  1233     IMUM_CONTEXT( CImumMboxManager::StoreAccountIdToEntryL, 0, KLogData );
       
  1234     IMUM_IN();
       
  1235 
       
  1236     TMsvId sendingMailboxId;
       
  1237     TMsvId receivingMailboxId;
       
  1238     TUint32 sendingAccountId;
       
  1239     TUint32 receivingAccountId;
       
  1240     GetMailboxAccountIdsL( aSettings.iMailboxId,
       
  1241         receivingMailboxId, receivingAccountId,
       
  1242         sendingMailboxId, sendingAccountId );
       
  1243 
       
  1244     StoreAccountIdToEntryL( receivingMailboxId, receivingAccountId );
       
  1245     StoreAccountIdToEntryL( sendingMailboxId, sendingAccountId );
       
  1246 
       
  1247     IMUM_OUT();
       
  1248     }
       
  1249 
       
  1250 /******************************************************************************
       
  1251 
       
  1252     Account Loading
       
  1253 
       
  1254 ******************************************************************************/
       
  1255 
       
  1256 // ----------------------------------------------------------------------------
       
  1257 // CImumMboxManager::LoadEmailSettingsL()
       
  1258 // ----------------------------------------------------------------------------
       
  1259 //
       
  1260 void CImumMboxManager::LoadEmailSettingsL(
       
  1261     const TMsvEntry& aEntry,
       
  1262     CImumMboxData& aSettings )
       
  1263     {
       
  1264     IMUM_CONTEXT( CImumMboxManager::LoadEmailSettingsL, 0, KLogData );
       
  1265     IMUM_IN();
       
  1266 
       
  1267     // Get both of the entries
       
  1268     TMsvEntry receiving = iMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
  1269         aEntry.Id(), MImumInMailboxUtilities::ERequestReceiving );
       
  1270 
       
  1271     // Store the id and protocol
       
  1272     aSettings.iMailboxId = receiving.iRelatedId;
       
  1273     aSettings.iIsImap4 = ( receiving.iMtm == KSenduiMtmImap4Uid );
       
  1274 
       
  1275     // Load settings based on the protocol
       
  1276     if ( aSettings.iIsImap4 )
       
  1277         {
       
  1278         iAccounts->GetImapAccountL(
       
  1279             receiving.Id(), aSettings.iImap4AccountId );
       
  1280         LoadImap4SettingsL( aSettings );
       
  1281 
       
  1282         // Load extended settings
       
  1283         TUint32 accountId = aSettings.iImap4AccountId.iImapAccountId;
       
  1284         iMboxSettingsCtrl->LoadSettings(
       
  1285             TIMAStorerParams( accountId, receiving.iMtm ),
       
  1286             *aSettings.iExtendedSettings );
       
  1287 
       
  1288         // Attempt to read the signature
       
  1289         TRAP_IGNORE( RestoreSignatureL( aSettings ) );
       
  1290         }
       
  1291     else // pop3
       
  1292         {
       
  1293         iAccounts->GetPopAccountL(
       
  1294             receiving.Id(), aSettings.iPop3AccountId );
       
  1295         LoadPop3SettingsL( aSettings );
       
  1296 
       
  1297         // Load extended settings
       
  1298         TUint32 accountId = aSettings.iPop3AccountId.iPopAccountId;
       
  1299         iMboxSettingsCtrl->LoadSettings(
       
  1300             TIMAStorerParams( accountId, receiving.iMtm ),
       
  1301             *aSettings.iExtendedSettings );
       
  1302 
       
  1303         // Attempt to read the signature
       
  1304         TRAP_IGNORE( RestoreSignatureL( aSettings ) );
       
  1305         }
       
  1306 
       
  1307     IMUM_OUT();
       
  1308     }
       
  1309 
       
  1310 // ---------------------------------------------------------------------------
       
  1311 // CImumMboxManager::LoadEmailSettingsL()
       
  1312 // ---------------------------------------------------------------------------
       
  1313 //
       
  1314 CImumInSettingsData* CImumMboxManager::LoadEmailSettingsL(
       
  1315     const TMsvId aMailboxId )
       
  1316     {
       
  1317     IMUM_CONTEXT( CImumMboxManager::LoadEmailSettingsL, 0, KLogData );
       
  1318     IMUM_IN();
       
  1319 
       
  1320     CImumMboxData* oldData = CImumMboxData::NewLC();
       
  1321     TMsvEntry mailbox =
       
  1322         iMailboxApi.MailboxUtilitiesL().GetMailboxEntryL( aMailboxId );
       
  1323     LoadEmailSettingsL( mailbox, *oldData );
       
  1324 
       
  1325     CImumInSettingsData* internalData =
       
  1326         CImumMboxInternalDataConverter::ConvertToInternalMboxDataLC(
       
  1327             iMailboxApi, *oldData );
       
  1328     CleanupStack::Pop( internalData );
       
  1329     CleanupStack::PopAndDestroy( oldData );
       
  1330     oldData = NULL;
       
  1331 
       
  1332     IMUM_OUT();
       
  1333 
       
  1334     return internalData;
       
  1335     }
       
  1336 
       
  1337 // ----------------------------------------------------------------------------
       
  1338 // CImumMboxManager::LoadPop3SettingsL()
       
  1339 // ----------------------------------------------------------------------------
       
  1340 //
       
  1341 void CImumMboxManager::LoadPop3SettingsL(
       
  1342     CImumMboxData& aSettings )
       
  1343     {
       
  1344     IMUM_CONTEXT( CImumMboxManager::LoadPop3SettingsL, 0, KLogData );
       
  1345     IMUM_IN();
       
  1346 
       
  1347     TSmtpAccount smtpAccountId;
       
  1348     iAccounts->GetSmtpAccountL(
       
  1349         aSettings.iPop3AccountId.iSmtpService, smtpAccountId );
       
  1350 
       
  1351     // Load mailbox settings
       
  1352     iAccounts->LoadPopSettingsL(
       
  1353         aSettings.iPop3AccountId, *aSettings.iPop3Settings );
       
  1354     iAccounts->LoadPopIapSettingsL(
       
  1355         aSettings.iPop3AccountId, *aSettings.iIncomingIapPref );
       
  1356     iAccounts->LoadSmtpSettingsL(
       
  1357         smtpAccountId, *aSettings.iSmtpSettings );
       
  1358     iAccounts->LoadSmtpIapSettingsL(
       
  1359         smtpAccountId, *aSettings.iOutgoingIapPref );
       
  1360 
       
  1361     LoadAccountFillIapL( aSettings );
       
  1362     aSettings.iName.Copy( aSettings.iPop3AccountId.iPopAccountName );
       
  1363 
       
  1364     IMUM_OUT();
       
  1365     }
       
  1366 
       
  1367 // ----------------------------------------------------------------------------
       
  1368 // CImumMboxManager::LoadImap4SettingsL()
       
  1369 // ----------------------------------------------------------------------------
       
  1370 //
       
  1371 void CImumMboxManager::LoadImap4SettingsL(
       
  1372     CImumMboxData& aSettings )
       
  1373     {
       
  1374     IMUM_CONTEXT( CImumMboxManager::LoadImap4SettingsL, 0, KLogData );
       
  1375     IMUM_IN();
       
  1376 
       
  1377     TSmtpAccount smtpAccountId;
       
  1378     iAccounts->GetSmtpAccountL(
       
  1379         aSettings.iImap4AccountId.iSmtpService, smtpAccountId );
       
  1380 
       
  1381     // Load mailbox settings
       
  1382     iAccounts->LoadImapSettingsL(
       
  1383         aSettings.iImap4AccountId, *aSettings.iImap4Settings );
       
  1384     iAccounts->LoadImapIapSettingsL(
       
  1385         aSettings.iImap4AccountId, *aSettings.iIncomingIapPref );
       
  1386     iAccounts->LoadSmtpSettingsL(
       
  1387         smtpAccountId, *aSettings.iSmtpSettings );
       
  1388     iAccounts->LoadSmtpIapSettingsL(
       
  1389         smtpAccountId, *aSettings.iOutgoingIapPref );
       
  1390 
       
  1391     LoadAccountFillIapL( aSettings );
       
  1392     aSettings.iName.Copy( aSettings.iImap4AccountId.iImapAccountName );
       
  1393 
       
  1394     IMUM_OUT();
       
  1395     }
       
  1396 
       
  1397 /******************************************************************************
       
  1398 
       
  1399     MISC TOOLS
       
  1400 
       
  1401 ******************************************************************************/
       
  1402 
       
  1403 // ----------------------------------------------------------------------------
       
  1404 // CImumMboxManager::StoreSignatureL()
       
  1405 // ----------------------------------------------------------------------------
       
  1406 //
       
  1407 void CImumMboxManager::StoreSignatureL(
       
  1408     const CImumMboxData& aSettings )
       
  1409     {
       
  1410     IMUM_CONTEXT( CImumMboxManager::StoreSignatureL, 0, KLogData );
       
  1411     IMUM_IN();
       
  1412 
       
  1413     // Get Signature
       
  1414     CMsvEntry* entry = iMailboxApi.MsvSession().GetEntryL( aSettings.iMailboxId );
       
  1415     CleanupStack::PushL( entry );
       
  1416     CMsvStore* msvStore = entry->EditStoreL();
       
  1417     CleanupStack::PushL( msvStore );
       
  1418 
       
  1419     msvStore->StoreBodyTextL( *( aSettings.iSignature->iRichText ) );
       
  1420     msvStore->CommitL();
       
  1421 
       
  1422     CleanupStack::PopAndDestroy( msvStore );
       
  1423     msvStore = NULL;
       
  1424     CleanupStack::PopAndDestroy( entry );
       
  1425     entry = NULL;
       
  1426 
       
  1427     IMUM_OUT();
       
  1428     }
       
  1429 
       
  1430 // ----------------------------------------------------------------------------
       
  1431 // CImumMboxManager::RestoreSignatureL()
       
  1432 // ----------------------------------------------------------------------------
       
  1433 //
       
  1434 void CImumMboxManager::RestoreSignatureL(
       
  1435     CImumMboxData& aSettings )
       
  1436     {
       
  1437     IMUM_CONTEXT( CImumMboxManager::RestoreSignatureL, 0, KLogData );
       
  1438     IMUM_IN();
       
  1439 
       
  1440     // Get Signature
       
  1441     CMsvEntry* entry = iMailboxApi.MsvSession().GetEntryL( aSettings.iMailboxId );
       
  1442     CleanupStack::PushL( entry );
       
  1443     CMsvStore* msvStore = entry->ReadStoreL();
       
  1444     CleanupStack::PushL( msvStore );
       
  1445 
       
  1446     aSettings.iSignature->CreateEmptyRichTextL();
       
  1447     msvStore->RestoreBodyTextL( *( aSettings.iSignature->iRichText ) );
       
  1448 
       
  1449     CleanupStack::PopAndDestroy( msvStore );
       
  1450     msvStore = NULL;
       
  1451     CleanupStack::PopAndDestroy( entry );
       
  1452     entry = NULL;
       
  1453 
       
  1454     IMUM_OUT();
       
  1455     }
       
  1456 
       
  1457 // ---------------------------------------------------------------------------
       
  1458 // CImumMboxManager::IsConnectedL()
       
  1459 // ---------------------------------------------------------------------------
       
  1460 //
       
  1461 TBool CImumMboxManager::IsConnectedL( const TMsvId aMailboxId ) const
       
  1462     {
       
  1463     IMUM_CONTEXT( CImumMboxManager::IsConnectedL, 0, KLogData );
       
  1464     IMUM_IN();
       
  1465 
       
  1466     TBool connected = EFalse;
       
  1467 
       
  1468     // Make sure that none of the entries is in connected state
       
  1469     MImumInMailboxUtilities::RMsvEntryArray entries;
       
  1470     iMailboxApi.MailboxUtilitiesL().GetMailboxEntriesL(
       
  1471         aMailboxId, entries );
       
  1472     CleanupClosePushL( entries );
       
  1473 
       
  1474     for ( TInt mbox = entries.Count(); --mbox >= 0 && !connected; )
       
  1475         {
       
  1476         connected = entries[mbox].Connected();
       
  1477         }
       
  1478 
       
  1479     CleanupStack::PopAndDestroy( &entries );
       
  1480 
       
  1481     IMUM_OUT();
       
  1482 
       
  1483     return connected;
       
  1484     }
       
  1485 
       
  1486 // ---------------------------------------------------------------------------
       
  1487 // CImumMboxManager::IsLockedL()
       
  1488 // ---------------------------------------------------------------------------
       
  1489 //
       
  1490 TBool CImumMboxManager::IsLockedL( const TMsvId aMailboxId ) const
       
  1491     {
       
  1492     IMUM_CONTEXT( CImumMboxManager::IsLockedL, 0, KLogData );
       
  1493     IMUM_IN();
       
  1494 
       
  1495     TBool isLocked = EFalse;
       
  1496     CMsvEntry* centry =
       
  1497         iMailboxApi.MsvSession().GetEntryL( aMailboxId );
       
  1498     CleanupStack::PushL( centry );
       
  1499 
       
  1500     // If the entry is locked, deletion should not be possible
       
  1501     TRAPD( err, centry->ChangeL( centry->Entry() ) );
       
  1502     if( err != KErrNone )
       
  1503         {
       
  1504         isLocked = ETrue;
       
  1505         }
       
  1506 
       
  1507     CleanupStack::PopAndDestroy( centry );
       
  1508     centry = NULL;
       
  1509 
       
  1510     IMUM_OUT();
       
  1511 
       
  1512     return isLocked;
       
  1513     }
       
  1514 
       
  1515 // ----------------------------------------------------------------------------
       
  1516 // CImumMboxManager::HandleMailboxInUseDeleteL()
       
  1517 // ----------------------------------------------------------------------------
       
  1518 //
       
  1519 TBool CImumMboxManager::HandleMailboxInUseDeleteL(
       
  1520     MImumInHealthServices::RMailboxIdArray& aMailboxes,
       
  1521     const TMsvEntry& aSmtpEntry ) const
       
  1522     {
       
  1523     IMUM_CONTEXT( CImumMboxManager::HandleMailboxInUseDeleteL, 0, KLogData );
       
  1524     IMUM_IN();
       
  1525     TBool continueDeletion(ETrue);
       
  1526     TMsvId newDefaultId = 0;
       
  1527     TInt mailboxCount = aMailboxes.Count();
       
  1528     if ( mailboxCount == 2 ) // CSI: 47 # Mailbox count.
       
  1529         {
       
  1530         // set default to be the other one
       
  1531         TInt newDefaultIndex =
       
  1532             ( aSmtpEntry.Id() == aMailboxes[0] ) ? 1 : 0;
       
  1533         newDefaultId = aMailboxes[newDefaultIndex];
       
  1534         }
       
  1535     else
       
  1536         {
       
  1537         // To show mailbox name list, the array must be constructed here
       
  1538         CDesCArrayFlat* items =
       
  1539             new ( ELeave ) CDesCArrayFlat( KImumMboxArrayGranularity );
       
  1540         CleanupStack::PushL( items );
       
  1541 
       
  1542         TMsvEntry tempEntry;
       
  1543         TInt delIndex=-1;
       
  1544         for (TInt loop = 0; loop < mailboxCount; loop++)
       
  1545             {
       
  1546             TMsvId tempServiceId;
       
  1547             User::LeaveIfError( iMailboxApi.MsvSession().GetEntry(
       
  1548                 aMailboxes[loop],
       
  1549                 tempServiceId,
       
  1550                 tempEntry ) );
       
  1551             if ( aSmtpEntry.Id() != tempEntry.Id() )
       
  1552                 {
       
  1553                 items->AppendL( tempEntry.iDetails );
       
  1554                 }
       
  1555             else
       
  1556                 {
       
  1557                 delIndex = loop;
       
  1558                 }
       
  1559             }
       
  1560         if ( delIndex>=0 )
       
  1561             {
       
  1562             //take the mailbox to be deleted off from the array
       
  1563             aMailboxes.Remove(delIndex);
       
  1564             }
       
  1565 
       
  1566         TInt index = 0;
       
  1567         CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog(&index);
       
  1568         dlg->PrepareLC( R_IMUM_NEW_DEFAULT_MAILBOX_LIST_QUERY );
       
  1569         dlg->SetItemTextArray( items );
       
  1570         dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
  1571         if ( dlg->RunLD( ) == EEikBidOk )
       
  1572             {
       
  1573             newDefaultId = aMailboxes[index];
       
  1574             }
       
  1575         else
       
  1576             {
       
  1577             continueDeletion = EFalse;
       
  1578             }
       
  1579 
       
  1580         CleanupStack::PopAndDestroy( items );  // items
       
  1581         items = NULL;
       
  1582         }
       
  1583 
       
  1584     if ( newDefaultId )
       
  1585         {
       
  1586         // Set default
       
  1587         MsvUiServiceUtilitiesInternal::SetDefaultServiceForMTML(
       
  1588                 iMailboxApi.MsvSession(),
       
  1589                 KSenduiMtmSmtpUid,
       
  1590                 newDefaultId );
       
  1591         }
       
  1592 
       
  1593     IMUM_OUT();
       
  1594     return continueDeletion;
       
  1595     }
       
  1596 
       
  1597 // ---------------------------------------------------------------------------
       
  1598 // CImumMboxManager::AccountDeletionConditionsOkL()
       
  1599 // ---------------------------------------------------------------------------
       
  1600 //
       
  1601 TBool CImumMboxManager::AccountDeletionConditionsOkL(
       
  1602     const TMsvId aMailboxId )
       
  1603     {
       
  1604     IMUM_CONTEXT( CImumMboxManager::AccountDeletionConditionsOkL, 0, KLogData );
       
  1605     IMUM_IN();
       
  1606 
       
  1607     TBool conditionsOk = EFalse;
       
  1608 
       
  1609     // Entry is required to get the name of the mailbox Id
       
  1610     TMsvEntry mailbox = iMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
  1611         aMailboxId, MImumInMailboxUtilities::ERequestSending );
       
  1612     TBuf<KImumMboxQueryTextLength> name;
       
  1613     name.Copy( mailbox.iDetails.Left( KImumMboxQueryTextLength ) );
       
  1614     TUid mtm = KSenduiMtmSmtpUid;
       
  1615 
       
  1616     TMsvId defaultService = MsvUiServiceUtilitiesInternal::
       
  1617             DefaultServiceForMTML(
       
  1618                 iMailboxApi.MsvSession(), mtm, EFalse );
       
  1619 
       
  1620     // Get the list of available mailboxes
       
  1621     MImumInHealthServices::RMailboxIdArray mailboxes;
       
  1622     iMailboxApi.HealthServicesL().GetMailboxList( mailboxes, 
       
  1623         MImumInHealthServices::EFlagGetHealthy | 
       
  1624         MImumInHealthServices::EFlagIncludeSmtp );
       
  1625     CleanupClosePushL( mailboxes );
       
  1626 
       
  1627     // Don't allow locked or connected mailboxes to be deleted
       
  1628     if ( IsConnectedL( aMailboxId ) ||
       
  1629          IsLockedL( mailbox.Id() ) )
       
  1630         {
       
  1631         CIMSSettingsNoteUi::ShowNoteL(
       
  1632             R_IMUM_SETTINGS_MAIL_NO_DELETE, EIMSInformationNote, ETrue );
       
  1633         }
       
  1634     //
       
  1635     else if ( mailboxes.Count() == 1 )
       
  1636         {
       
  1637         conditionsOk =
       
  1638             CIMSSettingsNoteUi::ShowQueryL<KImumMboxQueryTextLength>(
       
  1639                 R_IMUM_SETTINGS_MAIL_QUEST_DEL,
       
  1640                 mailbox.iDetails );
       
  1641 
       
  1642         }
       
  1643     // If the current mailbox is not default, it can be deleted
       
  1644     // immediately.
       
  1645     else if ( mailbox.Id() != defaultService )
       
  1646         {
       
  1647         conditionsOk =
       
  1648             CIMSSettingsNoteUi::ShowQueryL<KImumMboxQueryTextLength>(
       
  1649                 R_IMUM_COMMON_CONF_DELETE,
       
  1650                 mailbox.iDetails );
       
  1651         }
       
  1652     else
       
  1653         {
       
  1654         conditionsOk =
       
  1655             CIMSSettingsNoteUi::ShowQueryL<KImumMboxQueryTextLength>(
       
  1656                 R_IMUM_SETTINGS_MAIL_QUEST_D,
       
  1657                 mailbox.iDetails );
       
  1658 
       
  1659         if ( conditionsOk )
       
  1660             {
       
  1661             conditionsOk = HandleMailboxInUseDeleteL( mailboxes, mailbox );
       
  1662             }
       
  1663         }
       
  1664 
       
  1665     CleanupStack::PopAndDestroy( &mailboxes );
       
  1666 
       
  1667     IMUM_OUT();
       
  1668     return conditionsOk;
       
  1669     }
       
  1670 
       
  1671 
       
  1672 // End Of File
       
  1673