emailservices/emailcommon/src/CFSMailBox.cpp
changeset 65 478bc57ad291
parent 59 16ed8d08d0b1
child 66 084b5b1f02a7
equal deleted inserted replaced
59:16ed8d08d0b1 65:478bc57ad291
    30 // <qmail>
    30 // <qmail>
    31 #include "CFSMailFolder.h"
    31 #include "CFSMailFolder.h"
    32 #include "CFSMailAddress.h"
    32 #include "CFSMailAddress.h"
    33 // </qmail>
    33 // </qmail>
    34 
    34 
    35 const TInt KMaxMruEntries( 150 );
       
    36 
    35 
    37 // ================= MEMBER FUNCTIONS ==========================================
    36 // ================= MEMBER FUNCTIONS ==========================================
    38 // -----------------------------------------------------------------------------
    37 // -----------------------------------------------------------------------------
    39 // CFSMailBox::NewLC
    38 // CFSMailBox::NewLC
    40 // -----------------------------------------------------------------------------
    39 // -----------------------------------------------------------------------------
   206 // -----------------------------------------------------------------------------
   205 // -----------------------------------------------------------------------------
   207 EXPORT_C CFSMailMessage* CFSMailBox::CreateMessageToSend( )
   206 EXPORT_C CFSMailMessage* CFSMailBox::CreateMessageToSend( )
   208 {
   207 {
   209     NM_FUNCTION;
   208     NM_FUNCTION;
   210     
   209     
   211     CFSMailMessage* message = NULL;
   210     CFSMailMessage* message(NULL);
   212     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
   211     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
   213         {
   212         {
   214         TRAPD(err,message = plugin->CreateMessageToSendL( GetId() ));
   213         TRAPD(err,message = plugin->CreateMessageToSendL( GetId() ));
   215         if(err != KErrNone)
   214         if(err != KErrNone)
   216             {
   215             {
   307 EXPORT_C CFSMailMessage* CFSMailBox::CreateForwardMessage(  TFSMailMsgId aOriginalMessageId,
   306 EXPORT_C CFSMailMessage* CFSMailBox::CreateForwardMessage(  TFSMailMsgId aOriginalMessageId,
   308                                                             const TDesC& aHeaderDescriptor )
   307                                                             const TDesC& aHeaderDescriptor )
   309 {
   308 {
   310     NM_FUNCTION;
   309     NM_FUNCTION;
   311     
   310     
   312     CFSMailMessage* message = NULL;
   311     CFSMailMessage* message(NULL);
   313     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
   312     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
   314         {
   313         {
   315         TRAPD(err,message = plugin->CreateForwardMessageL( GetId(), 
   314         TRAPD(err,message = plugin->CreateForwardMessageL( GetId(), 
   316                                                                 aOriginalMessageId,
   315                                                                 aOriginalMessageId,
   317                                                                 aHeaderDescriptor ));
   316                                                                 aHeaderDescriptor ));
   613         {
   612         {
   614         plugin->CopyMessagesL(GetId(), aMessageIds, aNewMessages,
   613         plugin->CopyMessagesL(GetId(), aMessageIds, aNewMessages,
   615                                 aSourceFolderId, aDestinationFolderId );    
   614                                 aSourceFolderId, aDestinationFolderId );    
   616         }
   615         }
   617 }
   616 }
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CFSMailBox::SearchL
       
   621 // -----------------------------------------------------------------------------
       
   622 EXPORT_C void CFSMailBox::SearchL( const RPointerArray<TDesC>& /*aSearchStrings*/,
       
   623                                    const TFSMailSortCriteria&  /*aSortCriteria*/,
       
   624                                    MFSMailBoxSearchObserver&   /*aSearchObserver*/,
       
   625                                    const RArray<TFSMailMsgId>  /*aFolderIds */ )
       
   626     {
       
   627     NM_FUNCTION;
       
   628     }
       
   629     
   617     
   630 // -----------------------------------------------------------------------------
   618 // -----------------------------------------------------------------------------
   631 // CFSMailBox::SearchL
   619 // CFSMailBox::SearchL
   632 // -----------------------------------------------------------------------------
   620 // -----------------------------------------------------------------------------
   633 EXPORT_C void CFSMailBox::SearchL( const RPointerArray<TDesC>& aSearchStrings,
   621 EXPORT_C void CFSMailBox::SearchL( const RPointerArray<TDesC>& aSearchStrings,
   689         plugin->ClearSearchResultCache( GetId() );
   677         plugin->ClearSearchResultCache( GetId() );
   690         }
   678         }
   691     }
   679     }
   692 
   680 
   693 // -----------------------------------------------------------------------------
   681 // -----------------------------------------------------------------------------
   694 // CFSMailBox::ListMrusL
       
   695 // -----------------------------------------------------------------------------
       
   696 EXPORT_C MDesCArray* CFSMailBox::ListMrusL() const
       
   697     {
       
   698     NM_FUNCTION;
       
   699     
       
   700     MDesCArray* mruList(0);
       
   701     if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) )
       
   702         {
       
   703         mruList = plugin->GetMrusL( GetId() );
       
   704         }
       
   705     return mruList;
       
   706     }
       
   707 
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CFSMailBox::CurrentSyncState
   682 // CFSMailBox::CurrentSyncState
   711 // -----------------------------------------------------------------------------
   683 // -----------------------------------------------------------------------------
   712 EXPORT_C TSSMailSyncState CFSMailBox::CurrentSyncState() const
   684 EXPORT_C TSSMailSyncState CFSMailBox::CurrentSyncState() const
   713     {
   685     {
   714     NM_FUNCTION;
   686     NM_FUNCTION;
   719         syncState = plugin->CurrentSyncState( GetId() );
   691         syncState = plugin->CurrentSyncState( GetId() );
   720         }
   692         }
   721     return syncState;
   693     return syncState;
   722     }
   694     }
   723 
   695 
   724 // -----------------------------------------------------------------------------
       
   725 // CFSMailBox::HasCapability
       
   726 // -----------------------------------------------------------------------------
       
   727 EXPORT_C TBool CFSMailBox::HasCapability( const TFSMailBoxCapabilities aCapability ) const
       
   728 {
       
   729     NM_FUNCTION;
       
   730     
       
   731     TBool capability = EFalse;
       
   732     if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   733         {
       
   734         TRAPD( err,capability = plugin->MailboxHasCapabilityL( aCapability,GetId() )) ;
       
   735         if ( err != KErrNone )
       
   736             {
       
   737             capability = EFalse;
       
   738             }
       
   739         }
       
   740     return capability;
       
   741 }
       
   742 
   696 
   743 // -----------------------------------------------------------------------------
   697 // -----------------------------------------------------------------------------
   744 // CFSMailBox::GetMailBoxStatus
   698 // CFSMailBox::GetMailBoxStatus
   745 // -----------------------------------------------------------------------------
   699 // -----------------------------------------------------------------------------
   746 EXPORT_C TFSMailBoxStatus CFSMailBox::GetMailBoxStatus()
   700 EXPORT_C TFSMailBoxStatus CFSMailBox::GetMailBoxStatus()
   753         status = plugin->GetMailBoxStatus( GetId() );
   707         status = plugin->GetMailBoxStatus( GetId() );
   754     }
   708     }
   755     return status;
   709     return status;
   756 }
   710 }
   757 
   711 
   758 // -----------------------------------------------------------------------------
   712 
   759 // CFSMailBox::SetCredentialsL
       
   760 // -----------------------------------------------------------------------------
       
   761 EXPORT_C void CFSMailBox::SetCredentialsL( const TDesC& aUsername, const TDesC& aPassword )
       
   762     {
       
   763     NM_FUNCTION;
       
   764     
       
   765     if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId() ) )
       
   766         {
       
   767         plugin->SetCredentialsL( GetId(), aUsername, aPassword );
       
   768         }
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // CFSMailBox::RemoveDownLoadedAttachmentsL
       
   773 // -----------------------------------------------------------------------------
       
   774 EXPORT_C void CFSMailBox::RemoveDownLoadedAttachmentsL()
       
   775     {
       
   776     NM_FUNCTION;
       
   777     
       
   778     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() );
       
   779     if ( plugin )
       
   780         {
       
   781         // get inbox folder from plugin
       
   782         TFSMailMsgId folderId = GetStandardFolderId( EFSInbox );
       
   783         CFSMailFolder* folder = plugin->GetFolderByUidL( GetId(), folderId );
       
   784         if ( folder )
       
   785             {
       
   786             folder->RemoveDownLoadedAttachmentsL();
       
   787             delete folder;
       
   788             }
       
   789         }
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CFSMailBox::GetConnectionId
       
   794 // -----------------------------------------------------------------------------
       
   795 EXPORT_C TInt CFSMailBox::GetConnectionId( TUint32& aConnectionId )
       
   796     {
       
   797     NM_FUNCTION;
       
   798     
       
   799     TInt rcode = KErrNotSupported;
       
   800     if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   801         {
       
   802         rcode = plugin->GetConnectionId( GetId(), aConnectionId );
       
   803         }
       
   804     return rcode;
       
   805     }
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // CFSMailBox::IsConnectionAllowedWhenRoaming
       
   809 // -----------------------------------------------------------------------------
       
   810 EXPORT_C TInt CFSMailBox::IsConnectionAllowedWhenRoaming( TBool& aConnectionAllowed )
       
   811     {
       
   812     NM_FUNCTION;
       
   813     
       
   814     TInt rcode = KErrNotSupported;
       
   815     if ( CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetId() ) )
       
   816         {
       
   817         rcode = plugin->IsConnectionAllowedWhenRoaming( GetId(), aConnectionAllowed );
       
   818         }
       
   819     return rcode;
       
   820     }
       
   821 
       
   822 // -----------------------------------------------------------------------------
       
   823 // CFSMailBox::CreateMessageFromFileL
       
   824 // -----------------------------------------------------------------------------
       
   825 EXPORT_C CFSMailMessage* CFSMailBox::CreateMessageFromFileL( const RFile& aFile )
       
   826 {
       
   827     NM_FUNCTION;
       
   828     
       
   829     CFSMailMessage* message = NULL;
       
   830     if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId()))
       
   831     {
       
   832 		message = plugin->CreateMessageFromFileL( GetId(), aFile );
       
   833     }
       
   834     return message;
       
   835 }
       
   836 
       
   837 // -----------------------------------------------------------------------------
       
   838 // CFSMailBox::UpdateMrusL
       
   839 // -----------------------------------------------------------------------------
       
   840 void CFSMailBox::UpdateMrusL(
       
   841     const RPointerArray<CFSMailAddress>& aRecipients,
       
   842     const RPointerArray<CFSMailAddress>& aCCRecipients,
       
   843     const RPointerArray<CFSMailAddress>& aBCCRecipients ) const
       
   844     {
       
   845     NM_FUNCTION;
       
   846     
       
   847     // First lets make a copy of the current mru list
       
   848     // whose content we can later alter as we wish
       
   849     MDesCArray* currentMruList( NULL );
       
   850 
       
   851     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetId());
       
   852     if ( !plugin )
       
   853         {
       
   854         User::Leave( KErrGeneral );
       
   855         }
       
   856     currentMruList = plugin->GetMrusL( GetId() );
       
   857     if ( !currentMruList )
       
   858         {
       
   859         // This should not happen because previous function
       
   860         // should leave in error cases and if there are no
       
   861         // entries then the pointer should still be pointing
       
   862         // to valid array.
       
   863         User::Leave( KErrGeneral );
       
   864         }
       
   865     
       
   866     CDesCArraySeg* newMruList( NULL );
       
   867     TRAPD( error, newMruList = CopyArrayL( *currentMruList ) );
       
   868         
       
   869     delete currentMruList;
       
   870        
       
   871     if ( error != KErrNone )
       
   872         {
       
   873         User::Leave( error );
       
   874         }
       
   875         
       
   876     CleanupStack::PushL( newMruList );
       
   877         
       
   878     // Now check that all given recipients are found from the
       
   879     // mru list.
       
   880 
       
   881     // Notice that the order here has a meaning. For example
       
   882     // if the latest used address is appended to the end, then
       
   883     // the aRecipients' addresses are found from the end because
       
   884     // they are updated after cc and bcc recipients.
       
   885     UpdateMruListL( *newMruList, aBCCRecipients );
       
   886     UpdateMruListL( *newMruList, aCCRecipients );
       
   887     UpdateMruListL( *newMruList, aRecipients );
       
   888     
       
   889     // Finally update the new mru list to the plugin
       
   890     plugin->SetMrusL( GetId(), newMruList );
       
   891     
       
   892     CleanupStack::PopAndDestroy( newMruList );
       
   893     }
       
   894 
       
   895 // -----------------------------------------------------------------------------
       
   896 // CFSMailBox::CopyArrayL
       
   897 // -----------------------------------------------------------------------------    
       
   898 CDesCArraySeg* CFSMailBox::CopyArrayL( MDesCArray& aArrayToBeCopied ) const
       
   899     {
       
   900     NM_FUNCTION;
       
   901     
       
   902     CDesCArraySeg* newArray = new (ELeave) CDesCArraySeg( 10 );
       
   903     CleanupStack::PushL( newArray );
       
   904     
       
   905     TInt itemCount( aArrayToBeCopied.MdcaCount() );
       
   906     TInt index( 0 );
       
   907     while ( index < itemCount )
       
   908         {        
       
   909         newArray->AppendL( aArrayToBeCopied.MdcaPoint( index ) );
       
   910         ++index;
       
   911         }
       
   912     
       
   913     CleanupStack::Pop( newArray );
       
   914     return newArray;
       
   915     }
       
   916 
       
   917 // -----------------------------------------------------------------------------
       
   918 // CFSMailBox::UpdateMruListL
       
   919 // -----------------------------------------------------------------------------
       
   920 void CFSMailBox::UpdateMruListL(
       
   921     CDesCArraySeg& aMruList,
       
   922     const RPointerArray<CFSMailAddress>& aNewRecentlyUsedOnes ) const
       
   923     {
       
   924     NM_FUNCTION;
       
   925     
       
   926     TUint newCount( aNewRecentlyUsedOnes.Count() );
       
   927     TUint newIndexer( 0 );
       
   928     
       
   929     while ( newIndexer < newCount )
       
   930         {
       
   931         if ( aNewRecentlyUsedOnes[newIndexer] )
       
   932             {
       
   933             // The address is used as a search string because every
       
   934             // address does not have a display name
       
   935             TDesC& searchedAddress(
       
   936                 aNewRecentlyUsedOnes[newIndexer]->GetEmailAddress() );
       
   937             TInt position( -1 );
       
   938             
       
   939             TInt found(
       
   940                 FindAddressFromMruList( aMruList, searchedAddress, position ) );
       
   941             
       
   942             if ( found != 0 )
       
   943                 {
       
   944                 AddAndRemoveExcessMruL( aMruList,
       
   945                                         *aNewRecentlyUsedOnes[newIndexer] );
       
   946                 }
       
   947             else
       
   948                 {
       
   949                 SetAsMostRecentMruL( aMruList,
       
   950                                      position,
       
   951                                      *aNewRecentlyUsedOnes[newIndexer] );
       
   952                 }
       
   953             }        
       
   954         
       
   955         ++newIndexer;
       
   956         }
       
   957     }
       
   958 
       
   959 // -----------------------------------------------------------------------------
       
   960 // CFSMailBox::FindAddressFromMruList
       
   961 // -----------------------------------------------------------------------------
       
   962 TInt CFSMailBox::FindAddressFromMruList( CDesCArraySeg& aMruList,
       
   963                                          TDesC& searchedAddress,
       
   964                                          TInt& aPos ) const
       
   965     {
       
   966     NM_FUNCTION;
       
   967     
       
   968     // CDesCArray::Find() is not used here because there is
       
   969     // possibility that we have to go through the whole array
       
   970     // and return the index for one specific match. Find() returns
       
   971     // only the index of the first match and searching for the rest
       
   972     // using Find() would cause undesired complexity.
       
   973     
       
   974     
       
   975     const TInt KMruListCount( aMruList.Count() );
       
   976     // Start indexing from 1 because the first
       
   977     // address is on that index if it exists.
       
   978     TInt mruListIndexer( 1 );
       
   979     while( mruListIndexer < KMruListCount )
       
   980         {
       
   981         TPtrC address( aMruList[mruListIndexer] );
       
   982         if ( address == searchedAddress )
       
   983             {
       
   984             aPos = mruListIndexer;
       
   985             return 0;
       
   986             }
       
   987         
       
   988         // We are only interested of the addresses so let's
       
   989         // check only every other descriptor.
       
   990         // (the addresses)
       
   991         mruListIndexer = mruListIndexer + 2;
       
   992         }
       
   993     
       
   994     aPos = aMruList.Count();
       
   995     return 1;
       
   996     }
       
   997 
       
   998 
       
   999 
       
  1000 
       
  1001 // -----------------------------------------------------------------------------
       
  1002 // CFSMailBox::AddAndRemoveExcessMruL
       
  1003 // -----------------------------------------------------------------------------
       
  1004 void CFSMailBox::AddAndRemoveExcessMruL( CDesCArraySeg& aMruList,
       
  1005                                          CFSMailAddress& aToBeAdded ) const
       
  1006     {
       
  1007     NM_FUNCTION;
       
  1008     
       
  1009     if ( aMruList.Count() == KMaxMruEntries )
       
  1010         {
       
  1011         // Remove the oldest entry pair from the beginning
       
  1012         aMruList.Delete( 0, 2 );
       
  1013         }
       
  1014     // Latest address is always found from the end.
       
  1015     AppendMruItemL( aMruList, aToBeAdded );
       
  1016     }
       
  1017 
       
  1018 // -----------------------------------------------------------------------------
       
  1019 // CFSMailBox::SetAsMostRecentMruL
       
  1020 // -----------------------------------------------------------------------------
       
  1021 void CFSMailBox::SetAsMostRecentMruL( CDesCArraySeg& aMruList,
       
  1022                                       TInt aPosition,
       
  1023                                       CFSMailAddress& aMostRecent ) const
       
  1024     {
       
  1025     NM_FUNCTION;
       
  1026     
       
  1027     // Position of the address is given so the possible display name is
       
  1028     // in the previous slot. Delete both.
       
  1029     aMruList.Delete( aPosition - 1, 2 );
       
  1030     // Latest address is always found from the end.
       
  1031     AppendMruItemL( aMruList, aMostRecent );
       
  1032     }
       
  1033 
       
  1034 // -----------------------------------------------------------------------------
       
  1035 // CFSMailBox::AppendMruItemL
       
  1036 // -----------------------------------------------------------------------------
       
  1037 void CFSMailBox::AppendMruItemL( CDesCArraySeg& aMruList,
       
  1038                                  CFSMailAddress& aToBeAppended ) const
       
  1039     {
       
  1040     NM_FUNCTION;
       
  1041     
       
  1042     // In the array, display name is always the first and then comes
       
  1043     // the actual address.
       
  1044     
       
  1045     // <cmail> avoid setting email address as display name so it won't 
       
  1046     // be displayed twice in the list
       
  1047     TDesC* displayName  = &aToBeAppended.GetDisplayName();    
       
  1048     TDesC* emailAddress = &aToBeAppended.GetEmailAddress();
       
  1049 
       
  1050     if( displayName->Length() > 0 && displayName->Compare(*emailAddress) == 0 )
       
  1051     {
       
  1052         aMruList.AppendL( KNullDesC );
       
  1053     }
       
  1054     else
       
  1055     {
       
  1056         aMruList.AppendL( *displayName );                
       
  1057     }
       
  1058     
       
  1059     aMruList.AppendL( *emailAddress );    
       
  1060     }
       
  1061 
   713 
  1062 // -----------------------------------------------------------------------------
   714 // -----------------------------------------------------------------------------
  1063 // CFSMailBox::ReleaseExtension
   715 // CFSMailBox::ReleaseExtension
  1064 // -----------------------------------------------------------------------------
   716 // -----------------------------------------------------------------------------
  1065 EXPORT_C void CFSMailBox::ReleaseExtension( CEmailExtension* aExtension )
   717 EXPORT_C void CFSMailBox::ReleaseExtension( CEmailExtension* aExtension )
  1083 // <qmail>
   735 // <qmail>
  1084     extension = CExtendableEmail::ExtensionL( aInterfaceUid );    
   736     extension = CExtendableEmail::ExtensionL( aInterfaceUid );    
  1085     if ( aInterfaceUid == KMailboxExtMrCalInfo )
   737     if ( aInterfaceUid == KMailboxExtMrCalInfo )
  1086         {
   738         {
  1087 // </qmail>        
   739 // </qmail>        
  1088         if ( extension == NULL )
   740         if ( !extension )
  1089             {
   741             {
  1090             extension = new ( ELeave ) CMRCalendarInfoImpl();
   742             extension = new ( ELeave ) CMRCalendarInfoImpl();
  1091             CleanupStack::PushL( extension );
   743             CleanupStack::PushL( extension );
  1092             iExtensions.AddL( extension );
   744             iExtensions.AddL( extension );
  1093             CleanupStack::Pop(); // calInfo
   745             CleanupStack::Pop(); // calInfo