emailservices/emailserver/cmailhandlerplugin/src/fsnotificationhandlerbaseimpl.cpp
branchRCL_3
changeset 80 726fba06891a
parent 64 3533d4323edc
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
   102     {
   102     {
   103     FUNC_LOG;
   103     FUNC_LOG;
   104 
   104 
   105     CFSMailFolder* parentFolder(
   105     CFSMailFolder* parentFolder(
   106         MailClient().GetFolderByUidL( aMailboxId, aParentFolderId ) );
   106         MailClient().GetFolderByUidL( aMailboxId, aParentFolderId ) );
   107     User::LeaveIfNull( parentFolder );
   107     if ( !parentFolder )
       
   108         {
       
   109         // by some reason the folder could not be found..
       
   110         return EFalse;
       
   111         }
   108     CleanupStack::PushL( parentFolder );
   112     CleanupStack::PushL( parentFolder );
   109     
   113     
   110     CFSMailMessage* newestMsg( NULL );
   114     CFSMailMessage* newestMsg( NULL );
   111     TRAPD( notFoundError,
   115     TRAPD( notFoundError,
   112            newestMsg =
   116            newestMsg =
   142             currentMessage( MailClient().GetMessageByUidL(
   146             currentMessage( MailClient().GetMessageByUidL(
   143                 aMailboxId, 
   147                 aMailboxId, 
   144                 aParentFolderId,
   148                 aParentFolderId,
   145                 aMsgIdList[index], 
   149                 aMsgIdList[index], 
   146                 EFSMsgDataEnvelope ) );
   150                 EFSMsgDataEnvelope ) );
   147         User::LeaveIfNull( currentMessage );
   151         if ( currentMessage )
   148         const TTime dateOfCurrentMsg( currentMessage->GetDate() );
   152             {
   149         
   153             const TTime dateOfCurrentMsg( currentMessage->GetDate() );
   150         
   154             
   151         const TBool msgIsUnread( MsgIsUnread( *currentMessage ) );
   155             const TBool msgIsUnread( MsgIsUnread( *currentMessage ) );
   152         delete currentMessage;
   156             delete currentMessage;
   153         currentMessage = NULL;
   157             currentMessage = NULL;
   154         
   158             
   155         if ( msgIsUnread &&
   159             if ( msgIsUnread &&
   156              ( dateOfCurrentMsg >= dateOfNewest ) )
   160                  ( dateOfCurrentMsg >= dateOfNewest ) )
   157             {
   161                 {
   158             // At least one of the messages is unread and newest.
   162                 // At least one of the messages is unread and newest.
   159             return ETrue;
   163                 return ETrue;
       
   164                 }
   160             }
   165             }
   161             
   166             
   162         --index;
   167         --index;
   163         }
   168         }
   164     
   169     
   180     {
   185     {
   181     FUNC_LOG;
   186     FUNC_LOG;
   182     if ( aEvent != TFSEventMailboxDeleted )
   187     if ( aEvent != TFSEventMailboxDeleted )
   183         {
   188         {
   184         CFSMailBox* mailBox( MailClient().GetMailBoxByUidL( aMailbox ) );
   189         CFSMailBox* mailBox( MailClient().GetMailBoxByUidL( aMailbox ) );
   185         if ( mailBox == NULL )
   190         if ( !mailBox )
   186             {
   191             {
   187             User::Leave( KErrArgument );
   192             User::Leave( KErrArgument );
   188             }
   193             }
   189 
   194 
   190         if ( mailBox->HasCapability( EFSMBoxCapaNewEmailNotifications ) )
   195         if ( mailBox->HasCapability( EFSMBoxCapaNewEmailNotifications ) )
   217         {
   222         {
   218         // In case of TFSEventNewMail we have parent folder id
   223         // In case of TFSEventNewMail we have parent folder id
   219         // in aParam2
   224         // in aParam2
   220         TFSMailMsgId* parentFolderId( NULL );
   225         TFSMailMsgId* parentFolderId( NULL );
   221         parentFolderId = static_cast< TFSMailMsgId* >( aParam2 );
   226         parentFolderId = static_cast< TFSMailMsgId* >( aParam2 );
   222         if ( parentFolderId == NULL )
   227         if ( !parentFolderId )
   223             {
   228             {
   224             User::Leave( KErrArgument );
   229             User::Leave( KErrArgument );
   225             }
   230             }
   226 
   231 
   227         // Set the notification on only in cases that the new mail is
   232         // Set the notification on only in cases that the new mail is
   261 
   266 
   262 void CFSNotificationHandlerBase::TimerExpiredL()
   267 void CFSNotificationHandlerBase::TimerExpiredL()
   263     {
   268     {
   264     // process collected insert requests
   269     // process collected insert requests
   265     RArray<TFSMailMsgId> msgIds;
   270     RArray<TFSMailMsgId> msgIds;
       
   271     CleanupClosePushL( msgIds );
       
   272 
   266     TFSMailMsgId mailBoxId;
   273     TFSMailMsgId mailBoxId;
   267     TFSMailMsgId parentFolderId;
   274     TFSMailMsgId parentFolderId;
   268     for ( TInt i = 0; i< iNewInboxEntries.Count(); i++ )
   275     for ( TInt i = 0; i< iNewInboxEntries.Count(); i++ )
   269         {
   276         {
   270         TNewMailInfo& info = iNewInboxEntries[ i ];
   277         TNewMailInfo& info = iNewInboxEntries[ i ];
   297         {
   304         {
   298         TurnNotificationOn();
   305         TurnNotificationOn();
   299         }
   306         }
   300     // clear processed entries
   307     // clear processed entries
   301     msgIds.Reset();
   308     msgIds.Reset();
       
   309     CleanupStack::PopAndDestroy( &msgIds );
   302     iNewInboxEntries.Reset();    
   310     iNewInboxEntries.Reset();    
   303     }
   311     }
   304 
   312 
   305 CFSMailMessage* CFSNotificationHandlerBase::NewestMsgInFolderL(
   313 CFSMailMessage* CFSNotificationHandlerBase::NewestMsgInFolderL(
   306     CFSMailFolder& aFolder ) const
   314     CFSMailFolder& aFolder ) const
   321     sorting.Append( criteriaDate );
   329     sorting.Append( criteriaDate );
   322     MFSMailIterator* iterator = aFolder.ListMessagesL( details, sorting );
   330     MFSMailIterator* iterator = aFolder.ListMessagesL( details, sorting );
   323     
   331     
   324     // Resetting array of sort criteria already here because
   332     // Resetting array of sort criteria already here because
   325     // the iterator does not need it anymore.
   333     // the iterator does not need it anymore.
   326     CleanupStack::PopAndDestroy(); // sorting
   334     CleanupStack::PopAndDestroy( &sorting );
   327                                     
   335                                     
   328     // CleanupStack::PushL doesn't work for M-class
   336     // CleanupStack::PushL doesn't work for M-class
   329     CleanupDeletePushL( iterator ); 
   337     CleanupDeletePushL( iterator ); 
   330     
   338     
   331     RPointerArray<CFSMailMessage> messages;
   339     RPointerArray<CFSMailMessage> messages;
   340         }
   348         }
   341             
   349             
   342     CFSMailMessage* outcome = messages[0];
   350     CFSMailMessage* outcome = messages[0];
   343     messages.Remove( 0 ); // remove from array to prevent destruction of element
   351     messages.Remove( 0 ); // remove from array to prevent destruction of element
   344     messages.ResetAndDestroy();
   352     messages.ResetAndDestroy();
   345     CleanupStack::PopAndDestroy(); // messages
   353     CleanupStack::PopAndDestroy( &messages ); 
   346     CleanupStack::PopAndDestroy( iterator );
   354     CleanupStack::PopAndDestroy( iterator );
   347     return outcome;
   355     return outcome;
   348     }
   356     }
   349 
   357 
   350 CNewMailNotificationTimer::CNewMailNotificationTimer( MFSTimerObserver& aObserver ) :
   358 CNewMailNotificationTimer::CNewMailNotificationTimer( MFSTimerObserver& aObserver ) :
   390     {
   398     {
   391     FUNC_LOG;
   399     FUNC_LOG;
   392     iObserver.TimerExpiredL();
   400     iObserver.TimerExpiredL();
   393     }
   401     }
   394 
   402 
       
   403 TInt CNewMailNotificationTimer::RunError(TInt aError)
       
   404     {
       
   405     if( aError )
       
   406         {
       
   407         INFO_1( "CNewMailNotificationTimer::RunError( aError: %d )", aError );
       
   408         }
       
   409     
       
   410     return KErrNone;
       
   411     }
   395 
   412 
   396 void Panic( TCmailhandlerPanic aPanic )
   413 void Panic( TCmailhandlerPanic aPanic )
   397     {
   414     {
   398     _LIT( KPanicText, "emailhandlerplugin" );
   415     _LIT( KPanicText, "emailhandlerplugin" );
   399     User::Panic( KPanicText, aPanic );
   416     User::Panic( KPanicText, aPanic );