emailservices/emailstore/message_store/client/src/MsgStoreMailBox.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 mailbox client implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //<cmail>
       
    21 #include "MsgStoreMailBox.h"
       
    22 #include "DebugLogMacros.h"
       
    23 #include "RMessageStoreSession.h"
       
    24 #include "MsgStoreSessionContext.h"
       
    25 #include "MsgStoreFolder.h"
       
    26 #include "MsgStoreMessage.h"
       
    27 #include "MsgStorePropertyKeys.h"
       
    28 #include "MsgStoreObserverHandler.h"
       
    29 #include "MsgStorePropertyContainersArray.h"
       
    30 #include "MsgStoreSortCriteria.h"
       
    31 #include "MsgStoreSortResultIterator.h"
       
    32 #include "MsgStoreSearchHandler.h"
       
    33 #include "MsgStoreSearchCriteria.h"
       
    34 //#include "IsMsgStorePropertyKeys.h"
       
    35 //</cmail>
       
    36 
       
    37 // ====================
       
    38 // Internal CLASS: TFoldersArray
       
    39 // ====================
       
    40 class TFoldersArray : public MPropertiesArray
       
    41     {
       
    42     public:    
       
    43 
       
    44         // ==============
       
    45         // PUBLIC METHODS
       
    46         // ==============
       
    47         
       
    48         TFoldersArray( CMsgStoreSessionContext& aContext, TMsgStoreId aMailBoxId, RPointerArray<CMsgStoreFolder>& aFolders );
       
    49                
       
    50         // inherited from MPropertiesArray              
       
    51         virtual void AddElementL( TMsgStoreId aId, TMsgStoreId aParentId, const TDesC8& aProperties );
       
    52         virtual void Reset();        
       
    53     
       
    54     private:
       
    55 
       
    56         // ==================
       
    57         // PRIVATE ATTRIBUTES
       
    58         // ==================
       
    59     
       
    60         CMsgStoreSessionContext&        iContext;
       
    61         RPointerArray<CMsgStoreFolder>& iFolders;
       
    62         const TMsgStoreId 				iMailBoxId;
       
    63         
       
    64     }; // end class TFoldersArray
       
    65     
       
    66 // -------------	
       
    67 // TFoldersArray
       
    68 // -------------	
       
    69 
       
    70 // ==========================================================================
       
    71 // FUNCTION: Constructor
       
    72 // ==========================================================================
       
    73 TFoldersArray::TFoldersArray( CMsgStoreSessionContext& aContext, TMsgStoreId aMailBoxId, RPointerArray<CMsgStoreFolder>& aFolders ) : 
       
    74 iContext( aContext ), iFolders( aFolders ), iMailBoxId(aMailBoxId)
       
    75     {
       
    76     } // end 
       
    77        
       
    78 // ==========================================================================
       
    79 // FUNCTION: AddElementL 
       
    80 // ==========================================================================
       
    81 void TFoldersArray::AddElementL( TMsgStoreId aId, TMsgStoreId aParentId, const TDesC8& aProperties )
       
    82     {
       
    83 	CMsgStoreFolder *newFolder = CMsgStoreFolder::NewL( iContext, aId, aParentId, iMailBoxId, aProperties );
       
    84 	CleanupStack::PushL( newFolder );
       
    85 	
       
    86 	iFolders.AppendL( newFolder );    
       
    87 	
       
    88 	CleanupStack::Pop( newFolder );
       
    89     } // end AddElementL
       
    90     
       
    91 // ==========================================================================
       
    92 // FUNCTION: Reset
       
    93 // ==========================================================================
       
    94 void TFoldersArray::Reset()
       
    95     {
       
    96 	iFolders.ResetAndDestroy();
       
    97     } // end Reset
       
    98 
       
    99 // ==========================================================================
       
   100 // FUNCTION: AddObserverL
       
   101 // ==========================================================================
       
   102 EXPORT_C void CMsgStoreMailBox::AddObserverL( MMsgStoreMailBoxObserver* aObserver )
       
   103     {
       
   104 	if( !iContext.iObserverHandler )
       
   105 	    {	 
       
   106     	iContext.iObserverHandler = CMsgStoreObserverHandler::NewL( iContext.iSession );
       
   107 	    } // end if
       
   108 		    
       
   109 	iContext.iObserverHandler->AddObserverL( aObserver, Id() );
       
   110     }
       
   111 		
       
   112 // ==========================================================================
       
   113 // FUNCTION: RemoveObserverL
       
   114 // ==========================================================================
       
   115 EXPORT_C void CMsgStoreMailBox::RemoveObserverL( MMsgStoreMailBoxObserver* aObserver )
       
   116     {
       
   117 	if( !iContext.iObserverHandler )
       
   118 	    {
       
   119     	User::Leave( KErrNotFound );
       
   120 	    }
       
   121 	else
       
   122 	    {	    
       
   123     	iContext.iObserverHandler->RemoveObserverL( aObserver, Id() );
       
   124 	    } // end if
       
   125     }
       
   126 
       
   127 		
       
   128 // ==========================================================================
       
   129 // FUNCTION: FetchPropertiesL
       
   130 // ==========================================================================
       
   131 EXPORT_C void CMsgStoreMailBox::FetchPropertiesL( const RArray<TMsgStoreId>&                 aIds, 
       
   132                                                   const RPointerArray<TDesC8>&               aPropertyNames, 
       
   133                                                   RPointerArray<CMsgStorePropertyContainer>& aProperties )
       
   134     {
       
   135     if( aIds.Count() == 0 || aPropertyNames.Count() == 0 )
       
   136         {
       
   137     	__LOG_STATIC_ENTER( "MsgClient", "FetchPropertiesL" )
       
   138     	__LOG_WRITE_ERROR( "empty input array" )
       
   139    		__LOG_STATIC_EXIT
       
   140    		User::Leave( KErrArgument );
       
   141         } // end if
       
   142     
       
   143 	TMsgStorePropertyContainersArray containersArray( aProperties );
       
   144 	
       
   145     iContext.iSession.PropertiesL( aIds, aPropertyNames, containersArray );
       
   146     } // end FetchPropertiesL
       
   147 
       
   148 // ==========================================================================
       
   149 // FUNCTION: FetchPropertiesL
       
   150 // ==========================================================================
       
   151 EXPORT_C CMsgStoreWritablePropertyContainer* CMsgStoreMailBox::FetchPropertiesL( TMsgStoreId aId )
       
   152     {
       
   153     TMsgStoreId parentId = KMsgStoreInvalidId;
       
   154     
       
   155     RBuf8 propertiesBuf;
       
   156     CleanupClosePushL( propertiesBuf );
       
   157     
       
   158     iContext.iSession.ContainerPropertiesL( aId, parentId, KMsgStoreInvalidId, propertiesBuf );
       
   159     
       
   160     CMsgStoreWritablePropertyContainer* properties = CMsgStoreWritablePropertyContainer::NewL( iContext, aId, parentId, iId, propertiesBuf );
       
   161     
       
   162     CleanupStack::PopAndDestroy( &propertiesBuf );
       
   163 
       
   164     return properties;
       
   165     
       
   166     }
       
   167 		
       
   168 // ----------------
       
   169 // FOLDER FUNCTIONS
       
   170 // ----------------
       
   171 
       
   172 // ==========================================================================
       
   173 // FUNCTION: CreateFolderL
       
   174 // ==========================================================================
       
   175 EXPORT_C TMsgStoreId CMsgStoreMailBox::CreateFolderL( TMsgStoreId                 aParentId, 
       
   176 													  CMsgStorePropertyContainer& aProperties,
       
   177 													  TBool                       aIsLocal)
       
   178     {
       
   179 	//the parentId needs to be either a MailBox or a Folder
       
   180 	iContext.VerifyTypeL( aParentId, EMsgStoreMailBoxBits, EMsgStoreFolderBits );
       
   181 
       
   182 	aProperties.AddOrUpdatePropertyL( KMsgStorePropertyLocal, (TBool)aIsLocal );
       
   183 	
       
   184 	RBuf8 serializedProperties;
       
   185 	CleanupClosePushL( serializedProperties );
       
   186 	aProperties.SerializeL( serializedProperties );
       
   187 	
       
   188 	TInt id = iContext.iSession.CreateContainerL( aParentId, 
       
   189 												  KMsgStoreInvalidId, // do not check grandparent ID
       
   190 												  iId,                // mail box id
       
   191 												  EMsgStoreFolderBits,
       
   192 												  serializedProperties );
       
   193 	
       
   194 	CleanupStack::PopAndDestroy( &serializedProperties );
       
   195 	
       
   196 	return id;
       
   197     }
       
   198 
       
   199 
       
   200 // ==========================================================================
       
   201 // FUNCTION: DeleteFolderL
       
   202 // ==========================================================================
       
   203 EXPORT_C void CMsgStoreMailBox::DeleteFolderL( TMsgStoreId aId )
       
   204     {
       
   205 	iContext.VerifyTypeL( aId, EMsgStoreFolderBits );
       
   206 	
       
   207 	// Do not check location of folder.
       
   208 	iContext.iSession.DeleteContainerL( aId, KMsgStoreInvalidId, KMsgStoreInvalidId, iId );
       
   209     }
       
   210 
       
   211 		
       
   212 // ==========================================================================
       
   213 // FUNCTION: FoldersL
       
   214 // ==========================================================================
       
   215 EXPORT_C void CMsgStoreMailBox::FoldersL( RPointerArray<CMsgStoreFolder>& aFolders )
       
   216     {
       
   217 	aFolders.ResetAndDestroy();
       
   218 	
       
   219 	TFoldersArray foldersArray( iContext, iId, aFolders );
       
   220 	
       
   221 	iContext.iSession.ChildrenPropertiesL( iId,                     // aId 
       
   222 	                                       KMsgStoreInvalidId,     // aParentId (do not need to check parent ID)
       
   223 	                                       EMsgStoreFolderBits,    // aContainerType
       
   224 	                                       EFalse,                 // aQuickProperties
       
   225 	                                       ETrue,                  // aRecursive
       
   226 	                                       foldersArray );
       
   227 	
       
   228     }
       
   229 
       
   230 // ==========================================================================
       
   231 // FUNCTION: FoldersL
       
   232 // ==========================================================================
       
   233 EXPORT_C void CMsgStoreMailBox::FoldersL( TMsgStoreId aFolderId, 
       
   234                                           RPointerArray<CMsgStoreFolder>& aFolders,
       
   235                                           TBool                           aRecursive )
       
   236     {
       
   237 	iContext.VerifyTypeL( aFolderId, EMsgStoreMailBoxBits, EMsgStoreFolderBits );
       
   238 	
       
   239 	TFoldersArray foldersArray( iContext, iId, aFolders );
       
   240 	
       
   241 	iContext.iSession.ChildrenPropertiesL( aFolderId,           // aId
       
   242 	                                       KMsgStoreInvalidId,  // aParentId (do not need to check parent ID)
       
   243 	                                       EMsgStoreFolderBits, // aContainerType
       
   244 	                                       EFalse,              // aQuickProperties
       
   245 	                                       aRecursive,         
       
   246 	                                       foldersArray );	
       
   247     } // end FoldersL
       
   248 		
       
   249 // ==========================================================================
       
   250 // FUNCTION: FolderL
       
   251 // ==========================================================================
       
   252 EXPORT_C CMsgStoreFolder* CMsgStoreMailBox::FolderL( TMsgStoreId aId )
       
   253     {
       
   254 	iContext.VerifyTypeL( aId, EMsgStoreFolderBits );
       
   255 	
       
   256 	TMsgStoreId parentId = KMsgStoreInvalidId;
       
   257 	
       
   258 	RBuf8 propertiesBuf;
       
   259 	CleanupClosePushL( propertiesBuf );
       
   260 	
       
   261 	iContext.iSession.ContainerPropertiesL( aId, parentId, KMsgStoreInvalidId, propertiesBuf );
       
   262 	
       
   263 	CMsgStoreFolder* folder = CMsgStoreFolder::NewL( iContext, aId, parentId, iId, propertiesBuf );
       
   264 	
       
   265 	CleanupStack::PopAndDestroy( &propertiesBuf );
       
   266 
       
   267 	return folder;
       
   268     }
       
   269 
       
   270 // -----------------
       
   271 // MESSAGE FUNCTIONS
       
   272 // -----------------
       
   273 
       
   274 // ==========================================================================
       
   275 // FUNCTION: CreateMessageL
       
   276 // ==========================================================================
       
   277 EXPORT_C CMsgStoreMessage* CMsgStoreMailBox::CreateMessageL( TMsgStoreId aFolderId, const CMsgStorePropertyContainer& aProperties )
       
   278     {
       
   279 	iContext.VerifyTypeL( aFolderId, EMsgStoreFolderBits );
       
   280 	
       
   281 	RBuf8 serializedProperties;
       
   282 	CleanupClosePushL( serializedProperties );
       
   283 	aProperties.SerializeL( serializedProperties );
       
   284 	
       
   285 	// Temporarily create the message in the scratch folder, until the commit function is called.
       
   286 	TInt id = iContext.iSession.CreateContainerL( aFolderId, 
       
   287 												  KMsgStoreInvalidId, // do not check grandparent ID
       
   288 												  iId,                // mail box id
       
   289 												  EMsgStoreMessageBits,
       
   290 												  serializedProperties,
       
   291 												  EFalse );  // do not commit
       
   292 	
       
   293 	CMsgStoreMessage* message = CMsgStoreMessage::NewL( iContext, id, KMsgStoreInvalidId, aFolderId, iId, serializedProperties );
       
   294 	
       
   295 	CleanupStack::PopAndDestroy( &serializedProperties );
       
   296 	
       
   297 	return message;
       
   298     }
       
   299 
       
   300 // ==========================================================================
       
   301 // FUNCTION: FetchMessageL
       
   302 // ==========================================================================
       
   303 EXPORT_C CMsgStoreMessage* CMsgStoreMailBox::FetchMessageL( TMsgStoreId aMessageId, TMsgStoreId aFolderId )
       
   304     {										  
       
   305 	iContext.VerifyTypeL( aMessageId, EMsgStoreMessageBits );
       
   306 	iContext.VerifyTypeL( aFolderId, EMsgStoreFolderBits );
       
   307 	
       
   308 	TMsgStoreId parentId = aFolderId;
       
   309 	
       
   310 	RBuf8 propertiesBuf;
       
   311 	CleanupClosePushL( propertiesBuf );
       
   312 	
       
   313 	iContext.iSession.ContainerPropertiesL( aMessageId, parentId, KMsgStoreInvalidId, propertiesBuf, iId );
       
   314 	
       
   315 	CMsgStoreMessage* message = CMsgStoreMessage::NewL( iContext, aMessageId, parentId, parentId, iId, propertiesBuf );
       
   316 	
       
   317 	CleanupStack::PopAndDestroy( &propertiesBuf );
       
   318 	
       
   319 	return message;
       
   320     }
       
   321 		
       
   322 // ==========================================================================
       
   323 // FUNCTION: DeleteMessageL
       
   324 // ==========================================================================
       
   325 EXPORT_C void CMsgStoreMailBox::DeleteMessageL( TMsgStoreId aMessageId, TMsgStoreId aFolderId )
       
   326     {
       
   327 	iContext.VerifyTypeL( aMessageId, EMsgStoreMessageBits );
       
   328 	iContext.VerifyTypeL( aFolderId, EMsgStoreFolderBits );
       
   329 
       
   330 	iContext.iSession.DeleteContainerL( aMessageId, aFolderId, KMsgStoreInvalidId, iId );	
       
   331     } // end DeleteMessageL
       
   332 
       
   333 		
       
   334 // ==========================================================================
       
   335 // FUNCTION: MoveMessageL
       
   336 // ==========================================================================
       
   337 EXPORT_C void CMsgStoreMailBox::MoveMessageL( TMsgStoreId aMessageId, 
       
   338 											  TMsgStoreId aSourceFolderId, 
       
   339 											  TMsgStoreId aDestinationFolderId )
       
   340     {
       
   341 	iContext.VerifyTypeL( aMessageId, EMsgStoreMessageBits );
       
   342 	iContext.VerifyTypeL( aSourceFolderId, EMsgStoreFolderBits );
       
   343 	iContext.VerifyTypeL( aDestinationFolderId, EMsgStoreFolderBits );
       
   344 
       
   345 	iContext.iSession.MoveContainerL( aMessageId, aSourceFolderId, aDestinationFolderId );	
       
   346     } // end MoveMessageL
       
   347 
       
   348 
       
   349 EXPORT_C void CMsgStoreMailBox::MoveFolderL( TMsgStoreId aFolderId, 
       
   350 											  TMsgStoreId aSourceFolderId, 
       
   351 											  TMsgStoreId aDestinationFolderId )
       
   352     {
       
   353 	iContext.VerifyTypeL( aFolderId, EMsgStoreFolderBits );
       
   354 	iContext.VerifyTypeL( aSourceFolderId, EMsgStoreFolderBits, EMsgStoreMailBoxBits );
       
   355 	iContext.VerifyTypeL( aDestinationFolderId, EMsgStoreFolderBits, EMsgStoreMailBoxBits );
       
   356 
       
   357 	iContext.iSession.MoveContainerL( aFolderId, aSourceFolderId, aDestinationFolderId );	
       
   358     } // end MoveMessageL
       
   359 
       
   360 
       
   361 // ==========================================================================
       
   362 // FUNCTION: CopyMessageL
       
   363 // ==========================================================================
       
   364 EXPORT_C TMsgStoreId CMsgStoreMailBox::CopyMessageL( TMsgStoreId aMessageId, 
       
   365 													 TMsgStoreId aSourceFolderId, 
       
   366 													 TMsgStoreId aDestinationFolderId )
       
   367     {
       
   368 	iContext.VerifyTypeL( aMessageId, EMsgStoreMessageBits );
       
   369 	iContext.VerifyTypeL( aSourceFolderId, EMsgStoreFolderBits );
       
   370 	iContext.VerifyTypeL( aDestinationFolderId, EMsgStoreFolderBits );
       
   371 	
       
   372 	return iContext.iSession.CopyContainerL( aMessageId, 
       
   373 	                                          aSourceFolderId,
       
   374 	                                          KMsgStoreInvalidId,   // don't care
       
   375 	                                          aDestinationFolderId,
       
   376 	                                          KMsgStoreInvalidId,   // don't care
       
   377 	                                          iId);					// mailbox id
       
   378     }		
       
   379 		
       
   380 // ==========================================================================
       
   381 // FUNCTION: MessageIdsL
       
   382 // ==========================================================================
       
   383 EXPORT_C void CMsgStoreMailBox::MessageIdsL( TMsgStoreId aFolderId, RArray<TMsgStoreId>& aMessageIdList )
       
   384     {
       
   385 	iContext.VerifyTypeL( aFolderId, EMsgStoreFolderBits );
       
   386 	
       
   387 	aMessageIdList.Reset();
       
   388 	iContext.iSession.ChildrenIdsL( aFolderId, EMsgStoreMessageBits, aMessageIdList );
       
   389     }
       
   390 	
       
   391 // ==========================================================================
       
   392 // FUNCTION: MessageCountsL
       
   393 // ==========================================================================
       
   394 EXPORT_C void CMsgStoreMailBox::MessageCountsL( TMsgStoreId aFolderId, 
       
   395 												TUint&      aTotalCount, 
       
   396 												TUint&      aUnreadCount )
       
   397     {
       
   398 	iContext.VerifyTypeL( aFolderId, EMsgStoreFolderBits );
       
   399 	
       
   400 	iContext.iSession.ChildrenCountsL( aFolderId, aTotalCount, aUnreadCount );
       
   401     } // end MessageCountsL
       
   402 
       
   403 
       
   404 // ==========================================================================
       
   405 // FUNCTION: TotalMessageCountsL
       
   406 // ==========================================================================
       
   407 EXPORT_C void CMsgStoreMailBox::TotalMessageCountsL( TUint& aTotalCount, 
       
   408 													 TUint& aUnreadCount )
       
   409     {
       
   410 	iContext.iSession.TotalCountsL( iId, aTotalCount, aUnreadCount );
       
   411     } // end TotalMessageCountsL
       
   412 
       
   413 // ==========================================================================
       
   414 // FUNCTION: SortL
       
   415 // ==========================================================================
       
   416 EXPORT_C CMsgStoreSortResultIterator* CMsgStoreMailBox::SortL( RMsgStoreSortCriteria& aSortCriteria, TBool aInMemorySort )
       
   417     {
       
   418     if( aSortCriteria.PropertyKeys().Count() == 0 )
       
   419         {
       
   420         __LOG_STATIC_ENTER( "MsgClient", "SortL" )
       
   421         __LOG_WRITE_ERROR( "empty property array" )
       
   422         __LOG_STATIC_EXIT
       
   423         User::Leave( KErrArgument );
       
   424         } // end if
       
   425     
       
   426     TMsgStoreId sortSessionId = iContext.iSession.SortL( aSortCriteria, iId, aInMemorySort );
       
   427     return CMsgStoreSortResultIterator::NewL( iContext, sortSessionId );
       
   428     }
       
   429 
       
   430 // ==========================================================================
       
   431 // FUNCTION: SearchL
       
   432 // ==========================================================================
       
   433 EXPORT_C void CMsgStoreMailBox::SearchL( RMsgStoreSearchCriteria&  aSearchCriteria,
       
   434                                          MMsgStoreSearchClient&    aSearchClient )
       
   435     {
       
   436     if( aSearchCriteria.SearchStrings().Count() == 0  )
       
   437         {
       
   438         __LOG_STATIC_ENTER( "MsgClient", "SearchL" )
       
   439         __LOG_WRITE_ERROR( "no search string" )
       
   440         __LOG_STATIC_EXIT
       
   441         User::Leave( KErrArgument );
       
   442         } // end if
       
   443     
       
   444     TBool isEmptyFolderIdArray = EFalse;
       
   445     RArray<TMsgStoreId>& folderIds = aSearchCriteria.FolderIds();
       
   446     if( folderIds.Count() == 0 )
       
   447         {
       
   448         //a "global" search is requested, fill in with all the folders ids
       
   449         RPointerArray<CMsgStoreFolder> folders;
       
   450         FoldersL( folders );
       
   451         for ( TInt i = 0 ; i < folders.Count() ; i++ )
       
   452             {
       
   453             aSearchCriteria.AddFolderId( folders[i]->Id() );
       
   454             }
       
   455         folders.ResetAndDestroy();
       
   456         isEmptyFolderIdArray = ETrue;
       
   457         } // end if
       
   458     else
       
   459         {
       
   460         for ( TInt i = 0 ; i < folderIds.Count() ; i++ )
       
   461             {
       
   462             iContext.VerifyTypeL( folderIds[i], EMsgStoreFolderBits );
       
   463             }
       
   464         }
       
   465     
       
   466     if( iContext.iSearchHandler )
       
   467         {
       
   468         __LOG_STATIC_ENTER( "MsgClient", "SearchL" )
       
   469         __LOG_WRITE_ERROR( "search already in progress" )
       
   470         __LOG_STATIC_EXIT
       
   471         User::Leave( KErrInUse );
       
   472         } // end if   
       
   473     
       
   474     //cleanup search handlers from previous search sessions
       
   475     iOldSearchHandlers.ResetAndDestroy();
       
   476     
       
   477     iContext.iSearchHandler = CMsgStoreSearchHandler::NewL( iContext.iSession, aSearchCriteria, *this );
       
   478     iContext.iSearchClient  = &aSearchClient;
       
   479     
       
   480     if ( isEmptyFolderIdArray )
       
   481         {
       
   482         //retrore the folder id to empty array as it was received by this method
       
   483         folderIds.Reset();
       
   484         }
       
   485     }
       
   486                            
       
   487 // ==========================================================================
       
   488 // FUNCTION: CancelSearchL
       
   489 // ==========================================================================
       
   490 EXPORT_C void CMsgStoreMailBox::CancelSearch()
       
   491     {
       
   492     
       
   493     if ( iContext.iSearchHandler )
       
   494         {
       
   495         iContext.iSearchHandler->CancelSearch();
       
   496         }
       
   497     
       
   498     delete iContext.iSearchHandler;
       
   499     iContext.iSearchHandler = NULL;
       
   500     iContext.iSearchClient  = NULL;
       
   501     }
       
   502 
       
   503 // ==========================================================================
       
   504 // FUNCTION: ClearSearchResultCache
       
   505 // ==========================================================================
       
   506 EXPORT_C void CMsgStoreMailBox::ClearSearchResultCache()
       
   507     {
       
   508     CancelSearch();
       
   509     iOldSearchHandlers.ResetAndDestroy();
       
   510     iContext.iSession.ClearSearchResultCache();
       
   511     }
       
   512 
       
   513 // ==========================================================================
       
   514 // FUNCTION: AddMruAddresses
       
   515 // ==========================================================================
       
   516 EXPORT_C void CMsgStoreMailBox::AddMruAddressesL( RPointerArray<CMsgStoreAddress>& aAddressArray )
       
   517     {
       
   518     iContext.iSession.AddMruAddressesL( iId, aAddressArray  );
       
   519     }
       
   520 
       
   521 // ==========================================================================
       
   522 // FUNCTION: MruAddresses
       
   523 // ==========================================================================
       
   524 EXPORT_C void CMsgStoreMailBox::MruAddressesL( RPointerArray<CMsgStoreAddress>& aAddressArray )
       
   525     {
       
   526     iContext.iSession.MruAddressesL( iId, aAddressArray  );
       
   527     }
       
   528 
       
   529 // ==========================================================================
       
   530 // FUNCTION: MruAddresses
       
   531 // ==========================================================================
       
   532 EXPORT_C TMsgStoreContainerType CMsgStoreMailBox::ContainerTypeById( TMsgStoreId aId )
       
   533     {
       
   534     return iContext.iSession.ContainerTypeById( aId );
       
   535     }
       
   536 
       
   537 // ==========================================================================
       
   538 // FUNCTION: IsCorporateMailbox
       
   539 // Please see http://wiki.pumatech.com/display/EXPRESS/Multi+Mailbox+Support for
       
   540 // how to determine if a mialbox is corporate
       
   541 // ==========================================================================
       
   542 EXPORT_C TBool CMsgStoreMailBox::IsCorporateMailbox()
       
   543     {
       
   544     TBool isCorporate = EFalse;
       
   545     TUint index = 0;
       
   546     if ( FindProperty( KIsPropertyEmailSourceId, index ) )
       
   547         {
       
   548         TUint32 sourceId = 0;
       
   549         TRAP_IGNORE( sourceId = PropertyValueUint32L( index ) );
       
   550         const TInt KShift = 16;
       
   551         const TInt KSourceIDNonCorporate = 8;
       
   552         const TInt KSourceIDCorporate = 12;
       
   553         
       
   554         sourceId = sourceId >> KShift;
       
   555         switch ( sourceId & 0x07ff )
       
   556             {
       
   557             case KSourceIDCorporate:
       
   558                 isCorporate = ETrue;
       
   559                 break;
       
   560                 
       
   561             case KSourceIDNonCorporate:
       
   562                 {
       
   563                 index = 0;
       
   564                 if ( FindProperty( KIsPropertyCapabilities, index ) )
       
   565                     {
       
   566                     TUint featureVal = 0;
       
   567                     TRAP_IGNORE( featureVal = PropertyValueUint32L( index ) );
       
   568                     if ( featureVal & 0x80000000 )
       
   569                         {
       
   570                         isCorporate = ETrue;
       
   571                         }
       
   572                     }
       
   573                 }
       
   574                 break;
       
   575             }
       
   576         }
       
   577     else
       
   578         {
       
   579         //no source id, let's check the "type"
       
   580         index = 0;
       
   581         if ( FindProperty( KIsPropertyServerType, index ) )
       
   582             {
       
   583             TUint serverType = 0;
       
   584             TRAP_IGNORE( serverType = PropertyValueUint32L( index ) );
       
   585             if ( serverType == ESrvExchange ||
       
   586                  serverType == ESrvDomino ||
       
   587                  serverType == ESrvGroupWise )
       
   588                 {
       
   589                 isCorporate = ETrue;
       
   590                 }
       
   591             }
       
   592         }
       
   593             
       
   594     return isCorporate;
       
   595     }
       
   596 
       
   597 /**
       
   598  * 
       
   599  */
       
   600 /*public*/
       
   601 EXPORT_C void CMsgStoreMailBox::BeginBatchInsertL()
       
   602     {
       
   603     iContext.iSession.BeginBatchInsertL();
       
   604     }
       
   605 
       
   606 /**
       
   607  * 
       
   608  */
       
   609 /*public*/
       
   610 EXPORT_C void CMsgStoreMailBox::FinishBatchInsertL()
       
   611     {
       
   612     iContext.iSession.FinishBatchInsertL();
       
   613     }
       
   614 
       
   615 
       
   616 // ==========================================================================
       
   617 // FUNCTION: IsDefaultMailbox
       
   618 // ==========================================================================
       
   619 TBool CMsgStoreMailBox::IsDefaultMailbox()
       
   620     {
       
   621     TBool isDefault = EFalse;
       
   622     TUint index = 0;
       
   623     if ( FindProperty( KMsgStorePropertyIsDefault, index ) )
       
   624         {
       
   625         TRAP_IGNORE( isDefault = PropertyValueBoolL( index ) );
       
   626         }
       
   627             
       
   628     return isDefault;
       
   629     }
       
   630 
       
   631 // ==========================================================================
       
   632 // FUNCTION: SetDefaultMailboxL
       
   633 // ==========================================================================
       
   634 void CMsgStoreMailBox::SetDefaultMailboxL( TBool aIsDefault )
       
   635     {
       
   636     AddOrUpdatePropertyL( KMsgStorePropertyIsDefault, aIsDefault );
       
   637     StorePropertiesL();
       
   638     }
       
   639 
       
   640 // ==========================================================================
       
   641 // FUNCTION: MatchFound
       
   642 // ==========================================================================
       
   643 void CMsgStoreMailBox::MatchFound( CMsgStorePropertyContainer*& aMessageSummary )
       
   644     {
       
   645     iContext.iSearchClient->MatchFound( aMessageSummary );
       
   646     } // end MatchFound
       
   647     
       
   648 // ==========================================================================
       
   649 // FUNCTION: SearchCompleted
       
   650 // ==========================================================================
       
   651 void CMsgStoreMailBox::SearchCompleted()
       
   652     {
       
   653     //since we are in the the call back from the iContext.iSearchHandler
       
   654     //try not to delete it within its own call
       
   655     iOldSearchHandlers.Append( iContext.iSearchHandler );
       
   656     iContext.iSearchHandler = NULL;
       
   657     
       
   658     iContext.iSearchClient->SearchCompleted();
       
   659     iContext.iSearchClient = NULL;
       
   660     } // end SearchCompleted
       
   661 
       
   662 
       
   663 // ==========================================================================
       
   664 // FUNCTION: Destructor
       
   665 // ==========================================================================
       
   666 CMsgStoreMailBox::~CMsgStoreMailBox()
       
   667     {
       
   668     if ( iContext.iSearchHandler )
       
   669         {
       
   670         iContext.iSearchHandler->CancelSearch();
       
   671         delete iContext.iSearchHandler;
       
   672         }
       
   673     iOldSearchHandlers.ResetAndDestroy();
       
   674     }
       
   675 		
       
   676 // ==========================================================================
       
   677 // FUNCTION: NewL
       
   678 // ==========================================================================
       
   679 CMsgStoreMailBox* CMsgStoreMailBox::NewL( CMsgStoreSessionContext& iContext, TMsgStoreId iId, const TDesC8& aProperties )
       
   680     {
       
   681 	CMsgStoreMailBox* self = new( ELeave ) CMsgStoreMailBox( iContext, iId );
       
   682 	CleanupStack::PushL( self );
       
   683 	self->ConstructL( aProperties );
       
   684 	CleanupStack::Pop( self );
       
   685 	return self;
       
   686     }
       
   687 										 
       
   688 // ==========================================================================
       
   689 // FUNCTION: Constructor
       
   690 // ==========================================================================
       
   691 CMsgStoreMailBox::CMsgStoreMailBox( CMsgStoreSessionContext& aContext, TMsgStoreId aId )
       
   692 : CMsgStoreWritablePropertyContainer( aContext, aId, KMsgStoreRootMailBoxId, aId )
       
   693     {
       
   694     }
       
   695 		
       
   696 // ==========================================================================
       
   697 // FUNCTION: ConstructL
       
   698 // ==========================================================================
       
   699 void CMsgStoreMailBox::ConstructL( const TDesC8& aProperties )
       
   700     {
       
   701 	DeserializeL( aProperties );
       
   702     }