📄 internetemailengine.cpp
字号:
// ---------------------------------------------
// void CInternetEmailEngine::CancelOperation()
// public interface method for user initiated
// cancelling of email operations.
// ---------------------------------------------
//
void CInternetEmailEngine::CancelOperation()
{
iState= ECanceling; //we switch state and wait for op to cancel
if( iMsvOp )
{
iMsvOp->Cancel(); //iStatus now KErrCancel (-3)
}
}
// ---------------------------------------------
// void CInternetEmailEngine::DoCancel()
// framework cancel method, no implemented here
// ---------------------------------------------
//
void CInternetEmailEngine::DoCancel()
{
// no implementation required
}
// -------------------------------------------------------
// TInt CInternetEmailEngine::RunError( const TInt aError)
// simply return error value
// -------------------------------------------------------
//
TInt CInternetEmailEngine::RunError( const TInt aError)
{
return aError;
}
// -------------------------------------
// void CInternetEmailEngine::LoadMtmL()
// common helper to load mtm context
// -------------------------------------
//
void CInternetEmailEngine::LoadMtmL()
{
if(iId == KMsvRootIndexEntryId)
{
User::Leave(KErrNotFound);
}
TMsvEntry tmp;
User::LeaveIfError(iMsvSession->GetEntry(iId,iServiceId,tmp));
iMtm =InstantiateClientMtmL(iServiceId,iProtocolUid);
}
// ------------------------------------------------------
// CBaseMtm* CInternetEmailEngine::InstantiateClientMtmL(
// TMsvId aService, const TUid aType)
// Helper to load either imap/pop mtm using base class
// ------------------------------------------------------
//
CBaseMtm* CInternetEmailEngine::InstantiateClientMtmL(TMsvId aService, const TUid aType)
{
// create a client mtm
CBaseMtm* newMtm = iClientReg->NewMtmL(aType);
CleanupStack::PushL(newMtm);
// get the entry associated with the given servive ID
CMsvEntry* entry = iMsvSession->GetEntryL(aService);
CleanupStack::PushL(entry);
// set the entry as the current entry
// mtm takes ownership of the entry
newMtm->SetCurrentEntryL(entry);
CleanupStack::Pop(2); //newMtm, entry
return newMtm;
}
// -------------------------------------------------------------------
// void CInternetEmailEngine::Queue()
// SetActive() or complete our own status.
// this allows the active scheduler chance to
// service other active objects before return back to our RunL
// -------------------------------------------------------------------
//
void CInternetEmailEngine::Queue()
{
if(!IsActive())
{
SetActive();
}
TRequestStatus* st= &iStatus;
User::RequestComplete(st,KErrNone);
}
// -----------------------------------------------------------------
// TBool CInternetEmailEngine::CheckIfExistsL( const TInt typeenum )
// returns ETrue if given type protocol type exists
// -----------------------------------------------------------------
//
TBool CInternetEmailEngine::CheckIfExistsL( const TInt aTypeEnum )
{
TUid temp = ( aTypeEnum == EProtocolImap4 ) ? KUidMsgTypeIMAP4 : KUidMsgTypePOP3;
TMsvId id=FindServiceL(temp);
return ( id == KMsvRootIndexEntryId ) ? EFalse : ETrue;
}
// ---------------------------------------------------------------
// TPtrC CInternetEmailEngine::RemoteEmailTextL(const TInt aIndex)
// Get the subject of the email from message header
// ---------------------------------------------------------------
//
TPtrC CInternetEmailEngine::RemoteEmailTextL( const TInt aIndex )
{
if( iState == ECanceling )
{
User::Leave( KErrCancel );
}
TMsvId entryId=(*iRemoteEntries)[aIndex];
if(iEntry==NULL || iEntry->Entry().Id()!=entryId)
{
delete iEntry;
iEntry=NULL;
iEntry=iMsvSession->GetEntryL(entryId);
}
return iEntry->Entry().iDescription;
}
// ------------------------------------------------------------------
// TPtrC CInternetEmailEngine::RemoteEmailSenderL( const TInt aIndex)
// Get the sender of the email from message header
// ------------------------------------------------------------------
//
TPtrC CInternetEmailEngine::RemoteEmailSenderL( const TInt aIndex )
{
if( iState == ECanceling )
{
User::Leave( KErrCancel );
}
TMsvId entryId=(*iRemoteEntries)[aIndex];
if(iEntry==NULL || iEntry->Entry().Id()!=entryId)
{
delete iEntry;
iEntry=NULL;
iEntry=iMsvSession->GetEntryL(entryId);
}
return iEntry->Entry().iDetails;
}
// ---------------------------------------------
// TInt CInternetEmailEngine::RemoteEmailCount()
// get the email count as integer
// ---------------------------------------------
//
TInt CInternetEmailEngine::RemoteEmailCount()
{
return iRemoteCount;
}
// ------------------------------------------------------------------
// void CInternetEmailEngine::RemoteOpenEmailL( TInt aIndex )
// open remote email. may cause system to go online to retrieve mail
// ------------------------------------------------------------------
//
void CInternetEmailEngine::RemoteOpenEmailL( TInt aIndex )
{
TMsvId entryId=(*iRemoteEntries)[aIndex];
if(aIndex<0 || aIndex>=iRemoteCount)
{
User::Leave(KErrGeneral);
}
iState=EReady;
DisplayMessageL(entryId);
}
// --------------------------------------------------------
// void CInternetEmailEngine::RemoteFetchL()
// enters connect state and queues own request accordingly
// --------------------------------------------------------
//
void CInternetEmailEngine::RemoteFetchL()
{
iState=EConnecting;
Queue();
}
// ---------------------------------------------------------
// CMsvEntrySelection* CInternetEmailEngine::UpdateEntriesL(
// const TMsvId& aServiceId)
// updates the message entries for viewing
// ---------------------------------------------------------
//
CMsvEntrySelection* CInternetEmailEngine::UpdateEntriesL(
const TMsvId& aServiceId)
{
CMsvEntry* entry=iMsvSession->GetEntryL(aServiceId); // get the entry
CleanupStack::PushL(entry);
CMsvEntrySelection* entries=entry->ChildrenL(); // get the entry's children
CleanupStack::PopAndDestroy(entry);
return entries;
}
// -----------------------------------------------
// void CInternetEmailEngine::UpdateRemoteCountL()
// update the remote mail count
//
// Note: only method where observers are notified
// -----------------------------------------------
//
void CInternetEmailEngine::UpdateRemoteCountL()
{
// reset the remote mail count and entries
iRemoteCount=0;
delete iRemoteEntries;
iRemoteEntries=NULL;
// SEPARATION BETWEEN IMAP AND POP
if( iProtocolType == EProtocolImap4 && !iHasImapInbox )
{
iId=FindFolderThenServiceL(iProtocolUid); //leaves with KErrFound if still no folder set
}
// get the current entries. Note that iId is normally a remote
// mailbox for pop and first folder( inbox ) for imap. which is
// why we have to check if folders are already sync if protocol
// is imap, so we wont draw the screen with wrong parent and output
// folders to the listbox and not the message entries we want to.
iRemoteEntries=UpdateEntriesL(iId);
// if the nunber has changed then inform the observers
if(iRemoteEntries->Count()!=iRemoteCount)
{
iRemoteCount=iRemoteEntries->Count();
iObserver.HandleEngineChangedEventL(ERemoteCountChanged);
}
}
// -------------------------------------------
// TBool CInternetEmailEngine::IsProtocolSet()
// returns ETrue if protocol is set
// -------------------------------------------
//
TBool CInternetEmailEngine::IsProtocolSet()
{
return iIsProtocolSet;
}
// ----------------------------------------------------
// TBool CInternetEmailEngine::IsEngineReady()
// returns ETrue if server is ready thus engine is too
// ----------------------------------------------------
//
TBool CInternetEmailEngine::IsEngineReady()
{
return (iClientReg!=NULL)?(ETrue):(EFalse);
}
// --------------------------------------------------------------
// void CInternetEmailEngine::SetProtocolL( const TInt aType )
// sets protocol and loads mtm context for given protocol.
// note that the structure of mailbox is fundamentally different
// between simple POP and better IMAP. IMAP has folders like
// inbox under the service entry so we must the pick different
// nesting level with IMAP than with POP.
// --------------------------------------------------------------
//
void CInternetEmailEngine::SetProtocolL( const TInt aType )
{
iProtocolType=aType;
iProtocolUid=(iProtocolType==EProtocolPop3)?KUidMsgTypePOP3:KUidMsgTypeIMAP4;
iIsProtocolSet=ETrue;
iState=EReady;
iId=FindServiceL(iProtocolUid);
LoadMtmL();
if( iProtocolType!=EProtocolPop3) //Note IMAP has folders!
{
TRAPD( err, iId=FindFolderThenServiceL(iProtocolUid));
if( err != KErrNone )
{
//now we know we have fresh imap service without any folders
return;
}
}
UpdateRemoteCountL(); //we draw the message entries if any
}
// --------------------------------------------------------------
// TMsvId CInternetEmailEngine::FindServiceL(TUid aType)
// find the message id of a service given a UID
// this function will return the first service id for given type
// --------------------------------------------------------------
//
TMsvId CInternetEmailEngine::FindServiceL(TUid aType)
{
// select the root index to start the search
CMsvEntry* currentEntry = iMsvSession->GetEntryL(KMsvRootIndexEntryId);
CleanupStack::PushL(currentEntry);
// don't sort the entries
currentEntry->SetSortTypeL(TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone, ETrue));
TMsvId rc = KMsvRootIndexEntryId;
TInt count=currentEntry->Count();
// loop for every child entry of the root index
for(TInt i = 0;i<count;i++)
{
const TMsvEntry& child = (*currentEntry)[i];
// is the current child the same type as the type we are looking for ?
if (child.iMtm == aType)
{
rc=child.Id();
break;
}
}//for
CleanupStack::PopAndDestroy(currentEntry);
// return the service id of the type if found.
// otherwise return the root index
return rc;
}
// ---------------------------------------------------------------
// TMsvId CInternetEmailEngine::FindFolderThenServiceL(TUid aType)
// this function will return the first folder of first
// service of given type or if it doesnt exist then
// this function will leave with KErrNotFound as most of
// the usage sitations couldnt handle mailbox instead of
// folder.
// ----------------------------------------------------------------
//
TMsvId CInternetEmailEngine::FindFolderThenServiceL(TUid aType)
{
// select the root index to start the search
CMsvEntry* currentEntry = iMsvSession->GetEntryL(KMsvRootIndexEntryId);
CleanupStack::PushL(currentEntry);
// don't sort the entries
currentEntry->SetSortTypeL(TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone, ETrue));
TMsvId rc = KMsvRootIndexEntryId;
TInt count=currentEntry->Count();
// loop for every child entry of the root index
for(TInt i = 0;i<count;i++)
{
const TMsvEntry& child = (*currentEntry)[i];
// is the current child the same type as the type we are looking for ?
if (child.iMtm == aType)
{
// selects first entry as index entry
CMsvEntry* firstEntry = iMsvSession->GetEntryL(child.Id());
CleanupStack::PushL(firstEntry);
TInt innercount=firstEntry->Count();
if( innercount )
{ //if has childs == folders take first
const TMsvEntry& folder = (*firstEntry)[0];
rc=folder.Id();
iHasImapInbox=ETrue;
}
else
{
iHasImapInbox=EFalse;
}
CleanupStack::PopAndDestroy(firstEntry);
break;
}
}//for
CleanupStack::PopAndDestroy(currentEntry);
if( !iHasImapInbox )
{
User::Leave( KErrNotFound );
}
// return the service id of the type if found.
return rc;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -