email/imap4mtm/imapsession/src/cimapfetchmultibodystructures.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 "cimapfetchmultibodystructures.h"
       
    17 #include "cimapfetchresponse.h"
       
    18 #include "moutputstream.h"
       
    19 
       
    20 CImapFetchMultiBodyStructures* CImapFetchMultiBodyStructures::NewL(CImapFolderInfo* aSelectedFolderInfo, TInt aLogId, const TDesC8& aSequenceSet, const TDesC8& aHeaderFields, MImapFetchStructureObserver& aObserver)
       
    21 	{
       
    22 	CImapFetchMultiBodyStructures* self = new (ELeave) CImapFetchMultiBodyStructures(aSelectedFolderInfo, aLogId, aSequenceSet, aHeaderFields, aObserver);
       
    23 	CleanupStack::PushL(self);
       
    24 	self->ConstructL();
       
    25 	CleanupStack::Pop();
       
    26 	return self;
       
    27 	}
       
    28 
       
    29 CImapFetchMultiBodyStructures::CImapFetchMultiBodyStructures(CImapFolderInfo* aSelectedFolderInfo, TInt aLogId, const TDesC8& aSequenceSet, const TDesC8& aHeaderFields, MImapFetchStructureObserver& aObserver)
       
    30 	: CImapFetchBodyStructureBase(aSelectedFolderInfo, aLogId, aHeaderFields)
       
    31 	, iObserver(aObserver)
       
    32 	{
       
    33 	iSequenceSet = &aSequenceSet;
       
    34 	}
       
    35 
       
    36 void CImapFetchMultiBodyStructures::ConstructL()
       
    37 	{
       
    38 	}
       
    39 
       
    40 CImapFetchMultiBodyStructures::~CImapFetchMultiBodyStructures()
       
    41 	{
       
    42 	delete iFetchResponse;
       
    43 	}
       
    44 
       
    45 /**
       
    46 @param aData Will contain a single line of response from the server for LOGIN command without \r\n.
       
    47 @return will be any one of this
       
    48 	1) If the next expected chunk is a literal block, ParseMessageL() will return the size of the block it expects.
       
    49 	2) If the next expected chunk is a line, ParseMessageL() will return 0, and Result() will return EImapResponseNone.
       
    50 	3) If no further data is expected (e.g. the OK or error tag has been received) then ParseMessageL() will return 0, 
       
    51 	   and Result() will return one of EImapResponseOk, EImapResponseNo or EImapResponseBad.
       
    52 */
       
    53 CImapCommand::TParseBlockResult CImapFetchMultiBodyStructures::DoParseBlockL(const TDesC8& aData)
       
    54 	{
       
    55 	if (iFetchResponse == NULL)
       
    56 		{
       
    57 		iFetchResponse = CImapFetchResponse::NewL();
       
    58 		}
       
    59 
       
    60 	CImapCommand::TParseBlockResult resultCode = CImapFetchBodyStructureBase::DoParseBlockL(aData);
       
    61 
       
    62 	switch (resultCode)
       
    63 		{
       
    64 		case ECompleteUntagged:
       
    65 			{
       
    66 			if (UidDataItemFoundInResponse())
       
    67 				{
       
    68 				// A genuine UID FETCH response was received.
       
    69 				// Pass ownership of iFetchResponse to the observer
       
    70 				CImapFetchResponse* fetchResponse = iFetchResponse;
       
    71 				iFetchResponse = NULL;
       
    72 				iObserver.OnFetchLD(fetchResponse);
       
    73 				}
       
    74 			else
       
    75 				{
       
    76 				// An unsolicited FETCH server event was received.
       
    77 				// Don't pass ownership of the fetch response to the observer, but delete it here instead.
       
    78 				delete iFetchResponse;
       
    79 				iFetchResponse = NULL;
       
    80 				}			
       
    81 			} 
       
    82 			break;
       
    83 		case ECompleteTagged:
       
    84 			{
       
    85 			// perform the final commit
       
    86 			iObserver.OnFetchCommit();
       
    87 			}
       
    88 			// fall through
       
    89 		case ENotRecognised:
       
    90 			{
       
    91 			delete iFetchResponse;
       
    92 			iFetchResponse = NULL;
       
    93 			}
       
    94 			break;
       
    95 		}
       
    96 
       
    97 	return resultCode;
       
    98 	}
       
    99 
       
   100 /**
       
   101 This is called when the session has processed all the blocks in its input buffer, but the 
       
   102 command is not yet complete (so it is expecting more data).
       
   103 Commit any headers that have been created in response to receiving fetch responses.
       
   104 */
       
   105 void CImapFetchMultiBodyStructures::WaitingForMoreDataL()
       
   106 	{
       
   107 	iObserver.OnFetchCommit();
       
   108 	}