/**
CountLinesOfBodyTextL()
Counts the lines of body text in the email aEntry

@param aEntry
A reference to an object representing the email

@param aFooterExists
Reference to a boolean variable - set to ETrue if the footer string is found in the body text

@param aFooterSize
Expected KB left on server inserted into footer string if present 

@return
Number of lines in the body text 
*/
TInt CT_MsgComparePopEmailMsgs::CountLinesOfBodyTextL(CMsvEntry& aEntry, TBool& aFooterExists, TInt& aFooterSize)
	{
	TInt lines = 0;
	aFooterExists=EFalse;
	aFooterSize=0;
	aEntry.SetEntryL(aEntry.EntryId());
	if(aEntry.HasStoreL())
		{
		CMsvStore*	msvStore1= aEntry.ReadStoreL();
		CleanupStack::PushL(msvStore1);
		CParaFormatLayer*	paraFormatLayer1 = CParaFormatLayer::NewL();
		CleanupStack::PushL(paraFormatLayer1);
		CCharFormatLayer*	charFormatLayer1 = CCharFormatLayer::NewL(); 
		CleanupStack::PushL(charFormatLayer1);
		CRichText*	bodyText1=CRichText::NewL(paraFormatLayer1, charFormatLayer1, CEditableText::EFlatStorage, 256);
		CleanupStack::PushL(bodyText1);

		bodyText1->Reset();
		if (msvStore1->HasBodyTextL())
			{
			msvStore1->RestoreBodyTextL(*bodyText1);
			TUint16 val = CEditableText::ELineBreak;
			TInt n = 0;
			TInt pos = 0;
			for(;;)
				{
				TPtrC bodyText = bodyText1->Read(pos);
				n = bodyText.Find(&val, 1);
				if(n < 0)
					break;
				lines++;
				pos += n+1;
				
				//This Check is needed to delete the extra line introduced by communigate Pro Server
				TInt fpos = CheckIfServerMessageExists(bodyText);
				if (fpos != KErrNotFound)
					{
					lines--;
					}
				}
			TPtrC	pBt = bodyText1->Read(0);
			aFooterExists = CheckIfFooterMessageExistsL(pBt , aFooterSize);
			}		
		CleanupStack::PopAndDestroy(4, msvStore1);  //bodyText1,charFormatLayer1,paraFormatLayer1,msvStore1.
		}
	return lines;
	}
/**
CountLinesOfBodyTextL()
Counts the lines of body text in the email aEntry

@param aEntry
A reference to an object representing the email

@param aFooterExists
Reference to a boolean variable - set to ETrue if the footer string is found in the body text

@param aFooterSize
Expected KB left on server inserted into footer string if present 

@return
Number of lines in the body text 
*/
TInt CT_MsgComparePopEmailMsgs::CountLinesOfBodyTextL(CMsvEntry& aEntry, TBool& aFooterExists, TInt& aFooterSize)
	{
	TInt lines = 0;
	TInt count =0;
	aFooterExists=EFalse;
	aFooterSize=0;
	aEntry.SetEntryL(aEntry.EntryId());
	if(aEntry.HasStoreL())
		{
		CMsvStore*	msvStore1= aEntry.ReadStoreL();
		CleanupStack::PushL(msvStore1);
		CParaFormatLayer*	paraFormatLayer1 = CParaFormatLayer::NewL();
		CleanupStack::PushL(paraFormatLayer1);
		CCharFormatLayer*	charFormatLayer1 = CCharFormatLayer::NewL(); 
		CleanupStack::PushL(charFormatLayer1);
		CRichText*	bodyText1=CRichText::NewL(paraFormatLayer1, charFormatLayer1, CEditableText::EFlatStorage, 256);
		CleanupStack::PushL(bodyText1);

		bodyText1->Reset();
		if (msvStore1->HasBodyTextL())
			{
			msvStore1->RestoreBodyTextL(*bodyText1);
			TUint16 val = CEditableText::ELineBreak;
			TUint16 val1 = CEditableText::EParagraphDelimiter;
			TUint16 val2 = KUnicodeValue;
			
			TInt n = 0;
			TInt pos = 0;
			for(;;)
				{
				TPtrC bodyText = bodyText1->Read(pos);
				n = bodyText.Find(&val, 1);
								
				// if iStore8BitData flag is set, the line is terminated by "CEditableText::EParagraphDelimiter"			
				if(msvStore1->IsPresentL(KMsvPlainBodyText8))
					{
					if ( 0 == count )
						{
						TPtrC buffer = bodyText.Mid(0,n+2);
						// eg for 8bit the body look as : This is a simple email message.\x2028\x2029\x2029
						// eg for 16bit the body look as: This is a simple email message.\x2028\x2028\x2029
						if((bodyText.Right(2).Compare(KParagraphDelimiter)==KErrNone) && \
									 buffer.Find(&val2,1) != 75)
							{
							lines++;	
							count++;
							}				
							// Increment the line if EParagraphDelimiter or 0x0046 is found sequence as eg:1. \x2028\x2029
							// 2. \x2028\x2029\x2028\x2029\x0046 3. \x2028\x2029\x2028\x2029\x2028\x2029
						else if ( (buffer.Find(&val1,1)==0 && n==-1) || (buffer.Find(&val2,1)==1) \
										|| (buffer.Find(&val1,1)>0) )
							{
							lines++;		
							}
						}
					}
				if(n < 0)
					break;
				lines++;
				pos += n+1;
								
				//This Check is needed to delete the extra line introduced by communigate Pro Server
				TInt fpos = CheckIfServerMessageExists(bodyText);
				if (fpos != KErrNotFound)
					{
					lines--;
					}
				}
			TPtrC	pBt = bodyText1->Read(0);
			aFooterExists = CheckIfFooterMessageExistsL(pBt , aFooterSize);
			}		
		CleanupStack::PopAndDestroy(4, msvStore1);  //bodyText1,charFormatLayer1,paraFormatLayer1,msvStore1.
		}
	return lines;
	}