ipsservices/ipssosplugin/src/ipsplgsmtpoperation.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 4 e7aa27f58ae1
child 24 d189ee25cf9d
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include "emailtrace.h"
    19 #include "emailtrace.h"
    20 #include "ipsplgheaders.h"
    20 #include "ipsplgheaders.h"
       
    21 #include "miut_err.h" // SMTP error codes
    21 
    22 
    22 
    23 
    23 const TInt KIpsSmtpOperationCharLessThan = '<';
    24 const TInt KIpsSmtpOperationCharLessThan = '<';
    24 const TInt KIpsSmtpOperationCharMoreThan = '>';
    25 const TInt KIpsSmtpOperationCharMoreThan = '>';
    25 
    26 
    65     TRequestStatus& aObserverRequestStatus ) :
    66     TRequestStatus& aObserverRequestStatus ) :
    66     CMsvOperation( aMsvSession, aPriority, aObserverRequestStatus ),
    67     CMsvOperation( aMsvSession, aPriority, aObserverRequestStatus ),
    67     iSmtpMtm( NULL ),
    68     iSmtpMtm( NULL ),
    68     iOperation( NULL ),
    69     iOperation( NULL ),
    69     iSelection( NULL ),  
    70     iSelection( NULL ),  
    70     iMtmRegistry( NULL )
    71     iMtmRegistry( NULL ),
       
    72     iState( EIdle ),
       
    73     iEventHandler( NULL )
    71     {
    74     {
    72     FUNC_LOG;
    75     FUNC_LOG;
    73     }
    76     }
    74   
    77   
    75 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    81     Cancel();
    84     Cancel();
    82     delete iSmtpMtm;
    85     delete iSmtpMtm;
    83     delete iMtmRegistry;
    86     delete iMtmRegistry;
    84     delete iSelection;
    87     delete iSelection;
    85     delete iOperation;
    88     delete iOperation;
       
    89     iOperation = NULL;
       
    90     iEventHandler = NULL;
       
    91     iState = EIdle;
    86     } 
    92     } 
    87 
    93 
    88 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
    95 // ---------------------------------------------------------------------------
    90 //
    96 //
   124 // ---------------------------------------------------------------------------
   130 // ---------------------------------------------------------------------------
   125 //
   131 //
   126 void CIpsPlgSmtpOperation::RunL()
   132 void CIpsPlgSmtpOperation::RunL()
   127     {
   133     {
   128     FUNC_LOG;
   134     FUNC_LOG;
   129     
   135 
   130     
   136     switch ( iState )
   131     if ( iState == EMovingOutbox )
   137         {
   132         {
   138         case EMovingOutbox:
   133         delete iOperation;
   139             {
   134         iOperation = NULL;
   140             delete iOperation;
   135         iSelection->InsertL(0, iSmtpService );
   141             iOperation = NULL;
   136         CallSendL( );
   142             iSelection->InsertL( 0, iSmtpService );
   137         }
   143             CallSendL();
   138     else if ( iState == ESending )
   144             break;
   139         {
   145             }
   140         TImSmtpProgress prog;
   146         case ESending:
   141         TPckg<TImSmtpProgress> param(prog);
   147             {
   142         param.Copy( iOperation->FinalProgress() ); 
   148             TImSmtpProgress prog;
   143 
   149             TPckg<TImSmtpProgress> param(prog);
   144         CompleteObserver( prog.Error() );
   150             param.Copy( iOperation->FinalProgress() );
   145         }
   151 
   146     }
   152             if ( prog.Error() == KSmtpLoginRefused )
   147     
   153                 {
       
   154                 // Login details are wrong. Trying to ask for password
       
   155                 if ( !QueryUserPassL() )
       
   156                     {
       
   157                     CompleteObserver( prog.Error() );
       
   158                     }
       
   159                 }
       
   160             else if ( prog.Error() == KSmtpUnknownErr )
       
   161                 {
       
   162                 // try to handle empty password problem
       
   163                 CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   164                 CImSmtpSettings* smtpSettings = new(ELeave) CImSmtpSettings();
       
   165                 CleanupStack::PushL( smtpSettings );
       
   166                 TSmtpAccount smtpAccount;
       
   167                 accounts->GetSmtpAccountL( iSmtpService, smtpAccount );
       
   168                 accounts->LoadSmtpSettingsL( smtpAccount, *smtpSettings );
       
   169 
       
   170                 if ( smtpSettings->Password().Length() == 0 )
       
   171                     {
       
   172                     if ( !QueryUserPassL() )
       
   173                         {
       
   174                         CompleteObserver( prog.Error() );
       
   175                         }
       
   176                     }
       
   177                 CleanupStack::PopAndDestroy( 2, accounts );
       
   178                 }
       
   179             else
       
   180                 {
       
   181                 CompleteObserver( prog.Error() );
       
   182                 }
       
   183             break;
       
   184             }
       
   185         case EQueryingDetails:
       
   186             {
       
   187             delete iOperation;
       
   188             iOperation = NULL;
       
   189             // querying pass finished - try to resend mail
       
   190             CallSendL();
       
   191             break;
       
   192             }
       
   193         }
       
   194     }
       
   195 
   148 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
   149 // ---------------------------------------------------------------------------
   197 // ---------------------------------------------------------------------------
   150 //    
   198 //    
   151 void CIpsPlgSmtpOperation::DoCancel()
   199 void CIpsPlgSmtpOperation::DoCancel()
   152     {
   200     {
   398             User::Leave( KErrBadName );
   446             User::Leave( KErrBadName );
   399             }
   447             }
   400         }
   448         }
   401     }
   449     }
   402 
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // ---------------------------------------------------------------------------
       
   453 // 
       
   454 void CIpsPlgSmtpOperation::SetEventHandler( TAny* aEventHandler )
       
   455     {
       
   456     iEventHandler = aEventHandler;
       
   457     }
       
   458 
       
   459 // ---------------------------------------------------------------------------
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 TBool CIpsPlgSmtpOperation::QueryUserPassL()
       
   463     {
       
   464     if ( iEventHandler )
       
   465         {
       
   466         CIpsPlgEventHandler* eventHandler = static_cast<CIpsPlgEventHandler*>(iEventHandler);
       
   467         TMsvEntry entry;
       
   468         TMsvId service;
       
   469         User::LeaveIfError( iMsvSession.GetEntry( iSmtpService, service, entry ) );
       
   470 
       
   471         // ask for credentials for smtp account and wait for callback
       
   472         if ( eventHandler->QueryUsrPassL( entry.iRelatedId, this, EFalse ) )
       
   473             {
       
   474             iState = EQueryingDetails;
       
   475             }
       
   476         else
       
   477             {
       
   478             // another operation is waiting for password
       
   479             iState = EQueryingDetailsBusy;
       
   480             }
       
   481 
       
   482         return ETrue;
       
   483         }
       
   484 
       
   485     return EFalse;
       
   486     }
       
   487 
       
   488 // ---------------------------------------------------------------------------
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 void CIpsPlgSmtpOperation::CredientialsSetL( TInt aEvent )
       
   492     {
       
   493     FUNC_LOG;
       
   494 
       
   495     if ( iState == EQueryingDetails )
       
   496         {
       
   497         // response for our operation`s query
       
   498         if ( aEvent == EIPSSosCredientialsCancelled )
       
   499             {
       
   500             // user canceled operation
       
   501             CompleteObserver( KErrCancel );
       
   502             }
       
   503 
       
   504         // password has been set, continue with operation
       
   505         SetActive();
       
   506         CompleteThis();
       
   507         }
       
   508     else if ( iState == EQueryingDetailsBusy )
       
   509         {
       
   510         // response for other operation`s query
       
   511         // we could try to ask for password now,
       
   512         // but decision was made to cancel operation
       
   513         CompleteObserver( KErrCancel );
       
   514         SetActive();
       
   515         CompleteThis();
       
   516         }
       
   517     }
       
   518 
   403 // End of File
   519 // End of File
   404 
   520