emailservices/emailstore/message_store/server/src/MessageStoreSession.cpp
changeset 0 8466d47a6819
child 12 f5907b1a1053
child 51 d845db10c0d4
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:  Message store session implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ========
       
    21 // INCLUDES
       
    22 // ========
       
    23 
       
    24 #include "MsgStoreTypes.h"
       
    25 #include "MsgStorePropertyKeys.h"
       
    26 
       
    27 #include "MessageStoreSession.h"
       
    28 #include "MessageStoreServer.h"
       
    29 #include "ContainerStore.h"
       
    30 #include "PropertiesSerializer.h"
       
    31 #include "ContainerStoreMRUAddressTable.h"
       
    32 #include "bufferedmessagecreator.h"
       
    33 
       
    34 
       
    35 // =========
       
    36 // CONSTANTS
       
    37 // =========
       
    38 
       
    39 // The maximum number of observer events that will be queued up for a single session.
       
    40 const TInt KMsgStoreMaximumEventQueueDepth = 100;
       
    41 const TInt KInitialAddressBufSize          = 256;
       
    42 const TInt KSortedArrayGranularity         = 100;
       
    43 
       
    44 const TUint KValThree = 3;
       
    45 const TUint KGranularity25 = 25;
       
    46 const TUint KGranularity15 = 15;
       
    47 
       
    48 // ======================
       
    49 // CLASS CSearchResult
       
    50 // ======================
       
    51 // ==========================================================================
       
    52 // FUNCTION: NewL
       
    53 // ==========================================================================
       
    54 CSearchResult* CSearchResult::NewL( TContainerId aMessageId, TContainerId aFolderId, const TDesC8& aPropertyBuf )
       
    55     {
       
    56     CSearchResult* self = new(ELeave) CSearchResult( aMessageId, aFolderId );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aPropertyBuf );
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 CSearchResult* CSearchResult::SearchCompleteResultL()
       
    64     {
       
    65     return NewL( KContainerInvalidId, KContainerInvalidId, KNullDesC8 );
       
    66     }
       
    67 
       
    68 // ==========================================================================
       
    69 // FUNCTION: Constructor
       
    70 // ==========================================================================
       
    71 CSearchResult::CSearchResult( TContainerId aMessageId, TContainerId aFolderId )
       
    72     : iMessageId( aMessageId ), iFolderId( aFolderId )
       
    73     {
       
    74     }
       
    75 
       
    76 // ==========================================================================
       
    77 // FUNCTION: ConstructL
       
    78 // ==========================================================================
       
    79 void CSearchResult::ConstructL( const TDesC8& aPropertyBuf )
       
    80     {
       
    81     iPropertyBuf.Create( aPropertyBuf );
       
    82     }
       
    83 
       
    84 // ==========================================================================
       
    85 // FUNCTION: Destructor
       
    86 // ==========================================================================
       
    87 CSearchResult::~CSearchResult()
       
    88     {
       
    89     iPropertyBuf.Close();
       
    90     }
       
    91         
       
    92 
       
    93 // ==========================
       
    94 // CLASS CMessageStoreSession
       
    95 // ==========================
       
    96 // ==========================================================================
       
    97 // FUNCTION: Constructor
       
    98 // ==========================================================================
       
    99 CMessageStoreSession::CMessageStoreSession(CMessageStoreServer& aMessageStoreServer) : 
       
   100 	iServer(aMessageStoreServer),
       
   101 	iIds( KGranularity25 ),
       
   102 	iEventQueue( KGranularity15 ),
       
   103     iSearchHandler( NULL )
       
   104     {
       
   105   	__LOG_CONSTRUCT( "msg", "CMessageStoreSession" )
       
   106   	}
       
   107 
       
   108 // ==========================================================================
       
   109 // FUNCTION: CreateL
       
   110 // ==========================================================================
       
   111 void CMessageStoreSession::CreateL()
       
   112     {
       
   113     __LOG_ENTER( "CreateL" )
       
   114     
       
   115     iServer.AddSession( this );
       
   116 
       
   117     // This could leave if a session is created while the store is unavailable.
       
   118     TRAP_IGNORE( iServer.MessageStoreL().ObserveL( this ) );
       
   119     
       
   120     __LOG_EXIT
       
   121     } // end CreateL
       
   122 
       
   123 // ==========================================================================
       
   124 // FUNCTION: Destructor
       
   125 // ==========================================================================
       
   126 CMessageStoreSession::~CMessageStoreSession()	
       
   127 	{
       
   128     delete iBufferedMessageCreator;
       
   129     
       
   130 	iIds.Reset();
       
   131 	
       
   132     iMruAddressArray.ResetAndDestroy();
       
   133     
       
   134 	iPropertyNames.ResetAndDestroy();
       
   135     
       
   136 	iMatchMessages.ResetAndDestroy();
       
   137     
       
   138     iSearchStrings.ResetAndDestroy();
       
   139 	
       
   140 	delete iSearchHandler;
       
   141 	
       
   142 	TRAP_IGNORE( iServer.MessageStoreL().StopObserving( this ) );
       
   143 	
       
   144 	//close all the sort iterators when the client exits/crashes
       
   145 	for ( TInt i = 0 ; i < iSortSessionIds.Count(); i++  )
       
   146 	    {
       
   147 	    TRAP_IGNORE( iServer.MessageStoreL().EndSortingL( iSortSessionIds[i] ) );
       
   148 	    }
       
   149 	iSortSessionIds.Close();
       
   150 
       
   151 	iEventQueue.Close();
       
   152 
       
   153 	if( !iObserverMessage.IsNull() )
       
   154 		{
       
   155 		iObserverMessage.Complete( KErrCancel );
       
   156 		} // end if
       
   157 
       
   158 	if( !iGetMatchesMessage.IsNull() )
       
   159 		{
       
   160 		iGetMatchesMessage.Complete( KErrCancel );
       
   161 		} // end if
       
   162 
       
   163 	iServer.DropSession( this );
       
   164 
       
   165 	__LOG_DESTRUCT
       
   166 	} // end destructor
       
   167 
       
   168 // ==========================================================================
       
   169 // FUNCTION:ServiceL
       
   170 // ==========================================================================
       
   171 void CMessageStoreSession::ServiceL(const RMessage2& aMessage)
       
   172   {
       
   173   __LOG_ENTER_SUPPRESS( "ServiceL" )
       
   174   __LOG_WRITE8_FORMAT1_INFO( "%d", aMessage.Function() )
       
   175 
       
   176   // Call the appropriate message handler function, based on the message function ID.
       
   177   switch( aMessage.Function() )
       
   178     {
       
   179 	case EMsgStoreCmdAuthenticated:
       
   180 		DoAuthenticatedL( aMessage );
       
   181 		break;
       
   182         
       
   183 	case EMsgStoreCmdAuthenticate:
       
   184 		DoAuthenticateL( aMessage );
       
   185 		break;
       
   186         
       
   187 	case EMsgStoreCmdClearAuthentication:
       
   188 		DoClearAuthenticationL( aMessage );
       
   189 		break;
       
   190         
       
   191 	case EMsgStoreCmdHasPassword:
       
   192 		DoHasPasswordL( aMessage );
       
   193 		break;
       
   194         
       
   195 	case EMsgStoreCmdSetPassword:
       
   196 		DoSetPasswordL( aMessage );
       
   197 		break;
       
   198         
       
   199 	case EMsgStoreCmdChangePassword:
       
   200 		DoChangePasswordL( aMessage );
       
   201 		break;
       
   202         
       
   203     case EMsgStoreCmdEnableEncryption:
       
   204         DoEnableEncryptionL( aMessage );
       
   205         break;
       
   206         
       
   207     case EMsgStoreCmdDisableEncryption:
       
   208         DoDisableEncryptionL( aMessage );
       
   209         break;
       
   210         
       
   211 	case EMsgStoreCmdWipeEverything:
       
   212 		DoWipeEverythingL( aMessage );
       
   213 		break;
       
   214         
       
   215     case EMsgStoreCmdStartObserving:
       
   216 		DoStartObserving( aMessage );
       
   217 		break;
       
   218         
       
   219     case EMsgStoreCmdGetEvents:
       
   220 		DoGetEventsL( aMessage );
       
   221 		break;
       
   222         
       
   223     case EMsgStoreCmdStopObserving:	
       
   224 		DoStopObserving( aMessage );
       
   225 		break;
       
   226 		
       
   227     case EMsgStoreCmdCreateAccount:	
       
   228     	DoCreateAccountL( aMessage );
       
   229     	break;
       
   230     	
       
   231     case EMsgStoreCmdOpenAccount:	
       
   232 		DoOpenAccountL( aMessage );
       
   233 		break;
       
   234 		
       
   235     case EMsgStoreCmdDeleteAccount:	
       
   236 		DoDeleteAccountL( aMessage );
       
   237 		break;
       
   238 		
       
   239     case EMsgStoreCmdRenameAccount:	
       
   240 		DoRenameAccountL( aMessage );
       
   241 		break;
       
   242 		
       
   243     case EMsgStoreCmdListAccounts:	
       
   244 		DoListAccountsL( aMessage );
       
   245 		break;
       
   246     
       
   247     case EMsgStoreCmdCreateContainer:
       
   248 		DoCreateContainerL( aMessage );
       
   249 		break;
       
   250         
       
   251     case EMsgStoreCmdCommitContainer:
       
   252 		DoCommitContainerL( aMessage );
       
   253 		break;
       
   254         
       
   255     case EMsgStoreCmdAbandonContainer:
       
   256 		DoAbandonContainerL( aMessage );
       
   257 		break;
       
   258         
       
   259     case EMsgStoreCmdMoveContainer:
       
   260 		DoMoveContainerL( aMessage );
       
   261 		break;
       
   262         
       
   263     case EMsgStoreCmdCopyContainer:
       
   264 		DoCopyContainerL( aMessage );
       
   265 		break;
       
   266         
       
   267 	case EMsgStoreCmdDeleteContainer:
       
   268 		DoDeleteContainerL( aMessage );
       
   269 		break;
       
   270         
       
   271 	case EMsgStoreCmdChildrenCounts:
       
   272 		DoChildrenCountsL( aMessage );
       
   273 		break;
       
   274         
       
   275 	case EMsgStoreCmdTotalCounts:
       
   276 		DoTotalCountsL( aMessage );
       
   277 		break;
       
   278         
       
   279     case EMsgStoreCmdChildrenIds:
       
   280 		DoChildrenIdsL( aMessage );
       
   281 		break;
       
   282         
       
   283     case EMsgStoreCmdPropertiesList:
       
   284 		DoPropertiesListL( aMessage );
       
   285 		break;
       
   286         
       
   287 	case EMsgStoreCmdFetchProperties:
       
   288 		DoFetchPropertiesL( aMessage );
       
   289 		break;
       
   290         
       
   291 	case EMsgStoreCmdUpdateProperties:
       
   292 		DoUpdatePropertiesL( aMessage );
       
   293 		break;
       
   294         
       
   295 	case EMsgStoreCmdUpdateProperty:
       
   296 		DoUpdatePropertyL( aMessage );
       
   297 		break;
       
   298         
       
   299     case EMsgStoreCmdContentLength:
       
   300 		DoContentLengthL( aMessage );
       
   301 		break;
       
   302         
       
   303     case EMsgStoreCmdFetchContentToBuffer:
       
   304 		DoFetchContentToBufferL( aMessage );
       
   305 		break;
       
   306         
       
   307     case EMsgStoreCmdFetchContentToFile:
       
   308 		DoFetchContentToFileL( aMessage );
       
   309 		break;
       
   310         
       
   311     case EMsgStoreCmdReplaceContentWithBuffer:
       
   312 		DoReplaceContentWithBufferL( aMessage );
       
   313 		break;
       
   314         
       
   315     case EMsgStoreCmdReplaceContentWithFile:
       
   316 		DoReplaceContentWithFileL( aMessage );
       
   317 		break;
       
   318         
       
   319     case EMsgStoreCmdAppendToContent:
       
   320         DoAppendToContentL( aMessage );
       
   321 		break;
       
   322         
       
   323     case EMsgStoreCmdPrependToContent:
       
   324         DoPrependToContentL( aMessage );
       
   325         break;
       
   326 
       
   327     case EMsgStoreCmdRemoveContent:
       
   328 		DoRemoveContentL( aMessage );
       
   329 		break;
       
   330         
       
   331     case EMsgStoreCmdOpenContentFile:
       
   332         DoOpenContentFileL( aMessage );
       
   333         break;
       
   334         
       
   335     case EMsgStoreCmdPrepareSearch:
       
   336 		DoPrepareSearchL( aMessage );
       
   337 		break;
       
   338         
       
   339     case EMsgStoreCmdGetMatches:
       
   340 		DoGetMatches( aMessage );
       
   341 		break;
       
   342         
       
   343     case EMsgStoreCmdCancelSearch:
       
   344 		DoCancelSearch( aMessage );
       
   345 		break;
       
   346         
       
   347     case EMsgStoreCmdClearSearchResultCache:
       
   348         DoClearSearchResultCache( aMessage );
       
   349         break;
       
   350         
       
   351     case EMsgStoreCmdStartSorting:
       
   352         DoStartSortingL( aMessage );
       
   353         break;
       
   354         
       
   355     case EMsgStoreCmdEndSorting:
       
   356         DoEndSortingL( aMessage );
       
   357         break;
       
   358         
       
   359     case EMsgStoreCmdGetSortedRows:
       
   360         DoGetSortedRowsL( aMessage );
       
   361         break;
       
   362         
       
   363     case EMsgStoreCmdGetIteratorGroupCount:
       
   364         DoGetIteratorGroupCountL( aMessage );
       
   365         break;
       
   366 
       
   367     case EMsgStoreCmdGetIteratorIdsAndFlags:
       
   368         DoGetSortedIdsAndFlagsL( aMessage );
       
   369         break;
       
   370     
       
   371     case EMsgStoreCmdSortedIndexOf:
       
   372         DoGetSortedIndexOfL( aMessage );
       
   373         break;
       
   374 
       
   375     case EMsgStoreCmdGetIteratorIds:
       
   376         DoGetSortedIdsL( aMessage );
       
   377         break;
       
   378         
       
   379     case EMsgStoreCmdGetIteratorIdsAndGroupCount:
       
   380         DoGetSortedIdsAndGroupCountL( aMessage );
       
   381         break;
       
   382         
       
   383     case EMsgStoreCmdSetMaxMruAddressCount:
       
   384         DoSetMaxMruAdressCountL( aMessage );
       
   385         break;
       
   386         
       
   387     case EMsgStoreCmdSetMruAddressList:
       
   388         DoSetMruAddressListL( aMessage );
       
   389         break;
       
   390         
       
   391     case EMsgStoreCmdGetMruAddressList:
       
   392         DoGetMruAddressListL( aMessage );
       
   393         break;
       
   394         
       
   395     case EMsgStoreCmdBeginBatchInsert:
       
   396         DoBeginBatchInsertL( aMessage );
       
   397         break;
       
   398 
       
   399     case EMsgStoreCmdFinishBatchInsert:
       
   400         DoFinishBatchInsertL( aMessage );
       
   401         break;
       
   402 
       
   403 #ifdef _DEBUG
       
   404         
       
   405     case EMsgStoreCmdInjectBackupRestoreEvent:
       
   406         DoInjectBackupRestoreEventL( aMessage );
       
   407         break;
       
   408     case EMsgStoreCmdInjectPointSecEvent:
       
   409         DoInjectPointSecEvent( aMessage );
       
   410         break;
       
   411     case EMsgStoreCmdSimulateLowDiskSpace:
       
   412         DoSimulateLowDiskSpaceL( aMessage );
       
   413         break;
       
   414     case EMsgStoreCmdGetEncryptionState:
       
   415         DoGetEncryptionStateL( aMessage );
       
   416         break;
       
   417     case EMsgStoreCmdShutdownServer:
       
   418         DoShutdownServer( aMessage );
       
   419         break;
       
   420     
       
   421 #endif  
       
   422         
       
   423     default:
       
   424       __LOG_WRITE_ERROR( "Illegal function!" )
       
   425       PanicClient( aMessage, EPanicIllegalFunction );
       
   426       break;
       
   427     } // end switch
       
   428        
       
   429   __LOG_EXIT    
       
   430   } // end ServiceL
       
   431 
       
   432 // ==========================================================================
       
   433 // FUNCTION: ServiceError
       
   434 // ==========================================================================
       
   435 void CMessageStoreSession::ServiceError(const RMessage2& aMessage, TInt aError)
       
   436   {
       
   437   __LOG_ENTER_SUPPRESS( "ServiceError" )
       
   438   __LOG_WRITE8_FORMAT1_ERROR( "ServiceError %d", aError)
       
   439   CSession2::ServiceError( aMessage, aError );
       
   440   } // end ServiceError
       
   441 
       
   442 // ==========================================================================
       
   443 // FUNCTION: ContainerStoreUnavailable
       
   444 // ==========================================================================
       
   445 void CMessageStoreSession::ContainerStoreUnavailable()
       
   446 	{
       
   447     // Cancel any ongoing searches.
       
   448     delete iSearchHandler;
       
   449     iSearchHandler = NULL;
       
   450     iMatchMessages.ResetAndDestroy();    
       
   451     
       
   452 	TRAP_IGNORE( iServer.MessageStoreL().StopObserving( this ) );
       
   453 	} // end ContainerStoreUnavailable
       
   454 
       
   455 // ==========================================================================
       
   456 // FUNCTION: ContainerStoreAvailable
       
   457 // ==========================================================================
       
   458 void CMessageStoreSession::ContainerStoreAvailable()
       
   459 	{
       
   460 	TRAP_IGNORE( iServer.MessageStoreL().ObserveL( this ) );
       
   461 	} // end ContainerStoreAvailable
       
   462 
       
   463 // ----------------------
       
   464 // OBSERVER FUNCTIONALITY
       
   465 // ----------------------
       
   466 
       
   467 // ==========================================================================
       
   468 // FUNCTION: DoStartObserving
       
   469 // ==========================================================================
       
   470 void CMessageStoreSession::DoStartObserving( const RMessage2& aMessage )
       
   471 	{
       
   472 	iIsObserving = ETrue;
       
   473 	
       
   474 	aMessage.Complete( KErrNone );
       
   475 	} // end DoStartObserving
       
   476 	
       
   477 // ==========================================================================
       
   478 // FUNCTION: DoStopObserving
       
   479 // ==========================================================================
       
   480 void CMessageStoreSession::DoStopObserving( const RMessage2& aMessage )
       
   481 	{
       
   482 	iIsObserving = EFalse;
       
   483 	
       
   484 	iEventQueue.Reset();
       
   485 	
       
   486 	if( !iObserverMessage.IsNull() )
       
   487 		{
       
   488 		iObserverMessage.Complete( KErrCancel );
       
   489 		} // end if
       
   490 		
       
   491 	aMessage.Complete( KErrNone );
       
   492 	} // end DoStopObserving
       
   493 	
       
   494 // ==========================================================================
       
   495 // FUNCTION: DoCreateAccountL
       
   496 // ==========================================================================
       
   497 void CMessageStoreSession::DoCreateAccountL( const RMessage2& aMessage )
       
   498 	{
       
   499 	TInt32 ownerId = aMessage.Int1();
       
   500 
       
   501     RBuf name;    
       
   502     CleanupClosePushL( name );
       
   503     name.CreateL( aMessage.GetDesLengthL( 2 ) );
       
   504     
       
   505 	aMessage.ReadL( 2, name );
       
   506 	
       
   507 	RBuf8 propertiesBuf;
       
   508 	CleanupClosePushL( propertiesBuf );
       
   509 	propertiesBuf.CreateL( aMessage.GetDesLengthL( KValThree ) );
       
   510 	aMessage.ReadL( KValThree, propertiesBuf );
       
   511 	
       
   512 	TContainerId mbId = iServer.MessageStoreL().CreateAccountL( ownerId, name, this, propertiesBuf );
       
   513 	
       
   514     TPckg<TContainerId> mbIdPckg( mbId );
       
   515 	aMessage.WriteL( 0, mbIdPckg );
       
   516 	
       
   517 	CleanupStack::PopAndDestroy( &propertiesBuf );
       
   518 	CleanupStack::PopAndDestroy( &name );
       
   519 	
       
   520     aMessage.Complete( KErrNone );
       
   521 	}
       
   522 
       
   523 // ==========================================================================
       
   524 // FUNCTION: DoOpenAccountL
       
   525 // ==========================================================================
       
   526 void CMessageStoreSession::DoOpenAccountL( const RMessage2& aMessage )
       
   527 	{
       
   528 	__LOG_ENTER_SUPPRESS("DoOpenAccountL")
       
   529 	
       
   530 	//parameter 0 - result
       
   531 	TUint result;
       
   532 	TPckg<TUint> resultPckg( result );
       
   533 	
       
   534     //parameter 1 - params
       
   535 	TMsgStoreOpenAccountCmdParams params;
       
   536     TPckg<TMsgStoreOpenAccountCmdParams> paramsPckg( params );
       
   537 	aMessage.ReadL( 1, paramsPckg );
       
   538 	
       
   539 	TInt32 ownerId = params.iOwnerId;
       
   540 	
       
   541 	//parameter 2 - account anme
       
   542     RBuf name;    
       
   543     CleanupClosePushL( name );
       
   544     name.CreateL( aMessage.GetDesLengthL( 2 ) );
       
   545 	aMessage.ReadL( 2, name );
       
   546 	
       
   547 	//parameter 3 - property buf
       
   548 	RBuf8 propertiesBuf;
       
   549 	CleanupClosePushL( propertiesBuf );
       
   550 	
       
   551 	params.iMailBoxId = iServer.MessageStoreL().OpenAccountL( ownerId, name, propertiesBuf );
       
   552 	
       
   553 	if( propertiesBuf.Length() > aMessage.GetDesMaxLengthL( KValThree ) )
       
   554 	    {
       
   555 	    // Overflow!
       
   556 	    __LOG_WRITE8_FORMAT1_ERROR( "property buffer too long (%i)", propertiesBuf.Length() );
       
   557 	    
       
   558 	    // Write the required length to the result parameter, to indicate to the client that the
       
   559 	    // buffer must be increased to the given size.
       
   560 	    result = propertiesBuf.Length();
       
   561 	    aMessage.WriteL( 0, resultPckg );	    
       
   562 	    }
       
   563 	else
       
   564 	    {	    	
       
   565         result = 0;
       
   566 	    aMessage.WriteL( 0, resultPckg );
       
   567 	    
       
   568  	    aMessage.WriteL( 1, paramsPckg );
       
   569 
       
   570         aMessage.WriteL( KValThree, propertiesBuf );
       
   571 
       
   572 	    } // end if
       
   573 	
       
   574 	CleanupStack::PopAndDestroy( &propertiesBuf );
       
   575 	CleanupStack::PopAndDestroy( &name );
       
   576 	
       
   577     aMessage.Complete( KErrNone );
       
   578 	}
       
   579 
       
   580 // ==========================================================================
       
   581 // FUNCTION: DoRenameAccountL
       
   582 // ==========================================================================
       
   583 void CMessageStoreSession::DoRenameAccountL( const RMessage2& aMessage )
       
   584 	{
       
   585 	TInt32 ownerId = aMessage.Int0();
       
   586 
       
   587     RBuf oldName;    
       
   588     CleanupClosePushL( oldName );
       
   589     oldName.CreateL( aMessage.GetDesLengthL( 1 ) );
       
   590 	aMessage.ReadL( 1, oldName );
       
   591 	
       
   592     RBuf newName;    
       
   593     CleanupClosePushL( newName );
       
   594     newName.CreateL( aMessage.GetDesLengthL( 2 ) );
       
   595 	aMessage.ReadL( 2, newName );
       
   596 	
       
   597 	iServer.MessageStoreL().RenameAccountL( ownerId, oldName, newName, this );
       
   598 	
       
   599 	CleanupStack::PopAndDestroy( &newName );
       
   600 	CleanupStack::PopAndDestroy( &oldName );
       
   601 	
       
   602     aMessage.Complete( KErrNone );
       
   603 	}
       
   604 
       
   605 // ==========================================================================
       
   606 // FUNCTION: DoDeleteAccountL
       
   607 // ==========================================================================
       
   608 void CMessageStoreSession::DoDeleteAccountL( const RMessage2& aMessage )
       
   609 	{
       
   610 	TInt32 ownerId = aMessage.Int0();
       
   611 
       
   612     RBuf name;    
       
   613     CleanupClosePushL( name );
       
   614     name.CreateL( aMessage.GetDesLengthL( 1 ) );
       
   615 	aMessage.ReadL( 1, name );
       
   616 	
       
   617 	iServer.MessageStoreL().DeleteAccountL( ownerId, name, this );
       
   618 	
       
   619 	CleanupStack::PopAndDestroy( &name );
       
   620 	
       
   621     aMessage.Complete( KErrNone );
       
   622 	}
       
   623 
       
   624 // ==========================================================================
       
   625 // FUNCTION: DoListAccountsL
       
   626 // ==========================================================================
       
   627 void CMessageStoreSession::DoListAccountsL( const RMessage2& aMessage )
       
   628 	{
       
   629     RBuf8 resultBuf;
       
   630     CleanupClosePushL( resultBuf );
       
   631     resultBuf.CreateL( aMessage.GetDesMaxLength(0) );
       
   632     
       
   633     iServer.MessageStoreL().ListAccountsL( resultBuf );
       
   634     
       
   635     aMessage.WriteL( 0, resultBuf );
       
   636     
       
   637 	CleanupStack::PopAndDestroy( &resultBuf );
       
   638 	
       
   639     aMessage.Complete( KErrNone );
       
   640 	}
       
   641 
       
   642 // ==========================================================================
       
   643 // FUNCTION: DoGetEventsL
       
   644 // ==========================================================================
       
   645 void CMessageStoreSession::DoGetEventsL( const RMessage2& aMessage )
       
   646 	{
       
   647 	// If there are any queued events then send them right away, otherwise
       
   648 	// save the message until events become avaialable.
       
   649 	if( iEventQueue.Count() > 0 )
       
   650 		{
       
   651         TUint desLength = aMessage.GetDesMaxLengthL( 0 );
       
   652         
       
   653         TUint position = 0;
       
   654         
       
   655         while( iEventQueue.Count() > 0 && position < desLength )
       
   656             {
       
   657             TPckg<TMsgStoreEvent> eventPckg( iEventQueue[0] );
       
   658 			aMessage.WriteL( 0, eventPckg, position );
       
   659             
       
   660             position += sizeof( TMsgStoreEvent );
       
   661             iEventQueue.Remove( 0 );		
       
   662             } // end while
       
   663             
       
   664         aMessage.Complete( KErrNone );
       
   665 	    }
       
   666 	else
       
   667 	    {
       
   668 	    iObserverMessage = aMessage;
       
   669 		} // end if	
       
   670 		
       
   671 	} // end DoGetEventsL
       
   672 	
       
   673 // ==========================================================================
       
   674 // FUNCTION: SendEventToObserver
       
   675 // ==========================================================================
       
   676 void CMessageStoreSession::SendEventToObserver( TMsgStoreEvent aEvent )
       
   677 	{
       
   678 	__LOG_ENTER( "SendEventToObserver" )
       
   679 	
       
   680 	// If there is no observer message pending then queue up the message,
       
   681 	// otherwise send it immediately.
       
   682 	
       
   683 	if( iObserverMessage.IsNull() )
       
   684 		{
       
   685 		if( iEventQueue.Count() > KMsgStoreMaximumEventQueueDepth )
       
   686 		    {
       
   687 		    __LOG_WRITE_ERROR( "EVENT QUEUE OVERFLOW" );
       
   688 		    iEventQueue.Reset();
       
   689 		    
       
   690         	TMsgStoreEvent event;
       
   691         	event.iType        = EObserverEventQueueOverflow;
       
   692         	event.iId          = KMsgStoreInvalidId;
       
   693         	event.iParentId    = KMsgStoreInvalidId;
       
   694         	event.iOtherId     = KMsgStoreInvalidId;
       
   695         	event.iFlags       = KMsgStoreFlagsNotFound;
       
   696 
       
   697     		iEventQueue.Append( event );		
       
   698 		    }
       
   699 		else
       
   700 		    {
       
   701     		__LOG_WRITE_INFO( "event queued" )
       
   702     		iEventQueue.Append( aEvent );		
       
   703 		    } // end if		
       
   704 		}
       
   705 	else
       
   706 		{
       
   707 		__LOG_WRITE_INFO( "Sending event now" )
       
   708 		
       
   709 		TPckg<TMsgStoreEvent> eventPckg( aEvent );
       
   710 					
       
   711 		TRAPD( result, iObserverMessage.WriteL( 0, eventPckg ) );			
       
   712 		
       
   713 		iObserverMessage.Complete( result );
       
   714 		} // end if	
       
   715 		
       
   716     __LOG_EXIT		
       
   717 	} // end SendEventToObserver
       
   718 
       
   719 // ==========================================================================
       
   720 // FUNCTION: ContainerModified
       
   721 // ==========================================================================
       
   722 void CMessageStoreSession::ContainerModified( 
       
   723         TOperation aOperation, 
       
   724         const RArray<TContainerId>& aHierarchy, 
       
   725         TContainerId aNewParentId, 
       
   726         const TDesC8& aQuickProperties )
       
   727 	{
       
   728 	// If the children IDs array is not empty then a series of EMsgStoreCmdChildrenProperties
       
   729 	// messages are in progress, and a modified container could affect the data being streamed.
       
   730 	
       
   731 	if( iIds.Count() > 0 )
       
   732 	    {
       
   733         // The following event types could affect the properties that are being streamed to the client.
       
   734         // Reset the ID list to indicate that the streaming operation should be restarted.
       
   735         	
       
   736 	    if ( ( iUsingQuery ) && ( aHierarchy.Count() > 1 ) ) 
       
   737 	        {	        
       
   738 	        // If this is a query based list then the current change only affects the list if the
       
   739 	        // query was for all types or if the type match.
       
   740 	        if( (iQueryParams.iType == KContainerTypeAny) || (iQueryParams.iType == (aHierarchy[0] & KContainerTypeMask )) )
       
   741 	            {	            
       
   742             	switch( aOperation )
       
   743             		{
       
   744             		case EAdd:
       
   745             		case EMove:
       
   746              		case EDelete:
       
   747             		case EUpdateProperties:
       
   748             
       
   749                         // The current change only affects the list if the query was recursive or
       
   750                         // if the modified container has the same parent as used in the query.
       
   751             		    if( iQueryParams.iRecursive || (iQueryParams.iId == aHierarchy[1]) )
       
   752             		        {
       
   753             		        iIds.Reset();
       
   754             		        } // end if
       
   755                         break;
       
   756                             		        
       
   757             		} // end switch
       
   758             		
       
   759 	            } // end if
       
   760 	        }
       
   761 	    else
       
   762 	        {	        
       
   763    	        // Only deletes and property updates can affect the provided list of IDs.  Adds and
       
   764 	        // moves do not affect this operation.
       
   765         	switch( aOperation )
       
   766         		{
       
   767          		case EDelete:
       
   768         		case EUpdateProperties:
       
   769         		
       
   770                     iIds.Reset();
       
   771                     break;
       
   772                         		        
       
   773            		} // end switch
       
   774            		
       
   775 	        } // end if
       
   776     		
       
   777 	    } // end if	    
       
   778 	
       
   779 	// If the client session is currently observing then create an observer event.
       
   780 	
       
   781 	if( iIsObserving )
       
   782 	    {	    
       
   783     	TMsgStoreEvent event;
       
   784 
       
   785     	switch( aOperation )
       
   786     		{
       
   787     		case EAdd:
       
   788     		    event.iType = EMsgStoreAdd;
       
   789     			break;
       
   790     		case EMove:
       
   791     		    event.iType = EMsgStoreMove;
       
   792     			break;
       
   793     		case EDelete:
       
   794     			event.iType = EMsgStoreDelete;
       
   795     			break;
       
   796     		case EUpdateProperties:
       
   797     			event.iType = EMsgStoreUpdateProperties;
       
   798     			break;
       
   799     		case EUpdateContent:
       
   800     			event.iType = EMsgStoreUpdateContent;
       
   801     			break;
       
   802     		case ERemoveContent:
       
   803     			event.iType = EMsgStoreRemoveContent;
       
   804     			break;
       
   805     		default:
       
   806     		    // This shouldn't happen.
       
   807     		    event.iType = 0;
       
   808     		    break;    		    
       
   809     		} // end switch
       
   810     		
       
   811     	event.iId = aHierarchy[0];
       
   812     	
       
   813     	if( aHierarchy.Count() > 1 )
       
   814     	    {    	    
       
   815     	    event.iParentId = aHierarchy[1];
       
   816     	    }
       
   817     	else
       
   818     	    {
       
   819     	    event.iParentId = KContainerInvalidId;
       
   820     	    } // end if
       
   821     	        	
       
   822 	    if( aNewParentId != KContainerInvalidId )
       
   823 	        {
       
   824 	        // Use the new parent Id for the "other" id.
       
   825 	        event.iOtherId = aNewParentId;	        
       
   826 	        }
       
   827 	    else if( aHierarchy.Count() > 2 )
       
   828 	        {
       
   829 	        // Use the grandparent ID for the "other" ID.
       
   830 	        event.iOtherId = aHierarchy[2];
       
   831 	        }
       
   832 	    else
       
   833 	        {
       
   834 	        event.iOtherId = KContainerInvalidId;
       
   835 	        } // end if
       
   836 	    
       
   837 	    //Get the MailBoxId from the buttom of the Hierarchy
       
   838 	    if ( aHierarchy.Count() > 1 )
       
   839 	    	{
       
   840 	    	event.iMailBoxId = aHierarchy[ aHierarchy.Count() - 2 ];
       
   841 	    	}
       
   842 	    else
       
   843 	    	{
       
   844 	    	//this should not happen
       
   845 	    	event.iMailBoxId = KContainerInvalidId;
       
   846 	    	}
       
   847     	        	
       
   848         // Find the value of the flags property.
       
   849 
       
   850     	event.iFlags = KMsgStoreFlagsNotFound;
       
   851         if( aQuickProperties.Length() > 0 )
       
   852             {
       
   853             TPropertiesDeserializer deserializer( aQuickProperties );
       
   854             
       
   855             if( deserializer.Find( KMsgStorePropertyFlags ) && deserializer.Type() == EMsgStoreTypeUint32 )
       
   856                 {
       
   857     			TPckgBuf<TUint32> flagsPckg;
       
   858     			flagsPckg.Copy( deserializer.Value() );
       
   859 
       
   860                 event.iFlags = flagsPckg();                    
       
   861     			} // end if
       
   862 
       
   863             } // end if
       
   864         
       
   865         //initialize the names which are not used
       
   866         event.iAccountName.SetLength( 0 );
       
   867         event.iNewAccountName.SetLength( 0 );
       
   868 
       
   869     	SendEventToObserver( event );    	
       
   870     	
       
   871 	    } // end if
       
   872 	    
       
   873 	} // end ContainerModified
       
   874 	
       
   875 // ==========================================================================
       
   876 // FUNCTION: AuthenticationChanged
       
   877 // ==========================================================================
       
   878 void CMessageStoreSession::AuthenticationChanged( TBool aAuthenticated )
       
   879     {
       
   880     if( iIsObserving )
       
   881         {            
       
   882     	TMsgStoreEvent event;
       
   883 
       
   884     	if( aAuthenticated )
       
   885     	    {
       
   886     	    event.iType = EMsgStoreAuthenticated;
       
   887     	    }
       
   888     	else
       
   889     	    {
       
   890     	    event.iType = EMsgStoreNotAuthenticated;
       
   891     	    } // end if
       
   892 
       
   893     	event.iMailBoxId   = KMsgStoreInvalidId;
       
   894     	event.iId          = KMsgStoreInvalidId;
       
   895     	event.iParentId    = KMsgStoreInvalidId;
       
   896     	event.iOtherId     = KMsgStoreInvalidId;
       
   897     	event.iFlags       = KMsgStoreFlagsNotFound;
       
   898     	
       
   899         //initialize the names which are not used
       
   900         event.iAccountName.SetLength( 0 );
       
   901         event.iNewAccountName.SetLength( 0 );
       
   902     	
       
   903     	SendEventToObserver( event );
       
   904         } // end if
       
   905         
       
   906     } // end AuthenticationChanged
       
   907 
       
   908 // ==========================================================================
       
   909 // FUNCTION: AccountModified
       
   910 // ==========================================================================
       
   911 void CMessageStoreSession::AccountModified( TOperation aOperation, TInt32 aOwnerId, const TDesC8& aName, const TDesC8& aNewName, TContainerId aMailboxId )
       
   912 	{
       
   913     if( iIsObserving )
       
   914         {            
       
   915     	TMsgStoreEvent event;
       
   916     	
       
   917     	switch( aOperation )
       
   918 		{
       
   919 		case EAdd:
       
   920 		    event.iType = EMsgStoreAccountCreated;
       
   921 			break;
       
   922 		case EDelete:
       
   923 			event.iType = EMsgStoreAccountDeleted;
       
   924 			break;
       
   925 		case ERenameAccount:
       
   926 			event.iType = EMsgStoreAccountRenamed;
       
   927 			break;
       
   928 		default:
       
   929 		    // This shouldn't happen.
       
   930 		    event.iType = 0;
       
   931 		    break;    		    
       
   932 		} // end switch
       
   933 
       
   934     	event.iMailBoxId   = aMailboxId;
       
   935     	event.iId          = aOwnerId;
       
   936     	event.iParentId    = KMsgStoreInvalidId;
       
   937     	event.iOtherId     = KMsgStoreInvalidId;
       
   938     	event.iFlags       = KMsgStoreFlagsNotFound;
       
   939     	
       
   940         //initialize the names which are not used
       
   941         event.iAccountName.Copy( aName );
       
   942         event.iNewAccountName.Copy( aNewName );
       
   943     	
       
   944     	SendEventToObserver( event );
       
   945         } // end if
       
   946 	
       
   947 	}
       
   948 
       
   949 
       
   950 // --------------------    	
       
   951 // SEARCH FUNCTIONALITY
       
   952 // -------------------- 
       
   953     
       
   954 // ==========================================================================
       
   955 // FUNCTION: DoPrepareSearchL
       
   956 // ==========================================================================
       
   957 void CMessageStoreSession::DoPrepareSearchL( const RMessage2& aMessage )
       
   958     {
       
   959     //param 0 (search cmd param)
       
   960     TMsgStoreSearchCmdParams params;   
       
   961     TPckg<TMsgStoreSearchCmdParams> paramsPckg( params );
       
   962     aMessage.ReadL( 0, paramsPckg );
       
   963 
       
   964     //param 1 (search string)
       
   965     ReadString16ArrayL( aMessage, 1, iSearchStrings );
       
   966     
       
   967     //param 2 (folder IDs)
       
   968     ReadIdArrayL( aMessage, 2, iIds );
       
   969 
       
   970     //param 3 (property keys)
       
   971     // Deserialize the property names list.
       
   972     ReadString8ArrayL( aMessage, KValThree, iPropertyNames );
       
   973     
       
   974 	iMatchMessages.ResetAndDestroy();
       
   975     
       
   976     if ( iSearchHandler )
       
   977         {
       
   978         if ( iSearchHandler->IsSameSearchCriteriaL( iSearchStrings ) )
       
   979             {
       
   980             iSearchHandler->RestartL( params, iIds, iPropertyNames );
       
   981             }
       
   982         else
       
   983             {
       
   984             delete iSearchHandler;
       
   985             iSearchHandler = NULL;
       
   986             }
       
   987         }
       
   988     
       
   989     if ( !iSearchHandler )
       
   990         {
       
   991         // Create an asynchronous search handler and start it.
       
   992         iSearchHandler = iServer.MessageStoreL().SearchL( EMsgStoreMessageBits, params, iSearchStrings, iIds, iPropertyNames, *this );        
       
   993     	iSearchHandler->StartL();
       
   994         }
       
   995 	
       
   996     aMessage.Complete( KErrNone );
       
   997     } // end DoPrepareSearchL
       
   998     
       
   999 // ==========================================================================
       
  1000 // FUNCTION: DoGetMatchesL
       
  1001 // ==========================================================================
       
  1002 void CMessageStoreSession::DoGetMatches( const RMessage2& aMessage )
       
  1003     {
       
  1004     // TIpcArgs( &aMatchBuffer )
       
  1005     
       
  1006     iGetMatchesMessage = aMessage;
       
  1007     
       
  1008     // Always send the search results if the search has completed, even if there are not results found.
       
  1009     // The end of the search is indicated by a null search handler pointer.
       
  1010     TBool searchInProgress = EFalse;
       
  1011     if ( iSearchHandler )
       
  1012         {
       
  1013         searchInProgress = iSearchHandler->IsSearchInProgress();
       
  1014         }
       
  1015     
       
  1016     SendMatchesToClient( !searchInProgress );        
       
  1017     }
       
  1018     
       
  1019 // ==========================================================================
       
  1020 // FUNCTION: DoCancelSearch
       
  1021 // ==========================================================================
       
  1022 void CMessageStoreSession::DoCancelSearch( const RMessage2& aMessage )
       
  1023     {
       
  1024     iMatchMessages.ResetAndDestroy();
       
  1025     
       
  1026     if( iSearchHandler )
       
  1027         {     
       
  1028         //do not delete the search handler
       
  1029         iSearchHandler->CancelSearch();
       
  1030         } // end if
       
  1031         
       
  1032     if( !iGetMatchesMessage.IsNull() )
       
  1033         {
       
  1034         iGetMatchesMessage.Complete( KErrCancel );
       
  1035         } // end if
       
  1036     
       
  1037     iMatchMessages.ResetAndDestroy();
       
  1038     	
       
  1039 	aMessage.Complete( KErrNone );
       
  1040     } // end DoCancelSearch
       
  1041 
       
  1042 // ==========================================================================
       
  1043 // FUNCTION: DoClearSearchResultCache
       
  1044 // ==========================================================================
       
  1045 void CMessageStoreSession::DoClearSearchResultCache( const RMessage2& aMessage )
       
  1046     {
       
  1047     delete iSearchHandler;
       
  1048     iSearchHandler = NULL;
       
  1049     
       
  1050     aMessage.Complete( KErrNone );
       
  1051     }
       
  1052 
       
  1053 // ==========================================================================
       
  1054 // FUNCTION: MatchFound
       
  1055 // ==========================================================================
       
  1056 void CMessageStoreSession::MatchFound( TContainerId aMessageId, TContainerId aFolderId, const TDesC8& aPropertyBuf )
       
  1057     {
       
  1058     TRAP_IGNORE( DoMatchFoundL( aMessageId, aFolderId, aPropertyBuf ) );
       
  1059     } // end MatchFound
       
  1060 
       
  1061 // ==========================================================================
       
  1062 // FUNCTION: DoMatchFoundL
       
  1063 // ==========================================================================
       
  1064 void CMessageStoreSession::DoMatchFoundL( TContainerId aMessageId, TContainerId aFolderId, const TDesC8& aPropertyBuf )
       
  1065     {
       
  1066     CSearchResult* result = CSearchResult::NewL( aMessageId, aFolderId, aPropertyBuf );
       
  1067     iMatchMessages.Append( result );
       
  1068 
       
  1069     SendMatchesToClient();
       
  1070     } // end MatchFound
       
  1071 
       
  1072 // ==========================================================================
       
  1073 // FUNCTION: SearchComplete
       
  1074 // ==========================================================================
       
  1075 void CMessageStoreSession::SearchComplete( TInt /*aStatus*/ )
       
  1076     {
       
  1077     //do not delete the search handler
       
  1078     
       
  1079     // Always send the search results if the search has completed, even if there are not results found.
       
  1080     SendMatchesToClient( ETrue );
       
  1081     } // end SearchComplete
       
  1082     
       
  1083 // ==========================================================================
       
  1084 // FUNCTION: SendMatchesToClientL
       
  1085 // ==========================================================================
       
  1086 void CMessageStoreSession::SendMatchesToClient( TBool aAlwaysSend )
       
  1087     {
       
  1088     // If there is a pending GetMatches message and either aAlwaysSend is true or matches were found
       
  1089     // then build a nuffer of matching IDs and send to the client.
       
  1090     
       
  1091     if( !iGetMatchesMessage.IsNull() && (aAlwaysSend || iMatchMessages.Count() > 0 ) )
       
  1092         {
       
  1093         TRAPD( result, DoWriteMatchesToMessageL() );
       
  1094         iGetMatchesMessage.Complete( result );
       
  1095         } // end if
       
  1096 
       
  1097     } // end SendMatchesToClient
       
  1098   
       
  1099   
       
  1100 // ==========================================================================
       
  1101 // FUNCTION: DoWriteMatchesToMessageL
       
  1102 // ==========================================================================
       
  1103 void CMessageStoreSession::DoWriteMatchesToMessageL()
       
  1104     {
       
  1105     __LOG_ENTER_SUPPRESS( "DoWriteMatchesToMessageL" )
       
  1106     
       
  1107     TUint desLength = iGetMatchesMessage.GetDesMaxLengthL( 0 );        
       
  1108     TUint offset = 0;
       
  1109     
       
  1110     TUint fixedLength = sizeof(TContainerId)*2 + sizeof(TUint);  //fixed size: 2 ids and a length
       
  1111     
       
  1112     TInt msgWritten = 0;
       
  1113     
       
  1114     while( iMatchMessages.Count() > 0 && offset < desLength )
       
  1115         {
       
  1116         CSearchResult* result = iMatchMessages[0];
       
  1117         TUint length = result->PropertyBuf().Length();
       
  1118 	    TPckgBuf<TUint> lengthPkg( length );
       
  1119         
       
  1120         if ( desLength - offset >= fixedLength + length )
       
  1121             {
       
  1122             //write the message id
       
  1123             TPckgBuf<TContainerId> idPkg( result->MessageId() );
       
  1124             iGetMatchesMessage.WriteL( 0, idPkg, offset );
       
  1125             offset += sizeof( TContainerId );
       
  1126             
       
  1127             //write the folder id
       
  1128             TPckgBuf<TContainerId> folderIddPkg( result->FolderId() );
       
  1129             iGetMatchesMessage.WriteL( 0, folderIddPkg, offset );
       
  1130             offset += sizeof( TContainerId );
       
  1131 
       
  1132             //write the length
       
  1133             iGetMatchesMessage.WriteL( 0, lengthPkg, offset );
       
  1134             offset += sizeof( TUint );
       
  1135             
       
  1136             if ( length > 0 )
       
  1137                 {
       
  1138                 iGetMatchesMessage.WriteL( 0, result->PropertyBuf(), offset );
       
  1139                 offset += length;
       
  1140                 }
       
  1141             delete result;
       
  1142             iMatchMessages.Remove( 0 );
       
  1143             msgWritten++;
       
  1144             }
       
  1145         else
       
  1146             {
       
  1147             if ( msgWritten == 0 )
       
  1148                 {
       
  1149                 __LOG_WRITE_ERROR("ERR: Client buffer size too small, not enough for even 1 message")
       
  1150                 User::Leave( KErrOverflow );
       
  1151                 }
       
  1152             break;
       
  1153             }
       
  1154         } // end while
       
  1155         
       
  1156     } // end DoWriteMatchesToMessageL
       
  1157 
       
  1158 // -------------------------
       
  1159 // MESSAGE HANDLER FUNCTIONS
       
  1160 // -------------------------
       
  1161 
       
  1162 // ==========================================================================
       
  1163 // FUNCTION: DoAuthenticatedL
       
  1164 // ==========================================================================
       
  1165 void CMessageStoreSession::DoAuthenticatedL( const RMessage2& aMessage )
       
  1166     {
       
  1167     // TIpcArgs( &resultPckg )
       
  1168     
       
  1169     TBool authenticated = iServer.MessageStoreL().Authenticated();
       
  1170 
       
  1171     TPckg<TBool> authenticatedPckg( authenticated );
       
  1172 	aMessage.WriteL( 0, authenticatedPckg );
       
  1173 	
       
  1174 	aMessage.Complete( KErrNone );    
       
  1175     } // end DoAuthenticatedL
       
  1176     
       
  1177 // ==========================================================================
       
  1178 // FUNCTION: DoAuthenticateL
       
  1179 // ==========================================================================
       
  1180 void CMessageStoreSession::DoAuthenticateL( const RMessage2& aMessage )
       
  1181     {
       
  1182     // TIpcArgs( &resultPckg, &aPassword )
       
  1183     
       
  1184 	RBuf password;
       
  1185 	CleanupClosePushL( password );
       
  1186 	password.CreateL( aMessage.GetDesLengthL( 1 ) );
       
  1187 	aMessage.ReadL( 1, password );
       
  1188     
       
  1189     TBool result = iServer.MessageStoreL().AuthenticateL( password );
       
  1190 
       
  1191     CleanupStack::PopAndDestroy( &password );
       
  1192 
       
  1193     TPckg<TBool> resultPckg( result );
       
  1194 	aMessage.WriteL( 0, resultPckg );
       
  1195 
       
  1196 	aMessage.Complete( KErrNone );    
       
  1197     } // end DoAuthenticateL
       
  1198     
       
  1199 // ==========================================================================
       
  1200 // FUNCTION: DoClearAuthenticationL
       
  1201 // ==========================================================================
       
  1202 void CMessageStoreSession::DoClearAuthenticationL( const RMessage2& aMessage )
       
  1203     {
       
  1204     // No arguments
       
  1205     
       
  1206     iServer.MessageStoreL().ClearAuthentication();
       
  1207     
       
  1208 	aMessage.Complete( KErrNone );    
       
  1209     } // end DoClearAuthenticationL
       
  1210     
       
  1211 // ==========================================================================
       
  1212 // FUNCTION: DoHasPasswordL
       
  1213 // ==========================================================================
       
  1214 void CMessageStoreSession::DoHasPasswordL( const RMessage2& aMessage )
       
  1215     {
       
  1216     // TIpcArgs( &resultPckg )
       
  1217     
       
  1218     TBool result = iServer.MessageStoreL().HasPasswordL();
       
  1219 
       
  1220     TPckg<TBool> resultPckg( result );
       
  1221 	aMessage.WriteL( 0, resultPckg );
       
  1222 	
       
  1223 	aMessage.Complete( KErrNone );    
       
  1224     } // end DoHasPasswordL
       
  1225     
       
  1226 // ==========================================================================
       
  1227 // FUNCTION: DoSetPasswordL
       
  1228 // ==========================================================================
       
  1229 void CMessageStoreSession::DoSetPasswordL( const RMessage2& aMessage )
       
  1230     {
       
  1231     // TIpcArgs( &aPassword )
       
  1232     
       
  1233 	RBuf password;
       
  1234 	CleanupClosePushL( password );
       
  1235 	password.CreateL( aMessage.GetDesLengthL( 0 ) );
       
  1236 	aMessage.ReadL( 0, password );
       
  1237     
       
  1238     iServer.MessageStoreL().SetPasswordL( password );
       
  1239 
       
  1240     CleanupStack::PopAndDestroy( &password );
       
  1241 
       
  1242 	aMessage.Complete( KErrNone );    
       
  1243     } // end DoSetPasswordL
       
  1244 
       
  1245 // ==========================================================================
       
  1246 // FUNCTION: DoChangePasswordL
       
  1247 // ==========================================================================
       
  1248 void CMessageStoreSession::DoChangePasswordL( const RMessage2& aMessage )
       
  1249     {
       
  1250     // TIpcArgs( &resultPckg, &aOldPassword, &aNewPassword )
       
  1251     
       
  1252 	RBuf oldPassword;
       
  1253 	CleanupClosePushL( oldPassword );
       
  1254 	oldPassword.CreateL( aMessage.GetDesLengthL( 1 ) );
       
  1255 	aMessage.ReadL( 1, oldPassword );
       
  1256     
       
  1257 	RBuf newPassword;
       
  1258 	CleanupClosePushL( newPassword );
       
  1259 	newPassword.CreateL( aMessage.GetDesLengthL( 2 ) );
       
  1260 	aMessage.ReadL( 2, newPassword );
       
  1261     
       
  1262     TBool result = iServer.MessageStoreL().ChangePasswordL( oldPassword, newPassword );
       
  1263 
       
  1264     CleanupStack::PopAndDestroy( &newPassword );
       
  1265     CleanupStack::PopAndDestroy( &oldPassword );
       
  1266 
       
  1267     TPckg<TBool> resultPckg( result );
       
  1268 	aMessage.WriteL( 0, resultPckg );
       
  1269 
       
  1270 	aMessage.Complete( KErrNone );    
       
  1271     } // end DoChangePasswordL
       
  1272 
       
  1273 // ==========================================================================
       
  1274 // FUNCTION: DoEnableEncryptionL
       
  1275 // ==========================================================================
       
  1276 void CMessageStoreSession::DoEnableEncryptionL( const RMessage2& aMessage )
       
  1277     {
       
  1278     iServer.MessageStoreL().EnableEncryptionL();
       
  1279     
       
  1280     aMessage.Complete( KErrNone );    
       
  1281     }  // end DoEnableEncryptionL
       
  1282 
       
  1283 // ==========================================================================
       
  1284 // FUNCTION: DoDisableEncryptionL
       
  1285 // ==========================================================================
       
  1286 void CMessageStoreSession::DoDisableEncryptionL( const RMessage2& aMessage )
       
  1287     {
       
  1288     iServer.MessageStoreL().DisableEncryptionL();
       
  1289     
       
  1290     aMessage.Complete( KErrNone );    
       
  1291     } // end DoDisableEncryptionL
       
  1292 
       
  1293 // ==========================================================================
       
  1294 // FUNCTION: DoWipeEverythingL
       
  1295 // ==========================================================================
       
  1296 void CMessageStoreSession::DoWipeEverythingL( const RMessage2& aMessage )
       
  1297 	{
       
  1298 	iServer.WipeEverythingL();
       
  1299 	
       
  1300 	aMessage.Complete( KErrNone );
       
  1301 	} // end DoWipeEverythingL
       
  1302 
       
  1303 	
       
  1304 // ==========================================================================
       
  1305 // FUNCTION: DoCreateContainerL
       
  1306 // ==========================================================================
       
  1307 void CMessageStoreSession::DoCreateContainerL( const RMessage2& aMessage )
       
  1308 	{
       
  1309 	__LOG_ENTER( "DoCreateContainerL" )
       
  1310 	
       
  1311 	TMsgStoreCreateContainerCmdParams params;	
       
  1312 	TPckg<TMsgStoreCreateContainerCmdParams> paramsPckg( params );
       
  1313 	aMessage.ReadL( 0, paramsPckg );
       
  1314 	
       
  1315 	RBuf8 propertiesBuf;
       
  1316 	CleanupClosePushL( propertiesBuf );
       
  1317 	propertiesBuf.CreateL( aMessage.GetDesLengthL( 1 ) );
       
  1318 	aMessage.ReadL( 1, propertiesBuf );
       
  1319 	
       
  1320     RFile contentFile;
       
  1321     CleanupClosePushL( contentFile );
       
  1322     if( params.iHasContent )
       
  1323         {        
       
  1324 	    User::LeaveIfError( contentFile.AdoptFromClient( aMessage, 2, KValThree ) );
       
  1325 	    }
       
  1326 
       
  1327     CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  1328     TBool queued = creator.EnqueueL(
       
  1329         iServer.MessageStoreL(), params, propertiesBuf );
       
  1330     
       
  1331     //if the operation is queued then all subsequent and related
       
  1332     //CreateContainerL calls will be queued until the message container is
       
  1333     //committed; "related" are any direct or indirect descendants of the message
       
  1334     //container.
       
  1335     
       
  1336     if ( queued )
       
  1337         {
       
  1338         if( params.iHasContent )
       
  1339             {
       
  1340             TRAPD( err, creator.ReplaceContentL(
       
  1341                 iServer.MessageStoreL(), params.iId, contentFile ) );
       
  1342             
       
  1343             if ( KErrNone != err )
       
  1344                 {
       
  1345                 creator.ResetL( iServer.MessageStoreL() );
       
  1346                 User::Leave( err );
       
  1347                 }
       
  1348             }    
       
  1349         }
       
  1350     else
       
  1351         {
       
  1352         params.iId = iServer.MessageStoreL().CreateContainerL( params.iType, 
       
  1353                                                        params.iParentId, 
       
  1354                                                        params.iGrandparentId, 
       
  1355                                                        propertiesBuf );
       
  1356     
       
  1357         if( params.iHasContent )
       
  1358             {
       
  1359             TRAPD( result, iServer.MessageStoreL().ReplaceContentL( params.iId, 
       
  1360                                                                 params.iParentId, 
       
  1361                                                                 contentFile,
       
  1362                                                                 NULL ) );
       
  1363 
       
  1364             // Abandon the entire container if the content could not be written.
       
  1365             if( result != KErrNone )
       
  1366                 {
       
  1367                 __LOG_WRITE_ERROR( "failed to add content" );
       
  1368                 iServer.MessageStoreL().AbandonContainerL( params.iId );
       
  1369                 User::Leave( result );
       
  1370                 }
       
  1371             }
       
  1372 
       
  1373         if ( params.iCommitContainer )
       
  1374             {
       
  1375             iServer.MessageStoreL().CommitContainerL(
       
  1376                 params.iId, params.iParentId, params.iMailBoxId, this );
       
  1377             }
       
  1378         }
       
  1379    
       
  1380     CleanupStack::PopAndDestroy( &contentFile );
       
  1381     // if queued the ownership was transferred to the message creator.
       
  1382     queued ? CleanupStack::Pop( &propertiesBuf )
       
  1383         : CleanupStack::PopAndDestroy( &propertiesBuf );
       
  1384 	
       
  1385 	aMessage.WriteL( 0, paramsPckg );
       
  1386 	aMessage.Complete( KErrNone );
       
  1387 	
       
  1388 	__LOG_EXIT
       
  1389 	} // end DoCreateContainerL
       
  1390 
       
  1391 // ==========================================================================
       
  1392 // FUNCTION: DoCommitContainerL
       
  1393 // ==========================================================================
       
  1394 void CMessageStoreSession::DoCommitContainerL( const RMessage2& aMessage )
       
  1395     {
       
  1396 	TMsgStoreId id = aMessage.Int0();
       
  1397 	TMsgStoreId destinationId = aMessage.Int1();
       
  1398 	TMsgStoreId mailBoxId = aMessage.Int2();
       
  1399 
       
  1400 	CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  1401 	if ( creator.IsContainerBuffered( id ) )
       
  1402 	    {
       
  1403         creator.CommitMessageL( iServer.MessageStoreL(), this );
       
  1404 	    }
       
  1405 	else
       
  1406 	    {
       
  1407         iServer.MessageStoreL().CommitContainerL(
       
  1408             id, destinationId, mailBoxId, this );
       
  1409 	    }
       
  1410 	
       
  1411     aMessage.Complete( KErrNone );
       
  1412     } // end DoCommitContainerL
       
  1413 
       
  1414 // ==========================================================================
       
  1415 // FUNCTION: DoAbandonContainerL
       
  1416 // ==========================================================================
       
  1417 void CMessageStoreSession::DoAbandonContainerL( const RMessage2& aMessage )
       
  1418     {
       
  1419     // TIpcArgs( aId )    
       
  1420     
       
  1421 	TMsgStoreId id = aMessage.Int0();
       
  1422 
       
  1423 	CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  1424 	if ( creator.IsContainerBuffered( id ) )
       
  1425         {
       
  1426         creator.AbandonMessageL( iServer.MessageStoreL(), id );
       
  1427         }
       
  1428 	else
       
  1429 	    {
       
  1430         iServer.MessageStoreL().AbandonContainerL( id );
       
  1431 	    }
       
  1432     
       
  1433     aMessage.Complete( KErrNone );
       
  1434     } // end DoAbandonContainerL
       
  1435 
       
  1436 // ==========================================================================
       
  1437 // FUNCTION: DoMoveContainerL
       
  1438 // ==========================================================================
       
  1439 void CMessageStoreSession::DoMoveContainerL( const RMessage2& aMessage )
       
  1440 	{
       
  1441 	// TIpcArgs( aId, aSourceId, aDestinationId )
       
  1442 	
       
  1443 	TMsgStoreId id = aMessage.Int0();
       
  1444 
       
  1445 	TMsgStoreId sourceId = aMessage.Int1();
       
  1446 	
       
  1447 	TMsgStoreId destinationId = aMessage.Int2();
       
  1448 
       
  1449 	iServer.MessageStoreL().MoveContainerL( id, sourceId, destinationId, this );
       
  1450 	
       
  1451 	aMessage.Complete( KErrNone );	
       
  1452 	} // end DoMoveContainerL
       
  1453 	
       
  1454 // ==========================================================================
       
  1455 // FUNCTION: DoCopyContainerL
       
  1456 // ==========================================================================
       
  1457 void CMessageStoreSession::DoCopyContainerL( const RMessage2& aMessage )
       
  1458 	{
       
  1459     // TIpcArgs( &paramsPckg, &idPckg )	
       
  1460 
       
  1461 	TMsgStoreCopyContainerCmdParams        params;
       
  1462 	TPckg<TMsgStoreCopyContainerCmdParams> paramsPckg( params );
       
  1463 	aMessage.ReadL( 0, paramsPckg );
       
  1464 	
       
  1465 	TUint newId = iServer.MessageStoreL().CopyContainerL( params.iId,
       
  1466 	                                                      params.iSourceId,
       
  1467 	                                                      params.iSourceParentId,
       
  1468 	                                                      params.iDestinationId,
       
  1469 	                                                      params.iDestinationParentId,
       
  1470 	                                                      params.iMailBoxId,
       
  1471 	                                                      this );
       
  1472 
       
  1473 	TPckg<TMsgStoreId> newIdPckg(newId);
       
  1474 	aMessage.WriteL( 1, newIdPckg );
       
  1475 	
       
  1476 	aMessage.Complete( KErrNone );	
       
  1477 	} // end DoCopyContainerL
       
  1478 	
       
  1479 // ==========================================================================
       
  1480 // FUNCTION: DoFetchPropertiesL
       
  1481 // ==========================================================================
       
  1482 void CMessageStoreSession::DoFetchPropertiesL( const RMessage2& aMessage )
       
  1483 	{
       
  1484 	__LOG_ENTER( "DoFetchPropertiesL" )
       
  1485 	
       
  1486     // TIpcArgs( &params, &parentIdPckg, &aBuffer, &resultPckg );
       
  1487     
       
  1488     TMsgStoreFetchPropertiesCmdParams params;
       
  1489     TPckg<TMsgStoreFetchPropertiesCmdParams> paramsPckg( params );
       
  1490 	aMessage.ReadL( 0, paramsPckg );
       
  1491 
       
  1492 	TMsgStoreId parentId;
       
  1493 	TPckg<TMsgStoreId> parentIdPckg( parentId );
       
  1494 	aMessage.ReadL( 1, parentIdPckg );
       
  1495 	
       
  1496 	TUint result;
       
  1497 	TPckg<TUint> resultPckg( result );
       
  1498 	
       
  1499 	RBuf8 propertiesBuf;
       
  1500 	CleanupClosePushL( propertiesBuf );
       
  1501 
       
  1502 	iServer.MessageStoreL().FetchPropertiesL( params.iId, parentId, params.iGrandparentId, propertiesBuf, params.iMailboxId );
       
  1503 
       
  1504 	if( propertiesBuf.Length() > aMessage.GetDesMaxLengthL( 2 ) )
       
  1505 	    {
       
  1506 	    // Overflow!
       
  1507 	    __LOG_WRITE8_FORMAT1_ERROR( "property buffer too long (%i)", propertiesBuf.Length() );
       
  1508 	    
       
  1509 	    // Write the required length to the result parameter, to indicate to the client that the
       
  1510 	    // buffer must be increased to the given size.
       
  1511 	    result = propertiesBuf.Length();
       
  1512 	    aMessage.WriteL( KValThree, resultPckg );	    
       
  1513 	    }
       
  1514 	else
       
  1515 	    {	    	
       
  1516  	    aMessage.WriteL( 1, parentIdPckg );
       
  1517 
       
  1518         aMessage.WriteL( 2, propertiesBuf );
       
  1519 
       
  1520         result = 0;
       
  1521 	    aMessage.WriteL( KValThree, resultPckg );
       
  1522 	    } // end if
       
  1523 	    	    
       
  1524    	CleanupStack::PopAndDestroy( &propertiesBuf );	
       
  1525 
       
  1526 	aMessage.Complete( KErrNone );
       
  1527 	
       
  1528 	__LOG_EXIT
       
  1529 	} // end DoFetchPropertiesL
       
  1530 
       
  1531 // ==========================================================================
       
  1532 // FUNCTION: DoUpdatePropertiesL
       
  1533 // ==========================================================================
       
  1534 void CMessageStoreSession::DoUpdatePropertiesL( const RMessage2& aMessage )
       
  1535 	{
       
  1536 	// TIpcArgs( aId, aParentId, properties )
       
  1537 
       
  1538 	TMsgStoreId id = aMessage.Int0();
       
  1539 
       
  1540 	TMsgStoreId parentId = aMessage.Int1();
       
  1541 	
       
  1542 	TMsgStoreId mailBoxId = aMessage.Int2();
       
  1543 
       
  1544 	TInt propertiesLength = aMessage.GetDesLengthL( KValThree );
       
  1545 	RBuf8 propertiesBuf;
       
  1546 	CleanupClosePushL( propertiesBuf );
       
  1547 	propertiesBuf.CreateL( propertiesLength );
       
  1548 	aMessage.ReadL( KValThree, propertiesBuf );
       
  1549 
       
  1550 	iServer.MessageStoreL().UpdatePropertiesL( id, parentId, mailBoxId, propertiesBuf, this );
       
  1551 	
       
  1552 	CleanupStack::PopAndDestroy( &propertiesBuf );
       
  1553 	
       
  1554 	aMessage.Complete( KErrNone );
       
  1555 	} // end DoUpdatePropertiesL
       
  1556 
       
  1557 // ==========================================================================
       
  1558 // FUNCTION: DoUpdatePropertyL
       
  1559 // ==========================================================================
       
  1560 void CMessageStoreSession::DoUpdatePropertyL( const RMessage2& aMessage )
       
  1561 	{
       
  1562     // TIpcArgs( &params, &aName, &aValue )    
       
  1563     
       
  1564     TMsgStoreUpdatePropertyCmdParams        params;
       
  1565     TPckg<TMsgStoreUpdatePropertyCmdParams> paramsPckg( params );
       
  1566 	aMessage.ReadL( 0, paramsPckg );
       
  1567 
       
  1568 	RBuf8 nameBuf;
       
  1569 	CleanupClosePushL( nameBuf );
       
  1570 	nameBuf.CreateL( aMessage.GetDesLengthL( 1 ) );
       
  1571 	aMessage.ReadL( 1, nameBuf );
       
  1572 
       
  1573 	RBuf8 valueBuf;
       
  1574 	CleanupClosePushL( valueBuf );
       
  1575 	valueBuf.CreateL( aMessage.GetDesLengthL( 2 ) );
       
  1576 	aMessage.ReadL( 2, valueBuf );
       
  1577 
       
  1578 	iServer.MessageStoreL().UpdatePropertyL( params.iId, params.iParentId, params.iMailBoxId, nameBuf, params.iType, valueBuf, this );
       
  1579 	
       
  1580 	CleanupStack::PopAndDestroy( &valueBuf );
       
  1581 	CleanupStack::PopAndDestroy( &nameBuf );
       
  1582 	
       
  1583 	aMessage.Complete( KErrNone );
       
  1584 	} // end DoUpdatePropertyL
       
  1585 
       
  1586 // ==========================================================================
       
  1587 // FUNCTION: DoChildrenCountsL
       
  1588 // ==========================================================================
       
  1589 void CMessageStoreSession::DoChildrenCountsL( const RMessage2& aMessage )
       
  1590 	{
       
  1591 	// TIpcArgs( aId, &counts )
       
  1592 
       
  1593 	TMsgStoreId id = aMessage.Int0();
       
  1594 
       
  1595 	RBuf8 countsBuf;
       
  1596 	CleanupClosePushL( countsBuf );
       
  1597 	countsBuf.CreateL( KMsgStoreCountsLength );
       
  1598 	
       
  1599 	iServer.MessageStoreL().ChildrenCountsL( id, countsBuf );
       
  1600 		
       
  1601 	aMessage.WriteL( 1, countsBuf );
       
  1602 	
       
  1603 	CleanupStack::PopAndDestroy( &countsBuf );
       
  1604 	
       
  1605 	aMessage.Complete( KErrNone );
       
  1606 	} // end DoChildrenCountsL
       
  1607 
       
  1608 // ==========================================================================
       
  1609 // FUNCTION: DoTotalCountsL
       
  1610 // ==========================================================================
       
  1611 void CMessageStoreSession::DoTotalCountsL( const RMessage2& aMessage )
       
  1612 	{
       
  1613 	// TIpcArgs( &counts )
       
  1614 	
       
  1615 	TMsgStoreId mailBoxId = aMessage.Int0();
       
  1616 
       
  1617 	RBuf8 countsBuf;
       
  1618 	CleanupClosePushL( countsBuf );
       
  1619 	countsBuf.CreateL( KMsgStoreCountsLength );
       
  1620 	
       
  1621 	iServer.MessageStoreL().TotalCountsL( mailBoxId, countsBuf );
       
  1622 		
       
  1623 	aMessage.WriteL( 1, countsBuf );
       
  1624 	
       
  1625 	CleanupStack::PopAndDestroy( &countsBuf );
       
  1626 	
       
  1627 	aMessage.Complete( KErrNone );
       
  1628 	} // end DoTotalCountsL
       
  1629 
       
  1630 // ==========================================================================
       
  1631 // FUNCTION: DoChildrenIdsL
       
  1632 // ==========================================================================
       
  1633 void CMessageStoreSession::DoChildrenIdsL( const RMessage2& aMessage )	
       
  1634 	{
       
  1635 	// TIpcArgs( aId, aType, &childrenDes, &resultBuf )
       
  1636 
       
  1637 	__LOG_ENTER( "DoChildrenIdsL" )
       
  1638 		
       
  1639 	TMsgStoreId id = aMessage.Int0();
       
  1640 
       
  1641 	TMsgStoreId type = aMessage.Int1();
       
  1642 
       
  1643 	RArray<TMsgStoreId> childIds( KGranularity25 );
       
  1644 	CleanupClosePushL( childIds );
       
  1645 	
       
  1646 	TUint result;
       
  1647 	TPckg<TUint> resultPckg( result );
       
  1648 	
       
  1649 	iServer.MessageStoreL().ListChildrenL( childIds, id, KMsgStoreInvalidId, type );
       
  1650 
       
  1651     TUint sizeNeeded = childIds.Count() * sizeof(TMsgStoreId);
       
  1652 
       
  1653     if( sizeNeeded > aMessage.GetDesMaxLengthL( 2 ) )
       
  1654         {
       
  1655 	    // Overflow!
       
  1656 	    __LOG_WRITE8_FORMAT1_ERROR( "children IDs buffer too long (%i)", sizeNeeded );
       
  1657 	    
       
  1658 	    // Write the required length to the result parameter, to indicate to the client that the
       
  1659 	    // buffer must be increased to the given size.
       
  1660         result = sizeNeeded;
       
  1661         aMessage.WriteL( KValThree, resultPckg );        
       
  1662         }
       
  1663     else
       
  1664         {        
       
  1665     	for( TInt count = 0; count < childIds.Count(); count++ )
       
  1666     		{
       
  1667     		TPckg<TMsgStoreId> currentChild( childIds[count] );
       
  1668     		const TUint KFour = 4;
       
  1669     		aMessage.WriteL( 2, currentChild, count*KFour );
       
  1670     		} // end for
       
  1671     		
       
  1672         result = 0;
       
  1673         aMessage.WriteL( KValThree, resultPckg );            		
       
  1674         } // end if
       
  1675         
       
  1676 	CleanupStack::PopAndDestroy( &childIds ); 
       
  1677 	
       
  1678 	aMessage.Complete( KErrNone );
       
  1679 	
       
  1680 	__LOG_EXIT	
       
  1681 	} // end DoChildrenIdsL
       
  1682 
       
  1683 // ==========================================================================
       
  1684 // FUNCTION: DoPropertiesListL
       
  1685 // ==========================================================================
       
  1686 void CMessageStoreSession::DoPropertiesListL( const RMessage2& aMessage )
       
  1687 	{	
       
  1688     // TIpcArgs( &paramsPckg, &idList, &paramNames, &serializedBuf )	
       
  1689     
       
  1690     __LOG_ENTER( "DoPropertiesList" )
       
  1691     
       
  1692 	TMsgStorePropertiesListCmdParams params;
       
  1693 	TPckg<TMsgStorePropertiesListCmdParams> paramsPckg( params );
       
  1694 	aMessage.ReadL( 0, paramsPckg );	
       
  1695 
       
  1696 	TInt position = 0;
       
  1697 
       
  1698    	TMsgStoreId id;
       
  1699 	TPckg<TMsgStoreId> idPckg( id );
       
  1700 
       
  1701    	TMsgStoreId parentId;
       
  1702 	TPckg<TMsgStoreId> parentIdPckg( parentId );
       
  1703     
       
  1704     TUint16 length16;
       
  1705     TPckg<TUint16> length16Pckg( length16 );
       
  1706     
       
  1707     TUint32 length32;
       
  1708     TPckg<TUint32> length32Pckg( length32 );    
       
  1709 
       
  1710 	CContainerStore& messageStore = iServer.MessageStoreL();
       
  1711 
       
  1712 	// Suspend compaction here, to avoid suspension and resumption of compaction for each
       
  1713 	// fetch properties operation.	
       
  1714 	messageStore.SuspendCompactionLC();
       
  1715 
       
  1716 	// Populate the ids and property names lists, if needed.
       
  1717 	
       
  1718 	// params.iStartOver means that the client wants to reset the list
       
  1719 	// iIds.Count == 0 means that the container store has been modified
       
  1720 	if( params.iStartOver || iIds.Count() == 0 )
       
  1721 		{
       
  1722 		__LOG_WRITE_INFO( "Starting over" )
       
  1723 		
       
  1724 		iIds.Reset();
       
  1725 		iPropertyNames.ResetAndDestroy();
       
  1726 
       
  1727 		// Indicate to the client that any existing data should be cleared.		
       
  1728 	    params.iClearExisting = ETrue;
       
  1729 
       
  1730         iUsingQuery = params.iUseQuery;
       
  1731         
       
  1732         if( iUsingQuery )
       
  1733             {
       
  1734             __LOG_WRITE_INFO( "querying for children" )
       
  1735 
       
  1736             TPckg<TMsgStorePropertiesListQueryParams> queryParamsPckg( iQueryParams );    
       
  1737     
       
  1738        		aMessage.ReadL( 1, queryParamsPckg );		
       
  1739             
       
  1740             // Get the list of children IDs whose properties are to be retrieved.        		              		
       
  1741     		messageStore.ListChildrenL( iIds,
       
  1742     		                            iQueryParams.iId,
       
  1743     		                            iQueryParams.iParentId,
       
  1744     		                            iQueryParams.iType,
       
  1745     		                            iQueryParams.iRecursive );
       
  1746             } 
       
  1747         else            
       
  1748             {
       
  1749             __LOG_WRITE_INFO( "deserializing ID list" )
       
  1750 
       
  1751     		// Deserialize the ID list from the message.
       
  1752             ReadIdArrayL( aMessage, 1, iIds );
       
  1753             } // end if
       
  1754             
       
  1755         __LOG_WRITE_INFO( "deserializing property names" )
       
  1756             
       
  1757 		// Deserialize the property names list.
       
  1758         ReadString8ArrayL( aMessage, 2, iPropertyNames );
       
  1759 		}            
       
  1760     else
       
  1761         {
       
  1762         // The client should not clear any properties that have already been received.
       
  1763         params.iClearExisting = EFalse; 
       
  1764 		} // end if
       
  1765 
       
  1766     __LOG_WRITE8_FORMAT1_INFO( "iIds.Count=%i", iIds.Count() )
       
  1767     		    
       
  1768     RBuf8 propertiesBuf;
       
  1769     CleanupClosePushL( propertiesBuf );
       
  1770 
       
  1771     const TUint overhead  = idPckg.Length() + parentIdPckg.Length() + length32Pckg.Length();
       
  1772 	const TUint maxLength = aMessage.GetDesMaxLengthL( 3 );
       
  1773 
       
  1774  	TInt  result;
       
  1775     TBool bufferFull = EFalse;
       
  1776     
       
  1777     position = 0;    
       
  1778 	
       
  1779     // Continue adding properties to the buffer until there are no more properties or the buffer is full.
       
  1780 	while( iIds.Count() > 0 && !bufferFull )
       
  1781 		{
       
  1782 		propertiesBuf.SetLength( 0 );
       
  1783 		id       = iIds[0];
       
  1784 		parentId = KMsgStoreInvalidId;
       
  1785 		if( params.iUseQuery )
       
  1786 		    {
       
  1787     		// Use the fast fetch because the ContainerModified callback will cause the query to be
       
  1788     		// reissued if a potential change to a query item has been made.
       
  1789             TRAP( result, messageStore.FastFetchPropertiesL( id, 
       
  1790                                                              params.iQuickProperties, 
       
  1791                                                              parentId, 
       
  1792                                                              propertiesBuf ) );
       
  1793 		    }
       
  1794 		else
       
  1795 		    {
       
  1796             // Don't want to return properties for deleted items, so don't use the fast fetch.		    
       
  1797             TRAP( result, messageStore.FetchPropertiesL( id, 
       
  1798                                                          parentId,
       
  1799                                                          KMsgStoreInvalidId, 
       
  1800                                                          propertiesBuf ) );
       
  1801 		    } // end if
       
  1802                                
       
  1803         if( result == KErrNone )
       
  1804             {            
       
  1805             // Filter the properties, if needed.
       
  1806             if( iPropertyNames.Count() > 0 )
       
  1807                 {
       
  1808                 // Remove the properties that are not needed.
       
  1809                 TPropertiesSerializer serializer( propertiesBuf );        
       
  1810                 TBool moreProperties = serializer.First();        
       
  1811                 while( moreProperties )        
       
  1812                     {
       
  1813                     TBool found = EFalse;            
       
  1814                     for( TInt i = 0; !found && (i < iPropertyNames.Count()); i++ )
       
  1815                         {
       
  1816                         found = (iPropertyNames[i]->Compare( serializer.Name() ) == 0);
       
  1817                         } // end for                               
       
  1818                     if( found )
       
  1819                         {
       
  1820                         moreProperties = serializer.Next();
       
  1821                         }
       
  1822                     else
       
  1823                         {
       
  1824                         moreProperties = serializer.RemovePropertyL();
       
  1825                         } // end if                
       
  1826                     } // end while   
       
  1827                 } // end if
       
  1828                     
       
  1829             if( position + propertiesBuf.Length() + overhead > maxLength )
       
  1830                 {
       
  1831                 // Insufficient room in the IPC buffer for the current set of properties.
       
  1832                 bufferFull = ETrue;
       
  1833                 }
       
  1834             else
       
  1835                 {
       
  1836                 // Write the current set of properties into the IPC buffer.
       
  1837         		aMessage.WriteL( KValThree, idPckg, position );		
       
  1838         		position += idPckg.Length();
       
  1839         		
       
  1840     		    aMessage.WriteL( KValThree, parentIdPckg, position );
       
  1841         		position += parentIdPckg.Length();		    
       
  1842 
       
  1843         		length32 = propertiesBuf.Length();
       
  1844         		aMessage.WriteL( KValThree, length32Pckg, position );
       
  1845         		position += length32Pckg.Length();
       
  1846 
       
  1847         		aMessage.WriteL( KValThree, propertiesBuf, position );        		
       
  1848         		position += length32;
       
  1849     		
       
  1850     		    iIds.Remove( 0 );
       
  1851 
       
  1852                 } // end if
       
  1853             }
       
  1854         else                            
       
  1855             {
       
  1856     	    __LOG_WRITE8_FORMAT1_ERROR( "failure during DoPropertiesListL %i", result );
       
  1857     	    
       
  1858     	    // This entry couldn't be read for some reason.  Skip past it.
       
  1859    		    iIds.Remove( 0 );
       
  1860     		    
       
  1861             } // end if            
       
  1862 		    
       
  1863 		} // end for
       
  1864 
       
  1865     // If the current set of properties is larger than the transfer buffer then indicate to the client
       
  1866     // that a larger transfer buffer is needed.
       
  1867     params.iNewBufferSize = propertiesBuf.Length() + overhead;
       
  1868 	if( params.iNewBufferSize <= maxLength )
       
  1869 	    {	    
       
  1870         __LOG_WRITE_INFO( "larger buffer needed" )
       
  1871 	    params.iNewBufferSize = 0;	    
       
  1872 	    } // end if
       
  1873 	    
       
  1874 	if( iIds.Count() > 0 )
       
  1875 	    {
       
  1876         __LOG_WRITE_INFO( "more properties" )
       
  1877         
       
  1878 	    // Indicate that there are more properties to stream.
       
  1879 	    params.iMoreProperties = ETrue;
       
  1880 	    }
       
  1881 	else
       
  1882 	    {
       
  1883         __LOG_WRITE_INFO( "no more properties" )
       
  1884         
       
  1885 	    // Indicate that there are no more properties to stream.
       
  1886 	    params.iMoreProperties = EFalse;
       
  1887 	    
       
  1888 	    // free the memory
       
  1889 	    iIds.Reset();  
       
  1890 	    iPropertyNames.ResetAndDestroy();
       
  1891 		} // end if
       
  1892 
       
  1893     CleanupStack::PopAndDestroy( &propertiesBuf );
       
  1894 
       
  1895 	messageStore.ResumeCompaction();
       
  1896 	    		
       
  1897 	// Write the more flag.
       
  1898 	aMessage.WriteL( 0, paramsPckg );
       
  1899 	
       
  1900 	aMessage.Complete( KErrNone );
       
  1901 
       
  1902     __LOG_EXIT	
       
  1903 	} // end DoPropertiesListL
       
  1904 
       
  1905 // ==========================================================================
       
  1906 // FUNCTION: DoContentLengthL
       
  1907 // ==========================================================================
       
  1908 void CMessageStoreSession::DoContentLengthL( const RMessage2& aMessage )
       
  1909 	{
       
  1910 	// TIpcArgs( aId, aParentId, &lengthPckg )
       
  1911 	
       
  1912 	TMsgStoreId id = aMessage.Int0();
       
  1913 	
       
  1914 	TMsgStoreId parentId = aMessage.Int1();
       
  1915 
       
  1916 	TUint length = iServer.MessageStoreL().ContentLengthL( id, parentId );
       
  1917 	
       
  1918 	TPckg<TUint> lengthPckg( length );
       
  1919 	aMessage.WriteL( 2, lengthPckg );
       
  1920 	
       
  1921 	aMessage.Complete( KErrNone );
       
  1922 	} // end DoContentLengthL
       
  1923 	
       
  1924 // ==========================================================================
       
  1925 // FUNCTION: DoFetchContentToBufferL
       
  1926 // ==========================================================================
       
  1927 void CMessageStoreSession::DoFetchContentToBufferL( const RMessage2& aMessage )
       
  1928 	{
       
  1929 	// TIpcArgs( aId, aParentId, &aBuffer, aStartOffset )
       
  1930 	
       
  1931 	TMsgStoreId id = aMessage.Int0();
       
  1932 
       
  1933 	TMsgStoreId parentId = aMessage.Int1();
       
  1934 
       
  1935 	RBuf8 contentBuf;
       
  1936 	CleanupClosePushL( contentBuf );
       
  1937 	contentBuf.CreateL( aMessage.GetDesMaxLengthL( 2 ) );
       
  1938 
       
  1939 	TMsgStoreId startOffset = aMessage.Int3();
       
  1940 		
       
  1941 	iServer.MessageStoreL().FetchContentL( id, parentId, contentBuf, startOffset );
       
  1942 
       
  1943 	aMessage.WriteL( 2, contentBuf );
       
  1944 
       
  1945 	CleanupStack::PopAndDestroy( &contentBuf );
       
  1946 	
       
  1947 	aMessage.Complete( KErrNone );
       
  1948 	} // end DoFetchContentToBufferL
       
  1949 	
       
  1950 // ==========================================================================
       
  1951 // FUNCTION: DoFetchContentToFileL
       
  1952 // ==========================================================================
       
  1953 void CMessageStoreSession::DoFetchContentToFileL( const RMessage2& aMessage )
       
  1954 	{
       
  1955 	// TIpcArgs( aId, aParentId, fs, file )
       
  1956 	
       
  1957 	TMsgStoreId id = aMessage.Int0();
       
  1958 
       
  1959 	TMsgStoreId parentId = aMessage.Int1();
       
  1960 
       
  1961 	RFile file;	
       
  1962 	User::LeaveIfError( file.AdoptFromClient( aMessage, 2, KValThree ) );
       
  1963 	CleanupClosePushL( file );
       
  1964 	
       
  1965 	iServer.MessageStoreL().FetchContentL( id, parentId, file );
       
  1966 
       
  1967 	CleanupStack::PopAndDestroy( &file );
       
  1968 
       
  1969 	aMessage.Complete( KErrNone );
       
  1970 	} // end DoFetchContentToFileL
       
  1971 	
       
  1972 // ==========================================================================
       
  1973 // FUNCTION: DoReplaceContentWithBufferL
       
  1974 // ==========================================================================
       
  1975 void CMessageStoreSession::DoReplaceContentWithBufferL( const RMessage2& aMessage )
       
  1976 	{
       
  1977 	// TIpcArgs( aId, aParentId, &aBuffer )
       
  1978 	
       
  1979 	TMsgStoreId id = aMessage.Int0();
       
  1980 
       
  1981 	TMsgStoreId parentId = aMessage.Int1();
       
  1982 
       
  1983 	RBuf8 contentBuf;
       
  1984 	CleanupClosePushL( contentBuf );
       
  1985 	contentBuf.CreateL( aMessage.GetDesLengthL( 2 ) );
       
  1986 	aMessage.ReadL( 2, contentBuf );
       
  1987 
       
  1988 	CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  1989     if ( creator.IsContainerBuffered( id ) )
       
  1990         {
       
  1991         creator.ReplaceContentL(
       
  1992             iServer.MessageStoreL(), id, contentBuf );
       
  1993         }
       
  1994     else
       
  1995         {
       
  1996         iServer.MessageStoreL().ReplaceContentL(
       
  1997             id, parentId, contentBuf, this );
       
  1998         }
       
  1999     
       
  2000 	CleanupStack::PopAndDestroy( &contentBuf );
       
  2001 
       
  2002 	aMessage.Complete( KErrNone );
       
  2003 	} // end DoReplaceContentWithBufferL
       
  2004 	
       
  2005 // ==========================================================================
       
  2006 // FUNCTION: DoReplaceContentWithFileL
       
  2007 // ==========================================================================
       
  2008 void CMessageStoreSession::DoReplaceContentWithFileL( const RMessage2& aMessage )
       
  2009 	{
       
  2010 	// TIpcArgs( aId, aParentId, fs, file )
       
  2011 	
       
  2012 	TMsgStoreId id = aMessage.Int0();
       
  2013 
       
  2014 	TMsgStoreId parentId = aMessage.Int1();
       
  2015 
       
  2016     RFile file;    
       
  2017     User::LeaveIfError( file.AdoptFromClient( aMessage, 2, KValThree ) );
       
  2018     CleanupClosePushL( file );
       
  2019     	
       
  2020     CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  2021     if ( creator.IsContainerBuffered( id ) )
       
  2022         {
       
  2023         creator.ReplaceContentL(
       
  2024             iServer.MessageStoreL(), id, file );
       
  2025         }
       
  2026     else
       
  2027         {
       
  2028         iServer.MessageStoreL().ReplaceContentL( id, parentId, file, this );
       
  2029         }
       
  2030 
       
  2031 	CleanupStack::PopAndDestroy( &file );
       
  2032 
       
  2033 	aMessage.Complete( KErrNone );
       
  2034 	} // end DoReplaceContentWithFileL
       
  2035 	
       
  2036 // ==========================================================================
       
  2037 // FUNCTION: DoAppendToContentL
       
  2038 // ==========================================================================
       
  2039 void CMessageStoreSession::DoAppendToContentL( const RMessage2& aMessage )
       
  2040 	{
       
  2041 	// TIpcArgs( aId, aParentId, &aContent )
       
  2042 	
       
  2043 	TMsgStoreId id = aMessage.Int0();
       
  2044 
       
  2045 	TMsgStoreId parentId = aMessage.Int1();
       
  2046 
       
  2047 	RBuf8 contentBuf;
       
  2048 	CleanupClosePushL( contentBuf );
       
  2049 	contentBuf.CreateL( aMessage.GetDesLengthL( 2 ) );
       
  2050 	aMessage.ReadL( 2, contentBuf );
       
  2051 
       
  2052 	CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  2053     if ( creator.IsContainerBuffered( id ) )
       
  2054         {
       
  2055         creator.AppendContentL(
       
  2056             iServer.MessageStoreL(), id, contentBuf );
       
  2057         }
       
  2058     else
       
  2059         {
       
  2060         iServer.MessageStoreL().AppendContentL( id, parentId, contentBuf, this );
       
  2061         }
       
  2062 	
       
  2063 	CleanupStack::PopAndDestroy( &contentBuf );
       
  2064 
       
  2065 	aMessage.Complete( KErrNone );
       
  2066 	} // end DoAppendToContentL
       
  2067 	
       
  2068 // ==========================================================================
       
  2069 // FUNCTION: DoPrependToContentL
       
  2070 // ==========================================================================
       
  2071 void CMessageStoreSession::DoPrependToContentL( const RMessage2& aMessage )
       
  2072     {
       
  2073     TMsgStoreId id = aMessage.Int0();
       
  2074     TMsgStoreId parentId = aMessage.Int1();
       
  2075 
       
  2076     RBuf8 contentBuf;
       
  2077     CleanupClosePushL( contentBuf );
       
  2078     contentBuf.CreateL( aMessage.GetDesLengthL( 2 ) );
       
  2079     aMessage.ReadL( 2, contentBuf );
       
  2080     
       
  2081     CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  2082     if ( creator.IsContainerBuffered( id ) )
       
  2083         {
       
  2084         creator.PrependContentL(
       
  2085             iServer.MessageStoreL(), id, contentBuf );
       
  2086         }
       
  2087     else
       
  2088         {
       
  2089         iServer.MessageStoreL().PrependContentL(
       
  2090             id, parentId, contentBuf, this );
       
  2091         }
       
  2092     
       
  2093     CleanupStack::PopAndDestroy( &contentBuf );
       
  2094     aMessage.Complete( KErrNone );
       
  2095     }
       
  2096 
       
  2097 // ==========================================================================
       
  2098 // FUNCTION: DoRemoveContentL
       
  2099 // ==========================================================================
       
  2100 void CMessageStoreSession::DoRemoveContentL( const RMessage2& aMessage )
       
  2101 	{
       
  2102 	// TIpcArgs( aId, aParentId )
       
  2103 	
       
  2104 	TMsgStoreId id = aMessage.Int0();
       
  2105 
       
  2106 	TMsgStoreId parentId = aMessage.Int1();
       
  2107 
       
  2108 	iServer.MessageStoreL().RemoveContentL( id, parentId, this );	
       
  2109 
       
  2110 	aMessage.Complete( KErrNone );
       
  2111 	} // end DoRemoveContentL
       
  2112 
       
  2113 
       
  2114 // ==========================================================================
       
  2115 // FUNCTION: DoOpenContentFile
       
  2116 // ==========================================================================
       
  2117 void CMessageStoreSession::DoOpenContentFileL( const RMessage2& aMessage )
       
  2118     {
       
  2119     TMsgStoreId id = aMessage.Int0();
       
  2120     TMsgStoreId parentId = aMessage.Int1();
       
  2121     
       
  2122     RFs fs;
       
  2123     User::LeaveIfError(fs.Connect());
       
  2124     CleanupClosePushL(fs);                                 //+fs
       
  2125 
       
  2126     User::LeaveIfError(fs.ShareProtected());
       
  2127 
       
  2128     RFile file;
       
  2129     CleanupClosePushL( file );                             //+file
       
  2130     
       
  2131     iServer.MessageStoreL().OpenContentFileL( id, parentId, fs, file );
       
  2132     
       
  2133     // transfer to client: store the RFile handle into the package buffer in slot 2 
       
  2134     // and complete the message with the RFs handle
       
  2135     // This assumes that if TransferToClient() return an error, then
       
  2136     // the standard CServer2::RunError() will complete the message
       
  2137     User::LeaveIfError( file.TransferToClient(aMessage, 2) );
       
  2138     
       
  2139     CleanupStack::PopAndDestroy( &file );
       
  2140     CleanupStack::PopAndDestroy( &fs );
       
  2141     }
       
  2142 
       
  2143 // ==========================================================================
       
  2144 // FUNCTION: DoDeleteContainerL
       
  2145 // ==========================================================================
       
  2146 void CMessageStoreSession::DoDeleteContainerL( const RMessage2& aMessage )
       
  2147 	{
       
  2148 	// TIpcArgs( aId, aParentId, aGrandparentId )
       
  2149 	
       
  2150 	TMsgStoreId id = aMessage.Int0();
       
  2151 	
       
  2152 	TMsgStoreId parentId = aMessage.Int1();
       
  2153 
       
  2154 	TMsgStoreId grandparentId = aMessage.Int2();
       
  2155 	
       
  2156 	TMsgStoreId mailBoxId = aMessage.Int3();
       
  2157 	
       
  2158 	iServer.MessageStoreL().DeleteContainerL( id, parentId, grandparentId, mailBoxId, this );
       
  2159 	
       
  2160 	aMessage.Complete( KErrNone );
       
  2161 	} // end DoDeleteContainerL
       
  2162 
       
  2163 
       
  2164 // -------------------------
       
  2165 // SORTING HANDLER FUNCTIONS
       
  2166 // -------------------------
       
  2167 // ==========================================================================
       
  2168 // FUNCTION: DoStartSortingL
       
  2169 // ==========================================================================
       
  2170 void CMessageStoreSession::DoStartSortingL( const RMessage2& aMessage )
       
  2171     {
       
  2172     __LOG_ENTER( "DoStartSortingL" )
       
  2173     
       
  2174     TMsgStoreSortCriteria sortCriteria;
       
  2175     TPckg<TMsgStoreSortCriteria> paramsPckg( sortCriteria );
       
  2176     aMessage.ReadL( 1, paramsPckg );
       
  2177     
       
  2178     TUint16 length16;
       
  2179     TPckg<TUint16> length16Pckg( length16 );
       
  2180     
       
  2181     // Deserialize the property names list.
       
  2182     ReadString8ArrayL( aMessage, 2, iPropertyNames );
       
  2183     
       
  2184     //parameter 3
       
  2185     TBool inMemorySort = aMessage.Int3();
       
  2186 
       
  2187     TContainerId sessionId = iServer.MessageStoreL().StartSortingL( sortCriteria, iPropertyNames, inMemorySort );
       
  2188     iSortSessionIds.Append( sessionId );
       
  2189     
       
  2190     TPckg<TContainerId> sessionIdPckg( sessionId );
       
  2191     aMessage.WriteL( 0, sessionIdPckg );
       
  2192     
       
  2193     aMessage.Complete( KErrNone );
       
  2194     
       
  2195     __LOG_EXIT
       
  2196     }
       
  2197 
       
  2198 // ==========================================================================
       
  2199 // FUNCTION: DoEndSortingL
       
  2200 // ==========================================================================
       
  2201 void CMessageStoreSession::DoEndSortingL( const RMessage2& aMessage )
       
  2202     {
       
  2203     __LOG_ENTER( "DoEndSortingL" )
       
  2204     
       
  2205     TMsgStoreId sessionId = aMessage.Int0();
       
  2206     
       
  2207     iServer.MessageStoreL().EndSortingL( sessionId );
       
  2208     
       
  2209     TInt index = iSortSessionIds.Find( sessionId );
       
  2210     if ( index != KErrNotFound )
       
  2211         {
       
  2212         iSortSessionIds.Remove( index );
       
  2213         }
       
  2214     
       
  2215     aMessage.Complete( KErrNone );
       
  2216     
       
  2217     __LOG_EXIT
       
  2218     }
       
  2219 
       
  2220 // ==========================================================================
       
  2221 // FUNCTION: GetSortedRowsL
       
  2222 // ==========================================================================
       
  2223 void CMessageStoreSession::DoGetSortedRowsL( const RMessage2& aMessage )
       
  2224     {
       
  2225     __LOG_ENTER( "DoGetSortedRowsL" )
       
  2226     
       
  2227     //param 0   
       
  2228     TUint result;
       
  2229     TPckg<TUint> resultPckg( result );
       
  2230     
       
  2231     //param 1
       
  2232     TMsgStoreGetSortedRowsCmdParams params;
       
  2233     TPckg<TMsgStoreGetSortedRowsCmdParams> paramsPckg( params );
       
  2234     aMessage.ReadL( 1, paramsPckg );
       
  2235     
       
  2236     //param 2
       
  2237     RBuf8 propertiesBuf;
       
  2238     CleanupClosePushL( propertiesBuf );
       
  2239     
       
  2240     //param 3
       
  2241     TBool hasMore;
       
  2242     if ( params.iHasStartWith )
       
  2243         {
       
  2244         RBuf startWith;
       
  2245         CleanupClosePushL( startWith );
       
  2246         
       
  2247         startWith.CreateL( aMessage.GetDesLengthL( KValThree ) );
       
  2248         aMessage.ReadL( KValThree, startWith );
       
  2249         
       
  2250         hasMore = iServer.MessageStoreL().GetSortedRowsL( params, propertiesBuf, startWith );
       
  2251         CleanupStack::PopAndDestroy( &startWith );
       
  2252         }
       
  2253     else
       
  2254         {
       
  2255         hasMore = iServer.MessageStoreL().GetSortedRowsL( params, propertiesBuf );
       
  2256         }
       
  2257     params.iHasMoreRows = hasMore;
       
  2258     
       
  2259     if( propertiesBuf.Length() > aMessage.GetDesMaxLengthL( 2 ) )
       
  2260         {
       
  2261         // Overflow!
       
  2262         __LOG_WRITE8_FORMAT1_ERROR( "property buffer too long (%i)", propertiesBuf.Length() );
       
  2263         
       
  2264         // Write the required length to the result parameter, to indicate to the client that the
       
  2265         // buffer must be increased to the given size.
       
  2266         result = propertiesBuf.Length();
       
  2267         aMessage.WriteL( 0, resultPckg );       
       
  2268         }
       
  2269     else
       
  2270         {           
       
  2271         result = 0;
       
  2272         aMessage.WriteL( 0, resultPckg );
       
  2273         aMessage.WriteL( 1, paramsPckg );
       
  2274         aMessage.WriteL( 2, propertiesBuf );
       
  2275         } // end if
       
  2276     
       
  2277     CleanupStack::PopAndDestroy( &propertiesBuf );
       
  2278     
       
  2279     aMessage.Complete( KErrNone );
       
  2280     
       
  2281     __LOG_EXIT
       
  2282     }
       
  2283 
       
  2284 // ==========================================================================
       
  2285 // FUNCTION: DoGetIteratorGroupCountL
       
  2286 // ==========================================================================
       
  2287 void CMessageStoreSession::DoGetIteratorGroupCountL( const RMessage2& aMessage )
       
  2288     {
       
  2289     __LOG_ENTER("DoGetIteratorGroupCountL")
       
  2290     
       
  2291     //param 0
       
  2292     TMsgStoreId sessionId = aMessage.Int0();
       
  2293     
       
  2294     //param 1
       
  2295     TInt count;
       
  2296     TPckg<TInt> resultPckg( count );
       
  2297     
       
  2298     RArray<TUint> itemsInGroup;
       
  2299     CleanupClosePushL( itemsInGroup );
       
  2300     
       
  2301     count = iServer.MessageStoreL().IteratorGroupCountL( sessionId, itemsInGroup );
       
  2302     aMessage.WriteL( 1, resultPckg );
       
  2303     
       
  2304     TUint items;
       
  2305     TPckg<TUint> itemsPkg( items );
       
  2306     TInt position = 0;
       
  2307     
       
  2308     for ( TInt i = 0; i < count; i++ )
       
  2309         {
       
  2310         items = itemsInGroup[i];
       
  2311         aMessage.WriteL( 2, itemsPkg, position );     
       
  2312         position += itemsPkg.Length();
       
  2313         }
       
  2314     
       
  2315     CleanupStack::PopAndDestroy( &itemsInGroup );
       
  2316     
       
  2317     aMessage.Complete( KErrNone );
       
  2318     
       
  2319     __LOG_EXIT
       
  2320     }
       
  2321 
       
  2322 // ==========================================================================
       
  2323 // FUNCTION: DoGetSortedIdsAndFlagsL
       
  2324 // ==========================================================================
       
  2325 void CMessageStoreSession::DoGetSortedIdsAndFlagsL( const RMessage2& aMessage )
       
  2326 	{
       
  2327     __LOG_ENTER("DoGetSortedIdsAndFlags")
       
  2328     
       
  2329     //param 0
       
  2330     TMsgStoreId sessionId = aMessage.Int0();
       
  2331     
       
  2332     //param 1
       
  2333     TInt count;
       
  2334     TPckg<TInt> countPckg( count );
       
  2335     
       
  2336     RArray<TContainerId> idArray( KSortedArrayGranularity );
       
  2337     CleanupClosePushL( idArray );
       
  2338     
       
  2339     RArray<TUint32> flagArray ( KSortedArrayGranularity );
       
  2340     CleanupClosePushL( flagArray );
       
  2341     
       
  2342     iServer.MessageStoreL().SortedIdsAndFlagsL( sessionId, idArray, flagArray );
       
  2343     if ( idArray.Count() != flagArray.Count() )
       
  2344     	{
       
  2345     	User::Leave( KErrCorrupt );
       
  2346     	}
       
  2347     count = idArray.Count();
       
  2348     aMessage.WriteL( 1, countPckg );
       
  2349     
       
  2350     TContainerId id;
       
  2351     TPckg<TContainerId> idPkg( id );
       
  2352     
       
  2353     TUint32 flag;
       
  2354     TPckg<TUint32> flagPkg( flag );
       
  2355     
       
  2356     TInt position = 0;
       
  2357     
       
  2358     for ( TInt i = 0; i < count; i++ )
       
  2359         {
       
  2360         id = idArray[i];
       
  2361         aMessage.WriteL( 2, idPkg, position );     
       
  2362         position += idPkg.Length();
       
  2363         
       
  2364         flag = flagArray[i];
       
  2365         aMessage.WriteL( 2, flagPkg, position );     
       
  2366         position += flagPkg.Length();
       
  2367         }
       
  2368     
       
  2369     CleanupStack::PopAndDestroy( &flagArray );
       
  2370     CleanupStack::PopAndDestroy( &idArray );
       
  2371     
       
  2372     aMessage.Complete( KErrNone );
       
  2373     
       
  2374     __LOG_EXIT
       
  2375 	}
       
  2376 
       
  2377 
       
  2378 // ==========================================================================
       
  2379 // FUNCTION: DoGetSortedIndexOfL
       
  2380 // ==========================================================================
       
  2381 void CMessageStoreSession::DoGetSortedIndexOfL( const RMessage2& aMessage )
       
  2382     {
       
  2383     __LOG_ENTER("DoGetSortedIndexOfL")
       
  2384     
       
  2385     //param 0
       
  2386     TContainerId sessionId = aMessage.Int0();
       
  2387     
       
  2388     //param 1
       
  2389     TContainerId messageId = aMessage.Int1();
       
  2390     
       
  2391     //param 2
       
  2392     TInt index;
       
  2393     TPckg<TInt> indexPckg( index );
       
  2394     
       
  2395     index = iServer.MessageStoreL().SortedIndexOfL( sessionId, messageId );
       
  2396     
       
  2397     aMessage.WriteL( 2, indexPckg );
       
  2398     
       
  2399     aMessage.Complete( KErrNone );
       
  2400     
       
  2401     __LOG_EXIT
       
  2402     }
       
  2403 
       
  2404 // ==========================================================================
       
  2405 // FUNCTION: DoGetSortedIdsL
       
  2406 // ==========================================================================
       
  2407 void CMessageStoreSession::DoGetSortedIdsL( const RMessage2& aMessage )
       
  2408 	{
       
  2409     __LOG_ENTER("DoGetSortedIdsL")
       
  2410     
       
  2411     //param 0
       
  2412     TMsgStoreId sessionId = aMessage.Int0();
       
  2413     
       
  2414     //param 1
       
  2415     TInt count;
       
  2416     TPckg<TInt> countPckg( count );
       
  2417     
       
  2418     RArray<TContainerId> idArray( KSortedArrayGranularity );
       
  2419     CleanupClosePushL( idArray );
       
  2420     
       
  2421     iServer.MessageStoreL().SortedIdsL( sessionId, idArray );
       
  2422     count = idArray.Count();
       
  2423     aMessage.WriteL( 1, countPckg );
       
  2424     
       
  2425     TContainerId id;
       
  2426     TPckg<TContainerId> idPkg( id );
       
  2427     
       
  2428     TInt position = 0;
       
  2429     
       
  2430     for ( TInt i = 0; i < count; i++ )
       
  2431         {
       
  2432         id = idArray[i];
       
  2433         aMessage.WriteL( 2, idPkg, position );     
       
  2434         position += idPkg.Length();
       
  2435         }
       
  2436     
       
  2437     CleanupStack::PopAndDestroy( &idArray );
       
  2438     
       
  2439     aMessage.Complete( KErrNone );
       
  2440     
       
  2441     __LOG_EXIT
       
  2442 	}
       
  2443 
       
  2444 
       
  2445 // ==========================================================================
       
  2446 // FUNCTION: DoGetSortedIdsAndGroupCountL
       
  2447 // ==========================================================================
       
  2448 void CMessageStoreSession::DoGetSortedIdsAndGroupCountL( const RMessage2& aMessage )
       
  2449     {
       
  2450     __LOG_ENTER("DoGetSortedIdsAndGroupCountL")
       
  2451     
       
  2452     //param 0
       
  2453     TMsgStoreId sessionId = aMessage.Int0();
       
  2454     
       
  2455     //param 1
       
  2456     TInt idCount;
       
  2457     TPckg<TInt> idCountPckg( idCount );
       
  2458     
       
  2459     //param 2
       
  2460     TInt groupCount;
       
  2461     TPckg<TInt> groupCountPckg( groupCount );
       
  2462     
       
  2463     RArray<TContainerId> idArray( KSortedArrayGranularity );
       
  2464     CleanupClosePushL( idArray );
       
  2465     
       
  2466     RArray<TUint> itemsInGroup;
       
  2467     CleanupClosePushL( itemsInGroup );
       
  2468     
       
  2469     iServer.MessageStoreL().SortedIdsAndGroupCountL( sessionId, idArray, itemsInGroup );
       
  2470     
       
  2471     idCount = idArray.Count();
       
  2472     aMessage.WriteL( 1, idCountPckg );
       
  2473     
       
  2474     groupCount = itemsInGroup.Count();
       
  2475     aMessage.WriteL( 2, groupCountPckg );
       
  2476     
       
  2477     TContainerId id;
       
  2478     TPckg<TContainerId> idPkg( id );
       
  2479     
       
  2480     TInt position = 0;
       
  2481     
       
  2482     for ( TInt i = 0; i < idCount; i++ )
       
  2483         {
       
  2484         id = idArray[i];
       
  2485         aMessage.WriteL( KValThree, idPkg, position );     
       
  2486         position += idPkg.Length();
       
  2487         }
       
  2488     
       
  2489     TUint items;
       
  2490     TPckg<TUint> itemsPkg( items );
       
  2491     
       
  2492     for ( TInt i = 0 ; i < groupCount ; i++ )
       
  2493         {
       
  2494         items = itemsInGroup[i];
       
  2495         aMessage.WriteL( KValThree, itemsPkg, position );     
       
  2496         position += itemsPkg.Length();
       
  2497         }
       
  2498     
       
  2499     CleanupStack::PopAndDestroy( &itemsInGroup );
       
  2500     CleanupStack::PopAndDestroy( &idArray );
       
  2501     
       
  2502     aMessage.Complete( KErrNone );
       
  2503     
       
  2504     __LOG_EXIT
       
  2505     }
       
  2506 
       
  2507 // ==========================================================================
       
  2508 // FUNCTION: DoSetMaxMruAdressCountL
       
  2509 // ==========================================================================
       
  2510 void CMessageStoreSession::DoSetMaxMruAdressCountL( const RMessage2& aMessage )
       
  2511     {
       
  2512     __LOG_ENTER("DoSetMaxMruAdressCountL")
       
  2513     
       
  2514     TInt maxCount = aMessage.Int0();
       
  2515     
       
  2516     iServer.MessageStoreL().SetMaxMruCountL( maxCount );
       
  2517     
       
  2518     aMessage.Complete( KErrNone );
       
  2519     
       
  2520     __LOG_EXIT
       
  2521     }
       
  2522 
       
  2523 // ==========================================================================
       
  2524 // FUNCTION: DoSetMruAddressListL
       
  2525 // ==========================================================================
       
  2526 void CMessageStoreSession::DoSetMruAddressListL( const RMessage2& aMessage )
       
  2527     {
       
  2528     __LOG_ENTER("DoSetMruAddressListL")
       
  2529     
       
  2530     TMsgStoreId mailboxId = aMessage.Int0();
       
  2531     
       
  2532     iMruAddressArray.ResetAndDestroy();
       
  2533     
       
  2534     //read the address array
       
  2535     TInt bufSize = aMessage.GetDesLengthL( 1 );
       
  2536     
       
  2537     TUint16 length16;
       
  2538     TPckg<TUint16> length16Pckg( length16 );
       
  2539     
       
  2540     RBuf8 addressBuf;
       
  2541     CleanupClosePushL( addressBuf );
       
  2542     addressBuf.Create( KInitialAddressBufSize );
       
  2543     
       
  2544     RBuf8 dispNameBuf;
       
  2545     CleanupClosePushL( dispNameBuf );
       
  2546     dispNameBuf.Create( KInitialAddressBufSize );
       
  2547     
       
  2548     TInt position = 0;
       
  2549     while( position < bufSize )
       
  2550         {
       
  2551         //read the email address
       
  2552         aMessage.ReadL( 1, length16Pckg, position ); 
       
  2553         position += length16Pckg.Length();
       
  2554         
       
  2555         if ( addressBuf.MaxLength() < length16 )
       
  2556             {
       
  2557             addressBuf.ReAlloc( length16 );
       
  2558             }
       
  2559         aMessage.ReadL( 1, addressBuf, position );
       
  2560         
       
  2561         //now read convert the 8 bit descriptor to 16 descriptor
       
  2562         const TUint16* addressPtr = reinterpret_cast<const TUint16*>( addressBuf.Ptr() );
       
  2563         TPtrC addressDes( addressPtr, length16 / 2 );  
       
  2564         
       
  2565         position += length16;
       
  2566 
       
  2567         //read the display name
       
  2568         aMessage.ReadL( 1, length16Pckg, position ); 
       
  2569         position += length16Pckg.Length();
       
  2570         
       
  2571         if ( dispNameBuf.MaxLength() < length16 )
       
  2572             {
       
  2573             dispNameBuf.ReAlloc( length16 );
       
  2574             }
       
  2575         aMessage.ReadL( 1, dispNameBuf, position );
       
  2576         
       
  2577         //now read convert the 8 bit descriptor to 16 descriptor
       
  2578         const TUint16* dispNamePtr = reinterpret_cast<const TUint16*>( dispNameBuf.Ptr() );
       
  2579         TPtrC dispNameDes( dispNamePtr, length16 / 2 );  
       
  2580         
       
  2581         position += length16;
       
  2582         
       
  2583         CMruAddress* mruAddress = CMruAddress::NewL(0, addressDes, dispNameDes );
       
  2584         
       
  2585         iMruAddressArray.Append( mruAddress );
       
  2586         
       
  2587         } // end while
       
  2588     
       
  2589     iServer.MessageStoreL().SetMruAddressListL( mailboxId, iMruAddressArray );
       
  2590     
       
  2591     CleanupStack::PopAndDestroy( &dispNameBuf );
       
  2592     CleanupStack::PopAndDestroy( &addressBuf );
       
  2593     
       
  2594     iMruAddressArray.ResetAndDestroy();
       
  2595     
       
  2596     aMessage.Complete( KErrNone );
       
  2597     
       
  2598     __LOG_EXIT
       
  2599     }
       
  2600 
       
  2601 // ==========================================================================
       
  2602 // FUNCTION: DoGetMruAddressListL
       
  2603 // ==========================================================================
       
  2604 void CMessageStoreSession::DoGetMruAddressListL( const RMessage2& aMessage )
       
  2605     {
       
  2606     __LOG_ENTER("DoGetMruAddressListL")
       
  2607     
       
  2608     TUint result;
       
  2609     TPckg<TUint> resultPckg( result );
       
  2610     
       
  2611     TMsgStoreId mailboxId = aMessage.Int0();
       
  2612     
       
  2613     const RPointerArray<CMruAddress> addressArray = iServer.MessageStoreL().MruAddressListL( mailboxId );
       
  2614     
       
  2615     TUint16 length16;
       
  2616     TPckg<TUint16> length16Pckg( length16 );
       
  2617     
       
  2618     //Find out the size
       
  2619     TInt totalSize = 0;
       
  2620     TInt count = addressArray.Count();
       
  2621     TInt sizeOfLengthFields = sizeof( TUint16 ) * 2;  //two lengths
       
  2622     for ( TInt i = 0 ; i < count ; i++ )
       
  2623         {
       
  2624         totalSize += sizeOfLengthFields;
       
  2625         CMruAddress* address = addressArray[i];
       
  2626         totalSize += (address->EmailAddress().Length() * 2);
       
  2627         totalSize += (address->DisplayName().Length() * 2);
       
  2628         }
       
  2629     
       
  2630     //now check if the client buffer is big enough
       
  2631     if ( totalSize > aMessage.GetDesMaxLengthL( 2 ) )
       
  2632         {
       
  2633         // Overflow!
       
  2634         __LOG_WRITE8_FORMAT1_ERROR( "Mru buffer too long (%i)", totalSize );
       
  2635         
       
  2636         // Write the required length to the result parameter, to indicate to the client that the
       
  2637         // buffer must be increased to the given size.
       
  2638         result = static_cast<TUint>(totalSize);
       
  2639         aMessage.WriteL( 1, resultPckg );       
       
  2640         }
       
  2641     else
       
  2642         {
       
  2643         //now serialize it to the buffer
       
  2644         TUint position = 0;
       
  2645         
       
  2646         for ( TInt i = 0 ; i < count ; i++ )
       
  2647             {
       
  2648             CMruAddress* address = addressArray[i];
       
  2649             
       
  2650             //write the email address
       
  2651             //write the length and update the cursor
       
  2652             length16 = address->EmailAddress().Length() * 2 ;
       
  2653             aMessage.Write( 2, length16Pckg, position );
       
  2654             position += length16Pckg.Length();
       
  2655             
       
  2656             //convert the 16 bit descriptor to 8 bit descriptor
       
  2657             const TUint8* addressPtr = reinterpret_cast<const TUint8*>( address->EmailAddress().Ptr() );
       
  2658             TPtrC8 addressDes( addressPtr, length16 );  
       
  2659 
       
  2660             //write it and update the cursor
       
  2661             aMessage.Write( 2, addressDes, position );
       
  2662             position += length16;
       
  2663             
       
  2664             //write the displayName
       
  2665             //write the length and update the cursor
       
  2666             length16 = address->DisplayName().Length() * 2 ;
       
  2667             aMessage.Write( 2, length16Pckg, position );
       
  2668             position += length16Pckg.Length();
       
  2669             
       
  2670             //convert the 16 bit descriptor to 8 bit descriptor
       
  2671             const TUint8* namePtr = reinterpret_cast<const TUint8*>( address->DisplayName().Ptr() );
       
  2672             TPtrC8 nameDes( namePtr, length16 );  
       
  2673             
       
  2674             //write it and update the cursor
       
  2675             aMessage.Write( 2, nameDes, position );
       
  2676             position += length16;
       
  2677             }
       
  2678         
       
  2679         result = 0;
       
  2680         aMessage.WriteL( 1, resultPckg );       
       
  2681         }    
       
  2682     
       
  2683     aMessage.Complete( KErrNone );
       
  2684     
       
  2685     __LOG_EXIT
       
  2686     }
       
  2687 
       
  2688 /**
       
  2689  * 
       
  2690  */
       
  2691 void CMessageStoreSession::DoBeginBatchInsertL( const RMessage2& aMessage )
       
  2692     {
       
  2693     CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  2694     creator.BeginBatchInsertL( iServer.MessageStoreL() );
       
  2695     
       
  2696     aMessage.Complete( KErrNone );
       
  2697     }
       
  2698 
       
  2699 /**
       
  2700  * 
       
  2701  */
       
  2702 void CMessageStoreSession::DoFinishBatchInsertL( const RMessage2& aMessage )
       
  2703     {
       
  2704     CBufferedMessageCreator& creator = GetBufferedMessageCreatorL();
       
  2705     creator.FinishBatchInsertL( iServer.MessageStoreL(), this );
       
  2706     
       
  2707     aMessage.Complete( KErrNone );
       
  2708     }
       
  2709 
       
  2710 // ==========================================================================
       
  2711 // FUNCTION: ReadString8ArrayL
       
  2712 // ==========================================================================
       
  2713 void CMessageStoreSession::ReadString8ArrayL(  const RMessage2& aMessage, TInt aIndex, RPointerArray<HBufC8>& aArray )
       
  2714     {
       
  2715     TUint16 length16;
       
  2716     TPckg<TUint16> length16Pckg( length16 );
       
  2717     
       
  2718     // Deserialize the property names list.
       
  2719     aArray.ResetAndDestroy();
       
  2720     
       
  2721     TInt position = 0;
       
  2722     while( position < aMessage.GetDesLengthL( aIndex ) )
       
  2723         {
       
  2724         aMessage.ReadL( aIndex, length16Pckg, position );        
       
  2725         position += length16Pckg.Length();
       
  2726         
       
  2727         HBufC8* buf8 = HBufC8::NewL( length16 );            
       
  2728         aArray.Append( buf8 );
       
  2729         TPtr8 buf8Ptr( buf8->Des() );
       
  2730         aMessage.ReadL( aIndex, buf8Ptr, position );
       
  2731         buf8->Des().SetLength( length16 ); 
       
  2732         position += length16;
       
  2733         } // end while
       
  2734     }
       
  2735 
       
  2736 // ==========================================================================
       
  2737 // FUNCTION: ReadString16ArrayL
       
  2738 // ==========================================================================
       
  2739 void CMessageStoreSession::ReadString16ArrayL(  const RMessage2& aMessage, TInt aIndex, RPointerArray<HBufC>& aArray )
       
  2740     {
       
  2741     TUint16 length16;
       
  2742     TPckg<TUint16> length16Pckg( length16 );
       
  2743     
       
  2744     // Deserialize the property names list.
       
  2745     aArray.ResetAndDestroy();
       
  2746     
       
  2747     RBuf8 readBuf;
       
  2748     CleanupClosePushL( readBuf );
       
  2749     
       
  2750     TInt position = 0;
       
  2751     while( position < aMessage.GetDesLengthL( aIndex ) )
       
  2752         {
       
  2753         aMessage.ReadL( aIndex, length16Pckg, position );        
       
  2754         position += length16Pckg.Length();
       
  2755         
       
  2756         if ( readBuf.MaxLength() < length16 )
       
  2757             {
       
  2758             readBuf.ReAlloc( length16 );
       
  2759             }
       
  2760         aMessage.ReadL( aIndex, readBuf, position );
       
  2761         
       
  2762         //now read convert the 8 bit descriptor to 16 descriptor
       
  2763         const TUint16* valuePtr = reinterpret_cast<const TUint16*>( readBuf.Ptr() );
       
  2764         TPtrC valueDes( valuePtr, length16 / 2 );  
       
  2765         
       
  2766         aArray.Append( valueDes.AllocL() );
       
  2767         
       
  2768         position += length16;
       
  2769         } // end while
       
  2770     
       
  2771     CleanupStack::PopAndDestroy( &readBuf );
       
  2772     }
       
  2773 
       
  2774 // ==========================================================================
       
  2775 // FUNCTION: ReadIdArrayL
       
  2776 // ==========================================================================
       
  2777 void CMessageStoreSession::ReadIdArrayL( const RMessage2& aMessage, TInt aIndex, RArray<TContainerId>& aArray )
       
  2778     {
       
  2779     TMsgStoreId id;
       
  2780     TPckg<TMsgStoreId> idPckg( id );
       
  2781     TInt position = 0;
       
  2782 
       
  2783     aArray.Reset();
       
  2784     for( position = 0; position < aMessage.GetDesLengthL( aIndex ); position += idPckg.Length() )
       
  2785         {
       
  2786         aMessage.ReadL( aIndex, idPckg, position );      
       
  2787         aArray.Append( id );
       
  2788         } // end for
       
  2789     }
       
  2790 
       
  2791 /**
       
  2792  * 
       
  2793  */
       
  2794 /*private*/
       
  2795 CBufferedMessageCreator& CMessageStoreSession::GetBufferedMessageCreatorL()
       
  2796     {
       
  2797     if ( NULL == iBufferedMessageCreator )
       
  2798         {
       
  2799         iBufferedMessageCreator = CBufferedMessageCreator::NewL(
       
  2800             iServer.MessageStoreL() );
       
  2801         }
       
  2802     
       
  2803     return *iBufferedMessageCreator;
       
  2804     }
       
  2805 
       
  2806 // FUNCTIONS TO SUPPORT AUTOMATED UNIT TESTING
       
  2807 #ifdef _DEBUG
       
  2808 
       
  2809 void CMessageStoreSession::DoInjectBackupRestoreEventL( const RMessage2& aMessage )
       
  2810     {
       
  2811     // parameter 1 contains the event to inject
       
  2812 	TUint event = aMessage.Int0();
       
  2813     iServer.InjectBackupRestoreEventL( event );
       
  2814     aMessage.Complete( KErrNone );
       
  2815     }
       
  2816 
       
  2817 void CMessageStoreSession::DoInjectPointSecEvent( const RMessage2& aMessage )
       
  2818     {
       
  2819     // parameter 1 contains the event to inject
       
  2820     TUint event = aMessage.Int0();
       
  2821     iServer.InjectPointSecEvent( event );
       
  2822     aMessage.Complete( KErrNone );
       
  2823     }
       
  2824 	
       
  2825 void CMessageStoreSession::DoSimulateLowDiskSpaceL( const RMessage2& aMessage )
       
  2826     {    
       
  2827     // parameter 1 contains the number of calls to delay before indicating low disk space.
       
  2828 	TUint latency = aMessage.Int0();
       
  2829     iServer.MessageStoreL().SimulateLowDiskSpace( latency );
       
  2830     aMessage.Complete( KErrNone );
       
  2831     }
       
  2832 
       
  2833 void CMessageStoreSession::DoGetEncryptionStateL( const RMessage2& aMessage )
       
  2834     {
       
  2835     TInt state = iServer.MessageStoreL().GetEncryptionStateL();
       
  2836     
       
  2837     TPckg<TInt> statePckg( state );
       
  2838     aMessage.WriteL( 0, statePckg );
       
  2839     
       
  2840     aMessage.Complete( KErrNone );
       
  2841     }
       
  2842 
       
  2843 void CMessageStoreSession::DoShutdownServer( const RMessage2& aMessage )
       
  2844     {
       
  2845     aMessage.Complete( KErrNone );
       
  2846     iServer.Shutdown();
       
  2847     }
       
  2848 
       
  2849 #endif