email/imap4mtm/imapsession/src/cimapstore.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 
       
    17 #include "cimapstore.h"
       
    18 
       
    19 #include "moutputstream.h"
       
    20 #include "cimapsessionconsts.h"
       
    21 #include "imappaniccodes.h"
       
    22 
       
    23 // IMAP STORE command
       
    24 _LIT8(KCommandStore, "%d UID STORE %S %S %S\r\n");
       
    25 _LIT8(KUseSilent, ".SILENT");
       
    26 
       
    27 CImapStore*  CImapStore::NewL(CImapFolderInfo* aSelectedFolderData, TInt aLogId, const TDesC8& aSequenceSet, const TDesC8& aMessageDataItems, const TDesC8& aValue, TBool aUseSilent, RArrayMessageFlagInfo& aOutMessageFlagInfo)
       
    28 	{
       
    29 	CImapStore* self = new (ELeave) CImapStore(aSelectedFolderData, aLogId, aOutMessageFlagInfo);
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL(aSequenceSet, aMessageDataItems, aValue, aUseSilent);
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CImapStore::CImapStore(CImapFolderInfo* aSelectedFolderData, TInt aLogId, RArrayMessageFlagInfo& aOutMessageFlagInfo) 
       
    37 	: CImapFetchFlags(aSelectedFolderData, aLogId, aOutMessageFlagInfo)
       
    38 	{}
       
    39 
       
    40 CImapStore::~CImapStore()
       
    41 	{
       
    42 	delete iMessageDataItems;
       
    43 	delete iValue;
       
    44 	}
       
    45 	
       
    46 void CImapStore::ConstructL(const TDesC8& aSequenceSet, const TDesC8& aMessageDataItems, const TDesC8& aValue, TBool aUseSilent)
       
    47 	{
       
    48 	CImapFetchFlags::ConstructL(aSequenceSet);
       
    49 	
       
    50 	iMessageDataItems = aMessageDataItems.AllocL();
       
    51 	iValue = aValue.AllocL();	
       
    52 	iUseSilent = aUseSilent;
       
    53 	}
       
    54 
       
    55 /** 
       
    56 Formats and sends the IMAP STORE command.
       
    57 @param aTagId Command sequence id which will be sent along with the IMAP command.
       
    58 @param aStream A wrapper for the outbound stream of a connected socket, using which 
       
    59 the command will be sent to the server
       
    60 */	
       
    61 void CImapStore::SendMessageL(TInt aTagId, MOutputStream& aStream)
       
    62 	{
       
    63 	iTagId = aTagId;
       
    64 	
       
    65 	TInt bufLength = KCommandStore().Length();
       
    66 	bufLength += TagLength(aTagId);
       
    67 	bufLength += iSequenceSet->Length();
       
    68 	
       
    69 	if(iUseSilent)
       
    70 		//Append .SILENT option to message_data_items.
       
    71 		{
       
    72 		iMessageDataItems = iMessageDataItems->ReAlloc(iMessageDataItems->Length() + KUseSilent().Length());
       
    73 		iMessageDataItems->Des().Append(KUseSilent);
       
    74 		}
       
    75 		
       
    76 	bufLength += iMessageDataItems->Length();
       
    77 	bufLength += iValue->Length();
       
    78 	
       
    79 	__ASSERT_DEBUG(iOutputBuffer==NULL, TImapServerPanic::ImapPanic(TImapServerPanic::ECommandOutputBufferNotNull));
       
    80 	iOutputBuffer = HBufC8::NewL(bufLength);
       
    81 	iOutputBuffer->Des().Format(KCommandStore, aTagId, iSequenceSet, iMessageDataItems, iValue);	
       
    82 	
       
    83 	//send the command to the server
       
    84 	aStream.SendDataReq(*iOutputBuffer);		
       
    85 	}