email/pop3andsmtpmtm/clientmtms/src/MIUTHDR.CPP
changeset 0 72b543305e3a
child 55 5b3b2fa8c3ec
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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 // MIUTHDR.CPP
       
    15 //
       
    16 
       
    17 #include "MIUTHDR.H"
       
    18 #include <msvstd.h>
       
    19 #include <msvstore.h>	// CMsvStore
       
    20 #include "MIUT_ERR.H"
       
    21 #include "MIUTCONV.H"
       
    22 #include <imcvcodc.h>
       
    23 #include "cimencodedheader.h"
       
    24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS  
       
    25 #include "timrfc822datefield.h"
       
    26 #include "cimconvertheader.h"
       
    27 #include "miut_errconsts.h"
       
    28 #endif
       
    29 
       
    30 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
    31 _LIT16(KComma, ",");
       
    32 _LIT16(KDelimiter, ";");
       
    33 #endif
       
    34 
       
    35 const TInt KArrayGranularity = 16;
       
    36 
       
    37 GLDEF_C TPtrC8 LimitStringSize(const TPtrC8& aString, TInt aMaxSize)
       
    38 	{
       
    39 	if (aString.Length() < aMaxSize)
       
    40 		return aString;
       
    41 	else
       
    42 		return aString.Left(aMaxSize);
       
    43 	}
       
    44 
       
    45 GLDEF_C TPtrC16 LimitStringSize(const TPtrC16& aString, TInt aMaxSize)
       
    46 	{
       
    47 	if (aString.Length() < aMaxSize)
       
    48 		return aString;
       
    49 	else
       
    50 		return aString.Left(aMaxSize);
       
    51 	}
       
    52 
       
    53 /**
       
    54 // Ex/Internalize functions are not used at the moment, but have been left here since it is 
       
    55 // very likely they will be needed in future. They are commented out to keep arm5 happy.
       
    56 
       
    57 //----------------------------------------------------------------------------------------
       
    58 LOCAL_C void ExternalizeL(const CArrayFix<TImHeaderEncodingInfo>& anArray,
       
    59 								RWriteStream& aStream)
       
    60 //----------------------------------------------------------------------------------------
       
    61 	{
       
    62 	TInt count;
       
    63 	count=anArray.Count();
       
    64 
       
    65 	aStream << TCardinality(count);		// compressed value
       
    66 	for (TInt ii=count-1 ; ii>=0 ; --ii)
       
    67 		{
       
    68 		TImHeaderEncodingInfo info(anArray[ii]);
       
    69 		info.ExternalizeL(aStream);
       
    70 		}
       
    71 	}
       
    72 	
       
    73 //----------------------------------------------------------------------------------------
       
    74 LOCAL_C void InternalizeL(CArrayFix<TImHeaderEncodingInfo>& anArray, RReadStream& aStream)
       
    75 //----------------------------------------------------------------------------------------
       
    76 	{
       
    77 	TCardinality card;
       
    78 	aStream >> card;
       
    79 	TInt count=card;
       
    80 	anArray.Reset();
       
    81 	for (TInt ii=0; ii<count ; ++ii)
       
    82 		{
       
    83 		TImHeaderEncodingInfo info;
       
    84 		info.InternalizeL(aStream);
       
    85 		anArray.InsertL(0,info);
       
    86 		}
       
    87 	}
       
    88 */	
       
    89 
       
    90 #if defined (_UNICODE)
       
    91 
       
    92 void ExternalizeL(const CDesC16Array& anArray,RWriteStream& aStream)
       
    93 	{
       
    94 	// Used in CImHeader and CImEncodedHeader
       
    95 	TInt count=anArray.Count();
       
    96 	aStream << TCardinality(count);		// compressed value
       
    97 	for (TInt ii=0;ii<count;++ii)
       
    98 		aStream << LimitStringSize(anArray[ii], KMaxImHeaderStringLength);
       
    99 	}
       
   100 
       
   101 void InternalizeL(CDesC16Array& anArray,RReadStream& aStream)
       
   102 	{
       
   103 	TCardinality card;
       
   104 	aStream >> card;
       
   105 	TInt count=card;
       
   106 	anArray.Reset();
       
   107 	for (TInt ii=0;ii<count;++ii)
       
   108 		{
       
   109 		HBufC16* buf=HBufC16::NewLC(aStream,KMaxImHeaderStringLength);
       
   110 		anArray.CArrayFixBase::InsertL(ii,&buf);
       
   111 		CleanupStack::Pop();
       
   112 		}
       
   113 	}
       
   114 
       
   115 #endif
       
   116 
       
   117 void ExternalizeL(const CDesC8Array& anArray,RWriteStream& aStream)
       
   118 	{
       
   119 	// Used in CImHeader , CImMimeHeader & CImMimePartData
       
   120 	TInt count=anArray.Count();
       
   121 	aStream << TCardinality(count);		// compressed value
       
   122 	for (TInt ii=0;ii<count;++ii)
       
   123 		aStream << LimitStringSize(anArray[ii], KMaxImHeaderStringLength);
       
   124 	}
       
   125 
       
   126 void InternalizeL(CDesC8Array& anArray,RReadStream& aStream)
       
   127 	{
       
   128 	TCardinality card;
       
   129 	aStream >> card;
       
   130 	TInt count=card;
       
   131 	anArray.Reset();
       
   132 	for (TInt ii=0;ii<count;++ii)
       
   133 		{
       
   134 		HBufC8* buf=HBufC8::NewLC(aStream,KMaxImHeaderStringLength);
       
   135 		anArray.CArrayFixBase::InsertL(ii,&buf);
       
   136 		CleanupStack::Pop();
       
   137 		}
       
   138 	}
       
   139 
       
   140 
       
   141 
       
   142 //****************************************************************************************
       
   143 //              Class TImHeaderEncodingInfo Functions
       
   144 //****************************************************************************************
       
   145 
       
   146 //----------------------------------------------------------------------------------------
       
   147 EXPORT_C TImHeaderEncodingInfo::TImHeaderEncodingInfo() :  
       
   148 		iType(ENoEncoding), iAddSpace(EFalse), iCharsetUid(KUidMsvCharsetNone)
       
   149 //----------------------------------------------------------------------------------------
       
   150 /** Default constructor. */
       
   151 	{
       
   152 	}
       
   153 
       
   154 //----------------------------------------------------------------------------------------
       
   155 EXPORT_C TImHeaderEncodingInfo::TImHeaderEncodingInfo(const TImHeaderEncodingInfo& aFrom) 
       
   156 //----------------------------------------------------------------------------------------
       
   157 /** Copy constructor.
       
   158 
       
   159 @param aFrom Object to copy */
       
   160 	{
       
   161 	SetField( aFrom.Field() );
       
   162 	SetOffset( aFrom.Offset() );
       
   163 	SetLength( aFrom.Length() );
       
   164 	SetEncodingType( aFrom.EncodingType() );
       
   165 	SetArrayValue( aFrom.ArrayValue() );
       
   166 	SetCharsetUid(aFrom.CharsetUid());
       
   167 	SetAddSpace( aFrom.AddSpace() ); 
       
   168 	SetEncodedLength( aFrom.EncodedLength() ); 
       
   169 	}
       
   170 
       
   171 //----------------------------------------------------------------------------------------
       
   172 EXPORT_C void TImHeaderEncodingInfo::ExternalizeL( RWriteStream& aWriteStream ) const
       
   173 //----------------------------------------------------------------------------------------
       
   174 /** Externalises the object to the specified stream.
       
   175 
       
   176 @param aWriteStream Stream to write to */
       
   177 	{
       
   178 	aWriteStream.WriteUint16L( Field() );
       
   179 	aWriteStream.WriteUint16L( Offset() );
       
   180 	aWriteStream.WriteUint16L( Length() );
       
   181 	aWriteStream.WriteUint16L( EncodingType() );
       
   182 	aWriteStream.WriteUint16L( ArrayValue() );
       
   183 	aWriteStream.WriteUint32L( CharsetUid() );
       
   184 	aWriteStream.WriteUint16L( AddSpace() );
       
   185 	aWriteStream.WriteUint8L( EncodedLength() );
       
   186 	}
       
   187 
       
   188 
       
   189 //----------------------------------------------------------------------------------------
       
   190 EXPORT_C void TImHeaderEncodingInfo::InternalizeL( RReadStream& aReadStream )
       
   191 //----------------------------------------------------------------------------------------
       
   192 /** Internalises the object from the specified stream.
       
   193 
       
   194 @param aReadStream Stream to read from */
       
   195 	{
       
   196 	SetField( (TFieldList) aReadStream.ReadUint16L());
       
   197 	SetOffset( aReadStream.ReadUint16L());
       
   198 	SetLength( aReadStream.ReadUint16L());
       
   199 	SetEncodingType( (TEncodingType) aReadStream.ReadUint16L());
       
   200 	SetArrayValue( aReadStream.ReadUint16L());
       
   201 	SetCharsetUid( aReadStream.ReadUint32L());
       
   202 	SetAddSpace( aReadStream.ReadUint16L());
       
   203 	SetEncodedLength( aReadStream.ReadUint8L());
       
   204 	}
       
   205 
       
   206 //****************************************************************************************
       
   207 //              Class  CImHeader  Functions
       
   208 //****************************************************************************************
       
   209 
       
   210 
       
   211 CImHeader::CImHeader()
       
   212 	{
       
   213 	}
       
   214 
       
   215 EXPORT_C CImHeader* CImHeader::NewLC()
       
   216 /** Allocates and creates a new CImHeader object, leaving the object on the cleanup 
       
   217 stack.
       
   218 
       
   219 @return New CImHeader object */
       
   220 	{
       
   221 	// standard two-phase construction stuff...
       
   222 	CImHeader* self = new (ELeave) CImHeader;
       
   223 	CleanupStack::PushL( self );
       
   224 	self->ConstructL();
       
   225 	return self;
       
   226 	}
       
   227 	
       
   228 void CImHeader::ConstructL()
       
   229 	{
       
   230 	iTo  = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   231 	iCc  = new (ELeave)CDesCArrayFlat( KArrayGranularity );	
       
   232 	iBcc = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   233 	iEncodingInfo = new (ELeave) CArrayFixFlat<TImHeaderEncodingInfo>(KArrayGranularity);
       
   234 	iResentTo  = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   235 	iResentCc  = new (ELeave)CDesCArrayFlat( KArrayGranularity );	
       
   236 	iResentBcc = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   237 	iEncodedHeader = NULL;
       
   238 	Reset();
       
   239 	}
       
   240 
       
   241 EXPORT_C CImHeader::~CImHeader()
       
   242 /** Destructor. */
       
   243 	{
       
   244 	Reset();
       
   245 	delete iTo;
       
   246 	delete iCc;
       
   247 	delete iBcc;
       
   248 	delete iEncodingInfo;
       
   249 	delete iResentTo;
       
   250 	delete iResentCc;
       
   251 	delete iResentBcc;
       
   252 	delete iEncodedHeader;
       
   253 	}
       
   254 
       
   255 EXPORT_C void CImHeader::Reset()
       
   256 /** Resets all header field values. */
       
   257 	{
       
   258 	iVersion = KImHeaderVersion;
       
   259 	delete iFrom;
       
   260 	iFrom = NULL;
       
   261 
       
   262 	delete iSubject;
       
   263 	iSubject = NULL;
       
   264 	
       
   265 	delete iImMsgId;
       
   266 	iImMsgId = NULL;
       
   267 
       
   268 	delete iReplyTo;
       
   269 	iReplyTo = NULL;
       
   270 
       
   271 	delete iReceipt;
       
   272 	iReceipt = NULL;
       
   273 
       
   274 	if (iTo)
       
   275 		iTo->Reset();
       
   276 	if (iCc)
       
   277 		iCc->Reset();
       
   278 	if (iBcc)
       
   279 		iBcc->Reset();
       
   280 	if (iEncodingInfo)
       
   281 		iEncodingInfo->Reset();
       
   282 
       
   283 	delete iResentFrom;
       
   284 	iResentFrom=NULL;
       
   285 
       
   286 	delete iResentMsgId;
       
   287 	iResentMsgId=NULL;
       
   288 
       
   289 	delete iInReplyTo;
       
   290 	iInReplyTo=NULL;
       
   291 	
       
   292 	if (iResentTo)
       
   293 		iResentTo->Reset();
       
   294 	if (iResentCc)
       
   295 		iResentCc->Reset();
       
   296 	if (iResentBcc)
       
   297 		iResentBcc->Reset();
       
   298 
       
   299 	iBodyEncoding = EMsgOutboxMIME;
       
   300 
       
   301 if (iEncodedHeader)
       
   302 		iEncodedHeader->Reset();
       
   303 	}
       
   304 
       
   305 EXPORT_C const TPtrC CImHeader::Subject() const
       
   306 /** Gets the "Subject" header field.
       
   307 
       
   308 @return Field value */
       
   309 	{
       
   310 	return iSubject ? TPtrC(*iSubject) : TPtrC();
       
   311 	}
       
   312 
       
   313 EXPORT_C const TPtrC8 CImHeader::ImMsgId() const
       
   314 /** Gets the "MessageId" header field.
       
   315 
       
   316 @return Field value */
       
   317 	{
       
   318 	return iImMsgId ? TPtrC8(*iImMsgId) : TPtrC8();
       
   319 	}
       
   320 
       
   321 EXPORT_C const TPtrC CImHeader::From() const
       
   322 /** Gets the "From" header field. 
       
   323 
       
   324 This consists of an address and (possibly) an alias.
       
   325 
       
   326 @return Field value */
       
   327 	{
       
   328 	return iFrom ? TPtrC(*iFrom) : TPtrC();
       
   329 	}
       
   330 
       
   331 EXPORT_C const TPtrC CImHeader::ReceiptAddress() const
       
   332 /** Gets the "Receipt" header field. 
       
   333 
       
   334 @return Field value */
       
   335 	{
       
   336 	return iReceipt ? TPtrC(*iReceipt) : TPtrC();
       
   337 	}
       
   338 
       
   339 EXPORT_C const TPtrC CImHeader::ReplyTo() const
       
   340 /** Gets the "ReplyTo" header field. 
       
   341 
       
   342 @return Field value */
       
   343 	{
       
   344 	return iReplyTo ? TPtrC(*iReplyTo) : TPtrC();
       
   345 	}
       
   346 
       
   347 EXPORT_C TUint CImHeader::Charset() const
       
   348 /** Gets the character set to use when sending the message header.
       
   349 
       
   350 If set, this overrides the default system character set for sending
       
   351 the header. 
       
   352 
       
   353 Character set and encoding options can also be set on a per header field
       
   354 basis using TImHeaderEncodingInfo objects. See EncodingInfo().
       
   355 
       
   356 @return Identifier for the character set. Character sets idenitifiers
       
   357 are defined by the character conversion API in charconv.h. 
       
   358 @see SetCharset()
       
   359 @see EncodingInfo()
       
   360 */
       
   361 	{
       
   362 	return i822HeaderCharset;
       
   363 	}
       
   364 
       
   365 EXPORT_C void CImHeader::SetSubjectL( const TDesC8& aSubject )
       
   366 /** Sets the "Subject" header field. 
       
   367 
       
   368 @param aSubject Field value */
       
   369 	{
       
   370 #if defined (_UNICODE)
       
   371 	HBufC* newSubject = HBufC::NewL(aSubject.Length());
       
   372 	newSubject->Des().Copy(aSubject);
       
   373 # else
       
   374 	HBufC* newSubject = aSubject.Alloc();
       
   375 #endif
       
   376 	delete iSubject;
       
   377 	iSubject = newSubject;
       
   378 	}
       
   379 
       
   380 
       
   381 EXPORT_C void CImHeader::SetImMsgIdL( const TDesC8& aImMsgId )
       
   382 /** Sets the "MessageId" header field.
       
   383 
       
   384 @param aImMsgId Field value
       
   385 */
       
   386 	{
       
   387 	HBufC8* newImMsgId = aImMsgId.Alloc();
       
   388 	delete iImMsgId;
       
   389 	iImMsgId = newImMsgId;
       
   390 	}
       
   391 
       
   392 EXPORT_C void CImHeader::SetFromL( const TDesC8& aFrom )
       
   393 /** Sets the "From" header field. 
       
   394 
       
   395 @param aFrom Field value */
       
   396 	{
       
   397 #if defined (_UNICODE)
       
   398 	HBufC* newFrom = HBufC::NewL(aFrom.Length());
       
   399 	newFrom->Des().Copy(aFrom);
       
   400 # else
       
   401 	HBufC* newFrom = aFrom.Alloc();
       
   402 #endif
       
   403 	delete iFrom;
       
   404 	iFrom = newFrom;
       
   405 	}
       
   406 
       
   407 
       
   408 EXPORT_C void CImHeader::SetReplyToL( const TDesC8& aReplyTo )
       
   409 /** Sets the "ReplyTo" header field. 
       
   410 
       
   411 @param aReplyTo Field value */
       
   412 	{
       
   413 #if defined (_UNICODE)
       
   414 	HBufC* newReplyTo = HBufC::NewL(aReplyTo.Length());
       
   415 	newReplyTo->Des().Copy(aReplyTo);
       
   416 # else
       
   417 	HBufC* newReplyTo = aReplyTo.Alloc();
       
   418 #endif
       
   419 	delete iReplyTo;
       
   420 	iReplyTo = newReplyTo;
       
   421 	}
       
   422 
       
   423 
       
   424 EXPORT_C void CImHeader::SetReceiptAddressL( const TDesC8& aReceipt )
       
   425 /** Sets the "Receipt" header field. 
       
   426 
       
   427 @param Field value
       
   428 */
       
   429 	{
       
   430 #if defined (_UNICODE)
       
   431 	HBufC* newReceipt = HBufC::NewL(aReceipt.Length());
       
   432 	newReceipt->Des().Copy(aReceipt);
       
   433 # else
       
   434 	HBufC* newReceipt = aReceipt.Alloc();
       
   435 #endif
       
   436 	delete iReceipt;
       
   437 	iReceipt = newReceipt;
       
   438 	}
       
   439 
       
   440 EXPORT_C void CImHeader::ExternalizeL( RMsvWriteStream& aWriteStream ) const
       
   441 /** Externalises the settings to a specified stream.
       
   442 
       
   443 @param aWriteStream Stream to write to */
       
   444 	{
       
   445 	aWriteStream.WriteUint16L(Version());	// This MUST be the 1st item written into the stream
       
   446 
       
   447 	aWriteStream << LimitStringSize(ReceiptAddress(), KMaxImHeaderStringLength);
       
   448 	aWriteStream << LimitStringSize(ImMsgId(), KMaxImHeaderStringLength);
       
   449 	aWriteStream << LimitStringSize(From(), KMaxImHeaderStringLength);
       
   450 	aWriteStream << LimitStringSize(ReplyTo(), KMaxImHeaderStringLength);
       
   451 	aWriteStream << LimitStringSize(Subject(), KMaxImHeaderStringLength);
       
   452 	aWriteStream.WriteUint32L( iRemoteSize );
       
   453 
       
   454 	aWriteStream << ToRecipients();
       
   455 	aWriteStream << CcRecipients();
       
   456 	aWriteStream << BccRecipients();
       
   457 	aWriteStream << EncodingInfo();
       
   458 
       
   459 	aWriteStream << LimitStringSize(ResentMsgId(), KMaxImHeaderStringLength);
       
   460 	aWriteStream << LimitStringSize(ResentFrom(), KMaxImHeaderStringLength);
       
   461 	aWriteStream << ResentToRecipients();
       
   462 	aWriteStream << ResentCcRecipients();
       
   463 	aWriteStream << ResentBccRecipients();
       
   464 	aWriteStream << LimitStringSize(InReplyTo(), KMaxImHeaderStringLength);
       
   465 	aWriteStream.WriteInt8L(BodyEncoding());
       
   466 	aWriteStream.WriteUint32L(Charset());
       
   467 	}
       
   468 
       
   469 
       
   470 EXPORT_C void CImHeader::InternalizeL( RMsvReadStream& aReadStream )
       
   471 /** Internalises the settings from a specified stream.
       
   472 
       
   473 @param aReadStream Stream to read from */
       
   474 	{
       
   475 	Reset();
       
   476 
       
   477 	iVersion = aReadStream.ReadUint16L();
       
   478 	__ASSERT_DEBUG (iVersion == KImHeaderVersion, gPanic(EMiutBadStreamVersion));
       
   479 
       
   480 	iReceipt = HBufC::NewL( aReadStream, KMaxImHeaderStringLength );
       
   481 	iImMsgId = HBufC8::NewL( aReadStream, KMaxImHeaderStringLength );
       
   482 	iFrom = HBufC::NewL( aReadStream, KMaxImHeaderStringLength );
       
   483 	iReplyTo = HBufC::NewL( aReadStream, KMaxImHeaderStringLength );
       
   484 	iSubject = HBufC::NewL( aReadStream, KMaxImHeaderStringLength );
       
   485 	iRemoteSize=aReadStream.ReadUint32L();
       
   486 
       
   487 	aReadStream >> ToRecipients();
       
   488 	aReadStream >> CcRecipients();
       
   489 	aReadStream >> BccRecipients();
       
   490 	aReadStream >> EncodingInfo();
       
   491 
       
   492 	iResentMsgId = HBufC8::NewL( aReadStream, KMaxImHeaderStringLength );
       
   493 	iResentFrom = HBufC::NewL( aReadStream, KMaxImHeaderStringLength );
       
   494 	aReadStream >> ResentToRecipients();
       
   495 	aReadStream >> ResentCcRecipients();
       
   496 	aReadStream >> ResentBccRecipients();
       
   497 	iInReplyTo = HBufC8::NewL( aReadStream, KMaxImHeaderStringLength );
       
   498 	iBodyEncoding = (TMsgOutboxBodyEncoding)aReadStream.ReadInt8L();
       
   499 	i822HeaderCharset = aReadStream.ReadUint32L();
       
   500 	}
       
   501 
       
   502 
       
   503 EXPORT_C TInt CImHeader::DataSize()
       
   504 /** Gets the combined length of all the field values stored. 
       
   505 
       
   506 @return Combined length */
       
   507 	{
       
   508 	TInt headerSize = 2; // CRLF at end of header
       
   509 	// speed-up by getting 'this' as a local variable...
       
   510 	const CImHeader* self=this;
       
   511 	headerSize+=self->From().Length();
       
   512 	headerSize+=self->ReplyTo().Length();
       
   513 	headerSize+=self->Subject().Length();
       
   514 	headerSize+=self->ReceiptAddress().Length();
       
   515 	headerSize+=sizeof(TTime);
       
   516 	headerSize+=self->ImMsgId().Length();
       
   517 	headerSize+=sizeof(TUid);				// size of Charset
       
   518 // not added headerSize+=sizeof(TUint16); // iVersion
       
   519 
       
   520 	TInt ii;
       
   521 	CDesCArray& toArray = *self->iTo; 
       
   522 	for ( ii = 0; ii < toArray.Count(); ii++)
       
   523 		{
       
   524 		headerSize+=toArray[ii].Length();
       
   525 		}
       
   526 
       
   527 	CDesCArray& ccArray = *self->iCc;
       
   528 	for ( ii = 0; ii < ccArray.Count(); ii++)
       
   529 		{
       
   530 		headerSize+=ccArray[ii].Length(); 
       
   531 		}
       
   532 
       
   533 	CDesCArray& bccArray = *self->iBcc;
       
   534 	for ( ii = 0; ii < bccArray.Count(); ii++)
       
   535 		{
       
   536 		headerSize+=bccArray[ii].Length();
       
   537 		}
       
   538 
       
   539 	if (iEncodedHeader)
       
   540 		headerSize += iEncodedHeader->DataSize();
       
   541 
       
   542 	return headerSize;
       
   543 	}
       
   544 
       
   545 EXPORT_C void CImHeader::StoreL( CMsvStore& aMessageStore ) const
       
   546 /** Stores, but does not commit, settings to a specified message store.
       
   547 	@param aMessageStore Message store to write to */
       
   548 	{
       
   549 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
   550 	
       
   551 	if(aMessageStore.IsDbStore())
       
   552 		{
       
   553 		StoreDBL(aMessageStore);
       
   554 		}
       
   555 	else	
       
   556 		{
       
   557 		RMsvWriteStream out;
       
   558 		out.AssignLC( aMessageStore, KUidMsgFileIMailHeader ); // pushes 'out' to the stack
       
   559 		ExternalizeL(out);
       
   560 		out.CommitL();
       
   561 		CleanupStack::PopAndDestroy();
       
   562 	if (iEncodedHeader)
       
   563 		iEncodedHeader->StoreL(aMessageStore);	
       
   564 		}
       
   565 	
       
   566 	
       
   567 #else
       
   568 	RMsvWriteStream out;
       
   569 	out.AssignLC( aMessageStore, KUidMsgFileIMailHeader ); // pushes 'out' to the stack
       
   570 	ExternalizeL(out);
       
   571 	out.CommitL();
       
   572 	CleanupStack::PopAndDestroy();
       
   573 
       
   574 	if (iEncodedHeader)
       
   575 		iEncodedHeader->StoreL(aMessageStore);
       
   576 #endif
       
   577 	}
       
   578 
       
   579 
       
   580 EXPORT_C void CImHeader::StoreWithoutCommitL( CMsvStore& aMessageStore ) const
       
   581 /** Stores, but does not commit, settings to a specified message store.
       
   582 
       
   583 @param aMessageStore Message store to write to */
       
   584 	{
       
   585 	StoreL(aMessageStore);
       
   586 	}
       
   587 
       
   588 EXPORT_C void CImHeader::RestoreL( CMsvStore& aMessageStore )
       
   589 /** Restores settings from a specified message store.
       
   590 @param aMessageStore Message store to read from */
       
   591 	{
       
   592 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
   593 	if(aMessageStore.IsDbStore())
       
   594 		{
       
   595 		ReStoreDBL(aMessageStore);
       
   596 		}
       
   597 	else
       
   598 		{
       
   599 		RMsvReadStream in;
       
   600 		in.OpenLC( aMessageStore, KUidMsgFileIMailHeader ); // pushes 'in' to the stack
       
   601 		InternalizeL(in);
       
   602 		in.Close();// make sure we close the stream
       
   603 		CleanupStack::PopAndDestroy();
       
   604 		// Check if a stream for the encoded header exists.
       
   605 		if (aMessageStore.IsPresentL(KUidMsgFileIMailEncodedHeader)) 
       
   606 			{
       
   607 			if (!iEncodedHeader)
       
   608 				{
       
   609 				iEncodedHeader = CImEncodedHeader::NewL();
       
   610 				}
       
   611 			iEncodedHeader->RestoreL(aMessageStore);
       
   612 			}
       
   613 		}
       
   614 #else
       
   615 	RMsvReadStream in;
       
   616 	in.OpenLC( aMessageStore, KUidMsgFileIMailHeader ); // pushes 'in' to the stack
       
   617 	InternalizeL(in);
       
   618 	in.Close();// make sure we close the stream
       
   619 	CleanupStack::PopAndDestroy();
       
   620 
       
   621 	// Check if a stream for the encoded header exists.
       
   622 	if (aMessageStore.IsPresentL(KUidMsgFileIMailEncodedHeader)) 
       
   623 		{
       
   624 		if (!iEncodedHeader)
       
   625 			iEncodedHeader = CImEncodedHeader::NewL();
       
   626 		iEncodedHeader->RestoreL(aMessageStore);
       
   627 		}
       
   628 #endif
       
   629 	}
       
   630 
       
   631 
       
   632 EXPORT_C void CImHeader::AddEncodingInfoL(TImHeaderEncodingInfo& aInfo)
       
   633 /** Adds header field encoding information.
       
   634 
       
   635 @param aInfo Header field encoding information */
       
   636 	{
       
   637 	iEncodingInfo->InsertL(0, aInfo);
       
   638 	}
       
   639 
       
   640 //-------------------------------------------------------------------------------------
       
   641 //----------------------Used for forwarding/replying to an email ----------------------
       
   642 /**
       
   643 @deprecated
       
   644 */
       
   645 EXPORT_C const TPtrC8 CImHeader::ResentMsgId() const
       
   646 	{
       
   647 	return iResentMsgId ? TPtrC8(*iResentMsgId) : TPtrC8();
       
   648 	}
       
   649 
       
   650 /**
       
   651 @deprecated
       
   652 */
       
   653 EXPORT_C const TPtrC CImHeader::ResentFrom() const
       
   654 	{
       
   655 	return iResentFrom ? TPtrC(*iResentFrom) : TPtrC();
       
   656 	}
       
   657 
       
   658 /** Gets the "In Reply To" header field.
       
   659 
       
   660 For reply messages, this field stores the ID of the message to 
       
   661 which this is a reply. It is set by CImHeader::CreateReplyL().
       
   662 
       
   663 @return "In Reply To" header field
       
   664 */
       
   665 EXPORT_C const TPtrC8 CImHeader::InReplyTo() const 
       
   666 	{
       
   667 	return iInReplyTo ? TPtrC8(*iInReplyTo) : TPtrC8();
       
   668 	}
       
   669 
       
   670 /**
       
   671 @deprecated
       
   672 */
       
   673 EXPORT_C void CImHeader::SetResentMsgIdL( const TDesC8& aResentMsgId)
       
   674 {
       
   675 	HBufC8* newResentMsgId = aResentMsgId.AllocL();
       
   676     delete iResentMsgId;
       
   677 	iResentMsgId = newResentMsgId;
       
   678 }
       
   679 
       
   680 /**
       
   681 @deprecated
       
   682 */
       
   683 EXPORT_C void CImHeader::SetResentFromL( const TDesC& aResentFrom)
       
   684 	{
       
   685 	HBufC* newResentFrom = aResentFrom.AllocL();
       
   686     delete iResentFrom;
       
   687     iResentFrom = newResentFrom;
       
   688     }
       
   689 
       
   690 /** Sets the "In Reply To" header field.
       
   691 
       
   692 For reply messages, this field stores the ID of the message to 
       
   693 which this is a reply.
       
   694 
       
   695 @param aInReplyTo "In Reply To" header field
       
   696 */
       
   697 EXPORT_C void CImHeader::SetInReplyToL( const TDesC8& aInReplyTo)
       
   698 	{
       
   699 	HBufC8* newInReplyTo = aInReplyTo.AllocL();
       
   700 	delete iInReplyTo;
       
   701 	iInReplyTo = newInReplyTo;
       
   702 	}
       
   703 
       
   704 void CImHeader::FormatSubjectL(CImHeader& aCImHeader, TDesC& aFormatString)
       
   705 	{
       
   706 	//only add to the subject line when there isn't a re: fwd: in the subject
       
   707 	if (aFormatString.Length())
       
   708 		{
       
   709 		TInt formatPos=aFormatString.Find(KMiutFormatString);
       
   710 		TInt foundInSubj=KErrNotFound;
       
   711 		if (formatPos>0)
       
   712 			foundInSubj=Subject().FindF(aFormatString.Left(formatPos-1)); // -1 to avoid % in the string
       
   713 		//append only when it is not in the beginning of the subject line or not found.
       
   714 		if (foundInSubj==KErrNotFound || foundInSubj)
       
   715 			{
       
   716 			HBufC* subject = HBufC::NewLC(Subject().Length() + aFormatString.Length());
       
   717 			TPtr subjectPtr = subject->Des();
       
   718 			subjectPtr.Format(TRefByValue<const TDesC>(aFormatString), iSubject);
       
   719 			aCImHeader.SetSubjectL(subjectPtr);
       
   720 			CleanupStack::PopAndDestroy(subject);
       
   721 			return;
       
   722 			}
       
   723 		}
       
   724 	aCImHeader.SetSubjectL(Subject());
       
   725 	}
       
   726 
       
   727 EXPORT_C TInt CImHeader::CreateForwardL(CImHeader& aCImHeader, TDesC& aSubjectField)
       
   728 /** Populates a new forward header. 
       
   729 
       
   730 The subject line passed in is used to construct the forward subject field value. This is then stored in the new header. 
       
   731 
       
   732 @return	System wide error code
       
   733 @param aCImHeader Header to populate
       
   734 @param aSubjectField Subject line
       
   735 */
       
   736 	{
       
   737 	TInt error = KErrNone;
       
   738 	aCImHeader.Reset();
       
   739 	FormatSubjectL(aCImHeader,aSubjectField);
       
   740  
       
   741 	// Copy the Encoding info to the new Header
       
   742  	for (TInt index = 0; index<iEncodingInfo->Count(); index++)
       
   743  		{
       
   744  		// If this Encoding Info is for the subject field, then make sure
       
   745  		// the new Encoding Info stores the New Subject Length
       
   746  		TImHeaderEncodingInfo encodingInfo = iEncodingInfo->At(index);
       
   747  		if (encodingInfo.Field() == TImHeaderEncodingInfo::ESubject)
       
   748  			{
       
   749  			TInt newSubjLength = aCImHeader.Subject().Length();
       
   750  			encodingInfo.SetLength(newSubjLength);
       
   751  			}
       
   752  		aCImHeader.AddEncodingInfoL(encodingInfo);
       
   753  		}
       
   754 
       
   755 	return error;
       
   756 	}
       
   757 
       
   758 TBool CImHeader::IsRecipientPresent(CImHeader& aCImHeader, TPtrC16 newRecipient)
       
   759 /** checks if the recipient already exists in "Cc" or "To" list
       
   760 
       
   761 @return ETrue if duplicate exists, else EFalse
       
   762 @param aCImHeader Contains "To" and "Cc" lists
       
   763 @param newRecipient Recipient to be checked for duplicate
       
   764 */
       
   765 	{
       
   766 	
       
   767 	TInt toCount = aCImHeader.ToRecipients().Count();
       
   768 	for(TInt ii=0; ii<toCount; ++ii)
       
   769 		{
       
   770 		if((aCImHeader.ToRecipients()[ii].FindF(newRecipient)) >= 0)
       
   771 			{
       
   772 			return ETrue;
       
   773 			}
       
   774 		}
       
   775 
       
   776 	TInt ccCount = aCImHeader.CcRecipients().Count();
       
   777 	for(TInt jj=0; jj<ccCount; ++jj)
       
   778 		{
       
   779 		if((aCImHeader.CcRecipients()[jj].FindF(newRecipient)) >= 0)
       
   780 			{
       
   781 			return ETrue;
       
   782 			}
       
   783 		}
       
   784 
       
   785 	return EFalse;
       
   786 	}
       
   787 
       
   788 /** Populates a new Reply header. 
       
   789 
       
   790 The subject line passed in is used to construct the Reply subject field value. This is then stored in the new header. 
       
   791 
       
   792 @return	System wide error code
       
   793 @param aCImHeader Header to populate
       
   794 @param aSubjectField Subject line
       
   795 @param aReplyTo Reply-to address flag
       
   796 */
       
   797 EXPORT_C TInt CImHeader::CreateReplyL(CImHeader& aCImHeader, TReplyTo aReplyTo, TDesC& aSubjectField)
       
   798 	{
       
   799 	aCImHeader.Reset();
       
   800 	TInt error = KErrNone;
       
   801 	if ((ResentFrom().Length() > 0) || (ResentToRecipients().Count() > 0))
       
   802 		{
       
   803 		switch (aReplyTo)
       
   804 			{
       
   805 		case EOriginator:
       
   806 			// This may not go to the originator!
       
   807 			// If the "Reply-To" field exists, then the reply  should go to the 
       
   808 			//	addresses indicated in that field and not to the address(es) 
       
   809 			//	indicated in the "From" field.
       
   810 			// If there is a "From" field, but no "Reply-To" field, the reply 
       
   811 			//	should be sent to the address(es) indicated in the "From" field.
       
   812 			if (ReplyTo().Length() > 0)
       
   813 				aCImHeader.ToRecipients().AppendL(ReplyTo());
       
   814 			else
       
   815 				aCImHeader.ToRecipients().AppendL(From());
       
   816 			break;
       
   817 		case ESender:
       
   818 			aCImHeader.ToRecipients().AppendL(ResentFrom());
       
   819 			break;
       
   820 		case EAll:
       
   821 			aCImHeader.ToRecipients().AppendL(From());	// not sure if this is needed but added from completeness!
       
   822 			if(!IsRecipientPresent(aCImHeader, ResentFrom()))
       
   823 				{
       
   824 				aCImHeader.ToRecipients().AppendL(ResentFrom());
       
   825 				}
       
   826 			// don't need a break here - add To: and Cc: as well
       
   827 		case ERecipients:
       
   828 			TInt ii;
       
   829 			for (ii=0; ii<ResentToRecipients().Count(); ii++)
       
   830 				{
       
   831 				if(!IsRecipientPresent(aCImHeader, ResentToRecipients()[ii]))
       
   832 					{
       
   833 					aCImHeader.ToRecipients().AppendL(ResentToRecipients()[ii]);
       
   834 					}
       
   835 				}
       
   836 			for (ii=0; ii<ResentCcRecipients().Count(); ii++)
       
   837 				{
       
   838 				if(!IsRecipientPresent(aCImHeader, ResentCcRecipients()[ii]))
       
   839 					{
       
   840 					aCImHeader.CcRecipients().AppendL(ResentCcRecipients()[ii]);
       
   841 					}
       
   842 				}
       
   843 			// Bcc recipients discarded as there should not be other Bcc recipients
       
   844 			break;
       
   845 			}
       
   846 		}
       
   847 	else
       
   848 		{
       
   849 		switch (aReplyTo)
       
   850 			{
       
   851 		case EOriginator:
       
   852 		case ESender:
       
   853 			if (ReplyTo().Length() > 0)
       
   854 				aCImHeader.ToRecipients().AppendL(ReplyTo());
       
   855 			else
       
   856 				aCImHeader.ToRecipients().AppendL(From());
       
   857 			break;
       
   858 		case EAll:
       
   859 			if (ReplyTo().Length()>0)
       
   860 				aCImHeader.ToRecipients().AppendL(ReplyTo());
       
   861 			else
       
   862 				aCImHeader.ToRecipients().AppendL(From());
       
   863 			TInt jj, count;	
       
   864 			count = ToRecipients().Count();
       
   865 			for (jj=0; jj<count; jj++)
       
   866 				{
       
   867 				if(!IsRecipientPresent(aCImHeader, ToRecipients()[jj]))
       
   868 					{
       
   869 					aCImHeader.CcRecipients().AppendL(ToRecipients()[jj]);
       
   870 					}
       
   871 				}
       
   872 			count = CcRecipients().Count();	
       
   873 			for (jj=0; jj<count; jj++)
       
   874 				{
       
   875 				if(!IsRecipientPresent(aCImHeader, CcRecipients()[jj]))
       
   876 					{
       
   877 					aCImHeader.CcRecipients().AppendL(CcRecipients()[jj]);
       
   878 					}
       
   879 				}
       
   880             break;
       
   881 		case ERecipients:
       
   882 			TInt ii;
       
   883 			for (ii=0; ii<ToRecipients().Count(); ii++)
       
   884 				{
       
   885 				if(!IsRecipientPresent(aCImHeader, ToRecipients()[ii]))
       
   886 					{
       
   887 					aCImHeader.ToRecipients().AppendL(ToRecipients()[ii]);
       
   888 					}
       
   889 				}
       
   890 			for (ii=0; ii<CcRecipients().Count(); ii++)
       
   891 				{
       
   892 				if(!IsRecipientPresent(aCImHeader, CcRecipients()[ii]))
       
   893 					{
       
   894 					aCImHeader.CcRecipients().AppendL(CcRecipients()[ii]);
       
   895 					}
       
   896 				}
       
   897 			// Bcc recipients discarded as there should not be other Bcc recipients
       
   898 			break;
       
   899 			}
       
   900 		}
       
   901 		
       
   902 	if (ImMsgId().Length()>0)
       
   903 		aCImHeader.SetInReplyToL(ImMsgId());
       
   904 
       
   905 	FormatSubjectL(aCImHeader,aSubjectField);
       
   906 	return error;
       
   907 	}
       
   908 
       
   909 EXPORT_C void CImHeader::CreateReceiptL(CImHeader& aCImHeader, TDesC& aSubjectField)
       
   910 /** Populates a Receipt email header.
       
   911 
       
   912 @param aCImHeader Header to populate
       
   913 @param aSubjectField Subject line
       
   914 */
       
   915 	{
       
   916 	aCImHeader.Reset();
       
   917 	if (ReceiptAddress().Length())
       
   918 		aCImHeader.ToRecipients().AppendL(ReceiptAddress());
       
   919 	else
       
   920 		aCImHeader.ToRecipients().AppendL(From());
       
   921 	aCImHeader.SetInReplyToL(ImMsgId());
       
   922 	FormatSubjectL(aCImHeader,aSubjectField);
       
   923 	}
       
   924 
       
   925 #if defined (_UNICODE)
       
   926 
       
   927 EXPORT_C void CImHeader::SetSubjectL( const TDesC16& aSubject )
       
   928 /** Sets the "Subject" header field. 
       
   929 
       
   930 @param aSubject Field value */
       
   931 	{
       
   932 	HBufC16* newSubject = aSubject.AllocL(); 
       
   933 	delete iSubject;
       
   934 	iSubject = newSubject;
       
   935 	}
       
   936 
       
   937 EXPORT_C void CImHeader::SetFromL( const TDesC16& aFrom )
       
   938 /** Sets the "From" header field. 
       
   939 
       
   940 @param aFrom Field value */
       
   941 	{
       
   942 	HBufC16* newFrom = aFrom.AllocL();
       
   943 	delete iFrom;
       
   944 	iFrom = newFrom;
       
   945 	}
       
   946 
       
   947 EXPORT_C void CImHeader::SetReplyToL( const TDesC16& aReplyTo )
       
   948 /** Sets the "ReplyTo" header field. 
       
   949 
       
   950 @param aReplyTo Field value */
       
   951 	{
       
   952 	HBufC16* newReplyTo = aReplyTo.AllocL();
       
   953 	delete iReplyTo;
       
   954 	iReplyTo= newReplyTo;
       
   955 	}
       
   956 
       
   957 EXPORT_C void CImHeader::SetReceiptAddressL( const TDesC16& aReceipt )
       
   958 /** Sets the "Receipt" header field. 
       
   959 
       
   960 @param aReceipt "Receipt" header field
       
   961 */
       
   962 	{
       
   963 	HBufC16* newReceipt = aReceipt.AllocL();
       
   964 	delete iReceipt;
       
   965 	iReceipt = newReceipt;
       
   966 	}
       
   967 #endif
       
   968 
       
   969 EXPORT_C void CImHeader::SetCharset(const TUint aCharset)
       
   970 /** Sets the character set to use when sending the message header.
       
   971 
       
   972 This setting overrides the default system character set for sending
       
   973 the header. 
       
   974 
       
   975 Character set and encoding options can also be set on a per header field
       
   976 basis using TImHeaderEncodingInfo objects. See AddEncodingInfoL().
       
   977 
       
   978 @param aCharset Identifier for the character set. Character sets idenitifiers
       
   979 are defined by the character conversion API in charconv.h. 
       
   980 @see Charset()
       
   981 @see AddEncodingInfoL()
       
   982 */
       
   983 	{
       
   984 	i822HeaderCharset=aCharset;
       
   985 	}
       
   986 
       
   987 EXPORT_C TMsgOutboxBodyEncoding CImHeader::BodyEncoding() const
       
   988 /** Gets the method of encoding the body of the email message.
       
   989 
       
   990 The default value (EMsgOutboxMIME) is set so that text parts of the message
       
   991 are sent as MIME multipart/alternative text/html parts, and are encoded using
       
   992 UTF-8.
       
   993 	
       
   994 @see TMsgOutboxBodyEncoding
       
   995 
       
   996 @return Method of encoding.
       
   997 */
       
   998 	{
       
   999 	return iBodyEncoding;
       
  1000 	}
       
  1001 
       
  1002 /** Sets the method of encoding the body of the email message.
       
  1003 
       
  1004 The default value (EMsgOutboxMIME) is set so that text parts of the message
       
  1005 are sent as MIME multipart/alternative text/html parts, and are encoded using
       
  1006 UTF-8.
       
  1007 	
       
  1008 @see TMsgOutboxBodyEncoding
       
  1009 
       
  1010 @param aMessageBodyEncoding Method of encoding
       
  1011 */
       
  1012 EXPORT_C void CImHeader::SetBodyEncoding(TMsgOutboxBodyEncoding aMessageBodyEncoding)
       
  1013 	{
       
  1014 	iBodyEncoding = aMessageBodyEncoding;
       
  1015 	}
       
  1016 
       
  1017 //------------------------------------------------------------------------------
       
  1018 
       
  1019 EXPORT_C void CImHeader::ReDecodeL(RFs& aFS)
       
  1020 /**
       
  1021 Decodes the original message data into the CImHeader fields using the override
       
  1022 character set. 
       
  1023 
       
  1024 8 bit data MUST be decoded using the normal method initially before this method
       
  1025 is called.
       
  1026 
       
  1027 @param aFS
       
  1028 A file server session handle.
       
  1029 
       
  1030 @leave KErrNotSupported
       
  1031 Encoded header information has not been saved.
       
  1032 */
       
  1033 	{
       
  1034 	if (!iEncodedHeader)
       
  1035 		User::Leave(KErrNotSupported);
       
  1036 
       
  1037 	CCnvCharacterSetConverter* charsetConverter = CCnvCharacterSetConverter::NewL();
       
  1038 	CleanupStack::PushL(charsetConverter);
       
  1039 
       
  1040 	CImConvertCharconv* charConv = 
       
  1041 		CImConvertCharconv::NewL(*charsetConverter, aFS);
       
  1042 	CleanupStack::PushL(charConv);
       
  1043 
       
  1044 	CImConvertHeader* convertHeader = CImConvertHeader::NewL(*charConv);
       
  1045 	CleanupStack::PushL(convertHeader);
       
  1046 	
       
  1047 	convertHeader->SetOverrideCharset(iEncodedHeader->DecodeCharset());
       
  1048 
       
  1049 	// Copy our fields with 8 bit data from CImEncodedHeader
       
  1050 	iEncodedHeader->CopyToHeaderL(*this);
       
  1051 	convertHeader->SetMessageType(ETrue);
       
  1052 	convertHeader->DecodeAllHeaderFieldsL(*this);
       
  1053 
       
  1054 	CleanupStack::PopAndDestroy(3, charsetConverter);
       
  1055 	}
       
  1056 
       
  1057 //------------------------------------------------------------------------------
       
  1058 
       
  1059 EXPORT_C TUint CImHeader::OverrideCharset() const
       
  1060 /**
       
  1061 Returns the character set to be used when calling ReDecodeL.
       
  1062 */
       
  1063 	{
       
  1064 	return (iEncodedHeader ? (iEncodedHeader->DecodeCharset()) : 0);
       
  1065 	}
       
  1066 
       
  1067 //------------------------------------------------------------------------------
       
  1068 
       
  1069 EXPORT_C void CImHeader::SetOverrideCharset(const TUint aCharset)
       
  1070 /**
       
  1071 Sets the character set to be used when calling ReDecodeL.
       
  1072 
       
  1073 @param aCharset
       
  1074 The new character set.
       
  1075 */
       
  1076 	{
       
  1077 	if (iEncodedHeader)
       
  1078 		iEncodedHeader->SetDecodeCharset(aCharset);
       
  1079 	}
       
  1080 
       
  1081 //------------------------------------------------------------------------------
       
  1082 
       
  1083 EXPORT_C void CImHeader::SaveEncodedHeadersL()
       
  1084 /**
       
  1085 Saves the 8 bit data in supported fields into a CImEncodedHeader. This allows
       
  1086 later redecoding with different character sets.
       
  1087 
       
  1088 @internalTechnology
       
  1089 */
       
  1090 	{
       
  1091 	if (!iEncodedHeader)
       
  1092 		iEncodedHeader = CImEncodedHeader::NewL();
       
  1093 	iEncodedHeader->CopyFromHeaderL(*this);
       
  1094 	}
       
  1095 
       
  1096 //------------------------------------------------------------------------------
       
  1097 // Friend function of CImHeader, CImEncodedHeader
       
  1098 void CopyArrayL(const CDesCArray& aSource, CDesCArray& aDestination)
       
  1099 	{
       
  1100 	TInt count = aSource.Count();
       
  1101 
       
  1102 	aDestination.Reset();
       
  1103 	while (count--)
       
  1104 		{
       
  1105 		TPtrC descriptor = aSource[count];
       
  1106 		if (descriptor.Length() == 0)
       
  1107 			continue;
       
  1108 		aDestination.AppendL(descriptor);
       
  1109 		}
       
  1110 	}
       
  1111 
       
  1112 //------------------------------------------------------------------------------
       
  1113 
       
  1114 //
       
  1115 //
       
  1116 //
       
  1117 CImMimeHeader::CImMimeHeader()
       
  1118 	{
       
  1119 	__DECLARE_NAME(_S("CImMimeHeader"));
       
  1120 	}
       
  1121 
       
  1122 EXPORT_C CImMimeHeader* CImMimeHeader::NewLC()
       
  1123 /** Allocates and creates a new CImMimeHeader object, leaving the object on the 
       
  1124 cleanup stack.
       
  1125 
       
  1126 @return New CImMimeHeader object */
       
  1127 	{
       
  1128 	// standard two-phase construction stuff...
       
  1129 	CImMimeHeader* self = new (ELeave) CImMimeHeader;
       
  1130 	CleanupStack::PushL( self );
       
  1131 	self->ConstructL();
       
  1132 	return self;
       
  1133 	}
       
  1134 
       
  1135 EXPORT_C CImMimeHeader* CImMimeHeader::NewL()
       
  1136 /** Allocates and creates a new CImMimeHeader object.
       
  1137 
       
  1138 @return New CImMimeHeader object */
       
  1139 	{
       
  1140 	CImMimeHeader* self = CImMimeHeader::NewLC();
       
  1141 	CleanupStack::Pop();
       
  1142 	return self;
       
  1143 	}
       
  1144 
       
  1145 void CImMimeHeader::ConstructL()
       
  1146 	{
       
  1147 	iContentTypeParams  = new (ELeave)CDesC8ArrayFlat( 8 );
       
  1148 	iContentDispositionParams  = new (ELeave)CDesC8ArrayFlat( 8 );	
       
  1149 	iXTypeParams  = new (ELeave)CDesC8ArrayFlat( 8 );	
       
  1150 	Reset();
       
  1151 	}
       
  1152 
       
  1153 EXPORT_C CImMimeHeader::~CImMimeHeader()
       
  1154 /** Destructor. */
       
  1155 	{
       
  1156 	delete iRelativePath;
       
  1157 
       
  1158 	delete iContentType;
       
  1159 	delete iContentSubType;
       
  1160 	delete iContentDisposition;
       
  1161 
       
  1162 	delete iContentDescription;
       
  1163 
       
  1164 	delete iContentBase;
       
  1165 	delete iContentLocation;
       
  1166 	delete iContentID;
       
  1167 
       
  1168 	// delete arrays
       
  1169 	delete iContentTypeParams;
       
  1170 	delete iContentDispositionParams;
       
  1171 	delete iXTypeParams;
       
  1172 
       
  1173 	}
       
  1174 
       
  1175 EXPORT_C void CImMimeHeader::InternalizeL( RMsvReadStream& aReadStream )
       
  1176 /** Internalises the settings from a specified stream.
       
  1177 
       
  1178 @param aReadStream Stream to read from */
       
  1179 	{
       
  1180 	Reset();
       
  1181 
       
  1182 	iVersion = aReadStream.ReadUint16L();
       
  1183 	__ASSERT_DEBUG (iVersion==KImMimeHeaderVersion, gPanic(EMiutBadStreamVersion));
       
  1184 
       
  1185 	iRelativePath = HBufC8::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1186 
       
  1187 	iContentType = HBufC8::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1188 	iContentSubType = HBufC8::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1189 
       
  1190 	iContentTransferEncoding = (TImEncodingType) aReadStream.ReadInt8L();
       
  1191 	iContentDisposition = HBufC8::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1192 
       
  1193 	iContentDescription = HBufC8::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1194 
       
  1195 	iContentBase = HBufC8::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1196 	iContentLocation = HBufC16::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1197 	iContentID = HBufC8::NewL( aReadStream, KMaxImMimeFieldLength );
       
  1198 	//
       
  1199 	aReadStream >> ContentTypeParams();
       
  1200 	aReadStream >> ContentDispositionParams();
       
  1201 	aReadStream >> XTypeParams();
       
  1202 	iMimeCharset = aReadStream.ReadUint32L();
       
  1203 	}
       
  1204 
       
  1205 
       
  1206 EXPORT_C void CImMimeHeader::ExternalizeL( RMsvWriteStream& aWriteStream ) const
       
  1207 /** Externalises the settings to a specified stream.
       
  1208 
       
  1209 @param aWriteStream Stream to write to */
       
  1210 	{
       
  1211 	aWriteStream.WriteUint16L(Version());	// This MUST be the 1st item written into the stream
       
  1212 
       
  1213 	aWriteStream << LimitStringSize(RelativePath(), KMaxImMimeFieldLength);
       
  1214 	//
       
  1215 	aWriteStream << LimitStringSize(ContentType(), KMaxImMimeFieldLength);
       
  1216 	aWriteStream << LimitStringSize(ContentSubType(), KMaxImMimeFieldLength);
       
  1217 	//
       
  1218 	aWriteStream.WriteInt8L(ContentTransferEncoding());
       
  1219 	aWriteStream << LimitStringSize(ContentDisposition(), KMaxImMimeFieldLength);
       
  1220 
       
  1221 	aWriteStream << LimitStringSize(ContentDescription(), KMaxImMimeFieldLength);
       
  1222 
       
  1223 	aWriteStream << LimitStringSize(ContentBase(), KMaxImMimeFieldLength);
       
  1224 	aWriteStream << LimitStringSize(ContentLocation(), KMaxImMimeFieldLength);
       
  1225 	aWriteStream << LimitStringSize(ContentID(), KMaxImMimeFieldLength);
       
  1226 	//
       
  1227 	aWriteStream << ContentTypeParams();
       
  1228 	aWriteStream << ContentDispositionParams();
       
  1229 	aWriteStream << XTypeParams();
       
  1230 	aWriteStream.WriteUint32L(MimeCharset());
       
  1231 	}
       
  1232 
       
  1233 
       
  1234 
       
  1235 EXPORT_C void CImMimeHeader::Reset()
       
  1236 /** Resets all header field values. */
       
  1237 	{
       
  1238 	iVersion = KImMimeHeaderVersion;
       
  1239 	iContentTransferEncoding = EEncodingTypeUnknown;
       
  1240 
       
  1241 	delete iRelativePath;
       
  1242 	iRelativePath=NULL;
       
  1243 
       
  1244 	delete iContentType;
       
  1245 	iContentType=NULL;
       
  1246 
       
  1247 	delete iContentSubType;
       
  1248 	iContentSubType=NULL;
       
  1249 
       
  1250 	delete iContentDisposition;
       
  1251 	iContentDisposition=NULL;
       
  1252 
       
  1253 	delete iContentDescription;
       
  1254 	iContentDescription=NULL;
       
  1255 
       
  1256 	delete iContentBase;
       
  1257 	iContentBase=NULL;
       
  1258 
       
  1259 	delete iContentLocation;
       
  1260 	iContentLocation=NULL;
       
  1261 
       
  1262 	delete iContentID;
       
  1263 	iContentID=NULL;
       
  1264 
       
  1265 	iContentTypeParams->Reset();
       
  1266 	iContentDispositionParams->Reset();
       
  1267 	iXTypeParams->Reset();
       
  1268 	}
       
  1269 
       
  1270 
       
  1271 EXPORT_C void CImMimeHeader::RestoreL( CMsvStore& aMessageStore )
       
  1272 /** Restores settings from a specified message store.
       
  1273 
       
  1274 @param aMessageStore Message store to read from */
       
  1275 	{
       
  1276 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
  1277 	if(aMessageStore.IsDbStore())
       
  1278 		{
       
  1279 		ReStoreMimeDBL(aMessageStore);
       
  1280 		}
       
  1281 	else
       
  1282 		{
       
  1283 		RMsvReadStream in;
       
  1284 		in.OpenLC( aMessageStore, KUidMsgFileMimeHeader ); // pushes 'in' to the stack
       
  1285 		InternalizeL(in);
       
  1286 		in.Close();// make sure we close the stream
       
  1287 		CleanupStack::PopAndDestroy();
       
  1288 		}	
       
  1289 #else
       
  1290 	RMsvReadStream in;
       
  1291 	in.OpenLC( aMessageStore, KUidMsgFileMimeHeader ); // pushes 'in' to the stack
       
  1292 	InternalizeL(in);
       
  1293 	in.Close();// make sure we close the stream
       
  1294 	CleanupStack::PopAndDestroy();
       
  1295 #endif
       
  1296 	}
       
  1297 
       
  1298  
       
  1299 EXPORT_C void CImMimeHeader::StoreL( CMsvStore& aMessageStore ) const
       
  1300 /** Stores settings to a specified message store.
       
  1301 
       
  1302 @param aMessageStore Message store to write to */
       
  1303 	{
       
  1304 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
  1305 	if(aMessageStore.IsDbStore())
       
  1306 		{
       
  1307 		StoreMimeDBL(aMessageStore);
       
  1308 		}
       
  1309 	else
       
  1310 		{
       
  1311 		RMsvWriteStream out;
       
  1312 		out.AssignLC( aMessageStore, KUidMsgFileMimeHeader ); // pushes 'out' to the stack
       
  1313 		ExternalizeL(out);
       
  1314 		out.CommitL();
       
  1315 		CleanupStack::PopAndDestroy();
       
  1316 		}	
       
  1317 #else
       
  1318 	RMsvWriteStream out;
       
  1319 	out.AssignLC( aMessageStore, KUidMsgFileMimeHeader ); // pushes 'out' to the stack
       
  1320 	ExternalizeL(out);
       
  1321 	out.CommitL();
       
  1322 	CleanupStack::PopAndDestroy();
       
  1323 #endif
       
  1324 	}
       
  1325 
       
  1326 
       
  1327 EXPORT_C void CImMimeHeader::StoreWithoutCommitL( CMsvStore& aMessageStore ) const
       
  1328 /** Stores, but does not commit, settings to a specified message store.
       
  1329 
       
  1330 @param aMessageStore Message store to write to */
       
  1331 	{
       
  1332 	RMsvWriteStream out;
       
  1333 	out.AssignLC( aMessageStore, KUidMsgFileMimeHeader ); // pushes 'out' to the stack
       
  1334 	ExternalizeL(out);
       
  1335 	out.CommitL();
       
  1336 	out.Close(); // make sure we close the stream
       
  1337 	CleanupStack::PopAndDestroy();
       
  1338 	}
       
  1339 
       
  1340 EXPORT_C TInt CImMimeHeader::Size()
       
  1341 /** Estimates the size of the MIME header, constructed using the values stored.
       
  1342 
       
  1343 @return Size (bytes) */
       
  1344 	{
       
  1345 	TInt size=sizeof (TUint16) + sizeof (TImEncodingType);
       
  1346 	if (iContentType)
       
  1347 		size+=ContentType().Length();
       
  1348 	if (iContentSubType)
       
  1349 		size+=ContentSubType().Length();
       
  1350 	if (iContentDisposition)
       
  1351 		size+=ContentDisposition().Length();
       
  1352 	if (iContentDescription)
       
  1353 		size+=ContentDescription().Length();
       
  1354 
       
  1355 	if (iContentBase)
       
  1356 		size+=ContentBase().Length();
       
  1357 	if (iContentLocation)
       
  1358 		size+=ContentLocation().Length();
       
  1359 	if (iContentID)
       
  1360 		size+=ContentID().Length();
       
  1361 
       
  1362 	TInt i;
       
  1363 	for (i=0 ; i<ContentTypeParams().Count(); ++i)
       
  1364 		size+=ContentTypeParams()[i].Length();
       
  1365 
       
  1366 	for (i=0 ; i<ContentDispositionParams().Count(); ++i)
       
  1367 		size+=ContentDispositionParams()[i].Length();
       
  1368 
       
  1369 	for (i=0 ; i<XTypeParams().Count(); ++i)
       
  1370 		size+=XTypeParams()[i].Length();
       
  1371 
       
  1372 	return size;
       
  1373 	}
       
  1374 
       
  1375 
       
  1376 EXPORT_C void CImMimeHeader::SetContentTypeL(const TDesC8& aDesc)
       
  1377 /** Sets the Content-Type field value (e.g. "text" in Content-Type:text/plain). 
       
  1378 
       
  1379 The value is MIME defined and should always be 8-bit. 
       
  1380 
       
  1381 @param aDesc Field value
       
  1382 */
       
  1383 	{
       
  1384 	HBufC8* buf = aDesc.AllocL();
       
  1385 	delete iContentType;
       
  1386 	iContentType = buf;
       
  1387 	}
       
  1388 
       
  1389 
       
  1390 EXPORT_C const TPtrC8 CImMimeHeader::ContentType() const
       
  1391 /** Gets the Content-Type field value (e.g. "text" in Content-Type:text/plain). 
       
  1392 
       
  1393 @return Field value */
       
  1394 	{
       
  1395 	return iContentType ? TPtrC8(*iContentType) : TPtrC8();
       
  1396 	}
       
  1397 
       
  1398 
       
  1399 EXPORT_C void CImMimeHeader::SetContentSubTypeL(const TDesC8& aDesc)
       
  1400 /** Sets the Content-Type subtype field value (e.g. "plain" in Content-Type:text/plain). 
       
  1401 
       
  1402 The value is MIME defined and should always be 8-bit. 
       
  1403 
       
  1404 @param aDesc Field value */
       
  1405 	{
       
  1406 	HBufC8* buf = aDesc.AllocL();
       
  1407 	delete iContentSubType;
       
  1408 	iContentSubType = buf;
       
  1409 	}
       
  1410 
       
  1411 
       
  1412 EXPORT_C const TPtrC8 CImMimeHeader::ContentSubType() const
       
  1413 /** Gets the Content-Type subtype field value (e.g. "plain" in Content-Type:text/plain). 
       
  1414 
       
  1415 The value is MIME defined and should always be 8-bit. 
       
  1416 
       
  1417 @return Field value */
       
  1418 	{
       
  1419 	return iContentSubType ? TPtrC8(*iContentSubType) : TPtrC8();
       
  1420 	}
       
  1421 
       
  1422 
       
  1423 EXPORT_C void CImMimeHeader::SetContentDispositionL(const TDesC8& aDesc)
       
  1424 /** Sets the Content-Disposition field value (either inline or attachment). 
       
  1425 
       
  1426 The value is MIME defined and should always be 8-bit. 
       
  1427 
       
  1428 @param aDesc Field value */
       
  1429 	{
       
  1430 	HBufC8* buf = aDesc.AllocL();
       
  1431 	delete iContentDisposition;
       
  1432 	iContentDisposition = buf;
       
  1433 	}
       
  1434 
       
  1435 
       
  1436 EXPORT_C const TPtrC8 CImMimeHeader::ContentDisposition() const
       
  1437 /** Gets the Content-Disposition field value (either inline or attachment). 
       
  1438 
       
  1439 The value is MIME defined and should always be 8-bit. 
       
  1440 
       
  1441 @return Field value */
       
  1442 	{
       
  1443 	return iContentDisposition ? TPtrC8(*iContentDisposition) : TPtrC8();
       
  1444 	}
       
  1445 
       
  1446 
       
  1447 EXPORT_C void CImMimeHeader::SetContentDescriptionL(const TDesC8& aDesc)
       
  1448 /** Sets the Content-Description field value.
       
  1449 
       
  1450 The value is MIME defined and should always be 8-bit. 
       
  1451 
       
  1452 @param aDesc Field value */
       
  1453 	{
       
  1454 	HBufC8* buf = aDesc.AllocL();
       
  1455 	delete iContentDescription;
       
  1456 	iContentDescription = buf;
       
  1457 	}
       
  1458 
       
  1459 
       
  1460 EXPORT_C const TPtrC8 CImMimeHeader::ContentDescription() const
       
  1461 /** Gets the Content-Description field value.
       
  1462 
       
  1463 The value is MIME defined and should always be 8-bit. 
       
  1464 
       
  1465 @return Field value */
       
  1466 	{
       
  1467 	return iContentDescription ? TPtrC8(*iContentDescription) : TPtrC8();
       
  1468 	}
       
  1469 
       
  1470 
       
  1471 EXPORT_C void CImMimeHeader::SetContentBaseL(const TDesC8& aDesc)
       
  1472 /** Sets the Content-Base field value.
       
  1473 
       
  1474 @param aDesc Field value */
       
  1475 	{
       
  1476 	HBufC8* buf = aDesc.AllocL();
       
  1477 	delete iContentBase;
       
  1478 	iContentBase = buf;
       
  1479 	}
       
  1480 
       
  1481 
       
  1482 EXPORT_C const TPtrC8 CImMimeHeader::ContentBase() const
       
  1483 /** Gets the Content-Base field value.
       
  1484 
       
  1485 @return Field value */
       
  1486 	{
       
  1487 	return iContentBase ? TPtrC8(*iContentBase) : TPtrC8();
       
  1488 	}
       
  1489 
       
  1490 
       
  1491 EXPORT_C void CImMimeHeader::SetContentIDL(const TDesC8& aDesc)
       
  1492 /** Sets the Content-ID field value.
       
  1493 
       
  1494 @param aDesc Field value */
       
  1495 	{
       
  1496 	HBufC8* buf = aDesc.AllocL();
       
  1497 	delete iContentID;
       
  1498 	iContentID = buf;
       
  1499 	}
       
  1500 
       
  1501 
       
  1502 EXPORT_C const TPtrC8 CImMimeHeader::ContentID() const
       
  1503 /** Gets the Content-ID field value.
       
  1504 
       
  1505 @return Field value */
       
  1506 	{
       
  1507 	return iContentID ? TPtrC8(*iContentID) : TPtrC8();
       
  1508 	}
       
  1509 
       
  1510 EXPORT_C void CImMimeHeader::SetContentLocationL(const TDesC16& aDesc)
       
  1511 /** Sets the Content-Location field value.
       
  1512 
       
  1513 @param aDesc Field value */
       
  1514 	{
       
  1515 	HBufC16* buf = aDesc.AllocL();
       
  1516 	delete iContentLocation;
       
  1517 	iContentLocation = buf;
       
  1518 	}
       
  1519 
       
  1520 EXPORT_C const TPtrC16 CImMimeHeader::ContentLocation() const
       
  1521 /** Gets the Content-Location field value.
       
  1522 
       
  1523 @return Field value */
       
  1524 	{
       
  1525 	return iContentLocation ? TPtrC16(*iContentLocation) : TPtrC16();
       
  1526 	}
       
  1527 
       
  1528 EXPORT_C void CImMimeHeader::SetContentTransferEncodingL(const TDesC8& aDesc)
       
  1529 /** Sets the Content-Transfer-Encoding field value.
       
  1530 
       
  1531 @param aDesc Field value */
       
  1532 	{
       
  1533 	iContentTransferEncoding = EEncodingTypeUnknown;
       
  1534 
       
  1535 	if (KErrNotFound!=aDesc.MatchF(KMiutWildcardBase64))
       
  1536 		iContentTransferEncoding = EEncodingTypeBASE64;
       
  1537 	else if (KErrNotFound!=aDesc.MatchF(KMiutWildcardQP))
       
  1538 		iContentTransferEncoding = EEncodingTypeQP;
       
  1539 	else if (KErrNotFound!=aDesc.MatchF(KMiutWildcard7Bit))
       
  1540 		iContentTransferEncoding = EEncodingType7Bit;
       
  1541 	else if (KErrNotFound!=aDesc.MatchF(KMiutWildcard8Bit))
       
  1542 		iContentTransferEncoding = EEncodingType8Bit;
       
  1543 	else if (KErrNotFound!=aDesc.MatchF(KMiutWildcardBinary))
       
  1544 		iContentTransferEncoding = EEncodingTypeBinary;
       
  1545 	else if (KErrNotFound!=aDesc.MatchF(KMiutWildcardUU))	// can't be right - there's no MIME standard text to describe UU is there??
       
  1546 		iContentTransferEncoding = EEncodingTypeUU;
       
  1547 	}
       
  1548 
       
  1549 
       
  1550 EXPORT_C TImEncodingType CImMimeHeader::ContentTransferEncoding() const
       
  1551 /** Gets the Content-Transfer-Encoding field value.
       
  1552 
       
  1553 @return Field value */
       
  1554 	{
       
  1555 	return iContentTransferEncoding;
       
  1556 	}
       
  1557 
       
  1558 
       
  1559 EXPORT_C TImEncodingType CImMimeHeader::ContentTransferEncoding(TDes8& rType) const
       
  1560 /** Gets the Content-Transfer-Encoding field value as a string.
       
  1561 
       
  1562 @param rType On return, the field value as a string
       
  1563 @return Field value */
       
  1564 	{
       
  1565 	switch (iContentTransferEncoding)
       
  1566 		{
       
  1567 	case EEncodingTypeBASE64:
       
  1568 		rType.Insert(0,KMiutBase64String);
       
  1569 		break;
       
  1570 	case EEncodingTypeQP:
       
  1571 		rType.Insert(0,KMiutQPString);
       
  1572 		break;
       
  1573 	case EEncodingType7Bit:
       
  1574 		rType.Insert(0,KMiut7BitString);
       
  1575 		break;
       
  1576 	case EEncodingType8Bit:
       
  1577 		rType.Insert(0,KMiut8BitString);
       
  1578 		break;
       
  1579 	case EEncodingTypeBinary:
       
  1580 		rType.Insert(0,KMiutBinaryString);
       
  1581 		break;
       
  1582 	case EEncodingTypeUU:
       
  1583 		rType.Insert(0,KMiutUUString);
       
  1584 		break;
       
  1585 	case EEncodingTypeNone:
       
  1586 	case EEncodingTypeUnknown:
       
  1587 	default:
       
  1588 		rType.Zero();
       
  1589 		break;
       
  1590 		}
       
  1591 	return iContentTransferEncoding;
       
  1592 	}
       
  1593 
       
  1594 
       
  1595 EXPORT_C const TPtrC8 CImMimeHeader::GetContentTypeValue(const TDesC8& aContentTypeParameter) const
       
  1596 /** Gets the value for a particular Content-Type parameter. 
       
  1597 
       
  1598 For example, for "content-type: text/plain; name=umlaut.txt", GetContentType(_L8("name")) 
       
  1599 returns "umlaut.txt".
       
  1600 
       
  1601 @param aContentTypeParameter Parameter type
       
  1602 @return Parameter value */
       
  1603 	{
       
  1604 	__ASSERT_DEBUG (!(iContentTypeParams->Count()&1), gPanic(EMiutArrayHasOddNumberOfElements));
       
  1605 
       
  1606 	TInt result;
       
  1607 	if (KErrNone==iContentTypeParams->Find(aContentTypeParameter,result,ECmpFolded8))
       
  1608 		{
       
  1609 		result++;
       
  1610 		if ((result&1) && result < iContentTypeParams->Count())	// check result+1 is odd & entry exists
       
  1611 			{	
       
  1612 			return ContentTypeParams()[result];
       
  1613 			}
       
  1614 		}
       
  1615 	return TPtrC8();	// couldn't find match so return an empty descriptor
       
  1616 	}
       
  1617 
       
  1618 
       
  1619 // IMAP-specific info describing relative location of entry w.r.t. parent Email message
       
  1620 
       
  1621 EXPORT_C void CImMimeHeader::SetRelativePathL(const TDesC8& aRelativePath)
       
  1622 /** Sets IMAP-specific information for the relative location of the entry to the 
       
  1623 parent email message.
       
  1624 
       
  1625 @param aRelativePath Relative location */
       
  1626 	{
       
  1627 	HBufC8* newRelativePath = aRelativePath.AllocL();
       
  1628 	delete iRelativePath;
       
  1629 	iRelativePath = newRelativePath;
       
  1630 	}
       
  1631 
       
  1632 
       
  1633 EXPORT_C const TPtrC8 CImMimeHeader::RelativePath() const
       
  1634 /** Gets IMAP-specific information for the relative location of the entry to the 
       
  1635 parent email message.
       
  1636 
       
  1637 @return Relative location */
       
  1638 	{
       
  1639 	return iRelativePath ? TPtrC8(*iRelativePath) : TPtrC8();
       
  1640 	}
       
  1641 
       
  1642 
       
  1643 EXPORT_C TUint CImMimeHeader::MimeCharset() const
       
  1644 /** Gets the character set used in decoding the email MIME part.
       
  1645 
       
  1646 UID values for different MIME charsets are in charconv.h 
       
  1647 
       
  1648 @return Character set */
       
  1649 	{
       
  1650 	return iMimeCharset;
       
  1651 	}
       
  1652 
       
  1653 EXPORT_C void CImMimeHeader::SetMimeCharset(const TUint aCharset)
       
  1654 /** Sets the character set used in decoding the email MIME part.
       
  1655 
       
  1656 UID values for different MIME charsets are in charconv.h 
       
  1657 
       
  1658 @param aCharset Character set */
       
  1659 	{
       
  1660 	iMimeCharset = aCharset;
       
  1661 	}
       
  1662 
       
  1663 //
       
  1664 //
       
  1665 //
       
  1666 
       
  1667 EXPORT_C TInt TImRfc822DateField::ParseDateField(const TDesC8& aRfc822DateField, TTime& aTime)
       
  1668 /** Converts an RFC822 date field into a TTime value representing local time.  
       
  1669 Timezone information is added to represent time in local timezone.
       
  1670 
       
  1671 @param aRfc822DateField The RFC822 formatted date field
       
  1672 @param aTime The returned local time
       
  1673 @return KErrNone on success, KErrGeneral otherwise */
       
  1674 	{
       
  1675 	// time syntax = [day ","] date time
       
  1676 	// with date = dd Mmm yy, although most engines produce dd Mmm ccyy
       
  1677 	// and  time = hh:mm[:ss] zone
       
  1678 	// where zone can be 'UT', 'GMT' etc but is usually "+"/"-" 4 digits HHMM,
       
  1679 	// giving the local differential from GMT
       
  1680 	
       
  1681 	// remove leading data from the received header field	
       
  1682 	TLex8 source( aRfc822DateField );
       
  1683 	TLexMark8 monthMark;
       
  1684 	TLexMark8 tzMark;
       
  1685 	TBool validDate = EFalse;
       
  1686 	TBool validTime = EFalse;
       
  1687 	TBool validZone = EFalse;
       
  1688 	TLocale localeTime;
       
  1689 	
       
  1690 	// leading whitespace
       
  1691 	source.SkipSpace();
       
  1692 
       
  1693 	// possibly, day of week, comma & whitespace
       
  1694 	if ( source.Peek().IsAlpha() )
       
  1695 		{
       
  1696 		source.SkipCharacters();
       
  1697 		source.SkipSpace();
       
  1698 		}
       
  1699 	
       
  1700 	// now at the date
       
  1701 	TInt16 day=1;
       
  1702 	TInt16 year=0;
       
  1703 
       
  1704 	TMonth month=EJanuary;
       
  1705 	TInt16 hh=0;
       
  1706 	TInt16 mm=0;
       
  1707 	TInt16 ss=0;
       
  1708 	TInt tzOffsetMins = 0;
       
  1709 
       
  1710 	// here we expect to see a date with the format DD MMM YY
       
  1711 	if ( source.Peek().IsDigit() )
       
  1712 		validDate = (source.Val( day ) == KErrNone);
       
  1713 	
       
  1714 	if ( validDate )
       
  1715 		{
       
  1716 		source.SkipSpace();
       
  1717 		
       
  1718 		// start of the month triple
       
  1719 		source.Mark( monthMark );
       
  1720 		source.SkipCharacters( );
       
  1721 		TPtrC8 monthName( source.MarkedToken( monthMark ) );
       
  1722 		validDate = GetMonth( monthName, month );
       
  1723 		}
       
  1724 	
       
  1725 	if ( validDate )
       
  1726 		{
       
  1727 		source.SkipSpace();
       
  1728 		if ( source.Peek().IsDigit() )
       
  1729 			{
       
  1730 			validDate = (source.Val( year ) == KErrNone);
       
  1731 			}			
       
  1732 		else
       
  1733 			{
       
  1734 			validDate = EFalse;
       
  1735 			}			
       
  1736 		}
       
  1737 	
       
  1738 	if ( validDate )
       
  1739 		{
       
  1740 		// make sure we have a century.
       
  1741 		if ( year < KCenturyThreshold )
       
  1742 			if ( year < KCenturyOffset )
       
  1743 				{
       
  1744 				year += KNextCentury;
       
  1745 				}				
       
  1746 			else
       
  1747 				{
       
  1748 				year += KThisCentury;
       
  1749 				}				
       
  1750 
       
  1751 		source.SkipSpace();
       
  1752 		// now at the time, hh:mm[:ss]
       
  1753 		if ( source.Peek().IsDigit() )
       
  1754 			{
       
  1755 			validTime = (source.Val( hh ) == KErrNone);
       
  1756 			}			
       
  1757 		else 
       
  1758 			{
       
  1759 			validTime = EFalse;
       
  1760 			}			
       
  1761 		}
       
  1762 	
       
  1763 	if ( validTime && source.Peek() == ':' )
       
  1764 		{
       
  1765 		source.Inc( 1 ); // :
       
  1766 		if ( source.Peek().IsDigit() )
       
  1767 			{
       
  1768 			validTime = (source.Val( mm ) == KErrNone);
       
  1769 			}			
       
  1770 		else 
       
  1771 			{
       
  1772 			validTime = EFalse;
       
  1773 			}			
       
  1774 		}
       
  1775 	else
       
  1776 		{
       
  1777 		validTime = EFalse;
       
  1778 		}
       
  1779 		
       
  1780 
       
  1781 	if ( validTime && source.Peek() == ':' )
       
  1782 		{
       
  1783 		source.Inc( 1 ); // :
       
  1784 		if ( source.Peek().IsDigit() )
       
  1785 			{
       
  1786 			validTime = (source.Val ( ss ) == KErrNone);
       
  1787 			}				
       
  1788 		else 
       
  1789 			{
       
  1790 			validTime = EFalse;
       
  1791 			}			
       
  1792 		}
       
  1793 
       
  1794 	
       
  1795 	if ( validTime )
       
  1796 		{
       
  1797 		source.SkipSpaceAndMark( tzMark ); // now pointing at timezone
       
  1798 		source.SkipCharacters();
       
  1799 		TPtrC8 tzInfo( source.MarkedToken( tzMark ));
       
  1800 		validZone = GetTimezone( tzInfo, tzOffsetMins );
       
  1801 		}
       
  1802 	
       
  1803 
       
  1804 	TDateTime dateTime(1970, EJanuary, 1, 0, 0, 0, 0);		// year "zero" for Email app.
       
  1805 	TInt setDateError = KErrNone;
       
  1806 	if ( validDate && validTime && validZone)
       
  1807 		{
       
  1808 		if ((dateTime.SetYear( year )!=KErrNone)||(dateTime.SetMonth( month )!=KErrNone)||(dateTime.SetDay( day-1 )!=KErrNone))
       
  1809 			{
       
  1810 			setDateError = KErrGeneral;
       
  1811 			}			
       
  1812 
       
  1813 		if ((dateTime.SetHour( hh )!=KErrNone)||(dateTime.SetMinute( mm )!=KErrNone)||(dateTime.SetSecond( ss )!=KErrNone))
       
  1814 			{
       
  1815 			setDateError = KErrGeneral;
       
  1816 			}
       
  1817 			
       
  1818 		aTime = dateTime;
       
  1819 
       
  1820 		// Display local time (wherever mail was created).
       
  1821 		// Use zone info to reflect time of email relative to local time.
       
  1822 		aTime -= (TTimeIntervalMinutes)tzOffsetMins;
       
  1823 		
       
  1824 		}
       
  1825 	else
       
  1826 		aTime.UniversalTime();
       
  1827 
       
  1828 
       
  1829 	// if there are any errors while setting the date i.e an invalid date then the
       
  1830 	//	date/time is set to the current time/date.
       
  1831 	if (setDateError != KErrNone)
       
  1832 		{
       
  1833 		aTime.UniversalTime();
       
  1834 		}		
       
  1835 
       
  1836 	// Return KErrNone if all OK, or KErrGeneral if not.
       
  1837 	// If the code to set validZone is re-instated,  then a test that 
       
  1838 	//  validZone is True should be added to the check below
       
  1839 	return (validDate && validTime && (setDateError == KErrNone)) ? KErrNone : KErrGeneral;	
       
  1840 	}
       
  1841 
       
  1842 TBool TImRfc822DateField::GetMonth( const TDesC8& name, TMonth& month )
       
  1843 	{
       
  1844 	TBool validMonth = ETrue;
       
  1845 	TInt iLen;
       
  1846 	iLen = name.Length();
       
  1847 	if (iLen > 0)
       
  1848 		{
       
  1849 		switch ( name[0] )
       
  1850 			{
       
  1851 			case 'J': // jan , jun, jul
       
  1852 			case 'j':
       
  1853 				if (iLen > 1 && (name[1] == 'a' || name[1] == 'A')) 
       
  1854 					month = EJanuary; 
       
  1855                 else if (iLen > 2) 
       
  1856                     month = ( ( name[2] == 'n' || name[2] == 'N' ) ? EJune : EJuly); 
       
  1857                 else 
       
  1858                     validMonth = EFalse;
       
  1859 				break;
       
  1860 			case 'F': // feb
       
  1861 			case 'f':
       
  1862 				month = EFebruary;
       
  1863 				break;
       
  1864 			case 'M': // mar, may
       
  1865 			case 'm':
       
  1866 				if (iLen > 2) 
       
  1867 					month = ( (name[2] == 'r' || name[2] == 'R') ? EMarch : EMay); 
       
  1868                 else 
       
  1869                     validMonth = EFalse;
       
  1870 				break;
       
  1871 			case 'A': // apr, aug
       
  1872 			case 'a':
       
  1873 				if (iLen > 1) 
       
  1874                     month = ( (name[1] == 'p' || name[1] == 'P') ? EApril : EAugust); 
       
  1875                 else 
       
  1876 					validMonth = EFalse;
       
  1877 				break;
       
  1878 			case 'S': // sep
       
  1879 			case 's':
       
  1880 				month = ESeptember;
       
  1881 				break;
       
  1882 			case 'O': // oct
       
  1883 			case 'o':
       
  1884 				month = EOctober;
       
  1885 				break;
       
  1886 			case 'N': // nov
       
  1887 			case 'n':
       
  1888 				month = ENovember;
       
  1889 				break;
       
  1890 			case 'D': // dec
       
  1891 			case 'd':
       
  1892 				month = EDecember;
       
  1893 				break;
       
  1894 			default:
       
  1895 				validMonth = EFalse;
       
  1896 			}
       
  1897 		}
       
  1898 	else
       
  1899 		validMonth = EFalse;
       
  1900 
       
  1901 	return validMonth;
       
  1902 	}
       
  1903 
       
  1904 
       
  1905 TBool TImRfc822DateField::GetTimezone( const TDesC8& name, TInt& minsOffset ) 
       
  1906 /** 
       
  1907 @deprecated since 6.1 */
       
  1908 	{
       
  1909 	TBool ret = ETrue;
       
  1910 
       
  1911 	// just make sure there is any TZ info
       
  1912 	if ( name.Length() < 1 )
       
  1913 		{
       
  1914 		minsOffset = 0;
       
  1915 		return ret;
       
  1916 		}
       
  1917 	
       
  1918 	TChar c = name[0];
       
  1919 
       
  1920 	if ( (name.Length() == 1) && c.IsAlpha() )	
       
  1921 		// the TZ specifier is the Military format
       
  1922 		{
       
  1923 		if ( c == 'Z' )
       
  1924 			minsOffset = 0;
       
  1925 		else if ( c >= 'A' && c < 'J' )
       
  1926 			minsOffset = 60*(64-c);
       
  1927 		else if ( c >= 'K' && c <= 'M' )
       
  1928 			minsOffset = 60*(65-c);
       
  1929 		else if ( c >= 'N' && c <= 'Y')
       
  1930 			minsOffset = 60*(c-(TUint)77);
       
  1931 		else
       
  1932 			return ( EFalse );
       
  1933 		}
       
  1934 	else // multi-char TZ name or +/- & HHMM
       
  1935 		{
       
  1936 		switch ( c )
       
  1937 			{
       
  1938 			case '+':
       
  1939 			case '-': // offset explicitly given as HHMM
       
  1940 				{
       
  1941 				TBool pos = (c == '+'); // grab +ve or -ve offset
       
  1942 				TLex8 HHMM( name );
       
  1943 				HHMM.Inc();
       
  1944 				TInt hhmm;
       
  1945 				ret = (HHMM.Val( hhmm ) == KErrNone);
       
  1946 				// check that the offset value is valid - I know that TZ values should be no more than 13 hours
       
  1947 				// but I've seen one of 20 hours (sign up on the mailing list at www.tudogs.com & you'll get one too)
       
  1948 				if ( !ret || hhmm >= 2400 ) 
       
  1949 					hhmm = 0;
       
  1950 				minsOffset = (hhmm / 100)*60; // hours
       
  1951 				minsOffset += hhmm - (hhmm / 100)*100; // mins
       
  1952 				minsOffset *= (pos ? 1 : -1);
       
  1953 				break;
       
  1954 				}
       
  1955 			case 'U': // Universal time, same as...
       
  1956 			case 'G': // good ol' GMT
       
  1957 				minsOffset = 0;
       
  1958 				break;
       
  1959 			case 'B': // BST
       
  1960 				minsOffset = 60;
       
  1961 				break;
       
  1962 			case 'E': // EST or EDT
       
  1963 				minsOffset = (name[1]=='S' ? -300 : -240);
       
  1964 				break;
       
  1965 			case 'C': // CST or CDT
       
  1966 				minsOffset = (name[1]=='S' ? -360 : -300);
       
  1967 				break;
       
  1968 			case 'M': // MST or MDT
       
  1969 				minsOffset = (name[1]=='S' ? -420 : -360);
       
  1970 				break;
       
  1971 			case 'P': // PST or PDT
       
  1972 				minsOffset = (name[1]=='S' ? -480 : -420);
       
  1973 				break;
       
  1974 			default: //For all the malformed values return false
       
  1975 				return (EFalse);
       
  1976 			}
       
  1977 		}
       
  1978 
       
  1979 	return ret;
       
  1980 	}
       
  1981 
       
  1982 
       
  1983 //
       
  1984 //
       
  1985 //
       
  1986 
       
  1987 
       
  1988 EXPORT_C void TImRfc822DateField::SetDate(const TTime& aTimeDate, TDes8& rOutputLine)
       
  1989 /** Sets a descriptor to contain an RFC822 formatted date field from a TTime parameter.  
       
  1990 Timezone information is obtained from the locale settings.
       
  1991 
       
  1992 @param aTimeDate The TTime value to convert
       
  1993 @param rOutputLine The returned RFC822 formatted date field*/
       
  1994 	{
       
  1995 	TBuf8<KMiutDateStringLength> timeString;
       
  1996 
       
  1997 	// day of week
       
  1998 	TInt dayOfWeek = aTimeDate.DayNoInWeek();
       
  1999 	TPtrC8 dowPtr(TPtrC8(KMiutDayNames).Ptr()+dayOfWeek*3, 3);
       
  2000 
       
  2001 	// date in format 1*2DIGIT month 2DIGIT
       
  2002 	TDateTime date = aTimeDate.DateTime();
       
  2003 	TPtrC8 monthPtr(TPtrC8(KMiutMonthNames).Ptr()+date.Month()*3,3);
       
  2004 
       
  2005 	// produce a string in format Mon, 1 Sep 97 09:34:12
       
  2006 	// _LIT("%s, %2d %s %02d %02d:%02d:%02d ")
       
  2007 	timeString.Format(KMiutDateFormat, &dowPtr, (date.Day()+1), &monthPtr, date.Year(), date.Hour(), date.Minute(), date.Second());
       
  2008 
       
  2009 	TTimeIntervalSeconds offsetTemp=User::UTCOffset();
       
  2010 	TInt32 offset = offsetTemp.Int();
       
  2011 	
       
  2012 	TBool negative = (offset < 0);
       
  2013 	if (negative)
       
  2014 		offset = -offset;
       
  2015 	
       
  2016 	TInt32 offsetHours = offset / 3600;
       
  2017 	TInt32 offsetMins = (offset - offsetHours * 3600) / 60;
       
  2018 
       
  2019 
       
  2020 	TBuf8<5> offsetString;
       
  2021 	if (negative)
       
  2022 		offsetString.Format(KMiutTimeZoneNeg, offsetHours, offsetMins);
       
  2023 	else
       
  2024 		offsetString.Format(KMiutTimeZonePos, offsetHours, offsetMins);
       
  2025 	
       
  2026 	rOutputLine.Append(timeString);
       
  2027 	rOutputLine.Append(offsetString);
       
  2028 	}
       
  2029 
       
  2030 
       
  2031 
       
  2032 //
       
  2033 //
       
  2034 //
       
  2035 
       
  2036 
       
  2037 
       
  2038 EXPORT_C TMsvEmailEntry::TMsvEmailEntry() : TMsvEntry()
       
  2039 /** Default constructor. */
       
  2040 	{
       
  2041 	// TMsvEmailEntry uses these general purpose data members to store flag info,
       
  2042 	// so make sure they are reset when the object is created.
       
  2043 	iMtmData1=0;
       
  2044 	iMtmData2=0;
       
  2045 	iMtmData3=0;
       
  2046 	iSize=0;
       
  2047 	}
       
  2048 //
       
  2049 // copy from a TMsvEntry to a TMsvEmailEntry
       
  2050 //
       
  2051 
       
  2052 EXPORT_C TMsvEmailEntry::TMsvEmailEntry(const TMsvEntry& aGenericEntry) : TMsvEntry()
       
  2053 /** Copy constructor using a TMsvEntry object.
       
  2054 
       
  2055 @param aGenericEntry Object to copy */
       
  2056 	{
       
  2057 	Mem::Copy(this,&aGenericEntry,sizeof(*this));
       
  2058 	}
       
  2059 
       
  2060 //
       
  2061 // compare a TMsvEntry with this TMsvEmailEntry
       
  2062 //
       
  2063 EXPORT_C TBool TMsvEmailEntry::operator==(const TMsvEntry& aEntry) const
       
  2064 /** Equality operator for comparison to a TMsvEntry.
       
  2065 
       
  2066 @param aEntry Object to compare against
       
  2067 @return True if equal */
       
  2068 	{
       
  2069 	TInt size=sizeof(*this)-2*sizeof(TPtrC);
       
  2070 	TBool equal = !(Mem::Compare((TUint8*)&aEntry, size, (TUint8*)this, size));
       
  2071 	equal &= (aEntry.iDescription==this->iDescription);
       
  2072 	equal &= (aEntry.iDetails==this->iDetails);
       
  2073 	return equal;
       
  2074 	}
       
  2075 
       
  2076 
       
  2077 //
       
  2078 // compare another TMsvEmailEntry with this TMsvEmailEntry
       
  2079 //
       
  2080 EXPORT_C TBool TMsvEmailEntry::operator==(const TMsvEmailEntry& aEntry) const
       
  2081 /** Equality operator for comparison to a TMsvEmailEntry.
       
  2082 
       
  2083 @param aEntry Object to compare against
       
  2084 @return True if equal */
       
  2085 	{
       
  2086 	TInt size=sizeof(*this)-2*sizeof(TPtrC);
       
  2087 	TBool equal = !(Mem::Compare((TUint8*)&aEntry, size, (TUint8*)this, size));
       
  2088 	equal &= (aEntry.iDescription==this->iDescription);
       
  2089 	equal &= (aEntry.iDetails==this->iDetails);
       
  2090 	return equal;
       
  2091 	}
       
  2092 
       
  2093 
       
  2094 EXPORT_C void TMsvEmailEntry::GetIMAP4Flags(TBool& rUnread,TBool& rSeen,TBool& rAnswered,TBool& rFlagged,TBool& rDeleted,TBool& rDraft,TBool& rRecent)
       
  2095 /** Gets IMAP4-specific flags from the email entry: Unread, Seen, Answered, Flagged, 
       
  2096 Deleted, Draft and Recent.
       
  2097 
       
  2098 @param rUnread Unread flag
       
  2099 @param rSeen Seen flag
       
  2100 @param rAnswered Answered flag
       
  2101 @param rFlagged Flagged flag
       
  2102 @param rDeleted Deleted flag
       
  2103 @param rDraft Draft flag
       
  2104 @param rRecent Recent flag */
       
  2105 	{
       
  2106 	rUnread=UnreadIMAP4Flag();
       
  2107 	rSeen=SeenIMAP4Flag();
       
  2108 	rAnswered=AnsweredIMAP4Flag();
       
  2109 	rFlagged=FlaggedIMAP4Flag();
       
  2110 	rDeleted=DeletedIMAP4Flag();
       
  2111 	rDraft=DraftIMAP4Flag();
       
  2112 	rRecent=RecentIMAP4Flag();
       
  2113 	}
       
  2114 
       
  2115 
       
  2116 EXPORT_C void TMsvEmailEntry::SetIMAP4Flags(TBool aUnread,TBool aSeen,TBool aAnswered,TBool aFlagged,TBool aDeleted,TBool aDraft,TBool aRecent)
       
  2117 /** Sets IMAP4-specific flags from the email entry: Unread, Seen, Answered, Flagged, 
       
  2118 Deleted, Draft and Recent.
       
  2119 
       
  2120 @param aUnread Unread flag
       
  2121 @param aSeen Seen flag
       
  2122 @param aAnswered Answered flag
       
  2123 @param aFlagged Flagged flag
       
  2124 @param aDeleted Deleted flag
       
  2125 @param aDraft Draft flag
       
  2126 @param aRecent Recent flag */
       
  2127 	{
       
  2128 	SetUnreadIMAP4Flag(aUnread);
       
  2129 	SetSeenIMAP4Flag(aSeen);
       
  2130 	SetAnsweredIMAP4Flag(aAnswered);
       
  2131 	SetFlaggedIMAP4Flag(aFlagged);
       
  2132 	SetDeletedIMAP4Flag(aDeleted);
       
  2133 	SetDraftIMAP4Flag(aDraft);
       
  2134 	SetRecentIMAP4Flag(aRecent);
       
  2135 	}
       
  2136 
       
  2137 
       
  2138 EXPORT_C void TMsvEmailEntry::SetMessageFolderType(TImEmailFolderType aFolderType)
       
  2139 /** Sets a flag on an IMAP MTM folder entry indicating that it stores a 
       
  2140 multipart body structure.
       
  2141 
       
  2142 Multipart body structure parts are represented in the message 
       
  2143 store by a folder entry with this flag set to the appropriate 
       
  2144 multipart type string.
       
  2145 
       
  2146 @param aFolderType Folder type */
       
  2147 	{
       
  2148 	// Quick-implementation of this Set function
       
  2149 	// Final version should use more compact strategy to set/reset bytes
       
  2150 	// as opposed to using mutually-exclusive flags
       
  2151 
       
  2152 	iMtmData1 = iMtmData1 & ~KMsvMimeFolderMask;	// reset all bits
       
  2153 	TInt32 folderMask;
       
  2154 
       
  2155 	switch (aFolderType)
       
  2156 		{
       
  2157 	case EFolderTypeRelated:
       
  2158 		folderMask=KMsvMimeFolderRelatedMask;
       
  2159 		break;
       
  2160 	case EFolderTypeMixed:
       
  2161 		folderMask=KMsvMimeFolderMixedMask;
       
  2162 		break;
       
  2163 	case EFolderTypeAlternative:
       
  2164 		folderMask=KMsvMimeFolderAlternativeMask;
       
  2165 		break;
       
  2166 	case EFolderTypeParallel:
       
  2167 		folderMask=KMsvMimeFolderParallelMask;
       
  2168 		break;
       
  2169 	case EFolderTypeDigest:
       
  2170 		folderMask=KMsvMimeFolderDigestMask;
       
  2171 		break;
       
  2172 	case EFolderTypePartial:
       
  2173 		folderMask=KMsvMimeFolderPartialMask;
       
  2174 		break;
       
  2175 	case EFolderTypeDirectory:
       
  2176 		folderMask=KMsvMimeFolderDirectoryMask;
       
  2177 		break;
       
  2178 	case EFolderTypeExternal:
       
  2179 		folderMask=KMsvMimeFolderExternalMask;
       
  2180 		break;
       
  2181 	case EFolderTypeRFC822:
       
  2182 		folderMask=KMsvMimeFolderRFC822Mask;
       
  2183 		break;
       
  2184 	case EFolderTypeUnknown:
       
  2185 	default:
       
  2186 		folderMask=KMsvMimeFolderUnknownMask;
       
  2187 		break;
       
  2188 		}
       
  2189 	iMtmData1|=folderMask;	// set new folder flags
       
  2190 	}
       
  2191 
       
  2192 
       
  2193 EXPORT_C TImEmailFolderType TMsvEmailEntry::MessageFolderType() const
       
  2194 /** Gets a flag on an IMAP MTM folder entry indicating that it stores a 
       
  2195 multipart body structure.
       
  2196 
       
  2197 Multipart body structure parts are represented in the message 
       
  2198 store by a folder entry with this flag set to the appropriate  
       
  2199 multipart type string.
       
  2200 
       
  2201 @return Folder type */
       
  2202 	{
       
  2203 	TInt32 folderType = iMtmData1 & KMsvMimeFolderMask;
       
  2204 	switch (folderType)
       
  2205 		{
       
  2206 	case TMsvEmailEntry::KMsvMimeFolderRelatedMask:
       
  2207 		return EFolderTypeRelated;
       
  2208 
       
  2209 	case TMsvEmailEntry::KMsvMimeFolderMixedMask:
       
  2210 		return EFolderTypeMixed;
       
  2211 
       
  2212 	case TMsvEmailEntry::KMsvMimeFolderAlternativeMask:
       
  2213 		return EFolderTypeAlternative;
       
  2214 
       
  2215 	case TMsvEmailEntry::KMsvMimeFolderParallelMask:
       
  2216 		return EFolderTypeParallel;
       
  2217 
       
  2218 	case TMsvEmailEntry::KMsvMimeFolderDigestMask:
       
  2219 		return EFolderTypeDigest;
       
  2220 
       
  2221 	case TMsvEmailEntry::KMsvMimeFolderPartialMask:
       
  2222 		return EFolderTypePartial;
       
  2223 
       
  2224 	case TMsvEmailEntry::KMsvMimeFolderDirectoryMask:
       
  2225 		return EFolderTypeDirectory;
       
  2226 
       
  2227 	case TMsvEmailEntry::KMsvMimeFolderExternalMask:
       
  2228 		return EFolderTypeExternal;
       
  2229 
       
  2230 	case TMsvEmailEntry::KMsvMimeFolderRFC822Mask:
       
  2231 		return EFolderTypeRFC822;
       
  2232 
       
  2233 	case TMsvEmailEntry::KMsvMimeFolderUnknownMask:	// drop thru' to default state...
       
  2234 	default:
       
  2235 		return EFolderTypeUnknown;
       
  2236 		}
       
  2237 	}
       
  2238 
       
  2239 EXPORT_C void TMsvEmailEntry::SetDisconnectedOperation(TImDisconnectedOperationType aDisconnectedOperationType)
       
  2240 /** Sets the disconnected operation type.
       
  2241 
       
  2242 @param aDisconnectedOperationType Disconnected operation type */
       
  2243 	{
       
  2244 	iMtmData1 = iMtmData1 & ~KMsvEmailEntryDisconnectedOperation;	// reset all bits
       
  2245 	TInt32 disconnectedOperation;
       
  2246 
       
  2247 	switch (aDisconnectedOperationType)
       
  2248 		{
       
  2249 		case ENoDisconnectedOperations:
       
  2250 			disconnectedOperation = KMsvEmailEntryNoDisconnectedOperations;
       
  2251 			break;
       
  2252 		case EDisconnectedCreateOperation:
       
  2253 			disconnectedOperation = KMsvEmailEntryDisconnectedCreateOperation;
       
  2254 			break;
       
  2255 		case EDisconnectedDeleteOperation:
       
  2256 			disconnectedOperation = KMsvEmailEntryDisconnectedDeleteOperation;
       
  2257 			break;
       
  2258 		case EDisconnectedChangeOperation:
       
  2259 			disconnectedOperation = KMsvEmailEntryDisconnectedChangeOperation;
       
  2260 			break;
       
  2261 		case EDisconnectedCopyToOperation:
       
  2262 			disconnectedOperation = KMsvEmailEntryDisconnectedCopyToOperation;
       
  2263 			break;
       
  2264 		case EDisconnectedCopyFromOperation:
       
  2265 			disconnectedOperation = KMsvEmailEntryDisconnectedCopyFromOperation;
       
  2266 			break;
       
  2267 		case EDisconnectedCopyWithinServiceOperation:
       
  2268 			disconnectedOperation = KMsvEmailEntryDisconnectedCopyWithinServiceOperation;
       
  2269 			break;
       
  2270 		case EDisconnectedMoveToOperation:
       
  2271 			disconnectedOperation = KMsvEmailEntryDisconnectedMoveToOperation;
       
  2272 			break;
       
  2273 		case EDisconnectedMoveFromOperation:
       
  2274 			disconnectedOperation = KMsvEmailEntryDisconnectedMoveFromOperation;
       
  2275 			break;
       
  2276 		case EDisconnectedMoveWithinServiceOperation:
       
  2277 			disconnectedOperation = KMsvEmailEntryDisconnectedMoveWithinServiceOperation;
       
  2278 			break;
       
  2279 		case EDisconnectedSpecialOperation:
       
  2280 			disconnectedOperation = KMsvEmailEntryDisconnectedSpecialOperation;
       
  2281 			break;
       
  2282 		case EDisconnectedMultipleOperation:
       
  2283 			disconnectedOperation = KMsvEmailEntryDisconnectedMultipleOperation;
       
  2284 			break;
       
  2285 		case EDisconnectedUnknownOperation:
       
  2286 		default:
       
  2287 			disconnectedOperation = KMsvEmailEntryDisconnectedUnknownOperation;
       
  2288 			break;
       
  2289 		}
       
  2290 	iMtmData1|=disconnectedOperation;	// set new disconnected operation flags
       
  2291 	}
       
  2292 
       
  2293 EXPORT_C TImDisconnectedOperationType TMsvEmailEntry::DisconnectedOperation() const
       
  2294 /** Gets the disconnected operation type.
       
  2295 
       
  2296 @return Disconnected operation type */
       
  2297 	{
       
  2298 	TInt32 disconnectedOperation = iMtmData1 & KMsvEmailEntryDisconnectedOperation;
       
  2299 	switch (disconnectedOperation)
       
  2300 		{
       
  2301 		case TMsvEmailEntry::KMsvEmailEntryNoDisconnectedOperations:
       
  2302 			return ENoDisconnectedOperations;
       
  2303 
       
  2304 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedCreateOperation:
       
  2305 			return EDisconnectedCreateOperation;
       
  2306 
       
  2307 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedDeleteOperation:
       
  2308 			return EDisconnectedDeleteOperation;
       
  2309 
       
  2310 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedChangeOperation:
       
  2311 			return EDisconnectedChangeOperation;
       
  2312 
       
  2313 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedCopyToOperation:
       
  2314 			return EDisconnectedCopyToOperation;
       
  2315 
       
  2316 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedCopyFromOperation:
       
  2317 			return EDisconnectedCopyFromOperation;
       
  2318 
       
  2319 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedCopyWithinServiceOperation:
       
  2320 			return EDisconnectedCopyWithinServiceOperation;
       
  2321 
       
  2322 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedMoveToOperation:
       
  2323 			return EDisconnectedMoveToOperation;
       
  2324 
       
  2325 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedMoveFromOperation:
       
  2326 			return EDisconnectedMoveFromOperation;
       
  2327 
       
  2328 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedMoveWithinServiceOperation:
       
  2329 			return EDisconnectedMoveWithinServiceOperation;
       
  2330 
       
  2331 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedSpecialOperation:
       
  2332 			return EDisconnectedSpecialOperation;
       
  2333 
       
  2334 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedMultipleOperation:
       
  2335 			return EDisconnectedMultipleOperation;
       
  2336 
       
  2337 		case TMsvEmailEntry::KMsvEmailEntryDisconnectedUnknownOperation: // drop thru' to default state...
       
  2338 		default:
       
  2339 			return EDisconnectedUnknownOperation;
       
  2340 		}
       
  2341 	}
       
  2342 
       
  2343 EXPORT_C TBool TMsvEmailEntry::PartialDownloaded() const
       
  2344 /** Tests if body text is partially downloaded. 
       
  2345 
       
  2346 @return True if body text is partially downloaded. */
       
  2347 	{
       
  2348 	return iMtmData1 & KMsvEmailEntryPartialDownloadFlag;
       
  2349 	}
       
  2350 
       
  2351 EXPORT_C void TMsvEmailEntry::SetPartialDownloaded(TBool aPartialDownloaded)
       
  2352 /** Sets if the body text is partially downloaded.
       
  2353 
       
  2354 @param aPartialDownloaded True if body text is partially downloaded. */
       
  2355 	{
       
  2356 	iMtmData1 = (iMtmData1 & ~KMsvEmailEntryPartialDownloadFlag) | (aPartialDownloaded?KMsvEmailEntryPartialDownloadFlag:KMsvEmailEntryClearFlag);
       
  2357 	}
       
  2358 
       
  2359 
       
  2360 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
  2361 /**
       
  2362 Stores message header to a specified message store.
       
  2363 
       
  2364 @param aMessageStore Message store to write to
       
  2365 @return None.
       
  2366 */
       
  2367 void CImHeader::StoreDBL(CMsvStore& aMessageStore) const
       
  2368 	{
       
  2369 	_LIT(KDetails,"");
       
  2370 
       
  2371 	CHeaderFields* emailHeaderFields = new (ELeave)CHeaderFields();
       
  2372 	CleanupStack::PushL(emailHeaderFields);
       
  2373 	emailHeaderFields->iUid = KUidMsgFileIMailHeader;
       
  2374 	
       
  2375 	//version 0
       
  2376 	CFieldPair* emailHeaderVersionfield = new (ELeave)CFieldPair();
       
  2377 	CleanupStack::PushL(emailHeaderVersionfield);
       
  2378 	emailHeaderVersionfield->iFieldNumValue = Version();
       
  2379 	emailHeaderFields->iFieldPairList.AppendL(emailHeaderVersionfield);
       
  2380 	CleanupStack::Pop(emailHeaderVersionfield);
       
  2381 
       
  2382 	//ReceiptAddress 1
       
  2383 	CFieldPair* emailReceiptAddress = new (ELeave)CFieldPair();
       
  2384 	CleanupStack::PushL(emailReceiptAddress);
       
  2385 	emailReceiptAddress->iFieldTextValue = (LimitStringSize(ReceiptAddress(), KMaxImHeaderStringLength)).AllocL();
       
  2386 	emailHeaderFields->iFieldPairList.AppendL(emailReceiptAddress);
       
  2387 	CleanupStack::Pop(emailReceiptAddress);
       
  2388 	
       
  2389 	CFieldPair* emailImMsgId = new (ELeave)CFieldPair();
       
  2390 	CleanupStack::PushL(emailImMsgId);
       
  2391 	emailImMsgId->iFieldTextValue = Convert8to16L(LimitStringSize(ImMsgId(), KMaxImHeaderStringLength));;
       
  2392 	emailHeaderFields->iFieldPairList.AppendL(emailImMsgId);
       
  2393 	CleanupStack::Pop(emailImMsgId);
       
  2394 	
       
  2395 	//From 3
       
  2396 	CFieldPair* emailFrom = new (ELeave)CFieldPair();
       
  2397 	CleanupStack::PushL(emailFrom);
       
  2398 	emailFrom->iFieldTextValue = (LimitStringSize(From(), KMaxImHeaderStringLength)).AllocL();
       
  2399 	emailHeaderFields->iFieldPairList.AppendL(emailFrom);
       
  2400 	CleanupStack::Pop(emailFrom);
       
  2401 
       
  2402 	//ReplyTo 4
       
  2403 	CFieldPair* emailReplyTo = new (ELeave)CFieldPair();
       
  2404 	CleanupStack::PushL(emailReplyTo);
       
  2405 	emailReplyTo->iFieldTextValue = (LimitStringSize(ReplyTo(), KMaxImHeaderStringLength)).AllocL();
       
  2406 	emailHeaderFields->iFieldPairList.AppendL(emailReplyTo);
       
  2407 	CleanupStack::Pop(emailReplyTo);
       
  2408 	
       
  2409 	//ESubject 5
       
  2410 	CFieldPair* emailSubject = new (ELeave)CFieldPair();
       
  2411 	CleanupStack::PushL(emailSubject);
       
  2412 	emailSubject->iFieldTextValue = (LimitStringSize(Subject(), KMaxImHeaderStringLength)).AllocL();
       
  2413 	emailHeaderFields->iFieldPairList.AppendL(emailSubject);
       
  2414 	CleanupStack::Pop(emailSubject);
       
  2415 
       
  2416 	//iRemoteSize 6
       
  2417 	CFieldPair* emailRemoteSize = new (ELeave)CFieldPair();
       
  2418 	CleanupStack::PushL(emailRemoteSize);
       
  2419 	emailRemoteSize->iFieldNumValue = iRemoteSize;
       
  2420 	emailHeaderFields->iFieldPairList.AppendL(emailRemoteSize);
       
  2421 	CleanupStack::Pop(emailRemoteSize);
       
  2422 	
       
  2423 	//ToRecipients 7
       
  2424 	CFieldPair* emailToRecipients = new (ELeave)CFieldPair();
       
  2425 	CleanupStack::PushL(emailToRecipients);
       
  2426 	
       
  2427 	RBuf16 torecipients;
       
  2428 	CleanupClosePushL(torecipients);
       
  2429 	CreateBufferL(torecipients, *iTo);
       
  2430 	
       
  2431 	if(iTo->MdcaCount()>0)
       
  2432 		{
       
  2433 		emailToRecipients->iFieldTextValue = torecipients.AllocL();	
       
  2434 		}
       
  2435 	else
       
  2436 		{
       
  2437 		emailToRecipients->iFieldTextValue = KNullDesC().AllocL();		
       
  2438 		}
       
  2439 	
       
  2440 	emailHeaderFields->iFieldPairList.AppendL(emailToRecipients);
       
  2441 	torecipients.Close();
       
  2442 	CleanupStack::Pop(); 		//torecipients  
       
  2443 	CleanupStack::Pop(emailToRecipients);	//emailToRecipients
       
  2444 
       
  2445 	
       
  2446 	//CcRecipients 8
       
  2447 	CFieldPair* emailCcRecipients = new (ELeave)CFieldPair();
       
  2448 	CleanupStack::PushL(emailCcRecipients);
       
  2449 
       
  2450 	RBuf16 ccrecipients;
       
  2451 	CleanupClosePushL(ccrecipients);
       
  2452 	CreateBufferL(ccrecipients, *iCc);
       
  2453 	if(iCc->MdcaCount() >0)
       
  2454 		{
       
  2455 		emailCcRecipients->iFieldTextValue = ccrecipients.AllocL();	
       
  2456 		}
       
  2457 	else
       
  2458 		{
       
  2459 		emailCcRecipients->iFieldTextValue = KNullDesC().AllocL();	
       
  2460 		}
       
  2461 	
       
  2462 	emailHeaderFields->iFieldPairList.AppendL(emailCcRecipients);
       
  2463 	ccrecipients.Close();
       
  2464 	CleanupStack::Pop();			//ccrecipients
       
  2465 	CleanupStack::Pop(emailCcRecipients);		//emailCcRecipients
       
  2466 	
       
  2467 	//BccRecipients 9
       
  2468 	CFieldPair* emailBCcRecipients = new (ELeave)CFieldPair();
       
  2469 	CleanupStack::PushL(emailBCcRecipients);
       
  2470 
       
  2471 	RBuf16 bccrecipients;
       
  2472 	CleanupClosePushL(ccrecipients);
       
  2473 	CreateBufferL(bccrecipients, *iBcc);
       
  2474 	if(iBcc->MdcaCount() >0)
       
  2475 		{
       
  2476 		emailBCcRecipients->iFieldTextValue = bccrecipients.AllocL();	
       
  2477 		}
       
  2478 	else
       
  2479 		{
       
  2480 		emailBCcRecipients->iFieldTextValue = KNullDesC().AllocL();	
       
  2481 		}
       
  2482 	
       
  2483 	emailHeaderFields->iFieldPairList.AppendL(emailBCcRecipients);
       
  2484 	bccrecipients.Close();
       
  2485 	CleanupStack::Pop();					//bccrecipients
       
  2486 	CleanupStack::Pop(emailBCcRecipients);	//emailBCcRecipients 
       
  2487 	
       
  2488 	//EncodingInfo 10
       
  2489 	CFieldPair* emailEncodingInfo = new (ELeave)CFieldPair();
       
  2490 	CleanupStack::PushL(emailEncodingInfo);
       
  2491 	
       
  2492 	RBuf16 encodinginfo;
       
  2493 	CleanupClosePushL(encodinginfo);
       
  2494 	encodinginfo.CreateL(iEncodingInfo->Count() * sizeof(TImHeaderEncodingInfo));
       
  2495 		
       
  2496 	for (TInt i=0; i<iEncodingInfo->Count(); i++)
       
  2497 		{
       
  2498 		encodinginfo.AppendNum(iEncodingInfo->At(i).Field());
       
  2499 		encodinginfo.Append(KComma);	
       
  2500 		encodinginfo.AppendNum(iEncodingInfo->At(i).Offset());
       
  2501 		encodinginfo.Append(KComma);
       
  2502 		encodinginfo.AppendNum(iEncodingInfo->At(i).Length());
       
  2503 		encodinginfo.Append(KComma);
       
  2504 		encodinginfo.AppendNum(iEncodingInfo->At(i).EncodingType());
       
  2505 		encodinginfo.Append(KComma);
       
  2506 		encodinginfo.AppendNum(iEncodingInfo->At(i).ArrayValue());
       
  2507 		encodinginfo.Append(KComma);
       
  2508 		encodinginfo.AppendNum(iEncodingInfo->At(i).CharsetUid());
       
  2509 		encodinginfo.Append(KComma);
       
  2510 		encodinginfo.AppendNum(iEncodingInfo->At(i).AddSpace()); 
       
  2511 		encodinginfo.Append(KComma);
       
  2512 		encodinginfo.AppendNum(iEncodingInfo->At(i).EncodedLength()); 
       
  2513 		encodinginfo.Append(KDelimiter);
       
  2514 		}
       
  2515 	
       
  2516 	emailEncodingInfo->iFieldTextValue = encodinginfo.AllocL();
       
  2517 	emailHeaderFields->iFieldPairList.AppendL(emailEncodingInfo);
       
  2518 	encodinginfo.Close();
       
  2519 	CleanupStack::Pop();					//encodinginfo
       
  2520 	CleanupStack::Pop(emailEncodingInfo);
       
  2521 	
       
  2522 	//ResentMsgId 11
       
  2523 	CFieldPair* emailResentMsgId = new (ELeave)CFieldPair();
       
  2524 	CleanupStack::PushL(emailResentMsgId);
       
  2525 	emailResentMsgId->iFieldTextValue = Convert8to16L(LimitStringSize(ResentMsgId(), KMaxImHeaderStringLength));;
       
  2526 	emailHeaderFields->iFieldPairList.AppendL(emailResentMsgId);
       
  2527 	CleanupStack::Pop(emailResentMsgId);
       
  2528 	
       
  2529 	//ResentFrom 12
       
  2530 	CFieldPair* emailResentForm = new (ELeave)CFieldPair();
       
  2531 	CleanupStack::PushL(emailResentForm);
       
  2532 	emailResentForm->iFieldTextValue = (LimitStringSize(ResentFrom(), KMaxImHeaderStringLength).AllocL());
       
  2533 	emailHeaderFields->iFieldPairList.AppendL(emailResentForm);
       
  2534 	CleanupStack::Pop(emailResentForm);
       
  2535 	
       
  2536 	//ResentToRecipients 13
       
  2537 	CFieldPair* emailResentToRecipients= new (ELeave)CFieldPair();
       
  2538 	CleanupStack::PushL(emailResentToRecipients);
       
  2539 
       
  2540 	RBuf16 resentToRecipientsbuf;
       
  2541 	CleanupClosePushL(resentToRecipientsbuf);
       
  2542 	CreateBufferL(resentToRecipientsbuf, *iResentTo);
       
  2543 	if(iResentTo->MdcaCount() >0)
       
  2544 		{
       
  2545 		emailResentToRecipients->iFieldTextValue = resentToRecipientsbuf.AllocL();	
       
  2546 		}
       
  2547 	else
       
  2548 		{
       
  2549 		emailResentToRecipients->iFieldTextValue = KNullDesC().AllocL();	
       
  2550 		}
       
  2551 	
       
  2552 	emailHeaderFields->iFieldPairList.AppendL(emailResentToRecipients);
       
  2553 	resentToRecipientsbuf.Close();
       
  2554 	CleanupStack::Pop();						//resentToRecipientsbuf
       
  2555 	CleanupStack::Pop(emailResentToRecipients);
       
  2556 
       
  2557 	//ResentCcRecipients 14
       
  2558 	CFieldPair* emailResentCcRecipients= new (ELeave)CFieldPair();
       
  2559 	CleanupStack::PushL(emailResentCcRecipients);
       
  2560 	
       
  2561 	RBuf16 resentccRecipientsbuf;
       
  2562 	CleanupClosePushL(resentccRecipientsbuf);
       
  2563 	CreateBufferL(resentccRecipientsbuf, *iResentCc);
       
  2564 	
       
  2565 	if(iResentCc->MdcaCount() >0)
       
  2566 		{
       
  2567 		emailResentCcRecipients->iFieldTextValue = resentccRecipientsbuf.AllocL();	
       
  2568 		}
       
  2569 	else
       
  2570 		{
       
  2571 		emailResentCcRecipients->iFieldTextValue = KNullDesC().AllocL();	
       
  2572 		}
       
  2573 
       
  2574 	emailHeaderFields->iFieldPairList.AppendL(emailResentCcRecipients);
       
  2575 	resentccRecipientsbuf.Close();
       
  2576 	CleanupStack::Pop();						//resentccRecipientsbuf
       
  2577 	CleanupStack::Pop(emailResentCcRecipients);
       
  2578 
       
  2579 	//ResentBccRecipients 15
       
  2580 	CFieldPair* emailResentBCcRecipients= new (ELeave)CFieldPair();
       
  2581 	CleanupStack::PushL(emailResentBCcRecipients);
       
  2582 
       
  2583 	RBuf16 resentbccRecipientsbuf;
       
  2584 	CleanupClosePushL(resentbccRecipientsbuf);	
       
  2585 	CreateBufferL(resentbccRecipientsbuf, *iResentBcc);
       
  2586 	
       
  2587 	if(iResentCc->MdcaCount() >0)
       
  2588 		{
       
  2589 		emailResentBCcRecipients->iFieldTextValue = resentbccRecipientsbuf.AllocL();	
       
  2590 		}
       
  2591 	else
       
  2592 		{
       
  2593 		emailResentBCcRecipients->iFieldTextValue = KNullDesC().AllocL();	
       
  2594 		}
       
  2595 	emailHeaderFields->iFieldPairList.AppendL(emailResentBCcRecipients);
       
  2596 	resentbccRecipientsbuf.Close();
       
  2597 	CleanupStack::Pop();						//resentbccRecipientsbuf
       
  2598 	CleanupStack::Pop(emailResentBCcRecipients);
       
  2599 	
       
  2600 	//InReplyTo 16
       
  2601 	CFieldPair* emailInReplyTo = new (ELeave)CFieldPair();
       
  2602 	CleanupStack::PushL(emailInReplyTo);
       
  2603 	emailInReplyTo->iFieldTextValue = Convert8to16L(LimitStringSize(InReplyTo(), KMaxImHeaderStringLength));
       
  2604 	emailHeaderFields->iFieldPairList.AppendL(emailInReplyTo);
       
  2605 	CleanupStack::Pop(emailInReplyTo);
       
  2606 
       
  2607 	//BodyEncoding 17
       
  2608 	CFieldPair* emailBodyEncoding = new (ELeave)CFieldPair();
       
  2609 	CleanupStack::PushL(emailBodyEncoding);
       
  2610 	emailBodyEncoding->iFieldNumValue = BodyEncoding();
       
  2611 	emailHeaderFields->iFieldPairList.AppendL(emailBodyEncoding);
       
  2612 	CleanupStack::Pop(emailBodyEncoding);
       
  2613 
       
  2614 	//Charset 18
       
  2615 	CFieldPair* emailCharset = new (ELeave)CFieldPair();
       
  2616 	CleanupStack::PushL(emailCharset);
       
  2617 	emailCharset->iFieldNumValue = Charset();
       
  2618 	emailHeaderFields->iFieldPairList.AppendL(emailCharset);
       
  2619 	CleanupStack::Pop(emailCharset);
       
  2620 	
       
  2621 	//Detail This is used for MIME and Encoded Filed, 
       
  2622 	//We are Storing MIME and Encoded data in this Filed.
       
  2623 	CFieldPair* emaildetailField = new (ELeave)CFieldPair();
       
  2624 	CleanupStack::PushL(emaildetailField);
       
  2625 	emaildetailField->iFieldName =  KDetails().AllocL();
       
  2626 	emaildetailField->iFieldType = ETextField;
       
  2627 	emaildetailField->iFieldTextValue = KNullDesC().AllocL();
       
  2628 	emailHeaderFields->iFieldPairList.AppendL(emaildetailField);
       
  2629 	CleanupStack::Pop(emaildetailField);
       
  2630 	
       
  2631 	TMsvWriteStore storeWriter(aMessageStore);
       
  2632 	storeWriter.AssignL(emailHeaderFields);
       
  2633 	
       
  2634 	if (iEncodedHeader)
       
  2635 		{
       
  2636 		iEncodedHeader->StoreEncodedDBL(aMessageStore);
       
  2637 		}
       
  2638 		
       
  2639 	storeWriter.CommitL();
       
  2640 	CleanupStack::Pop(emailHeaderFields);
       
  2641 	}
       
  2642 
       
  2643 /**
       
  2644  * Create the buffer size.
       
  2645  * @param abuf Buffer to be created.
       
  2646  * @param ainto Array of iTo,iCc,iBcc.
       
  2647  * @return None.
       
  2648  */
       
  2649 
       
  2650 void CImHeader::CreateBufferL( RBuf16& aBuf, CDesCArray& aRecipients)const
       
  2651 	{
       
  2652 	TInt size = 0;
       
  2653 	TInt count = 0;
       
  2654 	for(count=0 ; count < aRecipients.MdcaCount() ; count++)
       
  2655 		{
       
  2656 		size += (aRecipients.MdcaPoint(count)).Length();
       
  2657 		}
       
  2658 	size= size + count + 1 ; //To keep space for delimiter.
       
  2659 	aBuf.CreateL(size);
       
  2660 	
       
  2661 	if(aRecipients.MdcaCount()>0)
       
  2662 		{
       
  2663 		for(count=0 ; count < aRecipients.MdcaCount() ; count++)
       
  2664 			{
       
  2665 			aBuf.Append(aRecipients.MdcaPoint(count));
       
  2666 			if(count< aRecipients.MdcaCount()-1)
       
  2667 				aBuf.Append(KComma);
       
  2668 			}
       
  2669 		aBuf.Append(KDelimiter);
       
  2670 		}
       
  2671 	}
       
  2672 
       
  2673 /**
       
  2674  * Convert the 8 bit descripter to 16 bit.
       
  2675  * @param astr A descripter to be convert into16 bit discripter.
       
  2676  * @return HBufC16* A 16 bit discripter.
       
  2677  */
       
  2678 
       
  2679 HBufC16* CImHeader::Convert8to16L(const TDesC8& aStr)const
       
  2680 	{
       
  2681 	HBufC16* newFrom1 = HBufC16::NewL(aStr.Length());
       
  2682 	newFrom1->Des().Copy(aStr);
       
  2683 	return newFrom1;
       
  2684 	}
       
  2685 
       
  2686 /**
       
  2687  * Restores  message header from a specified message store.
       
  2688  * 
       
  2689  * @param aMessageStore Message store to read from. 
       
  2690  * @return None.
       
  2691  */
       
  2692 
       
  2693 void CImHeader::ReStoreDBL(CMsvStore& aMessageStore)
       
  2694 	{
       
  2695 	TInt error;
       
  2696 	CHeaderFields* RcvHeaderRow = NULL;
       
  2697 	TMsvReadStore storeReader(aMessageStore, KUidMsgFileIMailHeader);
       
  2698 	storeReader.LoadL(RcvHeaderRow);
       
  2699 	
       
  2700 	Reset();
       
  2701 	
       
  2702 	TInt i = 0;  // Index.
       
  2703 
       
  2704 	//header version 0
       
  2705 	iVersion = RcvHeaderRow->iFieldPairList[i++]->iFieldNumValue; // header version.
       
  2706 
       
  2707 	//iReceipt 1
       
  2708 	iReceipt =  RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2709 	
       
  2710 	//iImMsgId 2
       
  2711 	iImMsgId = Convert16to8L(*(RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue));
       
  2712 	
       
  2713 	//iFrom 3
       
  2714 	iFrom = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2715 
       
  2716 	//iReplyTo 4
       
  2717 	iReplyTo = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2718 
       
  2719 	//iSubject 5
       
  2720 	iSubject = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2721 
       
  2722 	//iRemoteSize 6
       
  2723 	iRemoteSize = RcvHeaderRow->iFieldPairList[i++]->iFieldNumValue;
       
  2724 	
       
  2725 	//ToRecipients() 7 ---------------------
       
  2726 	HBufC* 	torecipientslist = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2727 	TPtrC strToRecipients = torecipientslist->Des();
       
  2728 	TRAP(error,CreateImHeaderArrayListL(strToRecipients,*iTo));
       
  2729 	delete torecipientslist;
       
  2730 	User::LeaveIfError(error);
       
  2731 	
       
  2732 	//CcRecipients 8	
       
  2733 	HBufC* 	ccrecipientslist = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2734 	TPtrC strCCRecipients = ccrecipientslist->Des();
       
  2735 	TRAP(error,CreateImHeaderArrayListL(strCCRecipients,*iCc));
       
  2736 	delete ccrecipientslist;
       
  2737 	User::LeaveIfError(error);
       
  2738 	
       
  2739 	//BCcRecipients 9	
       
  2740 	HBufC* 	bccrecipientslist = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2741 	TPtrC strbccrecipients = bccrecipientslist->Des();
       
  2742 	TRAP(error,CreateImHeaderArrayListL(strbccrecipients,*iBcc));
       
  2743 	delete bccrecipientslist;
       
  2744 	User::LeaveIfError(error);
       
  2745 
       
  2746 	//EncodingInfo 10
       
  2747 	HBufC16* encodinginfoList = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2748 	TPtr16 encodinginfoListPtr = (encodinginfoList->Des());
       
  2749 	TRAP(error,CreateEncodingInfoL(encodinginfoListPtr));
       
  2750 	delete encodinginfoList;
       
  2751 	User::LeaveIfError(error);
       
  2752 	
       
  2753 	iResentMsgId = Convert16to8L(*(RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue));
       
  2754 	
       
  2755 	//ResentFrom  12	
       
  2756 	iResentFrom = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2757 	
       
  2758 	//ResentToRecipients 13
       
  2759 	HBufC* 	torecientrecipientslist = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2760 	TPtrC strtorecientrecipients = torecientrecipientslist->Des();
       
  2761 	if(strtorecientrecipients.Length() >1 )
       
  2762 		TRAP(error,CreateImHeaderArrayListL(strtorecientrecipients,*iResentTo));
       
  2763 	delete torecientrecipientslist;
       
  2764 	User::LeaveIfError(error);
       
  2765 	
       
  2766 	//ResentCcRecipients 14
       
  2767 	HBufC* 	ccrecientrecipientslist = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2768 	TPtrC strccrecientrecipients = ccrecientrecipientslist->Des();
       
  2769 	if(strccrecientrecipients.Length() >1 )
       
  2770 		TRAP(error,CreateImHeaderArrayListL(strccrecientrecipients,*iResentCc));
       
  2771 	delete ccrecientrecipientslist;
       
  2772 	User::LeaveIfError(error);
       
  2773 	
       
  2774 	//ResentCcRecipients 14
       
  2775 	HBufC* 	bccrecientrecipientslist = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue->Des().AllocL();
       
  2776 	TPtrC strbccrecientrecipientslist = bccrecientrecipientslist->Des();
       
  2777 	if(strbccrecientrecipientslist.Length() >1 )
       
  2778 		TRAP(error,CreateImHeaderArrayListL(strbccrecientrecipientslist,*iResentBcc));
       
  2779 	delete bccrecientrecipientslist;
       
  2780 	User::LeaveIfError(error);
       
  2781 	
       
  2782 	iInReplyTo = Convert16to8L(*(RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue));
       
  2783 	
       
  2784 	//BodyEncoding 17
       
  2785 	iBodyEncoding = (TMsgOutboxBodyEncoding)RcvHeaderRow->iFieldPairList[i++]->iFieldNumValue;
       
  2786 	
       
  2787 	//Charset 18
       
  2788 	i822HeaderCharset = RcvHeaderRow->iFieldPairList[i++]->iFieldNumValue;
       
  2789 	
       
  2790 	// Check if a stream for the encoded header exists.
       
  2791 	if (aMessageStore.IsPresentL(KUidMsgFileIMailEncodedHeader)) 
       
  2792 		{
       
  2793 		if (!iEncodedHeader)
       
  2794 			{
       
  2795 			iEncodedHeader = CImEncodedHeader::NewL();
       
  2796 			}
       
  2797 		iEncodedHeader->ReStoreEncodedDBL(aMessageStore);
       
  2798 		}
       
  2799 	}
       
  2800 
       
  2801 
       
  2802 /**
       
  2803  * Create Array List(iTo,iCc,iBcc) from a given string.
       
  2804  * @param aStr A given string.
       
  2805  * @param aInto Array list to be created.
       
  2806  * @return None.
       
  2807  */
       
  2808 void CImHeader::CreateImHeaderArrayListL(TDesC16& aStr, CDesCArray& aRecipients)
       
  2809 	{
       
  2810 	if(aStr.Length() > 0)
       
  2811 		{
       
  2812 		TPtrC16 recvstr = aStr;
       
  2813 		TInt startPos = recvstr.Locate(',') ;
       
  2814 		if(startPos == KErrNotFound)
       
  2815 			{
       
  2816 			TInt startrecvPos = recvstr.Locate(';') ;
       
  2817 			TPtrC16 partstr = recvstr.Left(startrecvPos);
       
  2818 			aRecipients.AppendL(partstr);
       
  2819 			return;
       
  2820 			}
       
  2821 
       
  2822 		while(1)
       
  2823 			{
       
  2824 			TPtrC16 partstrx = recvstr.Left(startPos);
       
  2825 			aRecipients.AppendL(partstrx);
       
  2826 			startPos++;
       
  2827 			recvstr.Set(recvstr.Mid(startPos, recvstr.Length()- startPos));
       
  2828 		
       
  2829 			startPos = recvstr.Locate(',');
       
  2830 			if(startPos == KErrNotFound)
       
  2831 				{
       
  2832 				TPtrC16 partstrxy;
       
  2833 				partstrxy.Set(recvstr.Mid(0,recvstr.Length()-1));
       
  2834 				aRecipients.AppendL(partstrxy);
       
  2835 				break;
       
  2836 				}
       
  2837 			}
       
  2838 		}
       
  2839 	}
       
  2840 
       
  2841 /**
       
  2842  * Create encoding info from a given string.
       
  2843  * @param aStr A given string.
       
  2844  * @return None.
       
  2845  */
       
  2846 
       
  2847 void CImHeader::CreateEncodingInfoL(TDesC16& aEncodingStr1)
       
  2848 	{
       
  2849 	TPtrC16 aEncodingStr = aEncodingStr1.Left(aEncodingStr1.Length());
       
  2850 	if(aEncodingStr.Length()>0)
       
  2851 		{
       
  2852 		TInt startPos = 0;
       
  2853 		TInt firstSemiColonPos = aEncodingStr.Locate(';');
       
  2854 		TInt lastSemiColonPos = aEncodingStr.LocateReverse(';');
       
  2855 
       
  2856 		iEncodingInfo->Reset();
       
  2857 		TImHeaderEncodingInfo headerencodinginfo;
       
  2858 		RArray<TInt> encodingData;
       
  2859 
       
  2860 		do	{
       
  2861 			TPtrC16 str1 = aEncodingStr.Left(firstSemiColonPos+1); // First recipient
       
  2862 			startPos = str1.Locate(',') ;
       
  2863 			
       
  2864 			while(startPos != KErrNotFound )
       
  2865 				{
       
  2866 				TPtrC16 str2 = str1.Left(startPos);
       
  2867 				TInt a= ConvertToTInt(str2);
       
  2868 				encodingData.Append(a);
       
  2869 				
       
  2870 				startPos++;
       
  2871 				str1.Set(str1.Mid(startPos, str1.Length()- startPos));
       
  2872 			
       
  2873 				startPos = str1.Locate(',');
       
  2874 				if(startPos == KErrNotFound)
       
  2875 					{
       
  2876 					TPtrC16 str3;
       
  2877 					str3.Set(str1.Mid(0,str1.Length()-1));
       
  2878 					encodingData.Append(ConvertToTInt(str3));
       
  2879 					break;
       
  2880 					}
       
  2881 					
       
  2882 				}
       
  2883 
       
  2884 			headerencodinginfo.SetField(( TImHeaderEncodingInfo::TFieldList)encodingData[0]);
       
  2885 			headerencodinginfo.SetOffset(encodingData[1]);
       
  2886 			headerencodinginfo.SetLength(encodingData[2]);
       
  2887 			headerencodinginfo.SetEncodingType((TImHeaderEncodingInfo::TEncodingType)encodingData[3]);
       
  2888 			headerencodinginfo.SetArrayValue(encodingData[4]);
       
  2889 			headerencodinginfo.SetCharsetUid(encodingData[5]);
       
  2890 			headerencodinginfo.SetAddSpace(encodingData[6]);
       
  2891 			headerencodinginfo.SetEncodedLength(encodingData[7]); 
       
  2892 			iEncodingInfo->AppendL(headerencodinginfo);
       
  2893 			encodingData.Reset();	
       
  2894 
       
  2895 			if(firstSemiColonPos != lastSemiColonPos)
       
  2896 				{
       
  2897 				aEncodingStr.Set(aEncodingStr.Mid(firstSemiColonPos+1,aEncodingStr.Length()-firstSemiColonPos-1));
       
  2898 				firstSemiColonPos = aEncodingStr.Locate(';');
       
  2899 				lastSemiColonPos = aEncodingStr.LocateReverse(';');
       
  2900 				}
       
  2901 			else
       
  2902 				{
       
  2903 				break;
       
  2904 				}
       
  2905 			} while(ETrue);
       
  2906 
       
  2907 		encodingData.Close();
       
  2908 		}
       
  2909 	}
       
  2910 
       
  2911 
       
  2912 
       
  2913 
       
  2914 /**
       
  2915  * Stores mime header to a specified message store.
       
  2916  * @param aMessageStore Message store to write to.
       
  2917  * @return None.
       
  2918  */
       
  2919 
       
  2920 void CImMimeHeader::StoreMimeDBL(CMsvStore& aMessageStore) const
       
  2921 	{
       
  2922 	CHeaderFields* emailHeaderFields = new (ELeave)CHeaderFields();
       
  2923 	CleanupStack::PushL(emailHeaderFields);
       
  2924 	emailHeaderFields->iUid = KUidMsgFileMimeHeader;
       
  2925 
       
  2926 	//----------------------MIME Info From Filed 19th------------------------------	
       
  2927 	CFieldPair* emaildetailField = new (ELeave)CFieldPair();
       
  2928 	CleanupStack::PushL(emaildetailField);
       
  2929 
       
  2930 	//Make a string from  mime header info 
       
  2931 	RBuf8 mimeheaderinfo;
       
  2932 	CleanupClosePushL(mimeheaderinfo);
       
  2933 	mimeheaderinfo.CreateL(this->BufSize());
       
  2934 
       
  2935 	//Version
       
  2936 	mimeheaderinfo.AppendNum(Version());	
       
  2937 	mimeheaderinfo.Append(KDelimiter);
       
  2938 
       
  2939 	//iRelativePath
       
  2940 	mimeheaderinfo.Append(LimitStringSize(RelativePath(), KMaxImMimeFieldLength));
       
  2941 	mimeheaderinfo.Append(KDelimiter);
       
  2942 	
       
  2943 	//iContentType;
       
  2944 	mimeheaderinfo.Append(LimitStringSize(ContentType(), KMaxImMimeFieldLength));
       
  2945 	mimeheaderinfo.Append(KDelimiter);
       
  2946 	
       
  2947 	//iContentSubType;
       
  2948 	mimeheaderinfo.Append(LimitStringSize(ContentSubType(), KMaxImMimeFieldLength));
       
  2949 	mimeheaderinfo.Append(KDelimiter);
       
  2950 	
       
  2951 	//iContentTransferEncoding
       
  2952 	mimeheaderinfo.AppendNum(ContentTransferEncoding());	
       
  2953 	mimeheaderinfo.Append(KDelimiter);
       
  2954 
       
  2955 	//iContentDisposition
       
  2956 	mimeheaderinfo.Append(LimitStringSize(ContentDisposition(), KMaxImMimeFieldLength));
       
  2957 	mimeheaderinfo.Append(KDelimiter);
       
  2958 
       
  2959 	//iContentDescription
       
  2960 	mimeheaderinfo.Append(LimitStringSize(ContentDescription(), KMaxImMimeFieldLength));
       
  2961 	mimeheaderinfo.Append(KDelimiter);
       
  2962 
       
  2963 	//iContentBase
       
  2964 	mimeheaderinfo.Append(LimitStringSize(ContentBase(), KMaxImMimeFieldLength));
       
  2965 	mimeheaderinfo.Append(KDelimiter);
       
  2966 	
       
  2967 	//iContentLocation
       
  2968 	//16bit to 8bit
       
  2969 	HBufC8* newFrom = HBufC8::NewL((LimitStringSize(ContentLocation(), KMaxImMimeFieldLength)).Length());
       
  2970 	newFrom->Des().Copy(LimitStringSize(ContentLocation(), KMaxImMimeFieldLength));
       
  2971 	mimeheaderinfo.Append(newFrom->Des());
       
  2972 	mimeheaderinfo.Append(KDelimiter);
       
  2973 	delete newFrom;
       
  2974 	//iContentID
       
  2975 	mimeheaderinfo.Append(LimitStringSize(ContentID(), KMaxImMimeFieldLength));
       
  2976 	mimeheaderinfo.Append(KDelimiter);
       
  2977 	
       
  2978 	//iContentTypeParams
       
  2979 	for(TInt i=0 ; i<iContentTypeParams->MdcaCount() ; i++)
       
  2980 		{
       
  2981 		mimeheaderinfo.Append(iContentTypeParams->MdcaPoint(i));
       
  2982 		if(i< (iContentTypeParams->MdcaCount())-1)
       
  2983 			mimeheaderinfo.Append(KComma);
       
  2984 		}
       
  2985 	mimeheaderinfo.Append(KDelimiter);
       
  2986 	
       
  2987 	//iContentDispositionParams
       
  2988 	for(TInt i=0 ; i<iContentDispositionParams->MdcaCount() ; i++)
       
  2989 		{
       
  2990 		mimeheaderinfo.Append(iContentDispositionParams->MdcaPoint(i));
       
  2991 		if(i<(iContentDispositionParams->MdcaCount())-1)
       
  2992 			mimeheaderinfo.Append(KComma);
       
  2993 		}
       
  2994 	mimeheaderinfo.Append(KDelimiter);
       
  2995 	
       
  2996 	//iXTypeParams
       
  2997 	for(TInt i=0 ; i<iXTypeParams->MdcaCount() ; i++)
       
  2998 		{
       
  2999 		mimeheaderinfo.Append(iXTypeParams->MdcaPoint(i));
       
  3000 		if(i<(iXTypeParams->MdcaCount())-1)
       
  3001 			mimeheaderinfo.Append(KComma);
       
  3002 		}
       
  3003 	mimeheaderinfo.Append(KDelimiter);
       
  3004 
       
  3005 	//iMimeCharset
       
  3006 	mimeheaderinfo.AppendNum(MimeCharset());	
       
  3007 	mimeheaderinfo.Append(KDelimiter);
       
  3008 	
       
  3009 	//----------------------MIME Info end 19 ------------------------------	
       
  3010 	// 8bit to 16bit
       
  3011 	HBufC* newFrom1 = HBufC::NewL(mimeheaderinfo.Length());
       
  3012 	newFrom1->Des().Copy(mimeheaderinfo);
       
  3013 	emaildetailField->iFieldTextValue = newFrom1;
       
  3014 	emailHeaderFields->iFieldPairList.AppendL(emaildetailField);
       
  3015 	CleanupStack::Pop();  // Rbuf
       
  3016 	CleanupStack::Pop(emaildetailField);
       
  3017 	
       
  3018 	TMsvWriteStore storeWriter(aMessageStore);
       
  3019 	storeWriter.AssignL(emailHeaderFields);
       
  3020 	storeWriter.CommitL();
       
  3021 	
       
  3022 
       
  3023 	mimeheaderinfo.Close();
       
  3024 	CleanupStack::Pop(emailHeaderFields);
       
  3025 	}
       
  3026 
       
  3027 
       
  3028 
       
  3029 
       
  3030 /**
       
  3031  * Create Buffer size for Mime header.
       
  3032  * @param  None.
       
  3033  * @return TInt size of the Mime hedaer.
       
  3034  */
       
  3035 
       
  3036 TInt CImMimeHeader::BufSize() const
       
  3037 	{
       
  3038 	TInt size = 4; 	// Version
       
  3039 	
       
  3040 	if(iRelativePath)
       
  3041 		size += Align4(iRelativePath->Size());
       
  3042 	if(iContentType)
       
  3043 		size += Align4(iContentType->Size());
       
  3044 	if(iContentSubType)
       
  3045 		size += Align4(iContentSubType->Size());
       
  3046 	if(iContentDisposition)
       
  3047 		size += Align4(iContentDisposition->Size());
       
  3048 	if(iContentDescription)
       
  3049 		size += Align4(iContentDescription->Size());
       
  3050 	if(iContentBase)
       
  3051 		size += Align4(iContentBase->Size());
       
  3052 	if(iContentLocation)
       
  3053 		size += Align4(iContentLocation->Size());
       
  3054 	if(iContentID)
       
  3055 		size += Align4(iContentID->Size());
       
  3056 	if(iContentDisposition)
       
  3057 		size += Align4(iContentDisposition->Size());
       
  3058 	
       
  3059 	size += sizeof(TImEncodingType);
       
  3060 	size += sizeof(TUint);			// iMimeCharset
       
  3061 	
       
  3062 	TInt i;
       
  3063 	for (i=0 ; i<ContentTypeParams().Count(); ++i)
       
  3064 		{
       
  3065 		size += Align4(ContentTypeParams()[i].Size()) + 1; // 1 for Comma.
       
  3066 		}
       
  3067 	for (i=0 ; i<ContentDispositionParams().Count(); ++i)
       
  3068 		{
       
  3069 		size += Align4(ContentDispositionParams()[i].Size()) + 1;
       
  3070 		}
       
  3071 	for (i=0 ; i<XTypeParams().Count(); ++i)
       
  3072 		{
       
  3073 		size += Align4(XTypeParams()[i].Size()) + 1;
       
  3074 		}
       
  3075 	return (size+14); //For Delimiter (;)
       
  3076 	}
       
  3077 
       
  3078 
       
  3079 
       
  3080 	
       
  3081 /**
       
  3082  * Restores Mime header to a specified message store.
       
  3083  * @param aMessageStore Message store to read from 
       
  3084  * @return None
       
  3085  */
       
  3086 
       
  3087 void CImMimeHeader::ReStoreMimeDBL(CMsvStore& aMessageStore)
       
  3088 	{
       
  3089 	CHeaderFields* RcvHeaderRow = NULL;
       
  3090 	TMsvReadStore storeReader(aMessageStore, KUidMsgFileMimeHeader);
       
  3091 	storeReader.ReadL(RcvHeaderRow);
       
  3092 		
       
  3093 	Reset();
       
  3094 
       
  3095 	TInt i = 0; //Mime Header storeed in 19th Filed of the Email Header table.
       
  3096 
       
  3097 	HBufC* 	mimeheaderinfo = RcvHeaderRow->iFieldPairList[i++]->iFieldTextValue ;
       
  3098 	TPtr16 mimeheaderinfoPtr = (mimeheaderinfo->Des());	
       
  3099 
       
  3100 	//Parsing the encodedheader string 
       
  3101 	TInt firstSemiColonPos = mimeheaderinfo->Locate(';');
       
  3102 	TInt lastSemiColonPos = mimeheaderinfo->LocateReverse(';');
       
  3103 	
       
  3104 	if(firstSemiColonPos != lastSemiColonPos) // Expected MIME string :-0; 
       
  3105 	    {
       
  3106         RPointerArray<HBufC16>  mimeheaderinfoData;
       
  3107         CleanupClosePushL(mimeheaderinfoData);
       
  3108         TInt index = 0 ;
       
  3109     
       
  3110         do
       
  3111             {
       
  3112             TPtrC16 str1 = mimeheaderinfoPtr.Left(firstSemiColonPos); // First data
       
  3113             HBufC16* tt3 = str1.AllocL();
       
  3114             firstSemiColonPos++;
       
  3115             mimeheaderinfoData.AppendL(tt3); 
       
  3116             
       
  3117             if(firstSemiColonPos != lastSemiColonPos)
       
  3118                 {
       
  3119                 mimeheaderinfoPtr = (mimeheaderinfoPtr.Mid(firstSemiColonPos,mimeheaderinfoPtr.Length()-(firstSemiColonPos) ));
       
  3120                 firstSemiColonPos = mimeheaderinfoPtr.Locate(';');
       
  3121                 lastSemiColonPos = mimeheaderinfoPtr.LocateReverse(';');
       
  3122                 if(firstSemiColonPos == lastSemiColonPos)
       
  3123                     {
       
  3124                     TPtrC16 str1 = mimeheaderinfoPtr.Left(firstSemiColonPos); // Last data
       
  3125                     mimeheaderinfoData.AppendL(str1.AllocL()); 
       
  3126                     }
       
  3127                 }
       
  3128             
       
  3129             index++;	
       
  3130             }while(firstSemiColonPos != lastSemiColonPos);
       
  3131     
       
  3132             iVersion = ConvertToTInt(*mimeheaderinfoData[0]);
       
  3133             iRelativePath = Convert16to8L(*mimeheaderinfoData[1]);
       
  3134             iContentType  = Convert16to8L(*mimeheaderinfoData[2]);
       
  3135             iContentSubType = Convert16to8L(*mimeheaderinfoData[3]);
       
  3136             TInt ContentTransferEncodingint = ConvertToTInt(*mimeheaderinfoData[4]);
       
  3137             iContentTransferEncoding = (TImEncodingType)(ContentTransferEncodingint);
       
  3138             iContentDisposition = Convert16to8L(*mimeheaderinfoData[5]);
       
  3139             iContentDescription = Convert16to8L(*mimeheaderinfoData[6]);
       
  3140             iContentBase = Convert16to8L(*mimeheaderinfoData[7]);
       
  3141             iContentLocation = mimeheaderinfoData[8]->Des().AllocL();
       
  3142             iContentID = Convert16to8L(*mimeheaderinfoData[9]);
       
  3143             
       
  3144             //iContentTypeParams
       
  3145             if ((mimeheaderinfoData[10]->Des().Locate(',')) > -1 )
       
  3146                 {
       
  3147                 CreateMimeArrayListL(mimeheaderinfoData[10]->Des(),0); //To
       
  3148                 }
       
  3149             else
       
  3150                 {
       
  3151                 if(mimeheaderinfoData[10]->Length()>0)
       
  3152                     iContentTypeParams->AppendL(Convert16to8L(*mimeheaderinfoData[10])->Des());
       
  3153                 }
       
  3154         
       
  3155             //iContentDispositionParams
       
  3156             if ((mimeheaderinfoData[11]->Des().Locate(',')) > -1 )
       
  3157                 {
       
  3158                 CreateMimeArrayListL(mimeheaderinfoData[11]->Des(),1); //To
       
  3159                 }
       
  3160             else
       
  3161                 {
       
  3162                 if(mimeheaderinfoData[11]->Length()>0)
       
  3163                     iContentDispositionParams->AppendL(Convert16to8L(*mimeheaderinfoData[11])->Des());
       
  3164                 }
       
  3165         
       
  3166             //iXTypeParams
       
  3167             if ((mimeheaderinfoData[12]->Des().Locate(',')) > -1 )
       
  3168                 {
       
  3169                 CreateMimeArrayListL(mimeheaderinfoData[12]->Des(),2); //To
       
  3170                 }
       
  3171             else
       
  3172                 {
       
  3173                 if(mimeheaderinfoData[12]->Length()>0)
       
  3174                     iXTypeParams->AppendL(Convert16to8L(*mimeheaderinfoData[12])->Des());
       
  3175                 }
       
  3176     
       
  3177         iMimeCharset = ConvertToTInt(*mimeheaderinfoData[13]);
       
  3178         
       
  3179         mimeheaderinfoData.ResetAndDestroy();
       
  3180         mimeheaderinfoData.Close();
       
  3181         CleanupStack::Pop();   //RpointerArray
       
  3182 	    }// End of if(firstSemiColonPos != lastSemiColonPos)
       
  3183 	else
       
  3184 	    {
       
  3185 	    iMimeCharset = 0; // As Mime String is 0; Setting MimeCharacterSet 0
       
  3186 	    }
       
  3187 	}
       
  3188 
       
  3189 /**
       
  3190  * Create Mime Header List from a string.
       
  3191  * @param  aStr  A descripter String.
       
  3192  * @return None.
       
  3193  */
       
  3194 void CImMimeHeader::CreateMimeArrayListL(TPtrC16 aStr ,TInt aI)
       
  3195 	{
       
  3196 	TInt startPos = aStr.Locate(',') ;
       
  3197 	while(startPos > -1 )
       
  3198 		{
       
  3199 		TPtrC16 str2 = aStr.Left(startPos);
       
  3200 		if(aI == 0)
       
  3201 			{
       
  3202 			//iContentTypeParams
       
  3203 			iContentTypeParams->AppendL(Convert16to8L(str2)->Des());	
       
  3204 			}
       
  3205 		if(aI == 1)
       
  3206 			{
       
  3207 			//iContentDispositionParams
       
  3208 			iContentDispositionParams->AppendL(Convert16to8L(str2)->Des());
       
  3209 			}
       
  3210 		if( aI == 2)
       
  3211 			{
       
  3212 			//iXTypeParams
       
  3213 			iXTypeParams->AppendL(Convert16to8L(str2)->Des());
       
  3214 			}
       
  3215 		startPos++;
       
  3216 		aStr.Set(aStr.Mid(startPos, aStr.Length()- startPos));
       
  3217 	
       
  3218 		startPos = aStr.Locate(',');
       
  3219 		if(startPos == -1)
       
  3220 			{
       
  3221 			if(aStr.Length() > 0)
       
  3222 				{
       
  3223 				if(aI == 0)
       
  3224 					{
       
  3225 					//iContentTypeParams
       
  3226 					iContentTypeParams->AppendL(Convert16to8L(aStr)->Des());	
       
  3227 					}
       
  3228 				if(aI == 1)
       
  3229 					{
       
  3230 					//iContentDispositionParams
       
  3231 					iContentDispositionParams->AppendL(Convert16to8L(aStr)->Des());
       
  3232 					}
       
  3233 				if( aI == 2)
       
  3234 					{
       
  3235 					//iXTypeParams
       
  3236 					iXTypeParams->AppendL(Convert16to8L(aStr)->Des());
       
  3237 					}
       
  3238 					
       
  3239 				break;
       
  3240 				} //if(aStr.Length() > 0)
       
  3241 			} //if(startPos == -1)
       
  3242 		} //while(startPos >= -1 )
       
  3243 	}
       
  3244 
       
  3245 #endif