|         |      1 /* | 
|         |      2 * Copyright (c) 2006 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:  | 
|         |     15 *       Static functions for validating account settings prior to connection | 
|         |     16 * | 
|         |     17 */ | 
|         |     18  | 
|         |     19  | 
|         |     20 #include <eikenv.h> | 
|         |     21 #include <eikbtgpc.h> | 
|         |     22 #include <eikseced.h> | 
|         |     23 #include <iapprefs.h> | 
|         |     24 #include <smtpset.h> | 
|         |     25 #include <pop3set.h> | 
|         |     26 #include <imapset.h> | 
|         |     27 #include <MsvPrgReporter.h> | 
|         |     28 #include <imum.rsg>                 // R_MBXS_SETTINGS_MAIL_SAVE_PSWRD_QRY | 
|         |     29 #include <AknQueryDialog.h> | 
|         |     30 #include <SenduiMtmUids.h> | 
|         |     31 #include <ImumInternalApi.h>        // CImumInternalApi | 
|         |     32 #include "ImumPanic.h" | 
|         |     33 #include "EmailUtils.H" | 
|         |     34 #include "ComDbUtl.h" | 
|         |     35 #include "MsvConnectionValidation.h" | 
|         |     36 #include "ImumUsernameAndPasswordDialog.h" | 
|         |     37 #include "ImumMtmLogging.h" | 
|         |     38 #include "IMSSettingsNoteUi.h" | 
|         |     39 #include "ImumMboxSettingsUtils.h" | 
|         |     40 #include <ImumInMailboxServices.h> | 
|         |     41 #include <ImumInMailboxUtilities.h> | 
|         |     42 #include <ImumInSettingsKeys.h> | 
|         |     43 #include "EmailFeatureUtils.h" | 
|         |     44 #include "ImumDaErrorCodes.h" | 
|         |     45  | 
|         |     46 // CONSTANTS | 
|         |     47 const TInt KImumSettingsIapPreferenceNumber     = 0; | 
|         |     48  | 
|         |     49 // ---------------------------------------------------------------------------- | 
|         |     50 // MsvConnectionValidation::RunAndHandleLoginDialogL() | 
|         |     51 // ---------------------------------------------------------------------------- | 
|         |     52 // | 
|         |     53 TIMASPasswordSave MsvConnectionValidation::RunAndHandleLoginDialogL( | 
|         |     54     TDes8& aUserName, | 
|         |     55     TDes8& aPassword, | 
|         |     56     TBool& aPasswordTemporary ) | 
|         |     57     { | 
|         |     58     IMUM_STATIC_CONTEXT( MsvConnectionValidation::RunAndHandleLoginDialogL, 0, mtm, KImumMtmLog ); | 
|         |     59     IMUM_IN(); | 
|         |     60              | 
|         |     61     TIMASPasswordSave ret = EIMASPasswordNoSave; | 
|         |     62     // Store the username and password temporarily to prevent losing them | 
|         |     63     TMuiuPasswordText tempUsername; | 
|         |     64     TMuiuPasswordText tempPassword; | 
|         |     65     tempUsername.Copy( aUserName ); | 
|         |     66     tempPassword.Copy( aPassword ); | 
|         |     67  | 
|         |     68     // New values are accepted, but the user's permission is required to store | 
|         |     69     // the password to the settings | 
|         |     70     if ( RunUsernameAndPasswordDialogL( tempUsername, tempPassword ) ) | 
|         |     71         { | 
|         |     72          // Store settings. | 
|         |     73         aUserName.Copy( tempUsername ); | 
|         |     74         aPassword.Copy( tempPassword ); | 
|         |     75  | 
|         |     76         // If the user answers no, set the password temporary | 
|         |     77         if ( !CIMSSettingsNoteUi::ShowQueryL( | 
|         |     78             R_MBXS_SETTINGS_MAIL_SAVE_PSWRD_QRY, R_EMAIL_CONFIRMATION_QUERY ) ) | 
|         |     79             { | 
|         |     80             aPasswordTemporary = ETrue; | 
|         |     81             ret = EIMASPasswordTempSave; | 
|         |     82             } | 
|         |     83         else | 
|         |     84             { | 
|         |     85             aPasswordTemporary = EFalse; | 
|         |     86             ret = EIMASPasswordPermanentSave; | 
|         |     87             } | 
|         |     88         } | 
|         |     89     else | 
|         |     90         { | 
|         |     91         // Leave everything untouched | 
|         |     92         ret = EIMASPasswordCancelSave; | 
|         |     93         } | 
|         |     94     IMUM_OUT(); | 
|         |     95  | 
|         |     96     return ret; | 
|         |     97     } | 
|         |     98  | 
|         |     99 // ---------------------------------------------------------------------------- | 
|         |    100 // MsvConnectionValidation::CheckAndPromptForPasswordL | 
|         |    101 // Check that there is a password specified, if not, prompt user to enter one | 
|         |    102 // and store it in the settings. | 
|         |    103 // ---------------------------------------------------------------------------- | 
|         |    104 TBool MsvConnectionValidation::CheckAndPromptForPasswordL( | 
|         |    105     CImumInternalApi& aMailboxApi, | 
|         |    106     TMsvId aServiceId, | 
|         |    107     TMsvLoginData aLoginData, | 
|         |    108     TInt& aLoginRetryCounter ) | 
|         |    109     { | 
|         |    110     IMUM_STATIC_CONTEXT( MsvConnectionValidation::CheckAndPromptForPasswordL, 0, mtm, KImumMtmLog ); | 
|         |    111     IMUM_IN(); | 
|         |    112      | 
|         |    113     TBool ret = EFalse; | 
|         |    114  | 
|         |    115     // Temporary information is not accepted as valid data | 
|         |    116     if ( aLoginData.iIsPasswordTemporary ) | 
|         |    117         { | 
|         |    118         // Don't initialize temp password into a username/password query dialog | 
|         |    119         aLoginData.iPassword.Zero(); | 
|         |    120         } | 
|         |    121  | 
|         |    122     if ( aLoginData.iUsername.Length() && aLoginData.iPassword.Length() ) | 
|         |    123         { | 
|         |    124         // Have a valid password. | 
|         |    125         ret = ETrue; | 
|         |    126         } | 
|         |    127     else | 
|         |    128         { | 
|         |    129         aLoginRetryCounter++; | 
|         |    130  | 
|         |    131         // Run dialog | 
|         |    132         TIMASPasswordSave save = EIMASPasswordCancelSave; | 
|         |    133  | 
|         |    134         if( aMailboxApi.IsEmailFeatureSupportedL(  | 
|         |    135             CImumInternalApi::EMailLockedSettings ) ) | 
|         |    136             { | 
|         |    137             CIMSSettingsNoteUi::ShowNoteL(  | 
|         |    138                 R_IMUM_ERROR_LOCKED_SETTIGNS,  | 
|         |    139                 EIMSErrorNote );   | 
|         |    140             } | 
|         |    141         else | 
|         |    142             { | 
|         |    143             save = RunAndHandleLoginDialogL( | 
|         |    144                 aLoginData.iUsername, | 
|         |    145                 aLoginData.iPassword, | 
|         |    146                 aLoginData.iIsPasswordTemporary ); | 
|         |    147             } | 
|         |    148  | 
|         |    149         switch ( save ) | 
|         |    150             { | 
|         |    151             case EIMASPasswordTempSave: | 
|         |    152             case EIMASPasswordPermanentSave: | 
|         |    153                 // Save settings (login info) into data base. | 
|         |    154                 ImumMboxSettingsUtils::SetLoginInformationL( aMailboxApi, | 
|         |    155                     aLoginData.iUsername, aLoginData.iPassword, | 
|         |    156                     aLoginData.iIsPasswordTemporary, aServiceId ); | 
|         |    157                 ret = ETrue; | 
|         |    158                 break; | 
|         |    159             case EIMASPasswordCancelSave: | 
|         |    160             case EIMASPasswordNoSave: | 
|         |    161             default: | 
|         |    162                 ret = EFalse; | 
|         |    163             } | 
|         |    164         } | 
|         |    165     IMUM_OUT(); | 
|         |    166     return ret; | 
|         |    167     } | 
|         |    168  | 
|         |    169 // ---------------------------------------------------------------------------- | 
|         |    170 // MsvConnectionValidation::ShowLoginDetailsRejectionDlgL | 
|         |    171 // | 
|         |    172 // Prompt the user to check the login details for aRcvServiceId, allowing them to change the | 
|         |    173 // details. Returns EFalse if user cancels. | 
|         |    174 // | 
|         |    175 // ---------------------------------------------------------------------------- | 
|         |    176 TBool MsvConnectionValidation::ShowLoginDetailsRejectionDlgL( | 
|         |    177     CImumInternalApi& aMailboxApi, | 
|         |    178     TMsvId aServiceId ) | 
|         |    179     { | 
|         |    180     IMUM_STATIC_CONTEXT( MsvConnectionValidation::ShowLoginDetailsRejectionDlgL, 0, mtm, KImumMtmLog ); | 
|         |    181     IMUM_IN(); | 
|         |    182  | 
|         |    183     // Get settings. | 
|         |    184     TBuf8<KImasLoginLength> username8; | 
|         |    185     TBuf8<KImasPasswordLength> password8; | 
|         |    186     TBool isPasswordTemporary = EFalse; | 
|         |    187  | 
|         |    188     // Load login information | 
|         |    189     ImumMboxSettingsUtils::GetLoginInformationL( | 
|         |    190         aMailboxApi,  | 
|         |    191         username8,  | 
|         |    192         password8,  | 
|         |    193         isPasswordTemporary, | 
|         |    194         aServiceId ); | 
|         |    195  | 
|         |    196     TInt ret = EIMASPasswordCancelSave; | 
|         |    197  | 
|         |    198     // Run dialog if email settings lock is not active. | 
|         |    199     if( aMailboxApi.IsEmailFeatureSupportedL(  | 
|         |    200         CImumInternalApi::EMailLockedSettings ) ) | 
|         |    201         { | 
|         |    202         CIMSSettingsNoteUi::ShowNoteL(  | 
|         |    203             R_IMUM_ERROR_LOCKED_SETTIGNS,  | 
|         |    204             EIMSErrorNote );       | 
|         |    205         } | 
|         |    206     else | 
|         |    207         { | 
|         |    208         ret = RunAndHandleLoginDialogL( | 
|         |    209             username8,  | 
|         |    210             password8,  | 
|         |    211             isPasswordTemporary );     | 
|         |    212         }   | 
|         |    213     | 
|         |    214     // Save login information | 
|         |    215     ImumMboxSettingsUtils::SetLoginInformationL( | 
|         |    216         aMailboxApi,  | 
|         |    217         username8,  | 
|         |    218         password8,  | 
|         |    219         isPasswordTemporary,         | 
|         |    220         aServiceId ); | 
|         |    221     IMUM_OUT(); | 
|         |    222  | 
|         |    223     return ( ret == EIMASPasswordCancelSave ? EFalse : ETrue ); | 
|         |    224     } | 
|         |    225  | 
|         |    226 // ---------------------------------------------------------------------------- | 
|         |    227 // MsvConnectionValidation::IsAlwaysAskSet() | 
|         |    228 // ---------------------------------------------------------------------------- | 
|         |    229 // | 
|         |    230 TBool MsvConnectionValidation::IsAlwaysAskSet( | 
|         |    231     const CImIAPPreferences& iapPref ) | 
|         |    232     { | 
|         |    233     IMUM_STATIC_CONTEXT( MsvConnectionValidation::IsAlwaysAskSet, 0, mtm, KImumMtmLog ); | 
|         |    234     IMUM_IN(); | 
|         |    235      | 
|         |    236     TImIAPChoice iapChoice = | 
|         |    237         iapPref.IAPPreference( KImumSettingsIapPreferenceNumber ); | 
|         |    238  | 
|         |    239     // Always ask is set, when prompting is set and iap is set to 0 | 
|         |    240     if ( iapChoice.iDialogPref == ECommDbDialogPrefPrompt && | 
|         |    241          iapChoice.iIAP == 0 ) | 
|         |    242         { | 
|         |    243         IMUM_OUT(); | 
|         |    244         return ETrue; | 
|         |    245         } | 
|         |    246     IMUM_OUT(); | 
|         |    247  | 
|         |    248     return EFalse; | 
|         |    249     } | 
|         |    250  | 
|         |    251 // ---------------------------------------------------------------------------- | 
|         |    252 // MsvConnectionValidation::InstantiateSettingsObjectLC | 
|         |    253 // | 
|         |    254 // Create the appropriate type of settings object for aEntry. | 
|         |    255 // | 
|         |    256 // ---------------------------------------------------------------------------- | 
|         |    257 CImBaseEmailSettings* MsvConnectionValidation::InstantiateSettingsObjectLC( | 
|         |    258     const TMsvEntry& aEntry, | 
|         |    259     TUid& aMtmType) | 
|         |    260     { | 
|         |    261     IMUM_STATIC_CONTEXT( MsvConnectionValidation::InstantiateSettingsObjectLC, 0, mtm, KImumMtmLog ); | 
|         |    262     IMUM_IN(); | 
|         |    263      | 
|         |    264     CImBaseEmailSettings* ret = NULL; | 
|         |    265     aMtmType = aEntry.iMtm; | 
|         |    266     switch(aMtmType.iUid) | 
|         |    267         { | 
|         |    268         case KSenduiMtmSmtpUidValue: | 
|         |    269             ret = new(ELeave) CImSmtpSettings; | 
|         |    270             break; | 
|         |    271         case KSenduiMtmPop3UidValue: | 
|         |    272             ret = new(ELeave) CImPop3Settings; | 
|         |    273             break; | 
|         |    274         case KSenduiMtmImap4UidValue: | 
|         |    275             ret = new(ELeave) CImImap4Settings; | 
|         |    276             break; | 
|         |    277         default: | 
|         |    278             User::Panic(KImumMtmUiPanic,EPanicUnknownMtmType); | 
|         |    279             break; | 
|         |    280         } | 
|         |    281     CleanupStack::PushL(ret); | 
|         |    282     IMUM_OUT(); | 
|         |    283     return ret; | 
|         |    284     } | 
|         |    285  | 
|         |    286 // ---------------------------------------------------------------------------- | 
|         |    287 // MsvConnectionValidation::RunUsernameAndPasswordDialogL | 
|         |    288 // | 
|         |    289 // ---------------------------------------------------------------------------- | 
|         |    290 TInt MsvConnectionValidation::RunUsernameAndPasswordDialogL( | 
|         |    291     TDes& aUserName, | 
|         |    292     TDes& aPassword ) | 
|         |    293     { | 
|         |    294     IMUM_STATIC_CONTEXT( MsvConnectionValidation::RunUsernameAndPasswordDialogL, 0, mtm, KImumMtmLog ); | 
|         |    295     IMUM_IN(); | 
|         |    296      | 
|         |    297     CImumUsernameAndPasswordDialog* dlg = | 
|         |    298         CImumUsernameAndPasswordDialog::NewL( aUserName, aPassword ); | 
|         |    299     IMUM_OUT(); | 
|         |    300     return dlg->ExecuteLD(R_CONUTL_LOGINDETAILS_DLG); | 
|         |    301     } | 
|         |    302  | 
|         |    303  | 
|         |    304 // ---------------------------------------------------------------------------- | 
|         |    305 // MsvConnectionValidation::GetServiceNameL | 
|         |    306 // | 
|         |    307 // ---------------------------------------------------------------------------- | 
|         |    308 void MsvConnectionValidation::GetServiceNameL( | 
|         |    309     CMsvSession& aSession, | 
|         |    310     TMsvId aServiceId, | 
|         |    311     TDes& aServiceName ) | 
|         |    312     { | 
|         |    313     IMUM_STATIC_CONTEXT( MsvConnectionValidation::GetServiceNameL, 0, mtm, KImumMtmLog ); | 
|         |    314     IMUM_IN(); | 
|         |    315      | 
|         |    316     CMsvEntry* centry = aSession.GetEntryL(aServiceId); | 
|         |    317     aServiceName = centry->Entry().iDetails; | 
|         |    318     delete centry; | 
|         |    319     IMUM_OUT(); | 
|         |    320     } | 
|         |    321  | 
|         |    322 // ---------------------------------------------------------------------------- | 
|         |    323 // MsvConnectionValidation::GetServiceIapNameL | 
|         |    324 // | 
|         |    325 // ---------------------------------------------------------------------------- | 
|         |    326 void MsvConnectionValidation::GetServiceIapNameL( | 
|         |    327     CImumInSettingsData& aAccountSettings, TUid aMtmUid, TDes& aIapName) | 
|         |    328     { | 
|         |    329     IMUM_STATIC_CONTEXT( MsvConnectionValidation::GetServiceIapNameL, 0, mtm, KImumMtmLog ); | 
|         |    330     IMUM_IN(); | 
|         |    331      | 
|         |    332     TInt error = aAccountSettings.Validate(); | 
|         |    333        | 
|         |    334     if ( !error ) | 
|         |    335         {                     | 
|         |    336         TInt connection = ( aMtmUid == KSenduiMtmSmtpUid ) ? 1 : 0; | 
|         |    337          | 
|         |    338         aAccountSettings[connection].GetAttr(  | 
|         |    339             TImumInSettings::EKeyAccessPointName,  | 
|         |    340             aIapName ); | 
|         |    341         } | 
|         |    342     // handle the error caused by invalid email address | 
|         |    343     else if (( error == TImumDaErrorCode::EEmailAddressNotSet ) ||  | 
|         |    344              ( error == TImumDaErrorCode::EEmailAddressEmpty ) || | 
|         |    345              ( error == TImumDaErrorCode::EEmailAddressInvalid )) | 
|         |    346         { | 
|         |    347         CIMSSettingsNoteUi::ShowNoteL( R_IMUM_EDIT_OWN_EMAIL_ADDRESS_ERROR_TEXT, | 
|         |    348             EIMSInformationNote, ETrue ); | 
|         |    349         User::Leave( KErrNotReady ); | 
|         |    350         }     | 
|         |    351     else | 
|         |    352         { | 
|         |    353         User::Leave( KErrNotReady ); | 
|         |    354         } | 
|         |    355     IMUM_OUT(); | 
|         |    356     } | 
|         |    357  | 
|         |    358  | 
|         |    359 // End of File |