ipsservices/ipssosplugin/src/ipsplgsosbaseplugin.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 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: This file implements classes CIpsPlgSosBasePlugin, Plugin.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "emailtrace.h"
       
    21 #include "ipsplgheaders.h"
       
    22 
       
    23 #define FREESTYLE_EMAIL_UI_SID 0x2001E277
       
    24 
       
    25 const TInt KOpGranularity = 2;
       
    26 
       
    27 _LIT( KMimeTextCalRequest,  "text/calendar; method=REQUEST;" );
       
    28 _LIT( KMimeTextCalResponse, "text/calendar; method=RESPONSE;" );
       
    29 _LIT( KMimeTextCalCancel,   "text/calendar; method=CANCEL;" );
       
    30 _LIT8( KMethod, "method" );
       
    31 _LIT8( KRequest, "REQUEST" );
       
    32 _LIT8( KResponse, "RESPONSE" );
       
    33 _LIT8( KCancel, "CANCEL" );
       
    34 
       
    35 #ifdef __WINS__
       
    36 _LIT( KEmulatorIMEI, "123456789012345" );
       
    37 #endif // __WINS__
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CIpsPlgSosBasePlugin::CIpsPlgSosBasePlugin( const TUint aFSPluginId ) :
       
    43     iFSPluginId( aFSPluginId ),
       
    44     iSession( NULL ),
       
    45     iMsgMapper( NULL ),
       
    46     iOperations( KOpGranularity ),
       
    47     iActivitytimers( KOpGranularity ),
       
    48     iSmtpService( NULL ),
       
    49     iCachedEntry( NULL ),
       
    50     iCachedEmailMessage( NULL ),
       
    51     iMruList( NULL ),
       
    52     iSearch( NULL ),
       
    53     iSettingsApi( NULL ),
       
    54     iEventHandler( NULL ),
       
    55     iSessionOk( ETrue ),
       
    56     iBrandingId( NULL ),
       
    57     iIsUnderUiProcess( EFalse )
       
    58     {
       
    59     FUNC_LOG;
       
    60     }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CIpsPlgSosBasePlugin::~CIpsPlgSosBasePlugin()
       
    66     {
       
    67     FUNC_LOG;
       
    68     if ( iWait.IsStarted() )
       
    69         {
       
    70         iWait.AsyncStop();
       
    71         }
       
    72 
       
    73     iOperations.ResetAndDestroy();
       
    74     iActivitytimers.ResetAndDestroy();
       
    75     iOperations.Close();
       
    76     iActivitytimers.Close();
       
    77     delete iSmtpService;
       
    78     delete iMruList;
       
    79     if ( iEventHandler )
       
    80         {
       
    81         iEventHandler->UnRegisterPropertyObserver( iSyncStateHandler );
       
    82         }
       
    83     delete iEventHandler;
       
    84     delete iCachedEntry;
       
    85     delete iCachedEmailMessage;
       
    86     delete iMsgMapper;
       
    87     delete iSearch;
       
    88     delete iSettingsApi;
       
    89     delete iSyncStateHandler;
       
    90     delete iSession;
       
    91     delete iBrandingId;
       
    92     }
       
    93 
       
    94 // ----------------------------------------------------------------------------
       
    95 // ----------------------------------------------------------------------------
       
    96 void CIpsPlgSosBasePlugin::BaseConstructL()
       
    97     {
       
    98     FUNC_LOG;
       
    99     iEventHandler = CIpsPlgEventHandler::NewL( *this );
       
   100     iSession = CMsvSession::OpenAsyncL( *iEventHandler );
       
   101     iMsgMapper = CIpsPlgMsgMapper::NewL( *iSession, *this );
       
   102     iSmtpService = CIpsPlgSmtpService::NewL( *iSession, *this );
       
   103     iMruList = CIpsPlgMruList::NewL( );
       
   104     iSearch = CIpsPlgSearch::NewL( *iSession, *this );
       
   105     iSettingsApi = CIpsSetDataApi::NewL( *iSession );
       
   106     iSettingsApi->GetIMEIFromThePhoneL( iIMEI );
       
   107     iSyncStateHandler = CIpsPlgSyncStateHandler::NewL(
       
   108             *iSession, *this, iOperations );
       
   109     iEventHandler->RegisterPropertyObserverL( iSyncStateHandler );
       
   110 
       
   111     RProcess process;
       
   112     if ( process.SecureId() == FREESTYLE_EMAIL_UI_SID )
       
   113         {
       
   114         iIsUnderUiProcess = ETrue;
       
   115         }
       
   116     else
       
   117         {
       
   118         iIsUnderUiProcess = EFalse;
       
   119         }
       
   120     RAlwaysOnlineClientSession aosession;
       
   121     TInt err = aosession.Connect();
       
   122     if ( err == KErrNone )
       
   123         {
       
   124         TBuf8<1> dummyBuf;
       
   125         TRAP( err, aosession.RelayCommandL(
       
   126                 EServerAPIEmailDisableAOEmailPlugin,
       
   127                 dummyBuf ) );
       
   128         }
       
   129     aosession.Close();
       
   130     }
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // ----------------------------------------------------------------------------
       
   134 void CIpsPlgSosBasePlugin::CompleteConstructL()
       
   135     {
       
   136     FUNC_LOG;
       
   137     iSessionOk = ETrue;
       
   138     iEventHandler->CompleteConstructL( iSession );
       
   139     }
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // ----------------------------------------------------------------------------
       
   143 void CIpsPlgSosBasePlugin::SessionTerminated()
       
   144     {
       
   145     FUNC_LOG;
       
   146     iSessionOk = EFalse;
       
   147     }
       
   148 
       
   149 // ----------------------------------------------------------------------------
       
   150 // ----------------------------------------------------------------------------
       
   151 void CIpsPlgSosBasePlugin::OpCompleted(
       
   152 	CIpsPlgSingleOpWatcher& aOpWatcher,
       
   153 	TInt aCompletionCode )
       
   154     {
       
   155     FUNC_LOG;
       
   156     // Get valid operation count in each, some operations could have been
       
   157     // deleted in array
       
   158     TInt opId = aOpWatcher.Operation().Id();
       
   159     for ( TInt i = iOperations.Count()-1; i >= 0; i-- )
       
   160         {
       
   161         CMsvOperation& oper = iOperations[i]->Operation();
       
   162 
       
   163         if ( oper.Id() == opId )
       
   164             {
       
   165             DeleteAndRemoveOperation( i, aCompletionCode );
       
   166             }
       
   167         }
       
   168     // make draft deletion synchronous so that empty drafts are not left after application close.
       
   169     if ( iWait.IsStarted() )
       
   170         {
       
   171         iWait.AsyncStop();
       
   172         }
       
   173     }
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // ----------------------------------------------------------------------------
       
   177  TFSMailBoxStatus CIpsPlgSosBasePlugin::GetMailBoxStatus(
       
   178     const TFSMailMsgId&  aMailBoxId  )
       
   179     {
       
   180     FUNC_LOG;
       
   181     TMsvEntry tEntry;
       
   182     TMsvId service;
       
   183     TFSMailBoxStatus status;
       
   184     if( iSessionOk )
       
   185         {
       
   186         iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
       
   187 
       
   188         if ( tEntry.Connected() )
       
   189             {
       
   190             status = EFSMailBoxOnline;
       
   191             }
       
   192         else if ( ConnOpRunning( aMailBoxId ) )
       
   193             {
       
   194             status = EFSMailBoxOnline;
       
   195             }
       
   196         else
       
   197             {
       
   198             status = EFSMailBoxOffline;
       
   199             }
       
   200         }
       
   201     else
       
   202         {
       
   203         status = EFSMailBoxOffline;
       
   204         }
       
   205     return status;
       
   206     }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CIpsPlgSosBasePlugin::SpecifiedSendingMailbox
       
   210 // Returns 'null' ID, because the method is not relevant with IPS protocols
       
   211 // ----------------------------------------------------------------------------
       
   212  TFSMailMsgId CIpsPlgSosBasePlugin::SpecifiedSendingMailbox()
       
   213      {
       
   214     FUNC_LOG;
       
   215      return TFSMailMsgId();
       
   216      }
       
   217 
       
   218  // ----------------------------------------------------------------------------
       
   219  // ----------------------------------------------------------------------------
       
   220 void CIpsPlgSosBasePlugin::ListMailBoxesL( RArray<TFSMailMsgId>& aMailboxes )
       
   221 	{
       
   222     FUNC_LOG;
       
   223 
       
   224 	if( !iSessionOk )
       
   225         {
       
   226         User::Leave( KErrNotReady );
       
   227         }
       
   228 	CMsvEntry* cEntry = iSession->GetEntryL( KMsvRootIndexEntryId );
       
   229     CleanupStack::PushL( cEntry );
       
   230 
       
   231     CMsvEntrySelection* childEntries = cEntry->ChildrenWithMtmL( MtmId() );
       
   232     CleanupStack::PushL( childEntries );
       
   233 
       
   234     TInt count( childEntries->Count() );
       
   235     for ( TInt i(0); i < count; i++)
       
   236         {
       
   237       	TFSMailMsgId mailboxId;
       
   238     	TMsvEntry tEntry;
       
   239     	TMsvId serviceId;
       
   240     	TDriveUnit driveUnit = EDriveC;
       
   241 
       
   242         iSession->GetEntry( childEntries->At(i), serviceId, tEntry );
       
   243 
       
   244         if( iIMEI.Compare( tEntry.iDescription ) == 0 )
       
   245             {
       
   246             mailboxId.SetPluginId( TUid::Uid( PluginId() ) );
       
   247             mailboxId.SetId( childEntries->At(i) );
       
   248             aMailboxes.AppendL( mailboxId );
       
   249             }
       
   250         else
       
   251             {
       
   252             TRAPD( err, driveUnit = iSession->CurrentDriveL() );
       
   253             if ( err == KErrNone && driveUnit == EDriveC )
       
   254                 {
       
   255                 // When memory card restored to another phone mailbox
       
   256                 // should be visible
       
   257                 mailboxId.SetPluginId( TUid::Uid( PluginId() ) );
       
   258                 mailboxId.SetId( childEntries->At(i) );
       
   259                 StoreIMEIToMailboxL( mailboxId.Id() );
       
   260                 aMailboxes.AppendL( mailboxId );
       
   261                 }
       
   262             }
       
   263         }
       
   264     CleanupStack::PopAndDestroy( 2, cEntry ); // childEntries
       
   265 	}
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // ----------------------------------------------------------------------------
       
   269 CFSMailBox* CIpsPlgSosBasePlugin::GetMailBoxByUidL(
       
   270     const TFSMailMsgId& aMailBoxId)
       
   271 	{
       
   272     FUNC_LOG;
       
   273     CFSMailBox* result( NULL );
       
   274     TMsvEntry tEntry;
       
   275     TMsvId    serviceId;
       
   276     TInt      status;
       
   277     HBufC*    address( NULL );
       
   278 
       
   279     if( !iSessionOk )
       
   280         {
       
   281         User::Leave( KErrNotReady );
       
   282         }
       
   283     status = iSession->GetEntry( aMailBoxId.Id(), serviceId, tEntry );
       
   284 
       
   285     if ( status == KErrNone )
       
   286         {
       
   287         result = CFSMailBox::NewL( aMailBoxId );
       
   288         CleanupStack::PushL( result );   // << result
       
   289         result->SetName( tEntry.iDetails );
       
   290         result->SetSettingsUid( TUid::Uid( IPS_SET_ECOM_IMPLEMENTATION_UID ) );
       
   291 
       
   292         iSettingsApi->GetMailboxAddressL( tEntry, address );
       
   293         CleanupStack::PushL( address ); // << address
       
   294         CFSMailAddress* fsAddress = CFSMailAddress::NewLC();    // << fsAddress
       
   295         fsAddress->SetEmailAddress( *address );
       
   296         result->SetOwnMailAddressL( fsAddress );
       
   297         CleanupStack::Pop( fsAddress ); // >> fsAddress
       
   298         CleanupStack::PopAndDestroy( address ); // >>> address
       
   299         CleanupStack::Pop( result );    // >> result
       
   300         }
       
   301 
       
   302     return result;
       
   303 	}
       
   304 
       
   305 // ----------------------------------------------------------------------------
       
   306 // ----------------------------------------------------------------------------
       
   307 void CIpsPlgSosBasePlugin::DeleteMailBoxByUidL(
       
   308     const TFSMailMsgId& aMailBoxId,
       
   309     MFSMailRequestObserver& aOperationObserver,
       
   310     const TInt aRequestId )
       
   311     {
       
   312     FUNC_LOG;
       
   313     TMsvEntry tEntry;
       
   314     TMsvId service;
       
   315     if( !iSessionOk )
       
   316         {
       
   317         User::Leave( KErrNotReady );
       
   318         }
       
   319 
       
   320     // Create connection to Always Online
       
   321     RAlwaysOnlineClientSession aosess;
       
   322     User::LeaveIfError( aosess.Connect() );
       
   323 
       
   324     // Prepare the parameters to be forwarded to AO-server
       
   325     TPckg<TMsvId> param = aMailBoxId.Id();
       
   326 
       
   327     // Send message to server and close it
       
   328     TRAP_IGNORE( aosess.RelayCommandL( EServerAPIEmailAgentRemove, param ) );
       
   329     aosess.Close();
       
   330 
       
   331     // delete MRU list from cen rep
       
   332     iMruList->ClearDataL( aMailBoxId );
       
   333 
       
   334     iSyncStateHandler->NotifyMailboxRemove( aMailBoxId.Id() );
       
   335 
       
   336     CancelAllOnlineOperations( aMailBoxId );
       
   337 
       
   338     iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
       
   339     if ( tEntry.Connected() )
       
   340         {
       
   341         DisconnectL( aMailBoxId, aOperationObserver, aRequestId, ETrue );
       
   342 
       
   343         // remove activity timer from array here but leave the actual delete
       
   344         // to the disconnect operation. This is because the disconnect op
       
   345         // sometimes tries to use the timer after it was deleted here.
       
   346         TInt timerCount = iActivitytimers.Count();
       
   347         for ( TInt j = 0; j < timerCount; j++ )
       
   348             {
       
   349             if ( iActivitytimers[j]->FSMailboxId() == aMailBoxId )
       
   350                 {
       
   351                 iActivitytimers.Remove( j );
       
   352                 timerCount--;
       
   353                 j--;
       
   354                 }
       
   355             }
       
   356         }
       
   357     else
       
   358         {
       
   359         iSettingsApi->RemoveAccountL( tEntry, *iSession );
       
   360         TFSProgress progress = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone };
       
   361         progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
   362         progress.iError = KErrNone;
       
   363         TInt requestId = aRequestId;
       
   364         aOperationObserver.RequestResponseL( progress, requestId );
       
   365 
       
   366         DeleteActivityTimer( aMailBoxId  );
       
   367         }
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 // ----------------------------------------------------------------------------
       
   372 TDesC& CIpsPlgSosBasePlugin::GetBrandingIdL( const TFSMailMsgId& aMailBoxId )
       
   373     {
       
   374     FUNC_LOG;
       
   375     if( !iSessionOk )
       
   376         {
       
   377         User::Leave( KErrNotReady );
       
   378         }
       
   379     CMsvEntry* mboxEntry = iSession->GetEntryL( aMailBoxId.Id() );
       
   380     CleanupStack::PushL( mboxEntry );
       
   381 
       
   382     TDesC& address = iSettingsApi->GetServerAddressL( *mboxEntry );
       
   383     delete iBrandingId;
       
   384     iBrandingId = NULL;
       
   385     iBrandingId = address.AllocL();
       
   386     CleanupStack::PopAndDestroy( mboxEntry );
       
   387 
       
   388     return *iBrandingId;
       
   389     }
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // Pop3 has no implementation for this virtual
       
   393 // ----------------------------------------------------------------------------
       
   394 void CIpsPlgSosBasePlugin::MoveMessagesL(
       
   395     const TFSMailMsgId& aMailBoxId,
       
   396     const RArray<TFSMailMsgId>& aMessageIds,
       
   397     const TFSMailMsgId& aSourceFolderId,
       
   398     const TFSMailMsgId& aDestinationFolderId )
       
   399 	{
       
   400     FUNC_LOG;
       
   401 	if( aDestinationFolderId.Id() == KMsvDraftEntryId  )
       
   402 	    {
       
   403 	    MoveMessagesToDraftL(
       
   404 	        aMailBoxId,
       
   405 	        aMessageIds,
       
   406 	        aSourceFolderId,
       
   407 	        aDestinationFolderId );
       
   408 	    }
       
   409 	}
       
   410 
       
   411 // ----------------------------------------------------------------------------
       
   412 // asynchronic version from move messages function, pop3 plugin not implent
       
   413 // this virtual fucntion.
       
   414 // ----------------------------------------------------------------------------
       
   415 TInt CIpsPlgSosBasePlugin::MoveMessagesL(
       
   416     const TFSMailMsgId& aMailBoxId,
       
   417     const RArray<TFSMailMsgId>& aMessageIds,
       
   418     const TFSMailMsgId& aSourceFolderId,
       
   419     const TFSMailMsgId& aDestinationFolderId,
       
   420     MFSMailRequestObserver& aOperationObserver,
       
   421     TInt aRequestId )
       
   422     {
       
   423     FUNC_LOG;
       
   424     TInt ret = KErrNotSupported;
       
   425     if( aDestinationFolderId.Id() == KMsvDraftEntryId  )
       
   426         {
       
   427         MoveMessagesToDraftL(
       
   428             aMailBoxId,
       
   429             aMessageIds,
       
   430             aSourceFolderId,
       
   431             aDestinationFolderId );
       
   432         ret = KErrNone;
       
   433         }
       
   434     ret = KErrNotSupported;
       
   435     TFSProgress progress = { 
       
   436             TFSProgress::EFSStatus_RequestComplete, 0, 0, ret };
       
   437     aOperationObserver.RequestResponseL(
       
   438             progress, aRequestId );
       
   439     return ret;
       
   440     }
       
   441 
       
   442 // ----------------------------------------------------------------------------
       
   443 // ----------------------------------------------------------------------------
       
   444 void CIpsPlgSosBasePlugin::MoveMessagesToDraftL(
       
   445     const TFSMailMsgId& /*aMailBoxId*/,
       
   446     const RArray<TFSMailMsgId>& aMessageIds,
       
   447     const TFSMailMsgId& aSourceFolderId,
       
   448     const TFSMailMsgId& aDestinationFolderId )
       
   449     {
       
   450     FUNC_LOG;
       
   451 
       
   452     TInt count( aMessageIds.Count() );
       
   453     if ( !count )
       
   454         {
       
   455         User::Leave( KErrArgument );
       
   456         }
       
   457 
       
   458     if( !iSessionOk )
       
   459         {
       
   460         User::Leave( KErrNotReady );
       
   461         }
       
   462 
       
   463     TMsvId msgService;
       
   464     TMsvEntry tEntry;
       
   465 
       
   466     CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection;
       
   467     CleanupStack::PushL(sel);
       
   468 
       
   469     CMsvEntry* msgEntry = iSession->GetEntryL( aMessageIds[0].Id() );
       
   470     CleanupStack::PushL( msgEntry );
       
   471 
       
   472 	for( TInt i(0); i < count; i++ )
       
   473         {
       
   474         iSession->GetEntry( aMessageIds[i].Id(), msgService, tEntry );
       
   475 
       
   476         if( aSourceFolderId.Id() == KMsvGlobalOutBoxIndexEntryIdValue )
       
   477             {
       
   478             if( tEntry.SendingState() != KMsvSendStateSending )
       
   479                 {
       
   480                 // Set all states in outbox to suspended
       
   481                 tEntry.SetSendingState( KMsvSendStateSuspended );
       
   482                 msgEntry->ChangeL( tEntry );
       
   483                 sel->AppendL( tEntry.Id() );
       
   484                 }
       
   485             else
       
   486                 {
       
   487                 // Not possible to move when sending, what to do???
       
   488                 // Probably some note back to UI, but we leave..
       
   489                 User::Leave( KErrNotSupported );
       
   490                 }
       
   491             }
       
   492         else
       
   493             {
       
   494             sel->AppendL( tEntry.Id() );
       
   495             }
       
   496         }
       
   497     if( sel->Count() )
       
   498         {
       
   499         CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC();
       
   500         if( !aSourceFolderId.IsNullId() )
       
   501             {
       
   502             CMsvEntry* cEntry = iSession->GetEntryL( aSourceFolderId.Id() );
       
   503             CleanupStack::PushL( cEntry );
       
   504             cEntry->MoveL(
       
   505                 *sel,
       
   506                            aDestinationFolderId.Id(),//KMsvDraftEntryIdValue
       
   507                            wait->iStatus );
       
   508 
       
   509             CleanupStack::PopAndDestroy( cEntry );
       
   510             }
       
   511         else
       
   512             {
       
   513             // Message is in editing state, we can't use parent as entry
       
   514             // because it's equal to destination.
       
   515             TMsvId parent = msgEntry->Entry().Parent();
       
   516             msgEntry->SetEntryL( parent );
       
   517             msgEntry->CopyL(
       
   518                 *sel,
       
   519                              aDestinationFolderId.Id(),//KMsvDraftEntryIdValue
       
   520                              wait->iStatus );
       
   521             }
       
   522         wait->Start();
       
   523         CleanupStack::PopAndDestroy( wait ); // wait
       
   524         }
       
   525     CleanupStack::PopAndDestroy( 2, sel ); // msgEntry, sel
       
   526     }
       
   527 
       
   528 // ----------------------------------------------------------------------------
       
   529 // ----------------------------------------------------------------------------
       
   530 void CIpsPlgSosBasePlugin::CopyMessagesL(
       
   531     const TFSMailMsgId& /*aMailBoxId*/,
       
   532     const RArray<TFSMailMsgId>& /*aMessageIds*/,
       
   533     RArray<TFSMailMsgId>& /*aNewMessages*/,
       
   534     const TFSMailMsgId& /*aSourceFolderId*/,
       
   535     const TFSMailMsgId& /*aDestinationFolderId*/ )
       
   536 	{
       
   537 	}
       
   538 
       
   539 // ----------------------------------------------------------------------------
       
   540 // ----------------------------------------------------------------------------
       
   541 MDesCArray* CIpsPlgSosBasePlugin::GetMrusL(
       
   542                 const TFSMailMsgId& aMailBoxId)
       
   543     {
       
   544     return iMruList->GetMruListL( aMailBoxId );
       
   545     }
       
   546 
       
   547 // ----------------------------------------------------------------------------
       
   548 // ----------------------------------------------------------------------------
       
   549 void CIpsPlgSosBasePlugin::SetMrusL(
       
   550     const TFSMailMsgId& aMailBoxId,
       
   551     MDesCArray*  aNewMruList )
       
   552     {
       
   553     iMruList->SetMruListL( aMailBoxId, aNewMruList );
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // ---------------------------------------------------------------------------
       
   558 void CIpsPlgSosBasePlugin::GoOnlineL( const TFSMailMsgId& aMailBoxId )
       
   559     {
       
   560     if ( !ConnOpRunning( aMailBoxId) )
       
   561         {
       
   562         // append mailbox id go online mailbox array
       
   563         RefreshNowL( aMailBoxId, *this, 0 );
       
   564         }
       
   565     }
       
   566 
       
   567 // ---------------------------------------------------------------------------
       
   568 // ---------------------------------------------------------------------------
       
   569 void CIpsPlgSosBasePlugin::GoOfflineL( const TFSMailMsgId& aMailBoxId )
       
   570     {
       
   571     FUNC_LOG;
       
   572     CancelAllOnlineOperations( aMailBoxId );
       
   573     // use 0 for request id
       
   574     DisconnectL( aMailBoxId, *this, 0 );
       
   575     }
       
   576 
       
   577 // ----------------------------------------------------------------------------
       
   578 // ----------------------------------------------------------------------------
       
   579 const TFSProgress CIpsPlgSosBasePlugin::GetLastSyncStatusL(
       
   580     const TFSMailMsgId& aMailBoxId )
       
   581     {
       
   582     FUNC_LOG;
       
   583     TMsvEntry tEntry;
       
   584     TMsvId service;
       
   585     TFSProgress progress = { TFSProgress::EFSStatus_Status, 0, 0, KErrNone };
       
   586 
       
   587     if( !iSessionOk )
       
   588         {
       
   589         User::Leave( KErrNotReady );
       
   590         }
       
   591     iSession->GetEntry( aMailBoxId.Id(), service, tEntry );
       
   592 
       
   593     TInt state = iSettingsApi->GetLastSyncStatusL( tEntry );
       
   594 
       
   595     switch( state )
       
   596         {
       
   597         case ESyncFinishedSuccessfully:
       
   598             progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
   599             break;
       
   600         case ESyncCancelled:
       
   601             progress.iProgressStatus = TFSProgress::EFSStatus_RequestCancelled;
       
   602             break;
       
   603         case ESyncError:
       
   604             progress.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
   605             progress.iError = KErrGeneral;
       
   606             break;
       
   607         default:
       
   608             progress.iProgressStatus = TFSProgress::EFSStatus_Status;
       
   609             progress.iError = state; // probably some symbian error code
       
   610             break;
       
   611         }
       
   612     return progress;
       
   613     }
       
   614 
       
   615 // ----------------------------------------------------------------------------
       
   616 // ----------------------------------------------------------------------------
       
   617 TInt CIpsPlgSosBasePlugin::CancelSyncL( const TFSMailMsgId& aMailBoxId )
       
   618     {
       
   619     FUNC_LOG;
       
   620     TInt err = KErrNone;
       
   621 
       
   622     // found correct operation
       
   623     for ( TInt i = iOperations.Count()-1; i >= 0; i-- )
       
   624         {
       
   625         const CIpsPlgBaseOperation* baseOp =
       
   626             iOperations[i]->BaseOperation();
       
   627         if ( baseOp && baseOp->FSMailboxId() == aMailBoxId &&
       
   628                ( baseOp->IpsOpType() == EIpsOpTypePop3SyncOp
       
   629                 || baseOp->IpsOpType() == EIpsOpTypeImap4SyncOp
       
   630                 || baseOp->IpsOpType() == EIpsOpTypeImap4PopulateOp ) )
       
   631             {
       
   632             DeleteAndRemoveOperation( i, KErrCancel );
       
   633             }
       
   634         }
       
   635 /** <should be commented out until AO Manager API enhancements are back ported>
       
   636     RAlwaysOnlineClientSession aosession;
       
   637     err = aosession.Connect();
       
   638     if ( err == KErrNone )
       
   639         {
       
   640         TPckgBuf<TMsvId> buf(aMailBoxId.Id());
       
   641         TRAP( err, aosession.RelayCommandL(
       
   642                 EServerAPIEmailCancelAllAndDoNotDisconnect, buf ) );
       
   643         }
       
   644     aosession.Close();
       
   645     */
       
   646 
       
   647     return err;
       
   648     }
       
   649 
       
   650 // ----------------------------------------------------------------------------
       
   651 // ----------------------------------------------------------------------------
       
   652 //
       
   653 CFSMailFolder* CIpsPlgSosBasePlugin::GetFolderByUidL(
       
   654     const TFSMailMsgId& aMailBoxId,
       
   655     const TFSMailMsgId& aFolderId )
       
   656     {
       
   657     FUNC_LOG;
       
   658     CFSMailFolder* result( NULL);
       
   659     if( !iSessionOk )
       
   660         {
       
   661         User::Leave( KErrNotReady );
       
   662         }
       
   663 
       
   664     CMsvEntry* folderEntry = iSession->GetEntryL( aFolderId.Id() );
       
   665     CleanupStack::PushL( folderEntry ); // << folderEntry
       
   666 
       
   667     if ( folderEntry )
       
   668         {
       
   669         result = CFSMailFolder::NewLC( aFolderId ); // << result
       
   670         result->SetMailBoxId( aMailBoxId );
       
   671 
       
   672         CMsvEntrySelection* msgChilds = folderEntry->ChildrenWithTypeL(
       
   673                 KUidMsvMessageEntry );
       
   674         CleanupStack::PushL( msgChilds );
       
   675         TInt msgCount( msgChilds->Count() );
       
   676         result->SetMessageCount( msgCount );
       
   677         TInt unreadCount( 0 );
       
   678         TMsvId serviceId;
       
   679         for ( TInt i(0); i < msgCount; i++ )
       
   680             {
       
   681             TMsvEmailEntry emlEntry;
       
   682             TMsvId dummy;
       
   683             TBool isRead = ETrue;
       
   684             if ( iSession->GetEntry(
       
   685                     msgChilds->At(i), dummy, emlEntry ) == KErrNone )
       
   686                 {
       
   687                 if ( ( PluginId() == KIpsPlgImap4PluginUid.iUid ||
       
   688                        PluginId() == KIpsPlgPop3PluginUid.iUid ) &&
       
   689                         emlEntry.Unread() )
       
   690                     {
       
   691                     isRead = EFalse;
       
   692                     }
       
   693                 }
       
   694             if ( !isRead && !emlEntry.LocallyDeleted() )
       
   695                 {
       
   696                 unreadCount++;
       
   697                 }
       
   698             }
       
   699 
       
   700         CleanupStack::PopAndDestroy( msgChilds );
       
   701         result->SetUnreadCount( unreadCount );
       
   702         result->SetFolderName( folderEntry->Entry().iDetails );
       
   703         result->SetFolderType( GetFolderType( folderEntry, aFolderId ) );
       
   704         TMsvEntry parentEntry;
       
   705         TInt status = iSession->GetEntry( folderEntry->Entry().Parent( ), serviceId,
       
   706                 parentEntry );
       
   707         TUint parent( 0 );
       
   708 		if( status == KErrNone )
       
   709 			{
       
   710 			if( parentEntry.iType == KUidMsvFolderEntry )
       
   711 				{
       
   712 				parent = static_cast<TUint>( folderEntry->Entry().Parent() );
       
   713 				}
       
   714 			else
       
   715 				{
       
   716                 parent = 0;
       
   717 				}
       
   718 			}
       
   719 
       
   720         TFSMailMsgId parentId( PluginId(), parent );
       
   721         result->SetParentFolderId( parentId );
       
   722 
       
   723         // Set subfolder count here for ListFolderL
       
   724         CMsvEntrySelection* fldChildren =
       
   725     		folderEntry->ChildrenWithTypeL( KUidMsvFolderEntry );
       
   726     	CleanupStack::PushL( fldChildren );    // << children
       
   727         result->SetSubFolderCount( fldChildren->Count() );
       
   728         CleanupStack::PopAndDestroy( fldChildren );    // >>> children
       
   729 
       
   730         // Set blocklist for FW
       
   731         BlockCopyMoveFromFoldersL( folderEntry, aFolderId, *result );
       
   732 
       
   733         CleanupStack::Pop( result );    // >> result
       
   734         }
       
   735 	CleanupStack::PopAndDestroy( folderEntry ); // >>> folderEntry
       
   736 
       
   737     return result;
       
   738 	}
       
   739 
       
   740 // ----------------------------------------------------------------------------
       
   741 // ----------------------------------------------------------------------------
       
   742 CFSMailFolder* CIpsPlgSosBasePlugin::CreateFolderL(
       
   743     const TFSMailMsgId& /* aMailBoxId */,
       
   744     const TFSMailMsgId& /* aFolderId */,
       
   745     const TDesC& /* aFolderName */,
       
   746     const TBool /* aSync */)
       
   747 	{
       
   748 	return NULL;
       
   749 	}
       
   750 
       
   751 // ----------------------------------------------------------------------------
       
   752 // ----------------------------------------------------------------------------
       
   753 void CIpsPlgSosBasePlugin::DeleteFolderByUidL(
       
   754     const TFSMailMsgId& /* aMailBoxId */,
       
   755     const TFSMailMsgId& /* aFolderId */)
       
   756 	{
       
   757 	}
       
   758 
       
   759 // ----------------------------------------------------------------------------
       
   760 // ----------------------------------------------------------------------------
       
   761 MFSMailIterator* CIpsPlgSosBasePlugin::ListMessagesL(
       
   762     const TFSMailMsgId& aMailBoxId,
       
   763     const TFSMailMsgId& aFolderId,
       
   764     const TFSMailDetails aDetails,
       
   765     const RArray<TFSMailSortCriteria>& aSorting )
       
   766     {
       
   767     FUNC_LOG;
       
   768     CIpsPlgMsgIterator* iterator = CIpsPlgMsgIterator::NewL(
       
   769         *this, *iSession, aMailBoxId, aFolderId, aDetails, aSorting );
       
   770 
       
   771     return iterator;
       
   772     }
       
   773 
       
   774 // ----------------------------------------------------------------------------
       
   775 // ----------------------------------------------------------------------------
       
   776 //
       
   777 CFSMailMessage* CIpsPlgSosBasePlugin::GetMessageByUidL(
       
   778     const TFSMailMsgId& aMailBoxId,
       
   779     const TFSMailMsgId& /* aFolderId */,
       
   780     const TFSMailMsgId& aMessageId,
       
   781     const TFSMailDetails aDetails)
       
   782 	{
       
   783     FUNC_LOG;
       
   784 	CFSMailMessage* result( NULL );
       
   785 	TMsvId serviceId;
       
   786 	TMsvEntry tEntry;
       
   787 	TInt status( KErrNone );
       
   788 
       
   789 	if( !iSessionOk )
       
   790 	    {
       
   791 	    User::Leave( KErrNotReady );
       
   792 	    }
       
   793 
       
   794 	status = iSession->GetEntry( aMessageId.Id(), serviceId, tEntry);
       
   795 
       
   796 	const TMsvEmailEntry& emlEntry(tEntry);
       
   797 	// do not give deleted marked messages
       
   798 	if ( status == KErrNone &&
       
   799 	    EDisconnectedDeleteOperation != emlEntry.DisconnectedOperation()
       
   800 	    && !emlEntry.DeletedIMAP4Flag() )
       
   801 	    {
       
   802         result = iMsgMapper->GetMailMessageL( aMailBoxId, tEntry, aDetails );
       
   803 	    }
       
   804 
       
   805 	return result;
       
   806 	}
       
   807 
       
   808 // ----------------------------------------------------------------------------
       
   809 // ----------------------------------------------------------------------------
       
   810  CFSMailMessage* CIpsPlgSosBasePlugin::CreateMessageToSendL(
       
   811     const TFSMailMsgId& aMailBoxId )
       
   812 	{
       
   813     FUNC_LOG;
       
   814     CFSMailMessage* msg = iSmtpService->CreateNewSmtpMessageL( aMailBoxId );
       
   815 	return msg;
       
   816 	}
       
   817 
       
   818 // ----------------------------------------------------------------------------
       
   819 // ----------------------------------------------------------------------------
       
   820 CFSMailMessage* CIpsPlgSosBasePlugin::CreateForwardMessageL(
       
   821     const TFSMailMsgId& aMailBoxId,
       
   822     const TFSMailMsgId& aOriginalMessageId,
       
   823     const TDesC& /* aHeaderDescriptor */)
       
   824     {
       
   825     FUNC_LOG;
       
   826     CFSMailMessage* msg = iSmtpService->CreateForwardSmtpMessageL(
       
   827         aMailBoxId, aOriginalMessageId );
       
   828     return msg;
       
   829     }
       
   830 
       
   831 // ----------------------------------------------------------------------------
       
   832 // ----------------------------------------------------------------------------
       
   833 CFSMailMessage* CIpsPlgSosBasePlugin::CreateReplyMessageL(
       
   834     const TFSMailMsgId& aMailBoxId,
       
   835     const TFSMailMsgId& aOriginalMessageId,
       
   836     const TBool aReplyToAll,
       
   837     const TDesC& /* aHeaderDescriptor */ )
       
   838     {
       
   839     FUNC_LOG;
       
   840     CFSMailMessage* msg = iSmtpService->CreateReplySmtpMessageL(
       
   841         aMailBoxId, aOriginalMessageId, aReplyToAll );
       
   842     return msg;
       
   843     }
       
   844 
       
   845 // ----------------------------------------------------------------------------
       
   846 // ----------------------------------------------------------------------------
       
   847 //
       
   848 void CIpsPlgSosBasePlugin::StoreMessageL(
       
   849     const TFSMailMsgId& aMailBoxId,
       
   850     CFSMailMessage& aMessage )
       
   851  	{
       
   852     FUNC_LOG;
       
   853     TInt status( KErrNone);
       
   854     TFSMailMsgId msgId( aMessage.GetMessageId( ));
       
   855     TMsvEntry tEntry;
       
   856     TMsvId serviceId;
       
   857     TBool incoming( EFalse);
       
   858 
       
   859     // Check whether this is IMAP4 or POP3 (incoming) message
       
   860     if ( !msgId.IsNullId() )
       
   861         {
       
   862         status = iSession->GetEntry( msgId.Id( ), serviceId, tEntry );
       
   863 
       
   864         if ( status == KErrNone )
       
   865             {
       
   866             incoming = ( tEntry.iMtm == KSenduiMtmImap4Uid ) ||
       
   867                 ( tEntry.iMtm == KSenduiMtmPop3Uid );
       
   868             }
       
   869         }
       
   870 
       
   871     if ( incoming )
       
   872         {
       
   873         // It`s commented because when it`s used heavile cause -16 error
       
   874         // For example when user want to mark as read/unread many messages
       
   875         // Synchronous method solves this issue
       
   876         iMsgMapper->UpdateMessageFlagsL(msgId.Id(), aMessage);
       
   877         /*CIpsPlgSingleOpWatcher* opW = CIpsPlgSingleOpWatcher::NewLC( *this );
       
   878         CMsvOperation* op = iMsgMapper->UpdateMessageFlagsAsyncL(
       
   879                 msgId.Id(), aMessage, opW->iStatus );
       
   880 
       
   881         if ( op )
       
   882             {
       
   883             opW->SetOperation( op );
       
   884             iOperations.AppendL( opW );
       
   885             CleanupStack::Pop( opW );
       
   886             }
       
   887         else
       
   888             {
       
   889             CleanupStack::PopAndDestroy( opW );
       
   890             }*/
       
   891         }
       
   892     else
       
   893         {
       
   894         iSmtpService->StoreMessageL( aMailBoxId, aMessage );
       
   895         }
       
   896     }
       
   897 
       
   898 // ----------------------------------------------------------------------------
       
   899 // CIpsPlgSosBasePlugin::GetMessagesL()
       
   900 // ----------------------------------------------------------------------------
       
   901 //
       
   902 void CIpsPlgSosBasePlugin::GetMessagesL(
       
   903     const TFSMailMsgId& aMailBoxId,
       
   904     const TFSMailMsgId& aFolderId,
       
   905     const RArray<TFSMailMsgId>& aMessageIds,
       
   906     RPointerArray<CFSMailMessage>& aMessageList,
       
   907     const TFSMailDetails aDetails )
       
   908 	{
       
   909     FUNC_LOG;
       
   910     TInt i;
       
   911     CFSMailMessage* msg;
       
   912 
       
   913 	for (i = 0; i < aMessageIds.Count(); i++ )
       
   914         {
       
   915         msg = GetMessageByUidL(
       
   916             aMailBoxId, aFolderId, aMessageIds[i], aDetails );
       
   917         CleanupStack::PushL( msg );
       
   918         aMessageList.AppendL( msg );
       
   919         CleanupStack::Pop( msg );
       
   920         }
       
   921 	}
       
   922 
       
   923 // ----------------------------------------------------------------------------
       
   924 // ----------------------------------------------------------------------------
       
   925 void CIpsPlgSosBasePlugin::ChildPartsL(
       
   926     const TFSMailMsgId& aMailBoxId,
       
   927     const TFSMailMsgId& /* aParentFolderId */,
       
   928     const TFSMailMsgId& aMessageId,
       
   929     const TFSMailMsgId& aParentId,
       
   930     RPointerArray<CFSMailMessagePart>& aParts)
       
   931 	{
       
   932     FUNC_LOG;
       
   933     iMsgMapper->GetChildPartsL( aMailBoxId, aMessageId, aParentId, aParts );
       
   934 	}
       
   935 
       
   936 // ----------------------------------------------------------------------------
       
   937 // ----------------------------------------------------------------------------
       
   938 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartL(
       
   939     const TFSMailMsgId& aMailBoxId,
       
   940     const TFSMailMsgId& /* aParentFolderId */,
       
   941     const TFSMailMsgId& aMessageId,
       
   942     const TFSMailMsgId& aParentPartId,
       
   943     const TFSMailMsgId& /* aInsertBefore */,
       
   944     const TDesC& aContentType )
       
   945 	{
       
   946     FUNC_LOG;
       
   947     CFSMailMessagePart* result;
       
   948     result = iMsgMapper->NewChildPartL( aMailBoxId, aMessageId, aParentPartId,
       
   949         aContentType );
       
   950     return result;
       
   951     }
       
   952 
       
   953 // ----------------------------------------------------------------------------
       
   954 // ----------------------------------------------------------------------------
       
   955 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
       
   956     const TFSMailMsgId& aMailBoxId,
       
   957     const TFSMailMsgId& /* aParentFolderId */,
       
   958     const TFSMailMsgId& aMessageId,
       
   959     const TFSMailMsgId& /* aParentPartId */,
       
   960     const TDesC& aContentType,
       
   961     const TDesC& aFilePath )
       
   962     {
       
   963     FUNC_LOG;
       
   964     CFSMailMessagePart* result ( NULL );
       
   965     CMsvEntry* cEntry( NULL );
       
   966     CImEmailMessage* message( NULL );
       
   967     RFile file;
       
   968     TInt fileSize( 0 );
       
   969     TBool parentToMultipartAlternative( EFalse );
       
   970 
       
   971     // Read attachment size
       
   972     User::LeaveIfError( file.Open( iSession->FileSession(), aFilePath, EFileShareReadersOnly ) );
       
   973 
       
   974     //in rare case that file has disappeared while sending
       
   975     //we just won't get the size for it
       
   976     file.Size( fileSize );
       
   977     file.Close();
       
   978 
       
   979     // Initialize CMsvAttachment instance for the attachment creation
       
   980     CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
       
   981     CleanupStack::PushL( info );
       
   982 
       
   983     info->SetAttachmentNameL( aFilePath );
       
   984     info->SetSize( fileSize );
       
   985 
       
   986     // Create/acquire Symbian message entry objects
       
   987     GetMessageEntryL( aMessageId.Id(), cEntry, message );
       
   988 
       
   989     // Operation waiter needed to implement synchronous operation
       
   990     // on the top of async API
       
   991     CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
   992     CleanupStack::PushL( waiter );
       
   993 
       
   994     // Start attachment creation
       
   995     message->AttachmentManager().AddAttachmentL(
       
   996         aFilePath, info, waiter->iStatus );
       
   997 
       
   998     waiter->Start();
       
   999     CleanupStack::PopAndDestroy( waiter );
       
  1000     CleanupStack::Pop( info ); // attachment manager takes ownership
       
  1001 
       
  1002     // Dig out the entry ID of the new attachment (unbelievable that
       
  1003     // there seems to be no better way to do this)
       
  1004     message->GetAttachmentsListL( cEntry->Entry().Id( ),
       
  1005         CImEmailMessage::EAllAttachments, CImEmailMessage::EThisMessageOnly );
       
  1006     TKeyArrayFix key( 0, ECmpTInt32 );
       
  1007     CMsvEntrySelection* attachmentIds = message->Selection().CopyLC();
       
  1008     attachmentIds->Sort( key );
       
  1009     if ( !attachmentIds->Count() )
       
  1010         {
       
  1011         User::Leave( KErrGeneral );
       
  1012         }
       
  1013     TMsvId newAttachmentId = (*attachmentIds)[ attachmentIds->Count()-1 ];
       
  1014     CleanupStack::PopAndDestroy( attachmentIds );
       
  1015 
       
  1016     CMsvEntry* cAtta = iSession->GetEntryL( newAttachmentId );
       
  1017     CleanupStack::PushL( cAtta );
       
  1018 
       
  1019     // Set filename to iDetails
       
  1020     TMsvEntry tEntry = cAtta->Entry();
       
  1021     tEntry.iDetails.Set( aFilePath );
       
  1022     cAtta->ChangeL( tEntry );
       
  1023 
       
  1024     if( cAtta->HasStoreL() )
       
  1025         {
       
  1026         CMsvStore* store = cAtta->EditStoreL();
       
  1027         CleanupStack::PushL( store );
       
  1028         CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
  1029 
       
  1030         if( store->IsPresentL( KUidMsgFileMimeHeader ) )
       
  1031             {
       
  1032             mimeHeader->RestoreL( *store );
       
  1033             CDesC8Array& array = mimeHeader->ContentTypeParams();
       
  1034             array.AppendL( KMethod );
       
  1035             parentToMultipartAlternative = ETrue;
       
  1036 
       
  1037             if( aContentType.Find( KMimeTextCalRequest ) != KErrNotFound )
       
  1038                 {
       
  1039                 array.AppendL( KRequest );
       
  1040                 }
       
  1041             else if( aContentType.Find( KMimeTextCalResponse ) != KErrNotFound )
       
  1042                 {
       
  1043                 array.AppendL( KResponse );
       
  1044                 }
       
  1045             else if( aContentType.Find( KMimeTextCalCancel ) != KErrNotFound )
       
  1046                 {
       
  1047                 array.AppendL( KCancel );
       
  1048                 }
       
  1049             else
       
  1050                 {
       
  1051                 parentToMultipartAlternative = EFalse;
       
  1052                 }
       
  1053             mimeHeader->StoreWithoutCommitL( *store );
       
  1054             store->CommitL();
       
  1055             }
       
  1056 
       
  1057         CleanupStack::PopAndDestroy( 2, store );
       
  1058         }
       
  1059 
       
  1060     if( parentToMultipartAlternative &&
       
  1061         aFilePath.Find( _L(".ics")) != KErrNotFound )
       
  1062         {
       
  1063         TMsvEntry tAttaEntry = cAtta->Entry();
       
  1064         TMsvId id = tAttaEntry.Parent();
       
  1065         CMsvEntry* cParent = iSession->GetEntryL( id );
       
  1066         CleanupStack::PushL( cParent );
       
  1067 
       
  1068         TMsvEmailEntry tEntry = cParent->Entry();
       
  1069         tEntry.SetMessageFolderType( EFolderTypeAlternative );
       
  1070         cParent->ChangeL( tEntry );
       
  1071 
       
  1072         CleanupStack::PopAndDestroy( cParent );
       
  1073         }
       
  1074     CleanupStack::PopAndDestroy( cAtta );
       
  1075 
       
  1076     // Delete the message entries to get all the changes to disk and
       
  1077     // possible store locks released
       
  1078     CleanCachedMessageEntries();
       
  1079 
       
  1080     // Create the FS message part object
       
  1081     result = iMsgMapper->GetMessagePartL( newAttachmentId, aMailBoxId,
       
  1082         aMessageId );
       
  1083 
       
  1084     return result;
       
  1085     }
       
  1086 
       
  1087 // ----------------------------------------------------------------------------
       
  1088 // ----------------------------------------------------------------------------
       
  1089 CFSMailMessagePart* CIpsPlgSosBasePlugin::NewChildPartFromFileL(
       
  1090     const TFSMailMsgId& aMailBoxId,
       
  1091     const TFSMailMsgId& /* aParentFolderId */,
       
  1092     const TFSMailMsgId& aMessageId,
       
  1093     const TFSMailMsgId& /* aParentPartId */,
       
  1094     const TDesC& aContentType,
       
  1095     RFile& aFile )
       
  1096     {
       
  1097     FUNC_LOG;
       
  1098 
       
  1099     // Initialize helper variables
       
  1100     CFSMailMessagePart* result ( NULL );
       
  1101     CMsvEntry* cEntry( NULL );
       
  1102     CImEmailMessage* message( NULL );
       
  1103     TInt fileSize( 0 );
       
  1104     TBuf<KMaxFileName> fileName;
       
  1105 
       
  1106     // Create/acquire Symbian message entry objects
       
  1107     CleanCachedMessageEntries();
       
  1108     GetMessageEntryL( aMessageId.Id(), cEntry, message );
       
  1109 
       
  1110     // Initialize CMsvAttachment instance for the attachment creation
       
  1111     CMsvAttachment* info = CMsvAttachment::NewL( CMsvAttachment::EMsvFile );
       
  1112     CleanupStack::PushL( info );
       
  1113 
       
  1114     // Read attachment size
       
  1115     User::LeaveIfError( aFile.Size( fileSize ) );
       
  1116     info->SetSize( fileSize );
       
  1117 
       
  1118     // Read attachment filename
       
  1119     User::LeaveIfError( aFile.FullName( fileName ) );
       
  1120     info->SetAttachmentNameL( fileName );
       
  1121 
       
  1122     // Operation waiter needed to implement synchronous operation
       
  1123     // on the top of async API
       
  1124     CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1125     CleanupStack::PushL( waiter );
       
  1126     message->AttachmentManager().AddAttachmentL( aFile, info, waiter->iStatus );
       
  1127     waiter->Start();
       
  1128     CleanupStack::PopAndDestroy( waiter );
       
  1129     CleanupStack::Pop( info ); // attachment manager takes ownership
       
  1130 
       
  1131     // Dig out the entry ID of the new attachment
       
  1132     message->GetAttachmentsListL( cEntry->Entry().Id( ),
       
  1133         CImEmailMessage::EAllAttachments, CImEmailMessage::EThisMessageOnly );
       
  1134     TKeyArrayFix key( 0, ECmpTInt32 );
       
  1135     CMsvEntrySelection* attachmentIds = message->Selection().CopyLC();
       
  1136     attachmentIds->Sort( key );
       
  1137     if ( !attachmentIds->Count() )
       
  1138         {
       
  1139         User::Leave( KErrGeneral );
       
  1140         }
       
  1141     TMsvId newAttachmentId = (*attachmentIds)[ attachmentIds->Count()-1 ];
       
  1142     CleanupStack::PopAndDestroy( attachmentIds );
       
  1143 
       
  1144     // Meeting request related handling
       
  1145     TBool parentToMultipartAlternative( EFalse );
       
  1146     CMsvEntry* cAtta = iSession->GetEntryL( newAttachmentId );
       
  1147     CleanupStack::PushL( cAtta );
       
  1148 
       
  1149     // Set filename to iDetails
       
  1150     TMsvEntry tEntry = cAtta->Entry();
       
  1151     tEntry.iDetails.Set( fileName );
       
  1152     cAtta->ChangeL( tEntry );
       
  1153 
       
  1154     if( cAtta->HasStoreL() )
       
  1155         {
       
  1156         CMsvStore* store = cAtta->EditStoreL();
       
  1157         CleanupStack::PushL( store );
       
  1158         CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
  1159 
       
  1160         if( store->IsPresentL( KUidMsgFileMimeHeader ) )
       
  1161             {
       
  1162             mimeHeader->RestoreL( *store );
       
  1163             CDesC8Array& array = mimeHeader->ContentTypeParams();
       
  1164             array.AppendL( KMethod );
       
  1165             parentToMultipartAlternative = ETrue;
       
  1166 
       
  1167             if( aContentType.Find( KMimeTextCalRequest ) != KErrNotFound )
       
  1168                 {
       
  1169                 array.AppendL( KRequest );
       
  1170                 }
       
  1171             else if( aContentType.Find( KMimeTextCalResponse ) != KErrNotFound )
       
  1172                 {
       
  1173                 array.AppendL( KResponse );
       
  1174                 }
       
  1175             else if( aContentType.Find( KMimeTextCalCancel ) != KErrNotFound )
       
  1176                 {
       
  1177                 array.AppendL( KCancel );
       
  1178                 }
       
  1179             else
       
  1180                 {
       
  1181                 parentToMultipartAlternative = EFalse;
       
  1182                 }
       
  1183             mimeHeader->StoreWithoutCommitL( *store );
       
  1184             store->CommitL();
       
  1185             }
       
  1186         CleanupStack::PopAndDestroy( 2, store );
       
  1187         }
       
  1188     if( parentToMultipartAlternative && fileName.Find( _L(".ics")) != KErrNotFound )
       
  1189         {
       
  1190         TMsvEntry tAttaEntry = cAtta->Entry();
       
  1191         TMsvId id = tAttaEntry.Parent();
       
  1192         CMsvEntry* cParent = iSession->GetEntryL( id );
       
  1193         CleanupStack::PushL( cParent );
       
  1194 
       
  1195         TMsvEmailEntry tEntry = cParent->Entry();
       
  1196         tEntry.SetMessageFolderType( EFolderTypeAlternative );
       
  1197         cParent->ChangeL( tEntry );
       
  1198 
       
  1199         CleanupStack::PopAndDestroy( cParent );
       
  1200         }
       
  1201     CleanupStack::PopAndDestroy( cAtta );
       
  1202 
       
  1203     // Delete the message entries to get all the changes to disk and
       
  1204     // possible store locks released
       
  1205     CleanCachedMessageEntries();
       
  1206 
       
  1207     // Create the FS message part object and return it
       
  1208     result = iMsgMapper->GetMessagePartL( newAttachmentId, aMailBoxId,
       
  1209         aMessageId );
       
  1210     return result;
       
  1211     }
       
  1212 
       
  1213 // ----------------------------------------------------------------------------
       
  1214 // ----------------------------------------------------------------------------
       
  1215 CFSMailMessagePart* CIpsPlgSosBasePlugin::CopyMessageAsChildPartL(
       
  1216     const TFSMailMsgId& /* aMailBoxId */,
       
  1217     const TFSMailMsgId& /* aParentFolderId */,
       
  1218     const TFSMailMsgId& /* aMessageId */,
       
  1219     const TFSMailMsgId& /* aParentPartId */,
       
  1220     const TFSMailMsgId& /* aInsertBefore */,
       
  1221     const CFSMailMessage& /* aMessage */)
       
  1222 	{
       
  1223 	return NULL;
       
  1224 	}
       
  1225 
       
  1226 // ----------------------------------------------------------------------------
       
  1227 // Supports currently deletion of attachments and multipart structures
       
  1228 // which are represented as folders in Symbian store)
       
  1229 // ----------------------------------------------------------------------------
       
  1230 //
       
  1231 void CIpsPlgSosBasePlugin::RemoveChildPartL(
       
  1232     const TFSMailMsgId& /* aMailBoxId */,
       
  1233     const TFSMailMsgId& /* aParentFolderId */,
       
  1234     const TFSMailMsgId& aMessageId,
       
  1235     const TFSMailMsgId& /* aParentPartId */,
       
  1236     const TFSMailMsgId& aPartId)
       
  1237 	{
       
  1238     FUNC_LOG;
       
  1239     TInt status( KErrNone );
       
  1240     CMsvEntry* cEntry( NULL );
       
  1241     TMsvEntry tEntry;
       
  1242     TMsvId serviceId;
       
  1243     status = iSession->GetEntry( aPartId.Id(), serviceId, tEntry );
       
  1244 
       
  1245     if ( ( status == KErrNone ) &&
       
  1246          ( tEntry.iType == KUidMsvAttachmentEntry ) )
       
  1247         {
       
  1248         CImEmailMessage* message( NULL );
       
  1249         // We trust that the message ID really refers to a message
       
  1250         GetMessageEntryL( aMessageId.Id(), cEntry, message );
       
  1251 
       
  1252         MMsvAttachmentManager& attachmentMgr( message->AttachmentManager() );
       
  1253 
       
  1254         CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewL();
       
  1255         CleanupStack::PushL( waiter );
       
  1256 
       
  1257         attachmentMgr.RemoveAttachmentL(
       
  1258             (TMsvAttachmentId) aPartId.Id(), waiter->iStatus );
       
  1259 
       
  1260         waiter->Start();
       
  1261         CleanupStack::PopAndDestroy( waiter );
       
  1262         }
       
  1263     else if ( ( status == KErrNone ) &&
       
  1264               ( tEntry.iType == KUidMsvFolderEntry ) )
       
  1265         {
       
  1266         cEntry = iSession->GetEntryL( tEntry.Parent() );
       
  1267         CleanupStack::PushL( cEntry );
       
  1268         cEntry->DeleteL( tEntry.Id() );
       
  1269         CleanupStack::PopAndDestroy( cEntry );
       
  1270         }
       
  1271 	}
       
  1272 
       
  1273 // ----------------------------------------------------------------------------
       
  1274 // The implementation supoorts the atachment and body parts at the moment.
       
  1275 // ----------------------------------------------------------------------------
       
  1276 //
       
  1277 CFSMailMessagePart* CIpsPlgSosBasePlugin::MessagePartL(
       
  1278     const TFSMailMsgId& aMailBoxId,
       
  1279     const TFSMailMsgId& /* aParentFolderId */,
       
  1280     const TFSMailMsgId& aMessageId,
       
  1281     const TFSMailMsgId& aMessagePartId)
       
  1282 	{
       
  1283     FUNC_LOG;
       
  1284     CFSMailMessagePart* result( NULL );
       
  1285     result = iMsgMapper->GetMessagePartL( aMessagePartId.Id(), aMailBoxId,
       
  1286         aMessageId );
       
  1287     return result;
       
  1288 	}
       
  1289 
       
  1290 // ----------------------------------------------------------------------------
       
  1291 // The implementation bypass CImEmailMessage and its email's attachment
       
  1292 // manager. Instead, it calls Symbian framework classes directly by
       
  1293 // accessing the attachment entry.
       
  1294 // ----------------------------------------------------------------------------
       
  1295 TInt CIpsPlgSosBasePlugin::GetMessagePartFileL(
       
  1296     const TFSMailMsgId& /* aMailBoxId */,
       
  1297     const TFSMailMsgId& /* aParentFolderId */,
       
  1298     const TFSMailMsgId& /* aMessageId */,
       
  1299     const TFSMailMsgId& aMessagePartId,
       
  1300     RFile& aFileHandle)
       
  1301 	{
       
  1302     FUNC_LOG;
       
  1303     TInt status( KErrNone );
       
  1304     CMsvEntry* cEntry = iSession->GetEntryL( aMessagePartId.Id() );
       
  1305     CleanupStack::PushL( cEntry );
       
  1306     CMsvStore* store = NULL;
       
  1307     TBool hasStore = cEntry->HasStoreL();
       
  1308     if ( hasStore )
       
  1309         {
       
  1310         store = cEntry->ReadStoreL();
       
  1311         }
       
  1312 
       
  1313     if ( !store || !hasStore )
       
  1314         {
       
  1315         User::Leave( KErrNotFound );
       
  1316         }
       
  1317     CleanupStack::PushL( store );
       
  1318     MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL();
       
  1319 
       
  1320     // It is assumed that the attachment file is always in the index 0
       
  1321     if ( attachmentMgr.AttachmentCount() )
       
  1322         {
       
  1323         aFileHandle = attachmentMgr.GetAttachmentFileL( 0 );
       
  1324         }
       
  1325     else
       
  1326         {
       
  1327         User::Leave( KErrNotFound );
       
  1328         }
       
  1329     CleanupStack::PopAndDestroy( store );
       
  1330     CleanupStack::PopAndDestroy( cEntry );
       
  1331 	return status;
       
  1332     }
       
  1333 
       
  1334 // ----------------------------------------------------------------------------
       
  1335 // ----------------------------------------------------------------------------
       
  1336 //
       
  1337 void CIpsPlgSosBasePlugin::CopyMessagePartFileL(
       
  1338     const TFSMailMsgId& /* aMailBoxId */,
       
  1339     const TFSMailMsgId& /* aParentFolderId */,
       
  1340     const TFSMailMsgId& aMessageId,
       
  1341     const TFSMailMsgId& aMessagePartId,
       
  1342     const TDesC& aFilePath)
       
  1343 	{
       
  1344     FUNC_LOG;
       
  1345     CMsvEntry* cEntry( NULL );
       
  1346     CImEmailMessage* message( NULL );
       
  1347 
       
  1348     CFileMan* fileMgr = CFileMan::NewL( iSession->FileSession() );
       
  1349     CleanupStack::PushL( fileMgr );
       
  1350 
       
  1351     // We trust that the message ID really refers to a message
       
  1352     GetMessageEntryL( aMessageId.Id(), cEntry, message );
       
  1353 
       
  1354     // Without this e.g. alternative body iCal parts are not found
       
  1355     message->GetAttachmentsListL( aMessageId.Id(),
       
  1356         CImEmailMessage::EAllAttachments,
       
  1357         CImEmailMessage::EThisMessageAndEmbeddedMessages );
       
  1358     MMsvAttachmentManager& attachmentMgr( message->AttachmentManager() );
       
  1359     // It is assumed that the attachment ID is same as the corresponding
       
  1360     // entry ID
       
  1361     RFile attachmentFile = attachmentMgr.GetAttachmentFileL(
       
  1362         (TMsvAttachmentId) aMessagePartId.Id() );
       
  1363 
       
  1364     // Overwrites the target file if such exists
       
  1365     // There is no other way to report errors than leave
       
  1366     User::LeaveIfError( fileMgr->Copy( attachmentFile, aFilePath ) );
       
  1367 
       
  1368     attachmentFile.Close();
       
  1369     CleanupStack::PopAndDestroy( fileMgr );
       
  1370 	}
       
  1371 
       
  1372 // ----------------------------------------------------------------------------
       
  1373 // The method supports only reading of the plain text body currently.
       
  1374 // ----------------------------------------------------------------------------
       
  1375 void CIpsPlgSosBasePlugin::GetContentToBufferL(
       
  1376     const TFSMailMsgId& /* aMailBoxId */,
       
  1377     const TFSMailMsgId& /* aParentFolderId */,
       
  1378     const TFSMailMsgId& aMessageId,
       
  1379     const TFSMailMsgId& aMessagePartId,
       
  1380     TDes& aBuffer,
       
  1381     const TUint aStartOffset)
       
  1382 	{
       
  1383     FUNC_LOG;
       
  1384     CMsvEntry* cEntry( NULL );
       
  1385     CImEmailMessage* message( NULL );
       
  1386 
       
  1387     // We trust that the message ID really refers to a message
       
  1388     GetMessageEntryL( aMessageId.Id(), cEntry, message );
       
  1389     if ( message )
       
  1390         {
       
  1391     message->GetBodyTextEntryIdL(
       
  1392         cEntry->Entry().Id(), CImEmailMessage::EThisMessageOnly );
       
  1393 
       
  1394     if ( message->Selection().Count() > 0 )
       
  1395         {
       
  1396         // Check whether the body text is requested
       
  1397         if ( message->Selection()[0] == aMessagePartId.Id() )
       
  1398             {
       
  1399             CParaFormatLayer* globalParaLayer = CParaFormatLayer::NewL();
       
  1400             CleanupStack::PushL(globalParaLayer);
       
  1401             CCharFormatLayer* globalCharLayer = CCharFormatLayer::NewL();
       
  1402             CleanupStack::PushL(globalCharLayer);
       
  1403 
       
  1404             CRichText* bodyText = CRichText::NewL(
       
  1405                 globalParaLayer, globalCharLayer);
       
  1406             CleanupStack::PushL( bodyText );
       
  1407 
       
  1408             message->GetBodyTextL(
       
  1409                 aMessageId.Id(), CImEmailMessage::EThisMessageOnly,
       
  1410                 *bodyText, *globalParaLayer, *globalCharLayer );
       
  1411 
       
  1412             bodyText->Extract( aBuffer, aStartOffset, aBuffer.MaxLength() );
       
  1413 
       
  1414             CleanupStack::PopAndDestroy(bodyText);
       
  1415             CleanupStack::PopAndDestroy(globalCharLayer);
       
  1416             CleanupStack::PopAndDestroy(globalParaLayer);
       
  1417             }
       
  1418         }
       
  1419 	}
       
  1420 	}
       
  1421 
       
  1422 // ----------------------------------------------------------------------------
       
  1423 // ----------------------------------------------------------------------------
       
  1424 void CIpsPlgSosBasePlugin::SetContentL(
       
  1425     const TDesC& aBuffer,
       
  1426     const TFSMailMsgId& /* aMailBoxId */,
       
  1427     const TFSMailMsgId& /* aParentFolderId */,
       
  1428     const TFSMailMsgId& aMessageId,
       
  1429     const TFSMailMsgId& aMessagePartId )
       
  1430 	{
       
  1431     FUNC_LOG;
       
  1432     CMsvEntry* cEntry( NULL );
       
  1433     CImEmailMessage* message( NULL );
       
  1434 
       
  1435     // We trust that the message ID really refers to a message
       
  1436     GetMessageEntryL( aMessageId.Id(), cEntry, message );
       
  1437 	if ( message )
       
  1438 	    {
       
  1439 
       
  1440 	    message->GetBodyTextEntryIdL(
       
  1441 	    		cEntry->Entry().Id(), CImEmailMessage::EThisMessageOnly );
       
  1442 	    if ( message->Selection().Count() > 0 )
       
  1443 	    	{
       
  1444 	    	TMsvId dummy;
       
  1445 	    	TMsvEmailEntry newEmailMsg;
       
  1446 	    	iSession->GetEntry( aMessageId.Id(), dummy, newEmailMsg );
       
  1447 	    	TMsvId parent = newEmailMsg.Parent();
       
  1448 
       
  1449 	    	if ( message->Selection()[0] == aMessagePartId.Id() ||
       
  1450 	    		 newEmailMsg.ICalendar() )
       
  1451 	    		{
       
  1452 	    		CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC( );
       
  1453 	    		CParaFormatLayer* globalParaLayer = CParaFormatLayer::NewL();
       
  1454 	    		CleanupStack::PushL(globalParaLayer);
       
  1455 	    		CCharFormatLayer* globalCharLayer = CCharFormatLayer::NewL();
       
  1456 	    		CleanupStack::PushL(globalCharLayer);
       
  1457 	    		CRichText* text = CRichText::NewL( globalParaLayer, globalCharLayer );
       
  1458 	    		CleanupStack::PushL( text );
       
  1459 	    		// insert text
       
  1460 	    		text->InsertL(0, aBuffer );
       
  1461 	    		// synchronously
       
  1462 	    		message->StoreBodyTextL(
       
  1463 	    				cEntry->Entry().Id(), *text ,wait->iStatus );
       
  1464 	    		wait->Start();
       
  1465 	    		CleanupStack::PopAndDestroy( 4, wait );
       
  1466 	    		}
       
  1467 	    	}
       
  1468 	    }
       
  1469 	}
       
  1470 
       
  1471 // ----------------------------------------------------------------------------
       
  1472 // ----------------------------------------------------------------------------
       
  1473 void CIpsPlgSosBasePlugin::RemovePartContentL(
       
  1474     const TFSMailMsgId& /* aMailBoxId */,
       
  1475     const TFSMailMsgId& /* aParentFolderId */,
       
  1476     const TFSMailMsgId& /* aMessageId */,
       
  1477     const RArray<TFSMailMsgId>& aPartIds )
       
  1478     {
       
  1479     TInt count( aPartIds.Count() );
       
  1480 
       
  1481     for( TInt i(0); i < count; i++ )
       
  1482         {
       
  1483         CMsvEntry* cEntry = iSession->GetEntryL( aPartIds[i].Id() );
       
  1484         CleanupStack::PushL( cEntry );
       
  1485         CMsvStore* store = NULL;
       
  1486         TBool hasStore = cEntry->HasStoreL();
       
  1487         if ( hasStore )
       
  1488             {
       
  1489             store = cEntry->EditStoreL();
       
  1490             }
       
  1491 
       
  1492         if ( !store || !hasStore )
       
  1493             {
       
  1494             User::Leave( KErrNotFound );
       
  1495             }
       
  1496         CleanupStack::PushL( store );
       
  1497         MMsvAttachmentManager& attachmentMgr = store->AttachmentManagerL();
       
  1498 
       
  1499         // It is assumed that the attachment file is always in the index 0
       
  1500         if ( attachmentMgr.AttachmentCount() )
       
  1501             {
       
  1502             // delete attachment file
       
  1503             CIpsPlgOperationWait* waiter = CIpsPlgOperationWait::NewLC();
       
  1504             attachmentMgr.RemoveAttachmentL( 0, waiter->iStatus );
       
  1505             waiter->Start();
       
  1506             CleanupStack::PopAndDestroy( waiter );
       
  1507             store->CommitL();
       
  1508 
       
  1509             // clear complete flag
       
  1510             TMsvEntry tEntry( cEntry->Entry() );
       
  1511             tEntry.SetComplete( EFalse );
       
  1512 
       
  1513             waiter = CIpsPlgOperationWait::NewLC();
       
  1514             CMsvOperation* ops = cEntry->ChangeL( tEntry, waiter->iStatus );
       
  1515             CleanupStack::PushL( ops );
       
  1516             waiter->Start();
       
  1517             CleanupStack::PopAndDestroy( 2, waiter );
       
  1518             }
       
  1519         else
       
  1520             {
       
  1521             User::Leave( KErrNotFound );
       
  1522             }
       
  1523         CleanupStack::PopAndDestroy( store );
       
  1524         CleanupStack::PopAndDestroy( cEntry );
       
  1525         }
       
  1526     }
       
  1527 
       
  1528 // ----------------------------------------------------------------------------
       
  1529 // ----------------------------------------------------------------------------
       
  1530 void CIpsPlgSosBasePlugin::SetPartContentFromFileL(
       
  1531     const TFSMailMsgId& /* aMailBoxId */,
       
  1532     const TFSMailMsgId& /* aParentFolderId */,
       
  1533     const TFSMailMsgId& /* aMessageId */,
       
  1534     const TFSMailMsgId& /* aMessagePartId */,
       
  1535     const TDesC& /* aFilePath */)
       
  1536     {
       
  1537     }
       
  1538 
       
  1539 // ----------------------------------------------------------------------------
       
  1540 // ----------------------------------------------------------------------------
       
  1541 void CIpsPlgSosBasePlugin::StoreMessagePartL(
       
  1542     const TFSMailMsgId& /* aMailBoxId */,
       
  1543     const TFSMailMsgId& /* aParentFolderId */,
       
  1544     const TFSMailMsgId& /* aMessageId */,
       
  1545     CFSMailMessagePart& /* aMessagePart */)
       
  1546     {
       
  1547     }
       
  1548 
       
  1549 // ----------------------------------------------------------------------------
       
  1550 // ----------------------------------------------------------------------------
       
  1551 void CIpsPlgSosBasePlugin::UnregisterRequestObserver( TInt /* aRequestId */)
       
  1552     {
       
  1553     }
       
  1554 
       
  1555 // ----------------------------------------------------------------------------
       
  1556 // ----------------------------------------------------------------------------
       
  1557 void CIpsPlgSosBasePlugin::SendL(TFSMailMsgId aMessageId )
       
  1558  	{
       
  1559     FUNC_LOG;
       
  1560  	CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
       
  1561  	CleanupStack::PushL(watcher);
       
  1562     CIpsPlgSmtpOperation* op = CIpsPlgSmtpOperation::NewLC(
       
  1563         *iSession, CActive::EPriorityStandard, watcher->iStatus, ETrue );
       
  1564     watcher->SetOperation(op);
       
  1565     CleanupStack::Pop( op ); // op added as member of watcher
       
  1566     op->StartSendL( aMessageId.Id() );
       
  1567     iOperations.AppendL(watcher);
       
  1568     CleanupStack::Pop( watcher );
       
  1569  	}
       
  1570 
       
  1571 // ----------------------------------------------------------------------------
       
  1572 // ----------------------------------------------------------------------------
       
  1573 void CIpsPlgSosBasePlugin::SendMessageL( CFSMailMessage& aMessage )
       
  1574     {
       
  1575     FUNC_LOG;
       
  1576     // is EFSMsgFlag_CalendarMsg enabled,
       
  1577     // then move send to back ground process
       
  1578     if ( aMessage.GetFlags() & EFSMsgFlag_CalendarMsg )
       
  1579         {
       
  1580         iEventHandler->SetNewPropertyEvent(
       
  1581                 aMessage.GetMessageId().Id(),
       
  1582                 KIPSSosSmtpEmptyOutboxNow, KErrNone );
       
  1583         }
       
  1584     else
       
  1585         {
       
  1586         SendL( aMessage.GetMessageId() );
       
  1587         }
       
  1588     }
       
  1589 
       
  1590 // ----------------------------------------------------------------------------
       
  1591 // ----------------------------------------------------------------------------
       
  1592 TFSProgress CIpsPlgSosBasePlugin::StatusL( TInt aRequestId )
       
  1593 	{
       
  1594     FUNC_LOG;
       
  1595 	TFSProgress status;
       
  1596 	status.iProgressStatus = TFSProgress::EFSStatus_RequestComplete;
       
  1597 	for ( TInt i = 0; i < iOperations.Count(); i++ )
       
  1598         {
       
  1599         const CIpsPlgBaseOperation* op = iOperations[i]->BaseOperation();
       
  1600         if ( op && op->FSRequestId() == aRequestId )
       
  1601             {
       
  1602             status = op->GetFSProgressL();
       
  1603             }
       
  1604         }
       
  1605 	return status;
       
  1606 	}
       
  1607 
       
  1608 // ----------------------------------------------------------------------------
       
  1609 // ----------------------------------------------------------------------------
       
  1610 void CIpsPlgSosBasePlugin::CancelL(TInt aRequestId)
       
  1611 	{
       
  1612     FUNC_LOG;
       
  1613 	const TInt count = iOperations.Count();
       
  1614     for ( TInt i = count-1; i >= 0; i-- )
       
  1615         {
       
  1616         const CIpsPlgBaseOperation* oper = iOperations[i]->BaseOperation();
       
  1617         // all Fs operations are derived from ips base operation
       
  1618         if ( oper && oper->FSRequestId() == aRequestId )
       
  1619             {
       
  1620             DeleteAndRemoveOperation( i, KErrCancel );
       
  1621             break;
       
  1622             }
       
  1623         }
       
  1624 	}
       
  1625 
       
  1626 // ----------------------------------------------------------------------------
       
  1627 // ----------------------------------------------------------------------------
       
  1628 void CIpsPlgSosBasePlugin::SearchL(
       
  1629     const TFSMailMsgId& aMailBoxId,
       
  1630     const RArray<TFSMailMsgId>& aFolderIds,
       
  1631     const RPointerArray<TDesC>& aSearchStrings,
       
  1632     const TFSMailSortCriteria& aSortCriteria,
       
  1633     MFSMailBoxSearchObserver& aSearchObserver )
       
  1634     {
       
  1635     FUNC_LOG;
       
  1636 	iSearch->SearchL(
       
  1637 	    aMailBoxId,
       
  1638 	    aFolderIds,
       
  1639 	    aSearchStrings,
       
  1640 	    aSortCriteria,
       
  1641 	    aSearchObserver );
       
  1642 	}
       
  1643 
       
  1644 // ----------------------------------------------------------------------------
       
  1645 // ----------------------------------------------------------------------------
       
  1646 void CIpsPlgSosBasePlugin::CancelSearch( const TFSMailMsgId& /* aMailBoxId */ )
       
  1647 	{
       
  1648     FUNC_LOG;
       
  1649 	iSearch->Cancel();
       
  1650 	}
       
  1651 
       
  1652 // ----------------------------------------------------------------------------
       
  1653 // ----------------------------------------------------------------------------
       
  1654 void CIpsPlgSosBasePlugin::ClearSearchResultCache(
       
  1655     const TFSMailMsgId& /* aMailBoxId */ )
       
  1656 	{
       
  1657     FUNC_LOG;
       
  1658 	iSearch->ClearCache();
       
  1659 	}
       
  1660 
       
  1661 // ----------------------------------------------------------------------------
       
  1662 // ----------------------------------------------------------------------------
       
  1663 void CIpsPlgSosBasePlugin::AddObserverL(MFSMailEventObserver& aObserver)
       
  1664 	{
       
  1665     FUNC_LOG;
       
  1666 	iEventHandler->AddPluginObserverL( &aObserver );
       
  1667 	}
       
  1668 
       
  1669 // ----------------------------------------------------------------------------
       
  1670 // ----------------------------------------------------------------------------
       
  1671 void CIpsPlgSosBasePlugin::RemoveObserver(MFSMailEventObserver& aObserver)
       
  1672 	{
       
  1673 	//don't delete. we don't own this.
       
  1674 	iEventHandler->RemovePluginObserver( &aObserver );
       
  1675 	}
       
  1676 
       
  1677 // ----------------------------------------------------------------------------
       
  1678 // ----------------------------------------------------------------------------
       
  1679 void CIpsPlgSosBasePlugin::DeleteMessagesByUidL(
       
  1680     const TFSMailMsgId& /*aMailBoxId*/,
       
  1681     const TFSMailMsgId& /*aFolderId*/,
       
  1682 	const RArray<TFSMailMsgId>& aMessages )
       
  1683     {
       
  1684     FUNC_LOG;
       
  1685     CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
       
  1686     CleanupStack::PushL(sel);
       
  1687 
       
  1688     TInt count = aMessages.Count();
       
  1689     TMsvEntry tEntry;
       
  1690     TMsvId service;
       
  1691 
       
  1692     TMsvEntry parentEntry;
       
  1693 
       
  1694     for(TInt i=0; i<count; i++)
       
  1695         {
       
  1696         iSession->GetEntry( aMessages[i].Id(), service, tEntry );
       
  1697 
       
  1698         //make sure that only messages get deleted.
       
  1699         if( tEntry.iType == KUidMsvMessageEntry )
       
  1700             {
       
  1701             iSession->GetEntry( tEntry.Parent( ), service, parentEntry );
       
  1702 
       
  1703             CMsvEntry *cEntry = CMsvEntry::NewL(
       
  1704                         *iSession, tEntry.Id(), TMsvSelectionOrdering() );
       
  1705             CleanupStack::PushL( cEntry );
       
  1706             CIpsPlgOperationWait* wait = CIpsPlgOperationWait::NewLC( );
       
  1707             // Sets bit 32 of iMtmData1, used when msg deleted in Offline
       
  1708             // and status hasn't updated to server (client entry still exists)
       
  1709             tEntry.SetLocallyDeleted( ETrue );
       
  1710             CMsvOperation* msvOp = cEntry->ChangeL( tEntry, wait->iStatus );
       
  1711             CleanupStack::PushL(msvOp);
       
  1712             wait->Start();
       
  1713             sel->AppendL( tEntry.Id() );
       
  1714             CleanupStack::PopAndDestroy( 3, cEntry );
       
  1715             }
       
  1716         }
       
  1717 
       
  1718     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL( *this );
       
  1719     CleanupStack::PushL( watcher );
       
  1720     CMsvOperation* op = CIpsPlgDeleteRemote::NewL( *iSession,
       
  1721         watcher->iStatus, *sel );
       
  1722     watcher->SetOperation( op );
       
  1723 
       
  1724     // make draft deletion synchronous so that empty drafts are not left after application close
       
  1725     if ( parentEntry.Id() == KMsvDraftEntryIdValue && count == 1 )
       
  1726         {
       
  1727         iWait.Start();
       
  1728         CleanupStack::PopAndDestroy( watcher );
       
  1729         }
       
  1730     else
       
  1731         {
       
  1732         iOperations.AppendL( watcher );
       
  1733         CleanupStack::Pop( watcher );
       
  1734         }
       
  1735 
       
  1736     CleanupStack::PopAndDestroy( sel );
       
  1737     }
       
  1738 
       
  1739 // ----------------------------------------------------------------------------
       
  1740 // ----------------------------------------------------------------------------
       
  1741 void CIpsPlgSosBasePlugin::SubscribeMailboxEventsL(
       
  1742     const TFSMailMsgId& aMailboxId,
       
  1743     MFSMailEventObserver& aObserver)
       
  1744     {
       
  1745     FUNC_LOG;
       
  1746     TUint32 key = iSettingsApi->CreateCenRepKeyL(   // faulty CS warning
       
  1747         aMailboxId.Id(),
       
  1748         MtmId(),
       
  1749         CIpsSetDataStorer::EIpsSetDataLastModifiedH );
       
  1750 
       
  1751     iEventHandler->SubscribeMailboxEventsL( aMailboxId, aObserver, key );
       
  1752     }
       
  1753 
       
  1754 // ----------------------------------------------------------------------------
       
  1755 // ----------------------------------------------------------------------------
       
  1756 void CIpsPlgSosBasePlugin::UnsubscribeMailboxEvents(
       
  1757     const TFSMailMsgId& aMailboxId,
       
  1758     MFSMailEventObserver& aObserver)
       
  1759     {
       
  1760     FUNC_LOG;
       
  1761     iEventHandler->UnsubscribeMailboxEvents( aMailboxId, aObserver );
       
  1762     }
       
  1763 
       
  1764 // ----------------------------------------------------------------------------
       
  1765 // ----------------------------------------------------------------------------
       
  1766 TSSMailSyncState CIpsPlgSosBasePlugin::CurrentSyncState(
       
  1767     const TFSMailMsgId& aMailBoxId )
       
  1768     {
       
  1769     FUNC_LOG;
       
  1770     return iSyncStateHandler->GetCurrentSyncState( aMailBoxId );
       
  1771     }
       
  1772 
       
  1773 // ----------------------------------------------------------------------------
       
  1774 // ----------------------------------------------------------------------------
       
  1775 TInt CIpsPlgSosBasePlugin::WizardDataAvailableL( )
       
  1776     {
       
  1777     FUNC_LOG;
       
  1778     TInt error = KErrNone;
       
  1779     error = iSettingsApi->HandleMailboxCreation( MtmId(), *iSession );
       
  1780     if ( error == KErrNotSupported )
       
  1781         {
       
  1782         // this means that wizard data is not meaned for this plugin (instance)
       
  1783         // just return KErrNone at the moment
       
  1784         return KErrNone;
       
  1785         }
       
  1786     return error;
       
  1787     }
       
  1788 
       
  1789 // ----------------------------------------------------------------------------
       
  1790 // ----------------------------------------------------------------------------
       
  1791 TInt CIpsPlgSosBasePlugin::GetConnectionId(
       
  1792         TFSMailMsgId /*aMailBoxId*/,
       
  1793         TUint32& /*aConnectionId*/ )
       
  1794     {
       
  1795     return KErrNotSupported;
       
  1796     }
       
  1797 
       
  1798 // ----------------------------------------------------------------------------
       
  1799 // ----------------------------------------------------------------------------
       
  1800 TInt CIpsPlgSosBasePlugin::IsConnectionAllowedWhenRoaming(
       
  1801              TFSMailMsgId /*aMailBoxId*/,
       
  1802              TBool& /*aConnectionAllowed*/ )
       
  1803     {
       
  1804     return KErrNotSupported;
       
  1805     }
       
  1806 
       
  1807 // ----------------------------------------------------------------------------
       
  1808 // The method is not relevant for the Symbian based implementation
       
  1809 // ----------------------------------------------------------------------------
       
  1810 void CIpsPlgSosBasePlugin::AuthenticateL(
       
  1811     MFSMailRequestObserver& /* aOperationObserver */,
       
  1812     TInt /* aRequestId */)
       
  1813     {
       
  1814     }
       
  1815 
       
  1816 // ----------------------------------------------------------------------------
       
  1817 // method sets authentication popup data
       
  1818 // ----------------------------------------------------------------------------
       
  1819 void CIpsPlgSosBasePlugin::SetCredentialsL( const TFSMailMsgId& aMailBoxId,
       
  1820 	const TDesC& /*aUsername*/, const TDesC& aPassword )
       
  1821 	{
       
  1822     FUNC_LOG;
       
  1823 	TBool cancelled = EFalse;
       
  1824 
       
  1825 	if ( aPassword.Length() > 0 )
       
  1826 	    {
       
  1827     	//Set new password and signal (possible) ongoing connect operation
       
  1828     	CIpsSetDataApi* api = CIpsSetDataApi::NewL( *iSession );
       
  1829         CleanupStack::PushL( api );
       
  1830 
       
  1831         CMsvEntry* cEntry = iSession->GetEntryL( aMailBoxId.Id() );
       
  1832         CleanupStack::PushL( cEntry );
       
  1833 
       
  1834         api->SetNewPasswordL( *cEntry, aPassword );
       
  1835 
       
  1836         CleanupStack::PopAndDestroy( 2, api );//cEntry, api
       
  1837 
       
  1838         //now signal through eventhandler that credientials have been set
       
  1839 	    }
       
  1840 	else
       
  1841 	    {
       
  1842 	    cancelled = ETrue;
       
  1843 	    }
       
  1844 	iEventHandler->SignalCredientialsSetL( aMailBoxId.Id(), cancelled );
       
  1845 	}
       
  1846 
       
  1847 // ----------------------------------------------------------------------------
       
  1848 // CIpsPlgSosBasePlugin::GetMessageEntryL( )
       
  1849 // Checks whether the requested message is already cached. If not, the cached
       
  1850 // objects are deleted and new objects are created.
       
  1851 // ----------------------------------------------------------------------------
       
  1852 void CIpsPlgSosBasePlugin::GetMessageEntryL(
       
  1853     TMsvId aId,
       
  1854     CMsvEntry*& aMessageEntry,
       
  1855     CImEmailMessage*& aImEmailMessage )
       
  1856     {
       
  1857     FUNC_LOG;
       
  1858     if ( !iCachedEntry || ( aId != iCachedEntry->Entry().Id() ) ||
       
  1859             iCachedEmailMessage->IsActive() )
       
  1860         {
       
  1861         CleanCachedMessageEntries();
       
  1862 
       
  1863         iCachedEntry = iSession->GetEntryL( aId );
       
  1864         if ( iCachedEntry->Entry().iType == KUidMsvMessageEntry )
       
  1865             {
       
  1866             iCachedEmailMessage = CImEmailMessage::NewL( *iCachedEntry );
       
  1867             }
       
  1868         }
       
  1869     aMessageEntry = iCachedEntry;
       
  1870     aImEmailMessage = iCachedEmailMessage;
       
  1871     }
       
  1872 
       
  1873 // ----------------------------------------------------------------------------
       
  1874 // ----------------------------------------------------------------------------
       
  1875 //
       
  1876 void CIpsPlgSosBasePlugin::CleanCachedMessageEntries()
       
  1877     {
       
  1878     FUNC_LOG;
       
  1879     delete iCachedEmailMessage;
       
  1880     iCachedEmailMessage = NULL;
       
  1881     delete iCachedEntry;
       
  1882     iCachedEntry = NULL;
       
  1883     }
       
  1884 
       
  1885 // ----------------------------------------------------------------------------
       
  1886 // ----------------------------------------------------------------------------
       
  1887 TFSFolderType CIpsPlgSosBasePlugin::GetFolderType(
       
  1888     CMsvEntry* aEntry,
       
  1889     TFSMailMsgId aFolderId )
       
  1890 	{
       
  1891     FUNC_LOG;
       
  1892     TFSFolderType folderType( EFSOther );
       
  1893 
       
  1894 	if( ( aEntry->Entry().iDetails.CompareF( KIpsPlgInbox ) == 0 ) &&
       
  1895 		( aEntry->Entry().iType == KUidMsvFolderEntry ) )
       
  1896         {
       
  1897         folderType = EFSInbox;
       
  1898         }
       
  1899 	else if( ( aEntry->Entry().iMtm == KSenduiMtmPop3Uid ) &&
       
  1900 	         ( aEntry->Entry().iType == KUidMsvServiceEntry ) &&
       
  1901 	         ( aEntry->Entry().iServiceId == aFolderId.Id() ) )
       
  1902 	    {
       
  1903 	    folderType = EFSInbox;
       
  1904         }
       
  1905     else if( aFolderId.Id() == KMsvGlobalOutBoxIndexEntryId )
       
  1906         {
       
  1907         folderType = EFSOutbox;
       
  1908         }
       
  1909     else if( aFolderId.Id() == KMsvDraftEntryId )
       
  1910         {
       
  1911         folderType = EFSDraftsFolder;
       
  1912         }
       
  1913     else if( aFolderId.Id() == KMsvSentEntryId )
       
  1914         {
       
  1915         folderType = EFSSentFolder;
       
  1916         }
       
  1917     else if( aFolderId.Id() == KMsvDeletedEntryFolderEntryId )
       
  1918         {
       
  1919         folderType = EFSDeleted;
       
  1920         }
       
  1921     else if( aFolderId.Id() == KMsvUnknownServiceIndexEntryId )
       
  1922         {
       
  1923         folderType = EFSOther;
       
  1924         }
       
  1925     return folderType;
       
  1926 	}
       
  1927 
       
  1928 // ----------------------------------------------------------------------------
       
  1929 // ----------------------------------------------------------------------------
       
  1930 CIpsPlgTimerOperation& CIpsPlgSosBasePlugin::ActivityTimerL(
       
  1931     const TFSMailMsgId& aMailBoxId )
       
  1932     {
       
  1933     FUNC_LOG;
       
  1934     CIpsPlgTimerOperation* timer=NULL;
       
  1935     for ( TInt i = 0; i < iActivitytimers.Count(); i++ )
       
  1936         {
       
  1937         if ( iActivitytimers[i]->FSMailboxId().Id() == aMailBoxId.Id() )
       
  1938             {
       
  1939             timer = iActivitytimers[i];
       
  1940             }
       
  1941         }
       
  1942 
       
  1943     if ( !timer )
       
  1944         {
       
  1945         // No timer for mailbox found create new
       
  1946         timer = CIpsPlgTimerOperation::NewL( aMailBoxId, *this );
       
  1947         CleanupStack::PushL( timer );
       
  1948         User::LeaveIfError( iActivitytimers.Append( timer ) );
       
  1949         CleanupStack::Pop( timer );
       
  1950         }
       
  1951     return *timer;
       
  1952     }
       
  1953 
       
  1954 // ----------------------------------------------------------------------------
       
  1955 // ----------------------------------------------------------------------------
       
  1956 CIpsPlgSyncStateHandler& CIpsPlgSosBasePlugin::GetSyncStateHandler()
       
  1957     {
       
  1958     return *iSyncStateHandler;
       
  1959     }
       
  1960 
       
  1961 // ----------------------------------------------------------------------------
       
  1962 // ----------------------------------------------------------------------------
       
  1963 void CIpsPlgSosBasePlugin::CancelAllOnlineOperations(
       
  1964     const TFSMailMsgId& aMailboxId )
       
  1965     {
       
  1966     FUNC_LOG;
       
  1967     // cancel all ongoing operations
       
  1968     for ( TInt i = iOperations.Count()-1; i >= 0; i-- )
       
  1969         {
       
  1970         const CIpsPlgBaseOperation* baseOp = iOperations[i]->BaseOperation();
       
  1971         if ( baseOp && baseOp->FSMailboxId() == aMailboxId )
       
  1972             {
       
  1973             delete iOperations[i];
       
  1974             iOperations.Remove(i);
       
  1975             }
       
  1976         }
       
  1977     }
       
  1978 
       
  1979 // ---------------------------------------------------------------------------
       
  1980 // ---------------------------------------------------------------------------
       
  1981 void CIpsPlgSosBasePlugin::DeleteAndRemoveOperation(
       
  1982         const TInt aOpArrayIndex, TInt aCompleteCode )
       
  1983     {
       
  1984     FUNC_LOG;
       
  1985     CIpsPlgSingleOpWatcher* opWatcher = iOperations[aOpArrayIndex];
       
  1986 
       
  1987     // The operations matches, handle it in protocol plugin...if needed.
       
  1988     TRAP_IGNORE( HandleOpCompletedL( *opWatcher, aCompleteCode ) );
       
  1989 
       
  1990     const CIpsPlgBaseOperation* op = opWatcher->BaseOperation();
       
  1991     TMsvId service = KErrNotFound;
       
  1992     TUint pluginId = PluginId();
       
  1993     if ( op && (
       
  1994             op->IpsOpType() == EIpsOpTypeImap4SyncOp  ||
       
  1995              op->IpsOpType() == EIpsOpTypePop3SyncOp ||
       
  1996              op->IpsOpType() == EIpsOpTypeImap4PopulateOp ) )
       
  1997         {
       
  1998         service = op->Service();
       
  1999         }
       
  2000     iOperations.Remove( aOpArrayIndex );
       
  2001     delete opWatcher;
       
  2002     opWatcher = NULL;
       
  2003     // need to remove operation first because after signaling
       
  2004     // sync complete mailbox status is asked immediatelly
       
  2005     // and function checks connects ops also (see GetMailBoxStatus)
       
  2006     if ( service != KErrNotFound )
       
  2007         {
       
  2008         iEventHandler->SetNewPropertyEvent(
       
  2009                 service, KIpsSosEmailSyncCompleted, aCompleteCode );
       
  2010         }
       
  2011     }
       
  2012 
       
  2013 // ---------------------------------------------------------------------------
       
  2014 // ---------------------------------------------------------------------------
       
  2015 void CIpsPlgSosBasePlugin::DisconnectL(
       
  2016     const TFSMailMsgId& aMailBoxId,
       
  2017     MFSMailRequestObserver& aObserver,
       
  2018     const TInt aRequestId,
       
  2019     TBool aRemoveAccountAlso )
       
  2020     {
       
  2021     FUNC_LOG;
       
  2022     TMsvId service = aMailBoxId.Id();
       
  2023     TMsvEntry tEntry;
       
  2024     TMsvId serv;
       
  2025     iSession->GetEntry( service, serv, tEntry );
       
  2026 
       
  2027     if ( tEntry.Connected() )
       
  2028         {
       
  2029         CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
       
  2030         CleanupStack::PushL( watcher );
       
  2031 
       
  2032         TBuf8<1> dummyParams;
       
  2033         dummyParams.Zero();
       
  2034         CMsvEntrySelection* sel=new(ELeave) CMsvEntrySelection;
       
  2035         CleanupStack::PushL(sel);
       
  2036 
       
  2037         sel->AppendL( service );
       
  2038 
       
  2039         CIpsPlgBaseOperation* op = CIpsPlgDisconnectOp::NewL( *iSession,
       
  2040             watcher->iStatus, service, ActivityTimerL( aMailBoxId ),
       
  2041             aMailBoxId, aObserver, aRequestId,
       
  2042             aRemoveAccountAlso );
       
  2043 
       
  2044         watcher->SetOperation( op );
       
  2045         CleanupStack::PopAndDestroy( sel );
       
  2046         iOperations.AppendL( watcher );
       
  2047         CleanupStack::Pop( watcher );
       
  2048         }
       
  2049     }
       
  2050 
       
  2051 // ----------------------------------------------------------------------------
       
  2052 // ----------------------------------------------------------------------------
       
  2053 void CIpsPlgSosBasePlugin::HandleTimerFiredL( const TFSMailMsgId& aMailboxId )
       
  2054     {
       
  2055     FUNC_LOG;
       
  2056     for ( TInt i = 0; i < iActivitytimers.Count(); i++ )
       
  2057         {
       
  2058         // do not disconnect automatically mailboxes that are set to
       
  2059         // "connected"
       
  2060         if ( iActivitytimers[i]->FSMailboxId().Id() == aMailboxId.Id() )
       
  2061             {
       
  2062             // 0 for request id
       
  2063             DisconnectL( iActivitytimers[i]->FSMailboxId(), *this, 0 );
       
  2064             }
       
  2065         }
       
  2066     }
       
  2067 
       
  2068 // ---------------------------------------------------------------------------
       
  2069 // ---------------------------------------------------------------------------
       
  2070 void CIpsPlgSosBasePlugin::RequestResponseL(
       
  2071     TFSProgress /*aEvent*/,
       
  2072     TInt /*aRequestId*/ )
       
  2073     {
       
  2074     }
       
  2075 
       
  2076 // ---------------------------------------------------------------------------
       
  2077 // ---------------------------------------------------------------------------
       
  2078 void CIpsPlgSosBasePlugin::EmptyOutboxL( const TFSMailMsgId& aMailBoxId )
       
  2079     {
       
  2080     FUNC_LOG;
       
  2081     CIpsPlgSingleOpWatcher* watcher = CIpsPlgSingleOpWatcher::NewL(*this);
       
  2082  	CleanupStack::PushL(watcher);
       
  2083     CIpsPlgSmtpOperation* op = CIpsPlgSmtpOperation::NewLC(
       
  2084         *iSession, CActive::EPriorityStandard, watcher->iStatus, ETrue );
       
  2085     watcher->SetOperation(op);
       
  2086     op->EmptyOutboxFromPendingMessagesL( aMailBoxId.Id() );
       
  2087     iOperations.AppendL(watcher);
       
  2088     CleanupStack::Pop( 2, watcher );
       
  2089     }
       
  2090 
       
  2091 // ---------------------------------------------------------------------------
       
  2092 // ---------------------------------------------------------------------------
       
  2093 TBool CIpsPlgSosBasePlugin::CanConnectL( const TFSMailMsgId& /*aMailboxId*/,
       
  2094     TInt& /*aReason*/ )
       
  2095     {
       
  2096     FUNC_LOG;
       
  2097 #ifdef __WINS__
       
  2098     return ETrue;
       
  2099 #endif
       
  2100     TBool ret=ETrue;
       
  2101     //check offline mode. If set, we can't connect.
       
  2102     ret = !OfflineModeSetL();
       
  2103     if( ret )
       
  2104         {
       
  2105         ret = RoamingCheckL();
       
  2106         }
       
  2107     return ret;
       
  2108     }
       
  2109 
       
  2110 // ---------------------------------------------------------------------------
       
  2111 // ---------------------------------------------------------------------------
       
  2112 TBool CIpsPlgSosBasePlugin::IsUnderUiProcess()
       
  2113     {
       
  2114     return iIsUnderUiProcess;
       
  2115     }
       
  2116 
       
  2117 // ---------------------------------------------------------------------------
       
  2118 // ---------------------------------------------------------------------------
       
  2119 TBool CIpsPlgSosBasePlugin::OfflineModeSetL()
       
  2120     {
       
  2121     FUNC_LOG;
       
  2122     return !LocalFeatureL( KCRUidCoreApplicationUIs,
       
  2123         KCoreAppUIsNetworkConnectionAllowed, 1 );
       
  2124     }
       
  2125 
       
  2126 // ---------------------------------------------------------------------------
       
  2127 // ---------------------------------------------------------------------------
       
  2128 TBool CIpsPlgSosBasePlugin::LocalFeatureL(
       
  2129     const TUid& aCenRepUid,
       
  2130     const TUint32 aKeyId,
       
  2131     const TUint32 aFlag )
       
  2132     {
       
  2133     FUNC_LOG;
       
  2134     // Create the connection to Central Repository
       
  2135     CRepository* cenrep = CRepository::NewLC( aCenRepUid );
       
  2136 
       
  2137     // Fetch the value from the
       
  2138     TInt flags(0);
       
  2139     if ( cenrep )
       
  2140         {
       
  2141         cenrep->Get( aKeyId, flags );
       
  2142         }
       
  2143 
       
  2144     // Remove the connection
       
  2145     CleanupStack::PopAndDestroy( cenrep );
       
  2146     cenrep = NULL;
       
  2147 
       
  2148     // Return the result as a boolean value
       
  2149     return ( flags & aFlag ) == aFlag;
       
  2150     }
       
  2151 
       
  2152 // ---------------------------------------------------------------------------
       
  2153 // ---------------------------------------------------------------------------
       
  2154 TBool CIpsPlgSosBasePlugin::RoamingCheckL()
       
  2155     {
       
  2156     FUNC_LOG;
       
  2157     //first check our registration status
       
  2158     TInt regStatus = RegistrationStatusL();
       
  2159 
       
  2160     if ( regStatus == ENetworkRegistrationHomeNetwork )
       
  2161         {
       
  2162         return ETrue;
       
  2163         }
       
  2164     else if ( regStatus == ENetworkRegistrationRoaming )
       
  2165         {
       
  2166         //we're roaming. by default no auto connect when roaming.
       
  2167         return EFalse;
       
  2168         }
       
  2169     else
       
  2170         {
       
  2171         //other reg status states indicate that we cannot connect
       
  2172         //in any case.
       
  2173         //any different handling needed here?
       
  2174         return EFalse;
       
  2175         }
       
  2176     }
       
  2177 
       
  2178 // ---------------------------------------------------------------------------
       
  2179 // ---------------------------------------------------------------------------
       
  2180 TInt CIpsPlgSosBasePlugin::RegistrationStatusL()
       
  2181     {
       
  2182     FUNC_LOG;
       
  2183     TRequestStatus status;
       
  2184     TInt registrationStatus( 0 );
       
  2185 
       
  2186     //check network status
       
  2187     iConMon.ConnectL();
       
  2188 
       
  2189     iConMon.GetIntAttribute(
       
  2190         EBearerIdGSM, 0, KNetworkRegistration,
       
  2191         registrationStatus, status );
       
  2192 
       
  2193     User::WaitForRequest( status ); // faulty CS warning
       
  2194 
       
  2195     iConMon.Close();
       
  2196 
       
  2197     return registrationStatus;
       
  2198     }
       
  2199 
       
  2200 // ---------------------------------------------------------------------------
       
  2201 // ---------------------------------------------------------------------------
       
  2202 //
       
  2203 void CIpsPlgSosBasePlugin::BlockCopyMoveFromFoldersL(
       
  2204     CMsvEntry* aFolderEntry,
       
  2205     TFSMailMsgId aFolderId,
       
  2206     CFSMailFolder& aFSMailFolder )
       
  2207     {
       
  2208     FUNC_LOG;
       
  2209     // Currently IPS plugin can connect automatically when doing the actual
       
  2210     // move/copy operation, so no need to block offline moves separately
       
  2211     RArray<TFSFolderType> blockFolders;
       
  2212     CleanupClosePushL( blockFolders );
       
  2213 
       
  2214     // Move/Copy operations only between remote folders (+ IMAP Inbox) and
       
  2215     // Outbox -> Drafts, block others.
       
  2216     blockFolders.Reset();
       
  2217 
       
  2218     if( ( GetFolderType( aFolderEntry, aFolderId ) != EFSOther ) &&
       
  2219         ( GetFolderType( aFolderEntry, aFolderId ) != EFSInbox ) )
       
  2220         {
       
  2221         blockFolders.Append( EFSInbox );
       
  2222         blockFolders.Append( EFSOther );
       
  2223         }
       
  2224 
       
  2225     if( GetFolderType( aFolderEntry, aFolderId ) != EFSDraftsFolder )
       
  2226         {
       
  2227         blockFolders.Append( EFSOutbox );
       
  2228         }
       
  2229     blockFolders.Append( EFSSentFolder );
       
  2230     blockFolders.Append( EFSDraftsFolder );
       
  2231     blockFolders.Append( EFSDeleted );
       
  2232 
       
  2233     // Block move/copy to this folder from blocklist, same blocklist
       
  2234     // applies to both online and offline moves/copies
       
  2235     aFSMailFolder.BlockCopyFromL( blockFolders, EFSMailBoxOnline );
       
  2236     aFSMailFolder.BlockMoveFromL( blockFolders, EFSMailBoxOnline );
       
  2237     aFSMailFolder.BlockCopyFromL( blockFolders, EFSMailBoxOffline );
       
  2238     aFSMailFolder.BlockMoveFromL( blockFolders, EFSMailBoxOffline );
       
  2239 
       
  2240     CleanupStack::PopAndDestroy( &blockFolders );
       
  2241     }
       
  2242 
       
  2243 // ---------------------------------------------------------------------------
       
  2244 // ---------------------------------------------------------------------------
       
  2245 void CIpsPlgSosBasePlugin::StoreIMEIToMailboxL( const TMsvId aMailboxId )
       
  2246     {
       
  2247     FUNC_LOG;
       
  2248     CMsvEntry* centry = iSession->GetEntryL( aMailboxId );
       
  2249     CleanupStack::PushL( centry );
       
  2250 
       
  2251     TMsvEntry tentry = centry->Entry();
       
  2252     tentry.iDescription.Set( iIMEI );
       
  2253     centry->ChangeL( tentry );
       
  2254 
       
  2255     CleanupStack::PopAndDestroy( centry );
       
  2256     centry = NULL;
       
  2257     }
       
  2258 
       
  2259 // ---------------------------------------------------------------------------
       
  2260 // ---------------------------------------------------------------------------
       
  2261 TBool CIpsPlgSosBasePlugin::ConnOpRunning( const TFSMailMsgId& aMailBoxId  )
       
  2262     {
       
  2263     FUNC_LOG;
       
  2264     return iSyncStateHandler->ConnOpRunning( aMailBoxId );
       
  2265     }
       
  2266 
       
  2267 // ---------------------------------------------------------------------------
       
  2268 // ---------------------------------------------------------------------------
       
  2269 void CIpsPlgSosBasePlugin::SetMailboxName(
       
  2270         const TFSMailMsgId& aMailboxId,
       
  2271         const TDesC& aMailboxName )
       
  2272     {
       
  2273     FUNC_LOG;
       
  2274     TMsvEntry tEntry;
       
  2275     TMsvId service;
       
  2276     iSession->GetEntry( aMailboxId.Id(), service, tEntry );
       
  2277     TRAP_IGNORE( iSettingsApi->SetMailboxNameL( tEntry, aMailboxName ) );
       
  2278     }
       
  2279 
       
  2280 // ---------------------------------------------------------------------------
       
  2281 // ---------------------------------------------------------------------------
       
  2282 TUid CIpsPlgSosBasePlugin::MtmId() const
       
  2283     {
       
  2284     FUNC_LOG;
       
  2285     TUid ret = KSenduiMtmImap4Uid;
       
  2286     if ( iFSPluginId == KIpsPlgPop3PluginUidValue )
       
  2287         {
       
  2288         ret = KSenduiMtmPop3Uid;
       
  2289         }
       
  2290     return ret;
       
  2291     }
       
  2292 
       
  2293 // ---------------------------------------------------------------------------
       
  2294 // ---------------------------------------------------------------------------
       
  2295 TUint CIpsPlgSosBasePlugin::PluginId() const
       
  2296     {
       
  2297     return iFSPluginId;
       
  2298     }
       
  2299 
       
  2300 // ---------------------------------------------------------------------------
       
  2301 // ---------------------------------------------------------------------------
       
  2302 void CIpsPlgSosBasePlugin::DeleteActivityTimer( const TFSMailMsgId& aMailboxId  )
       
  2303     {
       
  2304     FUNC_LOG;
       
  2305     TInt timerCount = iActivitytimers.Count();
       
  2306     for ( TInt j = 0; j < timerCount; j++ )
       
  2307         {
       
  2308         if ( iActivitytimers[j]->FSMailboxId() == aMailboxId )
       
  2309             {
       
  2310             delete iActivitytimers[j];
       
  2311             iActivitytimers[j] = NULL;
       
  2312             iActivitytimers.Remove( j );
       
  2313             timerCount--;
       
  2314             j--;
       
  2315             }
       
  2316         }
       
  2317     }
       
  2318