emailservices/emailcommon/src/CFSMailMessagePart.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  common email part object
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 
       
    20 //<qmail>
       
    21 #include <nmcommonheaders.h>
       
    22 //</qmail>
       
    23 
       
    24 #include <apgcli.h>
       
    25 #include <apmrec.h>
       
    26 #include <mmf/common/mmfcontrollerpluginresolver.h> // CleanupResetAndDestroy
       
    27 
       
    28 //<cmail>
       
    29 #include "CFSMailMessagePart.h"
       
    30 #include "CFSMailPlugin.h"
       
    31 //</cmail>
       
    32 
       
    33 #include "CFSMailRequestObserver.h"
       
    34 
       
    35 //<qmail>
       
    36 #include "nmmessagepart.h"
       
    37 #include "nmconverter.h"
       
    38 //</qmail>
       
    39 
       
    40 
       
    41 // ================= MEMBER FUNCTIONS ==========================================
       
    42 // -----------------------------------------------------------------------------
       
    43 // CFSMailMessagePart::NewLC
       
    44 // -----------------------------------------------------------------------------
       
    45 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::NewLC( TFSMailMsgId aMessageId,
       
    46 														TFSMailMsgId aMessagePartId )
       
    47 {
       
    48     NM_FUNCTION;
       
    49     
       
    50     CFSMailMessagePart* adr = new (ELeave) CFSMailMessagePart();
       
    51     CleanupStack::PushL(adr);
       
    52     adr->ConstructL( aMessageId, aMessagePartId );
       
    53     return adr;
       
    54 } 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CFSMailMessagePart::NewL
       
    58 // -----------------------------------------------------------------------------
       
    59 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::NewL(	TFSMailMsgId aMessageId,
       
    60 														TFSMailMsgId aMessagePartId )
       
    61 {
       
    62     NM_FUNCTION;
       
    63     
       
    64     CFSMailMessagePart* adr =  CFSMailMessagePart::NewLC( aMessageId, aMessagePartId );
       
    65     CleanupStack::Pop(adr);
       
    66     return adr;
       
    67 }
       
    68 
       
    69 //<qmail>
       
    70 // -----------------------------------------------------------------------------
       
    71 // CFSMailMessagePart::NewLC
       
    72 // -----------------------------------------------------------------------------
       
    73 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::NewLC(const NmId &aNmMessageId,
       
    74     const NmMessagePart& aNmMessage )
       
    75 {
       
    76     NM_FUNCTION;
       
    77     
       
    78 	CFSMailMessagePart* self = new (ELeave) CFSMailMessagePart();
       
    79 	CleanupStack::PushL(self);
       
    80 	self->ConstructL( aNmMessageId,aNmMessage );
       
    81 	return self;
       
    82 } 
       
    83 //</qmail>
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CFSMailMessagePart::ConstructL
       
    87 // -----------------------------------------------------------------------------
       
    88 void CFSMailMessagePart::ConstructL( TFSMailMsgId aMessageId,
       
    89                                      TFSMailMsgId aMessagePartId )
       
    90 {
       
    91     NM_FUNCTION;
       
    92     
       
    93 //<qmail>
       
    94 	// Base class initialization
       
    95     CFSMailMessageBase::ConstructL(aMessageId);
       
    96 	
       
    97 	iNmPrivateMessagePart = new NmMessagePartPrivate();
       
    98 	
       
    99 	iNmPrivateMessagePart->mPartId.setId32(aMessagePartId.Id());
       
   100 	iNmPrivateMessagePart->mPartId.setPluginId32((quint32)aMessagePartId.PluginId().iUid);
       
   101 		
       
   102 	iMessagePartsStatus = EFSDefault;
       
   103 
       
   104 	iContentTypeParams  = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   105 	iContentDispositionParams = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   106 //</qmail>
       
   107 }
       
   108 
       
   109 //<qmail>
       
   110 // -----------------------------------------------------------------------------
       
   111 // CFSMailMessagePart::ConstructL
       
   112 // -----------------------------------------------------------------------------
       
   113 void CFSMailMessagePart::ConstructL( const NmId &aNmMessageId,const NmMessagePart& aNmMessage )
       
   114 {
       
   115     NM_FUNCTION;
       
   116     
       
   117     // Base class initialization
       
   118     CFSMailMessageBase::ConstructL(TFSMailMsgId(aNmMessageId));
       
   119     
       
   120     iNmPrivateMessagePart = aNmMessage.d;
       
   121            
       
   122     iMessagePartsStatus = EFSDefault;
       
   123 
       
   124     iContentTypeParams  = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   125     iContentDispositionParams = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   126 
       
   127 }
       
   128 //</qmail>
       
   129 
       
   130 //<qmail>
       
   131 // -----------------------------------------------------------------------------
       
   132 // CFSMailMessagePart::ConstructL
       
   133 // -----------------------------------------------------------------------------
       
   134 void CFSMailMessagePart::ConstructL(
       
   135     const NmMessagePart& aNmMessage,
       
   136     const NmMessageEnvelope& aNmMessageEnvelope)
       
   137 {
       
   138     NM_FUNCTION;
       
   139     
       
   140     // Base class initialization
       
   141     CFSMailMessageBase::ConstructL(aNmMessageEnvelope);
       
   142     
       
   143     iNmPrivateMessagePart = aNmMessage.d;
       
   144            
       
   145     iMessagePartsStatus = EFSDefault;
       
   146 
       
   147     iContentTypeParams  = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   148     iContentDispositionParams = new (ELeave)CDesCArrayFlat( KArrayGranularity );
       
   149 
       
   150 }
       
   151 //</qmail>
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CFSMailMessagePart::~CFSMailMessagePart
       
   155 // -----------------------------------------------------------------------------
       
   156 EXPORT_C CFSMailMessagePart::~CFSMailMessagePart()
       
   157 {
       
   158     NM_FUNCTION;
       
   159     
       
   160 //<qmail> iContentType, iContentDescription, iContentDisposition, iContentID removed </qmail>
       
   161 	if(iAttachmentName)
       
   162 	{
       
   163 		delete iAttachmentName;
       
   164 	}
       
   165  	iAttachmentName = NULL;
       
   166 
       
   167 	if(iContentClass)
       
   168 	{
       
   169 		delete iContentClass;
       
   170 	}
       
   171  	iContentClass = NULL;
       
   172 
       
   173 	if(iMeetingRequest)
       
   174 	{
       
   175 		delete iMeetingRequest;
       
   176 	}
       
   177 	iMeetingRequest = NULL;
       
   178 
       
   179 	if(iContentDispositionParams)
       
   180 		{
       
   181 	    iContentDispositionParams->Reset();
       
   182 	    delete iContentDispositionParams;
       
   183 		}
       
   184 	if(iContentTypeParams)
       
   185 		{
       
   186 	    iContentTypeParams->Reset();
       
   187 	    delete iContentTypeParams;		
       
   188 		}
       
   189 	
       
   190 	iMessageParts.ResetAndDestroy();
       
   191 }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CFSMailMessagePart::CFSMailMessagePart
       
   195 // -----------------------------------------------------------------------------
       
   196 CFSMailMessagePart::CFSMailMessagePart() : CFSMailMessageBase()
       
   197 {
       
   198     NM_FUNCTION;
       
   199 	
       
   200 //<qmail> iContentType, iContentDescription, iContentDisposition, iContentID removed </qmail>
       
   201 	iContentClass = HBufC::New(1);
       
   202 	iContentClass->Des().Copy(KNullDesC());
       
   203 
       
   204 	iAttachmentName = HBufC::New(1);
       
   205 	iAttachmentName->Des().Copy(KNullDesC());
       
   206 
       
   207 	iReadMessageParts = ETrue;
       
   208 }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CFSMailMessagePart::GetContentType
       
   212 // -----------------------------------------------------------------------------
       
   213 EXPORT_C const TDesC& CFSMailMessagePart::GetContentType() const
       
   214 {
       
   215     NM_FUNCTION;
       
   216     
       
   217 //<qmail>
       
   218     iContentTypePtr.Set(reinterpret_cast<const TUint16*> (iNmPrivateMessagePart->mContentType.utf16()),
       
   219     		iNmPrivateMessagePart->mContentType.length());
       
   220     return iContentTypePtr;
       
   221 //</qmail>
       
   222 }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CFSMailMessagePart::SetContentType
       
   226 // -----------------------------------------------------------------------------
       
   227 EXPORT_C void CFSMailMessagePart::SetContentType(const TDesC& aContentType)
       
   228 {
       
   229     NM_FUNCTION;
       
   230     
       
   231 //<qmail>
       
   232     QString qtContentType = QString::fromUtf16(aContentType.Ptr(), aContentType.Length());
       
   233     iNmPrivateMessagePart->mContentType = qtContentType;
       
   234 //</qmail>
       
   235 }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CFSMailMessagePart::GetPartId
       
   239 // -----------------------------------------------------------------------------
       
   240 EXPORT_C TFSMailMsgId CFSMailMessagePart::GetPartId() const
       
   241 {
       
   242     NM_FUNCTION;
       
   243     
       
   244 //<qmail>
       
   245     return TFSMailMsgId(iNmPrivateMessagePart->mPartId);
       
   246 //</qmail>	
       
   247 }
       
   248 
       
   249 //<qmail>
       
   250 // -----------------------------------------------------------------------------
       
   251 // CFSMailMessagePart::ChildPartsL
       
   252 // -----------------------------------------------------------------------------
       
   253 EXPORT_C void CFSMailMessagePart::ChildPartsL( RPointerArray<CFSMailMessagePart>& aParts,
       
   254     TFSMailMessagePartDataSource aDataSource)
       
   255 	{
       
   256     NM_FUNCTION;
       
   257 
       
   258     if (aDataSource == EDataSourceMessageStore)
       
   259         {
       
   260         if (CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
       
   261             {
       
   262             plugin->ChildPartsL(GetMailBoxId(), GetFolderId(),
       
   263                     GetMessageId(), GetPartId(), aParts);
       
   264             }
       
   265         }
       
   266     else
       
   267         {
       
   268         int count = iNmPrivateMessagePart->mChildParts.count();
       
   269         for (int i = 0; i < count; i++)
       
   270             {
       
   271             CFSMailMessagePart* part = CFSMailMessagePart::NewLC(
       
   272                     NmConverter::mailMsgIdToNmId(GetMessageId()),
       
   273                     *iNmPrivateMessagePart->mChildParts[i]);
       
   274             aParts.AppendL(part);
       
   275             CleanupStack::Pop(part);
       
   276             }
       
   277 		}
       
   278 	}
       
   279 //</qmail>
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CFSMailMessagePart::ChildPartL
       
   283 // -----------------------------------------------------------------------------
       
   284 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::ChildPartL(TFSMailMsgId aPartId)
       
   285 	{
       
   286     NM_FUNCTION;
       
   287 	
       
   288 	CFSMailMessagePart* part = NULL;
       
   289 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
       
   290 		{
       
   291 		part = plugin->MessagePartL(GetMailBoxId(),
       
   292 									GetFolderId(),
       
   293 									GetMessageId(),
       
   294 									aPartId);
       
   295 		}
       
   296 	return part;
       
   297 	}
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CFSMailMessagePart::IsMessageL
       
   301 // -----------------------------------------------------------------------------
       
   302 EXPORT_C TBool CFSMailMessagePart::IsMessageL() const
       
   303 	{
       
   304     NM_FUNCTION;
       
   305 
       
   306 	TBuf<KMaxDataTypeLength> ptr;
       
   307 //<qmail>
       
   308     if ( !iNmPrivateMessagePart->mContentType.isNull() ) 
       
   309     {
       
   310 		ptr.Copy(GetContentType());
       
   311 //</qmail>
       
   312 		TInt length = ptr.Locate(';');
       
   313 		if(length >= 0)
       
   314 			{
       
   315 			ptr.SetLength(length);
       
   316 			}
       
   317 		
       
   318 		if( !ptr.CompareF(KFSMailContentTypeMessage) )
       
   319 		{
       
   320 			return ETrue;
       
   321 		}
       
   322     }
       
   323 	return EFalse;
       
   324 	}
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CFSMailMessagePart::NewChildPartL
       
   328 // -----------------------------------------------------------------------------
       
   329 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::NewChildPartL( const TFSMailMsgId aInsertBefore,
       
   330 																const TDesC& aContentType )
       
   331 	{
       
   332     NM_FUNCTION;
       
   333 
       
   334 	CFSMailMessagePart* part = NULL;
       
   335 	
       
   336 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
       
   337 		{
       
   338 		part = plugin->NewChildPartL( 	GetMailBoxId(), GetFolderId(), GetMessageId(),
       
   339 								 		GetPartId(), aInsertBefore, aContentType );
       
   340 		}
       
   341 	return part;
       
   342 	}
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // CFSMailMessagePart::RemoveChildPartL
       
   346 // -----------------------------------------------------------------------------
       
   347 EXPORT_C void CFSMailMessagePart::RemoveChildPartL(TFSMailMsgId aPartId)
       
   348 {
       
   349     NM_FUNCTION;
       
   350     
       
   351 	// get plugin pointer
       
   352 	TFSMailMsgId id = GetPartId();
       
   353 	if(id.IsNullId())
       
   354 		{
       
   355 		id = GetMessageId();
       
   356 		}
       
   357 	CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(id);
       
   358 	
       
   359 	if(plugin)
       
   360 		{
       
   361 		plugin->RemoveChildPartL( GetMailBoxId(), GetFolderId(), GetMessageId(), GetPartId(), aPartId );
       
   362 		}
       
   363 	}
       
   364 	
       
   365 // <qmail>
       
   366 // -----------------------------------------------------------------------------
       
   367 // CFSMailMessagePart::RemoveChildPartL
       
   368 // -----------------------------------------------------------------------------
       
   369 EXPORT_C TInt CFSMailMessagePart::RemoveChildPartL( TFSMailMsgId aPartId,
       
   370                                                     MFSMailRequestObserver& aOperationObserver)
       
   371 {
       
   372     NM_FUNCTION;
       
   373     
       
   374     TFSPendingRequest request;
       
   375     // get plugin pointer
       
   376     TFSMailMsgId id = GetPartId();
       
   377     if(id.IsNullId())
       
   378         {
       
   379         id = GetMessageId();
       
   380         }
       
   381     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(id);
       
   382 
       
   383     if(plugin)
       
   384         {
       
   385         request = iRequestHandler->InitAsyncRequestL( id.PluginId(),
       
   386                                                       aOperationObserver );
       
   387         
       
   388         MFSMailRequestObserver* observer = request.iObserver;
       
   389         
       
   390         TRAPD(err, plugin->RemoveChildPartL( GetMailBoxId(),
       
   391             GetFolderId(),
       
   392             GetMessageId(),
       
   393             GetPartId(),
       
   394             aPartId,
       
   395             *observer,
       
   396             request.iRequestId));
       
   397         
       
   398         if( err != KErrNone )
       
   399             {
       
   400             iRequestHandler->CompleteRequest( request.iRequestId );
       
   401             User::Leave( err );
       
   402             }
       
   403         }
       
   404     else
       
   405         {
       
   406         User::Leave( KErrNotFound );
       
   407         }
       
   408     
       
   409     return request.iRequestId;
       
   410 }
       
   411 // </qmail>
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CFSMailMessagePart::GetContentClass
       
   415 // -----------------------------------------------------------------------------
       
   416 EXPORT_C const TDesC& CFSMailMessagePart::GetContentClass()
       
   417 	{
       
   418     NM_FUNCTION;
       
   419     
       
   420 		return *iContentClass;
       
   421 	}
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // CFSMailMessagePart::SetContentClass
       
   425 // -----------------------------------------------------------------------------
       
   426 EXPORT_C void CFSMailMessagePart::SetContentClass( const TDesC& aContentClass )
       
   427 	{
       
   428     NM_FUNCTION;
       
   429 
       
   430 	// 
       
   431 	HBufC* contentClass = HBufC::New(aContentClass.Length());
       
   432 	
       
   433 	// store new mailbox name
       
   434 	delete iContentClass;
       
   435 	iContentClass = contentClass;
       
   436 	iContentClass->Des().Copy(aContentClass);
       
   437 	iContentClass->ReAlloc(aContentClass.Length());
       
   438 	iContentClass->Des().Copy(aContentClass);		
       
   439 	}
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // CFSMailMessagePart::ContentSize
       
   443 // -----------------------------------------------------------------------------
       
   444 EXPORT_C TUint CFSMailMessagePart::ContentSize() const
       
   445 	{
       
   446     NM_FUNCTION;
       
   447     
       
   448 //<qmail>
       
   449     return (TUint)iNmPrivateMessagePart->mSize;
       
   450 //</qmail>
       
   451 	}
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CFSMailMessagePart::SetContentSize
       
   455 // -----------------------------------------------------------------------------
       
   456 EXPORT_C void CFSMailMessagePart::SetContentSize( TUint aContentSize )
       
   457 	{
       
   458     NM_FUNCTION;
       
   459     
       
   460 //<qmail>
       
   461     iNmPrivateMessagePart->mSize = quint32(aContentSize);
       
   462 //</qmail>
       
   463 	}
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CFSMailMessagePart::ContentID
       
   467 // -----------------------------------------------------------------------------
       
   468 EXPORT_C const TDesC& CFSMailMessagePart::ContentID()
       
   469 	{
       
   470     NM_FUNCTION;
       
   471     
       
   472 //<qmail>	
       
   473     iContentIDPtr.Set(reinterpret_cast<const TUint16*> (iNmPrivateMessagePart->mContentId.utf16()),
       
   474     		iNmPrivateMessagePart->mContentId.length());
       
   475     return iContentIDPtr;	
       
   476 //</qmail>
       
   477 	}
       
   478 	
       
   479 // -----------------------------------------------------------------------------
       
   480 // CFSMailMessagePart::SetContentIDL
       
   481 // -----------------------------------------------------------------------------
       
   482 EXPORT_C void CFSMailMessagePart::SetContentIDL(const TDesC& aContentID)
       
   483 	{
       
   484     NM_FUNCTION;
       
   485     
       
   486 //<qmail>
       
   487     QString qtContentID = QString::fromUtf16(aContentID.Ptr(), aContentID.Length());
       
   488     iNmPrivateMessagePart->mContentId = qtContentID;    
       
   489 //</qmail>    
       
   490 	}
       
   491 	
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CFSMailMessagePart::GetContentFileL
       
   495 // -----------------------------------------------------------------------------
       
   496 EXPORT_C RFile CFSMailMessagePart::GetContentFileL()
       
   497 	{
       
   498     NM_FUNCTION;
       
   499 	
       
   500 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
   501 		{
       
   502 		TInt rcode = plugin->GetMessagePartFileL( GetMailBoxId(), GetFolderId(),
       
   503 					                            GetMessageId(), GetPartId(),
       
   504 					                            iFile );
       
   505 		// if content is encrypted, use temp dir files
       
   506 		if(rcode == KErrNotSupported)
       
   507 		    {
       
   508 		    // temp directory C:\Private\<uid>
       
   509 		    TFileName fileName;
       
   510 		    iFile = iRequestHandler->GetTempFileL(GetPartId(),fileName);
       
   511 		    plugin->CopyMessagePartFileL(GetMailBoxId(), GetFolderId(),
       
   512 		                                 GetMessageId(), GetPartId(),
       
   513 		                                 fileName);
       
   514 		    }
       
   515 		}
       
   516 	
       
   517 	return iFile;
       
   518 	}
       
   519 
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CFSMailMessagePart::GetContentToBufferL
       
   523 // -----------------------------------------------------------------------------
       
   524 EXPORT_C void CFSMailMessagePart::GetContentToBufferL(TDes16& aBuffer, TUint aStartOffset)
       
   525 	{
       
   526     NM_FUNCTION;
       
   527     
       
   528 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
   529 		{
       
   530 		plugin->GetContentToBufferL( GetMailBoxId(), GetFolderId(), GetMessageId(),
       
   531 									 GetPartId(), aBuffer, aStartOffset );
       
   532 		}
       
   533 	}
       
   534 	
       
   535 // -----------------------------------------------------------------------------
       
   536 // CFSMailMessagePart::SetContent
       
   537 // -----------------------------------------------------------------------------
       
   538 EXPORT_C void CFSMailMessagePart::SetContent( TDes16& aBuffer )
       
   539 	{
       
   540     NM_FUNCTION;
       
   541     
       
   542 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
   543 		{
       
   544 // <qmail>
       
   545         TRAP_IGNORE(plugin->SetContentL( aBuffer, GetMailBoxId(), GetFolderId(),
       
   546             GetMessageId(), GetPartId() ));
       
   547 // </qmail>
       
   548         }
       
   549 	}
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // CFSMailMessagePart::ContentDescription
       
   553 // -----------------------------------------------------------------------------
       
   554 EXPORT_C const TDesC& CFSMailMessagePart::ContentDescription()
       
   555 	{
       
   556     NM_FUNCTION;
       
   557     
       
   558 //<qmail>
       
   559     iContentDescriptionPtr.Set(reinterpret_cast<const TUint16*> (
       
   560             iNmPrivateMessagePart->mContentDescription.utf16()),
       
   561     		iNmPrivateMessagePart->mContentDescription.length());
       
   562     
       
   563     return iContentDescriptionPtr;
       
   564 //</qmail>
       
   565 	}
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // CFSMailMessagePart::SetContentDescription
       
   569 // -----------------------------------------------------------------------------
       
   570 EXPORT_C void CFSMailMessagePart::SetContentDescription( const TDesC& aContentDescription )
       
   571 	{
       
   572     NM_FUNCTION;
       
   573     
       
   574 //<qmail>
       
   575     QString qtContentDescription = QString::fromUtf16(
       
   576             aContentDescription.Ptr(), aContentDescription.Length());
       
   577     iNmPrivateMessagePart->mContentDescription = qtContentDescription;
       
   578 //</qmail>
       
   579 	}
       
   580 // -----------------------------------------------------------------------------
       
   581 // CFSMailMessagePart::ContentDisposition
       
   582 // -----------------------------------------------------------------------------
       
   583 EXPORT_C const TDesC& CFSMailMessagePart::ContentDisposition()
       
   584 	{
       
   585     NM_FUNCTION;
       
   586     
       
   587 //<qmail>
       
   588 	iContentDispositionPtr.Set(reinterpret_cast<const TUint16*> (
       
   589 	        iNmPrivateMessagePart->mContentDisposition.utf16()),
       
   590 			iNmPrivateMessagePart->mContentDisposition.length());
       
   591 	return iContentDispositionPtr;
       
   592 //</qmail>
       
   593 	}
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CFSMailMessagePart::SetContentDisposition
       
   597 // -----------------------------------------------------------------------------
       
   598 EXPORT_C void CFSMailMessagePart::SetContentDisposition( const TDesC& aContentDisposition )
       
   599 	{
       
   600     NM_FUNCTION;
       
   601     
       
   602 //<qmail>
       
   603     QString qtContentDisposition = QString::fromUtf16(
       
   604             aContentDisposition.Ptr(), aContentDisposition.Length());
       
   605     iNmPrivateMessagePart->mContentDisposition = qtContentDisposition;
       
   606 //</qmail>
       
   607 	}
       
   608 
       
   609 // -----------------------------------------------------------------------------
       
   610 // CFSMailMessagePart::ContentTypeParameters
       
   611 // -----------------------------------------------------------------------------
       
   612 EXPORT_C CDesCArray& CFSMailMessagePart::ContentTypeParameters()
       
   613 	{
       
   614     NM_FUNCTION;
       
   615     
       
   616 //<qmail>	
       
   617     if (iNmPrivateMessagePart->mContentType.isNull())
       
   618 		{
       
   619 		return *iContentTypeParams;
       
   620 		}
       
   621 	
       
   622 	// clear parameter table
       
   623 	iContentTypeParams->Reset();
       
   624 	TInt ret = KErrNone;
       
   625 	
       
   626 	// check content type parameters existence
       
   627 	TInt index = GetContentType().Locate(';');
       
   628 //</qmail>	
       
   629 	if(index >= 0)
       
   630 		{
       
   631 		TInt attLength(0);
       
   632 		TInt valueLength(0);
       
   633 		while(index >= 0)
       
   634 			{
       
   635 			TPtrC attribute;
       
   636 			TPtrC value;
       
   637 			HBufC* buf;
       
   638 			
       
   639 			// set pointer to first parameter
       
   640 //<qmail>
       
   641 			TPtrC parameter = GetContentType().Mid(index+1);
       
   642 //</qmail>
       
   643 			attLength = parameter.Locate('=');
       
   644 			if(attLength >= 0)
       
   645 				{
       
   646 				attribute.Set(parameter.Left(attLength));
       
   647 		  		valueLength = parameter.Locate(';');
       
   648 			  	if(valueLength < 0)
       
   649 			  		{
       
   650 				  	value.Set( parameter.Right(parameter.Length()-attLength-1) );
       
   651 				  	index = -1;
       
   652 			  		}
       
   653 			  	else
       
   654 			  		{
       
   655 				  	value.Set(parameter.Mid(attLength+1,(valueLength-attLength-1)));
       
   656 					index += valueLength + 1;			  		
       
   657 			  		}
       
   658 				}
       
   659 			else
       
   660 				{
       
   661 		  		attLength = parameter.Locate(';');
       
   662 			  	if(attLength < 0)
       
   663 			  		{
       
   664 				  	attribute.Set(parameter);
       
   665 				  	index = -1;
       
   666 			  		}
       
   667 			  	else
       
   668 			  		{
       
   669 					attribute.Set(parameter.Left(attLength));
       
   670 				  	index += attLength + 1;
       
   671 			  		}
       
   672 			  	}
       
   673 			
       
   674 			if(attribute.Length())
       
   675 				{
       
   676 				buf = HBufC::New(attribute.Length());
       
   677 				buf->Des().Copy(attribute);
       
   678 				TRAPD(err,iContentTypeParams->AppendL(buf->Des()));
       
   679 				if(value.Length() && err == KErrNone)
       
   680 					{
       
   681 					buf = HBufC::New(value.Length());
       
   682 					buf->Des().Copy(value);
       
   683 					TRAP(err,iContentTypeParams->AppendL(buf->Des()));
       
   684 					ret = err;
       
   685 					}
       
   686 				else
       
   687 					{
       
   688 					TBufC<1> empty(KNullDesC);
       
   689 					HBufC* buf = HBufC::New(empty.Des().Length());
       
   690 					buf->Des().Copy(empty);
       
   691 					TRAP(err,iContentTypeParams->AppendL(buf->Des()));
       
   692 					ret = err;
       
   693 					}
       
   694     			}
       
   695     		}
       
   696     	}
       
   697 	
       
   698 	if(ret != KErrNone)
       
   699 		{
       
   700 		// clear parameter table
       
   701 		iContentTypeParams->Reset();
       
   702 		}
       
   703 		
       
   704 	return *iContentTypeParams;
       
   705     }
       
   706 
       
   707 // -----------------------------------------------------------------------------
       
   708 // CFSMailMessagePart::ContentDispositionParameters
       
   709 // -----------------------------------------------------------------------------
       
   710 EXPORT_C CDesCArray& CFSMailMessagePart::ContentDispositionParameters()
       
   711 	{
       
   712     NM_FUNCTION;
       
   713 	
       
   714 //<qmail>
       
   715     const TDesC& contentDisposition = ContentDisposition();
       
   716     
       
   717 	if(!contentDisposition.Ptr())
       
   718 		{
       
   719 		return *iContentDispositionParams;
       
   720 		}
       
   721 //</qmail>
       
   722 	
       
   723 	// clear parameter array
       
   724 	iContentDispositionParams->Reset();
       
   725 	TInt ret = KErrNone;
       
   726     
       
   727 	// check content disposition parameters existence
       
   728 //<qmail>
       
   729 	TInt index = contentDisposition.Locate(';');
       
   730 //</qmail>
       
   731 	if( index >= 0 )
       
   732 		{
       
   733 		TInt attLength(0);
       
   734 		TInt valueLength(0);
       
   735 		while(index >= 0)
       
   736 			{
       
   737 			TPtrC attribute;
       
   738 			TPtrC value;
       
   739 			
       
   740 			// set pointer to first parameter
       
   741 //<qmail>
       
   742 			TPtrC parameter = contentDisposition.Mid(index+1);
       
   743 //</qmail>
       
   744 			attLength = parameter.Locate('=');
       
   745 			if( attLength >= 0 )
       
   746 				{
       
   747 				attribute.Set(parameter.Left(attLength));
       
   748 		  		valueLength = parameter.Locate(';');
       
   749 			  	if( valueLength < 0 )
       
   750 			  		{
       
   751 				  	value.Set( parameter.Right(parameter.Length()-attLength-1) );
       
   752 				  	index = -1;
       
   753 			  		}
       
   754 			  	else
       
   755 			  		{
       
   756 				  	value.Set( parameter.Mid(attLength+1,(valueLength-attLength-1)) );
       
   757 					index += valueLength + 1;			  		
       
   758 			  		}
       
   759 				}
       
   760 			else
       
   761 				{
       
   762 		  		attLength = parameter.Locate(';');
       
   763 			  	if(attLength < 0)
       
   764 			  		{
       
   765 				  	attribute.Set(parameter);
       
   766 				  	index = -1;
       
   767 			  		}
       
   768 			  	else
       
   769 			  		{
       
   770 					attribute.Set(parameter.Left(attLength));
       
   771 				  	index += attLength + 1;
       
   772 			  		}
       
   773 			  	}
       
   774 		    
       
   775 			if(attribute.Length())
       
   776 				{
       
   777 				HBufC* attBuf = HBufC::New(attribute.Length());
       
   778 				attBuf->Des().Copy(attribute);
       
   779 				// let's trim the attribute before adding to array
       
   780 				TPtr attTrim( attBuf->Des() );
       
   781 				attTrim.Trim();
       
   782 				
       
   783 				if ( attTrim.Length() )
       
   784 				    {
       
   785 				    // add trimmed attribute to the array
       
   786 				    TRAPD(err,iContentDispositionParams->AppendL( attTrim ));
       
   787 				    
       
   788 				    if(value.Length() && err == KErrNone)
       
   789     					{
       
   790     					HBufC* valueBuf = HBufC::New(value.Length());
       
   791     					valueBuf->Des().Copy(value);
       
   792     					// let's trim also the value before adding to array
       
   793     					TPtr valueTrim( valueBuf->Des() );
       
   794     				    valueTrim.Trim();
       
   795     				    
       
   796     				    if ( valueTrim.Length() )
       
   797         				    {
       
   798         				    // add trimmed value to the array
       
   799         				    TRAPD(err,iContentDispositionParams->AppendL( valueTrim ));
       
   800 							ret = err;
       
   801         				    }
       
   802         				else
       
   803         				    {
       
   804         				    delete valueBuf;
       
   805         				    valueBuf = NULL;
       
   806         				    
       
   807         				    TBufC<1> empty(KNullDesC);
       
   808         					HBufC* emptyBuf = HBufC::New(empty.Des().Length());
       
   809         					emptyBuf->Des().Copy(empty);
       
   810         					TRAPD(err,iContentDispositionParams->AppendL(emptyBuf->Des()));
       
   811 							ret = err;
       
   812         				    }
       
   813     					}
       
   814     				else
       
   815     			        {
       
   816     			        TBufC<1> empty(KNullDesC);
       
   817     					HBufC* emptyBuf = HBufC::New(empty.Des().Length());
       
   818     					emptyBuf->Des().Copy(empty);
       
   819     					TRAPD(err,iContentDispositionParams->AppendL(emptyBuf->Des()));
       
   820     					ret = err;
       
   821     			        }
       
   822 				    }
       
   823 				else
       
   824 				    {
       
   825 				    delete attBuf;
       
   826 				    attBuf = NULL;
       
   827 				    }
       
   828 				}
       
   829     		} // while
       
   830     	}
       
   831 
       
   832 	if(ret != KErrNone)
       
   833 		{
       
   834 		// clear parameter table
       
   835 		iContentDispositionParams->Reset();
       
   836 		}
       
   837 	
       
   838 	return *iContentDispositionParams;
       
   839 	}
       
   840 
       
   841 // -----------------------------------------------------------------------------
       
   842 // CFSMailMessagePart::GetMRInfo
       
   843 // -----------------------------------------------------------------------------
       
   844 EXPORT_C MMRInfoObject& CFSMailMessagePart::GetMRInfo()
       
   845 {
       
   846     NM_FUNCTION;
       
   847     
       
   848 	return *iMeetingRequest;
       
   849 }
       
   850 
       
   851 // -----------------------------------------------------------------------------
       
   852 // CFSMailMessagePart::IsMRInfoSet
       
   853 // -----------------------------------------------------------------------------
       
   854 EXPORT_C TBool CFSMailMessagePart::IsMRInfoSet()
       
   855 {
       
   856     NM_FUNCTION;
       
   857     
       
   858 	if(iMeetingRequest)
       
   859 		{
       
   860 		return ETrue;
       
   861 		}
       
   862 	else
       
   863 		{
       
   864 		return EFalse;
       
   865 		}
       
   866 }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // CFSMailMessagePart::SetMRInfo
       
   870 // -----------------------------------------------------------------------------	
       
   871 EXPORT_C void CFSMailMessagePart::SetMRInfo(MMRInfoObject* aMeetingRequest)
       
   872 {
       
   873     NM_FUNCTION;
       
   874     
       
   875 	if(iMeetingRequest)
       
   876 	{
       
   877 		delete iMeetingRequest;
       
   878 	}
       
   879 	iMeetingRequest = aMeetingRequest;
       
   880 }
       
   881 
       
   882 // -----------------------------------------------------------------------------
       
   883 // CFSMailMessagePart::SaveL
       
   884 // -----------------------------------------------------------------------------
       
   885 EXPORT_C void CFSMailMessagePart::SaveL()
       
   886 	{
       
   887     NM_FUNCTION;
       
   888     
       
   889 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
   890 		{
       
   891 		plugin->StoreMessagePartL( GetMailBoxId(), GetFolderId(), GetMessageId(), *this );		
       
   892 		}
       
   893 	}
       
   894 
       
   895 
       
   896 // -----------------------------------------------------------------------------
       
   897 // CFSMailMessagePart::SetAttachmentNameL
       
   898 // -----------------------------------------------------------------------------
       
   899 EXPORT_C void CFSMailMessagePart::SetAttachmentNameL(const TDesC& aFilePath)
       
   900 	{
       
   901     NM_FUNCTION;
       
   902     
       
   903 	    // Parse file name in case full path is given
       
   904 		TPtrC name;
       
   905 		for(TInt i=0;i<aFilePath.Length();)
       
   906 			{
       
   907 			name.Set(aFilePath.Mid(i,(aFilePath.Length()-i)));
       
   908 			TInt skip = name.Locate(KPathDelimiter);
       
   909 			if(skip < 0) break;
       
   910 			else i += skip + 1;
       
   911 			}
       
   912 			
       
   913 	    // Set Content-Type param "name" = filename
       
   914 	    TUint length =  KFSMailContentTypeParamName.iTypeLength + name.Length() + 5;
       
   915 //<qmail>
       
   916 	    if (!iNmPrivateMessagePart->mContentType.isNull()) 
       
   917 			{
       
   918 			length += GetContentType().Length();
       
   919 	    	}
       
   920 
       
   921 	    HBufC* buffer = HBufC::NewL(length);
       
   922 	    if (!iNmPrivateMessagePart->mContentType.isNull()) 
       
   923 			{
       
   924 			buffer->Des().Append(GetContentType());
       
   925 	    	}
       
   926 //</qmail>
       
   927 		
       
   928 	    buffer->Des().Append(_L("; "));
       
   929 	    buffer->Des().Append(KFSMailContentTypeParamName);
       
   930 	    buffer->Des().Append('"');
       
   931 	    buffer->Des().Append(name);
       
   932 	    buffer->Des().Append('"');
       
   933 	    
       
   934 //<qmail>
       
   935 	    SetContentType(*buffer);
       
   936 	    delete buffer;
       
   937 //</qmail>
       
   938 	    
       
   939 	    // Set Content-Disposition as "attachment" and
       
   940 	    // Content-Disposition param "filename" = filename and
       
   941 	    length = KFSMailContentDispAttachment.iTypeLength +
       
   942 	    KFSMailContentDispParamFilename.iTypeLength + name.Length() + 4;
       
   943 		
       
   944 //<qmail>
       
   945 	    buffer = HBufC::NewL(length);
       
   946 	    if (ContentDisposition().FindF(KFSMailContentDispInline) != KErrNotFound)
       
   947 	        {
       
   948             buffer->Des().Append(KFSMailContentDispInline);
       
   949 	        }
       
   950 	    else
       
   951 	        {
       
   952             buffer->Des().Append(KFSMailContentDispAttachment);
       
   953 	        }
       
   954 	    
       
   955 	    buffer->Des().Append(_L("; "));
       
   956 	    buffer->Des().Append(KFSMailContentDispParamFilename);
       
   957 	    buffer->Des().Append('"');
       
   958 	    buffer->Des().Append(name);
       
   959 	    buffer->Des().Append('"');
       
   960 	    SetContentDisposition(*buffer);    
       
   961 	    delete buffer;	    
       
   962 	    
       
   963 		// set content description		
       
   964 		SetContentDescription(name);
       
   965 //</qmail>	
       
   966 	}
       
   967 
       
   968 // -----------------------------------------------------------------------------
       
   969 // CFSMailMessagePart::AttachmentNameL
       
   970 // -----------------------------------------------------------------------------
       
   971 EXPORT_C TDesC& CFSMailMessagePart::AttachmentNameL()
       
   972 	{
       
   973     NM_FUNCTION;
       
   974     
       
   975 //<qmail>
       
   976     // Look first from Content-Type param "name"
       
   977 	TInt ptr = GetContentType().Find(KFSMailContentTypeParamName);
       
   978     if(ptr >= 0)
       
   979     	{
       
   980     	ptr = GetContentType().Locate('=');
       
   981     	TInt length = GetContentType().Length()-ptr-3;
       
   982     	TPtrC name = GetContentType().Mid((ptr+2),length);
       
   983     	if(iAttachmentName)
       
   984     		{
       
   985     		delete iAttachmentName;
       
   986     		iAttachmentName = NULL;
       
   987     		}
       
   988     	iAttachmentName = HBufC::New(name.Length());
       
   989     	iAttachmentName->Des().Copy(name);
       
   990     	return *iAttachmentName;
       
   991     	}
       
   992     // then if Content-Disposition is "attachment" look from Content-Disposition param "filename" and
       
   993     TDesC contentDisposition = ContentDisposition(); 
       
   994     ptr = contentDisposition.Find(KFSMailContentDispAttachment);
       
   995 	if(ptr >= 0)
       
   996 		{
       
   997 		ptr = contentDisposition.Find(KFSMailContentDispParamFilename);
       
   998 		if(ptr > 0)
       
   999 			{
       
  1000 			ptr = contentDisposition.Locate('=');
       
  1001 			TInt length = contentDisposition.Length()-ptr-3;
       
  1002 	    	TPtrC name = contentDisposition.Mid(ptr+2,length);
       
  1003     		if(iAttachmentName)
       
  1004     		{
       
  1005     			delete iAttachmentName;
       
  1006     			iAttachmentName = NULL;
       
  1007     		}
       
  1008 	    	iAttachmentName = HBufC::New(name.Length());
       
  1009 	    	iAttachmentName->Des().Copy(name);
       
  1010     		return *iAttachmentName;
       
  1011 			}
       
  1012 		}
       
  1013     // finally look if there is Content-Description.
       
  1014 	return iContentDescriptionPtr;
       
  1015 //</qmail>
       
  1016 	}
       
  1017 
       
  1018 //<qmail>
       
  1019 // -----------------------------------------------------------------------------
       
  1020 // CFSMailMessagePart::FindBodyPartL
       
  1021 // -----------------------------------------------------------------------------
       
  1022 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::FindBodyPartL(
       
  1023         const TDesC& aContentType, 
       
  1024         TFSMailMessagePartDataSource aDataSource)
       
  1025     {
       
  1026     NM_FUNCTION;
       
  1027 
       
  1028     TBuf<KMaxDataTypeLength> ptr;
       
  1029     if (!iNmPrivateMessagePart->mContentType.isNull())
       
  1030         {
       
  1031         ptr.Copy(GetContentType());
       
  1032         TInt length = ptr.Locate(';');
       
  1033         if (length >= 0)
       
  1034             {
       
  1035             ptr.SetLength(length);
       
  1036             }
       
  1037 
       
  1038         if (!ptr.CompareF(aContentType))
       
  1039             {
       
  1040             return this;
       
  1041             }
       
  1042         }
       
  1043     CFSMailMessagePart* messagePart(NULL);
       
  1044     if (aDataSource == EDataSourceMessageStore)
       
  1045         {
       
  1046         if (CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
       
  1047             {
       
  1048             if (iReadMessageParts)
       
  1049                 {
       
  1050                 plugin->ChildPartsL(GetMailBoxId(), GetFolderId(),
       
  1051                         GetMessageId(), GetPartId(), iMessageParts);
       
  1052                 iReadMessageParts = EFalse;
       
  1053                 }
       
  1054             if (iMessageParts.Count())
       
  1055                 {
       
  1056                 if (!ptr.CompareF(KFSMailContentTypeMultipartAlternative))
       
  1057                     {
       
  1058                     // multipart / alternative
       
  1059                     for (TInt i = 0; i < iMessageParts.Count(); i++)
       
  1060                         {
       
  1061                         ptr.Copy(iMessageParts[i]->GetContentType());
       
  1062                         TInt length = ptr.Locate(';');
       
  1063                         if (length >= 0)
       
  1064                             {
       
  1065                             ptr.SetLength(length);
       
  1066                             }
       
  1067                         if (!ptr.CompareF(aContentType))
       
  1068                             {
       
  1069                             messagePart = iMessageParts[i];
       
  1070                             // remove part from table
       
  1071                             iMessageParts.Remove(i);
       
  1072                             break;
       
  1073                             }
       
  1074 						else if(!ptr.CompareF(KFSMailContentTypeMultipartRelated) ||
       
  1075 						   	 	!ptr.CompareF(KFSMailContentTypeMultipartMixed) ||
       
  1076 								!ptr.CompareF(KFSMailContentTypeMultipartAlternative) ||
       
  1077 								!ptr.CompareF(KFSMailContentTypeMultipartDigest) ||
       
  1078 								!ptr.CompareF(KFSMailContentTypeMultipartParallel))
       
  1079                             {
       
  1080                             // multipart, check child parts
       
  1081                             messagePart = iMessageParts[i];
       
  1082                             // remove part from table
       
  1083                             messagePart = messagePart->FindBodyPartL(aContentType);
       
  1084                             if (messagePart && messagePart->GetPartId() == iMessageParts[0]->GetPartId())
       
  1085                                 {
       
  1086                                 iMessageParts.Remove(i);
       
  1087                                 }
       
  1088                             break;
       
  1089                             }
       
  1090                         }
       
  1091                     }
       
  1092                 else
       
  1093                     {
       
  1094                     // all other cases
       
  1095                     messagePart = iMessageParts[0];
       
  1096                     // remove part from table
       
  1097                     messagePart = messagePart->FindBodyPartL(aContentType);
       
  1098                     if (messagePart && messagePart->GetPartId() == iMessageParts[0]->GetPartId())
       
  1099                         {
       
  1100                         iMessageParts.Remove(0);
       
  1101                         }
       
  1102                     }
       
  1103                 }
       
  1104             }
       
  1105         }
       
  1106     else
       
  1107         {
       
  1108         const QString contentType = NmConverter::toQString(aContentType);
       
  1109         int count = iNmPrivateMessagePart->mChildParts.count();
       
  1110         for (int i = 0; i < count; i++)
       
  1111             {
       
  1112             NmMessagePart* part = iNmPrivateMessagePart->mChildParts[i]->findContentPart(contentType);
       
  1113             if (part) 
       
  1114                 {
       
  1115                 messagePart = CFSMailMessagePart::NewLC(
       
  1116                         NmConverter::mailMsgIdToNmId(GetMessageId()),*part);
       
  1117                 messagePart->SetMailBoxId(GetMailBoxId());
       
  1118                 CleanupStack::Pop(messagePart);
       
  1119                 break;
       
  1120                 }
       
  1121             }
       
  1122         }
       
  1123     return messagePart;
       
  1124     }
       
  1125 //</qmail>
       
  1126 	
       
  1127 // -----------------------------------------------------------------------------
       
  1128 // CFSMailMessagePart::AppendAttachmentsL
       
  1129 // -----------------------------------------------------------------------------
       
  1130 EXPORT_C void CFSMailMessagePart::AppendAttachmentsL(
       
  1131     RPointerArray<CFSMailMessagePart>& aParts)
       
  1132     {
       
  1133     NM_FUNCTION;
       
  1134     
       
  1135     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetMessageId() );
       
  1136     if ( plugin )
       
  1137         {
       
  1138         RPointerArray<CFSMailMessagePart> messageParts;
       
  1139         CleanupResetAndDestroyPushL( messageParts );
       
  1140         plugin->ChildPartsL( GetMailBoxId(), GetFolderId(),
       
  1141                 GetMessageId(), GetPartId(), messageParts );	
       
  1142 
       
  1143         const TInt messagePartCount = messageParts.Count();
       
  1144         for ( TInt i = 0; i < messagePartCount; i++ )
       
  1145             {
       
  1146             const TDesC& contentType = messageParts[i]->GetContentType();
       
  1147             if (!contentType.CompareF(KFSMailContentTypeMultipartMixed) ||
       
  1148                 !contentType.CompareF(KFSMailContentTypeMultipartAlternative) ||
       
  1149                 !contentType.CompareF(KFSMailContentTypeMultipartDigest) ||
       
  1150                 !contentType.CompareF(KFSMailContentTypeMultipartRelated) ||
       
  1151                 !contentType.CompareF(KFSMailContentTypeMultipartParallel))
       
  1152                 {
       
  1153                 // get multipart message subparts
       
  1154                 messageParts[i]->AppendAttachmentsL( aParts );
       
  1155                 }
       
  1156             else
       
  1157                 {
       
  1158                 aParts.AppendL( messageParts[i] );
       
  1159                 messageParts[i] = NULL;
       
  1160                 }
       
  1161             }
       
  1162         CleanupStack::PopAndDestroy( &messageParts );
       
  1163         }
       
  1164     }
       
  1165 // -----------------------------------------------------------------------------
       
  1166 // CFSMailMessagePart::FetchedContentSize
       
  1167 // -----------------------------------------------------------------------------
       
  1168 EXPORT_C TUint CFSMailMessagePart::FetchedContentSize() const
       
  1169 	{
       
  1170     NM_FUNCTION;
       
  1171     
       
  1172 //<qmail>
       
  1173     return (TUint)iNmPrivateMessagePart->mFetchedSize;
       
  1174 //</qmail>
       
  1175 	}
       
  1176 
       
  1177 // -----------------------------------------------------------------------------
       
  1178 // CFSMailMessagePart::SetFetchedContentSize
       
  1179 // -----------------------------------------------------------------------------
       
  1180 EXPORT_C void CFSMailMessagePart::SetFetchedContentSize(TUint aContentSize)
       
  1181 	{
       
  1182     NM_FUNCTION;
       
  1183     
       
  1184 //<qmail>
       
  1185     iNmPrivateMessagePart->mFetchedSize = quint32(aContentSize);
       
  1186 //</qmail>
       
  1187 	}
       
  1188 
       
  1189 
       
  1190 // -----------------------------------------------------------------------------
       
  1191 // CFSMailMessagePart::FetchMessagePartL
       
  1192 // -----------------------------------------------------------------------------
       
  1193 EXPORT_C TInt CFSMailMessagePart::FetchMessagePartL( 	const TFSMailMsgId /*aMessagePartId*/,
       
  1194         										  		MFSMailRequestObserver& aOperationObserver,
       
  1195         												const TUint aPreferredByteCount)
       
  1196     {
       
  1197     NM_FUNCTION;
       
  1198     
       
  1199 	TInt requestId(0);
       
  1200 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
  1201 		{
       
  1202 	    RArray<TFSMailMsgId> messageList;
       
  1203     	messageList.AppendL(GetPartId());
       
  1204 		
       
  1205 	    // init async request
       
  1206 	    TFSPendingRequest request = iRequestHandler->InitAsyncRequestL(	GetPartId().PluginId(),
       
  1207 	    															  	aOperationObserver);
       
  1208 
       
  1209 	    requestId = request.iRequestId;
       
  1210     	MFSMailRequestObserver* observer = request.iObserver;
       
  1211 
       
  1212 		// fetch message parts
       
  1213 	    TRAPD(err,plugin->FetchMessagePartsL(	GetMailBoxId(),
       
  1214 	    										GetFolderId(),
       
  1215 	    										GetMessageId(),
       
  1216 	        									messageList,
       
  1217 	        									*observer,
       
  1218 	        									requestId,
       
  1219 	        									aPreferredByteCount ));
       
  1220 	    messageList.Reset();
       
  1221 	    if(err != KErrNone)
       
  1222 			{
       
  1223 			iRequestHandler->CompleteRequest(requestId);
       
  1224 			User::Leave(err);
       
  1225 			}
       
  1226 		}
       
  1227 	return requestId;
       
  1228     }
       
  1229     
       
  1230 // -----------------------------------------------------------------------------
       
  1231 // CFSMailMessagePart::FetchMessagesPartsL
       
  1232 // -----------------------------------------------------------------------------
       
  1233 EXPORT_C TInt CFSMailMessagePart::FetchMessagesPartsL( 
       
  1234 									const RArray<TFSMailMsgId>& aMessagePartIds,
       
  1235         							MFSMailRequestObserver& aOperationObserver,
       
  1236         							const TUint aPreferredByteCount)
       
  1237     {
       
  1238     NM_FUNCTION;
       
  1239 
       
  1240 	TInt requestId(0);
       
  1241     
       
  1242 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
  1243 		{
       
  1244 		
       
  1245 	    // get async request id
       
  1246 	    TFSPendingRequest request = 
       
  1247 	    iRequestHandler->InitAsyncRequestL(	GetPartId().PluginId(),
       
  1248 	    								 	aOperationObserver);
       
  1249 	    								 	
       
  1250 	    requestId = request.iRequestId;
       
  1251     	MFSMailRequestObserver* observer = request.iObserver;
       
  1252 	    
       
  1253 	    // fetch message parts
       
  1254 	    TRAPD(err,plugin->FetchMessagePartsL( 	GetMailBoxId(),
       
  1255 	    										GetFolderId(),
       
  1256 	    										GetMessageId(),
       
  1257 	        									aMessagePartIds,
       
  1258 												*observer,
       
  1259 	        									requestId,
       
  1260 	        									aPreferredByteCount ));
       
  1261 	            
       
  1262 	    if(err != KErrNone)
       
  1263 			{
       
  1264 			iRequestHandler->CompleteRequest(requestId);
       
  1265 			User::Leave(err);
       
  1266 			}
       
  1267 		}
       
  1268 	else
       
  1269 	    {
       
  1270         User::Leave(KErrArgument);
       
  1271 	    }
       
  1272     return requestId;
       
  1273     }
       
  1274 // -----------------------------------------------------------------------------
       
  1275 // CFSMailMessagePart::SetMessagePartsStatus
       
  1276 // -----------------------------------------------------------------------------
       
  1277 EXPORT_C void CFSMailMessagePart::SetMessagePartsStatus(TFSPartFetchState aMessagePartStatus)
       
  1278 	{
       
  1279     NM_FUNCTION;
       
  1280     
       
  1281 	iMessagePartsStatus = aMessagePartStatus;
       
  1282 	}
       
  1283 
       
  1284 // -----------------------------------------------------------------------------
       
  1285 // CFSMailMessagePart::AddNewAttachmentL
       
  1286 // -----------------------------------------------------------------------------
       
  1287 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::AddNewAttachmentL(	const TDesC& aFilePath,
       
  1288 																const TFSMailMsgId /*aInsertBefore*/,
       
  1289 																const TDesC& aContentType )
       
  1290     {
       
  1291     NM_FUNCTION;
       
  1292     
       
  1293     CFSMailMessagePart* newPart = NULL;
       
  1294 
       
  1295     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid( GetMessageId() );
       
  1296     if ( plugin )
       
  1297         {
       
  1298         newPart = plugin->NewChildPartFromFileL( GetMailBoxId(),
       
  1299             GetFolderId(),
       
  1300             GetMessageId(),
       
  1301             GetPartId(),
       
  1302             aContentType, //contentType,
       
  1303             aFilePath );
       
  1304         if (newPart) 
       
  1305             {
       
  1306             CleanupStack::PushL( newPart );
       
  1307         
       
  1308             // Set attachment name
       
  1309             newPart->SetAttachmentNameL( aFilePath );
       
  1310 
       
  1311             // save message part
       
  1312             newPart->SaveL();
       
  1313         
       
  1314             CleanupStack::Pop( newPart );
       
  1315             }
       
  1316         }
       
  1317 
       
  1318     return newPart;
       
  1319     }
       
  1320 
       
  1321 // -----------------------------------------------------------------------------
       
  1322 // CFSMailMessagePart::ReadOnlyPartSize
       
  1323 // -----------------------------------------------------------------------------
       
  1324 EXPORT_C TUint CFSMailMessagePart::ReadOnlyPartSize() const
       
  1325 {
       
  1326     NM_FUNCTION;
       
  1327     
       
  1328     return iReadOnlyPartSize;
       
  1329 }
       
  1330 
       
  1331 // -----------------------------------------------------------------------------
       
  1332 // CFSMailMessagePart::SetReadOnlyPartSize
       
  1333 // -----------------------------------------------------------------------------
       
  1334 EXPORT_C void CFSMailMessagePart::SetReadOnlyPartSize(const TUint aReadOnlyPartSize)
       
  1335 {
       
  1336     NM_FUNCTION;
       
  1337     
       
  1338     iReadOnlyPartSize = aReadOnlyPartSize;
       
  1339 }
       
  1340 
       
  1341 // -----------------------------------------------------------------------------
       
  1342 // CFSMailMessagePart::DoAttachmentListL
       
  1343 // -----------------------------------------------------------------------------
       
  1344 void CFSMailMessagePart::DoAttachmentListL( RPointerArray<CFSMailMessagePart>& /*aParts*/ )
       
  1345 {
       
  1346     NM_FUNCTION;
       
  1347 }
       
  1348 //<qmail>
       
  1349 // -----------------------------------------------------------------------------
       
  1350 // CFSMailMessagePart::GetNmMessagePart
       
  1351 // -----------------------------------------------------------------------------
       
  1352 EXPORT_C NmMessagePart* CFSMailMessagePart::GetNmMessagePart()
       
  1353 {
       
  1354     NM_FUNCTION;
       
  1355     
       
  1356     return new NmMessagePart(iNmPrivateMessagePart);
       
  1357 }
       
  1358 //</qmail>
       
  1359 
       
  1360 //<qmail>
       
  1361 // -----------------------------------------------------------------------------
       
  1362 // CFSMailMessagePart::GetLocalTextContentLC
       
  1363 // -----------------------------------------------------------------------------
       
  1364 EXPORT_C HBufC* CFSMailMessagePart::GetLocalTextContentLC()
       
  1365 {
       
  1366     NM_FUNCTION;
       
  1367     
       
  1368     return NmConverter::qstringToHBufCLC(iNmPrivateMessagePart->mTextContent);
       
  1369 }
       
  1370 //</qmail>