Read-only archive of the All About Symbian forum (2001–2013) · About this archive

encapsulating Or Attaching Cpop3Setting Within (with) Cmsventry and Cmsvsession

0 replies · 1,179 views · Started 15 May 2006

Hi ,

I have a code that make a setup for pop3 or Imap4 email server for reading email from It , Base on the Code bellow how I can encapsulate (join) this class with (Cmsventry) Or (CmsvSession) to be used in reading the email from another application classes e.g.: (Container) , Here Is the code that I have:

Container:
void CFolderContainer::ConstructL(const TRect& aRect,CFolderAppUi* aParent)
{

iParent=aParent;
CreateWindowL();
iListBox=new(ELeave)CAknDoubleStyleListBox;
iListBox->ConstructL(this,EAknListBoxSelectionList);
iListBox->SetContainerWindowL(*this);
SetRect(aRect);
CDesCArray *array=(CDesCArray*)iListBox->Model()->ItemTextArray();
//---->Original Statement
//CMsvSession *session=CMsvSession::OpenSyncL(*this);
CMsvSession *session=iParent->GetHandler()->GetSession(); //KMsvGlobalInBoxIndexEntryId
CleanupStack::PushL(session);//KMsvGlobalOutBoxIndexEntryId
//CMsvEntry *drafts=session->GetEntryL(KMsvDraftEntryId);
CMsvEntry *drafts=session->GetEntryL(KMsvGlobalInBoxIndexEntryId);
//CMsvEntry *drafts=session->GetEntryL(KMsvGlobalOutBoxIndexEntryId);
CleanupStack::PushL(drafts);
CMsvEntrySelection *children=drafts->ChildrenL();
CleanupStack::PushL(children);
_LIT(KItemFormat,"\t%S\t%S"😉;
TBuf<100> buf;
for(TInt i=0;i<children->Count();i++)
{
CMsvEntry *child=drafts->ChildEntryL((*children)[i]);
const TMsvEntry &entry=child->Entry();
buf.Format(KItemFormat,&entry.iDescription,&entry.iDetails);
delete child;
array->AppendL(buf);
}
CleanupStack::PopAndDestroy(3); // children, drafts, session
iListBox->SetSize(aRect.Size());
ActivateL();
}

Here Is a method from Another Class of type (MMsvsessionobserver) that use
(Cpop3Setting) class:

at the header:
CMsvSession* iSession;
CMsvEntrySelection* iSelection;
CClientMtmRegistry* iMtmRegistry;
CMsvEntry* iMsventry

CPop3ClientMtm* CEmailHandler::InstantiateClientMtmL(TMsvId aService, const TUid aType)
//---->Note aType Is The Type Of The Email Protocol weather It is
//---->Imap Or Pop3 e.g.: KUidMsgTypePOP3 or KUidMsgTypeIMAP4
{
//------>This Procedure In Case If We Want to Create SMTP account first
iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
TMsvId smtp = CreateServiceL(KUidMsgTypeSMTP, EFalse, EFalse, KServiceName1);
iMsvEntry->SetEntryL(KMsvRootIndexEntryId);
//------>End Of Creating SMTP account
//------>Now You Have to determaine If The Email Protocol Is (Imap4 Or Pop3)
TMsvId account;
if (aType==KUidMsgTypePOP3)
account = CreateServiceL(KUidMsgTypePOP3, EFalse, ETrue, KServiceName1);
else
account = CreateServiceL(KUidMsgTypeIMAP4, EFalse, ETrue, KServiceName1);
//------>
//------>Here The Processl Operation For Creating & Preparing The New Service
CTestActive* active = new (ELeave) CTestActive;
CleanupStack::PushL(active);
TMsvEntry entry;
iMsvEntry->SetEntryL(smtp);///////iSession->GetEntryL(aService);
entry = iMsvEntry->Entry();
entry.iRelatedId=account;
active->StartL();
CMsvOperation* opert = iMsvEntry->ChangeL(entry,active->iStatus);
CActiveScheduler::Start(); // operation complete
delete opert; opert=NULL;
iMsvEntry->SetEntryL(account);
entry = iMsvEntry->Entry();
entry.iRelatedId=smtp;
active->StartL();
opert = iMsvEntry->ChangeL(entry,active->iStatus);
CActiveScheduler::Start(); // operation complete
delete opert;
opert=NULL;
CleanupStack::PopAndDestroy(); // active
iMsvEntry->SetEntryL(smtp);
CMsvStore* store = iMsvEntry->EditStoreL();
CleanupStack::PushL(store);
CImSmtpSettings* smtpSettings = new (ELeave) CImSmtpSettings();
CleanupStack::PushL(smtpSettings);
//------>
//------>Now The Service Is Ready Lets Start Giving The Smtp Addresses To Connect
smtpSettings->Reset();
smtpSettings->SetServerAddressL(KSMTPServer1);
smtpSettings->SetEmailAliasL(KSMTPEmailAlias1);
smtpSettings->SetEmailAddressL(KSMTPEmailAddress1);
smtpSettings->SetReplyToAddressL(KSMTPEmailAddress1);
smtpSettings->SetBodyEncoding(EMsgOutboxMIME);//Text is encoded using quoted-printable encoding, and all attachments are encoded using BASE64
smtpSettings->SetReceiptAddressL(KSMTPEmailAddress1);
smtpSettings->SetPort(KPop3Port1);
smtpSettings->StoreL(*store);
store->CommitL();

CleanupStack::PopAndDestroy(2); // smtpSettings, store
//------>
//------>Now We Create And Prepare for the Protocol (IMAP or Pop3)
iMsvEntry->SetEntryL(account);
store = iMsvEntry->EditStoreL();
CleanupStack::PushL(store);
if (aType==KUidMsgTypeIMAP4)
{
CImImap4Settings* settings = new (ELeave) CImImap4Settings();
CleanupStack::PushL(settings);
settings->Reset();
settings->SetServerAddressL(KIMAP4Server1);
settings->SetLoginNameL(KIMAP4LoginName1);
settings->SetPasswordL(KIMAP4Password1);
settings->SetPort(KPop3Port1);
settings->StoreL(*store);
}
else
{
CImPop3Settings* settings = new (ELeave) CImPop3Settings();
CleanupStack::PushL(settings);
settings->Reset();
settings->SetServerAddressL(KPOP3Server1);
settings->SetLoginNameL(KPOP3LoginName1);
settings->SetPasswordL(KPOP3Password1);
settings->SetPort(KPop3Port1);
settings->StoreL(*store);
}
store->CommitL();
//------------------------------------------------------------------------------------------------------------------------->
CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
_LIT(messageCreated,"Initializing Process For Client Starts"😉;
informationNote->ExecuteLD(messageCreated);
iSession=&iMsvEntry->Session();
iMtmRegistry = CClientMtmRegistry::NewL(*iSession);
CPop3ClientMtm* newMtm = static_cast<CPop3ClientMtm*>(iMtmRegistry->NewMtmL(aType));
//newMtm = static_cast<CPop3ClientMtm*>(iMtmRegistry->NewMtmL(aType));
CleanupStack::PushL(newMtm);

//------------------------------------------------------------------------------------------------------------------------->
CleanupStack::PopAndDestroy(2); // settings, store
// create a client mtm///---->
return newMtm;
}

Thanks