Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 10:45, 22 March 2008.

How to get the count of different unread messages

From Forum Nokia Wiki


ID   Creation date March 22, 2008
Platform S60 3rd, S60 3rd FP1 Tested on devices N73, N95 8Gb
Category Symbian C++ Subcategory Messaging
Keywords: Unread messages, unread emails

Overview

The original article is in Russian. You can find it here.


You can use class CUnreadMsgCalc for getting the count of unread messages and for tracking appearance of new messages.

This class also separately counts the number of unread emails from all mailboxes, registered on the current device (only already downloaded emails checked).

In order to obtain the required information, this class asynchronously creates session for interaction with the Message Server. This session is initialized in ConstructL().

Main methods:

  • NewMsgCount() returns count of unread messages
  • NewEmailCount() returns count of unread emails
  • IsCalcCompleted() returns check result (calculation is completed or not)

Header File

#include <msvapi.h>   //MMsvSessionObserver
 
class CUnreadMsgCalc: public CBase,
                      public MMsvSessionObserver
{
   public:
      static CUnreadMsgCalc* NewL();  // factory
      virtual ~CUnreadMsgCalc();
 
      inline TBool IsCalcCompleted() { return iCalcCompleted; }  // if true - then NewXXXCount returns correct value
 
      inline TInt NewMsgCount()      { return iNewMsgCount; }
      inline TInt NewEmailCount()    { return iNewEmailPopCount + iNewEmailImapCount; }
      
   private:
      void ConstructL();      
      void CalcUnreadEntriesL( const TMsvId aMsvId, TInt& aCounter ); // read one entry
      
   private: // from MMsvSessionObserver      
      void HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3 );
	   
   private:      
      CMsvSession* iMsvSession;
      TBool iCalcCompleted;
      TInt iNewMsgCount, iNewEmailPopCount, iNewEmailImapCount;	
};

Source File

#include "msgCalc.h"
 
#include <cemailaccounts.h> //CEmailAccounts
#include <miutmsg.h>        //CImEmailMessage
#include <miuthdr.h>        //CImHeader
 
CUnreadMsgCalc* CUnreadMsgCalc :: NewL()
{
   CUnreadMsgCalc* self = new ( ELeave ) CUnreadMsgCalc;
   CleanupStack :: PushL( self );
   self->ConstructL();
   CleanupStack :: Pop( self );
   return self;	
}
 
CUnreadMsgCalc :: ~CUnreadMsgCalc()
{
   delete iMsvSession;
   iMsvSession = NULL;
}
 
 
void CUnreadMsgCalc :: ConstructL()
{
   iMsvSession = CMsvSession :: OpenAsyncL( *this );	
}
 
void CUnreadMsgCalc :: CalcUnreadEntriesL( const TMsvId aMsvId, TInt& aCounter )
{
   aCounter = 0;
   CMsvEntry* entry = CMsvEntry :: NewL( *iMsvSession, aMsvId, TMsvSelectionOrdering() );
   CleanupStack::PushL( entry );	
   CMsvEntrySelection* entries = entry->ChildrenL(); 
   CleanupStack::PushL( entries );
   for( TInt i = 0; i < entries->Count(); i++ ) 
   {		
      entry->SetEntryL( entries->At( i ) );
      TMsvEntry msvEntry( entry->Entry() );
      if( msvEntry.Unread() )
         aCounter++;
   }    
   CleanupStack::PopAndDestroy( 2 ); // entries entry
}
 
 
void CUnreadMsgCalc :: HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3 )
{
   switch( aEvent )
   {
      case EMsvServerReady:
      case EMsvEntriesCreated:
      case EMsvEntriesChanged:
      case EMsvEntriesDeleted:
      case EMsvEntriesMoved:
      {		 			
         iCalcCompleted = EFalse;
    	 CalcUnreadEntriesL( KMsvGlobalInBoxIndexEntryId, iNewMsgCount ); // reading global indox
    	  
         CEmailAccounts* mailAccount = CEmailAccounts::NewLC(); // get email accounts list
         
         iNewEmailPopCount = 0;
         RArray< TPopAccount >  popAccounts( 5 );    
         mailAccount->GetPopAccountsL( popAccounts );           
         CleanupClosePushL( popAccounts );
         for( TInt i = 0; i < popAccounts.Count(); i++ ) // reading all email inboxes (POP)
         {
            TInt iCounter = 0;
            CalcUnreadEntriesL( popAccounts[i].iPopService, iCounter );
            iNewEmailPopCount += iCounter;
         }
	         
         iNewEmailImapCount = 0;
         RArray< TImapAccount > imapAccounts( 5 );    
         mailAccount->GetImapAccountsL( imapAccounts );
         CleanupClosePushL( imapAccounts );
         for( TInt i = 0; i < imapAccounts.Count(); i++ )   // reading all email inboxes (IMAP)
         {
            TInt iCounter = 0;
            CalcUnreadEntriesL( imapAccounts[i].iImapService, iCounter );
            iNewEmailImapCount += iCounter;
         }         
         CleanupStack::PopAndDestroy( 3 ); // imapAccounts popAccounts mailAccount
         iCalcCompleted = ETrue;
      }  break;
 
      default:
         break; 
   }	
}

Internal Links

Related Discussions
Thread Thread Starter Forum Replies Last Post
SMS Read Commands javanui General Messaging 6 2006-07-15 09:07
15 SMS only? graetsch General Messaging 2 2002-06-27 04:13
Messaging module ikaroweb80 Python 4 2008-04-11 07:06
关于Agnda的问题。 allenxu Symbian 0 2003-08-16 07:02
Reading sms from my 3650 elyeoh General Messaging 3 2003-07-12 04:20
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZemailQ
     qfnZtopicQUqfnTopicZmessagingQ
     qfnZtopicQUqfnTopicZsmsQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX