ipsservices/ipssossettings/src/ipssetgwizardadapter.cpp
changeset 0 8466d47a6819
child 12 f5907b1a1053
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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: This file implements class CIpsSetWizardAdapter.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //INCLUDES
       
    20 #include "emailtrace.h"
       
    21 #include <e32base.h>
       
    22 #include <SendUiConsts.h>
       
    23 //<cmail>
       
    24 //#include <aplistitemlist.h>         // CApListItemList
       
    25 //#include <aplistitem.h>             // CApListItem
       
    26 //</cmail>
       
    27 #include <centralrepository.h>      // CRepository
       
    28 #include <AlwaysOnlineManagerClient.h>
       
    29 
       
    30 #include "ipssetwizardadapter.h"
       
    31 #include "ipssetdatamanager.h"
       
    32 #include "ipssetuiitemaccesspoint.h"
       
    33 #include "ipssetutils.h"
       
    34 #include "ipssetdataextension.h"
       
    35 
       
    36 
       
    37 #include "ipssetdata.h"
       
    38 
       
    39 
       
    40 // becuase of RD_IPS_AO_PLUGIN flag, can be removed
       
    41 // when flag is removed
       
    42 #include "ipsplgsosbaseplugin.hrh"
       
    43 
       
    44 //CONSTANTS
       
    45 const TInt KMaxMailboxes = 10;
       
    46 
       
    47 // security enums in fs wizard cenrep cenrep
       
    48 // Security protocol (0 = OFF, 1 = StartTLS, 2 = SSL/TLS)
       
    49 const TInt KWizardDataSecurityOff = 0;
       
    50 const TInt KWizardDataSecurityTLS = 1;
       
    51 const TInt KWizardDataSecuritySSL = 2;
       
    52 
       
    53 const TInt KWizardTCPMaxPort = 65535;
       
    54 
       
    55 const TInt KWizardMaxUidValue = 50;
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // ---------------------------------------------------------------------------
       
    59 CIpsSetWizardAdapter* CIpsSetWizardAdapter::NewL( 
       
    60     CRepository& aRepository, CMsvSession& aSession ) 
       
    61     {
       
    62     FUNC_LOG;
       
    63     CIpsSetWizardAdapter* self = CIpsSetWizardAdapter::NewLC( 
       
    64         aRepository, aSession );
       
    65     CleanupStack::Pop( self );
       
    66     return self;
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // ---------------------------------------------------------------------------
       
    72 CIpsSetWizardAdapter* CIpsSetWizardAdapter::NewLC( 
       
    73     CRepository& aRepository, CMsvSession& aSession )
       
    74     {
       
    75     FUNC_LOG;
       
    76     CIpsSetWizardAdapter* self = new( 
       
    77         ELeave ) CIpsSetWizardAdapter( aRepository, aSession );
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL( );
       
    80     return self;
       
    81     }
       
    82 
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // ---------------------------------------------------------------------------
       
    86 CIpsSetWizardAdapter::~CIpsSetWizardAdapter()
       
    87     {
       
    88     FUNC_LOG;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // ---------------------------------------------------------------------------
       
    93 CIpsSetWizardAdapter::CIpsSetWizardAdapter( 
       
    94     CRepository& aRepository, CMsvSession& aSession ) 
       
    95     : iWizardCenRep( aRepository ), iSession( aSession ) 
       
    96     {
       
    97     FUNC_LOG;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // ---------------------------------------------------------------------------
       
   102 void CIpsSetWizardAdapter::ConstructL()
       
   103     {
       
   104     FUNC_LOG;
       
   105     ClearFields();
       
   106     }
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // ---------------------------------------------------------------------------
       
   111 void CIpsSetWizardAdapter::ClearFields()
       
   112     {
       
   113     FUNC_LOG;
       
   114     iAccountNumber = 0;
       
   115     iMaxAccounts = 0;
       
   116     iEmailAddress.Zero();
       
   117     iUsername.Zero();
       
   118     iPassword.Zero();
       
   119     iIncomingServer.Zero();
       
   120     iProtocol = 0;
       
   121     iInSecurityAuth = 0;
       
   122     iInSecurityProtocol = 0;
       
   123     iInIncomingPort = 0;
       
   124     iProviderOutgoingServer.Zero();
       
   125     iProviderOutSecurityAuth = 0;
       
   126     iProviderOutSecurityProtocol = 0;
       
   127     iProviderOutgoingPort = 0;
       
   128     iOperatorOutgoingServer.Zero();
       
   129     iOperatorOutSecurityAuth = 0;
       
   130     iOperatorOutSecurityProtocol = 0;
       
   131     iOperatorOutgoingPort = 0;
       
   132     //<cmail>
       
   133     iHiddenData = EFalse;
       
   134     //</cmail>
       
   135     iRecomendedAP.Zero();
       
   136     iMailboxName.Zero();
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // ---------------------------------------------------------------------------
       
   141 void CIpsSetWizardAdapter::ReadWizardSettignsL()
       
   142     {
       
   143     FUNC_LOG;
       
   144     ClearFields();
       
   145     
       
   146     //<cmail>
       
   147     
       
   148     TIpsSetUtilsTextPlain tempText;
       
   149     TInt error = KErrNone;
       
   150      
       
   151     error = GetIntFromCenRepL( ECRKAccountsConfigured, iAccountNumber );
       
   152     if ( error != KErrNone )
       
   153         {
       
   154         iAccountNumber = KCRKAccountsConfiguredDefault;
       
   155         }
       
   156     
       
   157     error = GetIntFromCenRepL( ECRKMaxAccountsReached, iMaxAccounts );
       
   158     if ( error != KErrNone )
       
   159         {
       
   160         iMaxAccounts = KCRKMaxAccountsReachedDefault;
       
   161         }
       
   162     
       
   163     error = GetTextFromCenRepL( ECRKPopImapEmailAddressId, iEmailAddress );
       
   164     if ( error != KErrNone )
       
   165         {
       
   166         iEmailAddress = KCRKPopImapEmailAddressIdDefault;
       
   167         }
       
   168     
       
   169     tempText.Zero();
       
   170     error = GetTextFromCenRepL( ECRKPopImapUsernameId, tempText );
       
   171     if ( error != KErrNone )
       
   172         {
       
   173         tempText = KCRKPopImapUsernameIdDefault;
       
   174         }
       
   175     ChangeAsciiPrintable( tempText, iUsername );
       
   176     
       
   177     tempText.Zero();
       
   178     error = GetTextFromCenRepL( ECRKPopImapPasswordId, tempText );
       
   179     if ( error != KErrNone )
       
   180         {
       
   181         tempText = KCRKPopImapPasswordIdDefault;
       
   182         }
       
   183     ChangeAsciiPrintable( tempText, iPassword );
       
   184     
       
   185     tempText.Zero();
       
   186     error = GetTextFromCenRepL( ECRKPopImapIncomingServerId, tempText );
       
   187     if ( error != KErrNone )
       
   188         {
       
   189         tempText = KCRKPopImapIncomingServerIdDefault;
       
   190         }
       
   191     ChangeAsciiPrintable( tempText, iIncomingServer );
       
   192     
       
   193     error = GetIntFromCenRepL( ECRKPopImapProtocolIndicatorId, iProtocol );
       
   194     if ( error != KErrNone )
       
   195         {
       
   196         iProtocol = KCRKPopImapProtocolIndicatorIdDefault;
       
   197         }
       
   198     
       
   199     error = GetIntFromCenRepL( ECRKPopImapIncomingSecurityAuthId, iInSecurityAuth );
       
   200     if ( error != KErrNone )
       
   201         {
       
   202         iInSecurityAuth = KCRKPopImapIncomingSecurityAuthIdDefault;
       
   203         }
       
   204     
       
   205     error = GetIntFromCenRepL( ECRKPopImapIncomingSecurityProtocolId, 
       
   206             iInSecurityProtocol );
       
   207     if ( error != KErrNone )
       
   208         {
       
   209         iInSecurityProtocol = KCRKPopImapIncomingSecurityProtocolIdDefault;
       
   210         }
       
   211     
       
   212     error = GetIntFromCenRepL(  ECRKPopImapIncomingPortId, iInIncomingPort );
       
   213     if ( error != KErrNone )
       
   214         {
       
   215         iInIncomingPort = KCRKPopImapIncomingPortIdDefault;
       
   216         }
       
   217 
       
   218     tempText.Zero();
       
   219     error = GetTextFromCenRepL( ECRKPopImapOutgoingServerId, tempText );
       
   220     if ( error != KErrNone )
       
   221         {
       
   222         tempText = KCRKPopImapOutgoingServerIdDefault;
       
   223         }
       
   224     ChangeAsciiPrintable( tempText, iProviderOutgoingServer );
       
   225     
       
   226     error = GetIntFromCenRepL( ECRKPopImapOutgoingSecurityAuthId, 
       
   227             iProviderOutSecurityAuth );
       
   228     if ( error != KErrNone )
       
   229         {
       
   230         iProviderOutSecurityAuth = KCRKPopImapOutgoingSecurityAuthIdDefault;
       
   231         }
       
   232     
       
   233     error = GetIntFromCenRepL( ECRKPopImapOutgoingSecurityProtocolId, 
       
   234             iProviderOutSecurityProtocol );
       
   235     if ( error != KErrNone )
       
   236         {
       
   237         iProviderOutSecurityProtocol = KCRKPopImapOutgoingSecurityProtocolIdDefault;
       
   238         }
       
   239     
       
   240     error = GetIntFromCenRepL( ECRKPopImapOutgoingPortId, iProviderOutgoingPort );
       
   241     if ( error != KErrNone )
       
   242         {
       
   243         iProviderOutgoingPort = KCRKPopImapOutgoingPortIdDefault;
       
   244         }
       
   245     
       
   246     error = GetTextFromCenRepL( ECRKPopImapOperatorOutgoingServerId, 
       
   247             iOperatorOutgoingServer );
       
   248     if ( error != KErrNone )
       
   249         {
       
   250         iOperatorOutgoingServer = KCRKPopImapOperatorOutgoingServerIdDefault;
       
   251         }
       
   252     
       
   253     error = GetIntFromCenRepL( ECRKPopImapOperatorSecurityAuthId, 
       
   254             iOperatorOutSecurityAuth );
       
   255     if ( error != KErrNone )
       
   256         {
       
   257         iOperatorOutSecurityAuth = KCRKPopImapOperatorSecurityAuthIdDefault;
       
   258         }
       
   259     
       
   260     error = GetIntFromCenRepL( ECRKPopImapOperatorSecurityProtocolId, 
       
   261             iOperatorOutSecurityProtocol );
       
   262     if ( error != KErrNone )
       
   263         {
       
   264         iOperatorOutSecurityProtocol = KCRKPopImapOperatorSecurityProtocolIdDefault;
       
   265         }
       
   266     
       
   267     error = GetIntFromCenRepL( ECRKPopImapOperatorPortId,  
       
   268             iOperatorOutgoingPort );
       
   269     if ( error != KErrNone )
       
   270         {
       
   271         iOperatorOutgoingPort = KCRKPopImapOperatorPortIdDefault;
       
   272         }
       
   273     
       
   274     error = GetIntFromCenRepL( ECRKHideUsernameInSettings,  
       
   275             iHiddenData );
       
   276     if ( error != KErrNone )
       
   277         {
       
   278         iHiddenData = KCRKPopImapDataHideDefault;
       
   279         }
       
   280     
       
   281     error = GetTextFromCenRepL( ECRKPopImapAccessPointId, iRecomendedAP );
       
   282     if ( error != KErrNone )
       
   283         {
       
   284         iRecomendedAP = KCRKPopImapAccessPointIdDefault;
       
   285         }
       
   286         
       
   287     tempText.Zero();
       
   288     error = GetTextFromCenRepL( ECRKPopImapMailboxName, tempText );
       
   289     if ( error != KErrNone )
       
   290         {
       
   291         tempText = KCRKPopImapMailboxNameDefault;
       
   292         }
       
   293     ChangeUnicodePrintable( tempText, iMailboxName );
       
   294     
       
   295     EmptyWizardCenRep();
       
   296     //</cmail>
       
   297     
       
   298     } 
       
   299 // ---------------------------------------------------------------------------
       
   300 // ---------------------------------------------------------------------------
       
   301 TInt CIpsSetWizardAdapter::GetIntFromCenRepL( TIpsSetWizardSettings aSetting, 
       
   302                                               TInt& aVariable )
       
   303     {
       
   304     FUNC_LOG;
       
   305 	if ( &iWizardCenRep )
       
   306 		{
       
   307     	return iWizardCenRep.Get( aSetting, aVariable );
       
   308 		}
       
   309 	return KErrNone;
       
   310     }
       
   311         
       
   312         
       
   313 // ---------------------------------------------------------------------------
       
   314 // ---------------------------------------------------------------------------
       
   315 TInt CIpsSetWizardAdapter::GetTextFromCenRepL( TIpsSetWizardSettings aSetting, 
       
   316                                  TIpsSetUtilsTextPlain& aVariable )
       
   317     {
       
   318     FUNC_LOG;
       
   319 	if ( &iWizardCenRep )
       
   320 		{
       
   321     	return iWizardCenRep.Get( aSetting, aVariable );
       
   322 		}
       
   323 	return KErrNone;
       
   324     }
       
   325     
       
   326 // ---------------------------------------------------------------------------
       
   327 // ---------------------------------------------------------------------------
       
   328 void CIpsSetWizardAdapter::EmptyWizardCenRep()
       
   329     {
       
   330     FUNC_LOG;
       
   331     // error is used in debug purposes
       
   332     // <cmail>TInt error = KErrNone; Removed since it is not used.</cmail>
       
   333 	if ( &iWizardCenRep )
       
   334 		{
       
   335 	    iWizardCenRep.Set( ECRKPopImapEmailAddressId, KNullDesC );
       
   336 	    iWizardCenRep.Set( ECRKPopImapUsernameId, KNullDesC );
       
   337 	    iWizardCenRep.Set( ECRKPopImapPasswordId, KNullDesC );
       
   338 	    iWizardCenRep.Set( ECRKPopImapIncomingServerId, KNullDesC );
       
   339 	    iWizardCenRep.Set( 
       
   340 	            ECRKPopImapProtocolIndicatorId, KErrNotFound );
       
   341 	    iWizardCenRep.Set( 
       
   342 	            ECRKPopImapIncomingSecurityAuthId, KErrNotFound );
       
   343 	    iWizardCenRep.Set( 
       
   344 	            ECRKPopImapIncomingSecurityProtocolId, KErrNotFound );
       
   345 	    iWizardCenRep.Set( ECRKPopImapIncomingPortId, KErrNotFound );
       
   346 	    iWizardCenRep.Set( ECRKPopImapOutgoingServerId, KNullDesC );
       
   347 	    iWizardCenRep.Set( 
       
   348 	            ECRKPopImapOutgoingSecurityAuthId, KErrNotFound );
       
   349 	    iWizardCenRep.Set( 
       
   350 	            ECRKPopImapOutgoingSecurityProtocolId, KErrNotFound );
       
   351 	    iWizardCenRep.Set( ECRKPopImapOutgoingPortId, KErrNotFound );
       
   352 	    iWizardCenRep.Set( 
       
   353 	            ECRKPopImapOperatorOutgoingServerId, KNullDesC );
       
   354 	    iWizardCenRep.Set( 
       
   355 	            ECRKPopImapOperatorSecurityAuthId, KErrNotFound );
       
   356 	    iWizardCenRep.Set( 
       
   357 	            ECRKPopImapOperatorSecurityProtocolId, KErrNotFound );
       
   358 	    iWizardCenRep.Set( ECRKPopImapOperatorPortId, KErrNotFound );
       
   359 	    iWizardCenRep.Set( ECRKPopImapAccessPointId, KNullDesC );  
       
   360 	    iWizardCenRep.Set( ECRKPopImapMailboxName, KNullDesC );  
       
   361 		}
       
   362     
       
   363     }
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // ---------------------------------------------------------------------------
       
   367 void CIpsSetWizardAdapter::SetSettingsL( CIpsSetData& aSetData )
       
   368     {
       
   369     FUNC_LOG;
       
   370     TImIAPChoice iap;
       
   371     TPortValue port;
       
   372     TSecurityValue security;
       
   373     
       
   374     aSetData.SetProtocol( 
       
   375         (iProtocol == 0) ? KSenduiMtmPop3Uid : KSenduiMtmImap4Uid );
       
   376         
       
   377   //<cmail>
       
   378     if(iProtocol == 0)// KSenduiMtmPop3Uid - for Pop account- default is Headers Only
       
   379     	{
       
   380         aSetData.SetDownloadSizeL( CIpsSetData::EHeaders,KIpsSetDataHeadersOnly);
       
   381         }
       
   382     else 
       
   383     	{
       
   384     	aSetData.SetDownloadSizeL( CIpsSetData::EHeadersPlus, KIpsSetDataDefaultDownloadSizeKb );
       
   385         }
       
   386     //</cmail>
       
   387     aSetData.SetEmailAddressL( iEmailAddress );
       
   388     aSetData.SetUserNameL( iUsername, iUsername );
       
   389     aSetData.SetUserPwdL( iPassword, iPassword );
       
   390     aSetData.SetMailServerL( iIncomingServer, iProviderOutgoingServer );
       
   391     
       
   392     security = SetSecurityValues( iInSecurityProtocol, iProviderOutSecurityProtocol );
       
   393     aSetData.SetSecurity( security.inSecurity, security.outSecurity );
       
   394 
       
   395     port = CheckPortValues( iProtocol, 
       
   396                             iInIncomingPort, 
       
   397                             iProviderOutgoingPort, 
       
   398                             security );
       
   399     aSetData.SetPort( port.inport, port.outport );                             
       
   400     
       
   401     //<cmail>
       
   402     aSetData.SetDataHide( iHiddenData );
       
   403     //</cmail>
       
   404     aSetData.SetMailboxName( CheckMailboxNamesL( iMailboxName ) );
       
   405     aSetData.SetUserAuthentication( CIpsSetData::EUseIncoming );
       
   406 
       
   407     iap = SetIAPByNameL( iRecomendedAP );
       
   408     aSetData.SetIapL( iap, iap );
       
   409     // EIpsSetDataOutSecurityAuth
       
   410     // EIpsSetDataOutSecurityAuth
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------------------------
       
   414 // ---------------------------------------------------------------------------
       
   415 TSecurityValue CIpsSetWizardAdapter::SetSecurityValues( 
       
   416     const TInt aInSecurity, const TInt aOutSecurity )
       
   417     {
       
   418     FUNC_LOG;
       
   419     TSecurityValue values;
       
   420 
       
   421 
       
   422     switch( aInSecurity )
       
   423         {
       
   424         case KWizardDataSecurityOff:
       
   425             {
       
   426             values.inSecurity = CIpsSetData::ESecurityOff;
       
   427             break;
       
   428             }
       
   429         case KWizardDataSecurityTLS:
       
   430             {
       
   431             values.inSecurity = CIpsSetData::EStartTls;
       
   432             break;
       
   433             }
       
   434         case KWizardDataSecuritySSL:
       
   435             {
       
   436             values.inSecurity = CIpsSetData::ESslTls;
       
   437             break;
       
   438             }
       
   439         default:
       
   440             {
       
   441             values.inSecurity = CIpsSetData::ESecurityOff;
       
   442             break;
       
   443             }
       
   444         }
       
   445         
       
   446     switch( aOutSecurity )
       
   447         {
       
   448         case KWizardDataSecurityOff:
       
   449             {
       
   450             values.outSecurity = CIpsSetData::ESecurityOff;
       
   451             break;
       
   452             }
       
   453         case KWizardDataSecurityTLS:
       
   454             {
       
   455             values.outSecurity = CIpsSetData::EStartTls;
       
   456             break;
       
   457             }
       
   458         case KWizardDataSecuritySSL:
       
   459             {
       
   460             values.outSecurity = CIpsSetData::ESslTls;
       
   461             break;
       
   462             }
       
   463         default:
       
   464             {
       
   465             values.outSecurity = CIpsSetData::ESecurityOff;
       
   466             break;
       
   467             }
       
   468         }
       
   469     return values;
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // ---------------------------------------------------------------------------
       
   474 TPortValue CIpsSetWizardAdapter::CheckPortValues( const TInt aProtocol, 
       
   475     const TInt aInport, const TInt aOutport, const TSecurityValue aSecurity )
       
   476     {
       
   477     FUNC_LOG;
       
   478     TPortValue values;
       
   479         
       
   480     if( aInport <= 0 || aInport > KWizardTCPMaxPort )
       
   481         {
       
   482         values.inport = IpsSetUtils::GetDefaultSecurityPort( 
       
   483             aSecurity.inSecurity, ETrue, aProtocol );
       
   484         }
       
   485     else
       
   486         {
       
   487         values.inport = aInport;
       
   488         }        
       
   489         
       
   490     if( aOutport <= 0 || aOutport > KWizardTCPMaxPort )
       
   491         {
       
   492         values.outport = IpsSetUtils::GetDefaultSecurityPort( 
       
   493             aSecurity.outSecurity, EFalse, aProtocol );
       
   494         }
       
   495     else
       
   496         {
       
   497         values.outport = aOutport;
       
   498         }
       
   499     return values;
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // ---------------------------------------------------------------------------
       
   504 TImIAPChoice CIpsSetWizardAdapter::SetIAPByNameL( TDes& aIAPName )
       
   505     {
       
   506     FUNC_LOG;
       
   507     TInt iapcount;
       
   508     TImIAPChoice iap;
       
   509     TBuf<KWizardMaxUidValue> buf;
       
   510     CIpsSetUiItemAccessPoint* ipsSetAP = CIpsSetUiItemAccessPoint::NewLC();
       
   511     
       
   512     //<cmail>
       
   513     iapcount = ipsSetAP->iIapList.Count();
       
   514     //</cmail>
       
   515 
       
   516     //Set default AP to always ask
       
   517     iap.iDialogPref = ECommDbDialogPrefPrompt;
       
   518     iap.iIAP = 0;   
       
   519 
       
   520     //run through all found access points
       
   521 	//<cmail>
       
   522     TBool found( EFalse );
       
   523     for( TInt i = 0;!found &&  i < iapcount; i++ )
       
   524         {
       
   525         HBufC* name( ipsSetAP->AccessPointNameLC( i ) );
       
   526         // If AP stored in cenrep key as UID value, we need to do
       
   527         // comparison by UID also -> Used in TP wizard
       
   528         buf.Zero();
       
   529         buf.Num( ipsSetAP->iIapList[i] );
       
   530         if( ( name && aIAPName.Compare( name->Des() ) == 0 ) ||
       
   531                 aIAPName.Compare( buf ) == 0 )
       
   532             {
       
   533             //AP found!
       
   534             found = ETrue;
       
   535             iap.iDialogPref = ECommDbDialogPrefDoNotPrompt;
       
   536             iap.iIAP = ipsSetAP->iIapList[i];
       
   537             }
       
   538         CleanupStack::PopAndDestroy( name );
       
   539         }
       
   540 	//</cmail>
       
   541     CleanupStack::PopAndDestroy( ipsSetAP );
       
   542     return iap;
       
   543     }
       
   544     
       
   545 // ---------------------------------------------------------------------------
       
   546 // ---------------------------------------------------------------------------
       
   547 void CIpsSetWizardAdapter::CreateEmailAccountL( CIpsSetData& aSetData )
       
   548     {
       
   549     FUNC_LOG;
       
   550     TInt accountcount;
       
   551     
       
   552     CIpsSetDataManager* setManager = CIpsSetDataManager::NewLC( iSession );
       
   553     
       
   554     //create mailbox
       
   555     User::LeaveIfError( setManager->CreateEmailAccount( aSetData, EFalse ) );
       
   556     
       
   557     CEmailAccounts* accounts = CEmailAccounts::NewLC();    
       
   558     RArray<TSmtpAccount> RIpsSmtpArray;        
       
   559     accounts->GetSmtpAccountsL( RIpsSmtpArray );
       
   560     accountcount = RIpsSmtpArray.Count();
       
   561 
       
   562     //increase mailbox count
       
   563 	if ( &iWizardCenRep )
       
   564 		{ 
       
   565     	iWizardCenRep.Set( ECRKAccountsConfigured, accountcount );
       
   566 		}
       
   567     
       
   568     if( accountcount >= KMaxMailboxes && &iWizardCenRep )
       
   569         {
       
   570         iWizardCenRep.Set( ECRKMaxAccountsReached, ETrue );
       
   571         }
       
   572    
       
   573     RIpsSmtpArray.Close();
       
   574     CleanupStack::PopAndDestroy( accounts );
       
   575     CleanupStack::PopAndDestroy( setManager );
       
   576     
       
   577     // notify ao about new mailbox
       
   578 // <cmail> RD_IPS_AO_PLUGIN flag removed
       
   579     TInt mailboxId = KErrNotFound;
       
   580     if ( aSetData.ExtendedSettings() )
       
   581         {
       
   582         mailboxId = aSetData.ExtendedSettings()->MailboxId();
       
   583         }
       
   584     
       
   585     RAlwaysOnlineClientSession aosession; 
       
   586     TInt err = aosession.Connect();
       
   587     if ( mailboxId != KErrNotFound && err == KErrNone )
       
   588         {
       
   589         TPckgBuf<TMsvId> mboxBuf( mailboxId );
       
   590         TRAP( err, aosession.RelayCommandL( 
       
   591                 EServerAPIEmailTurnOn, 
       
   592                mboxBuf ) );
       
   593         }
       
   594     aosession.Close();
       
   595 //#endif <cmail>
       
   596     }
       
   597 
       
   598 // ---------------------------------------------------------------------------
       
   599 // ---------------------------------------------------------------------------
       
   600 TDes& CIpsSetWizardAdapter::CheckMailboxNamesL( TDes& aName )
       
   601     {
       
   602     FUNC_LOG;
       
   603     RArray<TSmtpAccount> RIpsSmtpArray;
       
   604     CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   605     TInt endNumber = 0; 
       
   606     
       
   607     accounts->GetSmtpAccountsL( RIpsSmtpArray );
       
   608     
       
   609     TIpsSetUtilsTextPlain tempName = aName;
       
   610     
       
   611     //Run through all mailboxes
       
   612     for ( TInt mailboxCount = RIpsSmtpArray.Count()-1; mailboxCount >= 0; mailboxCount-- )
       
   613         {
       
   614         TIpsSetUtilsTextPlain mailbox = 
       
   615             RIpsSmtpArray[mailboxCount].iSmtpAccountName;    
       
   616         
       
   617         if( !tempName.Compare( mailbox ) )
       
   618             {
       
   619             //if mailboxname already exists increase value after name
       
   620             tempName = aName;
       
   621             endNumber++;
       
   622             tempName.AppendNum( endNumber );
       
   623             //reset mailbox counter
       
   624             mailboxCount = RIpsSmtpArray.Count();
       
   625             }
       
   626         }
       
   627     aName = tempName;
       
   628     RIpsSmtpArray.Reset();
       
   629     CleanupStack::PopAndDestroy( accounts );
       
   630     return aName;
       
   631     }
       
   632  
       
   633 // ---------------------------------------------------------------------------
       
   634 // ---------------------------------------------------------------------------
       
   635 void CIpsSetWizardAdapter::HandleWizardDataL()
       
   636     {
       
   637     FUNC_LOG;
       
   638     // This leaves if reading is not successfull
       
   639     ReadWizardSettignsL();
       
   640     
       
   641     if( iMaxAccounts == EFalse )
       
   642         {
       
   643         //create settings
       
   644         CIpsSetData *setData = CIpsSetData::NewLC();
       
   645         SetSettingsL( *setData );
       
   646 
       
   647         //create mailbox
       
   648         CreateEmailAccountL( *setData ); 
       
   649 
       
   650         CleanupStack::PopAndDestroy( setData );
       
   651         }
       
   652     }
       
   653 
       
   654 // ---------------------------------------------------------------------------
       
   655 // ---------------------------------------------------------------------------
       
   656 void CIpsSetWizardAdapter::ChangeAsciiPrintable(
       
   657         const TDesC16& aOrgText, TDes& aValText )
       
   658      {
       
   659     FUNC_LOG;
       
   660      aValText.Zero();
       
   661      const TInt KMax7BitValue = 126;
       
   662      const TInt KMin7BitValue = 32;
       
   663 
       
   664      const TInt length = aOrgText.Length();
       
   665      const TText16* pText = aOrgText.Ptr();
       
   666 
       
   667      const TInt valMax = aValText.MaxLength();
       
   668      TInt valIndex = 0;
       
   669      for(TInt i=0; i<length; i++)
       
   670         {
       
   671         if ( valIndex >= valMax )
       
   672             {
       
   673             break;
       
   674             }
       
   675         if  (!((pText[i] > KMax7BitValue) || (pText[i] < KMin7BitValue)) )
       
   676             {
       
   677             aValText.Append( pText[i] );
       
   678             ++valIndex;
       
   679             }
       
   680         }
       
   681     }
       
   682 
       
   683 // ---------------------------------------------------------------------------
       
   684 // ---------------------------------------------------------------------------
       
   685 void CIpsSetWizardAdapter::ChangeUnicodePrintable(
       
   686         const TDesC16& aOrgText, TDes& aValText )
       
   687     {
       
   688     FUNC_LOG;
       
   689     aValText.Zero();
       
   690     const TText16* pText = aOrgText.Ptr();
       
   691     const TInt orgLength = aOrgText.Length();
       
   692     
       
   693     const TInt valMax = aValText.MaxLength();
       
   694     TInt valIndex = 0;
       
   695     
       
   696     for(TInt i =0; i < orgLength ; ++i) 
       
   697       {
       
   698       if ( valIndex >= valMax )
       
   699           {
       
   700           break;
       
   701           }
       
   702       
       
   703       TChar aChar = pText[i]; 
       
   704       if ( aChar.IsPrint() ) 
       
   705          { 
       
   706          aValText.Append( aChar );
       
   707          } 
       
   708       } 
       
   709     } 
       
   710 
       
   711