How to create folders and Subfolders inside Inbox
Article Metadata
One can create folders or service entries inside standard messaging folders like InBox or Drafts. The following code for creating subfolders does not result in the creation of a subfolder in older versions of Symbian 3rd Edition. However it works properly in Symbian 3rd Edition FP1.
Hearders Required:
#include <msvapi.h>
#include <msvstd.h >
Library required:
LIBRARY msgs.libMember Variables
CMsvSession* iSession;
// *this represents a class derived from MMsvSessionObserver
iSession = CMsvSession::OpenSyncL(*this);
CMsvOperationActiveSchedulerWait * iWaitOp;
CMsvEntry* iEntry1;
Functions
void CreateFolder()
{
TMsvEntry folderEntry;
folderEntry.iDescription.Set(_L("Folder"));
folderEntry.iDetails.Set(_L("Folder"));
folderEntry.iType = KUidMsvFolderEntry;
folderEntry.iMtm = KUidMsgTypeSMS;
folderEntry.SetReadOnly(EFalse);
folderEntry.iServiceId = KMsvGlobalInBoxIndexEntryId;
folderEntry.iDate.UniversalTime();
folderEntry.SetVisible(ETrue);
folderEntry.SetStandardFolder(ETrue);
TMsvSelectionOrdering sort1;
CMsvEntry* parenfolderEntry = CMsvEntry::NewL
(*iSession,KMsvGlobalInBoxIndexEntryId,sort1);
if (!iWaitOp)
{
iWaitOp = CMsvOperationActiveSchedulerWait::NewLC();
CleanupStack::Pop(iWaitOp);
}
CMsvOperation * pCreateFolderOp = parenfolderEntry->CreateL
(folderEntry,iWaitOp->iStatus);
CleanupStack::PushL(pCreateFolderOp);
iWaitOp->iStatus = KRequestPending;
iWaitOp->Start();
CleanupStack::PopAndDestroy(pCreateFolderOp);
CMsvEntrySelection* sel= parenfolderEntry->ChildrenWithMtmL
(KUidMsgTypeSMS);
TMsvId mtmid;
mtmid = sel->At(0); //Folder1 Entry Id
CreateSubFolderL(mtmid);
}
void CreateSubFolderL(TMsvId aParentId)
{
TMsvEntry subfolderEntry;
subfolderEntry.iDescription.Set(_L("SubFolder"));
subfolderEntry.iDetails.Set(_L("SubFolder"));
subfolderEntry.iType = KUidMsvFolderEntry;
subfolderEntry.iMtm = KUidMsgTypeSMS;
subfolderEntry.iServiceId = aParentId;
subfolderEntry.SetVisible(ETrue);
subfolderEntry.SetStandardFolder(ETrue);
subfolderEntry.iDate.UniversalTime();
TMsvSelectionOrdering sort2;
iEntry1 = CMsvEntry::NewL(*iSession, aParentId,sort2);
iEntry1->CreateL(subfolderEntry,iStatus);
SetActive();
}

