email/imap4mtm/imapsession/src/cimaprename.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 "cimaprename.h"
       
    17 #include "moutputstream.h"
       
    18 #include "cimapsessionconsts.h"
       
    19 #include "imappaniccodes.h"
       
    20 
       
    21 // IMAP RENAME command
       
    22 _LIT8(KCommandRename, "%d RENAME %S %S\r\n");
       
    23 
       
    24 /**
       
    25 The factory constructor.
       
    26 */
       
    27 CImapRename* CImapRename::NewL(CImapFolderInfo* aSelectedFolderData, TInt aLogId, const TDesC& aOldMailboxName, const TDesC& aNewMailboxName)
       
    28 // static method first phase construction
       
    29 	{
       
    30 	CImapRename* self = new (ELeave) CImapRename(aSelectedFolderData, aLogId);
       
    31 	CleanupStack::PushL(self);
       
    32 	self->ConstructL(aOldMailboxName, aNewMailboxName);
       
    33 	CleanupStack::Pop();
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 /**
       
    38 Constructor.
       
    39 @param	aSelectedFolderData
       
    40 */
       
    41 CImapRename::CImapRename(CImapFolderInfo* aSelectedFolderData, TInt aLogId)	
       
    42 	: CImapCommandEx(aSelectedFolderData, aLogId)
       
    43 	{
       
    44 	}
       
    45 
       
    46 /**
       
    47 Second phase constructor.
       
    48 Will convert the 16-bit maiboxname parameters to IMAP UTF-7.
       
    49 @param aOldMailboxName mailbox whose name is to be changed
       
    50 @param aNewMailboxName the new name for the mailbox
       
    51 */
       
    52 void CImapRename::ConstructL(const TDesC& aOldMailboxName, const TDesC& aNewMailboxName)
       
    53 	{
       
    54 	iOldMailboxName = EncodeMailboxNameForSendL(aOldMailboxName);
       
    55 	iNewMailboxName = EncodeMailboxNameForSendL(aNewMailboxName);
       
    56 	}
       
    57 /**
       
    58 Destructor
       
    59 */
       
    60 CImapRename::~CImapRename()
       
    61 	{
       
    62 	delete iOldMailboxName;
       
    63 	delete iNewMailboxName;
       
    64 	}
       
    65 
       
    66 /**
       
    67 Formats and sends the IMAP RENAME command.
       
    68 @param aTagId Command sequence id which will be sent along with the IMAP command.
       
    69 @param aStream A wrapper for the outbound stream of a connected socket, using which
       
    70 the command will be send to the server
       
    71 */
       
    72 void CImapRename::SendMessageL(TInt aTagId, MOutputStream& aStream)
       
    73 	{
       
    74 	iTagId = aTagId;
       
    75 
       
    76 	TInt bufLength = KCommandRename().Length();
       
    77 	bufLength += TagLength(aTagId);
       
    78 	bufLength += iOldMailboxName->Length();
       
    79 	bufLength += iNewMailboxName->Length();
       
    80 
       
    81 	__ASSERT_DEBUG(iOutputBuffer==NULL, TImapServerPanic::ImapPanic(TImapServerPanic::ECommandOutputBufferNotNull));
       
    82 	iOutputBuffer = HBufC8::NewL(bufLength);
       
    83 	iOutputBuffer->Des().Format(KCommandRename, aTagId, iOldMailboxName, iNewMailboxName);
       
    84 
       
    85 	//send the command to the server
       
    86 	aStream.SendDataReq(*iOutputBuffer);
       
    87 	}