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