email/imap4mtm/imapsession/src/cimapcapability.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 "cimapcapability.h"
       
    18 #include "cimapcapabilityinfo.h"
       
    19 #include "ctransportmanager.h"
       
    20 #include "moutputstream.h"
       
    21 #include "cimapsessionconsts.h"
       
    22 #include "imappaniccodes.h"
       
    23 
       
    24 _LIT8(KTxtCapabilityFormat, "%d CAPABILITY\r\n");
       
    25 
       
    26 /**
       
    27 The factory constructor. Part of two phased construction.
       
    28 @param aCapabilityInfo Output parameter that will hold the capability information upon successful completion of this command.
       
    29 */
       
    30 CImapCapability* CImapCapability::NewL(CImapFolderInfo* aSelectedFolderData, TInt aLogId, CImapCapabilityInfo& aCapabilityInfo)
       
    31 	{
       
    32 	CImapCapability* self = new(ELeave) CImapCapability(aSelectedFolderData, aLogId, aCapabilityInfo);
       
    33 	CleanupStack::PushL(self);
       
    34 	self->ConstructL();
       
    35 	CleanupStack::Pop(self);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 /**
       
    40 
       
    41 */
       
    42 void CImapCapability::ConstructL()
       
    43 	{
       
    44 	}
       
    45 	
       
    46 /**
       
    47 Constructor.
       
    48 @param aCapabilityInfo Output parameter that will hold the capability information upon successful completion of this command.
       
    49 */
       
    50 CImapCapability::CImapCapability(CImapFolderInfo* aSelectedFolderData, TInt aLogId, CImapCapabilityInfo& aCapabilityInfo)
       
    51 	: CImapCommandEx(aSelectedFolderData, aLogId)
       
    52 	, iCapabilityInfo(aCapabilityInfo)
       
    53 	{
       
    54 	}
       
    55 		
       
    56 /**
       
    57 Destructor.
       
    58 */
       
    59 CImapCapability::~CImapCapability()
       
    60 	{
       
    61 	}
       
    62 	
       
    63 /**
       
    64 Responsible for sending the IMAP capability command to the remote server to 
       
    65 perform the desired action the IMAP client wishes. The data will be sent 
       
    66 to the remote server on the output stream provided. 
       
    67 It is assumed the output stream has already been set up and ready to use.
       
    68 
       
    69 @param aTagId	Used to generate the IMAP tag that identifies the message.
       
    70 @param aStream	The output stream on which the message will be sent.
       
    71 */
       
    72 void CImapCapability::SendMessageL(TInt aTagId, MOutputStream& aStream)
       
    73 	{
       
    74 	iTagId = aTagId;
       
    75 	TInt bufferLength = KTxtCapabilityFormat.iTypeLength - 2 + TagLength(aTagId); // -2 for "%d"
       
    76 
       
    77 	__ASSERT_DEBUG(iOutputBuffer==NULL, TImapServerPanic::ImapPanic(TImapServerPanic::ECommandOutputBufferNotNull));
       
    78 	iOutputBuffer = HBufC8::NewL(bufferLength);
       
    79 	iOutputBuffer->Des().Format(KTxtCapabilityFormat, iTagId);
       
    80 	
       
    81 	// Send the data on the output stream
       
    82 	aStream.SendDataReq(*iOutputBuffer);
       
    83 	}
       
    84 
       
    85 CImapCommand::TParseBlockResult CImapCapability::ParseUntaggedResponseL()
       
    86 	{
       
    87 	TParseBlockResult result = ENotRecognised;
       
    88 	if (GetNextPart().CompareF(KTxtImapCapability) == 0)
       
    89 		{
       
    90 		ParseCapabilityDataL(iUnparsedData);
       
    91 		result = ECompleteUntagged;
       
    92 		}
       
    93 		
       
    94 	return result;
       
    95 	}
       
    96 	
       
    97 /**
       
    98 Parses capability-data, which can be received 
       
    99 as part of an untagged CAPABILITY response,
       
   100 or as part of the response-code of a tagged LOGIN OK response.
       
   101 	(i.e. as the data in the square brackets)
       
   102 It assumes that the "CAPABILITY" item has already been identified
       
   103 @param the capability-data, but without the "CAPABILITY" string at the front.  And with no square brackets.
       
   104 */
       
   105 void CImapCapability::ParseCapabilityDataL(const TDesC8& aCapabilityData)
       
   106 	{
       
   107 	// From RFC3501 section 9
       
   108 	//
       
   109 	// capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1" *(SP capability)
       
   110 	// capability = ("AUTH=" auth-type) / atom
       
   111 	//
       
   112 	
       
   113 	// "CAPABILITY" has beem found, so we're just looking for basic space-separated atoms.
       
   114 	
       
   115 	// First, reset iCapabilityInfo as it's going to be given some new information.
       
   116 	iCapabilityInfo.Reset();
       
   117 		
       
   118 	RDesParts capabilityItems;
       
   119 	CleanupClosePushL(capabilityItems);
       
   120 		
       
   121 	GetDelimitedPartsL(' ', aCapabilityData, capabilityItems);
       
   122 	TInt countItems = capabilityItems.Count();
       
   123 	for (TInt i=0; i<countItems; ++i)
       
   124 		{
       
   125 		TPtrC8 capability = capabilityItems[i];
       
   126 		
       
   127 		if (capability.CompareF(KImapTxtImapVersion) == 0)
       
   128 			{
       
   129 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::EVersion4Rev1, ETrue);
       
   130 			}
       
   131 		else if (capability.CompareF(KImapTxtIdle) == 0)
       
   132 			{			
       
   133 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::EIdle, ETrue);
       
   134 			}
       
   135 		else if (capability.CompareF(KImapTxtStartTls) == 0)
       
   136 			{
       
   137 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::EStartTls, ETrue);
       
   138 			}
       
   139 		else if (capability.CompareF(KImapTxtLoginDisabled) == 0)
       
   140 			{
       
   141 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::ELoginDisabled, ETrue);
       
   142 			}
       
   143 		else if (capability.CompareF(KImapTxtAuthPlain) == 0)
       
   144 			{
       
   145 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::EAuthPlain, ETrue);
       
   146 			}
       
   147 #if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
       
   148 		else if (capability.CompareF(KImapTxtBinaryCap) == 0)
       
   149 			{
       
   150 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::EBinaryCap, ETrue);
       
   151 			}
       
   152 		else if (capability.CompareF(KImapTxtAuthCRamMd5) == 0)
       
   153 			{
       
   154 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::EAuthCramMd5, ETrue);
       
   155 			}
       
   156 		else if (capability.CompareF(KImapTxtAuthLogin) == 0)
       
   157 			{
       
   158 			iCapabilityInfo.SetFlag(CImapCapabilityInfo::EAuthLogin, ETrue);
       
   159 			}
       
   160 #endif
       
   161 		}
       
   162 	
       
   163 	CleanupStack::PopAndDestroy(&capabilityItems);
       
   164 	}