//  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.
//
//
//  IMessage environment wrapper class
//  NOTES: Manages all subordinate IMessage resources
//      
#pragma   once
#include "P2PmsgMAPI.h"
#include "MAPIProp.h"

class CMAPIEx;
class CMAPISession;

/////////////////////////////////////////////////////////////
//  CMAPImessage
//  NOTES: Primarily wraps and manages the IMessage interface

class P2PmsgMAPI_EXT CMAPImessage : public CMAPIProp
{
    // Constructors and destructor
    public:
	      CMAPImessage ( );
	     ~CMAPImessage ( );

    // Attributes
    protected:
	    CString       m_strSenderName;
	    CString       m_strSenderEmail;
	    CString       m_strSubject;
	    CString       m_strBody;
	    CString       m_strRTF;
	    LPMAPITABLE   m_pRecipients;
      CMAPISession *m_pCMAPISession;

    // Internal Operations
    protected:
      void
        SetMessageFlags ( int nFlags );
      int
        GetMessageFlags ( );
      void
        GetMessageClass ( CString& strMessageClass );

    // External Operations
    public:
     	BOOL
        Create ( CMAPISession *pCMAPISession, BOOL bSaveToSentFolder=TRUE, CMAPIFolder* pFolder=NULL); 
	    virtual void
        Close( );
      HRESULT
        SubmitMessage ( ULONG ulFlags = 0 );

    // Message property assignment
    public:
	    BOOL
        AddRecipients ( LPADRLIST pAddressList );
	    BOOL
        AddRecipient ( LPCTSTR lpszEmailAddress, int nType=MAPI_TO, LPCTSTR szAddrType=NULL);  // MAPI_CC and MAPI_BCC also valid
	    void
        SetSender ( LPCTSTR szSenderName, LPCTSTR szSenderEmail);
	    HRESULT
        SetReadReceipt ( BOOL bSet=TRUE, LPCTSTR lpszReceiverEmail=NULL );
	    HRESULT
        SetDeliveryReport ( BOOL bReport=TRUE );
	    HRESULT
        SetSensitivity ( int nSensitivity );
	    HRESULT
        SetMessageStatus ( int nMessageStatus );
      HRESULT
        SetImportance ( int nPriority );

    // Message Subject and Body management
    public:
	    void
        SetSubject ( LPCTSTR szSubject );
      HRESULT
        SetMessageEditorFormat ( int nFormat );
      BOOL
        SetBody ( LPCTSTR lpszBody );

    // Raw property exposure
    public:
      IMessage*
        GetIMessage ( );
};
typedef P2PSafePtr<CMAPImessage> CMAPImessageSP;
