I am trying to read email from the phone Inbox. HasStoreL() always returns false. Please help. The same code was working sometime back but i made lot of changes and i am not able to figure out why it is not working now. Sorry for posting lengthy code.
msvEntry->Count() function returns the correct number of emails in the inbox. But i am not able to read subject, from and email body.
void CReadEmail::ReadEmailL(TDesC& aMailBoxType,TDesC &aMailBoxName)
_LIT(KPopType,"pop");
iSession = CMsvSession::OpenSyncL(*this);
CEmailAccounts* emailAccount = CEmailAccounts::NewLC();
TPtrC ptr(aMailBoxType);
CMsvEntry* msvEntry;
if(!ptr.Compare(KPopType))
{
RArray<TPopAccount> pop3Accounts;
emailAccount->GetPopAccountsL(pop3Accounts);
RBuf PopMailboxName;
TMsvId PopMailboxId;
for(TInt index=0;index<pop3Accounts.Count();index++)
{
PopMailboxName.CreateL(pop3Accounts[index].iPopAccountName);
if(!PopMailboxName.Compare(aMailBoxName))
{
PopMailboxId = pop3Accounts[index].iPopService;
}
}
pop3Accounts.Reset();
PopMailboxName.Close();
msvEntry =CMsvEntry::NewL(*iSession,PopMailboxId,TMsvSelectionOrdering::TMsvSelectionOrdering());
}
else
{
RArray<TImapAccount> imap4Accounts;
emailAccount ->GetImapAccountsL(imap4Accounts);
RBuf ImapMailboxName;
TMsvId ImapMailboxId;
for(TInt index=0;index<imap4Accounts.Count();index++)
{
ImapMailboxName.CreateL(imap4Accounts[index].iImapAccountName);
if(ImapMailboxName.Compare(aMailBoxName))
{
ImapMailboxId = imap4Accounts[index].iImapService;
}
}
imap4Accounts.Reset();
ImapMailboxName.Close();
msvEntry =CMsvEntry::NewL(*iSession,ImapMailboxId,TMsvSelectionOrdering::TMsvSelectionOrdering());
CleanupStack::PushL(msvEntry);
}
CleanupStack::PopAndDestroy(emailAccount);
if(msvEntry->Count())
{
TMsvSelectionOrdering sort;
sort.SetShowInvisibleEntries(ETrue);
sort.SetSorting(EMsvSortByDateReverse);
msvEntry->SetSortTypeL(sort);
CMsvEntrySelection* msvEntrySelection = msvEntry->ChildrenL();
for(TInt index =0; index<msvEntrySelection->Count();index++)
{
TMsvId emailId = msvEntry->ChildDataL(msvEntrySelection->At(index)).Id();
CMsvEntry* entry = iSession->GetEntryL((*msvEntrySelection)[index]);
CleanupStack::PushL(entry);
if(entry->HasStoreL())
{
CMsvStore* store=entry->ReadStoreL();
CleanupStack::PushL(store);
CImHeader* header=CImHeader::NewLC();
header->RestoreL(*store);
TBuf<50> subject = header->Subject();
TBuf<50> from = header->From();
CleanupStack::PopAndDestroy(header);
CleanupStack::PopAndDestroy(store);
}
CParaFormatLayer* paraFormatLayer=CParaFormatLayer::NewL();
CCharFormatLayer* charFormatLayer=CCharFormatLayer::NewL();
CRichText* richText=CRichText::NewL(paraFormatLayer,charFormatLayer);
CImEmailMessage* emailMessage = CImEmailMessage::NewLC(*entry);
emailMessage->GetBodyTextL(emailId,CImEmailMessage::EThisMessageOnly,*richText,*paraFormatLayer,*charFormatLayer);
RBuf emailBody;
TInt in = richText->DocumentLength();
emailBody.CreateL(richText->DocumentLength());
emailBody.Zero();
richText->Extract(emailBody);
const TInt length = richText->DocumentLength();
TBuf<400> mailContent;
mailContent.Copy(richText->Read(0,length));
emailBody.Close();
CleanupStack::PopAndDestroy(emailMessage);
delete richText; richText=NULL;
delete charFormatLayer; charFormatLayer=NULL;
delete paraFormatLayer; paraFormatLayer=NULL;
CleanupStack::PopAndDestroy(entry);
}
}



