emailservices/emailstore/base_plugin/src/basepluginnotifications.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Email interface notification systems implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //<cmail>
       
    21 #include "MsgStore.h"
       
    22 #include "MsgStoreFolder.h"
       
    23 //</cmail>
       
    24 
       
    25 #include "BasePlugin.h"
       
    26 #include "baseplugincommonutils.h"
       
    27 
       
    28 
       
    29 /**
       
    30  *
       
    31  */
       
    32 EXPORT_C void CBasePlugin::SubscribeMailboxEventsL(
       
    33     const TFSMailMsgId& aMailboxId,
       
    34     MFSMailEventObserver& aObserver )
       
    35 
       
    36 	{
       
    37     CMailboxInfo& mailBox = GetMailboxInfoL( aMailboxId.Id() );
       
    38 
       
    39     if ( KErrNotFound == mailBox.iObservers.Find( &aObserver ) )
       
    40         {
       
    41         mailBox.iObservers.AppendL( &aObserver );
       
    42         }
       
    43 	}
       
    44 
       
    45 
       
    46 /**
       
    47  *
       
    48  */
       
    49 EXPORT_C void CBasePlugin::UnsubscribeMailboxEvents(
       
    50     const TFSMailMsgId& aMailboxId,
       
    51     MFSMailEventObserver& aObserver )
       
    52 
       
    53 	{
       
    54 	TRAP_IGNORE( UnsubscribeMailboxEventsL( aMailboxId, aObserver ) );
       
    55 	}
       
    56 
       
    57 
       
    58 /**
       
    59  *
       
    60  */
       
    61 EXPORT_C void CBasePlugin::AddObserverL(
       
    62     MFSMailEventObserver& aObserver )
       
    63     {
       
    64     
       
    65     if ( KErrNotFound == iObservers.Find( &aObserver ) )
       
    66         {
       
    67         iObservers.AppendL( &aObserver );
       
    68         }
       
    69 
       
    70     if ( iObservers.Count() == 1 )
       
    71         {
       
    72         iMsgStore->AddObserverL( this );
       
    73         }
       
    74     }
       
    75 
       
    76 
       
    77 /**
       
    78  *
       
    79  */
       
    80 EXPORT_C void CBasePlugin::RemoveObserver(
       
    81     MFSMailEventObserver& aObserver )
       
    82     {
       
    83 
       
    84     TInt idx = iObservers.Find( &aObserver );
       
    85     
       
    86     if ( KErrNotFound != idx )
       
    87         {
       
    88         iObservers.Remove( idx );
       
    89         }
       
    90         
       
    91     if ( iObservers.Count() == 0 )
       
    92         {
       
    93         TRAP_IGNORE( iMsgStore->RemoveObserverL( this ) );
       
    94         }
       
    95     }
       
    96 
       
    97 
       
    98 /**
       
    99  *
       
   100  */
       
   101 EXPORT_C void CBasePlugin::UnregisterRequestObserver(
       
   102     TInt /*aRequestId*/ )
       
   103     {
       
   104     
       
   105     }
       
   106 
       
   107 
       
   108 #pragma mark -
       
   109 #pragma mark --- MSGSTORE OBSERVERS ---
       
   110 
       
   111 
       
   112 /**
       
   113  *
       
   114  */
       
   115 EXPORT_C void CBasePlugin::SystemEventNotify( TMsgStoreSystemEvent aEvent )
       
   116 	{
       
   117 	TRAP_IGNORE( SystemEventNotifyL( aEvent ) );
       
   118 	}
       
   119 
       
   120 
       
   121 /**
       
   122  *
       
   123  */
       
   124 void CBasePlugin::SystemEventNotifyL( TMsgStoreSystemEvent aEvent )
       
   125     
       
   126     {
       
   127     switch ( aEvent )
       
   128         {
       
   129         // A backup or restore is in progress.  The message store is unavailable.
       
   130         case EMsgStoreBackupOrRestoreInProgress:
       
   131         // The message store has been wiped, including the password.
       
   132         case EMsgStoreDatabaseWiped:
       
   133         // The message store has transitioned from an authenticated state to an unauthenticated state.
       
   134         case EMsgStoreNotAuthenticated:
       
   135             {
       
   136             NotifyGlobalEventL( TFSMailboxUnavailable );
       
   137             }
       
   138         break;
       
   139 
       
   140         // The backup or restore completed.  The message store is available again.   
       
   141         case EMsgStoreBackupOrRestoreCompleted:
       
   142         // The message store has transitioned from an unauthenticated state to an authenticated state.
       
   143         case EMsgStoreAuthenticated:
       
   144             {
       
   145             NotifyGlobalEventL( TFSMailboxAvailable );
       
   146             }
       
   147         break;
       
   148 
       
   149         // The observer event queue has overflowed and has been reset, so events have been lost.  This
       
   150         // shouldn't happen unless the client thread has been starved for an extended period of time, during
       
   151         // which many message store operations have occurred.
       
   152         case EObserverEventQueueOverflow:
       
   153         //don't see anything meaningful to do here.
       
   154         break;
       
   155         };
       
   156     }
       
   157 
       
   158 
       
   159 /**
       
   160  *
       
   161  */   
       
   162 EXPORT_C void CBasePlugin::AccountEventNotify(
       
   163     TMsgStoreAccountEvent aEvent,
       
   164 	TInt32 aOwnerId,
       
   165 	const TDesC& aName,
       
   166 	const TDesC& aNewName,
       
   167 	TMsgStoreId aMailboxId )
       
   168 	
       
   169 	{
       
   170 	if ( GetPluginId() == aOwnerId )
       
   171 	    {
       
   172 	    TRAP_IGNORE( AccountEventNotifyL( aEvent, aOwnerId, aName, aNewName, aMailboxId ) );
       
   173 	    }
       
   174 	}
       
   175 
       
   176 
       
   177 /**
       
   178  *
       
   179  */   
       
   180 void CBasePlugin::AccountEventNotifyL(
       
   181     TMsgStoreAccountEvent aEvent,
       
   182 	TInt32 /*aOwnerId*/,
       
   183 	const TDesC& /*aName*/,
       
   184 	const TDesC& /*aNewName*/,
       
   185 	TMsgStoreId aMailboxId )
       
   186 
       
   187     {
       
   188     switch ( aEvent )
       
   189         {
       
   190         case EMsgStoreAccountCreated:
       
   191             {
       
   192             TFSMailMsgId mailBox( GetPluginId(), aMailboxId );
       
   193             NotifyGlobalEventL( TFSEventNewMailbox, mailBox );
       
   194             }
       
   195         break;
       
   196 
       
   197         case EMsgStoreAccountDeleted:
       
   198             {
       
   199             //remove from the cache.
       
   200             if ( KErrNotFound != iMailboxes.Find( aMailboxId ) )
       
   201                 {
       
   202                 iMailboxes.RemoveL( aMailboxId );
       
   203                 }
       
   204 
       
   205             TFSMailMsgId mailBox( GetPluginId(), aMailboxId );
       
   206             
       
   207             HandleMailboxDeleteL( mailBox );
       
   208             
       
   209             NotifyGlobalEventL( TFSEventMailboxDeleted, mailBox );
       
   210             }
       
   211         break;
       
   212 
       
   213         case EMsgStoreAccountRenamed:
       
   214             {
       
   215             }
       
   216         break;
       
   217         };   
       
   218     }
       
   219 
       
   220 
       
   221 EXPORT_C void CBasePlugin::HandleMailboxDeleteL( const TFSMailMsgId& /*aMailboxId*/ )
       
   222     {
       
   223     //nothing to do
       
   224     }
       
   225 
       
   226 /**
       
   227  *
       
   228  */
       
   229 EXPORT_C void CBasePlugin::ModificationNotify(
       
   230     TMsgStoreId aMailBoxId,
       
   231     TMsgStoreOperation aOperation,
       
   232     TMsgStoreContainerType aType,
       
   233     TUint32 aFlags,
       
   234     TMsgStoreId aId,
       
   235     TMsgStoreId aParentId,
       
   236     TMsgStoreId aOtherId )
       
   237 
       
   238     {
       
   239     TRAP_IGNORE( ModificationNotifyL( aMailBoxId, aOperation, aType, aFlags, aId, aParentId, aOtherId ) );
       
   240     }
       
   241 
       
   242 
       
   243 /**
       
   244  *
       
   245  */
       
   246 void CBasePlugin::ModificationNotifyL(
       
   247     TMsgStoreId aMailBoxId,
       
   248     TMsgStoreOperation aOperation,
       
   249     TMsgStoreContainerType aType,
       
   250     TUint32 /*aFlags*/,
       
   251     TMsgStoreId aId,
       
   252     TMsgStoreId aParentId,
       
   253     TMsgStoreId aOtherId )
       
   254 
       
   255     {
       
   256     __LOG_ENTER( "ModificationNotifyL" );
       
   257     CMailboxInfo& mailBox = GetMailboxInfoL( aMailBoxId );
       
   258     
       
   259     __LOG_WRITE_FORMAT1_INFO( "aMailBoxId = 0x%X.", aMailBoxId );
       
   260     __LOG_WRITE_FORMAT1_INFO( "aId = 0x%X.", aId );
       
   261     __LOG_WRITE_FORMAT1_INFO( "aParentId = 0x%X.", aParentId );
       
   262     
       
   263     InvalidateCacheIfNecessary( aId, aParentId, aOtherId );
       
   264     
       
   265     if ( mailBox.iObservers.Count() > 0 )
       
   266         {
       
   267         switch ( aOperation )
       
   268             {
       
   269             
       
   270             case EMsgStoreAdd:
       
   271                 {
       
   272                 __LOG_WRITE_INFO( "EMsgStoreAdd." );
       
   273                 if ( EMsgStoreMessageContainer == aType )
       
   274                     {
       
   275                     NotifyEventL( aMailBoxId, aId, aParentId, TFSEventNewMail );
       
   276                     }
       
   277                 else if ( EMsgStoreFolderContainer == aType )
       
   278                     {
       
   279                     NotifyEventL( aMailBoxId, aId, aParentId, TFSEventNewFolder );
       
   280                     }
       
   281                 }
       
   282             break;
       
   283 
       
   284             case EMsgStoreDelete:
       
   285                 {
       
   286                 __LOG_WRITE_INFO( "EMsgStoreDelete." );
       
   287                 if ( EMsgStoreMessageContainer == aType )
       
   288                     {
       
   289                     NotifyEventL( aMailBoxId, aId, aParentId, TFSEventMailDeleted );
       
   290                     }
       
   291                 else if ( EMsgStoreFolderContainer == aType )
       
   292                     {
       
   293                     TRAPD( err, CMailboxInfo& mailBox = GetMailboxInfoL( aMailBoxId ) );
       
   294                     
       
   295                     if ( KErrNone == err )
       
   296                     	{
       
   297                     	for ( TInt i = EFSInbox; i <= EFSDeleted; i++ )
       
   298                     		{
       
   299                     		if ( mailBox.iRootFolders.iFolders[i] == aId )
       
   300                     			{
       
   301                     			TMsgStoreId newId = 0;
       
   302                     			
       
   303                     			/**@ this behavior is forced by the UI for some reason and should be revisited
       
   304                     			 * in the future as it allows more than one inbox folder which is not recommended. */
       
   305                     			
       
   306                     			//loop over all of the root folders looking for a replacement.
       
   307 								RPointerArray<CMsgStoreFolder> folders;
       
   308 								CleanupResetAndDestroyClosePushL( folders );
       
   309 
       
   310 								mailBox().FoldersL( aMailBoxId, folders );
       
   311 
       
   312 								for ( int j = 0; j < folders.Count(); j++ )
       
   313 									{
       
   314 									CMsgStoreFolder* folder = folders[j];
       
   315 
       
   316 									TUint index = 0;
       
   317 									if ( folder->FindProperty( KMsgStorePropertyFolderType, index ) )
       
   318 										{
       
   319 	                                    TUint32 type = folder->PropertyValueUint32L( index );
       
   320 
       
   321 	                                    if ( type == i )	//i is a value in the folder type enum.
       
   322 											{
       
   323 											newId = folder->Id();
       
   324 											break;
       
   325 											}
       
   326 	                                    }
       
   327 									}
       
   328 								
       
   329 								CleanupStack::PopAndDestroy( &folders );
       
   330                                 
       
   331                     			//set the new root folder info.
       
   332                     			mailBox.iRootFolders.iFolders[i] = newId;
       
   333                     			break;
       
   334                     			}                    		
       
   335                     		}
       
   336 						}
       
   337                 
       
   338                     NotifyEventL( aMailBoxId, aId, aParentId, TFSEventFoldersDeleted );
       
   339                     }
       
   340                 }
       
   341             break;
       
   342             
       
   343             case EMsgStoreMove:
       
   344                 {
       
   345                 __LOG_WRITE_INFO( "EMsgStoreMove." );
       
   346                 NotifyEventL( aMailBoxId, aId, aOtherId, TFSEventMailMoved, aParentId );
       
   347                 break;
       
   348                 }
       
   349 
       
   350             case EMsgStoreUpdateProperties:
       
   351                 {
       
   352                 __LOG_WRITE_INFO( "EMsgStoreUpdateProperties." );
       
   353                 if ( EMsgStoreMessageContainer == aType )
       
   354                     {
       
   355                     NotifyEventL( aMailBoxId, aId, aParentId, TFSEventMailChanged );
       
   356                     }
       
   357                 else if ( EMsgStoreFolderContainer == aType )
       
   358                     {
       
   359                     NotifyEventL( aMailBoxId, aId, aParentId, TFSEventFolderChanged );
       
   360                     }
       
   361                 else if ( EMsgStoreMailboxContainer == aType )
       
   362                     {
       
   363                     TBool mailBoxNameHasChanged( EFalse );
       
   364                     TRAP_IGNORE( RefreshCachedMailBoxDisplayNameL( mailBoxNameHasChanged, aMailBoxId ) );
       
   365                     
       
   366                     if ( mailBoxNameHasChanged )
       
   367                         {
       
   368                         NotifyEventL( aMailBoxId, aId, aParentId, TFSEventMailboxRenamed );
       
   369                         }
       
   370                     }
       
   371                 }
       
   372             break;
       
   373 
       
   374             case EMsgStoreRemoveContent:
       
   375                 break;
       
   376 
       
   377             default:
       
   378                 break;
       
   379             }
       
   380         }
       
   381         /* Reporting request status moved from above if-statement here. Now, request status is reported even there is no
       
   382          * mailbox observers.
       
   383          */ 
       
   384         switch ( aOperation )
       
   385             {
       
   386             case EMsgStoreUpdateProperties:
       
   387                 {
       
   388                 if ( EMsgStorePartContainer == aType )
       
   389                     {
       
   390                     ReportRequestStatusL( aMailBoxId, aOtherId, aParentId, aId );
       
   391                     }
       
   392                 }
       
   393                 break;
       
   394             /**@ check whether the ui removes the observer - then the observer must be kept
       
   395             until there are pending reqs ?*/
       
   396             //attachment download request handling.
       
   397             case EMsgStoreUpdateContent:
       
   398                 {
       
   399                 __LOG_WRITE_INFO( "EMsgStoreUpdateContent." );
       
   400                 ReportRequestStatusL( aMailBoxId, aOtherId, aParentId, aId, ETrue );
       
   401                 }
       
   402                 break;
       
   403                 
       
   404             default:
       
   405                 break;
       
   406         }
       
   407     
       
   408         
       
   409         __LOG_EXIT;
       
   410     } //ModificationNotifyL.
       
   411 
       
   412 
       
   413 /**
       
   414  *
       
   415  */
       
   416 void CBasePlugin::NotifyEventL(
       
   417     TMsgStoreId aMailBoxId,
       
   418     TMsgStoreId aId,
       
   419     TMsgStoreId aParentId,
       
   420     TFSMailEvent aFsEvent,
       
   421     TMsgStoreId aOtherId /*=KMsgStoreInvalidId*/ )
       
   422 
       
   423     {
       
   424     CMailboxInfo& mailBox = GetMailboxInfoL( aMailBoxId );
       
   425     
       
   426     TFSMailMsgId mailBoxId( GetPluginId(), aMailBoxId );
       
   427     TFSMailMsgId parent( GetPluginId(), aParentId );
       
   428     TFSMailMsgId other( GetPluginId(), aOtherId );
       
   429 
       
   430     TFSMailMsgId* param3 = NULL;
       
   431     if ( KMsgStoreInvalidId != aOtherId )
       
   432     	{
       
   433     	param3 = &other;
       
   434     	}
       
   435 
       
   436     RArray<TFSMailMsgId> entries;
       
   437     CleanupClosePushL( entries );
       
   438 
       
   439     TFSMailMsgId entry( GetPluginId(), aId );
       
   440     entries.AppendL( entry );
       
   441 
       
   442     TInt count = mailBox.iObservers.Count();
       
   443     for ( TInt i = 0; i < count; i++ )
       
   444         {
       
   445         mailBox.iObservers[i]->EventL( aFsEvent, mailBoxId, &entries, &parent, param3 );
       
   446         }
       
   447 
       
   448     CleanupStack::PopAndDestroy( &entries );
       
   449     }
       
   450 
       
   451 
       
   452 /**
       
   453  *
       
   454  */
       
   455 void CBasePlugin::NotifyGlobalEventL(
       
   456     TFSMailEvent aEvent,
       
   457     TFSMailMsgId aMailBox /*=TFSMailMsgId()*/,   //defaults to a null id.
       
   458     TAny* aParam1 /*=NULL*/,
       
   459     TAny* aParam2 /*=NULL*/,
       
   460     TAny* aParam3 /*=NULL*/ )
       
   461     
       
   462     {
       
   463     TInt count = iObservers.Count();
       
   464     
       
   465     for ( TInt i = 0; i < count; i++ )
       
   466         {
       
   467         iObservers[i]->EventL( aEvent, aMailBox, aParam1, aParam2, aParam3 );
       
   468         }
       
   469     }
       
   470 
       
   471 /**
       
   472  *
       
   473  */
       
   474 EXPORT_C void CBasePlugin::NotifyMailboxEventL(
       
   475         TFSMailEvent aEvent,
       
   476         TFSMailMsgId aMailBox,
       
   477         TAny* aParam1 /*=NULL*/,
       
   478         TAny* aParam2 /*=NULL*/,
       
   479         TAny* aParam3 /*=NULL*/ )
       
   480     {
       
   481     CMailboxInfo& mailBox = GetMailboxInfoL( aMailBox.Id() );
       
   482     
       
   483     for ( TInt i = 0; i < mailBox.iObservers.Count(); i++ )
       
   484         {
       
   485         mailBox.iObservers[i]->EventL( aEvent, aMailBox, aParam1, aParam2, aParam3 );
       
   486         }
       
   487     }
       
   488 
       
   489 
       
   490 /**
       
   491  *
       
   492  */
       
   493 EXPORT_C /*protected virtual*/ void CBasePlugin::ReportRequestStatusL(
       
   494     TMsgStoreId aMailBox,
       
   495     TMsgStoreId aOtherId,
       
   496     TMsgStoreId aMsgId,
       
   497     TMsgStoreId aPartId,
       
   498     TBool aCanReportCompletion /*=EFalse*/ )
       
   499 
       
   500     {
       
   501     __LOG_ENTER( "ReportRequestStatusL" );
       
   502 
       
   503     __LOG_WRITE_FORMAT1_INFO( "aMailBox : 0x%X.", aMailBox );
       
   504     __LOG_WRITE_FORMAT1_INFO( "aMsgId : 0x%X.", aMsgId );
       
   505     __LOG_WRITE_FORMAT1_INFO( "aPartId : 0x%X.", aPartId );
       
   506 
       
   507     TOngoingFetchInfo fetchInfo;
       
   508     if ( FindFetchRequestL( aMailBox, aOtherId, aMsgId, aPartId, fetchInfo ) )
       
   509         {
       
   510         __LOG_WRITE_INFO( "Request match found." );
       
   511 
       
   512         CMailboxInfo& mailBox = GetMailboxInfoL( aMailBox );
       
   513 
       
   514         //get the fetched and the server sizes.                    
       
   515         CMsgStoreMessage* msg = mailBox().FetchMessageL(
       
   516         	fetchInfo.iMessageId, KMsgStoreInvalidId );
       
   517         CleanupStack::PushL( msg );
       
   518         CMsgStoreMessagePart* part = msg->ChildPartL( aPartId, ETrue );
       
   519         CleanupStack::PushL( part );
       
   520 
       
   521         TUint32 size = 0;
       
   522         TUint idx = 0;
       
   523         if ( part->FindProperty( KMsgStorePropertySize, idx ) )
       
   524             {
       
   525             size = part->PropertyValueUint32L( idx );
       
   526             }
       
   527         
       
   528         TUint32 fetchedSize = 0;
       
   529         idx = 0;
       
   530         if ( part->FindProperty( KMsgStorePropertyRetrievedSize, idx ) )
       
   531             {
       
   532             fetchedSize = part->PropertyValueUint32L( idx );
       
   533             }
       
   534         
       
   535         CleanupStack::PopAndDestroy( part );
       
   536         CleanupStack::PopAndDestroy( msg );
       
   537 
       
   538         TFSProgress progress;
       
   539         progress.iError = KErrNone;
       
   540         progress.iMaxCount = size;
       
   541         progress.iCounter = fetchedSize;
       
   542         
       
   543         __LOG_WRITE_FORMAT2_INFO(
       
   544             "Size: %d, fetched size: %d.", size, fetchedSize );
       
   545             
       
   546         if ( fetchedSize < size )
       
   547             {
       
   548             __LOG_WRITE_INFO( "Download in progress, about to notify the UI." );
       
   549 
       
   550             progress.iProgressStatus = TFSProgress::EFSStatus_Status;
       
   551             fetchInfo.iRequest->iObserver.RequestResponseL(
       
   552             	progress, fetchInfo.iRequest->iRequestId );
       
   553             }
       
   554         else if ( aCanReportCompletion )
       
   555             {
       
   556             if ( DeleteFetchRequestForPart( fetchInfo ) )
       
   557             	{
       
   558             	//no more parts left for downloading thus completed.
       
   559                 progress.iProgressStatus
       
   560 					= TFSProgress::EFSStatus_RequestComplete;                        
       
   561                 __LOG_WRITE_INFO( "Download completed for all parts." );
       
   562 
       
   563                 fetchInfo.iRequest->iObserver.RequestResponseL(
       
   564                 	progress, fetchInfo.iRequest->iRequestId );
       
   565                 DeleteFetchRequest( fetchInfo );
       
   566             	}
       
   567             else
       
   568             	{
       
   569                 progress.iProgressStatus
       
   570 					= TFSProgress::EFSStatus_Status;
       
   571                 __LOG_WRITE_INFO( "A part download completed, more is left." );
       
   572 
       
   573                 fetchInfo.iRequest->iObserver.RequestResponseL(
       
   574                 	progress, fetchInfo.iRequest->iRequestId );
       
   575             	}
       
   576             }
       
   577         }
       
   578         
       
   579     __LOG_EXIT;
       
   580     }
       
   581 
       
   582 
       
   583 /**
       
   584  * @return ETrue in case there are no more parts left for downloading.
       
   585  */
       
   586 EXPORT_C /*protected*/ TBool CBasePlugin::DeleteFetchRequestForPart(
       
   587 	TOngoingFetchInfo& aFetchInfo )
       
   588 	{
       
   589     //remove the downloaded part from the request object.                        
       
   590 	aFetchInfo.iRequest->iParts.Remove( aFetchInfo.iPartIndex );
       
   591 
       
   592 	return 0 == aFetchInfo.iRequest->iParts.Count();
       
   593 	}
       
   594 
       
   595 
       
   596 /**
       
   597  * 
       
   598  */
       
   599 EXPORT_C /*protected*/ void CBasePlugin::DeleteFetchRequest(
       
   600 	TOngoingFetchInfo& aFetchInfo )
       
   601 	{
       
   602 	iReqs.Remove( aFetchInfo.iRequestIndex );
       
   603 	delete aFetchInfo.iRequest;
       
   604 	}
       
   605 
       
   606 
       
   607 /**
       
   608  * 
       
   609  */
       
   610 EXPORT_C TBool CBasePlugin::FindFetchRequestL(
       
   611 	TMsgStoreId aMailBox,
       
   612 	TMsgStoreId aOtherId,
       
   613 	TMsgStoreId aMsgId,
       
   614 	TMsgStoreId aPartId,
       
   615 	CBasePlugin::TOngoingFetchInfo& aOngoingFetchInfo )
       
   616 	{
       
   617 	
       
   618 	for ( TInt count = iReqs.Count(); aOngoingFetchInfo.iRequestIndex < count;
       
   619 		aOngoingFetchInfo.iRequestIndex++ )
       
   620 		{
       
   621 		TFSMailMsgId fsId( GetPluginId(), aPartId );
       
   622 		CFetchRequester* request = iReqs[aOngoingFetchInfo.iRequestIndex];
       
   623 		
       
   624 		//a request might specify more than one part for download, find the
       
   625 		//index of the currently processed part.
       
   626 		TInt partsCount = request->iParts.Count();
       
   627 		for ( TInt i = 0; i < partsCount; i++ )
       
   628 			{
       
   629 			if ( fsId == request->iParts[i] )
       
   630 				{
       
   631 				aOngoingFetchInfo.iPartIndex = i;
       
   632 				break;
       
   633 				}
       
   634 			}
       
   635 	
       
   636 		//there are MsgStore notification that receive the message id in the
       
   637 		//"other" id, determine for sure the id of the message this part belongs
       
   638 		//to. 
       
   639 		if ( aMsgId == request->iMessageId.Id() )
       
   640 			{
       
   641 			aOngoingFetchInfo.iMessageId = aMsgId;
       
   642 			}
       
   643 		else if ( aOtherId 
       
   644 			== request->iMessageId.Id() )
       
   645 			{
       
   646 			aOngoingFetchInfo.iMessageId = aOtherId;
       
   647 			}
       
   648 	
       
   649 		//final check before choosing the download request object that
       
   650 		//identifies this part download request.
       
   651 		if ( aMailBox == request->iMailBoxId.Id()
       
   652 			&& KMsgStoreInvalidId != aOngoingFetchInfo.iMessageId 
       
   653 			&& KErrNotFound != aOngoingFetchInfo.iPartIndex )
       
   654 			{
       
   655 			aOngoingFetchInfo.iRequest = request;
       
   656 			break;
       
   657 			}
       
   658 		}
       
   659 	
       
   660 	return NULL != aOngoingFetchInfo.iRequest;
       
   661 	} //FindRequestL.
       
   662 
       
   663 
       
   664 /**
       
   665  *
       
   666  */
       
   667 void CBasePlugin::UnsubscribeMailboxEventsL(
       
   668     const TFSMailMsgId& aMailboxId,
       
   669     MFSMailEventObserver& aObserver )
       
   670 
       
   671 	{
       
   672     CMailboxInfo& mailBox = GetMailboxInfoL( aMailboxId.Id() );
       
   673 
       
   674     TInt idx = mailBox.iObservers.Find( &aObserver );
       
   675     
       
   676     if ( KErrNotFound != idx )
       
   677         {
       
   678         mailBox.iObservers.Remove( idx );
       
   679         }
       
   680 	}