981 break; |
979 break; |
982 } |
980 } |
983 } |
981 } |
984 } |
982 } |
985 |
983 |
986 // --------------------------------------------------------- |
|
987 // CMailCpsHandler::HandleNewMailEventL |
|
988 // --------------------------------------------------------- |
|
989 // |
|
990 void CMailCpsHandler::HandleNewMailEventL( |
|
991 TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 ) |
|
992 { |
|
993 FUNC_LOG; |
|
994 |
|
995 iSettings->ToggleWidgetNewMailIconL( ETrue, aMailbox ); |
|
996 |
|
997 // Basic assertions |
|
998 if ( !aParam1 || !aParam2 ) |
|
999 { |
|
1000 User::Leave( KErrArgument ); |
|
1001 } |
|
1002 |
|
1003 // typecast param2 |
|
1004 TFSMailMsgId* parentFolder = static_cast<TFSMailMsgId*>( aParam2 ); |
|
1005 |
|
1006 // Check that folder is correct |
|
1007 CFSMailFolder* folder = MailClient().GetFolderByUidL( aMailbox, *parentFolder ); |
|
1008 if ( !folder ) |
|
1009 { |
|
1010 User::Leave( KErrNotFound ); |
|
1011 } |
|
1012 CleanupStack::PushL( folder ); |
|
1013 if ( folder->GetFolderType() != EFSInbox ) |
|
1014 { |
|
1015 CleanupStack::PopAndDestroy( folder ); |
|
1016 return; |
|
1017 } |
|
1018 CleanupStack::PopAndDestroy( folder ); |
|
1019 |
|
1020 // typecast param1 |
|
1021 RArray<TFSMailMsgId>* newEntries( |
|
1022 static_cast< RArray<TFSMailMsgId>* >( aParam1 ) ); |
|
1023 CleanupClosePushL( *newEntries ); |
|
1024 const TInt iiMax( newEntries->Count() ); |
|
1025 if ( iiMax == 0 ) |
|
1026 { |
|
1027 User::Leave( KErrArgument ); |
|
1028 } |
|
1029 |
|
1030 // Loop through message array |
|
1031 TFSMailMsgId msgId; |
|
1032 CFSMailMessage* msg( NULL ); |
|
1033 CMailMailboxDetails* mailbox; |
|
1034 for ( TInt ii = 0; ii < iiMax; ii++ ) |
|
1035 { |
|
1036 msgId = (*newEntries)[ii]; |
|
1037 |
|
1038 msg = MailClient().GetMessageByUidL( |
|
1039 aMailbox, *parentFolder, (*newEntries)[ii], EFSMsgDataEnvelope ); |
|
1040 if ( !msg ) |
|
1041 { |
|
1042 User::Leave( KErrNotFound ); |
|
1043 } |
|
1044 CleanupStack::PushL( msg ); |
|
1045 |
|
1046 // Check if message read |
|
1047 if ( !MsgIsUnread( *msg ) ) |
|
1048 { |
|
1049 // Ignore already read messages |
|
1050 CleanupStack::PopAndDestroy( msg ); |
|
1051 continue; |
|
1052 } |
|
1053 |
|
1054 // Find mailbox instance from array |
|
1055 mailbox = FindMailboxDetails( aMailbox ); |
|
1056 if ( !mailbox ) |
|
1057 { |
|
1058 CleanupStack::PopAndDestroy( msg ); |
|
1059 CleanupStack::PopAndDestroy( newEntries ); |
|
1060 return; |
|
1061 } |
|
1062 |
|
1063 // Check if message is duplicate |
|
1064 if ( IsDuplicate( *mailbox, msgId ) ) |
|
1065 { |
|
1066 // Ignore already known messages |
|
1067 CleanupStack::PopAndDestroy( msg ); |
|
1068 continue; |
|
1069 } |
|
1070 |
|
1071 CMailMessageDetails* messageDetails = CMailMessageDetails::NewL( |
|
1072 msg->GetMessageId(), |
|
1073 mailbox, |
|
1074 msg->GetSender()->GetEmailAddress(), |
|
1075 msg->GetSubject(), |
|
1076 msg->GetDate() ); |
|
1077 CleanupStack::PopAndDestroy( msg ); |
|
1078 CleanupStack::PushL( messageDetails ); |
|
1079 |
|
1080 // Place message to array |
|
1081 mailbox->iMessageDetailsArray.AppendL( messageDetails ); |
|
1082 CleanupStack::Pop( messageDetails ); |
|
1083 } |
|
1084 CleanupStack::PopAndDestroy( newEntries ); |
|
1085 } |
|
1086 |
|
1087 // --------------------------------------------------------- |
|
1088 // CMailCpsHandler::HandleMailDeletedEventL |
|
1089 // --------------------------------------------------------- |
|
1090 // |
|
1091 void CMailCpsHandler::HandleMailDeletedEventL( |
|
1092 TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 ) |
|
1093 { |
|
1094 FUNC_LOG; |
|
1095 // Basic assertions |
|
1096 if ( !aParam1 || !aParam2 ) |
|
1097 { |
|
1098 User::Leave( KErrArgument ); |
|
1099 } |
|
1100 // Typecast parameters |
|
1101 RArray<TFSMailMsgId>* entries( |
|
1102 static_cast< RArray<TFSMailMsgId>* >( aParam1 ) ); |
|
1103 CleanupClosePushL( *entries ); |
|
1104 if ( entries->Count() == 0 ) |
|
1105 { |
|
1106 User::Leave( KErrArgument ); |
|
1107 } |
|
1108 |
|
1109 // Find correct mailbox |
|
1110 CMailMailboxDetails* mailbox = FindMailboxDetails( aMailbox ); |
|
1111 if ( !mailbox ) |
|
1112 { |
|
1113 CleanupStack::PopAndDestroy( entries ); |
|
1114 return; |
|
1115 } |
|
1116 |
|
1117 const TInt iiMax( entries->Count() ); |
|
1118 const TInt jjMax( mailbox->iMessageDetailsArray.Count() ); |
|
1119 // Loop through entries in the array |
|
1120 for ( TInt ii = 0; ii < iiMax; ii++ ) |
|
1121 { |
|
1122 // Loop through messages in the local cache |
|
1123 for ( TInt jj = 0; jj < jjMax; jj++ ) |
|
1124 { |
|
1125 if ( mailbox->iMessageDetailsArray[jj]->iMsgId.Id() == |
|
1126 (*entries)[ii].Id() ) |
|
1127 { |
|
1128 CMailMessageDetails* details = mailbox->iMessageDetailsArray[jj]; |
|
1129 delete details; |
|
1130 details = NULL; |
|
1131 mailbox->iMessageDetailsArray.Remove(jj); |
|
1132 break; // breaks out from the inner loop and starts new outer loop if necessary |
|
1133 } |
|
1134 else |
|
1135 { |
|
1136 } |
|
1137 } |
|
1138 } |
|
1139 |
|
1140 CleanupStack::PopAndDestroy( entries ); |
|
1141 } |
|
1142 |
984 |
1143 // --------------------------------------------------------- |
985 // --------------------------------------------------------- |
1144 // CMailCpsHandler::GetUnreadCountL |
986 // CMailCpsHandler::GetUnreadCountL |
1145 // --------------------------------------------------------- |
987 // --------------------------------------------------------- |
1146 // |
988 // |
1664 |
1506 |
1665 return ETrue; |
1507 return ETrue; |
1666 } |
1508 } |
1667 |
1509 |
1668 // ----------------------------------------------------------------------------- |
1510 // ----------------------------------------------------------------------------- |
1669 // CMailCpsHandler::IsDuplicate |
|
1670 // ----------------------------------------------------------------------------- |
|
1671 TBool CMailCpsHandler::IsDuplicate( const CMailMailboxDetails& aMailbox, const TFSMailMsgId& aMsgId ) |
|
1672 { |
|
1673 FUNC_LOG; |
|
1674 TBool isDuplicate( EFalse ); |
|
1675 const TInt size( aMailbox.iMessageDetailsArray.Count() ); |
|
1676 for ( TInt jj = 0; jj < size; jj++ ) |
|
1677 { |
|
1678 if ( aMailbox.iMessageDetailsArray[jj]->iMsgId.Id() == aMsgId.Id() ) |
|
1679 { |
|
1680 isDuplicate = ETrue; |
|
1681 } |
|
1682 } |
|
1683 return isDuplicate; |
|
1684 } |
|
1685 |
|
1686 // ----------------------------------------------------------------------------- |
|
1687 // CMailCpsHandler::LaunchWidgetSettingsL() |
1511 // CMailCpsHandler::LaunchWidgetSettingsL() |
1688 // ----------------------------------------------------------------------------- |
1512 // ----------------------------------------------------------------------------- |
1689 // |
1513 // |
1690 void CMailCpsHandler::LaunchWidgetSettingsL( const TDesC& aContentId ) |
1514 void CMailCpsHandler::LaunchWidgetSettingsL( const TDesC& aContentId ) |
1691 { |
1515 { |