emailservices/emailstore/message_store/client/src/RMessageStoreSession.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Message store session client implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ========
       
    21 // INCLUDES
       
    22 // ========
       
    23 
       
    24 #include <s32mem.h>  // for descriptor read/write streams
       
    25 #include <f32file.h>
       
    26 
       
    27 #include "RMessageStoreSession.h"
       
    28 
       
    29 #include "EmailStoreUids.hrh"
       
    30 #include "MessageStoreClientServer.h"
       
    31 #include "RMessageStoreSession.h"
       
    32 //<cmail>
       
    33 #include "MsgStoreAccount.h"
       
    34 #include "AccountsSerializer.h"
       
    35 #include "MsgStoreSortCriteria.h"
       
    36 #include "MsgStoreSearchCriteria.h"
       
    37 #include "MsgStoreAddress.h"
       
    38 //</cmail>
       
    39 
       
    40 // =========
       
    41 // CONSTANTS
       
    42 // =========
       
    43 
       
    44 const TUint KInitialChildrenIdsTransferBufferLength    = 5000;
       
    45 const TUint KInitialPropertiesTransferBufferLength     = 10000;
       
    46 const TUint KInitialPropertiesListTransferBufferLength = 15000;
       
    47 const TUint KInitialAccountsTransferBufferLength       = 10000;  //shoud be more than enouth
       
    48 const TUint KInitialSortedListTransferBufferLength     = 30000;
       
    49 const TUint KInitialSortedIdsAndFlagsBufferLength      = 65536;  //shoud be more than enouth
       
    50 
       
    51 // This will try to connect to the server for a maximum of 20 seconds.
       
    52 const TUint KMaxServerConnectRetries         = 20;
       
    53 const TUint KServerRetryIntervalMicroSeconds = 1000000;
       
    54 
       
    55 const TUint KNumSlots = 3;
       
    56 
       
    57 const TUint KIpcArgsIndex2 = 2;
       
    58 const TUint KIpcArgsIndex3 = 3;
       
    59 
       
    60 // ======================
       
    61 // METHOD IMPLEMENTATIONS
       
    62 // ======================
       
    63 
       
    64 // ==========================================================================
       
    65 // FUNCTION: Constructor
       
    66 // ==========================================================================
       
    67 RMessageStoreSession::RMessageStoreSession()
       
    68     {
       
    69     __LOG_CONSTRUCT( "MsgClient", "RMessageStoreSession" )
       
    70     } // end constructor
       
    71 
       
    72 // ==========================================================================
       
    73 // FUNCTION: Destructor
       
    74 // ==========================================================================
       
    75 RMessageStoreSession::~RMessageStoreSession()
       
    76     {
       
    77     __LOG_DESTRUCT
       
    78     } // end destructor
       
    79 
       
    80 // ==========================================================================
       
    81 // FUNCTION: Connect
       
    82 // ==========================================================================
       
    83 TInt RMessageStoreSession::Connect( TBool aLaunchServerIfNeeded, TBool aRetryIndefinitely )
       
    84     {
       
    85     __LOG_ENTER( "Connect" )
       
    86 
       
    87     // This flag should only be used in the case where the message store server is being launched as a separate
       
    88     // thread within some other process.  In that case, the flag is used to control exactly which process the
       
    89     // server will be launched in.  Otherwise, always launch the server on reference.
       
    90     aLaunchServerIfNeeded = ETrue;
       
    91 
       
    92     TBool again = ETrue;    
       
    93     TInt  returnValue;
       
    94     TInt  retry = KMaxServerConnectRetries;
       
    95     
       
    96     while( again )
       
    97         {
       
    98         returnValue = CreateSession( KMsgStoreServerName, TVersion(KMsgStoreMajorVersion, KMsgStoreMinorVersion, KMsgStoreBuild), KNumSlots );
       
    99         
       
   100         if( returnValue == KErrNone )
       
   101             {
       
   102             // No need to retry.
       
   103             again = EFalse;            
       
   104             }
       
   105         else
       
   106             {
       
   107             __LOG_WRITE8_FORMAT1_ERROR( "CreateSession failed %i", returnValue )
       
   108             
       
   109             if( !aRetryIndefinitely )
       
   110                 {                
       
   111                 retry--;
       
   112                 } // end if
       
   113             
       
   114             if( retry == 0 )
       
   115                 {
       
   116                 // Do not retry again.
       
   117                 again = EFalse;
       
   118                 }
       
   119             else if( (returnValue == KErrNotFound) && aLaunchServerIfNeeded )
       
   120                 {
       
   121                 // Start the server as a thread within the current process.            
       
   122                 returnValue = StartServer();
       
   123                 }
       
   124             else
       
   125                 {
       
   126                 __LOG_WRITE_ERROR( "waiting between retries" )
       
   127                 
       
   128                 // Wait before trying again.
       
   129                 User::After( KServerRetryIntervalMicroSeconds );                             
       
   130                 
       
   131                 } // end if
       
   132 
       
   133             } // end if
       
   134             
       
   135         } // end if
       
   136     
       
   137     __LOG_WRITE8_FORMAT1_DEBUG3( "returnValue=%i", returnValue )    
       
   138     __LOG_EXIT
       
   139     return returnValue;
       
   140         
       
   141     } // end Connect
       
   142   
       
   143 // ==========================================================================
       
   144 // FUNCTION: StartServer
       
   145 // ==========================================================================
       
   146 TInt RMessageStoreSession::StartServer()
       
   147     {
       
   148     __LOG_ENTER( "StartServer" )
       
   149     
       
   150     TInt err = KErrNone;
       
   151     
       
   152     // Launch the server executable (i.e. in it its own process).
       
   153      __LOG_WRITE_INFO( "Launching server process" )
       
   154         
       
   155     // Create a new server process. Simultaneous launching of two such processes 
       
   156     // should be detected when the second one attempts to create the server 
       
   157     // object, failing with KErrAlreadyExists.
       
   158    _LIT( KMsgStoreExeName, "MessageStoreExe" );
       
   159     RProcess server;
       
   160     err = server.Create( KMsgStoreExeName, KNullDesC ); 
       
   161     
       
   162     if( err == KErrNone )
       
   163         {
       
   164         TRequestStatus stat;
       
   165         server.Rendezvous( stat );
       
   166         
       
   167         if( stat != KRequestPending )
       
   168             {            
       
   169             server.Kill( 0 );   // abort startup
       
   170             }
       
   171         else
       
   172             {            
       
   173             server.Resume();  // logon OK - start the server thread
       
   174             } // end if
       
   175 
       
   176         __LOG_WRITE_INFO( "Started" )
       
   177         User::WaitForRequest( stat );   // wait for start or death
       
   178 
       
   179         __LOG_WRITE8_FORMAT1_INFO( "stat.Int(() = %i", stat.Int() );
       
   180         __LOG_WRITE8_FORMAT1_INFO( "ExitReason() = %i", server.ExitReason() );
       
   181 
       
   182         TExitCategoryName exitCategory;
       
   183         exitCategory = server.ExitCategory();
       
   184         __LOG_WRITE_FORMAT1_INFO( "ExitCategory() = %S", &exitCategory );
       
   185 
       
   186         // we can't use the 'exit reason' if the server panicked as this
       
   187         // is the panic 'reason' and may be '0' which cannot be distinguished
       
   188         // from KErrNone  
       
   189         err = ( server.ExitType() == EExitPanic ) ? KErrGeneral : stat.Int();
       
   190         server.Close();	
       
   191         }
       
   192     else
       
   193         {
       
   194         __LOG_WRITE8_FORMAT1_ERROR( "failed to launch server, err=%i", err )
       
   195         } // end if
       
   196 
       
   197     __LOG_WRITE8_FORMAT1_DEBUG3( "err=%i", err )
       
   198     __LOG_EXIT
       
   199     return err;
       
   200     
       
   201     } // end StartServer
       
   202 
       
   203 // ==========================================================================
       
   204 // FUNCTION: Close
       
   205 // ==========================================================================
       
   206 void RMessageStoreSession::Close()
       
   207     {
       
   208     __LOG_ENTER( "Close" )
       
   209     
       
   210     RSessionBase::Close();  //basecall
       
   211     
       
   212     __LOG_EXIT
       
   213     } // end Close
       
   214 
       
   215 // ==========================================================================
       
   216 // FUNCTION: EnableEncryptionL
       
   217 // ==========================================================================
       
   218 void RMessageStoreSession::EnableEncryptionL()
       
   219     {
       
   220     __LOG_ENTER( "EnableEncryptionL" )
       
   221     
       
   222     User::LeaveIfError( SendReceive( EMsgStoreCmdEnableEncryption ) );
       
   223     
       
   224     __LOG_EXIT
       
   225     }
       
   226 
       
   227 // ==========================================================================
       
   228 // FUNCTION: DisableEncryptionL
       
   229 // ==========================================================================
       
   230 void RMessageStoreSession::DisableEncryptionL()
       
   231     {
       
   232     __LOG_ENTER( "DisableEncryptionL" )
       
   233     
       
   234     User::LeaveIfError( SendReceive( EMsgStoreCmdDisableEncryption ) );
       
   235     
       
   236     __LOG_EXIT
       
   237     }
       
   238 
       
   239 // ==========================================================================
       
   240 // FUNCTION: AuthenticatedL
       
   241 // ==========================================================================
       
   242 TBool RMessageStoreSession::AuthenticatedL()
       
   243     {
       
   244     __LOG_ENTER( "AuthenticatedL" )
       
   245     
       
   246     TPckgBuf<TBool> resultPckg( EFalse );
       
   247     
       
   248 	User::LeaveIfError( SendReceive( EMsgStoreCmdAuthenticated, TIpcArgs( &resultPckg ) ) );
       
   249     
       
   250     __LOG_WRITE8_FORMAT1_DEBUG3( "result=%i", resultPckg() )
       
   251     __LOG_EXIT
       
   252     
       
   253     return resultPckg();
       
   254     
       
   255     } // end AuthenticatedL
       
   256 
       
   257 // ==========================================================================
       
   258 // FUNCTION: AuthenticateL
       
   259 // ==========================================================================
       
   260 TBool RMessageStoreSession::AuthenticateL( const TDesC& aPassword )
       
   261     {
       
   262     __LOG_ENTER( "AuthenticateL" )
       
   263     
       
   264     TPckgBuf<TBool> resultPckg( EFalse );
       
   265     
       
   266 	User::LeaveIfError( SendReceive( EMsgStoreCmdAuthenticate, TIpcArgs( &resultPckg, &aPassword ) ) );
       
   267     
       
   268     __LOG_WRITE8_FORMAT1_DEBUG3( "result=%i", resultPckg() )
       
   269     __LOG_EXIT
       
   270     
       
   271     return resultPckg();
       
   272     
       
   273     } // end AuthenticateL
       
   274 
       
   275 // ==========================================================================
       
   276 // FUNCTION: ClearAuthenticationL
       
   277 // ==========================================================================
       
   278 void RMessageStoreSession::ClearAuthenticationL()
       
   279     {
       
   280     __LOG_ENTER( "ClearAuthenticationL" )
       
   281     
       
   282 	User::LeaveIfError( SendReceive( EMsgStoreCmdClearAuthentication ) );
       
   283 	
       
   284 	__LOG_EXIT
       
   285     } // end ClearAuthenticationL
       
   286 
       
   287 // ==========================================================================
       
   288 // FUNCTION: HasPasswordL
       
   289 // ==========================================================================
       
   290 TBool RMessageStoreSession::HasPasswordL()
       
   291     {
       
   292     __LOG_ENTER( "HasPasswordL" )
       
   293     
       
   294     TPckgBuf<TBool> resultPckg( EFalse );
       
   295     
       
   296 	User::LeaveIfError( SendReceive( EMsgStoreCmdHasPassword, TIpcArgs( &resultPckg ) ) );
       
   297     
       
   298     __LOG_WRITE8_FORMAT1_DEBUG3( "result=%i", resultPckg() )   
       
   299     __LOG_EXIT
       
   300     
       
   301     return resultPckg();
       
   302     
       
   303     } // end HasPasswordL
       
   304 
       
   305 // ==========================================================================
       
   306 // FUNCTION: SetPasswordL
       
   307 // ==========================================================================
       
   308 void RMessageStoreSession::SetPasswordL( const TDesC& aPassword )
       
   309     {
       
   310     __LOG_ENTER( "SetPasswordL" )
       
   311     
       
   312 	User::LeaveIfError( SendReceive( EMsgStoreCmdSetPassword, TIpcArgs( &aPassword ) ) );
       
   313 	
       
   314 	__LOG_EXIT
       
   315     } // end SetPasswordL
       
   316 
       
   317 // ==========================================================================
       
   318 // FUNCTION: ChangePasswordL
       
   319 // ==========================================================================
       
   320 TBool RMessageStoreSession::ChangePasswordL( const TDesC& aOldPassword, const TDesC& aNewPassword )
       
   321     {
       
   322     __LOG_ENTER( "ChangePasswordL" )
       
   323     
       
   324     TPckgBuf<TBool> resultPckg( EFalse );
       
   325     
       
   326 	User::LeaveIfError( SendReceive( EMsgStoreCmdChangePassword, TIpcArgs( &resultPckg, &aOldPassword, &aNewPassword ) ) );
       
   327 	
       
   328     __LOG_WRITE8_FORMAT1_DEBUG3( "result=%i", resultPckg() )  
       
   329     __LOG_EXIT
       
   330     
       
   331 	return resultPckg();
       
   332 	
       
   333     } // end ChangePasswordL
       
   334 
       
   335 //account management
       
   336 // ==========================================================================
       
   337 // FUNCTION: CreateAccountL
       
   338 // ==========================================================================
       
   339 TMsgStoreId RMessageStoreSession::CreateAccountL( const CMsgStoreAccount& aAccount, const TDesC8& aProperties )
       
   340 	{
       
   341     __LOG_ENTER( "CreateAccountL" )
       
   342     
       
   343     TPckgBuf<TMsgStoreId> resultPckg( KMsgStoreInvalidId );
       
   344     
       
   345     TInt32 ownerId = aAccount.Owner();
       
   346     const TDesC& name = aAccount.Name();
       
   347     
       
   348 	User::LeaveIfError( SendReceive( EMsgStoreCmdCreateAccount, TIpcArgs( &resultPckg, ownerId, &name, &aProperties ) ) );
       
   349 	
       
   350     __LOG_WRITE8_FORMAT1_DEBUG3( "result=%u", resultPckg() )  
       
   351     __LOG_EXIT
       
   352     
       
   353 	return resultPckg();
       
   354 	}
       
   355 
       
   356 // ==========================================================================
       
   357 // FUNCTION: OpenAccountL
       
   358 // ==========================================================================
       
   359 TMsgStoreId RMessageStoreSession::OpenAccountL( const CMsgStoreAccount& aAccount, RBuf8& aBuffer )
       
   360 	{
       
   361     __LOG_ENTER( "OpenAccountL" )
       
   362     
       
   363     TUint result = 1;
       
   364     TPckg<TUint> resultPckg( result );
       
   365     
       
   366 	TMsgStoreOpenAccountCmdParams params;
       
   367 	TPckg<TMsgStoreOpenAccountCmdParams> paramsPckg( params );
       
   368 	
       
   369 	params.iOwnerId = aAccount.Owner();
       
   370 	
       
   371     const TDesC& name = aAccount.Name();
       
   372     
       
   373 	aBuffer.CreateL( KInitialPropertiesTransferBufferLength );
       
   374 
       
   375     while( result != 0 )
       
   376 	    {	   
       
   377 	    User::LeaveIfError( SendReceive( EMsgStoreCmdOpenAccount, TIpcArgs( &resultPckg, &paramsPckg, &name, &aBuffer ) ) );
       
   378 	    
       
   379 	    // The buffer was too small.  Reallocate.
       
   380 	    if( result != 0 )
       
   381 	        {
       
   382 	        __LOG_WRITE8_FORMAT1_INFO( "growing buffer to %i", result );
       
   383 	        aBuffer.ReAllocL( result );
       
   384 	        }
       
   385 	    } // end while
       
   386 	
       
   387     __LOG_WRITE8_FORMAT1_DEBUG3( "result=%u", resultPckg() )    
       
   388     __LOG_EXIT
       
   389     
       
   390 	return params.iMailBoxId;
       
   391 	}
       
   392 
       
   393 // ==========================================================================
       
   394 // FUNCTION: DeleteAccountL
       
   395 // ==========================================================================
       
   396 void RMessageStoreSession::DeleteAccountL( const CMsgStoreAccount& aAccount )
       
   397 	{
       
   398     __LOG_ENTER( "DeleteAccountL" )
       
   399     
       
   400     TInt32 ownerId = aAccount.Owner();
       
   401     const TDesC& name = aAccount.Name();
       
   402     
       
   403 	User::LeaveIfError( SendReceive( EMsgStoreCmdDeleteAccount, TIpcArgs( ownerId, &name ) ) );
       
   404 	
       
   405 	__LOG_EXIT
       
   406 	}
       
   407 
       
   408 // ==========================================================================
       
   409 // FUNCTION: RenameAccountL
       
   410 // ==========================================================================
       
   411 void RMessageStoreSession::RenameAccountL( TInt32 aOwnerId, const TDesC& aOldName, const TDesC& aNewName )
       
   412 	{
       
   413     __LOG_ENTER( "RenameAccountL" )
       
   414     
       
   415 	User::LeaveIfError( SendReceive( EMsgStoreCmdRenameAccount, TIpcArgs( aOwnerId, &aOldName, &aNewName ) ) );
       
   416 	
       
   417 	__LOG_EXIT
       
   418 	}
       
   419 
       
   420 // ==========================================================================
       
   421 // FUNCTION: AccountsL
       
   422 // ==========================================================================
       
   423 void RMessageStoreSession::AccountsL( RPointerArray<CMsgStoreAccount>& aAccounts )
       
   424 	{
       
   425     __LOG_ENTER( "AccountsL" )
       
   426     
       
   427     RBuf8 resultBuf;
       
   428     CleanupClosePushL( resultBuf );
       
   429     resultBuf.CreateL( KInitialAccountsTransferBufferLength );
       
   430     
       
   431 	User::LeaveIfError( SendReceive( EMsgStoreCmdListAccounts, TIpcArgs( &resultBuf ) ) );
       
   432 	
       
   433 	CAccountsSerializer* serializer = new(ELeave)CAccountsSerializer();
       
   434 	CleanupStack::PushL( serializer );
       
   435 	
       
   436 	serializer->DeserializeL( resultBuf );
       
   437 	
       
   438 	TInt count = serializer->Count();
       
   439 	RArray<TInt32>& ownerIds = serializer->OwnerIds();
       
   440     RPointerArray<HBufC>& names = serializer->NamesArray();
       
   441 	
       
   442 	for ( int i = 0 ; i < count ; i++ )
       
   443 		{
       
   444 		CMsgStoreAccount* account = CMsgStoreAccount::NewL( ownerIds[i], *(names[i]) );
       
   445 		aAccounts.Append( account );
       
   446 		}
       
   447 	CleanupStack::PopAndDestroy( serializer );
       
   448 	CleanupStack::PopAndDestroy( &resultBuf );
       
   449 	
       
   450 	__LOG_EXIT
       
   451 	}
       
   452 
       
   453 // ==========================================================================
       
   454 // FUNCTION: StartObservingL
       
   455 // ==========================================================================
       
   456 void RMessageStoreSession::StartObservingL()
       
   457 	{
       
   458 	__LOG_ENTER( "StartObservingL" )
       
   459 	
       
   460 	User::LeaveIfError( SendReceive( EMsgStoreCmdStartObserving ) );
       
   461 	
       
   462 	__LOG_EXIT
       
   463 	} // end StartObservingL
       
   464 
       
   465 // ==========================================================================
       
   466 // FUNCTION: GetEvents
       
   467 // ==========================================================================
       
   468 void RMessageStoreSession::GetEvents( TRequestStatus& aStatus, TDes8& aBuffer )
       
   469 	{
       
   470 	__LOG_ENTER( "GetEvents" )
       
   471 	
       
   472 	aBuffer.SetLength( 0 );
       
   473     SendReceive( EMsgStoreCmdGetEvents, TIpcArgs( &aBuffer ), aStatus );
       
   474     
       
   475     __LOG_EXIT
       
   476 	} // end GetEvents
       
   477 		
       
   478 // ==========================================================================
       
   479 // FUNCTION: StopObserving
       
   480 // ==========================================================================
       
   481 void RMessageStoreSession::StopObserving()
       
   482 	{
       
   483 	__LOG_ENTER( "StopObserving" )
       
   484 	
       
   485 	SendReceive( EMsgStoreCmdStopObserving );
       
   486 	
       
   487 	__LOG_EXIT
       
   488 	} // end StopObserving
       
   489 		
       
   490 // ==========================================================================
       
   491 // FUNCTION: CreateContainerL
       
   492 // ==========================================================================
       
   493 TMsgStoreId RMessageStoreSession::CreateContainerL( TMsgStoreId             aParentId,
       
   494 													TMsgStoreId             aGrandparentId,
       
   495 													TMsgStoreId             aMailBoxId,
       
   496 													TMsgStoreContainerMasks aType,
       
   497 								                    const TDesC8&           aProperties,
       
   498 								                    TBool                   aCommitContainer,
       
   499 								                    const TDesC&            aContentFilename )
       
   500 	{
       
   501 	__LOG_ENTER( "CreateContainerL" )
       
   502 
       
   503 	TMsgStoreCreateContainerCmdParams params;
       
   504 	TPckg<TMsgStoreCreateContainerCmdParams> paramsPckg( params );
       
   505 	
       
   506 	params.iParentId        = aParentId;
       
   507 	params.iGrandparentId   = aGrandparentId;
       
   508 	params.iMailBoxId       = aMailBoxId;
       
   509 	params.iCommitContainer = aCommitContainer;
       
   510 	params.iType            = aType;
       
   511 	params.iHasContent      = ( aContentFilename.Length() > 0 );
       
   512 	
       
   513 	TIpcArgs ipcArgs( &paramsPckg, &aProperties );
       
   514 
       
   515     // Platform security documentation recommends using different file system session for
       
   516     // each file handle that is transferred between processes.
       
   517     RFs fs;
       
   518     CleanupClosePushL( fs );
       
   519 
       
   520     RFile file;
       
   521     CleanupClosePushL( file );
       
   522 	
       
   523 	if( params.iHasContent )
       
   524 	    {
       
   525         User::LeaveIfError( fs.Connect() );
       
   526         fs.ShareProtected();        
       
   527         
       
   528         User::LeaveIfError( file.Open( fs, aContentFilename, EFileRead | EFileShareAny ) );
       
   529         User::LeaveIfError( file.TransferToServer( ipcArgs, KIpcArgsIndex2, KIpcArgsIndex3 ) );	    	    
       
   530 	    } // end if
       
   531 
       
   532 	User::LeaveIfError( SendReceive( EMsgStoreCmdCreateContainer, ipcArgs ) );
       
   533 
       
   534 	CleanupStack::PopAndDestroy( &file );
       
   535 	CleanupStack::PopAndDestroy( &fs );
       
   536 		
       
   537     __LOG_WRITE8_FORMAT1_DEBUG3( "id=%x", params.iId )
       
   538     __LOG_EXIT
       
   539     
       
   540 	return params.iId;
       
   541 	
       
   542 	} // end CreateContainerL
       
   543 
       
   544 
       
   545 // ==========================================================================
       
   546 // FUNCTION: CreateContainerL
       
   547 // ==========================================================================
       
   548 TMsgStoreId RMessageStoreSession::CreateContainerL( TMsgStoreId             aParentId,
       
   549 													TMsgStoreId             aGrandparentId,
       
   550 													TMsgStoreId             aMailBoxId,
       
   551 													TMsgStoreContainerMasks aType,
       
   552 								                    const TDesC8&           aProperties,
       
   553 								                    TBool                   aCommitContainer,
       
   554 								                    RFile&                  aFile )
       
   555 	{
       
   556 	__LOG_ENTER( "CreateContainerL" )
       
   557 
       
   558 	TMsgStoreCreateContainerCmdParams params;
       
   559 	TPckg<TMsgStoreCreateContainerCmdParams> paramsPckg( params );
       
   560 	
       
   561     CleanupClosePushL( aFile );
       
   562 	
       
   563 	params.iParentId        = aParentId;
       
   564 	params.iGrandparentId   = aGrandparentId;
       
   565 	params.iMailBoxId       = aMailBoxId;
       
   566 	params.iCommitContainer = aCommitContainer;
       
   567 	params.iType            = aType;
       
   568 	params.iHasContent      = ETrue;
       
   569 	
       
   570 	TIpcArgs ipcArgs( &paramsPckg, &aProperties );
       
   571 
       
   572     User::LeaveIfError( aFile.TransferToServer( ipcArgs, 2, 3 ) );	    	    
       
   573 
       
   574 	User::LeaveIfError( SendReceive( EMsgStoreCmdCreateContainer, ipcArgs ) );
       
   575 	
       
   576 	CleanupStack::PopAndDestroy( &aFile );
       
   577 
       
   578     __LOG_WRITE8_FORMAT1_DEBUG3( "id=%x", params.iId )
       
   579     __LOG_EXIT
       
   580     
       
   581 	return params.iId;
       
   582 	
       
   583 	} // end CreateContainerL
       
   584 
       
   585 // ==========================================================================
       
   586 // FUNCTION: CommitContainerL
       
   587 // ==========================================================================
       
   588 void RMessageStoreSession::CommitContainerL( TMsgStoreId aId,
       
   589  	 									     TMsgStoreId aDestinationId,
       
   590  	 									     TMsgStoreId aMailBoxId)
       
   591 	{
       
   592 	__LOG_ENTER( "CommitContainerL" )
       
   593 
       
   594 	User::LeaveIfError( SendReceive( EMsgStoreCmdCommitContainer, TIpcArgs( aId, aDestinationId, aMailBoxId ) ) );
       
   595 
       
   596 	__LOG_EXIT
       
   597 	} // end CommitContainerL
       
   598 
       
   599 // ==========================================================================
       
   600 // FUNCTION: AbandonContainerL
       
   601 // ==========================================================================
       
   602 void RMessageStoreSession::AbandonContainerL( TMsgStoreId aId )
       
   603 	{
       
   604 	__LOG_ENTER( "AbandonContainerL" )
       
   605 
       
   606 	User::LeaveIfError( SendReceive( EMsgStoreCmdAbandonContainer, TIpcArgs( aId ) ) );
       
   607 
       
   608 	__LOG_EXIT
       
   609 	} // end AbandonContainerL
       
   610 
       
   611 // ==========================================================================
       
   612 // FUNCTION: MoveContainerL
       
   613 // ==========================================================================
       
   614 void RMessageStoreSession::MoveContainerL( TMsgStoreId aId,
       
   615 										   TMsgStoreId aSourceId,
       
   616 	 									   TMsgStoreId aDestinationId )
       
   617 	{
       
   618 	__LOG_ENTER( "MoveContainerL" )
       
   619 
       
   620 	User::LeaveIfError( SendReceive( EMsgStoreCmdMoveContainer, TIpcArgs( aId, aSourceId, aDestinationId ) ) );
       
   621 
       
   622 	__LOG_EXIT
       
   623 	} // end MoveContainerL
       
   624 
       
   625 // ==========================================================================
       
   626 // FUNCTION: CopyContainerL
       
   627 // ==========================================================================
       
   628 TMsgStoreId RMessageStoreSession::CopyContainerL( TMsgStoreId aId, 
       
   629                 								  TMsgStoreId aSourceId,
       
   630                 								  TMsgStoreId aSourceParentId,
       
   631                 							  	  TMsgStoreId aDestinationId,
       
   632                 								  TMsgStoreId aDestinationParentId,
       
   633                 								  TMsgStoreId aMailBoxId)
       
   634 	{
       
   635 	__LOG_ENTER( "CopyContainerL" )
       
   636 
       
   637 	TPckgBuf<TMsgStoreId> idPckg;	
       
   638 
       
   639 	TMsgStoreCopyContainerCmdParams        params;
       
   640 	TPckg<TMsgStoreCopyContainerCmdParams> paramsPckg( params );
       
   641 	
       
   642 	params.iId                  = aId;
       
   643 	params.iSourceId            = aSourceId,
       
   644 	params.iSourceParentId      = aSourceParentId,
       
   645 	params.iDestinationId       = aDestinationId;
       
   646 	params.iDestinationParentId = aDestinationParentId;
       
   647 	params.iMailBoxId           = aMailBoxId;
       
   648 	
       
   649 	User::LeaveIfError( SendReceive( EMsgStoreCmdCopyContainer, TIpcArgs( &paramsPckg, &idPckg ) ) );
       
   650 
       
   651     __LOG_WRITE8_FORMAT1_DEBUG3( "id=%x", idPckg() )
       
   652     __LOG_EXIT
       
   653     
       
   654 	return idPckg();
       
   655 
       
   656 	} // end CopyContainerL
       
   657 
       
   658 // ==========================================================================
       
   659 // FUNCTION: ContainerPropertiesL
       
   660 // ==========================================================================
       
   661 void RMessageStoreSession::ContainerPropertiesL( TMsgStoreId aId, TMsgStoreId& aParentId, TMsgStoreId aGrandparentId, RBuf8& aBuffer, TMsgStoreId aMailboxId )
       
   662 	{
       
   663 	__LOG_ENTER( "ContainerPropertiesL" )
       
   664 	
       
   665 	//TMsgStoreId originalParentId = aParentId;
       
   666 	
       
   667 	TMsgStoreFetchPropertiesCmdParams params;
       
   668 	TPckg<TMsgStoreFetchPropertiesCmdParams> paramsPckg( params );
       
   669 	
       
   670 	params.iId            = aId;
       
   671 	params.iGrandparentId = aGrandparentId;
       
   672 	params.iMailboxId = aMailboxId;
       
   673 	
       
   674 	TPckg<TMsgStoreId> parentIdPckg( aParentId );
       
   675 
       
   676     TUint result = 1;
       
   677 	TPckg<TUint> resultPckg( result );
       
   678 
       
   679 	aBuffer.CreateL( KInitialPropertiesTransferBufferLength );
       
   680 
       
   681     while( result != 0 )
       
   682 	    {	   
       
   683 	    User::LeaveIfError( SendReceive( EMsgStoreCmdFetchProperties, TIpcArgs( &paramsPckg, &parentIdPckg, &aBuffer, &resultPckg ) ) );
       
   684 	    
       
   685 	    // The buffer was too small.  Reallocate.
       
   686 	    if( result != 0 )
       
   687 	        {
       
   688 	        __LOG_WRITE8_FORMAT1_INFO( "growing buffer to %i", result );
       
   689 	        aBuffer.ReAllocL( result );
       
   690 	        }
       
   691 	    } // end while
       
   692     
       
   693 	__LOG_EXIT
       
   694 	} // end ContainerPropertiesL
       
   695 
       
   696 // ==========================================================================
       
   697 // FUNCTION: DeleteContainerL
       
   698 // ==========================================================================
       
   699 void RMessageStoreSession::DeleteContainerL( TMsgStoreId aId, TMsgStoreId aParentId, TMsgStoreId aGrandparentId, TMsgStoreId aMailBoxId )
       
   700 	{
       
   701 	__LOG_ENTER( "DeleteContainerL" )
       
   702 	
       
   703 	User::LeaveIfError( SendReceive( EMsgStoreCmdDeleteContainer, TIpcArgs( aId, aParentId, aGrandparentId, aMailBoxId ) ) );
       
   704 	
       
   705 	__LOG_EXIT
       
   706 	} // end DeleteContainerL
       
   707 
       
   708 // ==========================================================================
       
   709 // FUNCTION: ChildrenCountsL
       
   710 // ==========================================================================
       
   711 void RMessageStoreSession::ChildrenCountsL( TMsgStoreId aId, TUint& aMessageCount, TUint& aUnreadCount )
       
   712 	{
       
   713 	__LOG_ENTER( "ChildrenCountsL" )
       
   714 	
       
   715 	TMsgStoreCounts counts;
       
   716 	TPckg<TMsgStoreCounts> countsPckg( counts );
       
   717 	
       
   718 	User::LeaveIfError( SendReceive( EMsgStoreCmdChildrenCounts, TIpcArgs( aId, &countsPckg ) ) );
       
   719 
       
   720 	aMessageCount = counts.iMessagesCount;
       
   721 	aUnreadCount  = counts.iUnreadCount;
       
   722 		
       
   723 	__LOG_EXIT
       
   724 	} // end ChildrenCountsL
       
   725 	
       
   726 // ==========================================================================
       
   727 // FUNCTION: TotalCountsL
       
   728 // ==========================================================================
       
   729 void RMessageStoreSession::TotalCountsL( TMsgStoreId aMailBoxId, TUint& aMessageCount, TUint& aUnreadCount )
       
   730 	{
       
   731 	__LOG_ENTER( "TotalCountsL" )
       
   732 	
       
   733 	TMsgStoreCounts counts;
       
   734 	TPckg<TMsgStoreCounts> countsPckg( counts );
       
   735 	
       
   736 	User::LeaveIfError( SendReceive( EMsgStoreCmdTotalCounts, TIpcArgs( aMailBoxId, &countsPckg ) ) );
       
   737 
       
   738 	aMessageCount = counts.iMessagesCount;
       
   739 	aUnreadCount  = counts.iUnreadCount;
       
   740 		
       
   741 	__LOG_EXIT
       
   742 	} // end TotalCountsL
       
   743 	
       
   744 // ==========================================================================
       
   745 // FUNCTION: ChildrenIdsL
       
   746 // ==========================================================================
       
   747 void RMessageStoreSession::ChildrenIdsL( TMsgStoreId aId, TMsgStoreContainerMasks aType, RArray<TMsgStoreId>& aChildrenIds )
       
   748 	{
       
   749 	__LOG_ENTER( "ChildrenIdsL" )
       
   750 	
       
   751 	RBuf8 childrenBuf;
       
   752 	childrenBuf.CreateL( KInitialChildrenIdsTransferBufferLength );
       
   753 	CleanupClosePushL( childrenBuf );
       
   754 	
       
   755 	TUint result = 1;
       
   756 	TPckg<TUint> resultPckg( result );
       
   757 	
       
   758 	while( result != 0 )
       
   759 	    {	    	    
       
   760 	    User::LeaveIfError( SendReceive( EMsgStoreCmdChildrenIds, TIpcArgs( aId, aType, &childrenBuf, &resultPckg ) ) );	
       
   761 	    
       
   762 	    if( result != 0 )
       
   763 	        {
       
   764 	        // Overflow!
       
   765 	        __LOG_WRITE8_FORMAT1_INFO( "growing transfer buffer to %i", result )
       
   766 	        
       
   767 	        childrenBuf.ReAllocL( result );
       
   768 	        } // end if
       
   769 	        
       
   770 	    } // end while
       
   771 
       
   772 	RDesReadStream readStream( childrenBuf );
       
   773 	CleanupClosePushL( readStream );
       
   774 	
       
   775 	aChildrenIds.Reset();
       
   776 	const TUint KDivider = 4;
       
   777 	for( TInt count = 0; count < childrenBuf.Length() / KDivider; count++ )
       
   778 		{
       
   779 		aChildrenIds.Append( readStream.ReadUint32L() );
       
   780 		} // end for
       
   781 		
       
   782 	CleanupStack::PopAndDestroy( &readStream );
       
   783 	CleanupStack::PopAndDestroy( &childrenBuf );
       
   784 	
       
   785 	__LOG_EXIT	
       
   786 	} // end ChildrenIdsL
       
   787 
       
   788 // ==========================================================================
       
   789 // FUNCTION: UpdatePropertiesL
       
   790 // ==========================================================================
       
   791 void RMessageStoreSession::UpdatePropertiesL( TMsgStoreId   aId,
       
   792 											  TMsgStoreId   aParentId,
       
   793 											  TMsgStoreId   aMailBoxId,
       
   794 	 					                      const TDesC8& aProperties )
       
   795 	{
       
   796 	__LOG_ENTER( "UpdatePropertiesL" )
       
   797 
       
   798 	User::LeaveIfError( SendReceive( EMsgStoreCmdUpdateProperties, TIpcArgs( aId, aParentId, aMailBoxId, &aProperties ) ) );
       
   799 
       
   800 	__LOG_EXIT
       
   801 	} // end UpdatePropertiesL
       
   802 
       
   803 // ==========================================================================
       
   804 // FUNCTION: UpdatePropertyL
       
   805 // ==========================================================================
       
   806 void RMessageStoreSession::UpdatePropertyL( TMsgStoreId                aId,
       
   807 	 					                    TMsgStoreId                aParentId,
       
   808 	 					                    TMsgStoreId                aMailBoxId,
       
   809 	 					                    const TDesC8&              aName,
       
   810 	 					                    TMsgStorePropertyValueType aType,
       
   811 	 					                    const TDesC8&              aValue )
       
   812 	{
       
   813 	__LOG_ENTER( "UpdatePropertyL" )
       
   814 
       
   815     TMsgStoreUpdatePropertyCmdParams        params;
       
   816     TPckg<TMsgStoreUpdatePropertyCmdParams> paramsPckg( params );
       
   817     
       
   818     params.iId       = aId;
       
   819     params.iParentId = aParentId;
       
   820     params.iMailBoxId = aMailBoxId;
       
   821     params.iType     = aType;
       
   822     
       
   823 	User::LeaveIfError( SendReceive( EMsgStoreCmdUpdateProperty, TIpcArgs( &paramsPckg, &aName, &aValue ) ) );
       
   824 
       
   825 	__LOG_EXIT
       
   826 	} // end UpdatePropertyL
       
   827 
       
   828 // ==========================================================================
       
   829 // FUNCTION: WipeEverything
       
   830 // ==========================================================================
       
   831 void RMessageStoreSession::WipeEverythingL()
       
   832 	{
       
   833 	__LOG_ENTER( "WipeEverything" )
       
   834 	
       
   835 	User::LeaveIfError( SendReceive( EMsgStoreCmdWipeEverything ) );
       
   836 	
       
   837 	__LOG_EXIT		
       
   838 	} // end WipeEverything
       
   839 
       
   840 // ==========================================================================
       
   841 // FUNCTION: ContentLengthL
       
   842 // ==========================================================================
       
   843 TUint RMessageStoreSession::ContentLengthL( TMsgStoreId aId, TMsgStoreId aParentId )
       
   844 	{
       
   845 	__LOG_ENTER( "ContentLengthL" )
       
   846 	
       
   847 	TPckgBuf<TUint> lengthPckg;
       
   848 	
       
   849 	User::LeaveIfError( SendReceive( EMsgStoreCmdContentLength, TIpcArgs( aId, aParentId, &lengthPckg ) ) );
       
   850 	
       
   851     __LOG_WRITE8_FORMAT1_DEBUG3( "length=%i", lengthPckg() )	
       
   852     __LOG_EXIT
       
   853 
       
   854 	return lengthPckg();
       
   855 	
       
   856 	} // end ContentLengthL
       
   857 
       
   858 // ==========================================================================
       
   859 // FUNCTION: FetchContentL
       
   860 // ==========================================================================
       
   861 void RMessageStoreSession::FetchContentL( TMsgStoreId aId, TMsgStoreId aParentId, TDes8& aBuffer, TUint aStartOffset )
       
   862 	{
       
   863 	__LOG_ENTER( "FetchContentL(1)" )
       
   864 	
       
   865 	User::LeaveIfError( SendReceive( EMsgStoreCmdFetchContentToBuffer, TIpcArgs( aId, aParentId, &aBuffer, aStartOffset ) ) );
       
   866 	
       
   867 	__LOG_EXIT
       
   868 	} // end FetchContentL
       
   869 
       
   870 // ==========================================================================
       
   871 // FUNCTION: FetchContentL
       
   872 // ==========================================================================
       
   873 void RMessageStoreSession::FetchContentL( TMsgStoreId aId, TMsgStoreId aParentId, const TDesC& aFilename )
       
   874 	{
       
   875 	__LOG_ENTER( "FetchContentL(2)" )
       
   876 	
       
   877     // Platform security documentation recommends using different file system session for
       
   878     // each file handle that is transferred between processes.
       
   879     RFs   fs;
       
   880     User::LeaveIfError( fs.Connect() );
       
   881     CleanupClosePushL( fs );
       
   882     fs.ShareProtected();
       
   883     
       
   884     RFile file;
       
   885     User::LeaveIfError( file.Replace( fs, aFilename, EFileWrite | EFileShareAny ) );
       
   886     CleanupClosePushL( file );
       
   887 
       
   888     TIpcArgs ipcArgs;
       
   889         
       
   890     ipcArgs.Set( 0, aId );
       
   891     ipcArgs.Set( 1, aParentId );
       
   892 
       
   893     User::LeaveIfError( file.TransferToServer( ipcArgs, KIpcArgsIndex2, KIpcArgsIndex3 ) );
       
   894 	
       
   895 	TInt result = SendReceive( EMsgStoreCmdFetchContentToFile, ipcArgs );
       
   896 
       
   897 	CleanupStack::PopAndDestroy( &file );
       
   898 
       
   899     if( result != KErrNone )
       
   900         {
       
   901         // Something went wrong.  Cleanup file.
       
   902         fs.Delete( aFilename );
       
   903         User::Leave( result );        
       
   904         } // end if
       
   905 	
       
   906 	CleanupStack::PopAndDestroy( &fs );	
       
   907 
       
   908 	__LOG_EXIT
       
   909 	} // end FetchContentL
       
   910 
       
   911 // ==========================================================================
       
   912 // FUNCTION: ReplaceContentL
       
   913 // ==========================================================================
       
   914 void RMessageStoreSession::ReplaceContentL( TMsgStoreId aId, TMsgStoreId aParentId, const TDesC8& aContent )
       
   915 	{
       
   916 	__LOG_ENTER( "ReplaceContentL" )
       
   917 	
       
   918 	User::LeaveIfError( SendReceive( EMsgStoreCmdReplaceContentWithBuffer, TIpcArgs( aId, aParentId, &aContent ) ) );
       
   919 	
       
   920 	__LOG_EXIT
       
   921 	} // end ReplaceContentL
       
   922 
       
   923 // ==========================================================================
       
   924 // FUNCTION: ReplaceContentL
       
   925 // ==========================================================================
       
   926 void RMessageStoreSession::ReplaceContentWithFileL( TMsgStoreId aId, TMsgStoreId aParentId, const TDesC& aFilename )
       
   927 	{
       
   928 	__LOG_ENTER( "ReplaceContentWithFileL" )
       
   929 	
       
   930     TIpcArgs ipcArgs( aId, aParentId );
       
   931     
       
   932     // Platform security documentation recommends using different file system session for
       
   933     // each file handle that is transferred between processes.
       
   934     RFs   fs;
       
   935     User::LeaveIfError( fs.Connect() );
       
   936     CleanupClosePushL( fs );
       
   937     fs.ShareProtected();
       
   938     
       
   939     RFile file;
       
   940     User::LeaveIfError( file.Open( fs, aFilename, EFileRead ) );
       
   941     CleanupClosePushL( file );
       
   942     User::LeaveIfError( file.TransferToServer( ipcArgs, KIpcArgsIndex2, KIpcArgsIndex3 ) ); 
       
   943 	
       
   944 	User::LeaveIfError( SendReceive( EMsgStoreCmdReplaceContentWithFile, ipcArgs ) );
       
   945 	
       
   946 	CleanupStack::PopAndDestroy( &file );
       
   947 	CleanupStack::PopAndDestroy( &fs );
       
   948 	
       
   949 	__LOG_EXIT
       
   950 	} // end ReplaceContentL
       
   951 
       
   952 // ==========================================================================
       
   953 // FUNCTION: AppendToContentL
       
   954 // ==========================================================================
       
   955 void RMessageStoreSession::AppendToContentL( TMsgStoreId aId, TMsgStoreId aParentId, const TDesC8& aContent )
       
   956 	{
       
   957 	__LOG_ENTER( "AppendToContentL" )
       
   958 	
       
   959 	User::LeaveIfError( SendReceive( EMsgStoreCmdAppendToContent, TIpcArgs( aId, aParentId, &aContent ) ) );
       
   960 	
       
   961 	__LOG_EXIT
       
   962 	} // end AppendToContentL
       
   963 
       
   964 // ==========================================================================
       
   965 // FUNCTION: PrependToContentL
       
   966 // ==========================================================================
       
   967 void RMessageStoreSession::PrependToContentL( TMsgStoreId aId, TMsgStoreId aParentId, const TDesC8& aContent )
       
   968     {
       
   969     __LOG_ENTER( "PrependToContentL" )
       
   970     
       
   971     User::LeaveIfError( SendReceive( EMsgStoreCmdPrependToContent,
       
   972         TIpcArgs( aId, aParentId, &aContent ) ) );
       
   973     
       
   974     __LOG_EXIT
       
   975     }
       
   976 
       
   977 // ==========================================================================
       
   978 // FUNCTION: RemoveContentL
       
   979 // ==========================================================================
       
   980 void RMessageStoreSession::RemoveContentL( TMsgStoreId aId, TMsgStoreId aParentId )
       
   981 	{
       
   982 	__LOG_ENTER( "RemoveContentL" )
       
   983 	
       
   984 	User::LeaveIfError( SendReceive( EMsgStoreCmdRemoveContent, TIpcArgs( aId, aParentId ) ) );
       
   985 	
       
   986 	__LOG_EXIT
       
   987 	} // end RemoveContentL	
       
   988 
       
   989 // ==========================================================================
       
   990 // FUNCTION: OpenOriginalContentFileL
       
   991 // ==========================================================================
       
   992 void RMessageStoreSession::OpenOriginalContentFileL( TMsgStoreId aId, TMsgStoreId aParentId, RFile& aFile )
       
   993     {
       
   994     __LOG_ENTER( "OpenOriginalContentFileL" )
       
   995     
       
   996     // Retrieve the RFs and RFile handles from the server
       
   997     TInt fsh;             // session (RFs) handle
       
   998     TPckgBuf<TInt> fh;    // sub-session (RFile) handle
       
   999 
       
  1000     fsh = SendReceive( EMsgStoreCmdOpenContentFile, TIpcArgs( aId, aParentId, &fh ) );
       
  1001     User::LeaveIfError( fsh );
       
  1002     
       
  1003     User::LeaveIfError( aFile.AdoptFromServer( fsh, fh() ) );
       
  1004     
       
  1005     __LOG_EXIT
       
  1006     }
       
  1007 
       
  1008 // ==========================================================================
       
  1009 // FUNCTION: ChildrenPropertiesL
       
  1010 // ==========================================================================
       
  1011 void RMessageStoreSession::ChildrenPropertiesL( TMsgStoreId             aId,
       
  1012                                                 TMsgStoreId             aParentId,
       
  1013                                                 TMsgStoreContainerMasks aType,
       
  1014                                                 TBool                   aQuickProperties,
       
  1015                                                 TBool                   aRecursive,
       
  1016                                                 MPropertiesArray&       aPropertiesArray )
       
  1017     {
       
  1018     __LOG_ENTER( "ChildrenPropertiesL" )
       
  1019 
       
  1020     TMsgStorePropertiesListCmdParams params;
       
  1021     
       
  1022 	params.iUseQuery        = ETrue;
       
  1023 	params.iQuickProperties = aQuickProperties;
       
  1024     
       
  1025     TMsgStorePropertiesListQueryParams queryParams;
       
  1026     
       
  1027     queryParams.iId        = aId;
       
  1028     queryParams.iParentId  = aParentId;
       
  1029     queryParams.iType      = aType;
       
  1030     queryParams.iRecursive = aRecursive;
       
  1031 
       
  1032     TPckg<TMsgStorePropertiesListQueryParams> queryParamsPckg( queryParams );    
       
  1033     TBuf8<1> emptyBuf;
       
  1034 
       
  1035     DoPropertiesListL( params, queryParamsPckg, emptyBuf, aPropertiesArray );
       
  1036 
       
  1037     __LOG_EXIT
       
  1038     } // end ChildrenPropertiesL
       
  1039 
       
  1040 // ==========================================================================
       
  1041 // FUNCTION: DoPropertiesListL
       
  1042 // ==========================================================================
       
  1043 void RMessageStoreSession::DoPropertiesListL( TMsgStorePropertiesListCmdParams& aParams,
       
  1044                                               const TDesC8&                     aIdBuffer, 
       
  1045                                               const TDesC8&                     aSerializedPropertyNames, 
       
  1046                                               MPropertiesArray&                 aPropertiesArray )        
       
  1047     {
       
  1048     __LOG_ENTER( "DoPropertiesListL" )
       
  1049     
       
  1050     TPckg<TMsgStorePropertiesListCmdParams> paramsPckg( aParams );
       
  1051     
       
  1052 	RBuf8 serializedBuf;
       
  1053 	serializedBuf.CreateL( KInitialPropertiesListTransferBufferLength );
       
  1054 	CleanupClosePushL( serializedBuf );
       
  1055 
       
  1056 	TMsgStoreId id;
       
  1057 	TPckg<TMsgStoreId> idPckg( id );
       
  1058 	
       
  1059 	TMsgStoreId parentId;			
       
  1060 	TPckg<TMsgStoreId> parentIdPckg( parentId );
       
  1061 	
       
  1062 	TUint32 length32;
       
  1063 	TPckg<TUint32> length32Pckg( length32 );
       
  1064 
       
  1065     aParams.iStartOver      = ETrue;
       
  1066     aParams.iMoreProperties = ETrue;
       
  1067 	
       
  1068 	while( aParams.iMoreProperties )
       
  1069 	    {
       
  1070 	    __LOG_WRITE_INFO( "getting next chunk" )
       
  1071         
       
  1072         serializedBuf.SetLength( 0 );
       
  1073         
       
  1074 		User::LeaveIfError( SendReceive( EMsgStoreCmdPropertiesList, 
       
  1075 		                                 TIpcArgs( &paramsPckg, 
       
  1076 		                                           &aIdBuffer, 
       
  1077 		                                           &aSerializedPropertyNames, 
       
  1078 		                                           &serializedBuf ) ) );
       
  1079 
       
  1080         __LOG_WRITE_INFO( "handling chunk" )
       
  1081         	
       
  1082 	    if( aParams.iClearExisting )
       
  1083 	        {
       
  1084 	        __LOG_WRITE_INFO( "resetting local buffer" )
       
  1085 	        aPropertiesArray.Reset();
       
  1086 	        } // end if
       
  1087 
       
  1088 		const TUint8* pointer = serializedBuf.Ptr();
       
  1089 
       
  1090 		// Deserialize data until the current buffer is exhausted.
       
  1091 		while( pointer < serializedBuf.Ptr() + serializedBuf.Length() )
       
  1092 			{
       
  1093     		idPckg.Copy( pointer, idPckg.Length() );
       
  1094 			pointer += idPckg.Length();
       
  1095 			
       
  1096 	        parentIdPckg.Copy( pointer, parentIdPckg.Length() );
       
  1097 	        pointer += parentIdPckg.Length();
       
  1098 						
       
  1099 			length32Pckg.Copy( pointer, length32Pckg.Length() );
       
  1100 			pointer += length32Pckg.Length();
       
  1101 			
       
  1102 			TPtrC8 propertiesBuf( pointer, length32 );
       
  1103 			pointer += length32;
       
  1104 		
       
  1105 		    aPropertiesArray.AddElementL( id, parentId, propertiesBuf );			
       
  1106 			} // end while			
       
  1107 			
       
  1108 		serializedBuf.SetLength( 0 );	
       
  1109     	
       
  1110         if( aParams.iNewBufferSize > 0 )
       
  1111             {
       
  1112             __LOG_WRITE8_FORMAT1_INFO( "growing buffer to %i", aParams.iNewBufferSize );	        
       
  1113 	        serializedBuf.ReAllocL( aParams.iNewBufferSize );                
       
  1114             } // end if
       
  1115 
       
  1116         aParams.iStartOver = EFalse;
       
  1117 
       
  1118 		} // end while
       
  1119 		
       
  1120 	__LOG_WRITE_INFO( "done" );
       
  1121 	
       
  1122 	CleanupStack::PopAndDestroy( &serializedBuf );	
       
  1123 	
       
  1124 	__LOG_EXIT
       
  1125     } // end DoPropertiesListL
       
  1126 	
       
  1127 // ==========================================================================
       
  1128 // FUNCTION: SortL
       
  1129 // ==========================================================================
       
  1130 TMsgStoreId RMessageStoreSession::SortL( RMsgStoreSortCriteria& aSortCriteria, TMsgStoreId aMailBoxId, TBool aInMemorySort )
       
  1131     {    
       
  1132     __LOG_ENTER( "SortL" )
       
  1133     
       
  1134     TPckgBuf<TMsgStoreId> resultPckg( KMsgStoreInvalidId );
       
  1135     
       
  1136     TMsgStoreSortCriteria params;
       
  1137     TPckg<TMsgStoreSortCriteria> paramsPckg( params );
       
  1138     
       
  1139     params.iMailBoxId          = aMailBoxId;
       
  1140     params.iFolderId           = aSortCriteria.iFolderId;
       
  1141     params.iSortBy             = aSortCriteria.iSortBy;
       
  1142     params.iSortOrder          = aSortCriteria.iSortOrder;
       
  1143     params.iSecondarySortOrder = aSortCriteria.iSecondarySortOrder;
       
  1144     
       
  1145     // Serialize property names.
       
  1146     TUint16 nameLength;
       
  1147     TPckg<TUint16> nameLengthPckg( nameLength );      
       
  1148     
       
  1149     const RPointerArray<TDesC8>& aPropertyNames = aSortCriteria.PropertyKeys();
       
  1150     
       
  1151     TInt totalLength = 0;
       
  1152     for( TInt i = 0; i < aPropertyNames.Count(); i++ )
       
  1153         {
       
  1154         totalLength += (aPropertyNames[i]->Length() + nameLengthPckg.Length());
       
  1155         } // end for
       
  1156         
       
  1157     RBuf8 propertyNamesBuffer;            
       
  1158     CleanupClosePushL( propertyNamesBuffer );
       
  1159     propertyNamesBuffer.CreateL( totalLength );
       
  1160  
       
  1161     for( TInt i = 0; i < aPropertyNames.Count(); i++ )
       
  1162         {
       
  1163         nameLength = aPropertyNames[i]->Length();
       
  1164         propertyNamesBuffer.Append( nameLengthPckg );
       
  1165         propertyNamesBuffer.Append( *aPropertyNames[i] );
       
  1166         } // end for
       
  1167     
       
  1168     User::LeaveIfError( SendReceive( EMsgStoreCmdStartSorting, TIpcArgs( &resultPckg, &paramsPckg, &propertyNamesBuffer, aInMemorySort ) ) );
       
  1169     
       
  1170     CleanupStack::PopAndDestroy( &propertyNamesBuffer );
       
  1171 
       
  1172     __LOG_EXIT
       
  1173     
       
  1174     return resultPckg();
       
  1175     }
       
  1176 
       
  1177 // ==========================================================================
       
  1178 // FUNCTION: GetSortedRowsL
       
  1179 // ==========================================================================
       
  1180 TBool RMessageStoreSession::GetSortedRowsL( TMsgStoreId                aSortSessionId,
       
  1181                                             TMsgStoreId                aCurrentMessageId, 
       
  1182                                             TMsgStoreIteratorDirection aDirection,
       
  1183                                             TUint                      aCount, 
       
  1184                                             MPropertiesArray&          aPropertiesArray,
       
  1185                                             const TDesC&               aStartWith,
       
  1186                                             TBool                      aSkipCurrentGroup )
       
  1187     {
       
  1188     __LOG_ENTER( "GetSortedRowsL" )
       
  1189     
       
  1190     TUint result = 1;
       
  1191     TPckg<TUint> resultPckg( result );
       
  1192     
       
  1193     TMsgStoreGetSortedRowsCmdParams params;
       
  1194     TPckg<TMsgStoreGetSortedRowsCmdParams> paramsPckg( params );
       
  1195     
       
  1196     params.iSortSessionId     = aSortSessionId;
       
  1197     params.iStartingMessageId = aCurrentMessageId;
       
  1198     params.iDirection         = aDirection;
       
  1199     params.iRowsToRetrieve    = aCount;
       
  1200     params.iHasStartWith      = aStartWith != KNullDesC;
       
  1201     params.iSkipCurrentGroup  = aSkipCurrentGroup;
       
  1202     params.iHasMoreRows       = EFalse;
       
  1203     
       
  1204     RBuf8 serializedBuf;
       
  1205     CleanupClosePushL( serializedBuf );
       
  1206     serializedBuf.CreateL( KInitialSortedListTransferBufferLength );
       
  1207 
       
  1208     while( result != 0 )
       
  1209         {      
       
  1210         if ( aStartWith == KNullDesC )
       
  1211             {
       
  1212             User::LeaveIfError( SendReceive( EMsgStoreCmdGetSortedRows, TIpcArgs( &resultPckg, &paramsPckg, &serializedBuf ) ) );
       
  1213             }
       
  1214         else
       
  1215             {
       
  1216             User::LeaveIfError( SendReceive( EMsgStoreCmdGetSortedRows, TIpcArgs( &resultPckg, &paramsPckg, &serializedBuf, &aStartWith ) ) );
       
  1217             }
       
  1218         
       
  1219         // The buffer was too small.  Reallocate.
       
  1220         if( result != 0 )
       
  1221             {
       
  1222             __LOG_WRITE8_FORMAT1_INFO( "growing buffer to %i", result );
       
  1223             serializedBuf.ReAllocL( result );
       
  1224             }
       
  1225         } // end while
       
  1226     
       
  1227     // Deserialize data until the current buffer is exhausted.
       
  1228     TMsgStoreId id;
       
  1229     TPckg<TMsgStoreId> idPckg( id );
       
  1230     
       
  1231     TMsgStoreId parentId;           
       
  1232     TPckg<TMsgStoreId> parentIdPckg( parentId );
       
  1233     
       
  1234     TUint32 length32;
       
  1235     TPckg<TUint32> length32Pckg( length32 );
       
  1236    
       
  1237     const TUint8* pointer = serializedBuf.Ptr();
       
  1238     
       
  1239     while( pointer < serializedBuf.Ptr() + serializedBuf.Length() )
       
  1240         {
       
  1241         idPckg.Copy( pointer, idPckg.Length() );
       
  1242         pointer += idPckg.Length();
       
  1243         
       
  1244         parentIdPckg.Copy( pointer, parentIdPckg.Length() );
       
  1245         pointer += parentIdPckg.Length();
       
  1246                     
       
  1247         length32Pckg.Copy( pointer, length32Pckg.Length() );
       
  1248         pointer += length32Pckg.Length();
       
  1249         
       
  1250         TPtrC8 propertiesBuf( pointer, length32 );
       
  1251         pointer += length32;
       
  1252     
       
  1253         aPropertiesArray.AddElementL( id, parentId, propertiesBuf );            
       
  1254         } // end while          
       
  1255     
       
  1256     __LOG_EXIT
       
  1257 
       
  1258     CleanupStack::PopAndDestroy( &serializedBuf );
       
  1259     
       
  1260     return params.iHasMoreRows;
       
  1261     }
       
  1262 
       
  1263 // ==========================================================================
       
  1264 // FUNCTION: SortIteratorGroupCountL
       
  1265 // ==========================================================================
       
  1266 TInt RMessageStoreSession::SortIteratorGroupCountL( TMsgStoreId aSortSessionId, RArray<TUint>& aItemsInGroup )
       
  1267     {
       
  1268     __LOG_ENTER("SortIteratorGroupCountL")
       
  1269     
       
  1270     TInt result = 0;
       
  1271     TPckg<TInt> resultPckg( result );
       
  1272     
       
  1273     RBuf8 countsBuf;
       
  1274     CleanupClosePushL( countsBuf );
       
  1275     countsBuf.CreateL( KInitialSortedListTransferBufferLength );
       
  1276     
       
  1277     User::LeaveIfError( SendReceive( EMsgStoreCmdGetIteratorGroupCount, TIpcArgs( aSortSessionId, &resultPckg, &countsBuf ) ) );
       
  1278     
       
  1279     TUint count;
       
  1280     TPckg<TUint> countPckg( count );
       
  1281     const TUint8* pointer = countsBuf.Ptr();
       
  1282     
       
  1283     if ( result > 0 )
       
  1284         {
       
  1285         while( pointer < countsBuf.Ptr() + countsBuf.Length() )
       
  1286             {
       
  1287             countPckg.Copy( pointer, countPckg.Length() );
       
  1288             pointer += countPckg.Length();
       
  1289             
       
  1290             aItemsInGroup.Append( count );        
       
  1291             }
       
  1292         }
       
  1293     
       
  1294     CleanupStack::PopAndDestroy( &countsBuf );
       
  1295     
       
  1296     __LOG_EXIT
       
  1297     
       
  1298     return result;
       
  1299     }
       
  1300 
       
  1301 // ==========================================================================
       
  1302 // FUNCTION: SortedIdsAndFlagsL
       
  1303 // ==========================================================================
       
  1304 void RMessageStoreSession::SortedIdsAndFlagsL( TMsgStoreId aSortSessionId, RArray<TMsgStoreIdAndFlag>& aIdsAndFlags )
       
  1305 	{
       
  1306     __LOG_ENTER("SortedIdsAndFlagsL")
       
  1307     
       
  1308     TInt count = 0;
       
  1309     TPckg<TInt> countPckg( count );
       
  1310     
       
  1311     RBuf8 resultBuf;
       
  1312     CleanupClosePushL( resultBuf );
       
  1313     resultBuf.CreateL( KInitialSortedIdsAndFlagsBufferLength );
       
  1314     
       
  1315     User::LeaveIfError( SendReceive( EMsgStoreCmdGetIteratorIdsAndFlags, TIpcArgs( aSortSessionId, &countPckg, &resultBuf ) ) );
       
  1316     
       
  1317     TMsgStoreId id;
       
  1318     TPckg<TMsgStoreId> idPckg( id );
       
  1319     
       
  1320     TUint32 flag;
       
  1321     TPckg<TUint32> flagPckg( flag );
       
  1322     
       
  1323     const TUint8* pointer = resultBuf.Ptr();
       
  1324     
       
  1325     if ( count > 0 )
       
  1326         {
       
  1327         while( pointer < resultBuf.Ptr() + resultBuf.Length() )
       
  1328             {
       
  1329             idPckg.Copy( pointer, idPckg.Length() );
       
  1330             pointer += idPckg.Length();
       
  1331             
       
  1332             flagPckg.Copy( pointer, flagPckg.Length() );
       
  1333             pointer += flagPckg.Length();
       
  1334             
       
  1335             aIdsAndFlags.Append( TMsgStoreIdAndFlag( id, flag ) );        
       
  1336             }
       
  1337         }
       
  1338     
       
  1339     CleanupStack::PopAndDestroy( &resultBuf );
       
  1340     
       
  1341     __LOG_EXIT
       
  1342 	}
       
  1343 
       
  1344 
       
  1345 // ==========================================================================
       
  1346 // FUNCTION: SortedIndexOfL
       
  1347 // ==========================================================================
       
  1348 TInt RMessageStoreSession::SortedIndexOfL( TMsgStoreId aSortSessionId, TMsgStoreId aMessageId )
       
  1349     {
       
  1350     __LOG_ENTER("SortedIndexOfL")
       
  1351     
       
  1352     TInt index = 0;
       
  1353     TPckg<TInt> indexPckg( index );
       
  1354     
       
  1355     User::LeaveIfError( SendReceive( EMsgStoreCmdSortedIndexOf, TIpcArgs( aSortSessionId, aMessageId, &indexPckg ) ) );
       
  1356     
       
  1357     __LOG_EXIT
       
  1358     
       
  1359     return index;
       
  1360     }
       
  1361 
       
  1362 // ==========================================================================
       
  1363 // FUNCTION: SortedIdsL
       
  1364 // ==========================================================================
       
  1365 void RMessageStoreSession::SortedIdsL( TMsgStoreId aSortSessionId, RArray<TMsgStoreId>& aMessageIds )
       
  1366 	{
       
  1367     __LOG_ENTER("SortedIdsL")
       
  1368     
       
  1369     TInt count = 0;
       
  1370     TPckg<TInt> countPckg( count );
       
  1371     
       
  1372     RBuf8 resultBuf;
       
  1373     CleanupClosePushL( resultBuf );
       
  1374     resultBuf.CreateL( KInitialSortedIdsAndFlagsBufferLength );
       
  1375     
       
  1376     User::LeaveIfError( SendReceive( EMsgStoreCmdGetIteratorIds, TIpcArgs( aSortSessionId, &countPckg, &resultBuf ) ) );
       
  1377     
       
  1378     TMsgStoreId id;
       
  1379     TPckg<TMsgStoreId> idPckg( id );
       
  1380     
       
  1381     const TUint8* pointer = resultBuf.Ptr();
       
  1382     
       
  1383     if ( count > 0 )
       
  1384         {
       
  1385         while( pointer < resultBuf.Ptr() + resultBuf.Length() )
       
  1386             {
       
  1387             idPckg.Copy( pointer, idPckg.Length() );
       
  1388             pointer += idPckg.Length();
       
  1389             
       
  1390             aMessageIds.Append( id );        
       
  1391             }
       
  1392         }
       
  1393     
       
  1394     CleanupStack::PopAndDestroy( &resultBuf );
       
  1395     
       
  1396     __LOG_EXIT
       
  1397 	}
       
  1398 
       
  1399 // ==========================================================================
       
  1400 // FUNCTION: IdsAndGroupCountL
       
  1401 // ==========================================================================
       
  1402 void RMessageStoreSession::IdsAndGroupCountL( TMsgStoreId aSortSessionId, RArray<TMsgStoreId>& aMessageIds, RArray<TUint>& aItemsInGroup )
       
  1403     {
       
  1404     __LOG_ENTER("IdsAndGroupCountL")
       
  1405     
       
  1406     TInt idCount = 0;
       
  1407     TPckg<TInt> idCountPckg( idCount );
       
  1408     TInt groupCount = 0;
       
  1409     TPckg<TInt> groupCountPckg( groupCount );
       
  1410     
       
  1411     RBuf8 resultBuf;
       
  1412     CleanupClosePushL( resultBuf );
       
  1413     resultBuf.CreateL( KInitialSortedIdsAndFlagsBufferLength );
       
  1414     
       
  1415     User::LeaveIfError( SendReceive( EMsgStoreCmdGetIteratorIdsAndGroupCount, TIpcArgs( aSortSessionId, &idCountPckg, &groupCountPckg, &resultBuf ) ) );
       
  1416 
       
  1417     //get the ID array
       
  1418     TMsgStoreId id;
       
  1419     TPckg<TMsgStoreId> idPckg( id );
       
  1420     
       
  1421     const TUint8* pointer = resultBuf.Ptr();
       
  1422     
       
  1423     while( (pointer < resultBuf.Ptr() + resultBuf.Length() ) && (idCount > 0) )
       
  1424         {
       
  1425         idPckg.Copy( pointer, idPckg.Length() );
       
  1426         pointer += idPckg.Length();
       
  1427         
       
  1428         aMessageIds.Append( id );
       
  1429         --idCount;
       
  1430         }
       
  1431     
       
  1432     //get the count array
       
  1433     TUint count;
       
  1434     TPckg<TUint> countPckg( count );
       
  1435     while( ( pointer < resultBuf.Ptr() + resultBuf.Length() ) && (groupCount > 0) )
       
  1436         {
       
  1437         countPckg.Copy( pointer, countPckg.Length() );
       
  1438         pointer += countPckg.Length();
       
  1439         
       
  1440         aItemsInGroup.Append( count ); 
       
  1441         --groupCount;
       
  1442         }
       
  1443     
       
  1444     CleanupStack::PopAndDestroy( &resultBuf );
       
  1445     
       
  1446     __LOG_EXIT
       
  1447     }
       
  1448 
       
  1449 // ==========================================================================
       
  1450 // FUNCTION: EndSortL
       
  1451 // ==========================================================================
       
  1452 void RMessageStoreSession::EndSortL( TMsgStoreId aSortSessionId )
       
  1453     {
       
  1454     __LOG_ENTER("EndSortL")
       
  1455     
       
  1456     User::LeaveIfError( SendReceive( EMsgStoreCmdEndSorting, TIpcArgs( aSortSessionId ) ) );
       
  1457     
       
  1458     __LOG_EXIT
       
  1459     }
       
  1460 
       
  1461 // ==========================================================================
       
  1462 // FUNCTION: PrepareSearchL
       
  1463 // ==========================================================================
       
  1464 void RMessageStoreSession::PrepareSearchL( RMsgStoreSearchCriteria& aSearchCriteria )
       
  1465     {
       
  1466     __LOG_ENTER( "PrepareSearchL" )
       
  1467     
       
  1468     TMsgStoreSearchCmdParams params;
       
  1469     TPckg<TMsgStoreSearchCmdParams> paramsPckg( params );
       
  1470     
       
  1471     params.iSearchFields       = aSearchCriteria.iSearchFields;
       
  1472     params.iSortBy             = aSearchCriteria.iSortBy;
       
  1473     params.iSortOrder          = aSearchCriteria.iSortOrder;
       
  1474     params.iSecondarySortOrder = aSearchCriteria.iSecondarySortOrder;
       
  1475    
       
  1476     // Serialize ID list.
       
  1477     TMsgStoreId        id;
       
  1478     TPckg<TMsgStoreId> idPckg( id );
       
  1479     
       
  1480     RArray<TMsgStoreId>& aIds = aSearchCriteria.FolderIds();
       
  1481     
       
  1482     RBuf8 idBuffer;            
       
  1483     idBuffer.CreateL( aIds.Count() * idPckg.Length() );
       
  1484     CleanupClosePushL( idBuffer );
       
  1485     
       
  1486     for( TInt i = 0; i < aIds.Count(); i++ )
       
  1487         {
       
  1488         id = aIds[i];
       
  1489         idBuffer.Append( idPckg );
       
  1490         } // end for
       
  1491 
       
  1492     //serialize the search names
       
  1493     TUint16 searchStringLen;
       
  1494     TPckg<TUint16> searchStringLenPckg( searchStringLen ); 
       
  1495     
       
  1496     const RPointerArray<TDesC>& searchStrings = aSearchCriteria.SearchStrings();
       
  1497     
       
  1498     TInt totalLength = 0;
       
  1499     for( TInt i = 0; i < searchStrings.Count(); i++ )
       
  1500         {
       
  1501         totalLength += (searchStrings[i]->Length() * 2 + searchStringLenPckg.Length());
       
  1502         } // end for
       
  1503     
       
  1504     RBuf8 searchStringsBuffer;            
       
  1505     searchStringsBuffer.CreateL( totalLength );
       
  1506     CleanupClosePushL( searchStringsBuffer );
       
  1507 
       
  1508     for( TInt i = 0; i < searchStrings.Count(); i++ )
       
  1509         {
       
  1510         TDesC& val = *searchStrings[i];
       
  1511         searchStringLen = val.Length() * 2;
       
  1512         searchStringsBuffer.Append( searchStringLenPckg );
       
  1513         
       
  1514         const TUint8* valuePtr = reinterpret_cast<const TUint8*>( val.Ptr() );
       
  1515         TPtrC8 valueDes8( valuePtr, searchStringLen );  
       
  1516         searchStringsBuffer.Append( valueDes8 );
       
  1517         } // end for
       
  1518     
       
  1519     // Serialize property names.
       
  1520     TUint16 nameLength;
       
  1521     TPckg<TUint16> nameLengthPckg( nameLength );        
       
  1522 
       
  1523     const RPointerArray<TDesC8>& aPropertyNames = aSearchCriteria.PropertyKeys();
       
  1524     
       
  1525     totalLength = 0;
       
  1526     for( TInt i = 0; i < aPropertyNames.Count(); i++ )
       
  1527         {
       
  1528         totalLength += (aPropertyNames[i]->Length() + nameLengthPckg.Length());
       
  1529         } // end for
       
  1530     
       
  1531     RBuf8 propertyNamesBuffer;            
       
  1532     propertyNamesBuffer.CreateL( totalLength );
       
  1533     CleanupClosePushL( propertyNamesBuffer );
       
  1534 
       
  1535     for( TInt i = 0; i < aPropertyNames.Count(); i++ )
       
  1536         {
       
  1537         nameLength = aPropertyNames[i]->Length();
       
  1538         propertyNamesBuffer.Append( nameLengthPckg );
       
  1539         propertyNamesBuffer.Append( *aPropertyNames[i] );
       
  1540         } // end for
       
  1541     
       
  1542     User::LeaveIfError( SendReceive( EMsgStoreCmdPrepareSearch, TIpcArgs( &paramsPckg, &searchStringsBuffer, &idBuffer, &propertyNamesBuffer ) ) );
       
  1543     
       
  1544     CleanupStack::PopAndDestroy( &propertyNamesBuffer );
       
  1545     CleanupStack::PopAndDestroy( &searchStringsBuffer );
       
  1546     CleanupStack::PopAndDestroy( &idBuffer );
       
  1547 	
       
  1548 	__LOG_EXIT
       
  1549     } // end PrepareSearchL
       
  1550 
       
  1551 // ==========================================================================
       
  1552 // FUNCTION: GetMatchesL
       
  1553 // ==========================================================================
       
  1554 
       
  1555 void RMessageStoreSession::GetMatchesL( TRequestStatus& aStatus, TDes8& aBuffer )
       
  1556     {
       
  1557     __LOG_ENTER( "GetMatchesL" )
       
  1558     
       
  1559     aBuffer.SetLength( 0 );
       
  1560 	SendReceive( EMsgStoreCmdGetMatches, TIpcArgs( &aBuffer ), aStatus );    
       
  1561 	
       
  1562 	__LOG_EXIT
       
  1563     } // end GetMatchesL
       
  1564 
       
  1565 // ==========================================================================
       
  1566 // FUNCTION: CancelSearch
       
  1567 // ==========================================================================
       
  1568 void RMessageStoreSession::CancelSearch()
       
  1569     {
       
  1570     __LOG_ENTER( "CancelSearch" )
       
  1571     
       
  1572 	SendReceive( EMsgStoreCmdCancelSearch );        
       
  1573 	
       
  1574 	__LOG_EXIT
       
  1575     } // end CancelSearch
       
  1576 
       
  1577 // ==========================================================================
       
  1578 // FUNCTION: CleanupSearchResultCache
       
  1579 // ==========================================================================
       
  1580 void RMessageStoreSession::ClearSearchResultCache()
       
  1581     {
       
  1582     __LOG_ENTER( "CleanupSearchResultCache" )
       
  1583     
       
  1584     SendReceive( EMsgStoreCmdClearSearchResultCache );        
       
  1585     
       
  1586     __LOG_EXIT
       
  1587     }
       
  1588 
       
  1589 // ==========================================================================
       
  1590 // FUNCTION: SetMaxMruAddressCountL
       
  1591 // ==========================================================================
       
  1592 void RMessageStoreSession::SetMaxMruAddressCountL( TInt aMaxCount )
       
  1593     {
       
  1594     __LOG_ENTER( "SetMaxMruAddressCountL" )
       
  1595     
       
  1596     SendReceive( EMsgStoreCmdSetMaxMruAddressCount, TIpcArgs( aMaxCount ) );        
       
  1597     
       
  1598     __LOG_EXIT
       
  1599     }
       
  1600 
       
  1601 // ==========================================================================
       
  1602 // FUNCTION: AddMruAddressesL
       
  1603 // ==========================================================================
       
  1604 void RMessageStoreSession::AddMruAddressesL( TMsgStoreId aMailBoxId, RPointerArray<CMsgStoreAddress>& aAddressArray )
       
  1605     {
       
  1606     __LOG_ENTER( "AddMruAddressesL" )
       
  1607     
       
  1608     //find out the size needed for serializing the addresses
       
  1609     TInt totalSize = 0 ;
       
  1610     TInt count = aAddressArray.Count();
       
  1611     TInt sizeOfLengthFields = sizeof( TUint16 ) * 2;  //two lengths
       
  1612     for ( TInt i = 0 ; i < count ; i++ )
       
  1613         {
       
  1614         totalSize += sizeOfLengthFields;
       
  1615         CMsgStoreAddress* address = aAddressArray[i];
       
  1616         totalSize += (address->EmailAddress().Length() * 2);
       
  1617         totalSize += (address->DisplayName().Length() * 2);
       
  1618         }
       
  1619     
       
  1620     TUint16 length;
       
  1621     TPckg<TUint16> lengthPckg( length );                        
       
  1622     
       
  1623     RBuf8 serializedBuf;
       
  1624     CleanupClosePushL( serializedBuf );
       
  1625     serializedBuf.Create( totalSize );
       
  1626     
       
  1627     for( TInt i = 0 ; i < count ; i++ )
       
  1628         {
       
  1629         CMsgStoreAddress* address = aAddressArray[i];
       
  1630         
       
  1631         //write the email address
       
  1632         //length first
       
  1633         length = address->EmailAddress().Length() * 2;
       
  1634         serializedBuf.Append( lengthPckg );
       
  1635         
       
  1636         //convert the 16 bit descriptor to 8 bit descriptor
       
  1637         const TUint8* addressPtr = reinterpret_cast<const TUint8*>( address->EmailAddress().Ptr() );
       
  1638         TPtrC8 addressDes( addressPtr, length );  
       
  1639         serializedBuf.Append( addressDes );
       
  1640         
       
  1641         //write the displayName
       
  1642         //length first
       
  1643         length = address->DisplayName().Length() * 2;
       
  1644         serializedBuf.Append( lengthPckg );
       
  1645         
       
  1646         //convert the 16 bit descriptor to 8 bit descriptor
       
  1647         const TUint8* namePtr = reinterpret_cast<const TUint8*>( address->DisplayName().Ptr() );
       
  1648         TPtrC8 nameDes( namePtr, length );  
       
  1649         serializedBuf.Append( nameDes );
       
  1650         }
       
  1651     SendReceive( EMsgStoreCmdSetMruAddressList, TIpcArgs( aMailBoxId, &serializedBuf ) );        
       
  1652     
       
  1653     CleanupStack::PopAndDestroy( &serializedBuf );
       
  1654     
       
  1655     __LOG_EXIT
       
  1656     }
       
  1657 
       
  1658 // ==========================================================================
       
  1659 // FUNCTION: MruAddressesL
       
  1660 // ==========================================================================
       
  1661 void RMessageStoreSession::MruAddressesL( TMsgStoreId aMailBoxId, RPointerArray<CMsgStoreAddress>& aAddressArray )
       
  1662     {
       
  1663     __LOG_ENTER( "MruAddressesL" )
       
  1664     
       
  1665     TUint result = 1;
       
  1666     TPckg<TUint> resultPckg( result );
       
  1667     
       
  1668     RBuf8 serializedBuf;
       
  1669     CleanupClosePushL( serializedBuf );
       
  1670     serializedBuf.CreateL( KInitialPropertiesTransferBufferLength );
       
  1671     
       
  1672     while( result != 0 )
       
  1673         {      
       
  1674         User::LeaveIfError( SendReceive( EMsgStoreCmdGetMruAddressList, TIpcArgs( aMailBoxId, &resultPckg, &serializedBuf ) ) );
       
  1675         
       
  1676         // The buffer was too small.  Reallocate.
       
  1677         if( result != 0 )
       
  1678             {
       
  1679             __LOG_WRITE8_FORMAT1_INFO( "growing buffer to %i", result );
       
  1680             serializedBuf.ReAllocL( result );
       
  1681             }
       
  1682         } // end while
       
  1683 
       
  1684     TUint16 length;
       
  1685     TPckg<TUint16> lengthPckg( length );                        
       
  1686     
       
  1687     const TUint8* pointer = serializedBuf.Ptr();
       
  1688     const TUint8* endPointer = serializedBuf.Ptr() + serializedBuf.Length();
       
  1689 
       
  1690     // Deserialize data until the current buffer is exhausted.
       
  1691     while( pointer < endPointer )
       
  1692         {
       
  1693         //get the length of email address
       
  1694         lengthPckg.Copy( pointer, lengthPckg.Length() );
       
  1695         pointer += lengthPckg.Length();
       
  1696         
       
  1697         //get the 16 bit email address
       
  1698         const TUint16* addrPtr16 = reinterpret_cast<const TUint16*>( pointer );
       
  1699         TPtrC16 addrDes16( addrPtr16, length/2 );  
       
  1700         pointer += length;
       
  1701                     
       
  1702         //get the length of display name
       
  1703         lengthPckg.Copy( pointer, lengthPckg.Length() );
       
  1704         pointer += lengthPckg.Length();
       
  1705         
       
  1706         //get the 16 bit display name
       
  1707         const TUint16* namePtr16 = reinterpret_cast<const TUint16*>( pointer );
       
  1708         TPtrC16 nameDes16( namePtr16, length/2 );  
       
  1709         pointer += length;
       
  1710     
       
  1711         //create the address object and add it to the output array
       
  1712         CMsgStoreAddress *address = CMsgStoreAddress::NewL( addrDes16, nameDes16 );
       
  1713         aAddressArray.Append( address );            
       
  1714         } // end while          
       
  1715     
       
  1716     CleanupStack::PopAndDestroy( &serializedBuf );
       
  1717     
       
  1718     __LOG_EXIT
       
  1719     }
       
  1720 
       
  1721 
       
  1722 // ==========================================================================
       
  1723 // FUNCTION: ContainerTypeById
       
  1724 // ==========================================================================
       
  1725 TMsgStoreContainerType RMessageStoreSession::ContainerTypeById( TMsgStoreId aId )
       
  1726     {
       
  1727     
       
  1728     TMsgStoreContainerType resultType = EMsgStoreUnknownContainer;
       
  1729     
       
  1730     TMsgStoreId type = aId & EMsgStoreContainerMask;
       
  1731     
       
  1732     switch( type )
       
  1733         {
       
  1734         case EMsgStoreMailBoxBits:
       
  1735             resultType = EMsgStoreMailboxContainer;
       
  1736             break;
       
  1737             
       
  1738         case EMsgStoreFolderBits:
       
  1739             resultType = EMsgStoreFolderContainer;
       
  1740             break;
       
  1741             
       
  1742         case EMsgStoreMessageBits:
       
  1743             resultType = EMsgStoreMessageContainer;
       
  1744             break;
       
  1745             
       
  1746         case EMsgStorePartBits:
       
  1747             resultType = EMsgStorePartContainer;
       
  1748             break;
       
  1749         }
       
  1750     
       
  1751     return resultType;
       
  1752     }
       
  1753 
       
  1754 
       
  1755 // ==========================================================================
       
  1756 // FUNCTION: PropertiesL
       
  1757 // ==========================================================================
       
  1758 void RMessageStoreSession::PropertiesL( const RArray<TMsgStoreId>&   aIds, 
       
  1759                                         const RPointerArray<TDesC8>& aPropertyNames, 
       
  1760                                         MPropertiesArray&            aPropertiesArray )
       
  1761     {
       
  1762     __LOG_ENTER( "PropertiesL" )
       
  1763     
       
  1764     TMsgStorePropertiesListCmdParams params;
       
  1765     
       
  1766 	params.iUseQuery        = EFalse;
       
  1767 	params.iQuickProperties = EFalse;   
       
  1768 
       
  1769     // Serialize ID list.
       
  1770     TMsgStoreId        id;
       
  1771     TPckg<TMsgStoreId> idPckg( id );
       
  1772     
       
  1773     RBuf8 idBuffer;            
       
  1774     idBuffer.CreateL( aIds.Count() * idPckg.Length() );
       
  1775     CleanupClosePushL( idBuffer );
       
  1776     
       
  1777     for( TInt i = 0; i < aIds.Count(); i++ )
       
  1778         {
       
  1779         id = aIds[i];
       
  1780         idBuffer.Append( idPckg );
       
  1781         } // end for
       
  1782 
       
  1783     // Serialize property names.
       
  1784     TUint16 nameLength;
       
  1785     TPckg<TUint16> nameLengthPckg( nameLength );                        
       
  1786     
       
  1787     TInt totalLength = 0;
       
  1788     for( TInt i = 0; i < aPropertyNames.Count(); i++ )
       
  1789         {
       
  1790         totalLength += (aPropertyNames[i]->Length() + nameLengthPckg.Length());
       
  1791         } // end for
       
  1792         
       
  1793     RBuf8 propertyNamesBuffer;            
       
  1794     propertyNamesBuffer.CreateL( totalLength );
       
  1795     CleanupClosePushL( propertyNamesBuffer );
       
  1796 
       
  1797     for( TInt i = 0; i < aPropertyNames.Count(); i++ )
       
  1798         {
       
  1799         nameLength = aPropertyNames[i]->Length();
       
  1800         propertyNamesBuffer.Append( nameLengthPckg );
       
  1801         propertyNamesBuffer.Append( *aPropertyNames[i] );
       
  1802         } // end for
       
  1803                 
       
  1804     // Call server.
       
  1805     DoPropertiesListL( params, idBuffer, propertyNamesBuffer, aPropertiesArray );
       
  1806 
       
  1807     CleanupStack::PopAndDestroy( &propertyNamesBuffer );
       
  1808     CleanupStack::PopAndDestroy( &idBuffer );
       
  1809     	
       
  1810 	__LOG_EXIT    
       
  1811     } // end PropertiesL
       
  1812 
       
  1813 /**
       
  1814  * 
       
  1815  */
       
  1816 void RMessageStoreSession::BeginBatchInsertL()
       
  1817     {
       
  1818     User::LeaveIfError( SendReceive( EMsgStoreCmdBeginBatchInsert ) );
       
  1819     }
       
  1820 
       
  1821 /**
       
  1822  * 
       
  1823  */
       
  1824 void RMessageStoreSession::FinishBatchInsertL()
       
  1825     {
       
  1826     User::LeaveIfError( SendReceive( EMsgStoreCmdFinishBatchInsert ) );
       
  1827     }