×
Namespaces

Variants
Actions

Reading SMS from Inbox

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (10 Apr 2007)
Last edited: hamishwillee (14 Jun 2013)

The ReadMailFolderL()- function shows how you could get the list of available messages from the inbox. For reading other folders, you just need to change the KMsvGlobalInBoxIndexEntryId to be one of the following:

- KMsvGlobalOutBoxIndexEntryId (outbox folder)

- KMsvDraftEntryId (Drfats folder)

- KMsvSentEntryId (sent messages folder)

And if you want to get all other messages (non SMS), just comment out the line checking if the message entry’s MTM is KUidMsgTypeSMS. Note that aSession needs to be correctly opened before this function can be called.

void ReadMailFolderL(CMsvSession* aSession,RArray<TMsvEntry>& aMailArray)
{
CMsvEntry* Entrie = aSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
CleanupStack::PushL(Entrie);
if(Entrie->Count())
{
TMsvSelectionOrdering MySortType;
 
//MySortType.SetSorting(EMsvSortByDetails);
MySortType.SetSorting(EMsvSortByDate);
 
Entrie->SetSortTypeL(MySortType);
 
CMsvEntrySelection* entries = Entrie->ChildrenL();
CleanupStack::PushL(entries);
 
for(TInt i = (Entrie->Count() - 1); i >= 0; i--)
{
if(Entrie->ChildDataL(entries->At(i)).iMtm == KUidMsgTypeSMS)
{
aMailArray.Append(Entrie->ChildDataL(entries->At(i)));
}
}
 
CleanupStack::PopAndDestroy(entries);
}
 
CleanupStack::PopAndDestroy(1);//Entrie
}

You could use the aMailArray already to fill your list box, but if you need to get the phone number of the sender and the whole message body, you could utilize following GetMessageL()-function.

void GetMessageL(CMsvSession* aSession,TMsvEntry aMailEntry,TDes& aFrom,TDes& aMessage)
{
if(aMailEntry.iMtm == KUidMsgTypeSMS)
{
CSmsClientMtm* SmsMtm = STATIC_CAST(CSmsClientMtm*,iMtmReg->NewMtmL(KUidMsgTypeSMS));
CleanupStack::PushL(SmsMtm);
 
SmsMtm->SwitchCurrentEntryL(aMailEntry.Id());
SmsMtm->LoadMessageL();
 
aFrom.Copy(SmsMtm->SmsHeader().Message().ToFromAddress());
 
if(!aFrom.Length())
{
if(SmsMtm->AddresseeList().Count())
{
aFrom.Copy(SmsMtm->AddresseeList().MdcaPoint(0));
}
}
 
aMessage.Copy(SmsMtm->Body().Read(0)); //Warning! This will give you only first 256 symbols. Check SmsMtm->Body().DocumentLength() for actual length.
 
CleanupStack::PopAndDestroy(SmsMtm);
SmsMtm = NULL;
}
}

Related Links:

This page was last modified on 14 June 2013, at 09:34.
99 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×