⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wrap2cmc.cpp

📁 email client and support pop3、smtp、imap protocol.
💻 CPP
字号:
// Wrapper for cmc calls
// Currently only sendmail function implemented fully
// Wrap2CMC.cpp: implementation of the Wrap2CMC class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "InetServer.h"
#include "Wrap2CMC.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Wrap2CMC::Wrap2CMC()
{
	hlibCMC	= NULL ;
        lpfnCMCQueryConfiguration = NULL; // currently not used
	lpfnCMCLogon = NULL;
	lpfnCMCLogoff = NULL;
	lpfnCMCFree = NULL;
	lpfnCMCLookUp = NULL;
        lpfnCMCList = NULL;     // currently not used
	lpfnCMCSend = NULL;
        lpfnCMCRead = NULL;     // currently not used
        lpfnCMCActOn = NULL;    // currently not used
}

Wrap2CMC::~Wrap2CMC()
{
    if (hlibCMC)
    {
        FreeLibrary (hlibCMC);
        hlibCMC = (HINSTANCE) NULL;
    }

	lpfnCMCQueryConfiguration = NULL;
	lpfnCMCLogon = NULL;
	lpfnCMCLogoff = NULL;
	lpfnCMCFree = NULL;
	lpfnCMCLookUp = NULL;
	lpfnCMCList = NULL;
	lpfnCMCSend = NULL;
	lpfnCMCRead = NULL;
	lpfnCMCActOn = NULL;
}

BOOL Wrap2CMC::CMCInstalled()
{

    LONG lr;
    HKEY hkWMS;
    
    char szCMCValue[8];
    DWORD dwType;
    DWORD cbCMCValue = 8;

    lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                    "SOFTWARE\\Microsoft\\Windows Messaging Subsystem",
                     0, KEY_READ, &hkWMS);
    if(ERROR_SUCCESS == lr)
    {
        lr = RegQueryValueEx(hkWMS, "CMC", 0, &dwType, (unsigned char*)szCMCValue, &cbCMCValue);
        RegCloseKey(hkWMS);
        if(ERROR_SUCCESS == lr)
        {
            if(lstrcmp(szCMCValue, "1") == 0)
                return TRUE;
        }
    }
    
    return FALSE;

}

BOOL Wrap2CMC::CMCInit()
{
    char    szLibName[32] = "MAPI32.dll" ;

    // Check if CMC is installed on the system
    if(!CMCInstalled())
        return FALSE;


    // Get INI directives for alternate DLL PATH
    GetProfileString( "Mail", "CMCDLLNAME32", szLibName, szLibName, 
            sizeof(szLibName) - 1 );

    if ((hlibCMC = LoadLibrary (szLibName)) <  (HINSTANCE) 32)
    {
        MessageBox(NULL, "Unable to Load MAPI/CMC Lintary","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }

    if (!(lpfnCMCQueryConfiguration = (LPFNCMCQUERYCONFIGURATION)GetProcAddress (hlibCMC, "cmc_query_configuration") ))
    {
        MessageBox(NULL,"Cannot Load cmc_query_configurations process addres.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }
    if (!(lpfnCMCLogon  =  (LPFNCMCLOGON)GetProcAddress (hlibCMC, "cmc_logon") ))
    {
        MessageBox(NULL, "Cannot Load cmc_logon process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }

    if (!(lpfnCMCLogoff  =  (LPFNCMCLOGOFF)GetProcAddress (hlibCMC, "cmc_logoff") ))
    {
        MessageBox(NULL, "Cannot Load cmc_logoff process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }
    if (!(lpfnCMCFree  =  (LPFNCMCFREE)GetProcAddress (hlibCMC, "cmc_free") ))
    {
        MessageBox(NULL, "Cannot Load cmc_free process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }
	
    if (!(lpfnCMCLookUp  =  (LPFNCMCLOOKUP)GetProcAddress (hlibCMC, "cmc_look_up") ))
    {
        MessageBox(NULL, "Cannot Load cmc_look_up process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }

    if (!(lpfnCMCList  =  (LPFNCMCLIST)GetProcAddress (hlibCMC, "cmc_list") ))
    {
        MessageBox(NULL, "Cannot Load cmc_list process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }
    if (!(lpfnCMCSend  =  (LPFNCMCSEND)GetProcAddress (hlibCMC, "cmc_send") ))
    {
        MessageBox(NULL, "Cannot Load cmc_send process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }
	if (!(lpfnCMCRead  =  (LPFNCMCREAD)GetProcAddress (hlibCMC, "cmc_read") ))
    {
        MessageBox(NULL, "Cannot Load cmc_read process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }

    if (!(lpfnCMCActOn  =  (LPFNCMCACTON)GetProcAddress (hlibCMC, "cmc_act_on") ))
    {
        MessageBox(NULL, "Cannot Load cmc_acto_on process address.","Error", MB_ICONSTOP | MB_OK);
        return FALSE;
    }

    return (TRUE);
}

CMC_return_code Wrap2CMC::CMCLogon(char *mProfile, char *mPassword)
{
	CMC_return_code cmcStatus ;
	
	cmcStatus = (*lpfnCMCLogon)(
              NULL,                   /* Default service           */
              mProfile,          
              mPassword,         
              NULL,                   /* Default character set     */
              0,                      /* Default UI ID             */
              CMC_VERSION,            /* Version 1 CMC calls       */
              0,                      /* No user interface */
              &CMCSession,            /* Returned session ID       */
              NULL);                  /* No extensions             */
	if ( cmcStatus ==  CMC_SUCCESS )
	{
		return cmcStatus ;
	}
	return cmcStatus ;
}

CMC_return_code Wrap2CMC::CMCLogoff()
{
	CMC_return_code cmcStatus ;

	cmcStatus = (*lpfnCMCLogoff)(
					CMCSession,            /* Session ID                    */
					0,                  /* No UI will be used.           */
					0,                  /* No flags                      */
					NULL);              /* No extensions                 */
	if ( cmcStatus == CMC_SUCCESS )
		return cmcStatus ;
	return cmcStatus ;
}

CMC_return_code Wrap2CMC::CMCLookUp(CMC_recipient FAR *Recip, CMC_uint32 *cCount, CMC_recipient FAR **pRecipient)
{
        
	CMC_return_code cmcStatus ;
	cmcStatus = (*lpfnCMCLookUp)(
		CMCSession	,            // Session handle          
                Recip           ,            // Name to look up         
		CMC_LOOKUP_RESOLVE_UI |      // Resolve names using UI. 
		CMC_ERROR_UI_ALLOWED  |      // Display errors using UI.
		CMC_LOOKUP_RESOLVE_PREFIX_SEARCH, // 
		(CMC_ui_id)0,                // Default UI ID           
		cCount,                     // Only want one back      
		pRecipient,                 // Returned recipient ptr  
		NULL);     
	if ( cmcStatus == CMC_SUCCESS )
	{
		return cmcStatus ;
	}

	return cmcStatus ;
}

CMC_return_code Wrap2CMC::CMCFree(CMC_recipient *pRecipient)
{
	CMC_return_code cmcStatus ;
	cmcStatus = (*lpfnCMCFree)(pRecipient);
	return cmcStatus ;
}

CMC_return_code Wrap2CMC::CMCSend(CMC_message FAR *lpMessage)
{
	CMC_return_code cmcStatus ;
	cmcStatus = (*lpfnCMCSend)(CMCSession ,
								lpMessage ,
								0			,
								0			,
								NULL );
	if ( cmcStatus == CMC_SUCCESS )
		return cmcStatus ;
	return cmcStatus ;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -