email/imap4mtm/imapsession/src/cimapcopy.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 "cimapcopy.h"
       
    18 #include "moutputstream.h"
       
    19 #include "imappaniccodes.h"
       
    20 
       
    21 // IMAP COPY command
       
    22 _LIT8(KCommandCopy, "%d UID COPY %S %S\r\n");
       
    23 
       
    24 CImapCopy*  CImapCopy::NewL(CImapFolderInfo* aSelectedFolderData, TInt aLogId, const TDesC8& aSequenceSet, const TDesC& aMailboxName)
       
    25 	{
       
    26 	CImapCopy* self = new (ELeave) CImapCopy(aSelectedFolderData, aLogId);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL(aSequenceSet, aMailboxName);
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 		
       
    33 CImapCopy::CImapCopy(CImapFolderInfo* aSelectedFolderData, TInt aLogId)
       
    34 	: CImapCommandEx(aSelectedFolderData, aLogId)	
       
    35 	{}
       
    36 	
       
    37 CImapCopy::~CImapCopy()
       
    38 	{
       
    39 	delete iSequenceSet;
       
    40 	delete iMailboxName;
       
    41 	}
       
    42 	
       
    43 void CImapCopy::ConstructL(const TDesC8& aSequenceSet, const TDesC& aMailboxName)
       
    44 	{
       
    45 	iSequenceSet = aSequenceSet.AllocL();
       
    46 	iMailboxName = EncodeMailboxNameForSendL(aMailboxName);
       
    47 	}
       
    48 /** 
       
    49 Formats and sends the IMAP COPY command.
       
    50 @param aTagId Command sequence id which will be sent along with the IMAP command.
       
    51 @param aStream A wrapper for the outbound stream of a connected socket, using which 
       
    52 the command will be send to the server
       
    53 */
       
    54 void CImapCopy::SendMessageL(TInt aTagId, MOutputStream& aStream)
       
    55 	{
       
    56 	iTagId = aTagId;
       
    57 	
       
    58 	TInt bufLength = KCommandCopy().Length();	
       
    59 	bufLength += TagLength(aTagId);
       
    60 	bufLength += iSequenceSet->Length();
       
    61 	bufLength += iMailboxName->Length();
       
    62 	
       
    63 	__ASSERT_DEBUG(iOutputBuffer==NULL, TImapServerPanic::ImapPanic(TImapServerPanic::ECommandOutputBufferNotNull));
       
    64 	iOutputBuffer = HBufC8::NewL(bufLength);	
       
    65 	iOutputBuffer->Des().Format(KCommandCopy, aTagId, iSequenceSet, iMailboxName);	
       
    66 	
       
    67 	//send the command to the server
       
    68 	aStream.SendDataReq(*iOutputBuffer);
       
    69 		
       
    70 	}