messagingappbase/mcesettings/src/MceSettingsEmailSel.cpp
branchRCL_3
changeset 27 7fdbb852d323
equal deleted inserted replaced
26:ebe688cedc25 27:7fdbb852d323
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   Dialog showing all email MTMs
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <coemain.h> 
       
    22 #include <aknnotewrappers.h> 
       
    23 #include <eikenv.h>
       
    24 #include "MceSettingsEmailSel.h"
       
    25 #include <MceSettingsEmailSel.rsg>
       
    26 #include <MceSettings.rsg>
       
    27 #include <ConeResLoader.h>
       
    28 #include <data_caging_path_literals.hrh>
       
    29 #include <msvstd.h> 
       
    30 #include <msvapi.h>
       
    31 #include <msvids.h>
       
    32 #include <StringLoader.h>
       
    33 #include <centralrepository.h>
       
    34 #include <MessagingDomainCRKeys.h>
       
    35 #include <mtmuids.h>
       
    36 #include <mtudcbas.h>
       
    37 #include <mtmuibas.h>			
       
    38 #include <SendUiConsts.h>
       
    39 #include <bautils.h>
       
    40 #include <MtmExtendedCapabilities.hrh>
       
    41 #include <MuiuMsvUiServiceUtilities.h>
       
    42 #include <mtudreg.h>
       
    43 #include <miutset.h>
       
    44 #include <ImumInternalApi.h>
       
    45 #include <ImumInHealthServices.h>
       
    46 #include <muiuflags.h>
       
    47 #include <muiuemailtools.h>
       
    48 #include <featmgr.h>
       
    49 
       
    50 const TInt KArrayGranularity = 3;
       
    51 const TInt KCapabilitiesUnset = -1;
       
    52 
       
    53 _LIT( KMceEmailSelResourceFileName,
       
    54 	  "\\resource\\MceSettingsEmailSel.rsc" );
       
    55 #define KUidMsgTypeFsMtmVal               0x2001F406
       
    56 
       
    57 // EXTERNAL DATA STRUCTURES
       
    58 
       
    59 // EXTERNAL FUNCTION PROTOTYPES  
       
    60 
       
    61 // CONSTANTS
       
    62 
       
    63 // MACROS
       
    64 
       
    65 // LOCAL CONSTANTS AND MACROS
       
    66 
       
    67 // MODULE DATA STRUCTURES
       
    68 
       
    69 // LOCAL FUNCTION PROTOTYPES
       
    70 
       
    71 // FORWARD DECLARATIONS
       
    72 
       
    73 // ============================= LOCAL FUNCTIONS ===============================
       
    74 
       
    75 
       
    76 // ============================ MEMBER FUNCTIONS ===============================
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CSampleApplication::CreateDocumentL
       
    80 // Create a Sample document, and return a pointer to it.
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 CMceSettingsEmailSel* CMceSettingsEmailSel::NewL()
       
    84     {
       
    85     // Create an object, and return a pointer to it
       
    86     CMceSettingsEmailSel* self = new (ELeave) CMceSettingsEmailSel;
       
    87     CleanupStack::PushL( self );
       
    88     self->ConstructL();
       
    89     CleanupStack::Pop();
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CMceSettingsEmailSel::ConstructL
       
    95 // 2nd phase contructor that can leave.
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 void CMceSettingsEmailSel::ConstructL()
       
    99     {
       
   100     iMsvSessionPtr = CMsvSession::OpenSyncL( *this );   
       
   101     iMtmStore = CMtmStore::NewL( *iMsvSessionPtr );   
       
   102     LoadResourceL();      
       
   103     iRequiredCapabilities.iFlags = KCapabilitiesUnset;    
       
   104     
       
   105     if ( FeatureManager::FeatureSupported( KFeatureIdFfEmailFramework ) )
       
   106     {
       
   107       iEmailFramework = ETrue;
       
   108     } 
       
   109     iCmaillistItems = NULL;
       
   110     iCmailBoxes = NULL;
       
   111     iCmaillistItemUids = NULL;
       
   112     }
       
   113     
       
   114 // ---------------------------------------------------------
       
   115 // CMceSettingsEmailSel::CMceSettingsEmailSel
       
   116 // contructor
       
   117 // ---------------------------------------------------------
       
   118 //
       
   119 CMceSettingsEmailSel::CMceSettingsEmailSel()
       
   120 		:iEmailFramework(EFalse)
       
   121     {
       
   122     }        
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CMceSettingsEmailSel::~CMceSettingsEmailSel
       
   126 // Destructor
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 CMceSettingsEmailSel::~CMceSettingsEmailSel()
       
   130     {
       
   131     if( iMtmStore )
       
   132     	{
       
   133     	delete iMtmStore;
       
   134     	iMtmStore = NULL;
       
   135     	}     
       
   136     if( iMsvSessionPtr )
       
   137     	{
       
   138     	delete iMsvSessionPtr;
       
   139     	iMsvSessionPtr = NULL;
       
   140     	}  	  
       
   141     UnLoadResource();    	 	
       
   142     if(iCmaillistItemUids)
       
   143         {
       
   144         delete iCmaillistItemUids;
       
   145         iCmaillistItemUids  = NULL;
       
   146         }
       
   147     if(iCmailBoxes)
       
   148         {
       
   149         iCmailBoxes->Close();
       
   150         delete iCmailBoxes;
       
   151         iCmailBoxes  = NULL;
       
   152         }
       
   153     if(iCmaillistItems)
       
   154         {
       
   155         delete iCmaillistItems;
       
   156         iCmaillistItems = NULL;
       
   157         }
       
   158     }    
       
   159 
       
   160 // ---------------------------------------------------------
       
   161 // CMceSettingsEmailSel::LoadResourceL
       
   162 // Load the resource for the dll module
       
   163 // ---------------------------------------------------------
       
   164 //
       
   165 void CMceSettingsEmailSel::LoadResourceL()
       
   166     {
       
   167     TFileName resourceFileNameBuf( KMceEmailSelResourceFileName );
       
   168 
       
   169     CEikonEnv* eikEnv = CEikonEnv::Static();
       
   170     BaflUtils::NearestLanguageFile( eikEnv->FsSession(),
       
   171     		                        resourceFileNameBuf );
       
   172     iResourceOffset = eikEnv->AddResourceFileL( resourceFileNameBuf );
       
   173     }    
       
   174     
       
   175 // ---------------------------------------------------------
       
   176 // CMceSettingsEmailSel::UnLoadResource
       
   177 // Unload the resource for the dll module
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 void CMceSettingsEmailSel::UnLoadResource()
       
   181     {
       
   182     CEikonEnv* eikEnv = CEikonEnv::Static();
       
   183     eikEnv->DeleteResourceFile( iResourceOffset );
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // CMceSettingsEmailSel::HandleSessionEventL
       
   188 // From MMsvSessionObserver
       
   189 // ---------------------------------------------------------
       
   190 //    
       
   191 void CMceSettingsEmailSel::HandleSessionEventL(
       
   192     TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/,
       
   193     TAny* /*aArg2*/, TAny* /*aArg3*/ )
       
   194 	{	
       
   195 	}
       
   196 
       
   197 // ---------------------------------------------------------
       
   198 // CMceSettingsEmailSel::ShowEmailSelectDlgL
       
   199 // 
       
   200 // ---------------------------------------------------------
       
   201 //    
       
   202 EXPORT_C TBool CMceSettingsEmailSel::ShowSelectEmailDlgL(
       
   203     TMsvId& aSelectedService, TUid& aMtmType,
       
   204     TSendingCapabilities aRequiredCapabilities )
       
   205 	{		
       
   206 	CMceSettingsEmailSel* dlg = CMceSettingsEmailSel::NewL();
       
   207 
       
   208 	CleanupStack::PushL( dlg );
       
   209 	TBool retVal = dlg->ShowSelectDlgL(
       
   210 			             aSelectedService, aMtmType, aRequiredCapabilities );
       
   211 	CleanupStack::PopAndDestroy( dlg );
       
   212 	return retVal;	
       
   213 	}
       
   214 	
       
   215 // ---------------------------------------------------------
       
   216 // CMceSettingsEmailSel::ShowSelectDlgL
       
   217 // 
       
   218 // ---------------------------------------------------------
       
   219 //    	
       
   220 TBool CMceSettingsEmailSel::ShowSelectDlgL(
       
   221                                            TMsvId& aSelectedService, TUid& aMtmType, 
       
   222                                            TSendingCapabilities aRequiredCapabilities )
       
   223     {
       
   224     iRequiredCapabilities = aRequiredCapabilities;
       
   225     // List items for list query.
       
   226     CDesCArrayFlat* listItems = new (ELeave) CDesCArrayFlat(
       
   227                                 KArrayGranularity );
       
   228     CleanupStack::PushL( listItems );
       
   229 
       
   230     // This array is used to map user selection to correct service.
       
   231     CArrayFix<TUid>* listItemUids = 
       
   232         new ( ELeave ) CArrayFixFlat<TUid>( KArrayGranularity );
       
   233     CleanupStack::PushL( listItemUids );
       
   234 
       
   235     // Get and filter available MTM services supporting attachments.
       
   236     FilterEmailServicesL( *listItems, *listItemUids );
       
   237     
       
   238     //Check if Cmail is enabled
       
   239     if(iEmailFramework)
       
   240          {
       
   241          return ShowCmailSelectDlgL(aSelectedService, aMtmType,listItems, listItemUids );
       
   242          }
       
   243 
       
   244     // no accounts defined, nothing to show
       
   245     if ( 0 == listItems->Count() )
       
   246         {
       
   247         CleanupStack::PopAndDestroy( listItemUids );
       
   248         CleanupStack::PopAndDestroy( listItems );
       
   249         aSelectedService = KMsvUnknownServiceIndexEntryId;
       
   250         return ETrue;
       
   251         }
       
   252 
       
   253     // only one account, selection dialog not shown
       
   254     if( listItems->Count() == 1 )
       
   255         {
       
   256         aSelectedService = (*listItemUids)[0].iUid;
       
   257 
       
   258         TMsvEntry entry;
       
   259         TMsvId serviceId;
       
   260         User::LeaveIfError( iMsvSessionPtr->GetEntry(
       
   261                 (*listItemUids)[0].iUid, serviceId, entry ) );
       
   262         if ( entry.iMtm == KSenduiMtmPop3Uid ||
       
   263              entry.iMtm == KSenduiMtmImap4Uid )
       
   264             {
       
   265             aMtmType = KSenduiMtmSmtpUid;
       
   266             aSelectedService = entry.iRelatedId; // related = SMTP
       
   267             }
       
   268         else
       
   269             {
       
   270             aMtmType = entry.iMtm;
       
   271             }		
       
   272 
       
   273         CleanupStack::PopAndDestroy( listItemUids );
       
   274         CleanupStack::PopAndDestroy( listItems );
       
   275         return ETrue;		
       
   276         }
       
   277 
       
   278     // Show list query.
       
   279     TInt choice = KErrNotFound;
       
   280     CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( &choice );
       
   281     dlg->PrepareLC( R_SEND_EMAIL_LIST_QUERY );
       
   282     dlg->SetItemTextArray( listItems );
       
   283     dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   284 
       
   285     if ( !dlg->RunLD() )
       
   286         {
       
   287         // Cancel        
       
   288         CleanupStack::PopAndDestroy( listItemUids );
       
   289         CleanupStack::PopAndDestroy( listItems );
       
   290         return EFalse;
       
   291         }
       
   292 
       
   293     aSelectedService = (*listItemUids)[choice].iUid;
       
   294 
       
   295     TMsvEntry entry;
       
   296     TMsvId serviceId;
       
   297     User::LeaveIfError( iMsvSessionPtr->GetEntry(
       
   298             aSelectedService, serviceId, entry ) );
       
   299     if ( entry.iMtm == KSenduiMtmPop3Uid ||
       
   300          entry.iMtm == KSenduiMtmImap4Uid )
       
   301         {
       
   302         aMtmType = KSenduiMtmSmtpUid;
       
   303         aSelectedService = entry.iRelatedId; // related = SMTP
       
   304         }
       
   305     else
       
   306         {
       
   307         aMtmType = entry.iMtm;
       
   308         }
       
   309 
       
   310     CleanupStack::PopAndDestroy( listItemUids );
       
   311     CleanupStack::PopAndDestroy( listItems );
       
   312     return ETrue;	 
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------
       
   316 // CMceSettingsEmailSel::ShowCmailSelectDlgL
       
   317 // 
       
   318 // ---------------------------------------------------------
       
   319 //  
       
   320 TBool CMceSettingsEmailSel::ShowCmailSelectDlgL(TMsvId& aSelectedService, 
       
   321                             TUid& aMtmType,
       
   322                             CDesCArrayFlat*         aListItems,
       
   323                             CArrayFix<TUid>*        aListItemUids)
       
   324     {
       
   325     TBool retval = EFalse;
       
   326     //Add the non cmail boxes at the end of cmail list 
       
   327     for(int cnt = 0; cnt < aListItems->Count(); cnt++  )
       
   328         {
       
   329         iCmaillistItems->AppendL(aListItems->MdcaPoint(cnt));
       
   330         iCmaillistItemUids->AppendL(aListItemUids->At(cnt));
       
   331         }
       
   332     
       
   333     // no accounts defined, nothing to show
       
   334     if ( 0 == iCmaillistItems->Count() )
       
   335         {
       
   336         aSelectedService = KMsvUnknownServiceIndexEntryId;
       
   337         retval =  ETrue;
       
   338         }
       
   339 
       
   340     // only one account, selection dialog not shown
       
   341     if( iCmaillistItems->Count() == 1 && !retval )
       
   342         {
       
   343         aSelectedService = (*iCmaillistItemUids)[0].iUid;
       
   344 
       
   345         TMsvEntry entry;
       
   346         TMsvId serviceId;
       
   347         User::LeaveIfError( iMsvSessionPtr->GetEntry(
       
   348                 (*iCmaillistItemUids)[0].iUid, serviceId, entry ) );
       
   349         if ( entry.iMtm == KSenduiMtmPop3Uid ||
       
   350              entry.iMtm == KSenduiMtmImap4Uid )
       
   351             {
       
   352             aMtmType = KSenduiMtmSmtpUid;
       
   353             aSelectedService = entry.iRelatedId; // related = SMTP
       
   354             }
       
   355         else
       
   356             {
       
   357             aMtmType = entry.iMtm;
       
   358             }       
       
   359         retval = ETrue;       
       
   360         }
       
   361     TBool cancel = EFalse;
       
   362     if( !retval )
       
   363         {
       
   364         // Show list query.
       
   365         TInt choice = KErrNotFound;
       
   366         CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( &choice );
       
   367         dlg->PrepareLC( R_SEND_EMAIL_LIST_QUERY );
       
   368         dlg->SetItemTextArray( iCmaillistItems );
       
   369         dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   370     
       
   371         if ( !dlg->RunLD() )
       
   372             {
       
   373             // Cancel      
       
   374             cancel = ETrue;
       
   375             //retval = EFalse;
       
   376             }
       
   377         if(!cancel)
       
   378             {
       
   379             aSelectedService = (*iCmaillistItemUids)[choice].iUid;
       
   380         
       
   381             TMsvEntry entry;
       
   382             TMsvId serviceId;
       
   383             User::LeaveIfError( iMsvSessionPtr->GetEntry(
       
   384                     aSelectedService, serviceId, entry ) );
       
   385             aMtmType = entry.iMtm;
       
   386             }
       
   387         }
       
   388     if(iCmaillistItemUids)
       
   389         {
       
   390     	delete iCmaillistItemUids;
       
   391         iCmaillistItemUids  = NULL;
       
   392         }
       
   393     if(iCmaillistItems)
       
   394         {
       
   395    		delete iCmaillistItems;
       
   396         iCmaillistItems = NULL;
       
   397         }
       
   398     CleanupStack::PopAndDestroy( aListItemUids );
       
   399     CleanupStack::PopAndDestroy( aListItems );
       
   400     if(cancel)
       
   401         return EFalse;
       
   402     else
       
   403         return ETrue;   
       
   404     }
       
   405 // ---------------------------------------------------------
       
   406 // TPtrC8Ident
       
   407 // Hash Table Function 
       
   408 // ---------------------------------------------------------
       
   409 //
       
   410 TBool TPtrC8Ident(const TPtrC16& aL, const TPtrC16& aR)
       
   411      {
       
   412      return DefaultIdentity::Des16(aL, aR);
       
   413      }
       
   414 
       
   415 // ---------------------------------------------------------
       
   416 // TPtrC8Hash
       
   417 // Hash Table Function 
       
   418 // ---------------------------------------------------------
       
   419 //
       
   420 TUint32 TPtrC8Hash(const TPtrC16& aPtr)
       
   421      {
       
   422      return DefaultHash::Des16(aPtr);
       
   423 
       
   424      }
       
   425 // ---------------------------------------------------------
       
   426 // CMceSettingsEmailSel::FilterEmailServicesL
       
   427 // 
       
   428 // ---------------------------------------------------------
       
   429 //    
       
   430 void CMceSettingsEmailSel::FilterEmailServicesL(
       
   431     CDesCArrayFlat&         aListItems,
       
   432     CArrayFix<TUid>&        aListItemUids )
       
   433     {
       
   434     iDefaultIndex = -1;    
       
   435      
       
   436     TInt keyValue;
       
   437     CRepository* repository = NULL;
       
   438     TRAPD( ret, repository = CRepository::NewL( KCRUidSelectableDefaultEmailSettings   ) );
       
   439 
       
   440     if ( ret == KErrNone )
       
   441         {
       
   442         if ( repository->Get( KSelectableDefaultMailAccount  , keyValue ) != KErrNone )
       
   443             {
       
   444             iDefaultIndex = -1;
       
   445             }
       
   446         // Check if there is other than platform email application registered
       
   447         // to handle S60 mailboxes	
       
   448         TInt err = repository->Get( KIntegratedEmailAppMtmPluginId  ,
       
   449                                     iMtmPluginID );
       
   450         if ( err != KErrNone )
       
   451             {
       
   452             iMtmPluginID = 0;
       
   453             }
       
   454         }
       
   455     delete repository;
       
   456         
       
   457     // fetch email mtms
       
   458     CMsvEntry* entry = iMsvSessionPtr->GetEntryL( KMsvRootIndexEntryId );
       
   459     CleanupStack::PushL( entry );
       
   460 
       
   461     TInt cnt = entry->Count();
       
   462 
       
   463     // Add default item first
       
   464     if(!iEmailFramework)
       
   465       {
       
   466       entry->SetSortTypeL( TMsvSelectionOrdering(
       
   467                               KMsvGroupByType | KMsvGroupByStandardFolders,
       
   468                               EMsvSortByDetailsReverse, ETrue ) );
       
   469       
       
   470       for ( TInt cc = entry->Count(); --cc >= 0; )
       
   471           {
       
   472           iTentryDef = (*entry)[cc];
       
   473             if(!IsMailBoxHealthyL(iTentryDef))
       
   474                {
       
   475                continue;
       
   476                }
       
   477 
       
   478             if ( iTentryDef.iType.iUid == KUidMsvServiceEntryValue &&
       
   479                     iTentryDef.Id() != KMsvLocalServiceIndexEntryIdValue )
       
   480                 {
       
   481                 const TBool noRelatedId =
       
   482                 iTentryDef.iRelatedId == KMsvNullIndexEntryId ||
       
   483                 iTentryDef.iRelatedId == iTentryDef.Id();
       
   484 
       
   485                 if ( IsEmailEntryL(iTentryDef)  &&
       
   486                      ( ( iTentryDef.Id() == keyValue ) ||
       
   487                        ( iTentryDef.iRelatedId == keyValue) ) )
       
   488                     {
       
   489                     TBool append = ETrue;
       
   490                     // query capability (attachment)
       
   491                     TUid entryUid;
       
   492                     entryUid = iTentryDef.iMtm;
       
   493 
       
   494                     if ( iTentryDef.iMtm == KSenduiMtmPop3Uid ||
       
   495                             iTentryDef.iMtm == KSenduiMtmImap4Uid )
       
   496                         {
       
   497                         entryUid = KSenduiMtmSmtpUid;
       
   498                         }
       
   499 
       
   500                     TBool ret = EFalse;
       
   501                     TRAPD( err, ret = QueryCapabilitiesAndValidateAccountL(
       
   502                     		                                     entryUid ) )
       
   503                     if ( ret && ( err == KErrNone ) )
       
   504                         {
       
   505                         append = ETrue;
       
   506                         }
       
   507                     else
       
   508                         {
       
   509                         append = EFalse;
       
   510                         }
       
   511 
       
   512                     const TInt count = aListItemUids.Count();
       
   513 
       
   514                     // Check that related service is not already added to
       
   515                     // array
       
   516                     for ( TInt loop = 0; loop < count; loop ++ )
       
   517                         {
       
   518                         if ( iTentryDef.iRelatedId ==
       
   519                                                 aListItemUids.At(loop).iUid )
       
   520                             {
       
   521                             append = EFalse;
       
   522                             break;
       
   523                             }
       
   524                         }
       
   525 
       
   526                     if( append )
       
   527                         {
       
   528                         // Add this service if:
       
   529                         // it is visible, or,there is no associated related
       
   530                         // service, or, we have been asked to list all
       
   531                         // services.
       
   532                         HBufC* stringholder;
       
   533                         stringholder = StringLoader::LoadLC(
       
   534                             R_MCE_POPUP_DEFAULT_EMAIL,
       
   535                             iTentryDef.iDetails ); //Pushes stringholder onto the
       
   536                                                //Cleanup Stack.
       
   537 
       
   538                         entryUid.iUid = iTentryDef.Id();
       
   539                         aListItems.AppendL( stringholder->Des() );
       
   540                         aListItemUids.AppendL( entryUid );
       
   541                         iDefaultIndex = cc;
       
   542                         CleanupStack::PopAndDestroy( stringholder );
       
   543                         iTentryDef = (*entry)[iDefaultIndex];
       
   544                         break;
       
   545                         }
       
   546                     }
       
   547                 }
       
   548             }
       
   549         }
       
   550         
       
   551     //Add Other Email Boxes    
       
   552     AddOtherEmailBoxesL(aListItems, aListItemUids, entry);    
       
   553     
       
   554     if(iEmailFramework)
       
   555         {
       
   556         //Hash Table to store the information of non cmail mailboxes for sorting and arranging their uids
       
   557         RHashMap<TPtrC16, TInt32 >* nonCmailUid = new( ELeave )RHashMap< TPtrC16, TInt32 >
       
   558                               (&TPtrC8Hash , &TPtrC8Ident);
       
   559         CleanupStack::PushL( nonCmailUid);
       
   560         
       
   561         for(TInt loop = 0; loop < aListItems.Count() ; loop++ )
       
   562             {
       
   563             nonCmailUid->Insert(aListItems.MdcaPoint(loop), aListItemUids.At(loop).iUid );
       
   564             }
       
   565         
       
   566         //Sort the non cmail items alphabatically
       
   567         aListItems.Sort(ECmpFolded);
       
   568         
       
   569         //Reset the array to load the Uids in new sorted order
       
   570         aListItemUids.Reset();
       
   571         
       
   572         for(TInt loop = 0; loop < aListItems.Count() ; loop++ )
       
   573             {
       
   574             TInt32* uid = nonCmailUid->Find(aListItems.MdcaPoint(loop));
       
   575             aListItemUids.AppendL(TUid::Uid( *uid ));
       
   576             }
       
   577        
       
   578         CleanupStack::PopAndDestroy( nonCmailUid );
       
   579         }
       
   580         CleanupStack::PopAndDestroy( entry );
       
   581     
       
   582     }	
       
   583 // ---------------------------------------------------------
       
   584 // TPtrC8Hash
       
   585 // Hash Table Function
       
   586 // ---------------------------------------------------------
       
   587 //
       
   588 TUint32 TPtrC8Hash(const TInt64 & atime)
       
   589      {
       
   590      return DefaultHash::Integer(atime);
       
   591      }
       
   592 
       
   593 // ---------------------------------------------------------
       
   594 // TInt64Ident
       
   595 // Hash Table Function 
       
   596 // ---------------------------------------------------------
       
   597 //
       
   598 TBool TInt64Ident(const TInt64& aL, const TInt64& aR)
       
   599      {
       
   600      return DefaultIdentity::Integer(aL, aR);
       
   601 
       
   602      }
       
   603 
       
   604 // ---------------------------------------------------------
       
   605 // CMceSettingsEmailSel::IsEmailEntryL
       
   606 // 
       
   607 // (other items were commented in a header).
       
   608 // ---------------------------------------------------------
       
   609 //
       
   610 TBool CMceSettingsEmailSel::IsEmailEntryL(TMsvEntry tentry)
       
   611     {
       
   612     TBool appendEmail = EFalse;
       
   613     if ( tentry.Visible() )
       
   614         {
       
   615         appendEmail = ETrue;
       
   616         }
       
   617     else
       
   618         {
       
   619         CMtmUiDataRegistry* uiRegistry =
       
   620                          CMtmUiDataRegistry::NewL( *iMsvSessionPtr );
       
   621         CleanupStack::PushL(uiRegistry);
       
   622         if ( uiRegistry->IsPresent( tentry.iMtm ) &&
       
   623              uiRegistry->IsPresent( KUidMsgTypePOP3 ) )
       
   624             {
       
   625             TUid mailMTMTechType =
       
   626                     uiRegistry->TechnologyTypeUid( KUidMsgTypePOP3 );
       
   627             if( uiRegistry->TechnologyTypeUid( tentry.iMtm ) ==
       
   628                                                     mailMTMTechType )
       
   629                 {
       
   630                 appendEmail = ETrue;
       
   631                 }
       
   632             }
       
   633         CleanupStack::PopAndDestroy( uiRegistry );
       
   634         }
       
   635     return appendEmail;
       
   636     }
       
   637 
       
   638 // ---------------------------------------------------------
       
   639 // CMceSettingsEmailSel::AppendCmailBoxesL(
       
   640 // 
       
   641 // (other items were commented in a header).
       
   642 // ---------------------------------------------------------
       
   643 //
       
   644 void CMceSettingsEmailSel::AppendCmailBoxesL(CArrayFix<TInt64 >* atimeItems, CMsvEntry* aEntry)
       
   645     {
       
   646     //Sort the cmail Entry items based on time
       
   647     TKeyArrayFix key( 0, ECmpTInt64 );
       
   648     atimeItems->Sort(key);
       
   649     TUid cmailEntryUid;
       
   650     
       
   651     if(iCmaillistItems)
       
   652         {
       
   653         delete iCmaillistItems;
       
   654         iCmaillistItems = NULL;
       
   655         }   
       
   656     //Array to get the list of Cmail Boxes
       
   657     iCmaillistItems = new (ELeave) CDesCArrayFlat(
       
   658                                 KArrayGranularity );
       
   659     
       
   660     if(iCmaillistItemUids)
       
   661         {
       
   662         delete iCmaillistItemUids;
       
   663         iCmaillistItemUids = NULL;
       
   664         }
       
   665     iCmaillistItemUids = new ( ELeave ) 
       
   666             CArrayFixFlat<TUid>( KArrayGranularity );
       
   667    
       
   668     // Go one by one in Hash table
       
   669     if(atimeItems->Count() > 0)
       
   670         {    
       
   671         for(TInt cnt = (atimeItems->Count() - 1) ; cnt >= 0 ; cnt--)
       
   672             {
       
   673             //Take one by one the Time Entry and Find the correponding Position Key
       
   674             //from key get the correponding Entry
       
   675            TInt* entrypos = iCmailBoxes->Find(atimeItems->At(cnt));
       
   676            TMsvEntry cmailentry = (*aEntry)[*entrypos];
       
   677            
       
   678            iCmaillistItems->AppendL(cmailentry.iDetails);          
       
   679            cmailEntryUid.iUid = cmailentry.Id();
       
   680            iCmaillistItemUids->AppendL(cmailEntryUid); 
       
   681            }
       
   682          }
       
   683     }
       
   684 
       
   685 // ---------------------------------------------------------
       
   686 // CMceSettingsEmailSel::AddOtherEmailBoxesL
       
   687 // 
       
   688 // (other items were commented in a header).
       
   689 // ---------------------------------------------------------
       
   690 //
       
   691 void CMceSettingsEmailSel::AddOtherEmailBoxesL(CDesCArrayFlat& aListItems, CArrayFix<TUid>& aListItemUids , CMsvEntry* aEntry)
       
   692     {
       
   693     CArrayFix<TInt64 >* timeItems = NULL;
       
   694     CDesCArrayFlat* cmaillist = NULL;
       
   695     TTime timeNow;
       
   696     
       
   697     if(iEmailFramework)
       
   698         {
       
   699         //Added for Cmail Details
       
   700         if(iCmailBoxes)
       
   701            {
       
   702            iCmailBoxes->Close();
       
   703            delete iCmailBoxes;
       
   704            iCmailBoxes  = NULL;
       
   705            }
       
   706         iCmailBoxes =
       
   707               new( ELeave )RHashMap< TInt64, TInt >
       
   708                       (&TPtrC8Hash , &TInt64Ident);    
       
   709         
       
   710         // This array is used to map user selection to correct service.
       
   711         timeItems = 
       
   712              new ( ELeave ) CArrayFixFlat<TInt64 >( 3 );
       
   713         CleanupStack::PushL( timeItems );
       
   714              
       
   715         cmaillist = new (ELeave) CDesCArrayFlat(
       
   716                                     KArrayGranularity );
       
   717         CleanupStack::PushL( cmaillist );
       
   718         
       
   719         aEntry->SetSortTypeL( TMsvSelectionOrdering(
       
   720                                     KMsvGroupByMtm, 
       
   721                                     EMsvSortByDetailsReverse, ETrue ) );
       
   722                
       
   723         timeNow.UniversalTime();
       
   724         
       
   725         }
       
   726            
       
   727       // take entry one by one
       
   728       for ( TInt cc = aEntry->Count(); --cc >= 0; )
       
   729           {
       
   730           TMsvEntry tentry2 = (*aEntry)[cc];
       
   731           
       
   732            if(!IsMailBoxHealthyL(tentry2))
       
   733              {
       
   734              continue;
       
   735              }
       
   736 
       
   737           if ( tentry2.iType.iUid == KUidMsvServiceEntryValue &&
       
   738                tentry2.Id() != KMsvLocalServiceIndexEntryIdValue )
       
   739               {
       
   740               if ( IsEmailEntryL(tentry2) && ( cc != iDefaultIndex ) )
       
   741                   {
       
   742                   TBool append = ETrue;
       
   743                   TUid entryUid;
       
   744 
       
   745                   append = IsMailBoxAppendable( tentry2, &entryUid );
       
   746                   // If related service is SyncML or if 3'rd party email
       
   747                   // plugin is registered but the mailbox uid is wrong,
       
   748                   // it should be skipped. (This avoids doubles)
       
   749                   if(!iEmailFramework)
       
   750                   {
       
   751                    if ( entryUid != KSenduiMtmSmtpUid ||
       
   752                            iMtmPluginID != 0 && tentry2.iMtm.iUid != iMtmPluginID )
       
   753                        {
       
   754                        append = EFalse;
       
   755                        }
       
   756                   }
       
   757                   if ( append )
       
   758                   	{
       
   759                      append = IfMailBoxUidAlreadyAdded( &aListItemUids, tentry2 );
       
   760                   
       
   761                      if(! IfMailBoxAlreadyAdded(aListItems, cmaillist, tentry2 ))
       
   762                        continue;
       
   763                     }
       
   764                   if ( tentry2.iDetails.Compare(iTentryDef.iDetails) == 0 )
       
   765                       {
       
   766                       append = EFalse;
       
   767                       }
       
   768 
       
   769                   if( append )
       
   770                       {
       
   771                       // Add this service if:
       
   772                       // it is visible, or,there is no associated related
       
   773                       // service, or, we have been asked to list all
       
   774                       // services.                    
       
   775                       entryUid.iUid = tentry2.Id();    
       
   776                       //If cmail box add to the hash table and cmaillist
       
   777                       if(tentry2.iMtm.iUid == KUidMsgTypeFsMtmVal 
       
   778                               && timeItems != NULL && cmaillist != NULL)
       
   779                           {
       
   780                           TTimeIntervalMicroSeconds difference = timeNow.MicroSecondsFrom( tentry2.iDate.Int64() );
       
   781                           TInt ret = iCmailBoxes->Insert(difference.Int64() , cc );
       
   782                           timeItems->AppendL(difference.Int64());
       
   783                           cmaillist->AppendL(tentry2.iDetails);
       
   784                           }
       
   785                       //Add Non Cmail
       
   786                       else if( tentry2.iMtm.iUid != KSenduiMtmImap4UidValue && tentry2.iMtm.iUid != KSenduiMtmSmtpUidValue && tentry2.iMtm.iUid != KSenduiMtmPop3UidValue)
       
   787                           {
       
   788                           aListItemUids.AppendL( entryUid );
       
   789                           aListItems.AppendL( tentry2.iDetails );
       
   790                           }
       
   791                       }
       
   792                   }
       
   793               }
       
   794           }
       
   795       
       
   796       if(iEmailFramework)
       
   797           {
       
   798           AppendCmailBoxesL(timeItems, aEntry);
       
   799           CleanupStack::PopAndDestroy( cmaillist );
       
   800           CleanupStack::PopAndDestroy( timeItems );
       
   801           if(iCmailBoxes)
       
   802               {
       
   803               iCmailBoxes->Close();
       
   804               delete iCmailBoxes;
       
   805               iCmailBoxes = NULL;
       
   806               }
       
   807           }
       
   808       }
       
   809 
       
   810 // ---------------------------------------------------------
       
   811 // CMceSettingsEmailSel::IfMailBoxAlreadyAdded
       
   812 // 
       
   813 // (other items were commented in a header).
       
   814 // ---------------------------------------------------------
       
   815 //
       
   816 TBool CMceSettingsEmailSel::IfMailBoxAlreadyAdded(CDesCArrayFlat& aListItems, CDesCArrayFlat* aCmaillist, TMsvEntry aTentry)
       
   817     {
       
   818     TBool append = ETrue;
       
   819     if(iEmailFramework)
       
   820         {
       
   821         //Non Cmail/ Third Parties shold not be added twice
       
   822         for ( TInt loop = 0; loop < aListItems.Count(); loop ++ )
       
   823             {
       
   824             if ( aTentry.iDetails.Compare(aListItems.MdcaPoint(loop)) == 0 )
       
   825                 {
       
   826                 append = EFalse;
       
   827                 break;
       
   828                 }
       
   829             }
       
   830             
       
   831             //Cmail should not be added doubles 
       
   832             for ( TInt loop = 0; loop < aCmaillist->Count(); loop ++ )
       
   833                 {
       
   834                 if ( aTentry.iDetails.Compare(aCmaillist->MdcaPoint(loop)) == 0)
       
   835                        {
       
   836                        append = EFalse;
       
   837                        break;
       
   838                        }
       
   839                 }   
       
   840         }
       
   841     return append;
       
   842     }
       
   843 
       
   844 // ---------------------------------------------------------
       
   845 // CMceSettingsEmailSel::IsMailBoxAppendable
       
   846 // 
       
   847 // (other items were commented in a header).
       
   848 // ---------------------------------------------------------
       
   849 //
       
   850 TBool CMceSettingsEmailSel::IsMailBoxAppendable(TMsvEntry tentry2, TUid* aUid)
       
   851     {
       
   852     TBool append = ETrue;
       
   853 
       
   854     *aUid = tentry2.iMtm;
       
   855 
       
   856     if(!iEmailFramework)
       
   857        {
       
   858        if ( tentry2.iMtm == KSenduiMtmPop3Uid ||
       
   859                tentry2.iMtm == KSenduiMtmImap4Uid ||
       
   860                tentry2.iMtm.iUid == iMtmPluginID )
       
   861             {
       
   862             *aUid = KSenduiMtmSmtpUid;
       
   863             }
       
   864        }
       
   865     else
       
   866        {
       
   867        if ( (tentry2.iMtm == KSenduiMtmPop3Uid ||
       
   868                tentry2.iMtm == KSenduiMtmImap4Uid) && (tentry2.iMtm.iUid != KUidMsgTypeFsMtmVal))
       
   869             {
       
   870             *aUid = KSenduiMtmSmtpUid;
       
   871             }
       
   872        }
       
   873            
       
   874 
       
   875     TBool ret = EFalse;
       
   876     TRAPD( err, ret =
       
   877            QueryCapabilitiesAndValidateAccountL( *aUid ) )
       
   878     if ( ret && ( err == KErrNone ) )
       
   879         {
       
   880         append = ETrue;
       
   881         }
       
   882     else
       
   883         {
       
   884         append = EFalse;
       
   885         }
       
   886     return append;
       
   887     }
       
   888 
       
   889 // ---------------------------------------------------------
       
   890 // CMceSettingsEmailSel::IsMailBoxHealthyL
       
   891 // 
       
   892 // (other items were commented in a header).
       
   893 // ---------------------------------------------------------
       
   894 //
       
   895 TBool CMceSettingsEmailSel::IsMailBoxHealthyL(TMsvEntry aTentry)
       
   896     {
       
   897     TBool retval = EFalse;
       
   898     // Get all the healthy mailmox list. It filters the unhealthy mailbox.
       
   899     CImumInternalApi* emailApi = CreateEmailApiLC( &*iMsvSessionPtr );
       
   900     const MImumInHealthServices& mailboxDoctor = emailApi->HealthServicesL();
       
   901     
       
   902     if ( ( !mailboxDoctor.IsMailboxHealthy( aTentry.Id() ) ) &&
       
   903           ( !( ( aTentry.iType == KUidMsvServiceEntry ) && 
       
   904                ( aTentry.Id() != KMsvLocalServiceIndexEntryId ) && 
       
   905           ( !MuiuEmailTools::IsMailMtm( aTentry.iMtm, ETrue ) ) ) ) )
       
   906         {
       
   907         retval = EFalse;
       
   908         }
       
   909     else
       
   910         retval = ETrue;
       
   911     
       
   912     CleanupStack::PopAndDestroy( emailApi );
       
   913     return retval;
       
   914     }
       
   915 
       
   916 // ---------------------------------------------------------
       
   917 // CMceSettingsEmailSel::IfMailBoxUidAlreadyAdded
       
   918 // 
       
   919 // (other items were commented in a header).
       
   920 // ---------------------------------------------------------
       
   921 //
       
   922 TBool CMceSettingsEmailSel::IfMailBoxUidAlreadyAdded(CArrayFix<TUid>* aListItemsUids, TMsvEntry aTentry)
       
   923     {
       
   924     TBool append = ETrue;
       
   925     const TInt count = aListItemsUids->Count();
       
   926     // check that related service is not already added to
       
   927     // array
       
   928     for ( TInt loop = 0; loop < count; loop ++ )
       
   929         {
       
   930         if ( aTentry.iRelatedId ==
       
   931                             aListItemsUids->At( loop ).iUid )
       
   932             {
       
   933             append = EFalse;
       
   934             break;
       
   935             }
       
   936         
       
   937         }
       
   938     return append;
       
   939     }
       
   940 	
       
   941 // ---------------------------------------------------------
       
   942 // CMceSettingsEmailSel::QueryCapabilitiesAndValidateAccountL
       
   943 // 
       
   944 // (other items were commented in a header).
       
   945 // ---------------------------------------------------------
       
   946 //
       
   947 TBool CMceSettingsEmailSel::QueryCapabilitiesAndValidateAccountL(
       
   948 		TUid aMtmUid )
       
   949     {
       
   950     TInt response = 0;
       
   951     const TUid supportEditor = { KUidMsvMtmQuerySupportEditor };    
       
   952     const TUid canCreateNewMsg = { KUidMtmQueryCanCreateNewMsgValue };    
       
   953     
       
   954     // Check to see that accounts (if required) have been set up
       
   955     TMsvId id;
       
   956     TMsvEntry indexEntry;
       
   957 
       
   958     User::LeaveIfError( iMsvSessionPtr->GetEntry(
       
   959                         KMsvRootIndexEntryId, id, indexEntry ) );
       
   960 
       
   961     CBaseMtmUiData& mtmUiData = iMtmStore->MtmUiDataL( aMtmUid );
       
   962 
       
   963     TInt validAccounts = ETrue;
       
   964     TMsvEntry serviceEntry;
       
   965     serviceEntry.iType.iUid = KUidMsvServiceEntryValue;
       
   966     serviceEntry.iMtm = aMtmUid;
       
   967 
       
   968     if ( mtmUiData.CanCreateEntryL( indexEntry, serviceEntry, response ) )
       
   969         {
       
   970         CMsvEntrySelection* accounts =
       
   971         MsvUiServiceUtilities::GetListOfAccountsWithMTML(
       
   972                                *iMsvSessionPtr, aMtmUid, ETrue );
       
   973 
       
   974         if ( accounts->Count() == 0 )
       
   975             {
       
   976             validAccounts = EFalse;
       
   977             }
       
   978         
       
   979         delete accounts;
       
   980         accounts = NULL;
       
   981         }
       
   982 
       
   983     if ( !validAccounts )
       
   984         {
       
   985         iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
   986         return EFalse;
       
   987         }
       
   988 
       
   989     // Query capabilities
       
   990     if ( mtmUiData.QueryCapability( 
       
   991             canCreateNewMsg, response ) != KErrNone )
       
   992         {
       
   993         iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
   994         return EFalse;
       
   995         }
       
   996 
       
   997     mtmUiData.QueryCapability( KUidMtmQueryMaxBodySize, response );
       
   998     if ( response < iRequiredCapabilities.iBodySize )
       
   999         {
       
  1000         iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache        
       
  1001         return EFalse;
       
  1002         }
       
  1003 
       
  1004     mtmUiData.QueryCapability( KUidMtmQueryMaxTotalMsgSize, response );
       
  1005     if ( response < iRequiredCapabilities.iMessageSize )
       
  1006         {
       
  1007         iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
  1008         return EFalse;
       
  1009         }
       
  1010 
       
  1011     if ( iRequiredCapabilities.iFlags == TSendingCapabilities::EAllServices )
       
  1012         { // No capabilities required from service
       
  1013         iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
  1014         return ETrue;
       
  1015         }
       
  1016 
       
  1017     // Check if support for attachments are required.
       
  1018     if ( iRequiredCapabilities.iFlags & 
       
  1019             TSendingCapabilities::ESupportsAttachments )
       
  1020         {
       
  1021         if ( mtmUiData.QueryCapability( 
       
  1022                 KUidMtmQuerySupportAttachments, response ) == KErrNone )
       
  1023             {
       
  1024             iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
  1025             return ETrue;
       
  1026             }
       
  1027         }
       
  1028 
       
  1029     // Check if support for body text is required.
       
  1030     if ( iRequiredCapabilities.iFlags &
       
  1031             TSendingCapabilities::ESupportsBodyText )
       
  1032         {
       
  1033         if ( mtmUiData.QueryCapability( 
       
  1034                 KUidMtmQuerySupportedBody, response ) == KErrNone )
       
  1035             {
       
  1036             iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
  1037             return ETrue;
       
  1038             }
       
  1039         }
       
  1040 
       
  1041     // Check if support for BIO sending is required.
       
  1042     if ( iRequiredCapabilities.iFlags & 
       
  1043             TSendingCapabilities::ESupportsBioSending )
       
  1044         {
       
  1045         if ( mtmUiData.QueryCapability(
       
  1046                 KUidMsvQuerySupportsBioMsg, response ) == KErrNone )
       
  1047             {
       
  1048             iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
  1049             return ETrue;
       
  1050             }
       
  1051         }
       
  1052 
       
  1053     // Check if support for editor is required.
       
  1054     if ( iRequiredCapabilities.iFlags &
       
  1055             TSendingCapabilities::ESupportsEditor )
       
  1056         {
       
  1057         if ( mtmUiData.QueryCapability(
       
  1058                 supportEditor, response ) == KErrNone )
       
  1059             {
       
  1060             iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
  1061             return ETrue;
       
  1062             }
       
  1063         }
       
  1064 
       
  1065     iMtmStore->ReleaseMtmUiData( aMtmUid ); // Remove from cache
       
  1066     return EFalse;
       
  1067     }
       
  1068 	
       
  1069 //  End of File
       
  1070