Click here to Skip to main content
15,893,588 members
Articles / Desktop Programming / ATL

En/Decode MIME-Content with MimeSniffer

Rate me:
Please Sign up or sign in to vote.
4.88/5 (26 votes)
2 Dec 20022 min read 376.3K   7K   74  
RFC-compliant Mime-En/Decoder
// MimeBody.h : Declaration of the CMimeBody

#ifndef __MIMEBODY_H_
#define __MIMEBODY_H_

#include "resource.h"       // main symbols
#include "MimeDecoder.h"

/////////////////////////////////////////////////////////////////////////////
// CMimeBody
class ATL_NO_VTABLE CMimeBody : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CMimeBody, &CLSID_MimeBody>,
	public IPersistBaseImpl,
	public IDispatchImpl<IMimeBody, &IID_IMimeBody, &LIBID_MIMESNIFFERLib>
{
public:
	CMimeBody();
	virtual ~CMimeBody();

DECLARE_REGISTRY_RESOURCEID(IDR_MIMEBODY)
DECLARE_NOT_AGGREGATABLE(CMimeBody)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CMimeBody)
	COM_INTERFACE_ENTRY(IMimeBody)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IPersistStream)
	COM_INTERFACE_ENTRY(IPersistStreamInit)
END_COM_MAP()

public:
	void Init(CYYSType* pBody, CMimeDecoder* pRoot);

protected:
	CYYSType*		m_pBody;
	CMimeDecoder*	m_pRoot;
	CMimeDecoder*	m_pProxy;

protected:
	CYYSType& GetField(LPCTSTR strField, bool bCreate = false);
	void GetFields(LPCTSTR strField, vector<CYYSType>& result);
	CYYSType& GetBody(CYYSType*& bContentIsRaw, bool bCreate = false);

public:
	// IPersistStream
	STDMETHOD(GetClassID)(CLSID* pClassID)
	{
		*pClassID = CLSID_MimeBody;
		return S_OK;
	}
	STDMETHOD(Load)(LPSTREAM pStm);
	STDMETHOD(Save)(LPSTREAM pStm, BOOL fClearDirty);

	// IPersistStreamInit
	STDMETHOD(InitNew)(void);

// IMimeBody
public:
	STDMETHOD(get_EmbeddedMessage)(/*[out, retval]*/ LPDISPATCH *pVal);
	STDMETHOD(get_Value)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_Value)(/*[in]*/ BSTR newVal);
	STDMETHOD(get_FileName)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_FileName)(/*[in]*/ BSTR newVal);
	STDMETHOD(Import)(/*[in]*/ LPUNKNOWN pStream, /*[in,defaultvalue(0)]*/ VARIANT_BOOL StreamByReference, /*[out,retval]*/ VARIANT_BOOL* pbvarResult);
	STDMETHOD(Export)(/*[in]*/ LPUNKNOWN pStream, /*[out,retval]*/ VARIANT_BOOL* pbvarResult);
	STDMETHOD(ImportFromFile)(/*[in]*/ BSTR Path, /*[in,defaultvalue(0)]*/ VARIANT_BOOL StreamByReference, /*[out,retval]*/ VARIANT_BOOL* pbvarResult);
	STDMETHOD(ExportAsFile)(/*[in]*/ BSTR Path, /*[out,retval]*/ VARIANT_BOOL* pbvarResult);
	STDMETHOD(get_ContentID)(/*[out, retval]*/ VARIANT *pVal);
	STDMETHOD(put_ContentID)(/*[in]*/ VARIANT newVal);
	STDMETHOD(get_Description)(/*[out, retval]*/ VARIANT *pVal);
	STDMETHOD(put_Description)(/*[in]*/ VARIANT newVal);
	STDMETHOD(get_Encoding)(/*[out, retval]*/ VARIANT *pVal);
	STDMETHOD(put_Encoding)(/*[in]*/ VARIANT newVal);
	STDMETHOD(get_ExtField)(/*[in]*/ BSTR strName, /*[out, retval]*/ VARIANT *pVal);
	STDMETHOD(put_ExtField)(/*[in]*/ BSTR strName, /*[in]*/ VARIANT newVal);
	STDMETHOD(get_MinorContentType)(/*[out, retval]*/ VARIANT *pVal);
	STDMETHOD(put_MinorContentType)(/*[in]*/ VARIANT newVal);
	STDMETHOD(get_MajorContentType)(/*[out, retval]*/ VARIANT *pVal);
	STDMETHOD(put_MajorContentType)(/*[in]*/ VARIANT newVal);
	STDMETHOD(get_Count)(long* pcount);
	STDMETHOD(get_Item)(long Index, VARIANT* pvar);
	STDMETHOD(AddNew)(/*[out,retval]*/ LPDISPATCH* ppResult);
	STDMETHOD(Remove)(/*[in]*/ long Index);
	STDMETHOD(Clear)();
};

#endif //__MIMEBODY_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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions