emailservices/emailframework/commonlib/src/CFSMailBox.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  common mailbox object
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include <bamdesca.h>
       
    20 
       
    21 
       
    22 #include "CFSMailPlugin.h"
       
    23 #include "cmrcalendarinfoimpl.h"
       
    24 
       
    25 #include "CFSMailBox.h"
       
    26 #include "CFSMailRequestObserver.h"
       
    27 
       
    28 const TInt KMaxMruEntries( 150 );
       
    29 
       
    30 // ================= MEMBER FUNCTIONS ==========================================
       
    31 // -----------------------------------------------------------------------------
       
    32 // CFSMailBox::NewLC
       
    33 // -----------------------------------------------------------------------------
       
    34 EXPORT_C CFSMailBox* CFSMailBox::NewLC(TFSMailMsgId aMailBoxId)
       
    35 {
       
    36     FUNC_LOG;
       
    37   CFSMailBox* api = new (ELeave) CFSMailBox();
       
    38   CleanupStack:: PushL(api);
       
    39   api->ConstructL(aMailBoxId);
       
    40   return api;
       
    41 } 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CFSMailBox::NewL
       
    45 // -----------------------------------------------------------------------------
       
    46 EXPORT_C CFSMailBox* CFSMailBox::NewL(TFSMailMsgId aMailBoxId)
       
    47 {
       
    48     FUNC_LOG;
       
    49   CFSMailBox* api =  CFSMailBox::NewLC(aMailBoxId);
       
    50   CleanupStack:: Pop(api);
       
    51   return api;
       
    52 }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CFSMailBox::CFSMailBox
       
    56 // -----------------------------------------------------------------------------
       
    57 CFSMailBox::CFSMailBox()
       
    58 {
       
    59     FUNC_LOG;
       
    60 	// get requesthandler pointer
       
    61 	iRequestHandler = static_cast<CFSMailRequestHandler*>(Dll::Tls());
       
    62 }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CFSMailBox::~CFSMailBox
       
    66 // -----------------------------------------------------------------------------
       
    67 EXPORT_C CFSMailBox::~CFSMailBox()
       
    68 {
       
    69     FUNC_LOG;
       
    70 	iFolders.ResetAndDestroy();
       
    71 }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CFSMailBox::ConstructL
       
    75 // -----------------------------------------------------------------------------
       
    76 void CFSMailBox::ConstructL(TFSMailMsgId aMailBoxId)
       
    77 {
       
    78     FUNC_LOG;
       
    79     // <cmail>
       
    80     const TFSMailMsgId myId = aMailBoxId;
       
    81     CFSMailBoxBase::ConstructL(myId);   
       
    82     iMailBoxId = aMailBoxId; 
       
    83     // </cmail>    
       
    84 }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CFSMailBox::GoOnlineL
       
    88 // -----------------------------------------------------------------------------
       
    89 EXPORT_C void CFSMailBox::GoOnlineL()
       
    90     {
       
    91     FUNC_LOG;
       
    92 	
       
    93 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
    94 		{
       
    95 	    plugin->GoOnlineL( GetId() );
       
    96 		}
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CFSMailBox::GoOfflineL
       
   101 // -----------------------------------------------------------------------------
       
   102 EXPORT_C void CFSMailBox::GoOfflineL()
       
   103     {
       
   104     FUNC_LOG;
       
   105     
       
   106 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   107 		{
       
   108 	    plugin->GoOfflineL( GetId() );
       
   109 		}
       
   110 		
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CFSMailBox::CancelSyncL
       
   115 // -----------------------------------------------------------------------------
       
   116 EXPORT_C void CFSMailBox::CancelSyncL()
       
   117     {
       
   118     FUNC_LOG;
       
   119 	
       
   120 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   121 		{
       
   122 	    plugin->CancelSyncL( GetId() );
       
   123 		}
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CFSMailBox::GetLastSyncStatusL
       
   128 // -----------------------------------------------------------------------------
       
   129 EXPORT_C TFSProgress CFSMailBox::GetLastSyncStatusL()
       
   130     {
       
   131     FUNC_LOG;
       
   132     TFSProgress progress;
       
   133 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   134 		{
       
   135 	    progress = plugin->GetLastSyncStatusL( GetId() );		
       
   136 		}
       
   137 	return progress;
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CFSMailBox::RefreshNowL
       
   142 // -----------------------------------------------------------------------------
       
   143 EXPORT_C TInt CFSMailBox::RefreshNowL(
       
   144     MFSMailRequestObserver& aOperationObserver )
       
   145     {
       
   146     FUNC_LOG;
       
   147 
       
   148 	TFSPendingRequest request;
       
   149 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   150 		{
       
   151 		// init asynchronous request
       
   152     	request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(),
       
   153     													aOperationObserver );
       
   154     	MFSMailRequestObserver* observer = request.iObserver;
       
   155     	TRAPD(err,plugin->RefreshNowL( GetId(), *observer, request.iRequestId));
       
   156     	if(err != KErrNone)
       
   157 			{
       
   158 			iRequestHandler->CompleteRequest(request.iRequestId);
       
   159 			User::Leave(err);
       
   160 			}
       
   161 		}
       
   162  	return request.iRequestId;
       
   163 
       
   164    }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CFSMailBox::RefreshNowL
       
   168 // -----------------------------------------------------------------------------
       
   169 EXPORT_C TInt CFSMailBox::RefreshNowL( )
       
   170     {
       
   171     FUNC_LOG;
       
   172 
       
   173 	TFSPendingRequest request;
       
   174     MFSMailRequestObserver* observer = NULL;
       
   175    	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   176 		{
       
   177 		// init asynchronous request
       
   178         request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(), *observer );
       
   179     	
       
   180     	observer = request.iObserver;
       
   181     	TRAPD(err,plugin->RefreshNowL( GetId(), *observer, request.iRequestId));
       
   182     	if(err != KErrNone)
       
   183 			{
       
   184 			iRequestHandler->CompleteRequest(request.iRequestId);
       
   185 			User::Leave(err);
       
   186 			}
       
   187 		}
       
   188  	return request.iRequestId;
       
   189 
       
   190    }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CFSMailBox::CreateMessageToSend
       
   194 // -----------------------------------------------------------------------------
       
   195 EXPORT_C CFSMailMessage* CFSMailBox::CreateMessageToSend( )
       
   196 {
       
   197     FUNC_LOG;
       
   198 
       
   199 	CFSMailMessage* message = NULL;
       
   200 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   201 		{
       
   202 		TRAPD(err,message = plugin->CreateMessageToSendL( GetId() ));
       
   203 		if(err != KErrNone)
       
   204 			{
       
   205 			message = NULL;
       
   206 			}
       
   207 		}
       
   208 	return message;
       
   209 }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CFSMailBox::CreateForwardMessage
       
   213 // -----------------------------------------------------------------------------
       
   214 EXPORT_C CFSMailMessage* CFSMailBox::CreateForwardMessage( 	TFSMailMsgId aOriginalMessageId,
       
   215 															const TDesC& aHeaderDescriptor )
       
   216 {
       
   217     FUNC_LOG;
       
   218 	CFSMailMessage* message = NULL;
       
   219 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   220 		{
       
   221 		TRAPD(err,message = plugin->CreateForwardMessageL( GetId(), 
       
   222 																aOriginalMessageId,
       
   223 																aHeaderDescriptor ));
       
   224 		if(err != KErrNone)
       
   225 			{
       
   226 			message = NULL;
       
   227 			}
       
   228 		}
       
   229 	return message;
       
   230 }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CFSMailBox::CreateReplyMessage
       
   234 // -----------------------------------------------------------------------------
       
   235 EXPORT_C CFSMailMessage* CFSMailBox::CreateReplyMessage( TFSMailMsgId aOriginalMessageId,
       
   236 														 TBool aReplyToAll,
       
   237 														 const TDesC& aHeaderDescriptor )
       
   238 {
       
   239     FUNC_LOG;
       
   240 	CFSMailMessage* message = NULL;
       
   241 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   242 		{
       
   243 		TRAPD(err,message = plugin->CreateReplyMessageL( GetId(),
       
   244 															aOriginalMessageId,
       
   245 															aReplyToAll,
       
   246 															aHeaderDescriptor ));
       
   247 		if(err != KErrNone)
       
   248 			{
       
   249 			message = NULL;
       
   250 			}
       
   251 		}
       
   252 	return message;
       
   253 }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CFSMailBox::GetStandardFolderId
       
   257 // -----------------------------------------------------------------------------
       
   258 EXPORT_C TFSMailMsgId CFSMailBox::GetStandardFolderId(TFSFolderType aFolderType)
       
   259 {
       
   260     FUNC_LOG;
       
   261 
       
   262 	TFSMailMsgId folderId;
       
   263 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   264 		{
       
   265 		TRAPD(err, folderId = plugin->GetStandardFolderIdL(GetId(), aFolderType ));
       
   266 		if(err != KErrNone)
       
   267 			{
       
   268 			folderId.SetNullId();
       
   269 			}
       
   270 		}
       
   271 	return folderId;
       
   272 }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CFSMailBox::SendMessageL
       
   276 // -----------------------------------------------------------------------------
       
   277 EXPORT_C void CFSMailBox::SendMessageL( CFSMailMessage& aMessage )
       
   278     {
       
   279     FUNC_LOG;
       
   280 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   281 		{
       
   282 		UpdateMrusL( aMessage.GetToRecipients(),
       
   283 		           	 aMessage.GetCCRecipients(),
       
   284 		        	 aMessage.GetBCCRecipients() );
       
   285 		plugin->SendMessageL( aMessage );
       
   286 		
       
   287 		}
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // CFSMailBox::ListFolders
       
   292 // -----------------------------------------------------------------------------
       
   293 EXPORT_C void CFSMailBox::ListFolders( 	TFSMailMsgId aFolder,
       
   294 										RPointerArray<CFSMailFolder>& aFolderList)
       
   295 {
       
   296     FUNC_LOG;
       
   297 
       
   298 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   299 	{
       
   300 		TRAPD(err, plugin->ListFoldersL(GetId(),aFolder,aFolderList));
       
   301 		if(err != KErrNone)
       
   302 			{
       
   303 			aFolderList.ResetAndDestroy();
       
   304 			}
       
   305 	}
       
   306 }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CFSMailBox::ListFolders
       
   310 // -----------------------------------------------------------------------------
       
   311 EXPORT_C RPointerArray<CFSMailFolder>& CFSMailBox::ListFolders( )
       
   312 {	
       
   313 	iFolders.ResetAndDestroy();
       
   314 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   315 	{
       
   316 		TRAPD(err,plugin->ListFoldersL(GetId(),iFolders));
       
   317 		if(err != KErrNone)
       
   318 			{
       
   319 			iFolders.ResetAndDestroy();
       
   320 			}
       
   321 	}
       
   322 
       
   323 	return iFolders;
       
   324 }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CFSMailBox::GetBrandingIdL
       
   328 // -----------------------------------------------------------------------------
       
   329 EXPORT_C TDesC& CFSMailBox::GetBrandingIdL( )
       
   330 {
       
   331     FUNC_LOG;
       
   332 	return BrandingId();
       
   333 }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CFSMailBox::MoveMessagesL
       
   337 // -----------------------------------------------------------------------------
       
   338 EXPORT_C void CFSMailBox::MoveMessagesL( const RArray<TFSMailMsgId>& aMessageIds, 
       
   339                             			 const TFSMailMsgId aSourceFolderId, 
       
   340                             			 const TFSMailMsgId aDestinationFolderId )
       
   341 {
       
   342     FUNC_LOG;
       
   343 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   344 		{
       
   345 		plugin->MoveMessagesL(GetId(), aMessageIds, aSourceFolderId, aDestinationFolderId);
       
   346 		}
       
   347 }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CFSMailBox::MoveMessagesL
       
   351 // -----------------------------------------------------------------------------
       
   352 EXPORT_C TInt CFSMailBox::MoveMessagesL( MFSMailRequestObserver& aOperationObserver,
       
   353                                          const RArray<TFSMailMsgId>& aMessageIds, 
       
   354                             			 const TFSMailMsgId aSourceFolderId, 
       
   355                             			 const TFSMailMsgId aDestinationFolderId )
       
   356 {
       
   357     FUNC_LOG;
       
   358     TFSPendingRequest request;
       
   359 	if( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   360 		{
       
   361 		// init asynchronous request
       
   362     	request = iRequestHandler->InitAsyncRequestL( GetId().PluginId(),
       
   363     													aOperationObserver );        
       
   364         
       
   365 		plugin->MoveMessagesL(
       
   366 		    GetId(), 
       
   367 		    aMessageIds, 
       
   368 		    aSourceFolderId, 
       
   369 		    aDestinationFolderId, 
       
   370 		    aOperationObserver, 
       
   371 		    request.iRequestId );
       
   372 		}
       
   373     return request.iRequestId;
       
   374 }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CFSMailBox::CopyMessagesL
       
   378 // -----------------------------------------------------------------------------
       
   379 EXPORT_C void CFSMailBox::CopyMessagesL( const RArray<TFSMailMsgId>& aMessageIds, 
       
   380  										 RArray<TFSMailMsgId>& aNewMessages, 
       
   381                                      	 const TFSMailMsgId aSourceFolderId, 
       
   382                                     	 const TFSMailMsgId aDestinationFolderId )
       
   383 {
       
   384     FUNC_LOG;
       
   385 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   386 		{
       
   387 		plugin->CopyMessagesL(GetId(), aMessageIds, aNewMessages,
       
   388 								aSourceFolderId, aDestinationFolderId );	
       
   389 		}
       
   390 }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // CFSMailBox::SearchL
       
   394 // -----------------------------------------------------------------------------
       
   395 EXPORT_C void CFSMailBox::SearchL( const RPointerArray<TDesC>& /*aSearchStrings*/,
       
   396 								   const TFSMailSortCriteria&  /*aSortCriteria*/,
       
   397 					 			   MFSMailBoxSearchObserver&   /*aSearchObserver*/,
       
   398                                    const RArray<TFSMailMsgId>  /*aFolderIds */ )
       
   399 	{
       
   400     FUNC_LOG;
       
   401 
       
   402 	}
       
   403 	
       
   404 // -----------------------------------------------------------------------------
       
   405 // CFSMailBox::SearchL
       
   406 // -----------------------------------------------------------------------------
       
   407 EXPORT_C void CFSMailBox::SearchL( const RPointerArray<TDesC>& aSearchStrings,
       
   408 								   const TFSMailSortCriteria& aSortCriteria,
       
   409 					 			   MFSMailBoxSearchObserver& aSearchObserver )
       
   410 	{
       
   411     FUNC_LOG;
       
   412 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   413 		{
       
   414 
       
   415 		// get mailbox folder list
       
   416 		iFolders.ResetAndDestroy();
       
   417 		plugin->ListFoldersL(GetId(),iFolders);
       
   418 
       
   419 		TFSMailMsgId draftsFolderId = GetStandardFolderId( EFSDraftsFolder );
       
   420 		TFSMailMsgId outboxId = GetStandardFolderId( EFSOutbox );
       
   421 		
       
   422 		// remove outbox, drafts folder from folder list
       
   423 		RArray<TFSMailMsgId> folderIds;
       
   424 		folderIds.Reset();
       
   425 		for(TInt i=0;i<iFolders.Count();i++)
       
   426 		{
       
   427 			TFSMailMsgId id = iFolders[i]->GetFolderId();
       
   428 			if(	id != draftsFolderId && id != outboxId )
       
   429 			{
       
   430 				folderIds.Append(id);
       
   431 			}
       
   432 		}
       
   433 		
       
   434 		// start search
       
   435 		plugin->SearchL( GetId(), folderIds, aSearchStrings, aSortCriteria, aSearchObserver );
       
   436 		folderIds.Reset();
       
   437 		}
       
   438 	}
       
   439 
       
   440 // -----------------------------------------------------------------------------
       
   441 // CFSMailBox::CancelSearch
       
   442 // -----------------------------------------------------------------------------
       
   443 EXPORT_C void CFSMailBox::CancelSearch()
       
   444 	{
       
   445     FUNC_LOG;
       
   446 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   447 		{
       
   448 		plugin->CancelSearch( GetId() );
       
   449 		}
       
   450 	}
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CFSMailBox::ClearSearchResultCache
       
   454 // -----------------------------------------------------------------------------
       
   455 EXPORT_C void CFSMailBox::ClearSearchResultCache()
       
   456 	{
       
   457     FUNC_LOG;
       
   458 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   459 		{
       
   460 		plugin->ClearSearchResultCache( GetId() );
       
   461 		}
       
   462 	}
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CFSMailBox::ListMrusL
       
   466 // -----------------------------------------------------------------------------
       
   467 EXPORT_C MDesCArray* CFSMailBox::ListMrusL() const
       
   468 	{
       
   469     FUNC_LOG;
       
   470 	MDesCArray* mruList(0);
       
   471 	if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) )
       
   472 		{
       
   473    		mruList = plugin->GetMrusL( GetId() );
       
   474 		}
       
   475 	return mruList;
       
   476 	}
       
   477 
       
   478 
       
   479 // -----------------------------------------------------------------------------
       
   480 // CFSMailBox::CurrentSyncState
       
   481 // -----------------------------------------------------------------------------
       
   482 EXPORT_C TSSMailSyncState CFSMailBox::CurrentSyncState() const
       
   483 	{
       
   484     FUNC_LOG;
       
   485 	TSSMailSyncState syncState(Idle);
       
   486 	if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   487 		{
       
   488 		syncState = plugin->CurrentSyncState( GetId() );
       
   489 		}
       
   490 	return syncState;
       
   491 	}
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CFSMailBox::HasCapability
       
   495 // -----------------------------------------------------------------------------
       
   496 EXPORT_C TBool CFSMailBox::HasCapability( const TFSMailBoxCapabilities aCapability ) const
       
   497 {
       
   498     FUNC_LOG;
       
   499 	TBool capability = EFalse;
       
   500 	if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   501 		{
       
   502 		TRAPD( err,capability = plugin->MailboxHasCapabilityL( aCapability,GetId() )) ;
       
   503 		if ( err != KErrNone )
       
   504 			{
       
   505 			capability = EFalse;
       
   506 			}
       
   507 		}
       
   508 	return capability;
       
   509 }
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // CFSMailBox::GetMailBoxStatus
       
   513 // -----------------------------------------------------------------------------
       
   514 EXPORT_C TFSMailBoxStatus CFSMailBox::GetMailBoxStatus()
       
   515 {
       
   516     FUNC_LOG;
       
   517 	TFSMailBoxStatus status(EFSMailBoxOffline);
       
   518 	if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) )
       
   519 	{
       
   520 		status = plugin->GetMailBoxStatus( GetId() );
       
   521 	}
       
   522 	return status;
       
   523 }
       
   524 
       
   525 // -----------------------------------------------------------------------------
       
   526 // CFSMailBox::SetCredentialsL
       
   527 // -----------------------------------------------------------------------------
       
   528 EXPORT_C void CFSMailBox::SetCredentialsL( const TDesC& aUsername, const TDesC& aPassword )
       
   529     {
       
   530     FUNC_LOG;
       
   531 	if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) )
       
   532 		{
       
   533 	    plugin->SetCredentialsL( GetId(), aUsername, aPassword );
       
   534 		}
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CFSMailBox::RemoveDownLoadedAttachmentsL
       
   539 // -----------------------------------------------------------------------------
       
   540 EXPORT_C void CFSMailBox::RemoveDownLoadedAttachmentsL()
       
   541     {
       
   542     FUNC_LOG;
       
   543     
       
   544     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() );
       
   545     if ( plugin )
       
   546         {
       
   547         // get inbox folder from plugin
       
   548         TFSMailMsgId folderId = GetStandardFolderId( EFSInbox );
       
   549         CFSMailFolder* folder = plugin->GetFolderByUidL( GetId(), folderId );
       
   550         if ( folder )
       
   551             {
       
   552             folder->RemoveDownLoadedAttachmentsL();
       
   553             delete folder;
       
   554             }
       
   555         }
       
   556     }
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // CFSMailBox::GetConnectionId
       
   560 // -----------------------------------------------------------------------------
       
   561 EXPORT_C TInt CFSMailBox::GetConnectionId( TUint32& aConnectionId )
       
   562     {
       
   563     FUNC_LOG;
       
   564     TInt rcode = KErrNotSupported;
       
   565     if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   566         {
       
   567         rcode = plugin->GetConnectionId( GetId(), aConnectionId );
       
   568         }
       
   569     return rcode;
       
   570     }
       
   571 
       
   572 // -----------------------------------------------------------------------------
       
   573 // CFSMailBox::IsConnectionAllowedWhenRoaming
       
   574 // -----------------------------------------------------------------------------
       
   575 EXPORT_C TInt CFSMailBox::IsConnectionAllowedWhenRoaming( TBool& aConnectionAllowed )
       
   576     {
       
   577     FUNC_LOG;
       
   578     TInt rcode = KErrNotSupported;
       
   579     if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   580         {
       
   581         rcode = plugin->IsConnectionAllowedWhenRoaming( GetId(), aConnectionAllowed );
       
   582         }
       
   583     return rcode;
       
   584     }
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // CFSMailBox::CreateMessageFromFileL
       
   588 // -----------------------------------------------------------------------------
       
   589 EXPORT_C CFSMailMessage* CFSMailBox::CreateMessageFromFileL( const RFile& aFile )
       
   590 {
       
   591     FUNC_LOG;
       
   592     CFSMailMessage* message = NULL;
       
   593     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   594     {
       
   595         message = plugin->CreateMessageFromFileL( GetId(), aFile );
       
   596     }
       
   597     return message;
       
   598 }
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // CFSMailBox::UpdateMrusL
       
   602 // -----------------------------------------------------------------------------
       
   603 void CFSMailBox::UpdateMrusL(
       
   604     const RPointerArray<CFSMailAddress>& aRecipients,
       
   605     const RPointerArray<CFSMailAddress>& aCCRecipients,
       
   606     const RPointerArray<CFSMailAddress>& aBCCRecipients ) const
       
   607     {
       
   608     FUNC_LOG;
       
   609     
       
   610     // First lets make a copy of the current mru list
       
   611     // whose content we can later alter as we wish
       
   612     MDesCArray* currentMruList( NULL );
       
   613 
       
   614 	CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId());
       
   615     if ( !plugin )
       
   616         {
       
   617         User::Leave( KErrGeneral );
       
   618         }
       
   619     currentMruList = plugin->GetMrusL( GetId() );
       
   620     if ( !currentMruList )
       
   621         {
       
   622         // This should not happen because previous function
       
   623         // should leave in error cases and if there are no
       
   624         // entries then the pointer should still be pointing
       
   625         // to valid array.
       
   626         User::Leave( KErrGeneral );
       
   627         }
       
   628     
       
   629     CDesCArraySeg* newMruList( NULL );
       
   630     TRAPD( error, newMruList = CopyArrayL( *currentMruList ) );
       
   631         
       
   632     delete currentMruList;
       
   633        
       
   634     if ( error != KErrNone )
       
   635         {
       
   636         User::Leave( error );
       
   637         }
       
   638         
       
   639     CleanupStack::PushL( newMruList );
       
   640         
       
   641     // Now check that all given recipients are found from the
       
   642     // mru list.
       
   643 
       
   644     // Notice that the order here has a meaning. For example
       
   645     // if the latest used address is appended to the end, then
       
   646     // the aRecipients' addresses are found from the end because
       
   647     // they are updated after cc and bcc recipients.
       
   648     UpdateMruListL( *newMruList, aBCCRecipients );
       
   649     UpdateMruListL( *newMruList, aCCRecipients );
       
   650     UpdateMruListL( *newMruList, aRecipients );
       
   651     
       
   652     // Finally update the new mru list to the plugin
       
   653     plugin->SetMrusL( GetId(), newMruList );
       
   654     
       
   655     CleanupStack::PopAndDestroy( newMruList );
       
   656     }
       
   657 
       
   658 // -----------------------------------------------------------------------------
       
   659 // CFSMailBox::CopyArrayL
       
   660 // -----------------------------------------------------------------------------    
       
   661 CDesCArraySeg* CFSMailBox::CopyArrayL( MDesCArray& aArrayToBeCopied ) const
       
   662     {
       
   663     FUNC_LOG;
       
   664     CDesCArraySeg* newArray = new (ELeave) CDesCArraySeg( 10 );
       
   665     CleanupStack::PushL( newArray );
       
   666     
       
   667     TInt itemCount( aArrayToBeCopied.MdcaCount() );
       
   668     TInt index( 0 );
       
   669     while ( index < itemCount )
       
   670         {        
       
   671         newArray->AppendL( aArrayToBeCopied.MdcaPoint( index ) );
       
   672         ++index;
       
   673         }
       
   674     
       
   675     CleanupStack::Pop( newArray );
       
   676     return newArray;
       
   677     }
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 // CFSMailBox::UpdateMruListL
       
   681 // -----------------------------------------------------------------------------
       
   682 void CFSMailBox::UpdateMruListL(
       
   683     CDesCArraySeg& aMruList,
       
   684     const RPointerArray<CFSMailAddress>& aNewRecentlyUsedOnes ) const
       
   685     {
       
   686     FUNC_LOG;
       
   687     TUint newCount( aNewRecentlyUsedOnes.Count() );
       
   688     TUint newIndexer( 0 );
       
   689     
       
   690     while ( newIndexer < newCount )
       
   691         {
       
   692         if ( aNewRecentlyUsedOnes[newIndexer] )
       
   693             {
       
   694             // The address is used as a search string because every
       
   695             // address does not have a display name
       
   696             TDesC& searchedAddress(
       
   697                 aNewRecentlyUsedOnes[newIndexer]->GetEmailAddress() );
       
   698             TInt position( -1 );
       
   699             
       
   700             TInt found(
       
   701                 FindAddressFromMruList( aMruList, searchedAddress, position ) );
       
   702             
       
   703             if ( found != 0 )
       
   704                 {
       
   705                 AddAndRemoveExcessMruL( aMruList,
       
   706                                         *aNewRecentlyUsedOnes[newIndexer] );
       
   707                 }
       
   708             else
       
   709                 {
       
   710                 SetAsMostRecentMruL( aMruList,
       
   711                                      position,
       
   712                                      *aNewRecentlyUsedOnes[newIndexer] );
       
   713                 }
       
   714             }        
       
   715         
       
   716         ++newIndexer;
       
   717         }
       
   718     }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CFSMailBox::FindAddressFromMruList
       
   722 // -----------------------------------------------------------------------------
       
   723 TInt CFSMailBox::FindAddressFromMruList( CDesCArraySeg& aMruList,
       
   724                                          TDesC& searchedAddress,
       
   725                                          TInt& aPos ) const
       
   726     {
       
   727     FUNC_LOG;
       
   728     // CDesCArray::Find() is not used here because there is
       
   729     // possibility that we have to go through the whole array
       
   730     // and return the index for one specific match. Find() returns
       
   731     // only the index of the first match and searching for the rest
       
   732     // using Find() would cause undesired complexity.
       
   733     
       
   734     
       
   735     const TInt KMruListCount( aMruList.Count() );
       
   736     // Start indexing from 1 because the first
       
   737     // address is on that index if it exists.
       
   738     TInt mruListIndexer( 1 );
       
   739     while( mruListIndexer < KMruListCount )
       
   740         {
       
   741         TPtrC address( aMruList[mruListIndexer] );
       
   742         if ( address == searchedAddress )
       
   743             {
       
   744             aPos = mruListIndexer;
       
   745             return 0;
       
   746             }
       
   747         
       
   748         // We are only interested of the addresses so let's
       
   749         // check only every other descriptor.
       
   750         // (the addresses)
       
   751         mruListIndexer = mruListIndexer + 2;
       
   752         }
       
   753     
       
   754     aPos = aMruList.Count();
       
   755     return 1;
       
   756     }
       
   757 
       
   758 
       
   759 
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 // CFSMailBox::AddAndRemoveExcessMruL
       
   763 // -----------------------------------------------------------------------------
       
   764 void CFSMailBox::AddAndRemoveExcessMruL( CDesCArraySeg& aMruList,
       
   765                                          CFSMailAddress& aToBeAdded ) const
       
   766     {
       
   767     FUNC_LOG;
       
   768     if ( aMruList.Count() == KMaxMruEntries )
       
   769         {
       
   770         // Remove the oldest entry pair from the beginning
       
   771         aMruList.Delete( 0, 2 );
       
   772         }
       
   773     // Latest address is always found from the end.
       
   774     AppendMruItemL( aMruList, aToBeAdded );
       
   775     }
       
   776 
       
   777 // -----------------------------------------------------------------------------
       
   778 // CFSMailBox::SetAsMostRecentMruL
       
   779 // -----------------------------------------------------------------------------
       
   780 void CFSMailBox::SetAsMostRecentMruL( CDesCArraySeg& aMruList,
       
   781                                       TInt aPosition,
       
   782                                       CFSMailAddress& aMostRecent ) const
       
   783     {
       
   784     FUNC_LOG;
       
   785     // Position of the address is given so the possible display name is
       
   786     // in the previous slot. Delete both.
       
   787     aMruList.Delete( aPosition - 1, 2 );
       
   788     // Latest address is always found from the end.
       
   789     AppendMruItemL( aMruList, aMostRecent );
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CFSMailBox::AppendMruItemL
       
   794 // -----------------------------------------------------------------------------
       
   795 void CFSMailBox::AppendMruItemL( CDesCArraySeg& aMruList,
       
   796                                  CFSMailAddress& aToBeAppended ) const
       
   797     {
       
   798     FUNC_LOG;
       
   799     // In the array, display name is always the first and then comes
       
   800     // the actual address.
       
   801     
       
   802     // <cmail> avoid setting email address as display name so it won't 
       
   803     // be displayed twice in the list
       
   804     TDesC* displayName  = &aToBeAppended.GetDisplayName();    
       
   805     TDesC* emailAddress = &aToBeAppended.GetEmailAddress();
       
   806 
       
   807     if( displayName->Length() > 0 && displayName->Compare(*emailAddress) == 0 )
       
   808     {
       
   809         aMruList.AppendL( KNullDesC );
       
   810     }
       
   811     else
       
   812     {
       
   813         aMruList.AppendL( *displayName );                
       
   814     }
       
   815     
       
   816     aMruList.AppendL( *emailAddress );    
       
   817     }
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 // CFSMailBox::ExtensionL
       
   821 // -----------------------------------------------------------------------------
       
   822 EXPORT_C void CFSMailBox::ReleaseExtension( CEmailExtension* aExtension )
       
   823     {
       
   824     FUNC_LOG;
       
   825     // no specialized behaviour, call base class
       
   826     CExtendableEmail::ReleaseExtension( aExtension );
       
   827     }
       
   828     
       
   829 // -----------------------------------------------------------------------------
       
   830 // CFSMailBox::ExtensionL
       
   831 // -----------------------------------------------------------------------------
       
   832 EXPORT_C CEmailExtension* CFSMailBox::ExtensionL( const TUid& aInterfaceUid )
       
   833     {
       
   834     FUNC_LOG;
       
   835     CEmailExtension* extension = NULL;
       
   836     if ( aInterfaceUid == KMailboxExtMrCalInfo )
       
   837         {
       
   838         extension = CExtendableEmail::ExtensionL( aInterfaceUid );
       
   839         if ( extension == NULL )
       
   840             {
       
   841             extension = new ( ELeave ) CMRCalendarInfoImpl();
       
   842             CleanupStack::PushL( extension );
       
   843             iExtensions.AddL( extension );
       
   844             CleanupStack::Pop(); // calInfo
       
   845             }
       
   846         }    
       
   847     else
       
   848         {
       
   849         User::Leave( KErrNotSupported );
       
   850         }
       
   851     return extension;
       
   852     }
       
   853