📄 cpgpexch.cpp
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: CPGPexch.cpp,v 1.51 2002/11/22 03:14:18 pbj Exp $
____________________________________________________________________________*/
#include "CPGPexch.h"
#include <mapiutil.h>
#include "Globals.h"
#include "HiddenWindow.h"
#include "Outlook.h"
#include "Utils.h"
#include "resource.h"
#include "Prefs.h"
#include "pgpClientPrefs.h"
#include "pgpLnLib.h"
#include "CPGPMsgBackupHash.h"
#include "CPGPExtModeless.h"
#include "pgpUtilities.h"
#include "pgpDebug.h"
// The version that went out with Win95 is 410; with Exchange Server, 837.
// (RC1 used 611; RC2 used 736.3.)
// The Windows 95 Messaging Update is 839.
//
// Exchange 5.0 comes back as 4.0 build 1458
// Outlook 98 comes back as 4.0 build 1573
#define LAST_BUILD_SUPPORTED 1573
#define OUTLOOK98_BUILD 1573
// Other values returned by IExchExtCallback::GetVersion
// Microsoft Exchange 4.0 is 0x01??0400
#define CURRENT_PRODUCT_CODE 0x01000000
#define LAST_MAJVER_SUPPORTED 0x00000400
#define LAST_MINVER_SUPPORTED 0x00000000
extern "C" IExchExt* CALLBACK ExchEntryPoint();
static BOOL IsExchExtWithinOutlook(IExchExtCallback* peecb);
static void TurnOffWarning(ULONG ulMajVer, ULONG ulMinVer,
ULONG ulBuildMinVer);
static void SetNewerOK(ULONG ulMajVer,
ULONG ulMinVer,
ULONG ulBuildMinVer,
BOOL bOK);
static BOOL IsWarningOff(ULONG ulMajVer,
ULONG ulMinVer,
ULONG ulBuildMinVer);
static BOOL IsNewerOK(ULONG ulMajVer,
ULONG ulMinVer,
ULONG ulBuildMinVer);
static BOOL DoIExist(BOOL bOutlook, HANDLE *phSem);
static void SetNoLoad(void);
static BOOL ShouldILoad(void);
static void CheckExchangeServerID(HWND hWnd);
static void AddUserID(HWND hWnd, PGPKeyDBRef keyDB, PGPKeyDBObjRef key,
char *szName, char *szAddress);
// Global variables
PGPContextRef _pgpContext = NULL; // PGP context of current instance
PGPtlsContextRef _tlsContext = NULL; // TLS context of current instance
PGPMemoryMgrRef _memoryMgr = NULL; // Memory manager of PGP context
PGPError _errContext = kPGPError_NoErr; // Error code if context failed
UINT _nCopyDoneMsg = 0; // HTML copy text message
UINT _nPasteDoneMsg = 0; // HTML paste text message
CPGPMsgBackupHash g_MsgBackupHash;
// Local variables
static UINT _nRefCount = 0; // Ref count for freeing contexts
// DLL entry point
BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID)
{
if (DLL_PROCESS_ATTACH == fdwReason)
{
UISetInstance(hinstDll);
}
if (DLL_PROCESS_DETACH == fdwReason)
{
}
return TRUE;
}
// Exchange client extension entry point
IExchExt* CALLBACK ExchEntryPoint()
{
CPGPexch *pcpePGPExch = new CPGPexch;
#ifdef _DEBUG
ExchPluginTrace("ExchEntryPoint - constructed CPGPexch at %#x\n", pcpePGPExch);
#endif
return pcpePGPExch;
}
CPGPexch::CPGPexch()
: _cRef(1), _context(0),
_fInSubmitState(FALSE),
_fInitMenuOnce(FALSE)
{
#ifdef _DEBUG
ExchPluginTrace("CPGPexch(%#x) - constructed\n", this);
#endif
_hmenuPGP = NULL;
_bHaveAttachments = FALSE;
_bDecryptAttach = FALSE;
_pWipeList = NULL;
_hExistance = NULL;
m_pBackupMsg = NULL;
m_pExtMdlessCallBack = NULL;
m_pemOurMdlessCallBack = NULL;
_nRefCount++;
}
CPGPexch::~CPGPexch()
{
#ifdef _DEBUG
ExchPluginTrace("CPGPexch(%#x) - destroyed\n", this);
#endif
if (_hmenuPGP)
DestroyMenu(_hmenuPGP);
if (_pWipeList != NULL)
WipeAttachmentList();
if (m_pBackupMsg != NULL)
{
m_pBackupMsg->BackupRelease();
m_pBackupMsg = NULL;
}
if(NULL != m_pemOurMdlessCallBack)
{
m_pemOurMdlessCallBack->Release();
m_pemOurMdlessCallBack = NULL;
}
if(NULL != m_pExtMdlessCallBack)
{
m_pExtMdlessCallBack->Release();
m_pExtMdlessCallBack = NULL;
}
_nRefCount--;
if (!_nRefCount)
{
if (_hwndHidden)
{
DestroyWindow(_hwndHidden);
_hwndHidden = NULL;
}
if (_tlsContext)
{
PGPFreeTLSContext(_tlsContext);
_tlsContext = NULL;
}
if (_pgpContext && IsntPGPError(_errContext))
{
PGPclCloseLibrary();
_pgpContext = NULL;
_memoryMgr = NULL;
}
if (_hExistance != NULL)
CloseHandle(_hExistance);
}
}
STDMETHODIMP CPGPexch::QueryInterface(REFIID riid, void** ppvObj)
{
*ppvObj = NULL;
HRESULT hr = S_OK;
IUnknown* punk = NULL;
if (( IID_IUnknown == riid) || ( IID_IExchExt == riid) )
{
punk = (IExchExt*)this;
}
else if (IID_IExchExtMessageEvents == riid)
{
punk = (IExchExtMessageEvents*)this;
}
else if (IID_IExchExtCommands == riid)
{
punk = (IExchExtCommands*)this;
}
else if (IID_IExchExtAttachedFileEvents == riid)
{
punk = (IExchExtAttachedFileEvents*)this;
}
else
hr = E_NOINTERFACE;
if (NULL != punk)
{
*ppvObj = punk;
AddRef();
}
return hr;
}
STDMETHODIMP CPGPexch::Install(IExchExtCallback* peecb, ULONG eecontext, ULONG ulFlags)
{
ULONG ulBuildVer = 0;
ULONG ulProductVer = 0;
ULONG ulMajVer = 0;
ULONG ulMinVer = 0;
ULONG ulBuildMinVer = 0;
BOOL fMinorBuildOk = TRUE;
HRESULT hrRet = S_OK;
HWND hWnd = NULL;
LPADRBOOK pAddrBook = NULL;
PGPError err = kPGPError_NoErr;
#ifdef _DEBUG
ExchPluginTrace("CPGPexch(%#x)::Install in context %#x flags %#x\n",
this, eecontext, ulFlags);
#endif
hrRet = peecb->GetWindow(&hWnd);
pgpAssert(SUCCEEDED(hrRet));
if (NULL == hWnd)
hWnd = GetTopWindow(NULL);
hrRet = peecb->GetVersion(&ulProductVer, EECBGV_GETVIRTUALVERSION);
if (SUCCEEDED(hrRet))
hrRet = peecb->GetVersion(&ulBuildVer, EECBGV_GETBUILDVERSION);
if (FAILED(hrRet))
{
UIDisplayStringID(hWnd, IDS_E_NOVERSION);
SetNoLoad();
return S_FALSE;
}
ulMajVer = ulProductVer & EECBGV_VERSION_MAJOR_MASK;
ulMinVer = ulProductVer & EECBGV_VERSION_MINOR_MASK;
ulBuildMinVer = ulBuildVer & EECBGV_BUILDVERSION_MINOR_MASK;
// Check to see if we're running Outlook 97
_fOutlook = IsExchExtWithinOutlook(peecb);
// Check to see if we're running Outlook 98
if (ulBuildMinVer == OUTLOOK98_BUILD)
_fOutlook98 = TRUE;
else
_fOutlook98 = FALSE;
// Check to see if we're running Outlook 2000
_fOutlook2000 = FALSE;
_fOutlookXP = FALSE;
if (_fOutlook98)
{
HKEY hKey;
LONG lResult;
DWORD dwSize = _MAX_PATH;
// char szRegPath[_MAX_PATH];
char szExePath[_MAX_PATH];
GetModuleFileName(NULL, szExePath, _MAX_PATH);
GetShortPathName(szExePath, szExePath, _MAX_PATH);
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Office\\9.0\\Common\\InstallRoot",
0, KEY_QUERY_VALUE, &hKey);
if (lResult == ERROR_SUCCESS)
{
/*
RegQueryValueEx(hKey, "Path", NULL, NULL, (LPBYTE) szRegPath,
&dwSize);
szRegPath[dwSize] = 0;
GetShortPathName(szRegPath, szRegPath, _MAX_PATH);
if (!strnicmp(szExePath, szRegPath, strlen(szRegPath)))
*/
_fOutlook2000 = TRUE;
RegCloseKey(hKey);
}
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Office\\10.0\\Common\\InstallRoot",
0, KEY_QUERY_VALUE, &hKey);
if (lResult == ERROR_SUCCESS)
{
/*
RegQueryValueEx(hKey, "Path", NULL, NULL, (LPBYTE) szRegPath,
&dwSize);
szRegPath[dwSize] = 0;
GetShortPathName(szRegPath, szRegPath, _MAX_PATH);
if (!strnicmp(szExePath, szRegPath, strlen(szRegPath)))
*/
{
_fOutlookXP = TRUE;
_fOutlook2000 = FALSE;
}
RegCloseKey(hKey);
}
}
_fLoaded = DoIExist(_fOutlook, &_hExistance);
if (!ShouldILoad())
return S_FALSE;
if ((_fLoaded) && (_pgpContext == NULL))
_errContext = PGPNewContext(kPGPsdkAPIVersion, &_pgpContext);
_context = eecontext;
// Check for SDK expiration or other SDK initialization failure
if (IsPGPError(_errContext))
{
if (_errContext == kPGPError_FeatureNotAvailable)
UIDisplayStringID(hWnd, IDS_E_EXPIRED);
else
PGPclErrorBox(hWnd, _errContext);
SetNoLoad();
PGPFreeContext(_pgpContext);
_pgpContext = NULL;
return S_FALSE;
}
// Initialize common library
if (!_fLoaded)
{
err = PGPclInitLibrary(&_pgpContext, kPGPclEnableNewUserWizard);
if (IsPGPError(err))
{
if (err == kPGPError_FeatureNotAvailable)
UIDisplayStringID(hWnd, IDS_E_EXPIRED);
else
PGPclErrorBox(hWnd, err);
SetNoLoad();
PGPclCloseLibrary();
_pgpContext = NULL;
return S_FALSE;
}
// Check for beta/demo expiration
PGPlnLicenseCheck (_pgpContext);
if (PGPlnIsExpired(hWnd, kPGPlnModuleGraceExpiration) != kPGPError_NoErr)
{
SetNoLoad();
PGPclCloseLibrary();
_pgpContext = NULL;
return S_FALSE;
}
#if 0
//the the user needs to have a desktop license in order to use exchange
//server accounts (the desktop flag will never be turned off with the
//enterprise flag turned on so checking one is enough)
if((FALSE == PGPlnDesktop()) && PGPclIsExchangeServerUser())
{
SetNoLoad();
PGPclCloseLibrary();
_pgpContext = NULL;
return S_FALSE;
}
#endif
}
// Don't allow the plug-in to load if this is a file being
// sent from Windows Explorer
if (eecontext == EECONTEXT_SENDNOTEMESSAGE)
{
IMessage *pmsg = 0;
hrRet = peecb->GetObject(NULL, (IMAPIProp**)&pmsg);
if (SUCCEEDED(hrRet))
{
LPMAPITABLE ptableAttach = 0;
LPADRLIST pAddrList = 0;
SizedSPropTagArray(1, tagaAttach) = {1, {PR_ATTACH_LONG_FILENAME}};
SizedSPropTagArray(1, tagaTable) = {1, {PR_ATTACH_NUM}};
SizedSPropTagArray(1, tagaMsg) = {1, {PR_SUBJECT}};
SRowSet *prAttach = 0;
SPropValue *pval;
ULONG ulNumVals;
BOOL bError = FALSE;
char szSubject[1024];
hrRet = pmsg->GetProps((SPropTagArray *)&tagaMsg, 0, &ulNumVals,
&pval);
szSubject[0] = 0;
if (SUCCEEDED(hrRet))
{
if (pval[0].Value.lpszA &&
((pval[0].ulPropTag & 0xFF) != PT_ERROR))
{
if (strlen(pval[0].Value.lpszA) > 0)
strcpy(szSubject, pval[0].Value.lpszA);
}
MAPIFreeBuffer(pval);
}
hrRet = pmsg->GetAttachmentTable(0, &ptableAttach);
if (SUCCEEDED(hrRet) && (ptableAttach != NULL) &&
(szSubject[0] != 0))
{
ULONG ulNumRows;
ULONG ulNumMatch = 0;
ptableAttach->GetRowCount(0, &ulNumRows);
if (ulNumRows > 0)
{
LPATTACH pAttach = 0;
ULONG ulRow;
ULONG ulNum;
char szFileName[_MAX_PATH];
char *szLnk;
HrQueryAllRows(ptableAttach, (SPropTagArray *)&tagaTable,
NULL, NULL, 0, &prAttach);
for (ulRow=0; ulRow<prAttach->cRows; ulRow++)
{
ulNum = prAttach->aRow[ulRow].lpProps[0].Value.l;
pmsg->OpenAttach(ulNum, NULL, 0, &pAttach);
pAttach->GetProps((SPropTagArray *)&tagaAttach, 0,
&ulNumVals, &pval);
if (pval[0].Value.lpszA &&
((pval[0].ulPropTag & 0xFF) != PT_ERROR))
{
strcpy(szFileName, pval[0].Value.lpszA);
szLnk = strstr(szFileName, ".lnk");
if (szLnk != NULL)
*szLnk = 0;
if (strstr(szSubject, szFileName))
ulNumMatch++;
MAPIFreeBuffer(pval);
}
else
ulNumMatch++;
pAttach->Release();
}
if (ulNumMatch == ulNumRows)
{
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
UIWarnOk(hWnd, IDS_E_MUSTRUN,
kPGPPrefWin32OutlookNotFromExplorer);
bError = TRUE;
}
}
}
if (prAttach != NULL)
{
FreeProws(prAttach);
prAttach = NULL;
}
if (ptableAttach != NULL)
{
ptableAttach->Release();
ptableAttach = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -