email/imum/Utils/Src/ImumInMailboxUtilitiesImpl.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:  ImumInMailboxUtilitiesImpl.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <SendUiConsts.h>
       
    21 #include <msvapi.h>                         // CMsvSession
       
    22 #include <msvstd.hrh>                       // Constants
       
    23 #include <mtudreg.h>                        // CMtmUiDataRegistry
       
    24 #include <cemailaccounts.h>                 // CEmailAccounts
       
    25 #include <iapprefs.h>                       // CImIAPPreferences
       
    26 
       
    27 #include "ImumInMailboxUtilitiesImpl.h"
       
    28 #include "ImumInMailboxServicesImpl.h"
       
    29 #include "ImumInternalApiImpl.h"
       
    30 #include "ImumMboxManager.h"                // CImumMboxManager
       
    31 #include "ImumMboxScheduler.h"              // CImumMboxSchdeuler
       
    32 #include "ImumUtilsLogging.h"
       
    33 #include "muiuemailtools.h"
       
    34 #include "ComDbUtl.h"
       
    35 
       
    36 // CONSTANTS
       
    37 _LIT( KImumInImapInboxName,"INBOX");
       
    38 
       
    39 // ================ CLASS CONSTRUCTION ================
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CImumInMailboxUtilitiesImpl::CImumInMailboxUtilitiesImpl()
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CImumInMailboxUtilitiesImpl::CImumInMailboxUtilitiesImpl(
       
    46     CImumInternalApiImpl& aMailboxApi )
       
    47     :
       
    48     iMailboxApi( aMailboxApi )
       
    49     {
       
    50     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::CImumInMailboxUtilitiesImpl, 0, KLogInApi );
       
    51     IMUM_IN();
       
    52     IMUM_OUT();
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CImumInMailboxUtilitiesImpl::~CImumInMailboxUtilitiesImpl()
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CImumInMailboxUtilitiesImpl::~CImumInMailboxUtilitiesImpl()
       
    60     {
       
    61     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::~CImumInMailboxUtilitiesImpl, 0, KLogInApi );
       
    62     IMUM_IN();
       
    63 
       
    64     delete iMtmUiDataRegistry;
       
    65     iMtmUiDataRegistry = NULL;
       
    66 
       
    67     IMUM_OUT();
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CImumInMailboxUtilitiesImpl::NewL()
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CImumInMailboxUtilitiesImpl* CImumInMailboxUtilitiesImpl::NewL(
       
    75     CImumInternalApiImpl& aMailboxApi )
       
    76     {
       
    77     IMUM_STATIC_CONTEXT( CImumInMailboxUtilitiesImpl::NewL, 0, utils, KLogInApi );
       
    78     IMUM_IN();
       
    79 
       
    80     CImumInMailboxUtilitiesImpl* self = NewLC( aMailboxApi );
       
    81     CleanupStack::Pop( self );
       
    82 
       
    83     IMUM_OUT();
       
    84 
       
    85     return self;
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CImumInMailboxUtilitiesImpl::NewLC()
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 CImumInMailboxUtilitiesImpl* CImumInMailboxUtilitiesImpl::NewLC(
       
    93     CImumInternalApiImpl& aMailboxApi )
       
    94     {
       
    95     IMUM_STATIC_CONTEXT( CImumInMailboxUtilitiesImpl::NewLC, 0, utils, KLogInApi );
       
    96     IMUM_IN();
       
    97 
       
    98     CImumInMailboxUtilitiesImpl* self =
       
    99         new ( ELeave ) CImumInMailboxUtilitiesImpl( aMailboxApi );
       
   100     CleanupStack::PushL( self );
       
   101 
       
   102     self->ConstructL();
       
   103 
       
   104     IMUM_OUT();
       
   105 
       
   106     return self;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CImumInMailboxUtilitiesImpl::ConstructL()
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CImumInMailboxUtilitiesImpl::ConstructL()
       
   114     {
       
   115     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::ConstructL, 0, KLogInApi );
       
   116     IMUM_IN();
       
   117 
       
   118     iMtmUiDataRegistry = CMtmUiDataRegistry::NewL( iMailboxApi.MsvSession() );
       
   119 
       
   120     IMUM_OUT();
       
   121     }
       
   122 
       
   123 // ================ INTERFACE IMPLEMENTATION ================
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // From class MImumInMailboxUtilities.
       
   127 // CImumInMailboxUtilitiesImpl::DefaultMailbox()
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 TMsvId CImumInMailboxUtilitiesImpl::DefaultMailboxId(
       
   131     const TBool aForceGet ) const
       
   132     {
       
   133     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::DefaultMailboxId, 0, KLogInApi );
       
   134     IMUM_IN();
       
   135 
       
   136     TMsvId defaultId = KMsvUnknownServiceIndexEntryId;
       
   137 
       
   138     //Should not leave, defaultId is just unknown
       
   139     TRAP_IGNORE( defaultId = DefaultMailboxIdL( aForceGet ) );
       
   140 
       
   141     IMUM1(0,"Default mailbox: 0x%x", defaultId );
       
   142     IMUM_OUT();
       
   143 
       
   144     return defaultId;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // From class MImumInMailboxUtilities.
       
   149 // CImumInMailboxUtilitiesImpl::IsMailMtm()
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 TBool CImumInMailboxUtilitiesImpl::IsMailMtm(
       
   153     const TUid& aMtm,
       
   154     const TBool& aAllowExtended ) const
       
   155     {
       
   156     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::IsMailMtm, 0, KLogInApi );
       
   157     IMUM_IN();
       
   158 
       
   159     // Basic mail mtm's
       
   160     TBool basicMtms =
       
   161         ( aMtm == KSenduiMtmSmtpUid ) ||
       
   162         ( aMtm == KSenduiMtmPop3Uid ) ||
       
   163         ( aMtm == KSenduiMtmImap4Uid );
       
   164 
       
   165     // Extended mail mtm's
       
   166     // Check if mailbox is 3rd party mailbox.
       
   167     TBool extendedMtms = EFalse;
       
   168     
       
   169     if( aAllowExtended && !basicMtms )
       
   170     	{
       
   171         // We donīt know 3rd party mailbox uid values so technology type
       
   172         // is compared instead.
       
   173     	if( iMtmUiDataRegistry->IsPresent( aMtm ) )
       
   174     	    {
       
   175             const TUid& technologyType =
       
   176                 iMtmUiDataRegistry->TechnologyTypeUid( aMtm );
       
   177             extendedMtms = ( KSenduiTechnologyMailUid == technologyType );
       
   178     	    }
       
   179     	}
       
   180 
       
   181     IMUM_OUT();
       
   182 
       
   183     // Returns ETrue, if the id is any of the following
       
   184     return basicMtms || ( aAllowExtended && extendedMtms );
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // From class MImumInMailboxUtilities.
       
   189 // CImumInMailboxUtilitiesImpl::IsMailbox()
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TBool CImumInMailboxUtilitiesImpl::IsMailbox( const TMsvId aMailboxId ) const
       
   193     {
       
   194     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::IsMailbox, 0, KLogInApi );
       
   195     IMUM_IN();
       
   196 
       
   197     // First get the entry and make sure it is a service
       
   198     TBool isMailbox = EFalse;
       
   199     TMsvId serviceId;
       
   200     TMsvEntry entry;
       
   201     if ( !iMailboxApi.MsvSession().GetEntry( aMailboxId, serviceId, entry ) &&
       
   202           entry.iType.iUid == KUidMsvServiceEntryValue )
       
   203         {
       
   204         // Get the technology type of the entry
       
   205         const TUid& technologyType =
       
   206             iMtmUiDataRegistry->TechnologyTypeUid( entry.iMtm );
       
   207 
       
   208         // Match with mail technology type
       
   209         isMailbox = ( KSenduiTechnologyMailUid == technologyType );
       
   210         }
       
   211 
       
   212     IMUM_OUT();
       
   213 
       
   214     return isMailbox;
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // From class MImumInMailboxUtilities.
       
   219 // CImumInMailboxUtilitiesImpl::IsMailbox()
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 TBool CImumInMailboxUtilitiesImpl::IsMailbox(
       
   223     const TMsvEntry& aEntry ) const
       
   224     {
       
   225     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::IsMailbox, 0, KLogInApi );
       
   226     IMUM_IN();
       
   227 
       
   228     // At first, make sure the entry is a service
       
   229     if ( aEntry.iType.iUid == KUidMsvServiceEntryValue )
       
   230         {
       
   231         // Get the technology type of the entry
       
   232         const TUid& technologyType =
       
   233             iMtmUiDataRegistry->TechnologyTypeUid( aEntry.iMtm );
       
   234 
       
   235         // Match with mail technology type
       
   236         return ( KSenduiTechnologyMailUid == technologyType );
       
   237         }
       
   238 
       
   239     IMUM_OUT();
       
   240 
       
   241     return EFalse;
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // From class MImumInMailboxUtilities.
       
   246 // CImumInMailboxUtilitiesImpl::GetMailboxL()
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 TMsvEntry CImumInMailboxUtilitiesImpl::GetMailboxEntryL(
       
   250     const TMsvId aMailboxId,
       
   251     const TImumInMboxRequest& aType,
       
   252     const TBool aServiceCheck ) const
       
   253     {
       
   254     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::GetMailboxEntryL, 0, KLogInApi );
       
   255     IMUM_IN();
       
   256 
       
   257     // Get the entry based on mailbox id
       
   258     TMsvId serviceId;
       
   259     TMsvEntry entry;
       
   260     User::LeaveIfError( iMailboxApi.MsvSession().GetEntry(
       
   261         aMailboxId, serviceId, entry ) );
       
   262 
       
   263     // Make sure the id is mailbox
       
   264     if ( !( aServiceCheck && !IsMailbox( entry ) ) )
       
   265         {
       
   266         // Continue handling, if successful
       
   267         if ( aType != ERequestCurrent )
       
   268             {
       
   269             TInt32 mtm = entry.iMtm.iUid;
       
   270 
       
   271             // Get related entry, if:
       
   272             // Mailbox type is smtp and pop3 or imap4 is wanted OR
       
   273             // Mailbox type is pop3 or imap4 and smtp is wanted
       
   274             if ( aType == ERequestSending && mtm != KSenduiMtmSmtpUidValue ||
       
   275                  aType == ERequestReceiving && mtm == KSenduiMtmSmtpUidValue )
       
   276                 {
       
   277                 User::LeaveIfError( iMailboxApi.MsvSession().GetEntry(
       
   278                     entry.iRelatedId, serviceId, entry ) );
       
   279                 }
       
   280             }
       
   281         }
       
   282     else
       
   283         {
       
   284         User::Leave( KErrUnknown );
       
   285         }
       
   286 
       
   287     IMUM_OUT();
       
   288 
       
   289     return entry;
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // From class MImumInMailboxUtilities.
       
   294 // CImumInMailboxUtilitiesImpl::GetMailboxEntriesL()
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 const TUid& CImumInMailboxUtilitiesImpl::GetMailboxEntriesL(
       
   298     const TMsvId aMailboxId,
       
   299     RMsvEntryArray& aEntries,
       
   300     const TBool aResetArray ) const
       
   301     {
       
   302     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::GetMailboxEntriesL, 0, KLogInApi );
       
   303     IMUM_IN();
       
   304 
       
   305     // Reset the array on request
       
   306     if ( aResetArray )
       
   307         {
       
   308         aEntries.Reset();
       
   309         }
       
   310 
       
   311     // Get the entries
       
   312     aEntries.Append( GetMailboxEntryL( aMailboxId, ERequestReceiving ) );
       
   313     aEntries.Append( GetMailboxEntryL( aMailboxId, ERequestSending ) );
       
   314 
       
   315     IMUM_OUT();
       
   316 
       
   317     // return the mtm id
       
   318     return aEntries[0].iMtm;
       
   319     }
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // From class MImumInMailboxUtilities.
       
   323 // CImumInMailboxUtilitiesImpl::IsInbox()
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 TBool CImumInMailboxUtilitiesImpl::IsInbox(
       
   327     const TMsvEntry& aFolderEntry ) const
       
   328     {
       
   329     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::IsInbox, 0, KLogInApi );
       
   330     IMUM_IN();
       
   331 
       
   332     TBool isInbox( EFalse );
       
   333     if ( aFolderEntry.iDetails.CompareF( KImumInImapInboxName ) == 0 )
       
   334         {
       
   335         // If parent is Mailbox service, then this is IMAP4 protocol inbox,
       
   336         // otherwise it is something else...
       
   337         TMsvId serviceId;
       
   338         TMsvEntry entry;
       
   339         TInt error = iMailboxApi.MsvSession().GetEntry(
       
   340             aFolderEntry.Parent(), serviceId, entry );
       
   341         if ( ( error == KErrNone ) && ( entry.Id() == serviceId ) )
       
   342             {
       
   343             isInbox = ETrue;
       
   344             }
       
   345         }
       
   346 
       
   347     IMUM_OUT();
       
   348 
       
   349     return isInbox;
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // From class MImumInMailboxUtilities.
       
   354 // CImumInMailboxUtilitiesImpl::HasWlanConnectionL()
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 TBool CImumInMailboxUtilitiesImpl::HasWlanConnectionL(
       
   358     const TMsvId aMailboxId ) const
       
   359     {
       
   360     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::HasWlanConnectionL, 0, KLogInApi );
       
   361     IMUM_IN();
       
   362 
       
   363     // Connecting to WLAN accesspoint is allowed to offline mode also,
       
   364     // so return ETrue if WLAN access point
       
   365     TBool wlanIap = EFalse;
       
   366 
       
   367     CEmailAccounts* account = CEmailAccounts::NewLC();
       
   368     CImIAPPreferences* iapPreferences = CImIAPPreferences::NewLC();
       
   369 
       
   370     TMsvId serviceId;
       
   371     TMsvEntry mailbox;
       
   372     TInt error = iMailboxApi.MsvSession().GetEntry( aMailboxId,
       
   373     												serviceId,
       
   374     												mailbox );
       
   375 
       
   376     // In some cases the mailId is passed to this method instead of the actual mailboxId so we
       
   377     // need to check the owningService as well.
       
   378     CMsvEntry* owningEntry = iMailboxApi.MsvSession().GetEntryL(aMailboxId);
       
   379     CleanupStack::PushL( owningEntry );
       
   380     TMsvId owningService = owningEntry->OwningService();
       
   381     CleanupStack::PopAndDestroy( owningEntry );
       
   382 
       
   383     // Make sure that the entry belongs to mailbox
       
   384     if ( !IsMailbox( mailbox ) )
       
   385     	{
       
   386     	if ( !IsMailbox( owningService ) )
       
   387         	{
       
   388         	IMUM0(0, "Not a mailbox");
       
   389         	error = KErrNotSupported;
       
   390         	}
       
   391         }
       
   392 
       
   393     if ( error == KErrNone )
       
   394         {
       
   395         IMUM0(0, "Retrieving preferences");
       
   396         error = CImumMboxManager::GetIapPreferencesL(
       
   397             serviceId,
       
   398             *account,
       
   399             *iapPreferences,
       
   400             iMailboxApi,
       
   401             ( mailbox.iMtm == KSenduiMtmSmtpUid ) );
       
   402         }
       
   403 
       
   404     if ( error == KErrNone && iapPreferences->NumberOfIAPs() )
       
   405         {
       
   406         IMUM0(0, "Accesspoints exist");
       
   407         TImIAPChoice iap = iapPreferences->IAPPreference( 0 );
       
   408 
       
   409         // Do not allow always ask
       
   410         if ( iap.iIAP > 0 )
       
   411             {
       
   412             CMsvCommDbUtilities* dbUtils = CMsvCommDbUtilities::NewLC();
       
   413 
       
   414             TRAPD( error, wlanIap = dbUtils->IsWlanAccessPointL( iap.iIAP ) );
       
   415             // If access point item is not found, force always ask
       
   416             if ( error )
       
   417                 {
       
   418                 CImumMboxManager::ForceAlwaysAskL(
       
   419                     serviceId,
       
   420                     *account,
       
   421                     *iapPreferences,
       
   422                     iMailboxApi,
       
   423                     EFalse );
       
   424                 wlanIap = ETrue;
       
   425                 }
       
   426             CleanupStack::PopAndDestroy(); // dbUtils
       
   427             }
       
   428         else
       
   429             {
       
   430             // Return ETrue for the always ask
       
   431             wlanIap = ETrue;
       
   432             }
       
   433         }
       
   434     CleanupStack::PopAndDestroy( 2, account ); // CSI: 47 # iapPreferences, account.
       
   435 
       
   436     IMUM_OUT();
       
   437     return wlanIap;
       
   438     }
       
   439 
       
   440 // ----------------------------------------------------------------------------
       
   441 // From class MImumInMailboxUtilities.
       
   442 // CImumInMailboxUtilitiesImpl::HasSubscribedFoldersL()
       
   443 // ----------------------------------------------------------------------------
       
   444 //
       
   445 TBool CImumInMailboxUtilitiesImpl::HasSubscribedFoldersL(
       
   446     const TMsvId aFolderId ) const
       
   447     {
       
   448     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::HasSubscribedFoldersL, 0, KLogInApi );
       
   449     IMUM_IN();
       
   450 
       
   451     // Make sure the id is receiving
       
   452     TMsvEntry rcv = iMailboxApi.MailboxUtilitiesL().GetMailboxEntryL(
       
   453         aFolderId,
       
   454         MImumInMailboxUtilities::ERequestReceiving,
       
   455         EFalse );
       
   456 
       
   457     // Get the folder entry
       
   458     CMsvEntry* folderEntry = iMailboxApi.MsvSession().GetEntryL( rcv.Id() );
       
   459     CleanupStack::PushL( folderEntry );
       
   460 
       
   461     // Subscribed folders are hidden entries before the first sync
       
   462     TMsvSelectionOrdering order = folderEntry->SortType();
       
   463     order.SetShowInvisibleEntries( ETrue );
       
   464     folderEntry->SetSortTypeL( order );
       
   465 
       
   466     TBool found( EFalse );
       
   467 
       
   468     // Search through all the folders and locate the subscribed ones
       
   469     const TInt count = folderEntry->Count();
       
   470     for ( TInt loop = 0; !found && loop < count; loop++ )
       
   471         {
       
   472         TMsvEmailEntry mailEntry = ( *folderEntry )[ loop ];
       
   473         if ( mailEntry.iType.iUid == KUidMsvFolderEntryValue )
       
   474             {
       
   475             if ( mailEntry.LocalSubscription() && !IsInbox( mailEntry ) )
       
   476                 {
       
   477                 found = ETrue;
       
   478                 }
       
   479             else
       
   480                 {
       
   481                 // Go into the folder to search the new entry
       
   482                 found = HasSubscribedFoldersL( mailEntry.Id() );
       
   483                 }
       
   484             }
       
   485         }
       
   486 
       
   487     CleanupStack::PopAndDestroy( folderEntry );
       
   488 
       
   489     IMUM_OUT();
       
   490 
       
   491     return found;
       
   492     }
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // From class MImumInMailboxUtilities.
       
   496 // CImumInMailboxUtilitiesImpl::IsAlwaysOnlineOnL()
       
   497 // ---------------------------------------------------------------------------
       
   498 //
       
   499 void CImumInMailboxUtilitiesImpl::QueryAlwaysOnlineStateL(
       
   500     const TMsvId aMailboxId,
       
   501     TInt64& aAlwaysOnlineStatus ) const
       
   502     {
       
   503     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::QueryAlwaysOnlineStateL, 0, KLogInApi );
       
   504     IMUM_IN();
       
   505 
       
   506     // Query the result from the scheduler utility
       
   507     CImumMboxScheduler* scheduler = CImumMboxScheduler::NewLC(
       
   508         iMailboxApi, aMailboxId );
       
   509     aAlwaysOnlineStatus = scheduler->QueryAlwaysOnlineStateL();
       
   510 
       
   511     // Cleanup
       
   512     CleanupStack::PopAndDestroy( scheduler );
       
   513     scheduler = NULL;
       
   514 
       
   515     IMUM_OUT();
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 // From class MImumInMailboxUtilities.
       
   520 // CImumInMailboxUtilitiesImpl::NextAlwaysOnlineIntervalL()
       
   521 // ---------------------------------------------------------------------------
       
   522 //
       
   523 void CImumInMailboxUtilitiesImpl::NextAlwaysOnlineIntervalL(
       
   524     const TMsvId aMailboxId,
       
   525     TInt64& aAlwaysOnlineStatus,
       
   526     TTimeIntervalSeconds& aSeconds ) const
       
   527     {
       
   528     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::NextAlwaysOnlineIntervalL, 0, KLogInApi );
       
   529     IMUM_IN();
       
   530 
       
   531     // Query the result from the scheduler utility
       
   532     CImumMboxScheduler* scheduler = CImumMboxScheduler::NewLC(
       
   533         iMailboxApi, aMailboxId );
       
   534     aAlwaysOnlineStatus = scheduler->SecondsToNextMark( aSeconds );
       
   535 
       
   536     // Cleanup
       
   537     CleanupStack::PopAndDestroy( scheduler );
       
   538     scheduler = NULL;
       
   539 
       
   540     IMUM_OUT();
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // From class MImumInMailboxUtilities.
       
   545 // CImumInMailboxUtilitiesImpl::DefaultMailboxIdL()
       
   546 // ---------------------------------------------------------------------------
       
   547 //
       
   548 TMsvId CImumInMailboxUtilitiesImpl::DefaultMailboxIdL(
       
   549     const TBool aForceGet ) const
       
   550     {
       
   551     IMUM_CONTEXT( CImumInMailboxUtilitiesImpl::DefaultMailboxIdL, 0, KLogInApi );
       
   552     IMUM_IN();
       
   553 
       
   554     // The system must have default mtm for mailboxes, so find one
       
   555     TUid defaultMtm = KSenduiMtmSmtpUid;
       
   556 
       
   557     TMsvId defaultId = MuiuEmailTools::DefaultSendingMailboxL(
       
   558         iMailboxApi.MsvSession(), defaultMtm );
       
   559 
       
   560     // There's no such of thing, so force find any.
       
   561     // This may be true in case the message store has been swapped between
       
   562     // the phone and memorycard. Forcing default mailbox makes it possible
       
   563     // to write and send emails without problems.
       
   564     if ( aForceGet && defaultId == KMsvUnknownServiceIndexEntryId )
       
   565         {
       
   566         // Find first valid mailbox
       
   567         iMailboxApi.MailboxServicesL().SetDefaultMailboxL( 0 );
       
   568         defaultId = MuiuEmailTools::DefaultSendingMailboxL(
       
   569             iMailboxApi.MsvSession(), defaultMtm );
       
   570         }
       
   571 
       
   572     IMUM_OUT();
       
   573     return defaultId;
       
   574     }
       
   575