emailservices/emailcommon/src/CFSMailMessagePart.cpp
changeset 62 a8c646b56683
parent 51 d845db10c0d4
child 66 084b5b1f02a7
equal deleted inserted replaced
57:ae34e1715e21 62:a8c646b56683
   429 
   429 
   430 	// 
   430 	// 
   431 	HBufC* contentClass = HBufC::New(aContentClass.Length());
   431 	HBufC* contentClass = HBufC::New(aContentClass.Length());
   432 	
   432 	
   433 	// store new mailbox name
   433 	// store new mailbox name
   434 	if(contentClass)
   434 	delete iContentClass;
   435 	{
   435 	iContentClass = contentClass;
   436 		delete iContentClass;
   436 	iContentClass->Des().Copy(aContentClass);
   437 		iContentClass = contentClass;
   437 	iContentClass->ReAlloc(aContentClass.Length());
   438 		iContentClass->Des().Copy(aContentClass);
   438 	iContentClass->Des().Copy(aContentClass);		
   439 	}
       
   440 		iContentClass->ReAlloc(aContentClass.Length());
       
   441 		if(iContentClass)
       
   442 		{
       
   443 			iContentClass->Des().Copy(aContentClass);		
       
   444 		}
       
   445 	}
   439 	}
   446 
   440 
   447 // -----------------------------------------------------------------------------
   441 // -----------------------------------------------------------------------------
   448 // CFSMailMessagePart::ContentSize
   442 // CFSMailMessagePart::ContentSize
   449 // -----------------------------------------------------------------------------
   443 // -----------------------------------------------------------------------------
   493     QString qtContentID = QString::fromUtf16(aContentID.Ptr(), aContentID.Length());
   487     QString qtContentID = QString::fromUtf16(aContentID.Ptr(), aContentID.Length());
   494     iNmPrivateMessagePart->mContentId = qtContentID;    
   488     iNmPrivateMessagePart->mContentId = qtContentID;    
   495 //</qmail>    
   489 //</qmail>    
   496 	}
   490 	}
   497 	
   491 	
   498 // -----------------------------------------------------------------------------
       
   499 // CFSMailMessagePart::CopyMessageAsChildPartL
       
   500 // -----------------------------------------------------------------------------
       
   501 EXPORT_C CFSMailMessagePart* CFSMailMessagePart::CopyMessageAsChildPartL(
       
   502 													TFSMailMsgId aInsertBefore,
       
   503 													CFSMailMessage* aMessage)
       
   504 	{
       
   505     NM_FUNCTION;
       
   506 	
       
   507 	CFSMailMessagePart* part = NULL;
       
   508 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
   509 	{
       
   510 		part = plugin->CopyMessageAsChildPartL(GetMailBoxId(),GetFolderId(),GetMessageId(),GetPartId(),
       
   511 											aInsertBefore, *aMessage);
       
   512 	}
       
   513 	return part;
       
   514 	}
       
   515 
       
   516 // -----------------------------------------------------------------------------
       
   517 // CFSMailMessagePart::RemoveContentL
       
   518 // -----------------------------------------------------------------------------
       
   519 EXPORT_C void CFSMailMessagePart::RemoveContentL()
       
   520 	{
       
   521     NM_FUNCTION;
       
   522 	
       
   523 	CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId());
       
   524 	if(plugin == NULL)
       
   525 	    {
       
   526 	    plugin = iRequestHandler->GetPluginByUid(GetMessageId());
       
   527 	    }
       
   528 	
       
   529 	if(plugin != NULL)
       
   530 		{
       
   531 		RPointerArray<CFSMailMessagePart> parts;
       
   532         CleanupResetAndDestroyPushL( parts );
       
   533         plugin->ChildPartsL(GetMailBoxId(),GetFolderId(),GetMessageId(),GetPartId(),parts);
       
   534         RArray<TFSMailMsgId> partIds;
       
   535         CleanupClosePushL( partIds );
       
   536         partIds.ReserveL( 1 + parts.Count() );
       
   537 		for(TInt i=0;i<parts.Count();i++)
       
   538 			{
       
   539 			partIds.AppendL( parts[i]->GetMessageId() );
       
   540 			}
       
   541         partIds.AppendL( GetPartId() );
       
   542 		plugin->RemovePartContentL(GetMailBoxId(), GetFolderId(), GetMessageId(), partIds);
       
   543         CleanupStack::PopAndDestroy( &partIds );
       
   544         CleanupStack::PopAndDestroy( &parts );
       
   545 		}
       
   546 	}
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // CFSMailMessagePart::RemoveDownLoadedAttachmentsL
       
   550 // -----------------------------------------------------------------------------
       
   551 EXPORT_C void CFSMailMessagePart::RemoveDownLoadedAttachmentsL()
       
   552     {
       
   553     NM_FUNCTION;
       
   554         
       
   555     CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId());
       
   556     if(plugin == NULL)
       
   557         {
       
   558         plugin = iRequestHandler->GetPluginByUid(GetMessageId());
       
   559         }
       
   560     
       
   561     if(plugin != NULL)
       
   562         {
       
   563         // get attachment list
       
   564         RPointerArray<CFSMailMessagePart> attachments;
       
   565         CleanupResetAndDestroyPushL( attachments );
       
   566         DoAttachmentListL(attachments);
       
   567 
       
   568         // copy attachment part ids
       
   569         RArray<TFSMailMsgId> ids;
       
   570         CleanupClosePushL( ids ); 
       
   571         for(TInt i=0;i<attachments.Count();i++)
       
   572             {
       
   573             ids.AppendL(attachments[i]->GetPartId());
       
   574             }
       
   575         
       
   576         // remove attachment fetched contents 
       
   577         if(ids.Count())
       
   578             {
       
   579             TRAP_IGNORE(plugin->RemovePartContentL(GetMailBoxId(), GetFolderId(), GetMessageId(), ids));
       
   580             }
       
   581         
       
   582         // clean tables
       
   583         CleanupStack::PopAndDestroy( &ids );
       
   584         CleanupStack::PopAndDestroy( &attachments );
       
   585         }
       
   586     }
       
   587 
   492 
   588 // -----------------------------------------------------------------------------
   493 // -----------------------------------------------------------------------------
   589 // CFSMailMessagePart::GetContentFileL
   494 // CFSMailMessagePart::GetContentFileL
   590 // -----------------------------------------------------------------------------
   495 // -----------------------------------------------------------------------------
   591 EXPORT_C RFile CFSMailMessagePart::GetContentFileL()
   496 EXPORT_C RFile CFSMailMessagePart::GetContentFileL()
   609 		    }
   514 		    }
   610 		}
   515 		}
   611 	
   516 	
   612 	return iFile;
   517 	return iFile;
   613 	}
   518 	}
   614 	
   519 
   615 // -----------------------------------------------------------------------------
       
   616 // CFSMailMessagePart::SetContentFromFileL
       
   617 // -----------------------------------------------------------------------------
       
   618 EXPORT_C void CFSMailMessagePart::SetContentFromFileL(const TDesC& aFilePath)
       
   619 	{
       
   620     NM_FUNCTION;
       
   621     
       
   622 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
   623 		{
       
   624 		plugin->SetPartContentFromFileL(GetMailBoxId(), GetFolderId(),
       
   625 			GetMessageId(), GetPartId(), aFilePath );
       
   626 		}
       
   627 	}
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 // CFSMailMessagePart::CopyContentFileL
       
   631 // -----------------------------------------------------------------------------
       
   632 EXPORT_C void CFSMailMessagePart::CopyContentFileL( const TDesC& aFilePath )
       
   633 	{
       
   634     NM_FUNCTION;
       
   635     
       
   636 	if(CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetPartId()))
       
   637 		{
       
   638 		plugin->CopyMessagePartFileL( GetMailBoxId(), GetFolderId(),
       
   639 			GetMessageId(), GetPartId(), aFilePath);		
       
   640 		}
       
   641 	}
       
   642 
   520 
   643 // -----------------------------------------------------------------------------
   521 // -----------------------------------------------------------------------------
   644 // CFSMailMessagePart::GetContentToBufferL
   522 // CFSMailMessagePart::GetContentToBufferL
   645 // -----------------------------------------------------------------------------
   523 // -----------------------------------------------------------------------------
   646 EXPORT_C void CFSMailMessagePart::GetContentToBufferL(TDes16& aBuffer, TUint aStartOffset)
   524 EXPORT_C void CFSMailMessagePart::GetContentToBufferL(TDes16& aBuffer, TUint aStartOffset)
  1160         if (!ptr.CompareF(aContentType))
  1038         if (!ptr.CompareF(aContentType))
  1161             {
  1039             {
  1162             return this;
  1040             return this;
  1163             }
  1041             }
  1164         }
  1042         }
  1165     
  1043     CFSMailMessagePart* messagePart(NULL);
  1166     CFSMailMessagePart* messagePart = NULL;
       
  1167     if (aDataSource == EDataSourceMessageStore)
  1044     if (aDataSource == EDataSourceMessageStore)
  1168         {
  1045         {
  1169         if (CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
  1046         if (CFSMailPlugin* plugin = iRequestHandler->GetPluginByUid(GetMessageId()))
  1170             {
  1047             {
  1171             if (iReadMessageParts)
  1048             if (iReadMessageParts)
  1246     return messagePart;
  1123     return messagePart;
  1247     }
  1124     }
  1248 //</qmail>
  1125 //</qmail>
  1249 	
  1126 	
  1250 // -----------------------------------------------------------------------------
  1127 // -----------------------------------------------------------------------------
  1251 // CFSMailMessagePart::ContentTypeMatches
       
  1252 // -----------------------------------------------------------------------------
       
  1253 EXPORT_C TBool CFSMailMessagePart::ContentTypeMatches( const TDesC& aContentType )
       
  1254 {
       
  1255     NM_FUNCTION;
       
  1256 
       
  1257 	TBuf<KMaxDataTypeLength> ptr;
       
  1258 	TBool result(EFalse);
       
  1259 //<qmail>
       
  1260 	if ( !iNmPrivateMessagePart->mContentType.isNull() )
       
  1261     {
       
  1262         ptr.Copy(GetContentType());
       
  1263 //</qmail>
       
  1264 		TInt length = ptr.Locate(';');
       
  1265 		if(length >= 0)
       
  1266 			{
       
  1267 			ptr.SetLength(length);
       
  1268 			}
       
  1269 		
       
  1270 		if( !ptr.CompareF(aContentType) ) // case-insensitive comparision
       
  1271 		{
       
  1272 			result = ETrue;
       
  1273 		}
       
  1274     }
       
  1275 
       
  1276     return result;
       
  1277 }
       
  1278 
       
  1279 // -----------------------------------------------------------------------------
       
  1280 // CFSMailMessagePart::AppendAttachmentsL
  1128 // CFSMailMessagePart::AppendAttachmentsL
  1281 // -----------------------------------------------------------------------------
  1129 // -----------------------------------------------------------------------------
  1282 EXPORT_C void CFSMailMessagePart::AppendAttachmentsL(
  1130 EXPORT_C void CFSMailMessagePart::AppendAttachmentsL(
  1283     RPointerArray<CFSMailMessagePart>& aParts)
  1131     RPointerArray<CFSMailMessagePart>& aParts)
  1284     {
  1132     {
  1312                 }
  1160                 }
  1313             }
  1161             }
  1314         CleanupStack::PopAndDestroy( &messageParts );
  1162         CleanupStack::PopAndDestroy( &messageParts );
  1315         }
  1163         }
  1316     }
  1164     }
  1317 
       
  1318 // -----------------------------------------------------------------------------
  1165 // -----------------------------------------------------------------------------
  1319 // CFSMailMessagePart::FetchedContentSize
  1166 // CFSMailMessagePart::FetchedContentSize
  1320 // -----------------------------------------------------------------------------
  1167 // -----------------------------------------------------------------------------
  1321 EXPORT_C TUint CFSMailMessagePart::FetchedContentSize() const
  1168 EXPORT_C TUint CFSMailMessagePart::FetchedContentSize() const
  1322 	{
  1169 	{
  1337 //<qmail>
  1184 //<qmail>
  1338     iNmPrivateMessagePart->mFetchedSize = quint32(aContentSize);
  1185     iNmPrivateMessagePart->mFetchedSize = quint32(aContentSize);
  1339 //</qmail>
  1186 //</qmail>
  1340 	}
  1187 	}
  1341 
  1188 
  1342 // -----------------------------------------------------------------------------
  1189 
  1343 // CFSMailMessagePart::FetchLoadState
       
  1344 // -----------------------------------------------------------------------------
       
  1345 EXPORT_C TFSPartFetchState CFSMailMessagePart::FetchLoadState() const
       
  1346 	{
       
  1347     NM_FUNCTION;
       
  1348     
       
  1349 //<qmail>
       
  1350 	 if(iMessagePartsStatus != EFSDefault)
       
  1351 		{
       
  1352 		return iMessagePartsStatus;
       
  1353 		}
       
  1354      else if (iNmPrivateMessagePart->mSize == 0)
       
  1355      	{
       
  1356      	return EFSFull;     	
       
  1357      	}
       
  1358      else if(iNmPrivateMessagePart->mFetchedSize == 0)
       
  1359      	{
       
  1360      	return EFSNone;
       
  1361      	}
       
  1362      else if (iNmPrivateMessagePart->mFetchedSize < iNmPrivateMessagePart->mSize)
       
  1363      	{
       
  1364      	return EFSPartial;
       
  1365      	}
       
  1366      else
       
  1367      	{
       
  1368      	return EFSFull;
       
  1369      	}
       
  1370 //</qmail>
       
  1371 	}
       
  1372 	
       
  1373 // -----------------------------------------------------------------------------
  1190 // -----------------------------------------------------------------------------
  1374 // CFSMailMessagePart::FetchMessagePartL
  1191 // CFSMailMessagePart::FetchMessagePartL
  1375 // -----------------------------------------------------------------------------
  1192 // -----------------------------------------------------------------------------
  1376 EXPORT_C TInt CFSMailMessagePart::FetchMessagePartL( 	const TFSMailMsgId /*aMessagePartId*/,
  1193 EXPORT_C TInt CFSMailMessagePart::FetchMessagePartL( 	const TFSMailMsgId /*aMessagePartId*/,
  1377         										  		MFSMailRequestObserver& aOperationObserver,
  1194         										  		MFSMailRequestObserver& aOperationObserver,
  1452 	    {
  1269 	    {
  1453         User::Leave(KErrArgument);
  1270         User::Leave(KErrArgument);
  1454 	    }
  1271 	    }
  1455     return requestId;
  1272     return requestId;
  1456     }
  1273     }
  1457 
       
  1458 // -----------------------------------------------------------------------------
  1274 // -----------------------------------------------------------------------------
  1459 // CFSMailMessagePart::SetMessagePartsStatus
  1275 // CFSMailMessagePart::SetMessagePartsStatus
  1460 // -----------------------------------------------------------------------------
  1276 // -----------------------------------------------------------------------------
  1461 EXPORT_C void CFSMailMessagePart::SetMessagePartsStatus(TFSPartFetchState aMessagePartStatus)
  1277 EXPORT_C void CFSMailMessagePart::SetMessagePartsStatus(TFSPartFetchState aMessagePartStatus)
  1462 	{
  1278 	{
  1483             GetFolderId(),
  1299             GetFolderId(),
  1484             GetMessageId(),
  1300             GetMessageId(),
  1485             GetPartId(),
  1301             GetPartId(),
  1486             aContentType, //contentType,
  1302             aContentType, //contentType,
  1487             aFilePath );
  1303             aFilePath );
  1488 
  1304         if (newPart) 
  1489         CleanupStack::PushL( newPart );
  1305             {
       
  1306             CleanupStack::PushL( newPart );
  1490         
  1307         
  1491         // Set attachment name
  1308             // Set attachment name
  1492         newPart->SetAttachmentNameL( aFilePath );
  1309             newPart->SetAttachmentNameL( aFilePath );
  1493 
  1310 
  1494         // save message part
  1311             // save message part
  1495         newPart->SaveL();
  1312             newPart->SaveL();
  1496         
  1313         
  1497         CleanupStack::Pop( newPart );
  1314             CleanupStack::Pop( newPart );
       
  1315             }
  1498         }
  1316         }
  1499 
  1317 
  1500     return newPart;
  1318     return newPart;
  1501     }
  1319     }
  1502 
  1320 
  1525 // -----------------------------------------------------------------------------
  1343 // -----------------------------------------------------------------------------
  1526 void CFSMailMessagePart::DoAttachmentListL( RPointerArray<CFSMailMessagePart>& /*aParts*/ )
  1344 void CFSMailMessagePart::DoAttachmentListL( RPointerArray<CFSMailMessagePart>& /*aParts*/ )
  1527 {
  1345 {
  1528     NM_FUNCTION;
  1346     NM_FUNCTION;
  1529 }
  1347 }
  1530 
       
  1531 //<qmail>
  1348 //<qmail>
  1532 // -----------------------------------------------------------------------------
  1349 // -----------------------------------------------------------------------------
  1533 // CFSMailMessagePart::GetNmMessagePart
  1350 // CFSMailMessagePart::GetNmMessagePart
  1534 // -----------------------------------------------------------------------------
  1351 // -----------------------------------------------------------------------------
  1535 EXPORT_C NmMessagePart* CFSMailMessagePart::GetNmMessagePart()
  1352 EXPORT_C NmMessagePart* CFSMailMessagePart::GetNmMessagePart()