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 ) |