email/pop3andsmtpmtm/imapservermtm/test/src/T_LOG.cpp
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <f32fsys.h>
       
    18 #include <s32file.h>
       
    19 #include <e32base.h>
       
    20 #include <txtetext.h>
       
    21 #include <txtrich.h>
       
    22 #include <bautils.h>
       
    23 #include <miuthdr.h>
       
    24 #include <miutmsg.h>
       
    25 #include <miutset.h>  //KUidMsgTypePOP3
       
    26 #include <imutdll.h>	
       
    27 #include <imcvtext.h>
       
    28 #include <imcvrecv.h>
       
    29 #include <imcvsend.h>
       
    30 
       
    31 #include <imapset.h>
       
    32 
       
    33 //Oyster includes
       
    34 #include <msvstd.h>
       
    35 #include <msvids.h>
       
    36 #include <msvuids.h>
       
    37 #include <msvruids.h>
       
    38 #include <msvreg.h>
       
    39 
       
    40 #include <msventry.h> 
       
    41 #include <msvapi.h>
       
    42 #include <mtclbase.h>
       
    43 #include <cemailaccounts.h>
       
    44 #include <pop3set.h>
       
    45 
       
    46 #include <offop.h>
       
    47 
       
    48 #include "t_log.h"
       
    49 
       
    50 //----------------------------------------------------------------------------------------
       
    51 
       
    52 _LIT( KFileNameCombined, "Entry_All.txt");
       
    53 
       
    54 _LIT( KFileNameBody, "Entry_Bodys.txt");
       
    55 _LIT( KFileNameHeader, "Entry_Header.txt");
       
    56 _LIT( KFileNameMimeHeader, "Entry_MimeHeader.txt");
       
    57 _LIT( KFileNameSettings, "Entry_Settings.txt");
       
    58 
       
    59 _LIT( KFileNameEntryStruct, "Entry_Zac.txt");
       
    60 
       
    61 //----------------------------------------------------------------------------------------
       
    62 
       
    63 _LIT(KPerCentS, "%S");
       
    64 _LIT(KCRLF, "\r\n");
       
    65 
       
    66 
       
    67 //----------------------------------------------------------------------------------------
       
    68 
       
    69 // nicked from IMCM::OFFOP.CPP
       
    70 
       
    71 LOCAL_D const TUid KUidImQueuedOperationList = {0x10001794};	// 2648441492 dec.
       
    72 
       
    73 //----------------------------------------------------------------------------------------
       
    74 // Handy conversion routines between 8 and 16bit worlds
       
    75 
       
    76 #define Ptr8From16( aText ) TPtrC8( (const TUint8 *)(aText).Ptr(), (aText).Size() )
       
    77 #define Ptr16From8( aText ) TPtrC16( (const TUint16 *)(aText).Ptr(), (aText).Size()/2 )
       
    78 
       
    79 LOCAL_C HBufC16* HBuf16From8LC( const TDesC8& aText )
       
    80 	{
       
    81 	HBufC16* pOutputLine = HBufC16::NewLC( aText.Length() );
       
    82 	TPtr16 pOutput = pOutputLine->Des();
       
    83 	pOutput.Zero();
       
    84 
       
    85 	TUint8 theChar;
       
    86 	TInt i=0;
       
    87 	
       
    88 	while(i<aText.Length())
       
    89 		{
       
    90 		theChar=aText[i++];
       
    91 		pOutput.Append( (TUint16)theChar );
       
    92 		}
       
    93 
       
    94 	return pOutputLine;
       
    95 	}
       
    96 
       
    97 // Note this function will lose data if fed text other than ISO-8859-1
       
    98 LOCAL_C HBufC8* HBuf8From16LC( const TDesC16& aText )
       
    99 	{
       
   100 	HBufC8* pOutputLine = HBufC8::NewLC( aText.Length() );
       
   101 	TPtr8 pOutput = pOutputLine->Des();
       
   102 	pOutput.Zero();
       
   103 
       
   104 	TUint16 theChar;
       
   105 	TInt i=0;
       
   106 	
       
   107 	while(i<aText.Length())
       
   108 		{
       
   109 		theChar=aText[i++];
       
   110 		pOutput.Append( (TUint8)theChar );
       
   111 		}
       
   112 
       
   113 	return pOutputLine;
       
   114 	}
       
   115 
       
   116 //----------------------------------------------------------------------------------------
       
   117 
       
   118 class COutputterOverflow: public TDes16Overflow
       
   119 	{
       
   120 public:
       
   121 	COutputterOverflow( COutputter* aPutter );
       
   122 	void Overflow(TDes16& aDes);
       
   123 private:
       
   124 	COutputter* iPutter;
       
   125 	};
       
   126 
       
   127 //----------------------------------------------------------------------------------------
       
   128 //----------------------------------------------------------------------------------------
       
   129 
       
   130 COutputterOverflow::COutputterOverflow( COutputter* aPutter )
       
   131 	{
       
   132 	iPutter = aPutter;
       
   133 	}
       
   134 
       
   135 void COutputterOverflow::Overflow(TDes16 &aDes)
       
   136 	{
       
   137 	TRAPD(ret,iPutter->PrintL( _L("\r\n\r\n\r\n") ));
       
   138 	TRAP(ret,iPutter->PrintL( _L("Overflow when outputting data")));
       
   139 	TRAP(ret,iPutter->PrintL( aDes ));
       
   140 	TRAP(ret,iPutter->PrintL( _L("\r\n\r\n\r\n")));
       
   141 	}
       
   142 
       
   143 //----------------------------------------------------------------------------------------
       
   144 
       
   145 COutputter* COutputter::NewL(RTest* aTest)
       
   146 	{
       
   147 	COutputter* putter = new (ELeave) COutputter;
       
   148 	CleanupStack::PushL(putter);
       
   149 
       
   150 	putter->iTest = aTest;
       
   151 	putter->iUseFiles = ETrue;
       
   152 	putter->ConstructL();
       
   153 
       
   154 	CleanupStack::Pop();
       
   155 	return putter;
       
   156 	}
       
   157 
       
   158 void COutputter::ConstructL()
       
   159 	{
       
   160 	iOverflow = new(ELeave) COutputterOverflow( this );
       
   161 	iPrefix.FillZ();
       
   162 	}
       
   163 
       
   164 COutputter::~COutputter()
       
   165 	{
       
   166 	while ( iFilesOpen > 0 )
       
   167 		UnSetFile();
       
   168 
       
   169 	delete iOverflow;
       
   170 	}
       
   171 
       
   172 void COutputter::SetRFs(RFs* aFs)
       
   173 	{
       
   174 	iFs = aFs;
       
   175 	}
       
   176 
       
   177 void COutputter::UnSetFile()
       
   178 	{
       
   179 	if ( iFilesOpen > 0 )
       
   180 		iFile[--iFilesOpen].Close();
       
   181 	}
       
   182 
       
   183 void COutputter::SetFilePrefix( TUint aNum )
       
   184 	{
       
   185 	iPrefix.Format( _L("%08x_"), aNum);
       
   186 	}
       
   187 
       
   188 void COutputter::SetFileL( const TDesC& aLeafName, TBool aUnicode )
       
   189 	{
       
   190 	if ( iUseFiles )
       
   191 		{
       
   192 		if (iFilesOpen >= 4)
       
   193 			iTest->Panic( _L("Too many open files") );
       
   194 
       
   195 		RFile& file = iFile[iFilesOpen++];
       
   196 
       
   197 		TFileName name = iPrefix;
       
   198 		name += aLeafName;
       
   199 		
       
   200 		TInt err = file.Open( *iFs, name, EFileShareAny | EFileStreamText | EFileWrite);
       
   201 		if (err == KErrNotFound) // file does not exist - create it
       
   202 			err = file.Create( *iFs, name, EFileShareAny | EFileStreamText | EFileWrite);
       
   203 		User::LeaveIfError(err);
       
   204 
       
   205 		// not sure what this is for - but it was in originally
       
   206 		TInt offset=0;
       
   207 		(*iTest)(file.Seek(ESeekEnd, offset)==KErrNone);
       
   208 
       
   209 		iUnicode=aUnicode;
       
   210 		}
       
   211 	iPrefix.FillZ();
       
   212 	}
       
   213 
       
   214 void COutputter::PrintL( const TDesC8& aText ) // should be L
       
   215  	{
       
   216 	if ( iFilesOpen > 0 )
       
   217 		{
       
   218 		if (iUnicode)
       
   219 			{
       
   220 			HBufC16 *buf = HBuf16From8LC( aText );
       
   221 			iFile[iFilesOpen-1].Write( Ptr8From16(*buf) );
       
   222 			CleanupStack::PopAndDestroy(); // buf
       
   223 			}
       
   224 		else
       
   225 			iFile[iFilesOpen-1].Write( aText );
       
   226 		}
       
   227 	else
       
   228 		{
       
   229 #if _UNICODE
       
   230 		HBufC16 *buf = HBuf16From8LC( aText );
       
   231 		PrintL( *buf );
       
   232 		CleanupStack::PopAndDestroy(); // buf
       
   233 #else
       
   234 		TInt len = aText.Length();
       
   235 		for ( TInt pos = 0; pos < len; pos += 256 )
       
   236 			{
       
   237 			TPtrC ptr = aText.Mid( pos, len-pos<256?len-pos:256 );
       
   238 			iTest->Printf( KPerCentS, &ptr );
       
   239 			}
       
   240 #endif
       
   241 		}
       
   242 	}
       
   243 
       
   244 void COutputter::PrintL( const TDesC16& aText ) // should be L
       
   245 	{
       
   246 	if ( iFilesOpen > 0 )
       
   247 		{
       
   248 		if (iUnicode)
       
   249 			iFile[iFilesOpen-1].Write( Ptr8From16( aText ) );
       
   250 		else
       
   251 			{
       
   252 			HBufC8 *buf = HBuf8From16LC( aText );
       
   253 			iFile[iFilesOpen-1].Write( *buf );
       
   254 			CleanupStack::PopAndDestroy(); // buf
       
   255 			}
       
   256 		}
       
   257 	else
       
   258 		{
       
   259 #if _UNICODE
       
   260 		// write data in chunks to ensure no overrun of underlying
       
   261 		// Printf function
       
   262 		TInt len = aText.Length();
       
   263 		for ( TInt pos = 0; pos < len; pos += 256 )
       
   264 			{
       
   265 			TPtrC ptr = aText.Mid( pos, len-pos<256?len-pos:256 );
       
   266 			iTest->Printf( KPerCentS, &ptr );
       
   267 			}
       
   268 #else
       
   269 		HBufC8 *buf = HBuf8From16LC( aText );
       
   270 		PrintL( *buf );
       
   271 		CleanupStack::PopAndDestroy(); // buf
       
   272 #endif
       
   273 		}
       
   274 	}
       
   275 
       
   276 void COutputter::Printf( TRefByValue<const TDesC> aFmt, ... )
       
   277 	{
       
   278 	TBuf<1024> buf;
       
   279 
       
   280 	VA_LIST list;
       
   281 	VA_START( list, aFmt );
       
   282 	buf.AppendFormatList( aFmt, list, iOverflow );
       
   283 	VA_END( list );
       
   284 	
       
   285 	TRAP_IGNORE(PrintL( buf ));
       
   286 	}
       
   287 
       
   288 void COutputter::PrintIfNotNullL( const TDesC& aLabel, const TDesC8& aValue )
       
   289 	{
       
   290 	if ( aValue.Length() )
       
   291 		{
       
   292 		PrintL( aLabel );
       
   293 		PrintL( aValue );
       
   294 		PrintL( KCRLF );
       
   295 		}	
       
   296 	}
       
   297 
       
   298 void COutputter::PrintIfNotNullL( const TDesC& aLabel, const TDesC16& aValue )
       
   299 	{
       
   300 	if ( aValue.Length() )
       
   301 		{
       
   302 		PrintL( aLabel );
       
   303 		PrintL( aValue );
       
   304 		PrintL( KCRLF );
       
   305 		}	
       
   306 	}
       
   307 
       
   308 void COutputter::PrintListL( const TDesC& aLabel, CDesC8Array& aList )
       
   309 	{
       
   310 	for(TInt i=0; i < aList.Count(); i++)
       
   311 		{
       
   312 		PrintL(aLabel);
       
   313 		PrintL(aList[i]);
       
   314 		PrintL(KCRLF);
       
   315 		}
       
   316 	}
       
   317 
       
   318 void COutputter::PrintListL( const TDesC& aLabel, CDesC16Array& aList )
       
   319 	{
       
   320 	for(TInt i=0; i < aList.Count(); i++)
       
   321 		{
       
   322 		PrintL(aLabel);
       
   323 		PrintL(aList[i]);
       
   324 		PrintL(KCRLF);
       
   325 		}
       
   326 	}
       
   327 
       
   328 void COutputter::PrintDataL( const TDesC8& aData )
       
   329 	{
       
   330 	TInt i;
       
   331 	for(i=0; i < aData.Length(); i++)
       
   332 		{
       
   333 		Printf(_L("%02x "), aData[i]);
       
   334 		if ((i&7)==7)
       
   335 			PrintL(KCRLF);
       
   336 		}
       
   337 	if ((i&7)!=0)
       
   338 		PrintL(KCRLF);
       
   339 	}
       
   340 
       
   341 void CMsgOutputter::RemoveRichtextFormatting(TDes& aSourceLine)
       
   342 	{
       
   343 	TUint16* ptr = (TUint16*)aSourceLine.Ptr();
       
   344 	TUint16* start = ptr;
       
   345 
       
   346 	TInt totalLength = aSourceLine.Length();
       
   347 	do {
       
   348 		if(*ptr==CEditableText::EParagraphDelimiter || *ptr==CEditableText::ELineBreak || *ptr==CEditableText::EPageBreak)
       
   349 			*ptr=0x0A;
       
   350 		} while((++ptr-start)<totalLength);
       
   351 	}
       
   352 
       
   353 //----------------------------------------------------------------------------------------
       
   354 void CMsgOutputter::BodyDataL( CMsvStore& aFileStore )
       
   355 //----------------------------------------------------------------------------------------
       
   356 	{
       
   357 	CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
       
   358 	CleanupStack::PushL(paraLayer);
       
   359 
       
   360 	CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
       
   361 	CleanupStack::PushL(charLayer);
       
   362 
       
   363 	CRichText* body = CRichText::NewL(paraLayer,charLayer);
       
   364 	CleanupStack::PushL(body);
       
   365 
       
   366 	aFileStore.RestoreBodyTextL(*body);
       
   367 
       
   368 	HBufC* pBodyText = HBufC::NewLC(body->DocumentLength()+(body->DocumentLength()/70)+1);
       
   369 
       
   370 	if ( iParts==EToMultipleFiles )
       
   371 		iPutter->SetFileL( KFileNameBody );
       
   372 	iPutter->Printf( _L("*** %08x *************** RichText Data ***************\r\n"), iMsgId);
       
   373 	iPutter->Printf( _L("Size >>> %d\r\n"), body->DocumentLength());
       
   374 	
       
   375 	TPtr pBody = pBodyText->Des();
       
   376 	body->Extract(pBody, 0);
       
   377 	RemoveRichtextFormatting(pBody);
       
   378 	iPutter->PrintL( pBody );
       
   379 	
       
   380 	iPutter->PrintL(_L("\r\n********************* end of Body ***********************\r\n"));
       
   381 	
       
   382 	CleanupStack::PopAndDestroy(4); // pBodyText, paraLayer, charLayer, body
       
   383 
       
   384 	if ( iParts==EToMultipleFiles )
       
   385 		iPutter->UnSetFile();
       
   386 	}
       
   387 
       
   388 
       
   389 //----------------------------------------------------------------------------------------
       
   390 void CMsgOutputter::MimeHeaderL( CMsvStore& aFileStore )
       
   391 //----------------------------------------------------------------------------------------
       
   392 	{
       
   393 	if ( iParts==EToMultipleFiles )
       
   394 		iPutter->SetFileL( KFileNameMimeHeader );
       
   395 
       
   396 	iPutter->Printf(_L("*** %08x ************* Mime Header ******************\r\n"), iMsgId);
       
   397 
       
   398 	CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
   399 	mimeHeader->RestoreL(aFileStore);
       
   400 	
       
   401 	iPutter->Printf(_L("Version: %d\r\n"),mimeHeader->Version());
       
   402 
       
   403 	iPutter->PrintIfNotNullL( _L("Content-Type: "), mimeHeader->ContentType() );
       
   404 	iPutter->PrintIfNotNullL( _L("Content-Type,SubType: "), mimeHeader->ContentSubType() );
       
   405 	iPutter->PrintIfNotNullL( _L("Content-Disposition: "), mimeHeader->ContentDisposition() );
       
   406 	iPutter->PrintIfNotNullL( _L("Content-Description: "), mimeHeader->ContentDescription() );
       
   407 	iPutter->PrintIfNotNullL( _L("Content-Base: "), mimeHeader->ContentBase() );
       
   408 	iPutter->PrintIfNotNullL( _L("Content-ID: "), mimeHeader->ContentID() );
       
   409 	iPutter->PrintIfNotNullL( _L("Content-Location: "), mimeHeader->ContentLocation() );
       
   410 
       
   411 	if ( mimeHeader->ContentTransferEncoding() )
       
   412 		iPutter->Printf( _L("Content-Transfer-Encoding: %d\r\n"), mimeHeader->ContentTransferEncoding() );
       
   413 
       
   414 	iPutter->PrintListL( _L("ContentTypeParams: "), mimeHeader->ContentTypeParams() );
       
   415 	iPutter->PrintListL( _L("ContentDispositionParams: "), mimeHeader->ContentDispositionParams() );
       
   416 
       
   417 	iPutter->PrintL(_L("******************** end of MIME Header ****************\r\n"));
       
   418 	if ( iParts==EToMultipleFiles )
       
   419 		iPutter->UnSetFile();
       
   420 
       
   421 	CleanupStack::PopAndDestroy(); // mimeHeader
       
   422 	}
       
   423 
       
   424 //----------------------------------------------------------------------------------------
       
   425 void CMsgOutputter::HeaderL( CMsvStore& aFileStore )
       
   426 //----------------------------------------------------------------------------------------
       
   427 	{
       
   428 	if ( iParts==EToMultipleFiles )
       
   429 		iPutter->SetFileL( KFileNameHeader );
       
   430 	iPutter->Printf( _L("*** %08x ************* Rfc822 Header ****************\r\n"), iMsgId);
       
   431 
       
   432 	CImHeader* header = CImHeader::NewLC();
       
   433 	
       
   434 	TUint emptySize = header->DataSize();
       
   435 	header->RestoreL(aFileStore);
       
   436 
       
   437 	TUint size = header->DataSize()-emptySize;
       
   438 
       
   439 	iPutter->Printf(_L("Size >>> %d\r\n"), size);
       
   440 	iPutter->PrintIfNotNullL(_L("Subject: "), header->Subject());
       
   441 	iPutter->PrintIfNotNullL(_L("ID: "), header->ImMsgId());
       
   442 	iPutter->PrintIfNotNullL(_L("From: "), header->From());
       
   443 	iPutter->PrintIfNotNullL(_L("Reply-To: "), header->ReplyTo());
       
   444 	iPutter->PrintIfNotNullL(_L("Return-Receipt-To: "), header->ReceiptAddress());
       
   445 
       
   446 	iPutter->PrintListL(_L("To: "), header->ToRecipients());
       
   447 	iPutter->PrintListL(_L("Cc: "), header->CcRecipients());
       
   448 	iPutter->PrintListL(_L("Bcc: "), header->BccRecipients());
       
   449 	
       
   450 	iPutter->PrintL(_L("******************** end of RFC822 header **************\r\n"));
       
   451 
       
   452 	if ( iParts==EToMultipleFiles )
       
   453 		iPutter->UnSetFile();
       
   454 	CleanupStack::PopAndDestroy(); // header
       
   455 	}
       
   456 
       
   457 TPtrC CMsgOutputter::SyncTypeString( TFolderSyncType aType )
       
   458 	{
       
   459 	switch (aType)
       
   460 		{
       
   461 	case EUseCombination:
       
   462 		return _L("UseCombination");
       
   463 		
       
   464 	case EUseLocal:
       
   465 		return _L("UseLocal");
       
   466 
       
   467 	case EUseRemote:
       
   468 		return _L("UseRemote");
       
   469 		}
       
   470 	return _L("");
       
   471 	}
       
   472 
       
   473 TPtrC CMsgOutputter::SubscribeTypeString( TFolderSubscribeType aType )
       
   474 	{
       
   475 	switch (aType)
       
   476 		{
       
   477 	case EUpdateNeither:
       
   478 		return _L("UpdateNeither");
       
   479 		
       
   480 	case EUpdateLocal:
       
   481 		return _L("UpdateLocal");
       
   482 
       
   483 	case EUpdateRemote:
       
   484 		return _L("UpdateRemote");
       
   485 
       
   486 	case EUpdateBoth:
       
   487 		return _L("UpdateBoth");
       
   488 		}
       
   489 	return _L("");
       
   490 	}
       
   491 
       
   492 TPtrC CMsgOutputter::GetMailOptionsString( TImap4GetMailOptions aOpts )
       
   493 	{
       
   494 	switch (aOpts)
       
   495 		{
       
   496 	case EGetImap4EmailHeaders:
       
   497 		return _L("GetImap4EmailHeaders");
       
   498 	case EGetImap4EmailBodyText:
       
   499 		return _L("GetImap4EmailBodyText");
       
   500 	case EGetImap4EmailBodyTextAndAttachments:
       
   501 		return _L("GetImap4EmailBodyTextAndAttachments");
       
   502 	case EGetImap4EmailAttachments:
       
   503 		return _L("GetImap4EmailAttachments");
       
   504 		}
       
   505 	return _L("");
       
   506 	}
       
   507 
       
   508 //----------------------------------------------------------------------------------------
       
   509 void CMsgOutputter::Imap4SettingsL(const TMsvEntry& aEntry)
       
   510 //----------------------------------------------------------------------------------------
       
   511 	{
       
   512 	if ( iParts==EToMultipleFiles )
       
   513 		iPutter->SetFileL( KFileNameSettings );
       
   514 	iPutter->Printf(_L("*** %08x ************* Settings ****************\r\n"), iMsgId);
       
   515 
       
   516 	CImImap4Settings* settings = new (ELeave)CImImap4Settings();
       
   517 	CleanupStack::PushL(settings);
       
   518 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   519 	
       
   520 	TImapAccount imapAccountId;
       
   521 	accounts->GetImapAccountL(aEntry.Id(), imapAccountId);
       
   522 	accounts->LoadImapSettingsL(imapAccountId, *settings);
       
   523 	CleanupStack::PopAndDestroy(accounts);
       
   524 
       
   525 	iPutter->Printf(         _L("IAP index:                     %u\r\n"), iEntry->Entry().MtmData1());
       
   526 	iPutter->PrintIfNotNullL( _L("LoginName:                     "), settings->LoginName());
       
   527 	iPutter->PrintIfNotNullL( _L("Password:                      "), settings->Password());
       
   528 	iPutter->PrintIfNotNullL( _L("FolderPath:                    "), settings->FolderPath());
       
   529 	iPutter->Printf(         _L("PathSeparator:                 %c\r\n"), settings->PathSeparator());
       
   530 	iPutter->Printf(         _L("DisconnectedUserMode:          %u\r\n"), settings->DisconnectedUserMode()?1:0);
       
   531 	iPutter->PrintIfNotNullL( _L("Synchronise:                   "), SyncTypeString(settings->Synchronise()));
       
   532 	iPutter->PrintIfNotNullL( _L("Subscribe:                     "), SubscribeTypeString(settings->Subscribe()));
       
   533 	iPutter->Printf(         _L("AutoSendOnConnect:             %u\r\n"), settings->AutoSendOnConnect()?1:0);
       
   534 	iPutter->Printf(         _L("MaxEmailSize:                  %u\r\n"), settings->MaxEmailSize());
       
   535 	iPutter->Printf(         _L("DeleteEmailsWhenDisconnecting: %u\r\n"), settings->DeleteEmailsWhenDisconnecting()?1:0);
       
   536 	iPutter->Printf(         _L("AcknowledgeReceipts:           %u\r\n"), settings->AcknowledgeReceipts()?1:0);
       
   537 	iPutter->PrintIfNotNullL( _L("GetMailOptions:                "), GetMailOptionsString(settings->GetMailOptions()));
       
   538 
       
   539 	iPutter->PrintIfNotNullL( _L("Server:                        "), settings->ServerAddress());
       
   540 	iPutter->Printf(         _L("Port:                          %u\r\n"), settings->Port());
       
   541 	iPutter->Printf(         _L("Secure:                        %u\r\n"), settings->SecureSockets()?1:0);
       
   542 	
       
   543 	iPutter->PrintL(_L("******************** end of Settings **************\r\n"));
       
   544 	if ( iParts==EToMultipleFiles )
       
   545 		iPutter->UnSetFile();
       
   546 
       
   547 	CleanupStack::PopAndDestroy(); // settings
       
   548 	}
       
   549 
       
   550 
       
   551 //----------------------------------------------------------------------------------------
       
   552 void CMsgOutputter::SettingsL(const TMsvEntry& aEntry)
       
   553 //----------------------------------------------------------------------------------------
       
   554 	{
       
   555 	if ( iParts==EToMultipleFiles )
       
   556 		iPutter->SetFileL( KFileNameSettings );
       
   557 	iPutter->Printf(_L("*** %08x ************* Settings ****************\r\n"), iMsgId);
       
   558 
       
   559 	CImBaseEmailSettings* settings(NULL);
       
   560 	
       
   561 	CEmailAccounts* accounts = CEmailAccounts::NewLC();
       
   562 	
       
   563 	
       
   564 	if (aEntry.iMtm == KUidMsgTypeIMAP4)
       
   565 		{
       
   566 		CImImap4Settings* imap4Settings = new(ELeave) CImImap4Settings;
       
   567 		TImapAccount imapAccountId;
       
   568 		accounts->GetImapAccountL(aEntry.Id(), imapAccountId);
       
   569 		accounts->LoadImapSettingsL(imapAccountId, *imap4Settings);
       
   570 		settings = imap4Settings;
       
   571 		}
       
   572 	else if (aEntry.iMtm == KUidMsgTypePOP3)
       
   573 		{
       
   574 		CImPop3Settings* pop3Settings = new(ELeave) CImPop3Settings;
       
   575 		TPopAccount pop3AccountId;
       
   576 		accounts->GetPopAccountL(aEntry.Id(), pop3AccountId);
       
   577 		accounts->LoadPopSettingsL(pop3AccountId, *pop3Settings);
       
   578 		settings = pop3Settings;
       
   579 		}
       
   580 	else if (aEntry.iMtm == KUidMsgTypeSMTP)
       
   581 		{
       
   582 		CImSmtpSettings* smtpSettings = new(ELeave) CImSmtpSettings;
       
   583 		TSmtpAccount smtpAccountId;
       
   584 		accounts->GetSmtpAccountL(aEntry.Id(), smtpAccountId);
       
   585 		accounts->LoadSmtpSettingsL(smtpAccountId, *smtpSettings);
       
   586 		settings = smtpSettings;
       
   587 		}
       
   588 	else
       
   589 		{
       
   590 		User::Leave(KErrNotFound);
       
   591 		}
       
   592 
       
   593 	iPutter->Printf(         _L("IAP index: %u\r\n"), iEntry->Entry().MtmData1());
       
   594 	iPutter->PrintIfNotNullL( _L("Server:    "), settings->ServerAddress());
       
   595 	iPutter->Printf(         _L("Port:      %u\r\n"), settings->Port());
       
   596 	iPutter->Printf(         _L("Secure:    %u\r\n"), settings->SecureSockets());
       
   597 	
       
   598 	iPutter->PrintL(_L("******************** end of Settings **************\r\n"));
       
   599 	if ( iParts==EToMultipleFiles )
       
   600 		iPutter->UnSetFile();
       
   601 	
       
   602 	CleanupStack::PopAndDestroy(); // settings
       
   603 
       
   604 	CleanupStack::PopAndDestroy(accounts);
       
   605 	}
       
   606 
       
   607 
       
   608 TPtrC CMsgOutputter::OffLineOpTypeString(CImOffLineOperation::TOffLineOpType op)
       
   609 	{
       
   610 	switch (op)
       
   611 		{
       
   612 	case CImOffLineOperation::EOffLineOpNone:
       
   613 		return _L("None");
       
   614 
       
   615 	case CImOffLineOperation::EOffLineOpCopyToLocal:
       
   616 		return _L("CopyToLocal");
       
   617 	case CImOffLineOperation::EOffLineOpCopyFromLocal:
       
   618 		return _L("CopyFromLocal");
       
   619 	case CImOffLineOperation::EOffLineOpCopyWithinService:
       
   620 		return _L("CopyWithinService");
       
   621 
       
   622 	case CImOffLineOperation::EOffLineOpMoveToLocal:
       
   623 		return _L("MoveToLocal");
       
   624 	case CImOffLineOperation::EOffLineOpMoveFromLocal:
       
   625 		return _L("MoveFromLocal");
       
   626 	case CImOffLineOperation::EOffLineOpMoveWithinService:
       
   627 		return _L("MoveWithinService");
       
   628 
       
   629 	case CImOffLineOperation::EOffLineOpDelete:
       
   630 		return _L("Delete");
       
   631 
       
   632 	case CImOffLineOperation::EOffLineOpChange:
       
   633 		return _L("Change");
       
   634 	case CImOffLineOperation::EOffLineOpCreate:
       
   635 		return _L("Create");
       
   636 
       
   637 	case CImOffLineOperation::EOffLineOpMtmSpecific:
       
   638 		return _L("MtmSpecific");
       
   639 
       
   640 	default:
       
   641 		break;
       
   642 		}
       
   643 	return _L("Unknown");
       
   644 	}
       
   645 
       
   646 //----------------------------------------------------------------------------------------
       
   647 void CMsgOutputter::QueuedOpsL( CMsvStore& aFileStore )
       
   648 //----------------------------------------------------------------------------------------
       
   649 	{
       
   650 	if ( iParts==EToMultipleFiles )
       
   651 		iPutter->SetFileL( KFileNameSettings );
       
   652 	iPutter->Printf(_L("*** %08x ************* Queued operations ****************\r\n"), iMsgId);
       
   653 
       
   654 	CImOffLineOperationArray* ops=CImOffLineOperationArray::NewL();
       
   655 	CleanupStack::PushL(ops);
       
   656 
       
   657 	CImOffLineArrayStore arraystore(*ops);
       
   658 	arraystore.RestoreL(aFileStore);
       
   659 	
       
   660 	for (TInt opNum=0; opNum < ops->CountOperations(); opNum++)
       
   661 		{
       
   662 		const CImOffLineOperation& op = ops->Operation(opNum);
       
   663 		iPutter->PrintL(         _L("------------------\r\n"));
       
   664 		iPutter->Printf(        _L("Operation %d\r\n"), opNum);
       
   665 		iPutter->PrintIfNotNullL(_L("OpType:   "), OffLineOpTypeString(op.OpType()));
       
   666 		iPutter->Printf(        _L("Message:  %08x\r\n"), op.MessageId());
       
   667 		iPutter->Printf(        _L("Target:   %08x\r\n"), op.TargetMessageId());
       
   668 		if (op.OpType() == CImOffLineOperation::EOffLineOpMtmSpecific)
       
   669 			{
       
   670 			iPutter->Printf(        _L("Function: %d\r\n"), op.MtmFunctionId());
       
   671 			iPutter->Printf(        _L("Data:     %d bytes\r\n"), op.MtmParameters().Length());
       
   672 			iPutter->PrintDataL(op.MtmParameters());
       
   673 			}
       
   674 		}
       
   675 	
       
   676 	iPutter->PrintL(_L("******************** end of Queued operations **************\r\n"));
       
   677 	if ( iParts==EToMultipleFiles )
       
   678 		iPutter->UnSetFile();
       
   679 	
       
   680 	CleanupStack::PopAndDestroy(); // ops
       
   681 	}
       
   682 
       
   683 
       
   684 //----------------------------------------------------------------------------------------
       
   685 
       
   686 TPtrC CMsgOutputter::TypeString( const TMsvEmailEntry& entry )
       
   687 	{
       
   688 	TPtrC type;
       
   689 	if(entry.iType == KUidMsvRootEntry)
       
   690 		type.Set(_L("ROOT"));
       
   691 	else if(entry.iType == KUidMsvServiceEntry)
       
   692 		type.Set(_L("SERVICE"));
       
   693 	else if(entry.iType == KUidMsvFolderEntry)
       
   694 		type.Set(_L("FOLDER"));
       
   695 	else if(entry.iType == KUidMsvMessageEntry)
       
   696 		type.Set(_L("MESSAGE"));
       
   697 	else if(entry.iType == KUidMsvEmailTextEntry)
       
   698 		type.Set(_L("TEXT"));
       
   699 	else if(entry.iType == KUidMsvAttachmentEntry)
       
   700 		type.Set(_L("ATTACHMENT"));
       
   701 	else if(entry.iType == KUidMsvEmailHtmlEntry)
       
   702 		type.Set(_L("HTML"));
       
   703 	else
       
   704 		type.Set(_L("UNKNOWN"));
       
   705 	return type;
       
   706 	}
       
   707 
       
   708 TPtrC CMsgOutputter::PriorityString( const TMsvEmailEntry& entry )
       
   709 	{
       
   710 	TPtrC priority;
       
   711 	TMsvPriority temp=entry.Priority();
       
   712 	if(temp==EMsvHighPriority)
       
   713 		priority.Set(_L("Hi"));
       
   714 	else if(temp==EMsvMediumPriority)
       
   715 		priority.Set(_L("Me"));
       
   716 	else if(temp==EMsvLowPriority)
       
   717 		priority.Set(_L("Lo"));
       
   718 	else
       
   719 		priority.Set(_L("No"));
       
   720 	return priority;
       
   721 	}
       
   722 
       
   723 TPtrC CMsgOutputter::DisconnectedOpString( const TMsvEmailEntry& entry )
       
   724 	{
       
   725 	TImDisconnectedOperationType opType = entry.DisconnectedOperation();
       
   726 	switch (opType)
       
   727 		{
       
   728 	case ENoDisconnectedOperations:
       
   729 		return _L("Non");
       
   730 	case EDisconnectedCreateOperation:
       
   731 		return _L("Cre");
       
   732 	case EDisconnectedDeleteOperation:
       
   733 		return _L("Del");
       
   734 	case EDisconnectedChangeOperation:
       
   735 		return _L("Cha");
       
   736 	case EDisconnectedCopyToOperation:
       
   737 		return _L("CTo");
       
   738 	case EDisconnectedCopyFromOperation:
       
   739 		return _L("CFr");
       
   740 	case EDisconnectedCopyWithinServiceOperation:
       
   741 		return _L("CWi");
       
   742 	case EDisconnectedMoveToOperation:
       
   743 		return _L("MTo");
       
   744 	case EDisconnectedMoveFromOperation:
       
   745 		return _L("MFr");
       
   746 	case EDisconnectedMoveWithinServiceOperation:
       
   747 		return _L("MWi");
       
   748 	case EDisconnectedSpecialOperation:
       
   749 		return _L("Spe");
       
   750 	case EDisconnectedUnknownOperation:
       
   751 		return _L("Unk");
       
   752 	case EDisconnectedMultipleOperation:
       
   753 		return _L("Mul");
       
   754 	default:
       
   755 		break;
       
   756 		}
       
   757 	return _L("");
       
   758 	}
       
   759 
       
   760 void CMsgOutputter::FlagsString( TBuf<8>& other, const TMsvEmailEntry& entry )
       
   761 	{
       
   762 	other = _L("--------");
       
   763 
       
   764 	if(entry.Visible())
       
   765 		other.Replace(0, 1, _L("V"));
       
   766 	if(entry.Complete())
       
   767 		other.Replace(7, 1, _L("C"));
       
   768 
       
   769 	if (entry.iType == KUidMsvFolderEntry)
       
   770 		{
       
   771 		if(entry.Subscribed())
       
   772 			other.Replace(1, 1, _L("S")); // subscribed on server
       
   773 		if(entry.LocalSubscription())
       
   774 			other.Replace(2, 1, _L("L")); // subscribed to locally
       
   775 		if(entry.ValidUID())
       
   776 			other.Replace(3, 1, _L("I"));
       
   777 		}
       
   778 	else
       
   779 		{
       
   780 		if(entry.New())
       
   781 			other.Replace(1, 1, _L("N"));
       
   782 		if(entry.Unread())
       
   783 			other.Replace(2, 1, _L("U"));
       
   784 		if(entry.Receipt())
       
   785 			other.Replace(3, 1, _L("R"));
       
   786 		if(entry.Orphan())
       
   787 			other.Replace(4, 1, _L("O"));
       
   788 		if(entry.MHTMLEmail())
       
   789 			other.Replace(5, 1, _L("M"));
       
   790 		if(entry.Attachment())
       
   791 			other.Replace(6, 1, _L("A"));
       
   792 		}
       
   793 	}
       
   794 
       
   795 void CMsgOutputter::IMAP4FlagsString( TBuf<7>& other, const TMsvEmailEntry& entry )
       
   796 	{
       
   797 	other = _L("-------");
       
   798 
       
   799 	if(entry.UnreadIMAP4Flag())
       
   800 		other.Replace(0, 1, _L("U"));
       
   801 	if(entry.SeenIMAP4Flag())
       
   802 		other.Replace(1, 1, _L("S"));
       
   803 	if(entry.AnsweredIMAP4Flag())
       
   804 		other.Replace(2, 1, _L("A"));
       
   805 	if(entry.FlaggedIMAP4Flag())
       
   806 		other.Replace(3, 1, _L("F"));
       
   807 	if(entry.DeletedIMAP4Flag())
       
   808 		other.Replace(4, 1, _L("X"));
       
   809 	if(entry.DraftIMAP4Flag())
       
   810 		other.Replace(5, 1, _L("D"));
       
   811 	if(entry.RecentIMAP4Flag())
       
   812 		other.Replace(6, 1, _L("R"));
       
   813 	}
       
   814 
       
   815 void CMsgOutputter::OutputPartsL(TBuf<5>& aStreams)
       
   816 	{
       
   817 	aStreams=_L("-----");
       
   818 
       
   819 	if(iEntry->HasStoreL())
       
   820 		{
       
   821 		CMsvStore* fileStore = iEntry->ReadStoreL();
       
   822 		CleanupStack::PushL(fileStore);
       
   823 		
       
   824 		TMsvEmailEntry entry = iEntry->Entry(); // Get Details
       
   825 
       
   826 		iPutter->SetFilePrefix(entry.Id());
       
   827 		
       
   828 		if (iParts == EToOneFile)
       
   829 			iPutter->SetFileL(KFileNameCombined);
       
   830 		
       
   831 		// messages
       
   832 		if(fileStore->IsPresentL(KUidMsgFileIMailHeader))
       
   833 			{
       
   834 			if (iParts!=ENone)
       
   835 				HeaderL(*fileStore);
       
   836 			aStreams.Replace(0, 1, _L("H"));
       
   837 			}
       
   838 		if(fileStore->IsPresentL(KUidMsgFileMimeHeader))
       
   839 			{
       
   840 			if (iParts!=ENone)
       
   841 				MimeHeaderL(*fileStore);
       
   842 			aStreams.Replace(1, 1, _L("M"));
       
   843 			}
       
   844 		if(fileStore->IsPresentL(KMsvEntryRichTextBody))
       
   845 			{
       
   846 			if (iParts!=ENone)
       
   847 				BodyDataL(*fileStore);
       
   848 			aStreams.Replace(2, 1, _L("B"));
       
   849 			}
       
   850 		if(entry.Attachment())
       
   851 			aStreams.Replace(3, 1, _L("A"));
       
   852 
       
   853 		// services
       
   854 		if(fileStore->IsPresentL(KUidMsvServiceEntry))
       
   855 			{
       
   856 			if (iParts!=ENone)
       
   857 				{
       
   858 				if (entry.iMtm==KUidMsgTypeIMAP4)
       
   859 					Imap4SettingsL(entry);
       
   860 				else
       
   861 					SettingsL(entry);
       
   862 				}
       
   863 			aStreams.Replace(0, 1, _L("S"));
       
   864 			}
       
   865 
       
   866 		// folders and services
       
   867 		if(fileStore->IsPresentL(KUidImQueuedOperationList))
       
   868 			{
       
   869 			if (iParts!=ENone)
       
   870 				QueuedOpsL(*fileStore);
       
   871 			aStreams.Replace(1, 1, _L("Q"));
       
   872 			}
       
   873 
       
   874 		if (iParts == EToOneFile)
       
   875 			iPutter->UnSetFile();
       
   876 
       
   877 		CleanupStack::PopAndDestroy(); // fileStore
       
   878 		}
       
   879 	}
       
   880 
       
   881 CMsgOutputter* CMsgOutputter::NewL( COutputter* aPutter, CMsvServerEntry* aEntry )
       
   882 	{
       
   883 	CMsgOutputter* self = new(ELeave) CMsgOutputter(aPutter,aEntry);
       
   884 	return self;
       
   885 	}
       
   886 
       
   887 CMsgOutputter::CMsgOutputter( COutputter* aPutter, CMsvServerEntry* aEntry )
       
   888 	: iPutter(aPutter), iEntry(aEntry)
       
   889 	{
       
   890 	}
       
   891 
       
   892 CMsgOutputter::~CMsgOutputter()
       
   893 	{
       
   894 	}
       
   895 
       
   896 void CMsgOutputter::DumpL( TMsvId aId, TInt aSummary,
       
   897 						   TInt aParts,
       
   898 						   TBool aRecurse, TBool aShowIds,
       
   899 						   MsgMatchFn aMatch )
       
   900 	{
       
   901 	iEntry->SetEntry(aId);
       
   902 
       
   903 	iSummary = aSummary;
       
   904 	iParts = aParts;
       
   905 	iRecurse = aRecurse;
       
   906 	iShowIds = aShowIds;
       
   907 	iMatch = aMatch;
       
   908 
       
   909 	if (iSummary == EToOneFile)
       
   910 		{
       
   911 		iPutter->SetFileL( KFileNameEntryStruct );
       
   912 		iPutter->PrintL( _L8("Store: (H)eader (M)ime header (B)ody (A)ttachment (S)ervice data (Q)ueuedops\r\n") );
       
   913 		iPutter->PrintL( _L8("Flags: (V)isible (C)omplete (S)ubscribed (L)ocalsubscribe validu(I)d\r\n") );
       
   914 		iPutter->PrintL( _L8("Flags: (N)ew (U)nread (R)eceipt (O)rphan (M)html (A)ttachment\r\n") );
       
   915 		iPutter->PrintL( _L8("IMAP4: (U)nread (S)een (A)nswered (F)lagged (X)Deleted (D)raft (R)ecent\r\n") );
       
   916 		iPutter->PrintL( _L8("\r\n") );
       
   917 		}
       
   918 
       
   919 	__UHEAP_MARK;
       
   920 	DumpRecurseL();
       
   921 	__UHEAP_MARKEND;
       
   922 
       
   923 	if (iSummary == EToOneFile)
       
   924 		iPutter->UnSetFile();
       
   925 
       
   926 	// park
       
   927 	iEntry->SetEntry(KMsvNullIndexEntryId);
       
   928 	}
       
   929 
       
   930 void CMsgOutputter::DumpRecurseL()
       
   931 	{
       
   932 	const TMsvEmailEntry entry = iEntry->Entry(); // Get Details
       
   933 
       
   934 	// we may not want to show ids because they are not persistent
       
   935 	// over message store wipes
       
   936 	iMsgId = iShowIds ? entry.Id() : 0;
       
   937 
       
   938 //	TBool matchThis = iMatch ? (*iMatch)(entry) : ETrue;
       
   939 	TBool matchThis = iMatch ? (*iMatch)(iEntry) : ETrue;
       
   940 
       
   941 	TBuf<5> streams;
       
   942 	if (matchThis)
       
   943 		OutputPartsL(streams);
       
   944 	
       
   945 	// find the children
       
   946 	CMsvEntrySelection* msvSelection = new (ELeave) CMsvEntrySelection;
       
   947 	CleanupStack::PushL(msvSelection);
       
   948 	User::LeaveIfError( iEntry->GetChildren(*msvSelection) );
       
   949 	
       
   950 	TInt attachCount = msvSelection->Count(); 	// For each child ..
       
   951 
       
   952 	if (matchThis && iSummary != ENone)
       
   953 		{
       
   954 		// get information about the entry
       
   955 		TPtrC type = TypeString( entry );
       
   956 		TPtrC priority = PriorityString( entry );
       
   957 
       
   958 		TBuf<7> imap4flags;
       
   959 		IMAP4FlagsString(imap4flags, entry);
       
   960 
       
   961 		TBuf<8> other;
       
   962 		FlagsString(other, entry);
       
   963 
       
   964 		TPtrC discOp = DisconnectedOpString(entry);
       
   965 		
       
   966 		// indent according to depth
       
   967 		TInt i;
       
   968 		for(i=0; i<iDepth; i++)
       
   969 			iPutter->PrintL(_L(" "));
       
   970 
       
   971 		iPutter->Printf( _L("%S"), &type );
       
   972 
       
   973 		for(i=iDepth + type.Length(); i<8+10; i++)
       
   974 			iPutter->PrintL(_L(" "));
       
   975 
       
   976 		iPutter->Printf( _L(" %08x [%3d], Size=%8d, Store=%S, D=%S, P=%S, F=%S, I4F=%S, R=%08x, uid=%08x, mtm=%08x"),
       
   977 						 entry.Id(),
       
   978 						 attachCount, 
       
   979 						 entry.iSize,
       
   980 						 &streams,
       
   981 						 &discOp,
       
   982 						 &priority,
       
   983 						 &other,
       
   984 						 &imap4flags,
       
   985 						 entry.iRelatedId,
       
   986 						 entry.UID(),
       
   987 						 entry.iMtm);
       
   988 
       
   989 		iPutter->Printf( _L(", '%S'"), &entry.iDescription );
       
   990 		iPutter->Printf( _L(", '%S'"), &entry.iDetails );
       
   991 		iPutter->PrintL( KCRLF );
       
   992 		}
       
   993 	
       
   994 	if ( iRecurse )
       
   995 		{
       
   996 		iDepth++;
       
   997 
       
   998 		for(TInt j=0; j<attachCount; j++)
       
   999 			{
       
  1000 			iEntryCount++;
       
  1001 
       
  1002 			iEntry->SetEntry((*msvSelection)[j]);
       
  1003 		
       
  1004 			__UHEAP_MARK;
       
  1005 			DumpRecurseL();
       
  1006 			__UHEAP_MARKEND;
       
  1007 			}	
       
  1008 
       
  1009 		iDepth--;
       
  1010 		}
       
  1011 
       
  1012 	CleanupStack::PopAndDestroy(); // msvSelection
       
  1013 }
       
  1014 
       
  1015 //----------------------------------------------------------------------------------------
       
  1016 //----------------------------------------------------------------------------------------
       
  1017 
       
  1018 class CTextFile : public RFile
       
  1019 	{
       
  1020 public:
       
  1021 	CTextFile();
       
  1022 	~CTextFile();
       
  1023 
       
  1024 	TInt ReadChar(TDes& aDes);
       
  1025 	TPtrC ReadLineL();
       
  1026 	void SetUnicodeL();
       
  1027 	
       
  1028 private:
       
  1029 	HBufC *iBuf;
       
  1030 	TBool iFileIsUnicode;
       
  1031 	};
       
  1032 
       
  1033 CTextFile::CTextFile()
       
  1034 	{
       
  1035 #if _UNICODE
       
  1036 	iFileIsUnicode = ETrue;
       
  1037 #else
       
  1038 	iFileIsUnicode = EFalse;
       
  1039 #endif
       
  1040 	}
       
  1041 
       
  1042 CTextFile::~CTextFile()
       
  1043 	{
       
  1044 	if (iBuf != NULL)
       
  1045 		delete iBuf;
       
  1046 	}
       
  1047 
       
  1048 void CTextFile::SetUnicodeL()
       
  1049 	{
       
  1050 	TBuf8<2> c;
       
  1051 	User::LeaveIfError(Read(c,2));
       
  1052 
       
  1053 	TInt pos = 0;
       
  1054 	User::LeaveIfError(Seek(ESeekAddress,pos));
       
  1055 
       
  1056 	// OK this is not guaranteed to work but it will in all cases
       
  1057 	// where we have created the files
       
  1058 	iFileIsUnicode = c[1] == 0;
       
  1059 	}
       
  1060 
       
  1061 TInt CTextFile::ReadChar(TDes& aDes)
       
  1062 	{
       
  1063 	TInt err;
       
  1064 	if (iFileIsUnicode)
       
  1065 		{
       
  1066 		TBuf8<2> c;
       
  1067 		err = Read(c, 2);
       
  1068 	
       
  1069 		aDes[0] = c[0];
       
  1070 #if _UNICODE
       
  1071 		aDes[0] |= c[1] << 8;
       
  1072 		// truncate the high byte if in non-Unicode build
       
  1073 #endif
       
  1074 		}
       
  1075 	else
       
  1076 		{
       
  1077 #if _UNICODE
       
  1078 		TBuf8<1> c;
       
  1079 		err = Read(c, 1);
       
  1080 		aDes[0] = c[0];
       
  1081 #else
       
  1082 		err = Read(aDes, 1);
       
  1083 #endif
       
  1084 		}
       
  1085 
       
  1086 	return err;
       
  1087 	}
       
  1088 
       
  1089 TPtrC CTextFile::ReadLineL()
       
  1090 	{
       
  1091 	if (iBuf == NULL)
       
  1092 		iBuf = HBufC::NewL(512);
       
  1093 
       
  1094 	TBuf<1> c;
       
  1095 	TBool finished = EFalse;
       
  1096 	do
       
  1097 		{
       
  1098 		User::LeaveIfError(ReadChar(c));
       
  1099 		
       
  1100 		if (c.Length() && c[0] != 0xA0)
       
  1101 			{
       
  1102 			TPtr16 des = iBuf->Des();
       
  1103 			if (iBuf->Length() == des.MaxLength())
       
  1104 				iBuf = iBuf->ReAllocL(iBuf->Length()*2);
       
  1105 			
       
  1106 			des.Append(c);
       
  1107 			}
       
  1108 		else
       
  1109 			finished = ETrue;
       
  1110 		}
       
  1111 	while (!finished);
       
  1112 
       
  1113 	return iBuf->Des();
       
  1114 	}
       
  1115 
       
  1116 //----------------------------------------------------------------------------------------
       
  1117 
       
  1118 // eof T_LOG.CPP