Platform SDK: SMTP Server Events

Sink.h

[This is preliminary documentation and subject to change.]

#ifndef __SINK_H_
#define __SINK_H_

#include "resource.h"       // main symbols
#include <mailmsg.h>
#include <smtpevent.h>
#include <seo.h>
#define SMTPINITGUID
#include <smtpguid.h>

#define RESPONSE_DEFAULT "Please try again later dude"

/////////////////////////////////////////////////////////////////////////////
// CSink
class ATL_NO_VTABLE CSink : 
    public CComObjectRootEx<CComMultiThreadModel>,
    public CComCoClass<CSink, &CLSID_Sink>,
    public ISmtpInCommandSink,
    public IEventIsCacheable,
    public IPersistPropertyBag,
    public IDispatchImpl<ISink, &IID_ISink, &LIBID_SHIELDSUPLib>
{
public:
    CSink() : g_fHaveCustomText(FALSE)
    {
      g_szResponseText = new char[sizeof(RESPONSE_DEFAULT)+1];
      strcpy(g_szResponseText,RESPONSE_DEFAULT);
      g_dwResponseSize = strlen(RESPONSE_DEFAULT) + 1;
    }
   ~CSink()
   {
      if(g_szResponseText) {
         delete [] g_szResponseText;
         g_szResponseText = NULL;
      }
   }

DECLARE_REGISTRY_RESOURCEID(IDR_SINK)
DECLARE_NOT_AGGREGATABLE(CSink)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CSink)
    COM_INTERFACE_ENTRY(ISink)
    COM_INTERFACE_ENTRY(ISmtpInCommandSink)
    COM_INTERFACE_ENTRY(IEventIsCacheable)
    COM_INTERFACE_ENTRY(IPersistPropertyBag)
    COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

// ISink
public:
   STDMETHOD(UnRegisterSink)(/*[in]*/ long lInstance, /*[in]*/ BSTR BindingGUID);
   STDMETHOD(RegisterSink)(/*[in]*/ long lInstance, /*[in]*/ BSTR DisplayName, BSTR BindingGUID, BSTR ResponseText, VARIANT_BOOL fEnabled, BSTR* OutBindingGUID);
    /*
    ** ISmtpInCommandSink
    */
    STDMETHOD(OnSmtpInCommand)( 
            IUnknown *pServer,
            IUnknown *pSession,
            IMailMsgProperties *pMsg,
            ISmtpInCommandContext *pContext);

    /*
    ** IEventIsCacheable
    */
    STDMETHOD(IsCacheable)(void){ return S_OK;} 

    /*
    ** IPersistPropertyBag : IPersist
    */
    STDMETHOD(GetClassID)(CLSID *pClassID);
    STDMETHOD(InitNew)(void);
    STDMETHOD(Load)(IPropertyBag* pBag,IErrorLog *pErrorLog);
    STDMETHOD(Save)( 
            IPropertyBag *pPropBag,
            BOOL fClearDirty,
            BOOL fSaveAllProperties);

private:
   BOOL g_fHaveCustomText;
   DWORD g_dwResponseSize;
   LPSTR g_szResponseText;
};

#endif //__SINK_H_