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