email/imap4mtm/imapmailstore/src/cimapmailstore.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "cimapmailstore.h"
       
    17 #include "cimheaderqueueentry.h"
       
    18 #include "cimmimeheaderqueueentry.h"
       
    19 #include "cbodyqueueentry8.h"
       
    20 #include "cbodyqueueentry16.h"
       
    21 #include "cattachmentqueueentry.h"
       
    22 #include "cqueueentrybase.h"
       
    23 #include "cimaplogger.h"
       
    24 #include "imappaniccodes.h"
       
    25 #include "cmsvplainbodytextqueueentry.h"
       
    26 
       
    27 /**
       
    28 Constructor.
       
    29 */
       
    30 CImapMailStore::CImapMailStore(CMsvServerEntry& aServerEntry)
       
    31 	: iServerEntry(aServerEntry)
       
    32 	{	
       
    33 	}
       
    34 	
       
    35 /**
       
    36 Destructor.
       
    37 */
       
    38 CImapMailStore::~CImapMailStore()
       
    39 	{
       
    40 	iRequestArray.ResetAndDestroy();
       
    41 	}
       
    42 	
       
    43 /**
       
    44 Factory constructors.
       
    45 */
       
    46 EXPORT_C CImapMailStore* CImapMailStore::NewL(CMsvServerEntry& aServerEntry)
       
    47 	{
       
    48 	CImapMailStore* self=new(ELeave) CImapMailStore(aServerEntry);
       
    49 	CleanupStack::PushL(self);
       
    50 	self->ConstructL();
       
    51 	CleanupStack::Pop();
       
    52 	return self;
       
    53 	}
       
    54 
       
    55 void CImapMailStore::ConstructL()
       
    56 	{
       
    57 	}
       
    58 	
       
    59 
       
    60 EXPORT_C TInt CImapMailStore::RequestCount() const
       
    61 	{
       
    62 	return iRequestArray.Count();	
       
    63 	}
       
    64 
       
    65 /**
       
    66 Tests two CQueueEntryBase for a match based on entry id and entry type. 
       
    67 @param aFirstEntry 	the first object to be compared.
       
    68 @param aSecondEntry	the second object to be compared.
       
    69 @return ETrue if a match was identified, EFalse otherwise
       
    70 */
       
    71 
       
    72 TBool CImapMailStore::IdsAndTypeMatch(const CQueueEntryBase& aFirstEntry,const CQueueEntryBase& aSecondEntry)
       
    73     {
       
    74     return ((aFirstEntry.GetId() == aSecondEntry.GetId()) && (aFirstEntry.GetEntryType() == aSecondEntry.GetEntryType()));
       
    75     }
       
    76 
       
    77 /**
       
    78 Removes a CQueueEntryBase derived object that has completed its request from the array and deletes it.
       
    79 @param aQueueEntry	the CQueueEntryBase derived object to be removed.
       
    80 @return
       
    81 */	
       
    82 	
       
    83 void CImapMailStore::RemoveFromQueueAndDelete(CQueueEntryBase* aQueueEntry)
       
    84 	{
       
    85 	TInt index=iRequestArray.Find(aQueueEntry);
       
    86 	__ASSERT_DEBUG(index!=KErrNotFound,TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectNotFound));
       
    87 	CQueueEntryBase* qEntry=iRequestArray[index];
       
    88 	iRequestArray.Remove(index);
       
    89 	delete qEntry;		
       
    90 	}
       
    91 	
       
    92 /**
       
    93 Adds a request to store a CIMHeader to the queue.
       
    94 @param aHeader		CImHeader* object to be stored, ownership is taken.
       
    95 @param aId			The id of the entry under which the object will be stored.
       
    96 @param aObserver	A reference to a MMailStoreObserver object that will be called back when the request is complete.
       
    97 @return
       
    98 */	
       
    99 
       
   100 EXPORT_C void CImapMailStore::StorePartL(CImHeader* aHeader,TMsvId aId,MMailStoreObserver& aObserver)
       
   101 	{	
       
   102 	CImHeaderQueueEntry* qEntry=CImHeaderQueueEntry::NewL(aHeader,aId,*this,iServerEntry,aObserver);
       
   103 	CleanupStack::PushL(qEntry);
       
   104 	iRequestArray.AppendL(qEntry);
       
   105 	CleanupStack::Pop(qEntry);
       
   106 	}
       
   107 
       
   108 /**
       
   109 Adds a request to store a CIMMimeHeader to the queue.
       
   110 @param aHeader		CImMimeHeader* object to be stored, ownership is taken.
       
   111 @param aId			The id of the entry under which the object will be stored.
       
   112 @param aObserver	A reference to a MMailStoreObserver object that will be called back when the request is complete.
       
   113 @return
       
   114 */
       
   115 
       
   116 EXPORT_C void CImapMailStore::StorePartL(CImMimeHeader* aHeader,TMsvId aId, MMailStoreObserver& aObserver)
       
   117 	{
       
   118 	CImMimeHeaderQueueEntry* qEntry=CImMimeHeaderQueueEntry::NewL(aHeader,aId,*this,iServerEntry,aObserver);
       
   119 	CleanupStack::PushL(qEntry);
       
   120 	iRequestArray.AppendL(qEntry);
       
   121 	CleanupStack::Pop(qEntry);
       
   122 	}
       
   123 	
       
   124 /**
       
   125 Creates a CAttachmentQueueEntry used to store attachments and adds the object to the queue.
       
   126 @param aTotalChunks	The number of chunks of body data that will be stored.
       
   127 @param aId			The id of the entry under which the object will be stored.
       
   128 @param aObserver	A reference to a MMailStoreObserver object that will be called back when the request is complete.
       
   129 @return
       
   130 */
       
   131 
       
   132 EXPORT_C void CImapMailStore::InitialiseStoreAttachmentL(TInt aTotalChunks,CImapSettings& aImapSettings,CFetchBodyInfo& aFetchBodyInfo,TInt aLogId,MMailStoreObserver& aObserver)
       
   133 	{
       
   134 	__ASSERT_DEBUG(aTotalChunks>0,TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreNoDataChunks));
       
   135 	__LOG_FORMAT((aLogId, "CImapMailStore::InitialiseStoreAttachmentL total chunks = %d",aTotalChunks));
       
   136 	CAttachmentQueueEntry* qEntry=CAttachmentQueueEntry::NewL(aTotalChunks,*this,iServerEntry,aImapSettings,aFetchBodyInfo,aLogId,aObserver);
       
   137 	CleanupStack::PushL(qEntry);
       
   138 	//make sure that we do not place a CAttachmentQueueEntry on the queue if one aleady exists for this entry.
       
   139 #if (defined _DEBUG)	
       
   140 	TIdentityRelation<CQueueEntryBase> relationIdsAndTypeMatch(IdsAndTypeMatch);
       
   141 	TInt index=iRequestArray.Find(qEntry,relationIdsAndTypeMatch);
       
   142 	__ASSERT_DEBUG(index==KErrNotFound, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectAlreadyExists));		
       
   143 #endif	
       
   144 	iRequestArray.AppendL(qEntry);
       
   145 	CleanupStack::Pop(qEntry);
       
   146 	}
       
   147 	
       
   148 /**
       
   149 Creates a CreateAttachmentInfoL used to synchronously create information only about an attachment that is not currently being downloaded.
       
   150 @param aId			The id of the entry under which the data will be stored.
       
   151 @return
       
   152 */
       
   153 
       
   154 EXPORT_C void CImapMailStore::CreateAttachmentInfoL(TMsvId aId)
       
   155 	{
       
   156 	RFile file;
       
   157 	iServerEntry.SetEntry(aId);
       
   158 	CAttachmentQueueEntry::CreateAttachmentInfoL(iServerEntry,file);
       
   159 	file.Close();
       
   160 	}
       
   161 	
       
   162 /**
       
   163 Creates a CMultiChunkBodyEntry used to store body text and adds the object to the queue.
       
   164 @param aTotalChunks	The number of chunks of body data that will be stored.
       
   165 @param aId			The id of the entry under which the object will be stored.
       
   166 @param aObserver	A reference to a MMailStoreObserver object that will be called back when the request is complete.
       
   167 @param aBinaryCap   if true, message body is downloaded using FETCH BINARY
       
   168 					else FETCH BODY is used to download body message
       
   169 @return
       
   170 */
       
   171 
       
   172 EXPORT_C void CImapMailStore::InitialiseStoreBody16L(TInt aTotalChunks,CImapSettings& aImapSettings,CFetchBodyInfo& aFetchBodyInfo,TInt aLogId,MMailStoreObserver& aObserver, TBool aBinaryCap)
       
   173 	{
       
   174 	 __ASSERT_DEBUG(aTotalChunks>0, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreNoDataChunks));
       
   175 	__LOG_FORMAT((aLogId, "CImapMailStore::InitialiseStoreBody16L total chunks = %d",aTotalChunks));
       
   176 	CBodyQueueEntry16* qEntry=CBodyQueueEntry16::NewL(aTotalChunks,*this,iServerEntry,aImapSettings,aFetchBodyInfo,aLogId,aObserver,aBinaryCap);
       
   177 	CleanupStack::PushL(qEntry);
       
   178 	//make sure that we do not place a CBodyQueueEntry16 on the queue if one aleady exists for this entry.
       
   179 #if (defined _DEBUG)	
       
   180 	TIdentityRelation<CQueueEntryBase> relationIdsAndTypeMatch(IdsAndTypeMatch);
       
   181 	TInt index=iRequestArray.Find(qEntry,relationIdsAndTypeMatch);
       
   182 	__ASSERT_DEBUG(index==KErrNotFound, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectAlreadyExists));		
       
   183 #endif
       
   184 	iRequestArray.AppendL(qEntry);
       
   185 	CleanupStack::Pop(qEntry);
       
   186 	}
       
   187 	
       
   188 /**
       
   189 Creates a CBodyQueueEntry8 used to store body text and adds the object to the queue.
       
   190 @param aTotalChunks				The number of chunks of body data that will be stored.
       
   191 @param aId						The id of the entry under which the object will be stored.
       
   192 @param aCharacterSetIdentifier	The CharacterSet that was used to encode the body text.
       
   193 @param aObserver				A reference to a MMailStoreObserver object that will be called back when 
       
   194 								the request is complete.
       
   195 @param aBinaryCap   if true, message body is downloaded using FETCH BINARY
       
   196 					else FETCH BODY is used to download body message
       
   197 @return
       
   198 */
       
   199 	                                            
       
   200 EXPORT_C void CImapMailStore::InitialiseStoreBody8L(TInt aTotalChunks,CImapSettings& aImapSettings,CFetchBodyInfo& aFetchBodyInfo,TInt aLogId,MMailStoreObserver& aObserver, TBool aBinaryCap)
       
   201 	{
       
   202 	__ASSERT_DEBUG(aTotalChunks>0, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreNoDataChunks));
       
   203 	__LOG_FORMAT((aLogId, "CImapMailStore::InitialiseStoreBody8L total chunks = %d",aTotalChunks));
       
   204 	CBodyQueueEntry8* qEntry=CBodyQueueEntry8::NewL(aTotalChunks,*this,iServerEntry,aImapSettings,aFetchBodyInfo,aLogId,aObserver,aBinaryCap);
       
   205 	CleanupStack::PushL(qEntry);
       
   206 	//make sure that we do not place a CBodyQueueEntry8 on the queue if one aleady exists for this entry.
       
   207 #if (defined _DEBUG)	
       
   208 	TIdentityRelation<CQueueEntryBase> relationIdsAndTypeMatch(IdsAndTypeMatch);
       
   209 	TInt index=iRequestArray.Find(qEntry,relationIdsAndTypeMatch);
       
   210 	__ASSERT_DEBUG(index==KErrNotFound, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectAlreadyExists));		
       
   211 #endif	
       
   212 	iRequestArray.AppendL(qEntry);
       
   213 	CleanupStack::Pop(qEntry);
       
   214 	}
       
   215 
       
   216 /**
       
   217 Loops through the queue looking for a CMultiChunkBodyEntry that has been created for the entry. 
       
   218 If found ownership of the data is transferred to the object. Otherwise asserts.
       
   219 @param aData		The text to be stored. CImapMailStore takes ownership. 		
       
   220 @param aId			The id of the entry under which the object will be stored.
       
   221 @param aChunkNumber	The chunk number, used store the chunk in the correct order.
       
   222 @return	  			KErrNone if the request was found on the queue, KErrNotFound otherwise.
       
   223 */
       
   224 
       
   225 EXPORT_C void CImapMailStore::StoreBodyChunk16L(HBufC8* aData,TMsvId aId,TInt aChunkNumber, TInt aExtraFetchRequestCount)
       
   226 	{
       
   227 	//chunk number starts at 1 for body chunks
       
   228 	__ASSERT_DEBUG(aChunkNumber>=0, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreDataChunkOutOfRange));
       
   229 	//get the entry on the queue
       
   230 	TInt count=iRequestArray.Count();
       
   231 	//loop through the requests on the queue
       
   232 	TInt i;
       
   233 	for(i=0;i<count;++i)
       
   234 		{
       
   235 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   236 		//if a CMultiChunkBodyEntry request exists to store body data into this entry 
       
   237 		if(qEntry->GetEntryType()==CQueueEntryBase::EBody16 && qEntry->GetId()==aId)
       
   238 			{
       
   239 			CBodyQueueEntry16* multiChunkBodyEntry=static_cast<CBodyQueueEntry16*>(qEntry);
       
   240 			//add the chunk to the CMultiChunkBodyEntry object
       
   241 			multiChunkBodyEntry->AddChunkL(aData,aChunkNumber,aExtraFetchRequestCount);	
       
   242 			return;
       
   243 			}
       
   244 		}
       
   245 	//if the request was not on the queue then assert
       
   246 	if(i==count)
       
   247 		{
       
   248 		__ASSERT_DEBUG(EFalse,TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectNotFound));	
       
   249 		}
       
   250 	}
       
   251 
       
   252 
       
   253 /**
       
   254 Loops through the queue looking for a CBodyQueueEntry8 that has been created for the entry. 
       
   255 If found ownership of the data is transferred to the object. Otherwise asserts.
       
   256 @param aData		The text to be stored. CImapMailStore takes ownership. 		
       
   257 @param aId			The id of the entry under which the object will be stored.
       
   258 @param aChunkNumber	The chunk number, used store the chunk in the correct order.
       
   259 @return	  			KErrNone if the request was found on the queue, KErrNotFound otherwise.
       
   260 */
       
   261 
       
   262 EXPORT_C void CImapMailStore::StoreBodyChunk8L(HBufC8* aData,TMsvId aId,TInt aChunkNumber,TInt aExtraFetchRequestCount)
       
   263 	{
       
   264 	//chunk number starts at 1 for body chunks
       
   265 	__ASSERT_DEBUG(aChunkNumber>=0, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreDataChunkOutOfRange));
       
   266 	//get the entry on the queue
       
   267 	TInt count=iRequestArray.Count();
       
   268 	//loop through the requests on the queue
       
   269 	TInt i;
       
   270 	for(i=0;i<count;++i)
       
   271 		{
       
   272 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   273 		//if a CMultiChunkBodyEntry request exists to store body data into this entry 
       
   274 		if(qEntry->GetEntryType()==CQueueEntryBase::EBody8 && qEntry->GetId()==aId)
       
   275 			{
       
   276 			CBodyQueueEntry8* multiChunkEightBitBodyEntry=static_cast<CBodyQueueEntry8*>(qEntry);
       
   277 			//add the chunk to the CBodyQueueEntry8 object
       
   278 			multiChunkEightBitBodyEntry->AddChunkL(aData,aChunkNumber,aExtraFetchRequestCount);	
       
   279 			return;
       
   280 			}
       
   281 		}
       
   282 	//if the request was not on the queue then assert
       
   283 	if(i==count)
       
   284 		{
       
   285 		__ASSERT_DEBUG(EFalse,TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectNotFound));
       
   286 		}
       
   287 	}
       
   288 	
       
   289 	
       
   290 /**
       
   291 Loops through the queue looking for a CAttachmentQueueEntry that has been created for the entry. 
       
   292 If found ownership of the data is transferred to the object. Otherwise asserts.
       
   293 @param aData		The text to be stored. CImapMailStore takes ownership. 		
       
   294 @param aId			The id of the entry under which the object will be stored.
       
   295 @param aChunkNumber	The chunk number, used store the chunk in the correct order.
       
   296 @return	  			KErrNone if the request was found on the queue, KErrNotFound otherwise.
       
   297 */
       
   298 
       
   299 EXPORT_C void CImapMailStore::StoreAttachmentChunkL(HBufC8* aData,TMsvId aId,TInt aChunkNumber)
       
   300 	{
       
   301 	__ASSERT_DEBUG(aChunkNumber>=0,TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreDataChunkOutOfRange));
       
   302 	//get the entry on the queue
       
   303 	TInt count=iRequestArray.Count();
       
   304 	//loop through the requests on the queue
       
   305 	TInt i;
       
   306 	for(i=0;i<count;++i)
       
   307 		{
       
   308 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   309 		//if a CMultiChunkBodyEntry request exists to store body data into this entry 
       
   310 		if(qEntry->GetEntryType()==CQueueEntryBase::EAttachment && qEntry->GetId()==aId)
       
   311 			{
       
   312 			CAttachmentQueueEntry* multiChunkAttachmentEntry=static_cast<CAttachmentQueueEntry*>(qEntry);
       
   313 			//add the chunk to the CMultiChunkBodyEntry object
       
   314 			multiChunkAttachmentEntry->AddChunkL(aData,aChunkNumber);	
       
   315 			return;
       
   316 			}
       
   317 		}
       
   318 	//if the request was not on the queue then assert
       
   319 	if(i==count)
       
   320 		{
       
   321 		__ASSERT_DEBUG(EFalse,TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectNotFound));
       
   322 		}
       
   323 	}
       
   324 
       
   325 /**
       
   326 @param aObserver	The observer for the entry for which all outstanding requests will be cancelled .
       
   327 @return	  			KErrNone if one or more matching request were found on the queue, KErrNotFound otherwise.
       
   328 */
       
   329 
       
   330 EXPORT_C TInt CImapMailStore::CancelRequest(MMailStoreObserver& aObserver)
       
   331 	{
       
   332 	TInt err=KErrNotFound;	
       
   333 	//loop through the requests on the queue 
       
   334 	for(TInt i=iRequestArray.Count()-1;i>=0;--i)
       
   335 		{
       
   336 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   337 		//if a request matches the observer specified then remove it from the queue.
       
   338 		if(&(qEntry->GetObserver())==&aObserver)
       
   339 			{
       
   340 			qEntry->Cancel();
       
   341 			}
       
   342 		}
       
   343 		
       
   344 	for(TInt i=iRequestArray.Count()-1;i>=0;--i)
       
   345 		{
       
   346 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   347 		//if a request matches the observer specified then remove it from the queue.
       
   348 		if(&(qEntry->GetObserver())==&aObserver)
       
   349 			{
       
   350 			qEntry->CancelRequest();
       
   351 			//remove the request from the queue and delete it
       
   352 			iRequestArray.Remove(i);
       
   353 			delete qEntry;	
       
   354 			err=KErrNone;
       
   355 			}
       
   356 		}
       
   357 		
       
   358 		return err;
       
   359 	}
       
   360 	
       
   361 /**
       
   362 @param aId	The TMsvId of the entry for which all outstanding requests will be cancelled .
       
   363 @return	  	KErrNone if one or more matching request were found on the queue, KErrNotFound otherwise.
       
   364 */
       
   365 
       
   366 EXPORT_C TInt CImapMailStore::CancelRequest(TMsvId aId)
       
   367 	{
       
   368 	TInt err=KErrNotFound;
       
   369 	
       
   370 	//loop through the requests on the queue 
       
   371 	for(TInt i=iRequestArray.Count()-1;i>=0;--i)
       
   372 		{
       
   373 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   374 		//if a request matches the TMsvId specified then remove it from the queue.
       
   375 		if(qEntry->GetId()==aId)
       
   376 			{
       
   377 			qEntry->Cancel();
       
   378 			}
       
   379 		}
       
   380 	//loop through the requests on the queue 
       
   381 	for(TInt i=iRequestArray.Count()-1;i>=0;--i)
       
   382 		{
       
   383 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   384 		//if a request matches the TMsvId specified then remove it from the queue.
       
   385 		if(qEntry->GetId()==aId)
       
   386 			{
       
   387 			qEntry->CancelRequest();
       
   388 			//remove the request from the queue and delete it
       
   389 			iRequestArray.Remove(i);
       
   390 			delete qEntry;	
       
   391 			err=KErrNone;
       
   392 			}
       
   393 		}
       
   394 		
       
   395 		return err;
       
   396 	}
       
   397 
       
   398 /**
       
   399 Creates a CMsvPlainBodyTextQueueEntry used to store body text and adds the object to the queue.
       
   400 @param aTotalChunks		The number of chunks of body data that will be stored.
       
   401 @param aImapSettings 	The CImapSettings object.
       
   402 @param aFetchBodyInfo 	The CFetchBodyInfo object.
       
   403 @param aId				The id of the entry under which the object will be stored.
       
   404 @param aObserver		A reference to a MMailStoreObserver object that will be called back when the request is complete.
       
   405 @param aChunkObserver 	A reference to a MChunkOutOfOrderObserver that will be called back when a proper chunk is 
       
   406 					    recieved from server if a out of order chunk was recieved in previous FETCH response.
       
   407 @param aBinaryCap   if true, message body is downloaded using FETCH BINARY
       
   408 					else FETCH BODY is used to download body message
       
   409 @return
       
   410 */
       
   411 
       
   412 EXPORT_C void CImapMailStore::InitialiseStorePlainBodyTextL(TInt aTotalChunks, CImapSettings& aImapSettings, CFetchBodyInfo& aFetchBodyInfo, TInt aLogId, MMailStoreObserver& aObserver, MChunkOutOfOrderObserver& aChunkObserver, TBool aBinaryCap)
       
   413 	{
       
   414 	 __ASSERT_DEBUG(aTotalChunks>0, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreNoDataChunks));
       
   415 
       
   416 	__LOG_FORMAT((aLogId, "CImapMailStore::InitialiseStorePlainBodyTextL total chunks = %d",aTotalChunks));
       
   417 
       
   418 	CMsvPlainBodyTextQueueEntry* qEntry=CMsvPlainBodyTextQueueEntry::NewL(aTotalChunks,*this,iServerEntry,aImapSettings,aFetchBodyInfo,aLogId,aObserver,aChunkObserver,aBinaryCap);
       
   419 	CleanupStack::PushL(qEntry);
       
   420 	
       
   421 	//make sure that we do not place a CMsvPlainBodyTextQueueEntry on the queue if one aleady exists for this entry.
       
   422 #if (defined _DEBUG)
       
   423 	TIdentityRelation<CQueueEntryBase> relationIdsAndTypeMatch(IdsAndTypeMatch);
       
   424 	TInt index=iRequestArray.Find(qEntry,relationIdsAndTypeMatch);
       
   425 	__ASSERT_DEBUG(index==KErrNotFound, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectAlreadyExists));		
       
   426 #endif
       
   427 	iRequestArray.AppendL(qEntry);
       
   428 	CleanupStack::Pop(qEntry);
       
   429 	}
       
   430 
       
   431 /**
       
   432 Loops through the queue looking for a CMultiChunkBodyEntry that has been created for the entry. 
       
   433 If found ownership of the data is transferred to the object. Otherwise asserts.
       
   434 @param aChunkNumber	The chunk number, used store the chunk in the correct order.
       
   435 @param aId			The id of the entry under which the object will be stored.
       
   436 @param aData		The text to be stored. CImapMailStore takes ownership. 
       
   437 @return	  			ETrue if the chunk was recieved in order.
       
   438 					EFalse if the chunks were recieved out of order and the chunk storing array exceeded limit(3 chunks default).
       
   439 */	
       
   440 EXPORT_C TBool CImapMailStore::StorePlainBodyTextL(HBufC8* aData, TMsvId aId, TInt aChunkNumber, TInt aExtraFetchRequestCount)
       
   441 	{
       
   442 	 //chunk number starts at 1 for body chunks
       
   443 	__ASSERT_DEBUG(aChunkNumber>=0, TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreDataChunkOutOfRange));
       
   444 	//get the entry on the queue
       
   445 	TInt count=iRequestArray.Count();
       
   446 	//loop through the requests on the queue
       
   447 	TBool sendCommand = ETrue;
       
   448 	TInt i;
       
   449 	for(i=0;i<count;++i)
       
   450 		{
       
   451 		CQueueEntryBase* qEntry=iRequestArray[i];
       
   452 		//if a CMultiChunkBodyEntry request exists to store body data into this entry 
       
   453 		if(qEntry->GetEntryType()==CQueueEntryBase::EPlainTextBody && qEntry->GetId()==aId)
       
   454 			{
       
   455 			CMsvPlainBodyTextQueueEntry* multiChunkBodyEntry=static_cast<CMsvPlainBodyTextQueueEntry*>(qEntry);
       
   456 			//add the chunk to the CMultiChunkBodyEntry object
       
   457 		
       
   458 			sendCommand = multiChunkBodyEntry->AddChunkL(aData,aChunkNumber,aExtraFetchRequestCount);	
       
   459 			return sendCommand;
       
   460 			}
       
   461 		}
       
   462 	//if the request was not on the queue then assert
       
   463 	if(i==count)
       
   464 		{
       
   465 		__ASSERT_DEBUG(EFalse,TImapServerPanic::ImapPanic(TImapServerPanic::EMailStoreQueueEntryObjectNotFound));	
       
   466 		}
       
   467 	return sendCommand;
       
   468 	}