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

📄 gwcommand.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				{
					//show "failed to invoke the preferences dialog !!"
					DisplayMessage(NULL, IDS_E_PREF_LAUNCH_FAILURE);
					break;
				}
			}
			break;

		case IDM_AUTO_ENCRYPT_ONSEND:
			pgpAssert(NULL != m_hCtxtWindow);
			g_pccihCmdHash->ToggleState((ULONG)m_hCtxtWindow, MIS_AUTO_ENCRYPT_ON_SEND);
			break;

		case IDM_AUTO_SIGN_ONSEND:
			pgpAssert(NULL != m_hCtxtWindow);
			g_pccihCmdHash->ToggleState((ULONG)m_hCtxtWindow, MIS_AUTO_SIGN_ON_SEND);
			break;

		case IDM_DECRYPT_VERIFY://TODO:add the functionality for 
								//the command in main menu context
			{
				BSTR bstrResult=NULL;
				//int iHandleTokenRet=DLL_HAN_NO_ERROR;
				char szTokenBuf[200]={0};
				int iCipherTxtMsgLen=0;
				

				//PGP structs
				PGPError pgpErrRet=kPGPError_NoErr;
				PGPtlsContextRef tlsContext=NULL;
				PGPSize pgpsBufOutLen=0;
				char *pCipherBuf=NULL;
				char *pOutBuf=NULL;
				char *pFinalBuf=NULL;
				BOOL bForYourEyesOnly=FALSE;

				char szTitle[255]={0};
				int iRet=0;
				BOOL bRet=TRUE;

				pgpAssert(NULL != m_hCtxtWindow);
				pgpAssert(NULL != lpMsgInfo);
				pgpAssert((0 < (m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT)) ||
						(0 < (m_dwCmdUiInfo&CUIO_MAINWND_CONTEXT)) ||
						(0 < (m_dwCmdUiInfo&CUIO_ATTVIEW_CONTEXT)));

				g_pccihCmdHash->Lock();
				
				if((m_dwCmdUiInfo&CUIO_MAINWND_CONTEXT) &&//if in the main window context
				   (NULL == lpMsgInfo->bstrId))//if no/multiple mails are selected
				{
					//so, we dont know which message to operate on. now we can
					//pop a message saying that or else we just do nothing
					pgpAssert(FALSE);//interesting case to watch(not a failure)
					goto idm_decrypt_verify_cleanup;
				}

				if((m_dwCmdUiInfo&CUIO_ATTVIEW_CONTEXT) &&//if in the attachment viewer context
				   (NULL != lpMsgInfo->bstrId))
				{
					//get the attachment file name(s)

				
					//SendMessage(hWndViewer, WM_SETTEXT, 0, (LPARAM)"hello");

					goto idm_decrypt_verify_cleanup;
				}


				//get the type of this message being verified/decrypted
				ZeroMemory(szTokenBuf, sizeof(szTokenBuf));
				pgpAssert(NULL != lpMsgInfo->bstrId);
				sprintf(szTokenBuf, "ItemGetType(\"%S\")", lpMsgInfo->bstrId);
				hrRet=Publish(szTokenBuf, &bstrResult);
				if(FAILED(hrRet))
				{
					pgpAssert(FALSE);
					DisplayMessage(NULL, IDS_E_ITEM_TYPE, hrRet);
					goto idm_decrypt_verify_cleanup;
				}

				//check if the message being operated is a mail
				if(0 != wcscmp(bstrResult, MAILMESSAGETYPEW))
				{
					PgpGwTrace("Skipping one non-mail item(type=%S) sent.\n", bstrResult);
					goto idm_decrypt_verify_cleanup;
				}
				
				//check if the user has license to run us. we must have a valid 
				//license with desktop flag turned on in the license number for 
				//decrypt/verify to work
				if(FALSE == PgpGwExLicenseChk())
					goto idm_decrypt_verify_cleanup;

				//get a tls context for ourselves
				pgpAssert(NULL != g_pgpContext);
				pgpErrRet=PGPNewTLSContext(g_pgpContext, &tlsContext);
				if(IsPGPError(pgpErrRet) || (NULL == tlsContext))
				{
					pgpAssert(FALSE);
					hrRet=E_FAIL;
					DisplayMessage(NULL, IDS_E_PGP_INTERNAL, pgpErrRet);
					goto idm_decrypt_verify_cleanup;
				}

				//get the message text
				ZeroMemory(szTokenBuf, sizeof(szTokenBuf));
				sprintf(szTokenBuf, "ItemGetText(\"%S\";10)", lpMsgInfo->bstrId); 
				hrRet=Publish(szTokenBuf, &bstrResult);
				if(FAILED(hrRet))
				{
					pgpAssert(FALSE);
					DisplayMessage(NULL, IDS_E_GET_MESSAGE_TXT, hrRet);
					goto idm_decrypt_verify_cleanup;
				}
				
				//if there is no message text in the mail 
				if(0 == wcslen(bstrResult))
					goto idm_decrypt_verify_cleanup;//we are done

				//convert the message to ansi
				pCipherBuf=ConvertToAnsi(bstrResult);
				pgpAssert(NULL != pCipherBuf);
				if(NULL == pCipherBuf)
				{
					hrRet=E_OUTOFMEMORY;
					goto idm_decrypt_verify_cleanup;
				}

				//decrypt and verify the message text
 				pgpErrRet=DecryptVerifyBuffer(g_hInstance, m_hCtxtWindow, g_pgpContext, tlsContext, 
							CLIENTNAME, MODULEFILENAME, pCipherBuf, strlen(pCipherBuf), FALSE, FALSE, FALSE, 
							(void **)&pOutBuf, &pgpsBufOutLen, &bForYourEyesOnly);
				pgpAssert(!IsPGPError(pgpErrRet));
				pgpAssert(NULL != pOutBuf);
				pgpAssert(0 < pgpsBufOutLen);
				if(IsPGPError(pgpErrRet) || (NULL == pOutBuf) || (0 >= pgpsBufOutLen))
				{
					hrRet=E_FAIL;
					DisplayMessage(NULL, IDS_E_DECRYPT_VERIFY, pgpErrRet);
					goto idm_decrypt_verify_cleanup;
				}
				
				//if we are decrypting text in a new mail
				if(m_dwCmdUiInfo&CUIO_NEWMAIL_CONTEXT)//this should never get executed
				{
					//allocate buffer for the token and parameters
					pFinalBuf=(char *)calloc(pgpsBufOutLen+sizeof(szTokenBuf), 1);
					pgpAssert(NULL != pFinalBuf);
					if(NULL == pFinalBuf)
					{
						hrRet=E_OUTOFMEMORY;
						goto idm_decrypt_verify_cleanup;
					}

					//change the mail body to the decrypted stuff.
					sprintf(pFinalBuf, "ItemSetText(\"%S\";10;\"%s\")", lpMsgInfo->bstrId, pOutBuf); 
					hrRet=Publish(pFinalBuf, &bstrResult);
					if(FAILED(hrRet))
					{
						pgpAssert(FALSE);
						DisplayMessage(NULL, IDS_E_SET_DECMSG_TXT, hrRet);
						goto idm_decrypt_verify_cleanup;
					}
				}
				else if(m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT)
				{
					//if we are supposed to show decrypted stuff in secure viewer
					if((TRUE == bForYourEyesOnly) || (PGPscGetSecureViewerPref(g_pgpContext)))
					{
						//pop up secure viewer with(out) anti-tempest font
						PGPscTempestViewer(g_pgpContext, m_hCtxtWindow, pOutBuf, 
							pgpsBufOutLen, bForYourEyesOnly);
					}
					else//secure viewer option is not selected in PGP options
					{
						HWND hPlainTxtMsgWnd=NULL, hHtmlTxtMsgWnd=NULL, 
							hOverlappingWnd=NULL, hTrackedMsgWnd=NULL;

						//find out the current state of affairs
						hPlainTxtMsgWnd=lpMsgInfo->hPlainTxtMsgWnd;
						hHtmlTxtMsgWnd=lpMsgInfo->hHtmlTxtMsgWnd;
						hOverlappingWnd=lpMsgInfo->hNewMsgTxtWnd;

						//show the decrypted text
						SetTextOfReadOnlyMail(pOutBuf, hPlainTxtMsgWnd, hHtmlTxtMsgWnd, 
							hOverlappingWnd, hTrackedMsgWnd);
						
						//remember the window handles for operations later
						if((NULL != hPlainTxtMsgWnd) || (NULL != hOverlappingWnd) || (NULL != hTrackedMsgWnd))
						{
							lpMsgInfo->hPlainTxtMsgWnd=hPlainTxtMsgWnd;
							lpMsgInfo->hNewMsgTxtWnd=hOverlappingWnd;
							lpMsgInfo->hTrackedMsgWnd=hTrackedMsgWnd;
						}
						
						//if we are showing the overlapping window
						if((NULL != hOverlappingWnd) && 
						   (NULL != hPlainTxtMsgWnd) &&
						   (hPlainTxtMsgWnd != hOverlappingWnd) &&
						   (hHtmlTxtMsgWnd != hOverlappingWnd))
						{
							EnableCommands(lpMsgInfo->hMenuBar, FALSE, ECO_UNSUPPORTED);
						}
					}
				}
				else if(m_dwCmdUiInfo&CUIO_MAINWND_CONTEXT)
					0==0;//TODO: add code here for main window command

			idm_decrypt_verify_cleanup:

				g_pccihCmdHash->UnLock();

				if(NULL != bstrResult)
				{
					SysFreeString(bstrResult);
					bstrResult=NULL;
				}

				if(NULL != tlsContext)
				{
					PGPFreeTLSContext(tlsContext);
					tlsContext=NULL;
				}

				if(NULL != pOutBuf)
				{
					pgpAssert(pgpsBufOutLen > 0);
					PGPFreeData(pOutBuf);
					pOutBuf=NULL;
				}
				if(NULL != pFinalBuf)
				{
					free(pFinalBuf);
					pFinalBuf=NULL;
				}
				if(NULL != pCipherBuf)//not necessary but NTL -ssd
				{
					delete pCipherBuf;
					pCipherBuf=NULL;
				}

				//TODO:free pszRecipients array
				//return iHandleTokenRet;
			}

			break;

		case IDM_CONVERT_TO_PLAIN_TEXT:
			pgpAssert(NULL != m_hCtxtWindow);
			g_pccihCmdHash->ToggleState((ULONG)m_hCtxtWindow, MIS_CONV_TO_PLAIN_TEXT);
			break;
	
		case IDM_SHOW_ORIGINAL:
			{
				HWND hTrackedMsgWnd=NULL, hOverlappingWnd=NULL;
				HMENU hMainMenu=NULL;

				pgpAssert(NULL != m_hCtxtWindow);
				pgpAssert(NULL != lpMsgInfo);

				//get the window handles involved
				g_pccihCmdHash->Lock();
				hTrackedMsgWnd=lpMsgInfo->hTrackedMsgWnd;
				hOverlappingWnd=lpMsgInfo->hNewMsgTxtWnd;
				hMainMenu=lpMsgInfo->hMenuBar;
				g_pccihCmdHash->UnLock();

				//hide the overlapping window if it is around
				if((NULL != hOverlappingWnd) && (IsWindowVisible(hOverlappingWnd)))
				{
					ShowWindow(hTrackedMsgWnd, SW_SHOW);//show the original window
					ShowWindow(hOverlappingWnd, SW_HIDE);//hide the decrypt/verify window
					EnableCommands(hMainMenu, TRUE, 0);
				}

			}
			break;
		case IDM_MAIL_OPEN:
			{
#ifdef _DEBUG
				char szClassName[200]={0};
#endif
				pgpAssert(NULL == m_hCtxtWindow);//context window should be unknown till now
				pgpAssert(NULL == lpMsgInfo);//no info from hash should be existing for this command
				pgpAssert(NULL != m_pigwBaseCmd);
				if(NULL == m_pigwBaseCmd)
					break;

				HRESULT hrRet=m_pigwBaseCmd->Execute();
				pgpAssert(SUCCEEDED(hrRet));
				if(FAILED(hrRet))
					break;//error while opening - we dont do nothing

				//attempt to learn the context. we set the cmd context now so 
				//that learning is possible.
				m_dwCmdUiInfo |= CUIO_MAIL_CONTEXT;
				LearnCommandContext();
				pgpAssert(NULL != m_hCtxtWindow);

#ifdef _DEBUG
				//the current window should now be the opened mail window
				pgpAssert(GetClassName(m_hCtxtWindow, szClassName, sizeof(szClassName)-sizeof(char)) > 0);
				pgpAssert(0 == strcmp(szClassName, MAILVIEWWINDOWCLASSNAMEA));
#endif

				//now we need to decrypt/verify the message
				m_nID=IDM_DECRYPT_VERIFY;//we mutate "open" command to a decrypt command from now on
				hrRet=this->Execute();
				pgpAssert(SUCCEEDED(hrRet));
			}
			break;
		default:
			pgpAssert(FALSE);//control should never come here. unsupported operation attempted
			break;			 //on this command object !!
	}

end:
	return S_OK;
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::Help				
//
//  Description:Invokes help for the GWCommand.	
//
//  In:	none
//
//  Out:none
//
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::Help()
{
	PgpGwTrace("CGWCommand::Help\n");	
	return S_OK;
}

////////////////////////////////////////////////////////////////////
//	Name: CGWCommand::Undo				
//  
//  Description:Required method. Never called in XTD.	
//  
//  In:	none
//  
//  Out: none
//  
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::Undo()
{
	PgpGwTrace("CGWCommand::Undo\n");	
	return S_OK;
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::Validate				
//
//  Description:This interface is called to determine the state of a C3po
//       command. Determining the state is termed the validation.
//       he command is assumed by default to be in an enabled, unchecked,
//       visible state. The C3po provider can then modify that assumption
//       by returning flags. The available flags are:
//
//       eGW_CMDVAL_ALWAYS - The command is always in the same state
//	                         and there is no need to validate it again.
//       eGW_CMDVAL_CHECKED - The command has a check mark.
//       eGW_CMDVAL_DISABLED - The command is disabled.
//
//  In:	none
//
//  Out:long FAR* plValidate
//
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::Validate(long FAR* plValidate)
{
	//PgpGwTrace("CGWCommand::Validate this=%#x, m_nID=%d\n", this, m_nID);	
	HRESULT hrRet=S_OK;
	PMSGINFO lpMsgInfo=NULL;
	BOOL bRet=TRUE;

	//fill up the members and the hash with relevant details that might be missing
	hrRet=LearnCommandContext();
	if(FAILED(hrRet))//if we have any problem determining the context
	{
		*plValidate=eGW_CMDVAL_DISABLED;//dont wait till we are told to execute the command
		goto cleanup;					//so disable the command
	}

	//if the license has expired
	if(TRUE == g_bPlugInExpired)
	{
		*plValidate=eGW_CMDVAL_DISABLED;//we disable the command
		goto cleanup;
	}

	//get the context info
	pgpAssert(0 != m_dwCmdUiInfo);
	pgpAssert(NULL != m_hCtxtWindow);
	lpMsgInfo=g_pccihCmdHash->Get((ULONG)m_hCtxtWindow);
	if(NULL == lpMsgInfo)
	{
		*plValidate=eGW_CMDVAL_DISABLED;//dont wait till we are told to execute the command
		goto cleanup;
	}

	switch(m_nID)
	{
		case IDM_LAUNCH_PGPKEYS://launch pgpkeys
		case IDM_SHOW_PREFS://show the pgp options dialog
			*plValidate=0/*eGW_CMDVAL_ALWAYS*/;//always enabled
			break;

		case IDM_AUTO_ENCRYPT_ONSEND:
			pgpAssert(0 != (m_dwCmdUiInfo&CUIO_MAIL_CONTEXT));
			//lock the hash table			
			g_pccihCmdHash->Lock();

			//if the command is in the context of a discussion/note then disable it
			if(m_dwCmdUiInfo&CUIO_DISCUSSION_CONTEXT)
			{
				pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPTION);//should be an option
				pgpAssert(m_dwCmdUiInfo & CUIO_MAIL_CONTEXT);//discussion context is also a mail context
				
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}
			//if the command is in the context of a new mail
			else if(m_dwCmdUiInfo&CUIO_NEWMAIL_CONTEXT)
			{

⌨️ 快捷键说明

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