emailservices/emailserver/cmailhandlerplugin/src/fsmailauthenticationhandler.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class to handle mail led turning on.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //<cmail>
       
    20 #include "emailtrace.h"
       
    21 #include "CFSMailClient.h"
       
    22 //</cmail>
       
    23 
       
    24 #include "fsmailauthenticationhandler.h"
       
    25 
       
    26 
       
    27 
       
    28 CFSMailAuthenticationHandler* CFSMailAuthenticationHandler::NewL(
       
    29     MFSNotificationHandlerMgr& aOwner )
       
    30     {
       
    31     FUNC_LOG;
       
    32     CFSMailAuthenticationHandler* self =
       
    33         new (ELeave) CFSMailAuthenticationHandler( aOwner );
       
    34     CleanupStack::PushL( self );
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop( self );
       
    37     return self;
       
    38     }
       
    39 
       
    40 CFSMailAuthenticationHandler::CFSMailAuthenticationHandler(
       
    41     MFSNotificationHandlerMgr& aOwner ) :
       
    42     CFSNotificationHandlerBase( aOwner )
       
    43     {
       
    44     FUNC_LOG;
       
    45     }
       
    46 
       
    47 void CFSMailAuthenticationHandler::ConstructL()
       
    48     {
       
    49     FUNC_LOG;
       
    50     CFSNotificationHandlerBase::ConstructL();
       
    51 
       
    52     // We are now ready to observe mail events
       
    53     SetObserving( ETrue );
       
    54     }
       
    55 
       
    56 CFSMailAuthenticationHandler::~CFSMailAuthenticationHandler()
       
    57     {
       
    58     FUNC_LOG;
       
    59     iNotifierInitiators.ResetAndDestroy();
       
    60     }
       
    61 
       
    62 void CFSMailAuthenticationHandler::NotifierInitiatorDoneL(
       
    63     CFSNotificationHandlerNotifierInitiator* aInitiator )
       
    64     {
       
    65     FUNC_LOG;
       
    66     
       
    67     TInt initiatorIndexer( FindInitiator( aInitiator ) );
       
    68    
       
    69     if ( initiatorIndexer == KErrNotFound )
       
    70         {
       
    71         User::Leave( KErrNotFound );
       
    72         }
       
    73         
       
    74     iNotifierInitiators.Remove( initiatorIndexer );
       
    75     CleanupStack::PushL( aInitiator );
       
    76     
       
    77     // User has just given new authentication values. Pass them to
       
    78     // framework.
       
    79     
       
    80     CFSMailBox* mailBox(
       
    81         MailClient().GetMailBoxByUidL( aInitiator->MailBoxId() ) );
       
    82     User::LeaveIfNull( mailBox );
       
    83     CleanupStack::PushL( mailBox );
       
    84     
       
    85     TBuf<KFsEmailNotifierPasswordMaxLength> newPassword;
       
    86     aInitiator->GetLastAuthenticationOutput( newPassword );
       
    87     
       
    88     mailBox->SetCredentialsL( KNullDesC, newPassword );
       
    89     
       
    90     CleanupStack::PopAndDestroy( mailBox );
       
    91     CleanupStack::PopAndDestroy( aInitiator );
       
    92     }
       
    93 
       
    94 TBool CFSMailAuthenticationHandler::CapabilitiesToContinueL(
       
    95     TFSMailEvent /*aEvent*/,
       
    96     TFSMailMsgId /*aMailbox*/,
       
    97     TAny* /*aParam1*/,
       
    98     TAny* /*aParam2*/,
       
    99     TAny* /*aParam3*/ ) const
       
   100     {
       
   101     FUNC_LOG;
       
   102     // Authentication query is always shown by instance of this class
       
   103     // if necessary.
       
   104     return ETrue;
       
   105     }
       
   106 
       
   107 void CFSMailAuthenticationHandler::HandleEventL(
       
   108     TFSMailEvent aEvent,
       
   109     TFSMailMsgId aMailbox,
       
   110     TAny* aParam1,
       
   111     TAny* /*aParam2*/,
       
   112     TAny* /*aParam3*/ )
       
   113     {
       
   114     FUNC_LOG;
       
   115     switch ( aEvent )
       
   116         {
       
   117         case TFSEventMailboxSyncStateChanged:
       
   118             {
       
   119             TSSMailSyncState& state = *static_cast<TSSMailSyncState*>( aParam1 );
       
   120             
       
   121             
       
   122             if ( state == PasswordExpiredError ||
       
   123                  state == PasswordNotVerified )
       
   124                 {
       
   125                 ShowAuthenticationQueryL( aMailbox );
       
   126                 }
       
   127                 
       
   128             break;
       
   129             }
       
   130             /*
       
   131         case TFSEventMailboxOffline:
       
   132             {
       
   133             // ONLY FOR TESTING
       
   134             
       
   135             ShowAuthenticationQueryL( aMailbox );
       
   136                 
       
   137             break;
       
   138             }
       
   139             */
       
   140         default:
       
   141             {
       
   142             break;
       
   143             }
       
   144         }
       
   145     }
       
   146 
       
   147 
       
   148 void CFSMailAuthenticationHandler::ShowAuthenticationQueryL(
       
   149     TFSMailMsgId aMailbox )
       
   150     {
       
   151     FUNC_LOG;
       
   152     
       
   153     TInt index( FindInitiator( aMailbox ) );
       
   154     
       
   155     // Only one authentication query is permitted for one mailbox
       
   156     if ( index == KErrNotFound )
       
   157         {
       
   158 
       
   159         CFSMailBox* mailBox(
       
   160             MailClient().GetMailBoxByUidL( aMailbox ) );
       
   161         User::LeaveIfNull( mailBox );
       
   162         CleanupStack::PushL( mailBox );
       
   163         TDesC& mailboxName( mailBox->GetName() );
       
   164         
       
   165         CFSNotificationHandlerNotifierInitiator* newNotifierInitiator =
       
   166             CFSNotificationHandlerNotifierInitiator::NewL( *this, iOwner );
       
   167         CleanupStack::PushL( newNotifierInitiator );
       
   168             
       
   169         newNotifierInitiator->SetMailBoxId( aMailbox );
       
   170         newNotifierInitiator->RequestAuthenticationL(
       
   171             mailboxName );
       
   172         
       
   173         iNotifierInitiators.AppendL( newNotifierInitiator );
       
   174         CleanupStack::Pop( newNotifierInitiator );
       
   175         CleanupStack::PopAndDestroy( mailBox );
       
   176         }
       
   177     else
       
   178         {
       
   179         // notifierInitiator exists so we are already showing
       
   180         // an authentication query for the mailbox. Let's not
       
   181         // show/queue a new one.      
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 TInt CFSMailAuthenticationHandler::FindInitiator(
       
   187     CFSNotificationHandlerNotifierInitiator* aInitiator ) const
       
   188     {
       
   189     FUNC_LOG;
       
   190     return iNotifierInitiators.Find( aInitiator );
       
   191     }
       
   192 
       
   193 TInt CFSMailAuthenticationHandler::FindInitiator(
       
   194     TFSMailMsgId aMailBoxId ) const
       
   195     {
       
   196     FUNC_LOG;
       
   197     TInt initiatorCount( iNotifierInitiators.Count() );
       
   198     TInt initiatorIndexer( 0 );
       
   199     
       
   200     while ( initiatorIndexer < initiatorCount )
       
   201         {
       
   202         if( iNotifierInitiators[initiatorIndexer]->MailBoxId()
       
   203                 == aMailBoxId )
       
   204             {
       
   205             return initiatorIndexer;
       
   206             }
       
   207         
       
   208         ++initiatorIndexer;
       
   209         }
       
   210     
       
   211     return KErrNotFound;
       
   212     }
       
   213 
       
   214 
       
   215 void CFSMailAuthenticationHandler::TurnNotificationOn()
       
   216     {
       
   217     FUNC_LOG;
       
   218     }
       
   219 
       
   220 void CFSMailAuthenticationHandler::TurnNotificationOff()
       
   221     {
       
   222     FUNC_LOG;
       
   223     }
       
   224