You Are Here:

Community: Wiki

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

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 Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5fgetE5ftheE5fcountE5fofE5fdifferentE5funreadE5fmessagesX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxHowE20toE20getE20theE20countE20ofE20differentE20unreadE20messagesE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZemailQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZmessagingQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZsmsQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxeE2dmailX qfnZuserE5ftagQSxmessagingX qfnZuserE5ftagQSxsmsX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ