Click here to Skip to main content
15,896,730 members
Articles / Desktop Programming / ATL

OeLibrary 1.0

Rate me:
Please Sign up or sign in to vote.
4.91/5 (19 votes)
22 Aug 2013GPL33 min read 134K   2.5K   56  
Opensource Outlook Express automation library
// Message.h : Declaration of the CMailItem

#ifndef __MESSAGE_H_
#define __MESSAGE_H_

#include "resource.h"       // main symbols
#include "OutlookInterface\\msoeapi.h"
#include "attachment.h"
typedef struct tagMsgStructure
{
    MESSAGEID msgId;
	BSTR To;
	BSTR From;
	BSTR Subject;
	BSTR Message;
	MsgPriority MailPriority;
	VARIANT_BOOL bRead;
}MsgStruct;


/////////////////////////////////////////////////////////////////////////////
// CMailItem
class ATL_NO_VTABLE CMailItem : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CMailItem, &CLSID_MailItem>,
	public ISupportErrorInfo,
	public IDispatchImpl<IMailItem, &IID_IMailItem, &LIBID_OELib>
{

	private:
		BOOL InitializeFolder();
		CComPtr<IStoreNamespace> pStoreNamespace;
		unsigned int m_nAttachmentCount;
		BOOL m_bAttachmentCalled;
		LPHBODY pprgAttach;
		CComPtr<IMimeMessage> piMime;
		
public:
    CComPtr<IStoreFolder> pStoreFolder;
    ULONG m_nNoOfAttachment;//no od Attachment
	BSTR bstMessageTo;//Message Send to
	BSTR bstMessageFrom;//Message Send From
	BSTR bstMessageSubject;//Message Subject
    DWORD m_dwMessageID; //MessageID
	DWORD m_dwParentFolderID;//FolderID
	BOOL m_bSerialKey;
	BOOL m_bMsgReadOnly;
	MsgStruct m_LocalMsgStruct;
	
	CMailItem():m_dwMessageID(0),m_dwParentFolderID(0),m_bAttachmentCalled(FALSE),m_nAttachmentCount(0),m_nNoOfAttachment(0),m_bSerialKey(FALSE)
	{
			pStoreNamespace=NULL;
		pStoreFolder=NULL;
		piMime=NULL;
		
		HRESULT hr=::CoCreateInstance(CLSID_StoreNamespace,NULL,CLSCTX_ALL,IID_IStoreNamespace,(void**)&this->pStoreNamespace);
		
		//set msg to Read Only
		m_bMsgReadOnly=TRUE;
		m_LocalMsgStruct.MailPriority=NORMAL;
		m_LocalMsgStruct.bRead=FALSE;

		
		//Now initialize IStoreNamespace	
		hr=this->pStoreNamespace->Initialize(0,0);	
		//Give The ID TO
		this->m_dwParentFolderID=FOLDERID_ROOT;

	}



DECLARE_REGISTRY_RESOURCEID(IDR_MESSAGE)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CMailItem)
	COM_INTERFACE_ENTRY(IMailItem)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

// IMailItem
public:
	STDMETHOD(get_SetReadOnly)(/*[out, retval]*/ BOOL *pVal);
	STDMETHOD(put_SetReadOnly)(/*[in]*/ BOOL newVal);
	STDMETHOD(SetBody)(/*[in]*/BSTR BodyMsg);
	STDMETHOD(get_Priority)(/*[out, retval]*/ MsgPriority *pVal);
	STDMETHOD(put_Priority)(/*[in]*/ MsgPriority newVal);
	STDMETHOD(get_Subject)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_Subject)(/*[in]*/ BSTR newVal);
	STDMETHOD(get_From)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_From)(/*[in]*/ BSTR newVal);
	STDMETHOD(get_To)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_To)(/*[in]*/ BSTR newVal);
	STDMETHOD(get_MsgState)(/*[out, retval]*/ long *pVal);
	STDMETHOD(GetNextAttachment)(/*[out,retval]*/IAttachment **ppAttachment);
	STDMETHOD(GetFirstAttachment)(/*[out,retval]*/IAttachment **ppAttachment);
	STDMETHOD(Body)(/*[out,retval]*/BSTR* bstTextBody);
	STDMETHOD(Delete)();
	STDMETHOD(Copy)(/*[in]*/IMailFolder*pIFolder);
	STDMETHOD(Move)(/*[in]*/IMailFolder*pIFolder);
	STDMETHOD(get_Read)(/*[out, retval]*/ VARIANT_BOOL *pVal);
	STDMETHOD(put_Read)(/*[in]*/ VARIANT_BOOL newVal);
	STDMETHOD(get_AttachmentCount)(/*[out, retval]*/ short *pVal);
	STDMETHOD(get_MessageID)(/*[out, retval]*/ long *pVal);
	STDMETHOD(get_ParentFolderID)(/*[out, retval]*/ long *pVal);
	STDMETHOD(put_ParentFolderID)(/*[in]*/ long newVal);
};

#endif //__MESSAGE_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
India India
He used to have biography here Smile | :) , but now he will hire someone (for free offcourse Big Grin | :-D ), Who writes his biography on his behalf Smile | :)

He is Great Fan of Mr. Johan Rosengren (his idol),Lim Bio Liong, Nishant S and DavidCrow and Believes that, he will EXCEL in his life by following there steps!!!

He started with Visual C++ then moved to C# then he become language agnostic, you give him task,tell him the language or platform, he we start immediately, if he knows the language otherwise he quickly learn it and start contributing productively

Last but not the least, For good 8 years he was Visual CPP MSMVP!

Comments and Discussions