//  Beta release only.
//
//  Copyright(c) Ivyware Pty Ltd 2013  (all rights reserved)
//               MELBOURNE, VICTORIA, AUSTRALIA, 3130
//
//  Provided no fee is charged (either by the distributer or user)
//  permission to use, copy, modify, and distribute this software and
//  its documentation for any purpose and without fee is hereby granted,
//  provided that the above copyright notice appear in all copies and
//  that both that copyright notice and this permission notice appear
//  in supporting documentation.
//
//  No waranty or suitablity for purpose is implied.
//
//
//  IMAPIFolder interface wrapper class
//  NOTES: Manages all subordinate IMAPIFolder resources
//      
#pragma once
#include "P2PmsgMAPI.h"
#include "MAPISession.h"

#define DEFAULT_FOLDER_BUFFER_SIZE 512

/////////////////////////////////////////////////////////////
//  CMAPIFolder
//  NOTES: Primarily wraps and manages the IMAPIFolder interface

class CMAPISession;
class CMAPImessage;
class P2PmsgMAPI_EXT CMAPIFolder : public CMAPIProp
{
      void
        RenderThisSafe ( );

    // Constructors and destructor
    public:
	      CMAPIFolder ( );
	      CMAPIFolder ( CMAPISession *pMAPISession, IMAPIFolder *pIMAPIFolder, LPCTSTR lpszName=NULL);
      virtual
	     ~CMAPIFolder ( );

    // Attributes
    protected:
      CMAPISession *m_pCMAPISession;
	    IMAPITable   *m_pHierarchy;
	    IMAPITable   *m_pContents;
	    int           m_nMaxRowsSize;
	    ULONG         m_nRowsIndex;
	    LPSRowSet     m_pSRowSet;
	    CString       m_strName;

    // Internal Operations
    protected:
	    BOOL
        QueryRows ( );
	    SRow*
        GetNextRow ( );

    // External Operations
    public:
	    void
        Attach ( CMAPISession* pCMAPISession, IMAPIFolder *pIMAPIFolder, LPCTSTR lpszName);

	    virtual void Close();
	    void
        SetBufferSize ( int nSize );
	    void
        ClearRowSet ( );

    // Folder and Message management
    public:
	    CMAPIFolder*
        Query4SubFolder ( LPCTSTR lpszSubFolder );
	    CMAPIFolder*
        Query4NextSubFolder ( );
      CMAPImessage*
        CreateMessage ( int nPriority=IMPORTANCE_NORMAL, BOOL bSaveToSentFolder=TRUE ); 

    // Property exposure
    public:
	    IMAPIFolder*
        GetIMAPIFolder();
	    IMAPITable*
        GetHierarchy ( );
      LPCTSTR
        GetName ( );
	    int
        GetRowCount();
	    IMAPITable*
        GetContents();
};
typedef P2PSafePtr<CMAPIFolder> CMAPIFolderSP;
