/**
  Function 		: MoveAsyncImap4CommandL
  Description 	: This function retrieves the download limits set
  @param 		: aCommand			The Imap command to be executed.
			 	  aImapServiceId	The Imap service Id
				  aMailSelection	The selection object
				  aDownloadLimits	The download limts set.		
  @return 		: none
*/
void CT_MsgImapMoveAsyncFunction::MoveAsyncImap4CommandL( TImap4Cmds aCommand,
										    CMsvEntrySelection& aMailSelection, TMsvId aImapServiceId , TBool aDownloadLimits, TMsvId afolderId)
	{
	
	// Loads the Imap account settings and saves the download limits
	CEmailAccounts* emailAccounts = CEmailAccounts::NewLC();	
	CImImap4Settings* imapSettings =  new(ELeave) CImImap4Settings();
	CleanupStack::PushL(imapSettings);

	TImapAccount imapAccount;
	emailAccounts->GetImapAccountL(aImapServiceId, imapAccount);
	emailAccounts->LoadImapSettingsL(imapAccount, *imapSettings);


	// If full download limts are set load it onto the the account
	CT_MsgActive&	active=Active();
	if(aDownloadLimits)
		{
		TImImap4GetMailInfo imapFullinfo;
		imapFullinfo.iDestinationFolder = afolderId;
		imapFullinfo.iGetMailBodyParts = imapSettings->GetMailOptions();
		imapFullinfo.iMaxEmailSize = imapSettings->MaxEmailSize();
	
		// Package of the download limits
		TPckgBuf<TImImap4GetMailInfo> fullPack(imapFullinfo);

		iSharedDataIMAP.iMtm->SwitchCurrentEntryL(aImapServiceId);
		// Moves asynchronous IMAP4-specific operation 
		iOperation = iSharedDataIMAP.iMtm->InvokeAsyncFunctionL(aCommand,aMailSelection, fullPack, active.iStatus);	
		}
	// If partial download limts are set load it onto the the account 
	else 
		{
		TImImap4GetPartialMailInfo imapPartialinfo;
		imapPartialinfo.iAttachmentSizeLimit = imapSettings->AttachmentSizeLimit();
		imapPartialinfo.iBodyTextSizeLimit = imapSettings->BodyTextSizeLimit();
		imapPartialinfo.iDestinationFolder = afolderId;
		imapPartialinfo.iPartialMailOptions = imapSettings->PartialMailOptions();
		imapPartialinfo.iTotalSizeLimit = imapSettings->MaxEmailSize();
	
		// Package of the download limits 
		TPckgBuf<TImImap4GetPartialMailInfo> partialPack(imapPartialinfo);
		
		// Switches the cuurent context on to the IMAP service ID 
		iSharedDataIMAP.iMtm->SwitchCurrentEntryL(aImapServiceId);
		
		// Moves asynchronous IMAP4-specific operation
		iOperation = iSharedDataIMAP.iMtm->InvokeAsyncFunctionL(aCommand,aMailSelection, partialPack, active.iStatus);
		}

	active.Activate();
	CActiveScheduler::Start();
	User::LeaveIfError(active.Result());

	CleanupStack::PopAndDestroy(2,emailAccounts); // imapSettings,emailAccounts
	}
// <qmail> new functions added
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void CIpsPlgImap4ConnectOp::ConstructImapPartialFetchInfo( 
    TImImap4GetPartialMailInfo& aInfo, 
    const CImImap4Settings& aImap4Settings )
    {
    FUNC_LOG;
    TInt sizeLimit = aImap4Settings.BodyTextSizeLimit();
    
    if ( sizeLimit == KIpsSetDataHeadersOnly )
        {
        aInfo.iTotalSizeLimit = KIpsSetDataHeadersOnly;
        }
    else if ( sizeLimit == KIpsSetDataFullBodyAndAttas )
        {        
        aInfo.iTotalSizeLimit = KMaxTInt;
        aInfo.iAttachmentSizeLimit = KMaxTInt;
        aInfo.iBodyTextSizeLimit = KMaxTInt;
        aInfo.iMaxEmailSize = KMaxTInt;
        aInfo.iPartialMailOptions = ENoSizeLimits;
        aInfo.iGetMailBodyParts = EGetImap4EmailBodyTextAndAttachments;
        }
    else if ( sizeLimit == KIpsSetDataFullBodyOnly )
        {
        aInfo.iTotalSizeLimit = KMaxTInt; 
        aInfo.iAttachmentSizeLimit = 0;
        aInfo.iBodyTextSizeLimit = KMaxTInt;
        aInfo.iMaxEmailSize = KMaxTInt;
        aInfo.iPartialMailOptions = EBodyAlternativeText;
        aInfo.iGetMailBodyParts = EGetImap4EmailBodyAlternativeText;
        }
    else
        {
    //<qmail> include html in body
        aInfo.iTotalSizeLimit = sizeLimit*1024; 
        aInfo.iAttachmentSizeLimit = 0;
        aInfo.iMaxEmailSize = sizeLimit*1024;
        aInfo.iBodyTextSizeLimit = sizeLimit*1024;
        aInfo.iPartialMailOptions = EBodyAlternativeText;
        aInfo.iGetMailBodyParts = EGetImap4EmailBodyAlternativeText;
    // </qmail>    
        }
    }