email/pop3andsmtpmtm/servermtmutils/src/CMsvPlainBodyTextEntry.CPP
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2007-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 "CMsvPlainBodyTextEntry.H"
       
    17 #include <msventry.h>
       
    18 #include <cmsvplainbodytext.h>
       
    19 
       
    20 #include "IMUTDLL.H"
       
    21 
       
    22 /**
       
    23 The NewL Factory function.
       
    24 */
       
    25 CMsvPlainBodyTextEntry* CMsvPlainBodyTextEntry::NewL(TInt aIs8Bit, CMsvServerEntry& aServerEntry, TUint aCharset, TUint aDefaultCharset)
       
    26 	{
       
    27 	CMsvPlainBodyTextEntry* self = new (ELeave) CMsvPlainBodyTextEntry();
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL(aIs8Bit, aServerEntry, aCharset, aDefaultCharset);
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 	
       
    34 /**
       
    35 Constructor.
       
    36 */
       
    37 CMsvPlainBodyTextEntry::CMsvPlainBodyTextEntry()
       
    38 	{	
       
    39 	}
       
    40 
       
    41 /**
       
    42 Creates an instance of CMsvPlainBodytext, that is used to store the bodytext .
       
    43 */	
       
    44 void CMsvPlainBodyTextEntry::ConstructL(TInt aIs8Bit, CMsvServerEntry& aServerEntry, TUint aCharset, TUint aDefaultCharset)
       
    45 	{
       
    46 	iPlainBodyTextCache = HBufC8::NewL(KPlainBodyTextCacheSizeBytes);
       
    47 	
       
    48 	iStore = aServerEntry.EditStoreL();	
       
    49 	iPlainBodyText = iStore->InitialisePlainBodyTextForWriteL(aIs8Bit, aCharset, aDefaultCharset);
       
    50 	}
       
    51 
       
    52 
       
    53 /**
       
    54 Destructor.
       
    55 */	
       
    56 CMsvPlainBodyTextEntry::~CMsvPlainBodyTextEntry()
       
    57 	{
       
    58 	delete iPlainBodyText;	
       
    59 	delete iStore;	
       
    60 	delete iPlainBodyTextCache;	
       
    61 	}
       
    62 		
       
    63 /**
       
    64 Adds a chunk of body data to the intermediate buffer.If aLineOfData contains last chunk of 
       
    65 data then it is directly written to store.
       
    66 @param aLineOfData 	the body data, ownership  is taken.
       
    67 */	
       
    68 void CMsvPlainBodyTextEntry::AddChunkL(const TDesC8& aLineOfData)
       
    69 	{
       
    70 	__ASSERT_DEBUG(iCommittedData != ECommittedData, gPanic(EPanicDataCommitted));
       
    71 	// Leave if the data has already been committed.
       
    72 	if(iCommittedData == ECommittedData)
       
    73 		{
       
    74 		User::Leave(KErrAlreadyExists);
       
    75 		}
       
    76 
       
    77 	TInt spaceLeft = KPlainBodyTextCacheSizeBytes - iPlainBodyTextCache->Length();
       
    78 	
       
    79 	// If iPlainBodyTextCache is full, then write the cache to the message store.
       
    80 	if(spaceLeft < aLineOfData.Length())
       
    81 		{
       
    82 		iPlainBodyText->StoreChunkL(*iPlainBodyTextCache);
       
    83 		iPlainBodyTextCache->Des().SetLength(0);
       
    84 		}
       
    85 
       
    86 	// Now we need to store aLineOfData
       
    87 	// Recalculate how much space is available in the cache
       
    88 	spaceLeft = KPlainBodyTextCacheSizeBytes - iPlainBodyTextCache->Length();
       
    89 	if(spaceLeft < aLineOfData.Length())
       
    90 		{
       
    91 		// We still don't have enough room.  Write this line directly to the store
       
    92 		iPlainBodyText->StoreChunkL(aLineOfData);
       
    93 		}
       
    94 	else
       
    95 		{
       
    96 		// Cache the line of data - it will get written later.
       
    97 		iPlainBodyTextCache->Des().Append(aLineOfData);
       
    98 		}
       
    99 	iCommittedData = EUnCommittedData;	
       
   100 	}
       
   101 	
       
   102 /**
       
   103 Commit the plainbody text file to message store.
       
   104 */	
       
   105 void CMsvPlainBodyTextEntry::TryCommitL()
       
   106 	{
       
   107 	switch(iCommittedData)
       
   108 		{
       
   109 		// Commit the data, since entire data is recieved at this point.
       
   110 		case EUnCommittedData:
       
   111 			{
       
   112 			// Write any remaining bodytext data to the store.
       
   113 			if(iPlainBodyTextCache->Size() > 0)
       
   114 				{
       
   115 				iPlainBodyText->StoreChunkL(*iPlainBodyTextCache);
       
   116 				iPlainBodyTextCache->Des().SetLength(0);
       
   117 				}
       
   118 				
       
   119 			// Now commit the data.
       
   120 			iPlainBodyText->CommitL();
       
   121 		
       
   122 			iCommittedData = ECommittedData;
       
   123 			// Clean up.
       
   124 			delete iPlainBodyText;
       
   125 			iPlainBodyText = NULL;
       
   126 			
       
   127 			delete iStore;
       
   128 			iStore = NULL;
       
   129 			break;
       
   130 			}
       
   131 		case ECommittedData:
       
   132 		case ENoData:
       
   133 		default:
       
   134 			{
       
   135 			// Nothing to do in this state since data has already been committed.
       
   136 			break;
       
   137 			}
       
   138 		}
       
   139 
       
   140 	}