emailservices/emailframework/src/CFSMailBrandManagerImpl.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  ES Protocol Framework branding manager interface definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <fsmailbrandmanager.rsg>
       
    21 #include <barsread.h>
       
    22 #include <bautils.h>
       
    23 #include <mmf/common/mmfcontrollerpluginresolver.h> // CleanupResetAndDestroy
       
    24 // <gmail_brand_issue>
       
    25 #include <etelmm.h>
       
    26 #include <mmtsy_names.h>
       
    27 #include <startupdomainpskeys.h>
       
    28 #include <tzlocalizer.h> // CTzLocalizer
       
    29 #include <centralrepository.h>
       
    30 // </gmail_brand_issue>
       
    31 //<cmail>
       
    32 #include "CFSMailClient.h"
       
    33 //</cmail>
       
    34 
       
    35 #include "CFSMailBrandManagerImpl.h"
       
    36 #include "CFSMailBrand.h"
       
    37 
       
    38 
       
    39 const TInt KBrandArrayGranularity = 5;
       
    40 _LIT( KResourceFilePath,"\\resource\\fsmailbrandmanager.rsc" );
       
    41 
       
    42 // The following are needed to convert "Gmail" brand name to "Google Mail"
       
    43 // in certain countries.
       
    44 // <gmail_brand_issue>
       
    45 
       
    46 _LIT( KBrandNameGmail, "Gmail" );
       
    47 _LIT( KBrandNameGoogleMail, "Google Mail" );
       
    48 
       
    49 _LIT( KMCCGermany, "262" );
       
    50 _LIT( KMCCUK1, "234" );
       
    51 _LIT( KMCCUK2, "235" );
       
    52 
       
    53 const TUint8 KGermanyTzId = 36;
       
    54 const TUint8 KUKTzId = 104;
       
    55 
       
    56 const TInt KMCCValueMaxLength = 3;
       
    57 
       
    58 #ifdef __WINS__
       
    59 LOCAL_C void RetrieveNextToken( TDes8& aContent, TDes& aToken )	
       
    60 	{
       
    61 	_LIT8( KComma, "," );
       
    62 	TInt pos = aContent.Find( KComma );
       
    63 	if ( pos != KErrNotFound ) 
       
    64 		{
       
    65 		aToken.Copy( aContent.MidTPtr( 0, pos ) );
       
    66 		aContent.Copy(
       
    67 		    aContent.RightTPtr( aContent.Length() - pos - 1 ) );
       
    68 		}
       
    69 	}
       
    70 #endif // __WINS__
       
    71 // </gmail_brand_issue>
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CFSMailBrandManagerImpl::CFSMailBrandManagerImpl
       
    75 // -----------------------------------------------------------------------------
       
    76 CFSMailBrandManagerImpl::CFSMailBrandManagerImpl(
       
    77     CFSMailClient& aMailClient ) :
       
    78     iMailClient( aMailClient )
       
    79 	{
       
    80     FUNC_LOG;
       
    81 
       
    82 	}
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CFSMailBrandManagerImpl::ConstructL
       
    86 // -----------------------------------------------------------------------------
       
    87 void CFSMailBrandManagerImpl::ConstructL()
       
    88     {
       
    89     FUNC_LOG;
       
    90 
       
    91     // Read resource file, get the drive letter according to the DLL drive
       
    92     TFileName dllFileName;
       
    93     Dll::FileName( dllFileName );
       
    94     
       
    95  	TParse parse;
       
    96     User::LeaveIfError( parse.Set( KResourceFilePath, &dllFileName, NULL ) );
       
    97     TFileName resourceFileName( parse.FullName() );
       
    98 
       
    99     if ( !iFsSession.Handle() )
       
   100         {
       
   101         User::LeaveIfError( iFsSession.Connect() );
       
   102         }
       
   103 
       
   104     BaflUtils::NearestLanguageFile( iFsSession, resourceFileName );
       
   105     
       
   106     iResourceFile.OpenL( iFsSession, resourceFileName );
       
   107         
       
   108     iResourceFile.ConfirmSignatureL();
       
   109 
       
   110     HBufC8* resourceBuffer = iResourceFile.AllocReadLC( R_BRANDING_DATA );
       
   111 
       
   112     TResourceReader reader;
       
   113     reader.SetBuffer( resourceBuffer );
       
   114 
       
   115 	ConstructFromResourceL( reader );
       
   116 
       
   117     CleanupStack::PopAndDestroy( resourceBuffer );
       
   118 
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CFSMailBrandManagerImpl::~CFSMailBrandManagerImpl
       
   123 // -----------------------------------------------------------------------------
       
   124 CFSMailBrandManagerImpl::~CFSMailBrandManagerImpl()
       
   125 	{
       
   126     FUNC_LOG;
       
   127 	
       
   128 	iResourceFile.Close();
       
   129     iFsSession.Close();
       
   130 	
       
   131 	if ( iBrands )
       
   132 		{
       
   133 		iBrands->ResetAndDestroy();
       
   134 		}
       
   135 	delete iBrands;
       
   136 	}
       
   137 	
       
   138 // -----------------------------------------------------------------------------
       
   139 // CFSMailBrandManagerImpl::NewL
       
   140 // -----------------------------------------------------------------------------
       
   141 CFSMailBrandManagerImpl* CFSMailBrandManagerImpl::NewL(
       
   142     CFSMailClient& aMailClient )
       
   143     {
       
   144     FUNC_LOG;
       
   145     CFSMailBrandManagerImpl* self =
       
   146         CFSMailBrandManagerImpl::NewLC( aMailClient );
       
   147     CleanupStack::Pop( self );
       
   148     return self;
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CFSMailBrandManagerImpl::NewLC
       
   153 // -----------------------------------------------------------------------------
       
   154 CFSMailBrandManagerImpl* CFSMailBrandManagerImpl::NewLC(
       
   155     CFSMailClient& aMailClient )
       
   156     {
       
   157     FUNC_LOG;
       
   158     CFSMailBrandManagerImpl* self =
       
   159         new( ELeave ) CFSMailBrandManagerImpl( aMailClient );
       
   160     CleanupStack::PushL( self );
       
   161     self->ConstructL();
       
   162     return self;
       
   163     }
       
   164     
       
   165 // -----------------------------------------------------------------------------
       
   166 // CFSMailBrandManagerImpl::UpdateMailboxNamesL
       
   167 // -----------------------------------------------------------------------------
       
   168 void CFSMailBrandManagerImpl::UpdateMailboxNamesL( const TFSMailMsgId aMailBoxId )
       
   169     {
       
   170     FUNC_LOG;
       
   171     
       
   172     // list all mailboxes
       
   173     RPointerArray<CFSMailBox> mailBoxes;
       
   174     CleanupResetAndDestroyPushL( mailBoxes );
       
   175     iMailClient.ListMailBoxes( TFSMailMsgId(), mailBoxes );
       
   176     // Check is there need to change the name of the mailbox
       
   177     TPtrC name = GetTextL( EFSMailboxName, aMailBoxId);
       
   178     // <gmail_brand_issue>
       
   179     VerifyMailAccountName( name );
       
   180     // </gmail_brand_issue>
       
   181     if( name.Length() )
       
   182         {
       
   183         // check duplicates
       
   184         TInt orderNumber(2);
       
   185         TBool duplicate(ETrue);
       
   186         HBufC* newName = HBufC::NewL(name.Length()+6);
       
   187         TPtrC brandedName = name;
       
   188         while(duplicate != EFalse)
       
   189             {
       
   190             duplicate = EFalse;
       
   191             for(TInt i = 0; i < mailBoxes.Count( );i++)
       
   192                 {
       
   193                 if(brandedName == mailBoxes[i]->GetName() && 
       
   194                    aMailBoxId != mailBoxes[i]->GetId( ))
       
   195                     {
       
   196                     duplicate = ETrue;
       
   197                     newName->Des().Copy(name);
       
   198                     newName->Des().Append(' ');
       
   199                     newName->Des().Append('(');
       
   200                     newName->Des().AppendNum(orderNumber++);
       
   201                     newName->Des().Append(')');
       
   202                     brandedName.Set(newName->Des());
       
   203                     break;
       
   204                     }
       
   205                 }
       
   206             }
       
   207         iMailClient.SetMailboxName(aMailBoxId,brandedName);
       
   208         delete newName;
       
   209         }
       
   210     CleanupStack::PopAndDestroy( &mailBoxes );
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CFSMailBrandManagerImpl::GetGraphicL
       
   215 // -----------------------------------------------------------------------------
       
   216 CGulIcon* CFSMailBrandManagerImpl::GetGraphicL(
       
   217     TFSBrandElement aElement, 
       
   218 	const TFSMailMsgId& aMailboxId )
       
   219 	{
       
   220     FUNC_LOG;
       
   221 	CFSMailBox* mailBox( NULL );
       
   222 	TRAPD( mailboxError,
       
   223 	       mailBox = iMailClient.GetMailBoxByUidL( aMailboxId ) );
       
   224 	if ( mailboxError != KErrNone )
       
   225 	    {
       
   226 	    User::Leave( mailboxError );
       
   227 	    }	
       
   228 	User::LeaveIfNull( mailBox );
       
   229 	
       
   230     CleanupStack::PushL( mailBox );    
       
   231     TDesC& brandId = mailBox->GetBrandingIdL();
       
   232 
       
   233 	CFSMailBrand* brand = FindMatchingBrandL( brandId );
       
   234 	CleanupStack::PopAndDestroy( mailBox );
       
   235 	if ( brand == NULL )
       
   236 	    {
       
   237 	    return NULL;    
       
   238 	    }
       
   239 	
       
   240 	return brand->GetGraphicL( aElement );
       
   241 	}
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CFSMailBrandManagerImpl::GetGraphicL
       
   245 // -----------------------------------------------------------------------------
       
   246 CGulIcon* CFSMailBrandManagerImpl::GetGraphicL(
       
   247     TFSBrandElement aElement, 
       
   248     const TDesC& aBrandId )
       
   249     {
       
   250     FUNC_LOG;
       
   251     CFSMailBrand* brand = FindMatchingBrandL( aBrandId );
       
   252     if ( brand == NULL )
       
   253         {
       
   254         return NULL;    
       
   255         }    
       
   256     return brand->GetGraphicL( aElement );
       
   257     }
       
   258     
       
   259 // -----------------------------------------------------------------------------
       
   260 // CFSMailBrandManagerImpl::GetGraphicIdsL
       
   261 // -----------------------------------------------------------------------------
       
   262 TInt CFSMailBrandManagerImpl::GetGraphicIdsL(
       
   263     TFSBrandElement aElement, 
       
   264 	const TFSMailMsgId& aMailboxId,
       
   265     TDes& aIconIds  )
       
   266 	{
       
   267     FUNC_LOG;
       
   268 	CFSMailBox* mailBox( NULL );
       
   269 	TRAPD( mailboxError,
       
   270 	       mailBox = iMailClient.GetMailBoxByUidL( aMailboxId ) );
       
   271 	if ( mailboxError != KErrNone )
       
   272 	    {
       
   273 	    User::Leave( mailboxError );
       
   274 	    }	
       
   275 	User::LeaveIfNull( mailBox );
       
   276 	
       
   277     CleanupStack::PushL( mailBox );    
       
   278     TDesC& brandId = mailBox->GetBrandingIdL();
       
   279 
       
   280 	CFSMailBrand* brand = FindMatchingBrandL( brandId );
       
   281 	CleanupStack::PopAndDestroy( mailBox );
       
   282 
       
   283 	if ( brand == NULL )
       
   284 	    {
       
   285 	    return KErrNotFound;
       
   286 	    }
       
   287     return brand->GetGraphicIdsL( aElement, aIconIds );
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CFSMailBrandManagerImpl::GetTextL
       
   292 // -----------------------------------------------------------------------------
       
   293 TPtrC CFSMailBrandManagerImpl::GetTextL(
       
   294     TFSBrandElement aElement,
       
   295     const TFSMailMsgId& aMailboxId )
       
   296 	{
       
   297     FUNC_LOG;
       
   298 	CFSMailBox* mailBox( NULL );
       
   299 	TRAPD( mailboxError,
       
   300 	       mailBox = iMailClient.GetMailBoxByUidL( aMailboxId ) );
       
   301 	if ( mailboxError != KErrNone )
       
   302 	    {
       
   303 	    User::Leave( mailboxError );
       
   304 	    }
       
   305 	    
       
   306 	User::LeaveIfNull( mailBox );
       
   307     CleanupStack::PushL( mailBox );
       
   308     TDesC& brandId = mailBox->GetBrandingIdL();
       
   309 	
       
   310 	CFSMailBrand* brand = FindMatchingBrandL( brandId );
       
   311 	CleanupStack::PopAndDestroy( mailBox );
       
   312 	if ( brand == NULL )
       
   313 	    {
       
   314 	    return KNullDesC();    
       
   315 	    }	
       
   316 	
       
   317 	return brand->GetText( aElement );
       
   318 	}
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // CFSMailBrandManagerImpl::GetTextL
       
   322 // -----------------------------------------------------------------------------
       
   323 TPtrC CFSMailBrandManagerImpl::GetTextL(
       
   324 	TFSBrandElement aElement,
       
   325 	const TDesC& aBrandId )
       
   326 	{
       
   327     FUNC_LOG;
       
   328 
       
   329 	CFSMailBrand* brand = FindMatchingBrandL( aBrandId );
       
   330 	if ( brand == NULL )
       
   331 	    {
       
   332 	    return KNullDesC();    
       
   333 	    }	
       
   334 
       
   335 	return brand->GetText( aElement );
       
   336 	}
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CFSMailBrandManagerImpl::GetColorL
       
   340 // -----------------------------------------------------------------------------
       
   341 TInt CFSMailBrandManagerImpl::GetColorL(
       
   342     TFSBrandElement aElement,
       
   343     const TFSMailMsgId& aMailboxId,
       
   344     TRgb& aColor )
       
   345 	{
       
   346     FUNC_LOG;
       
   347 	CFSMailBox* mailBox = iMailClient.GetMailBoxByUidL( aMailboxId );
       
   348 	User::LeaveIfNull( mailBox );
       
   349     CleanupStack::PushL( mailBox );    
       
   350     TDesC& brandId = mailBox->GetBrandingIdL();
       
   351 	
       
   352 	CFSMailBrand* brand = FindMatchingBrandL( brandId );
       
   353 	CleanupStack::PopAndDestroy( mailBox );
       
   354 	if ( brand == NULL )
       
   355 	    {
       
   356 	    return KErrNotFound;  
       
   357 	    }
       
   358 	    
       
   359     return brand->GetColor( aElement, aColor );
       
   360 	}
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CFSMailBrandManagerImpl::ConstructFromResourceL
       
   364 // -----------------------------------------------------------------------------
       
   365 void CFSMailBrandManagerImpl::ConstructFromResourceL( TResourceReader& aReader )
       
   366 	{
       
   367     FUNC_LOG;
       
   368 	iBrands = new ( ELeave )
       
   369 				CArrayPtrSeg< CFSMailBrand >( KBrandArrayGranularity );
       
   370 						
       
   371 	// Read White Label Brand from Cenrep
       
   372 	CFSMailBrand* newBrand = CFSMailBrand::NewLC( aReader, true );
       
   373 	iBrands->AppendL( newBrand );
       
   374 	CleanupStack::Pop( newBrand );
       
   375 	
       
   376 	
       
   377 	// Read general brands from resource file
       
   378 	TInt brandCount = aReader.ReadInt16();
       
   379 
       
   380 	for ( TInt i = 0; i < brandCount; i++ )
       
   381 		{
       
   382 		CFSMailBrand* newBrand = CFSMailBrand::NewLC( aReader, false );
       
   383 		iBrands->AppendL( newBrand );
       
   384 		CleanupStack::Pop( newBrand );
       
   385 		}
       
   386 	}
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CFSMailBrandManagerImpl::FindMatchingBrandL
       
   390 // -----------------------------------------------------------------------------
       
   391 CFSMailBrand* CFSMailBrandManagerImpl::FindMatchingBrandL( const TDesC& aBrandId )
       
   392     {
       
   393     FUNC_LOG;
       
   394     if( aBrandId.Length() )
       
   395         {
       
   396         TInt brandCount( iBrands->Count() );
       
   397         for ( TInt i( 0 ); i < brandCount; i++ )
       
   398             {
       
   399             if ( (*iBrands)[ i ]->IsMatching( aBrandId ) )
       
   400                 return (*iBrands)[ i ];
       
   401             }
       
   402         }
       
   403     return NULL;
       
   404     }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // CFSMailBrandManagerImpl::MailboxMatchingBrandIdL
       
   408 // -----------------------------------------------------------------------------
       
   409 CFSMailBox* CFSMailBrandManagerImpl::MailboxMatchingBrandIdL(
       
   410     const TDesC& aBrandId ) const
       
   411     {    
       
   412     RPointerArray<CFSMailBox> mailboxes;
       
   413 
       
   414     CleanupResetAndDestroyPushL( mailboxes );
       
   415 
       
   416     iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxes );
       
   417 
       
   418     TInt mailboxCount( mailboxes.Count() );
       
   419     TInt mailboxIndexer( 0 );
       
   420     while ( mailboxIndexer < mailboxCount )
       
   421         {
       
   422         TDesC* brandId( NULL );
       
   423         TRAPD( brandGetError,
       
   424                brandId = &mailboxes[mailboxIndexer]->GetBrandingIdL() )
       
   425         if ( brandGetError != KErrNone )
       
   426             {
       
   427             mailboxes.ResetAndDestroy();
       
   428             User::Leave( brandGetError );
       
   429             }
       
   430             
       
   431         if ( *brandId == aBrandId )
       
   432             {
       
   433             CFSMailBox* matchingMailbox = mailboxes[mailboxIndexer];
       
   434             mailboxes.Remove( mailboxIndexer );
       
   435             mailboxes.ResetAndDestroy();
       
   436             return matchingMailbox;
       
   437             }
       
   438         
       
   439         ++mailboxIndexer;
       
   440         }
       
   441         
       
   442     CleanupStack::PopAndDestroy( &mailboxes );
       
   443     User::Leave( KErrNotFound );
       
   444     return NULL; // To prevent warning
       
   445     }
       
   446 
       
   447 // <gmail_brand_issue>
       
   448 // -----------------------------------------------------------------------------
       
   449 // CFSMailBrandManagerImpl::GetMCCValueL
       
   450 // -----------------------------------------------------------------------------
       
   451 void CFSMailBrandManagerImpl::GetMCCValueL( TDes& aMcc ) const
       
   452     {
       
   453     aMcc.Zero();
       
   454     
       
   455     TInt err = KErrNone;
       
   456 
       
   457 #ifndef __WINS__
       
   458 
       
   459     TBool isSimPresent = EFalse;
       
   460     
       
   461     TInt simStatus( 0 );
       
   462 
       
   463 	err = RProperty::Get( KPSUidStartup, KPSSimStatus, simStatus );
       
   464 
       
   465 	if ( err == KErrNone &&
       
   466 	        simStatus != ESimNotPresent &&
       
   467 	        simStatus != ESimNotSupported )
       
   468 	    {
       
   469 	    isSimPresent = ETrue;
       
   470 	    }
       
   471 
       
   472     if ( isSimPresent )
       
   473         {
       
   474         // We cannot let the method leave here
       
   475         TRAP( err, GetMCCValueFromSIML( aMcc ) );
       
   476 
       
   477         // If reading from SIM fails one time try again after 0.5 secs
       
   478         if ( err != KErrNone )
       
   479             {
       
   480             const TInt KHalfSecond = 500000;
       
   481 
       
   482             User::After( KHalfSecond );
       
   483             
       
   484             err = KErrNone;
       
   485 
       
   486             // We cannot let the method leave here
       
   487             TRAP( err, GetMCCValueFromSIML( aMcc ) );
       
   488             }
       
   489         }
       
   490 
       
   491 #else // __WINS__
       
   492 
       
   493     _LIT( KSIMInfo, "C:\\data\\Settings\\SIMInfo.txt" );
       
   494 
       
   495     RFs fs;
       
   496 
       
   497     User::LeaveIfError( fs.Connect() );
       
   498 
       
   499     RFile simFile;
       
   500 
       
   501     err = simFile.Open( fs, KSIMInfo(), EFileShareReadersOnly |
       
   502                                         EFileStream |
       
   503                                         EFileRead );
       
   504     if ( err == KErrNone )
       
   505         {
       
   506         TBuf8<100> content;
       
   507         TBuf<100> dummy;
       
   508 
       
   509         simFile.Read( content );
       
   510 
       
   511     	simFile.Close();
       
   512 
       
   513     	fs.Close();
       
   514 
       
   515         if ( content.Length() > 0 )
       
   516         	{
       
   517             RetrieveNextToken( content, dummy );
       
   518             RetrieveNextToken( content, dummy );
       
   519             RetrieveNextToken( content, dummy );
       
   520             RetrieveNextToken( content, dummy );
       
   521 
       
   522             RMobilePhone::TMobilePhoneSubscriberId subscriberId;
       
   523 
       
   524             RetrieveNextToken( content, subscriberId );
       
   525 
       
   526             if ( subscriberId.Length() >= KMCCValueMaxLength )
       
   527                 {
       
   528                 aMcc = subscriberId.Left( KMCCValueMaxLength );
       
   529                 }
       
   530         	}
       
   531         }
       
   532 
       
   533 #endif // __WINS__
       
   534 
       
   535     }
       
   536 
       
   537 // ----------------------------------------------------------------------------
       
   538 // CFSMailBrandManagerImpl::GetMCCValueFromSIML
       
   539 // ----------------------------------------------------------------------------
       
   540 // 
       
   541 void CFSMailBrandManagerImpl::GetMCCValueFromSIML( TDes& aMcc ) const
       
   542     {
       
   543     RTelServer telServer;
       
   544 
       
   545     CleanupClosePushL( telServer );
       
   546 
       
   547     User::LeaveIfError( telServer.Connect() );
       
   548 
       
   549     User::LeaveIfError( telServer.LoadPhoneModule( KMmTsyModuleName ) );
       
   550     
       
   551     RMobilePhone mobilePhone;
       
   552 
       
   553     CleanupClosePushL( mobilePhone );
       
   554 
       
   555     User::LeaveIfError( mobilePhone.Open( telServer, KMmTsyPhoneName ) );
       
   556     
       
   557     TRequestStatus status;
       
   558 
       
   559     RMobilePhone::TMobilePhoneSubscriberId subscriberId;       
       
   560 
       
   561     mobilePhone.GetSubscriberId( status, subscriberId );
       
   562     
       
   563     User::WaitForRequest( status );
       
   564 
       
   565     User::LeaveIfError( status.Int() );
       
   566     
       
   567     CleanupStack::PopAndDestroy( &mobilePhone );
       
   568 
       
   569     CleanupStack::PopAndDestroy( &telServer );
       
   570 
       
   571     if ( subscriberId.Length() >= KMCCValueMaxLength )
       
   572         {
       
   573         aMcc = subscriberId.Left( KMCCValueMaxLength );
       
   574         }
       
   575     }
       
   576 
       
   577 // ----------------------------------------------------------------------------
       
   578 // CFSMailBrandManagerImpl::GetCurrentCountryL
       
   579 // ----------------------------------------------------------------------------
       
   580 // 
       
   581 TUint8 CFSMailBrandManagerImpl::GetCurrentCountryL() const
       
   582     {
       
   583     CTzLocalizer* localizer = CTzLocalizer::NewLC();
       
   584 
       
   585     CTzLocalizedCity* city = localizer->GetFrequentlyUsedZoneCityL(
       
   586         CTzLocalizedTimeZone::ECurrentZone );
       
   587         
       
   588     CleanupStack::PushL( city );
       
   589 
       
   590     CTzLocalizedCityGroup* cityGroup = 
       
   591         localizer->GetCityGroupL( city->GroupId() );
       
   592 
       
   593     TUint8 countryId = cityGroup->Id();
       
   594     
       
   595     delete cityGroup;
       
   596     cityGroup = NULL;
       
   597     
       
   598     CleanupStack::PopAndDestroy( 2, localizer );
       
   599     
       
   600     return countryId;
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CFSMailBrandManagerImpl::VerifyMailAccountName
       
   605 // -----------------------------------------------------------------------------
       
   606 void CFSMailBrandManagerImpl::VerifyMailAccountName(
       
   607         TPtrC& aBrandedName ) const
       
   608     {
       
   609     // Due to legal reasons we don't show brand name "Gmail" in Germany and UK
       
   610     if ( !aBrandedName.CompareF( KBrandNameGmail ) )
       
   611         {
       
   612         // First check timezone id
       
   613         TUint8 timeZone = 0;
       
   614         
       
   615         TRAPD( err, timeZone = GetCurrentCountryL() );
       
   616         
       
   617         if ( err == KErrNone && ( timeZone == KGermanyTzId ||
       
   618                                   timeZone == KUKTzId ) )
       
   619             {
       
   620             aBrandedName.Set( KBrandNameGoogleMail );
       
   621             }
       
   622         // Then if necessary check MCC
       
   623         else
       
   624             {
       
   625             TBuf<KMCCValueMaxLength> mcc;
       
   626 
       
   627             TRAPD( err2, GetMCCValueL( mcc ) );
       
   628             
       
   629             if ( err2 == KErrNone && ( mcc == KMCCGermany ||
       
   630                                        mcc == KMCCUK1 ||
       
   631                                        mcc == KMCCUK2 ) )
       
   632                 {
       
   633                 aBrandedName.Set( KBrandNameGoogleMail );
       
   634                 }
       
   635             }
       
   636 
       
   637         }
       
   638     }
       
   639 // </gmail_brand_issue>