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

📄 sendmsgwndproc.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 3 页
字号:
				SetMenuItemInfo(plugin->hPGPMenu, IDC_PGPKEYS, FALSE, 
					&menuInfo);
				
				return lResult;
			}
		}
		break;

	case WM_NOTIFY:
		if ((((LPNMHDR) lParam)->code) == TTN_GETDISPINFO) 
		{
			int idCtrl;
			NMTTDISPINFO *pInfo;
			BOOL bTooltip = FALSE;

			idCtrl = ((LPNMHDR) lParam)->idFrom;
			pInfo = (NMTTDISPINFO *) lParam;

			switch (idCtrl)
			{
			case IDC_ENCRYPT_SMIME:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_SMIME_ENCRYPT;
				bTooltip = TRUE;
				break;

			case IDC_SIGN_SMIME:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_SMIME_SIGN;
				bTooltip = TRUE;
				break;

			case IDC_ENCRYPT_PGP:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_PGP_ENCRYPT;
				bTooltip = TRUE;
				break;

			case IDC_SIGN_PGP:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_PGP_SIGN;
				bTooltip = TRUE;
				break;

			case IDC_PGPKEYS:
				pInfo->lpszText = (LPTSTR) IDS_TOOLTIP_PGPKEYS;
				bTooltip = TRUE;
				break;
			}

			if (bTooltip)
			{
				pInfo->hinst = UIGetInstance();
				return 0;
			}
		}
		break;
	}

	return CommonWndProc(hDlg, msg, wParam, lParam);
}


BOOL EncryptSignMessage(HWND hwnd)
{
	HWND hAttach;
	char *szInput = NULL;
	char *szOutput;
	DWORD dwLength;
	PGPSize nOutLength;
	PGPclRecipientDialogStruct *prds = NULL;
	PGPOptionListRef signOptions = NULL;
	PluginInfo *plugin;
	BOOL bSuccess = FALSE;
	char szExe[256];
	char szDll[256];
	PGPError nError = kPGPError_NoErr;
	
	UIGetString(szExe, sizeof(szExe), IDS_EXE);
	UIGetString(szDll, sizeof(szDll), IDS_DLL);
	
	plugin = GetPluginInfo(hwnd);

	if (plugin->bOE5)
	{
		HWND hContainer;

		hContainer = FindWindowEx(hwnd, NULL, "OE_Envelope", NULL);
		hAttach = FindWindowEx(hContainer, NULL, "SysListView32", NULL);
	}
	else
		hAttach = FindWindowEx(hwnd, NULL, "SysListView32", NULL);

	if (hAttach)
		if (ListView_GetItemCount(hAttach) > 0)
			if (!UIWarnUser(hwnd, IDS_W_ATTACHMENT, "Attachment"))
				return FALSE;

	prds = (PGPclRecipientDialogStruct *) 
			calloc(sizeof(PGPclRecipientDialogStruct), 1);
	if(NULL == prds)
		goto EncryptSignMessageError;

	nError = PGPclOpenDefaultKeyrings(plugin->pgpContext, 
				kPGPOpenKeyDBFileOptions_Mutable, &(prds->keydbOriginal));

	if (IsPGPError(nError))
		nError = PGPclOpenDefaultKeyrings(plugin->pgpContext, 
					kPGPOpenKeyDBFileOptions_None, &(prds->keydbOriginal));

	if (IsPGPError(nError))
	{
		UIDisplayErrorCode(__FILE__, __LINE__, szDll, nError, TRUE);
		goto EncryptSignMessageError;
	}

	if (!GetMessageText(hwnd, FALSE, &szInput))
		goto EncryptSignMessageError;

	dwLength = strlen(szInput);
	FixBadSpaces(szInput);

	if (plugin->bEncrypt)
	{
		char *szRecipients;

		if (!GetRecipientText(hwnd, &szRecipients))
			goto EncryptSignMessageError;

		nError = GetRecipients(hwnd, szRecipients, plugin->pgpContext, 
					plugin->tlsContext, prds);
		free(szRecipients);
	}

	if (IsPGPError(nError))
	{
		if (nError != kPGPError_UserAbort)
			UIDisplayErrorCode(__FILE__, __LINE__, szDll, 
				nError, FALSE);

		goto EncryptSignMessageError; 
	}
			
	nError = EncryptSignBuffer(UIGetInstance(), hwnd, plugin->pgpContext, 
				plugin->tlsContext, szExe, szDll, szInput, dwLength, prds, 
				NULL, &signOptions, (void **) &szOutput, &nOutLength, 
				plugin->bEncrypt, plugin->bSign, FALSE, FALSE);

	free(szInput);
	szInput = NULL;

	if (IsntPGPError(nError))
	{
		if (nOutLength)
		{
			char *szTemp;

			szTemp = (char *) PGPNewData(plugin->memoryMgr, nOutLength+3, 0);
			strcpy(&szTemp[2], szOutput);
			szTemp[0] = '\r';
			szTemp[1] = '\n';
			PGPFreeData(szOutput);
			szOutput = szTemp;
			nOutLength += 2;
		}

		if (!SetMessageText(hwnd, szOutput))
			PGPFreeData(szOutput);
		else
		{
			if (plugin->szOutput != NULL)
			{
				free(plugin->szOutput);
				plugin->szOutput = NULL;
			}

			plugin->szOutput = (char *) calloc(nOutLength + 1, 1);
			if(NULL != plugin->szOutput)
			{
				strcpy(plugin->szOutput, szOutput);
				PGPFreeData(szOutput);
				bSuccess = TRUE;//success
			}
			else
				PGPFreeData(szOutput);//failure since we could not allocate
		}
	}

EncryptSignMessageError:

	if (signOptions != NULL)
	{
		PGPFreeOptionList(signOptions);
		signOptions = NULL;
	}

	if(NULL != prds)
	{
		if (prds->keydbOriginal != NULL)
		{
			PGPFreeKeyDB(prds->keydbOriginal);
			prds->keydbOriginal = NULL;
		}

		FreeRecipients(prds);
		free(prds);
		prds = NULL;
	}

	if (szInput != NULL)
		free(szInput);

	return bSuccess;
}


void DoubleLineFeeds(char *szOriginal, char *szNew)
{
	int nOrigIndex = 0;
	int nNewIndex = 0;
	BOOL bCRLF = FALSE;

	while (szOriginal[nOrigIndex] != '\0')
	{
		szNew[nNewIndex++] = szOriginal[nOrigIndex++];
		if (szOriginal[nOrigIndex-1] == '\n')
		{
			if (bCRLF)
			{
				szNew[nNewIndex++] = '\r';
				szNew[nNewIndex++] = '\n';
				bCRLF = FALSE;
			}
			else
				bCRLF = TRUE;
		}
	}

	szNew[nNewIndex] = '\0';
	return;
}


static void UpdateMenus(HWND hwnd, PluginInfo *plugin)
{
	if (plugin->bEncrypt)
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_ENCRYPT_PGP, 
			MF_BYCOMMAND | MF_CHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_ENCRYPT_PGP,
			MAKELONG(TRUE, 0));
	}
	else
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_ENCRYPT_PGP, 
			MF_BYCOMMAND | MF_UNCHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_ENCRYPT_PGP,
			MAKELONG(FALSE, 0));
	}
	
	if (plugin->bSign)
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_SIGN_PGP, 
			MF_BYCOMMAND | MF_CHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_SIGN_PGP,
			MAKELONG(TRUE, 0));
	}
	else
	{
		CheckMenuItem(plugin->hToolsMenu, IDC_SIGN_PGP, 
			MF_BYCOMMAND | MF_UNCHECKED);
		SendMessage(plugin->hToolbar, TB_CHECKBUTTON, IDC_SIGN_PGP,
			MAKELONG(FALSE, 0));
	}
	
}


LRESULT CALLBACK SendToolbarParentWndProc(HWND hDlg, 
										  UINT msg,
										  WPARAM wParam, 
										  LPARAM lParam)
{
	WNDPROC lpOldProc;
	PluginInfo *plugin;
	LPNMHDR lpnm;
	LPNMTOOLBAR lptb;

	lpOldProc = (WNDPROC)GetProp( hDlg, "oldproc" );
	plugin = GetPluginInfo(hDlg);

	lpnm = (LPNMHDR) lParam;
	lptb = (LPNMTOOLBAR) lParam;

	switch(msg)
	{
		case WM_NOTIFY:
			{
				switch(lpnm->code)
				{
					case TBN_BEGINADJUST:
						//if we have inserted our stuff into the toolbar already
						if(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE)
							RemoveSendToolbarButtons(plugin);//de-initialize/remove stuff
						break;

					case TBN_ENDADJUST:
						{
							//DWORD dwSize;
							//int nX;
							//int nY;
							LRESULT lResult;
							
							lResult = CallWindowProc(lpOldProc, hDlg, msg, wParam, 
										lParam);

							//if we have not inserted our stuff into the toolbar already
							if(!(plugin->dwInitState & PIIF_TOOLSINSERTION_DONE))
							{
								//insert our stuff as necessary
								pgpAssert(-1 == plugin->nPGPKeysButton);
								AddSendToolbarButtons(plugin);								
							}

								
							/*dwSize = SendMessage(plugin->hToolbar, TB_GETBUTTONSIZE, 
										0, 0);
							nX = LOWORD(dwSize);
							nY = HIWORD(dwSize);
							
							SendMessage(plugin->hToolbar, TB_ADDBUTTONS, 4, 
								(LPARAM) &tbb);
							
							SendMessage(plugin->hToolbar, TB_SETBUTTONSIZE, 0, 
								MAKELONG(nX, nY));*/
							
							return lResult;
						}//case TBN_ENDADJUST

						break;

					default:
						break;
				}
			}
			break;
		default:
			break;
	}

	return CallWindowProc(lpOldProc, hDlg, msg, wParam, lParam);
}


void AddSendToolbarButtons(PluginInfo *lppilPlugInf)
{
	TBBUTTON tbb[4]={0};
	char szText[255] = {0};
	int nX = -1;
	int nEncryptBMP = -1;
	int nSignBMP = -1;
	int nPGPkeysBMP = -1;
	LONG lResult = 0;
	int nEncryptSTR = -1;
	int nSignSTR = -1;
	int nPGPkeysSTR = -1;
	int nRet = 0;

	//we should not be called out of sequence
	pgpAssert(lppilPlugInf->dwInitState & PIIF_MAINUIELEMENTS_FOUND);
	pgpAssert(!(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE));
	if(lppilPlugInf->dwInitState & PIIF_TOOLSINSERTION_DONE)
		return;//we have already inserted ourselves to the toolbar
	
	//get the no of buttons in the toolbar currently
	//nX = SendMessage(lppilPlugInf->hToolbar, TB_BUTTONCOUNT, 0, 0);
	//if (nX < 2)//if less than 2 buttons
	//	return;//bail. try again later ?!!

	//we should not be there already. alternately OE could not be using
	//our command id for itself
	pgpAssert(-1 == SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX, IDC_ENCRYPT_PGP, 0));
	pgpAssert(-1 == SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX, IDC_SIGN_PGP, 0));
	pgpAssert(-1 == SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX, IDC_PGPKEYS, 0));
	
	//add the encrypt bitmap to the imagelists
	nEncryptBMP = LoadAppropriateBitmaps(lppilPlugInf, IDC_ENCRYPT_PGP);
	pgpAssert(-1 != nEncryptBMP);

	//remember the encrypt image index
	pgpAssert(-1 == lppilPlugInf->nEncryptImage);
	lppilPlugInf->nEncryptImage = nEncryptBMP;

	//load the sign bitmap
	nSignBMP = LoadAppropriateBitmaps(lppilPlugInf, IDC_SIGN_PGP);
	pgpAssert(-1 != nSignBMP);

	//remember the sign bitmap image index
	pgpAssert(-1 == lppilPlugInf->nSignImage);
	lppilPlugInf->nSignImage = nSignBMP;

	//load the pgpkeys bitmap
	nPGPkeysBMP = LoadAppropriateBitmaps(lppilPlugInf, IDC_PGPKEYS);
	pgpAssert(-1 != nPGPkeysBMP);

	//remember the keys bitmap image index
	pgpAssert(-1 == lppilPlugInf->nPGPKeysImage);
	lppilPlugInf->nPGPKeysImage = nPGPkeysBMP;

	//set the normal image list back
	//SendMessage(lppilPlugInf->hToolbar, TB_SETIMAGELIST, 0, (LPARAM) hilToolbar);
	
	if (lppilPlugInf->bOE5)
	{
		TBBUTTON tbOE;
		int nIndex;
		int nEncryptSMIME;
		int nSignSMIME;
		
		//set the hot imagelist back. this is not necessary since we are not creating
		//a separate imagelist. just appending to the existing
		//SendMessage(lppilPlugInf->hToolbar, TB_SETHOTIMAGELIST, 0, (LPARAM) hilHotToolbar);
		
		//add the strings for encrypt and sign and pgpkeys

		//if we have not already added the string for encrypt button
		if(-1 == lppilPlugInf->nEncryptString)
		{
			UIGetString(szText, 254, IDS_BUTTON_PGP_ENCRYPT);
			nEncryptSTR = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 0, (LPARAM) szText);
			pgpAssert(-1 != nEncryptSTR);

			lppilPlugInf->nEncryptString = nEncryptSTR;
		}

		//if we have not already added the string for sign button
		if(-1 == lppilPlugInf->nSignString)
		{
			UIGetString(szText, 254, IDS_BUTTON_PGP_SIGN);
			nSignSTR = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 0, (LPARAM) szText);
			pgpAssert(-1 != nSignSTR);

			lppilPlugInf->nSignString = nSignSTR;
		}

		//if we have not already added the string for pgpkeys button
		if(-1 == lppilPlugInf->nPGPKeysString)
		{
			UIGetString(szText, 254, IDS_TOOLTIP_PGPKEYS);
			nPGPkeysSTR = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 0, (LPARAM) szText);
			pgpAssert(-1 != nPGPkeysSTR);

			lppilPlugInf->nPGPKeysString = nPGPkeysSTR;
		}	
		
		//find the smime encrypt button of OE
		nIndex = SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
					IDC_OE5_ENCRYPT_SMIME, 0);
		if (nIndex > -1)//if found
		{
			//add our smime string to the toolbar
			UIGetString(szText, 254, IDS_BUTTON_SMIME_ENCRYPT);
			nEncryptSMIME = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 
								0, (LPARAM) szText);
			
			//get smime button details
			SendMessage(lppilPlugInf->hToolbar, TB_GETBUTTON, nIndex,
				(LPARAM) &tbOE);
			
			//set the text to our text
			tbOE.iString = nEncryptSMIME;

			//delete button and reinsert
			SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, nIndex, 0);
			SendMessage(lppilPlugInf->hToolbar, TB_INSERTBUTTON, nIndex, 
				(LPARAM) &tbOE);
		}
		
		//find the smime sign button of OE
		nIndex = SendMessage(lppilPlugInf->hToolbar, TB_COMMANDTOINDEX,
					IDC_OE5_SIGN_SMIME, 0);
		if (nIndex > -1) //if found
		{
			//add our smime sign string to toolbar
			UIGetString(szText, 254, IDS_BUTTON_SMIME_SIGN);
			nSignSMIME = SendMessage(lppilPlugInf->hToolbar, TB_ADDSTRING, 0,
				(LPARAM) szText);
			
			//get smime sign button details
			SendMessage(lppilPlugInf->hToolbar, TB_GETBUTTON, nIndex,
				(LPARAM) &tbOE);
			
			tbOE.iString = nSignSMIME;//set the text to our text

			//delete button and reinsert
			SendMessage(lppilPlugInf->hToolbar, TB_DELETEBUTTON, nIndex, 0);
			SendMessage(lppilPlugInf->hToolbar, TB_INSERTBUTTON, nIndex, 
				(LPARAM) &tbOE); 
		}
	}//end if (lppilPlugInf->bOE5)
	
	//add our buttons with a separator from the rest
	tbb[0].iBitmap = -1;
	tbb[0].idCommand = -1;
	tbb[0].fsState = TBSTATE_ENABLED;
	tbb[0].fsStyle = TBSTYLE_SEP;
	tbb[0].dwData = 0;
	tbb[0].iString = -1;
	
	tbb[1].iBitmap = nEncryptBMP;
	tbb[1].idCommand = IDC_ENCRYPT_PGP;
	tbb[1].fsState = TBSTATE_ENABLED;
	tbb[1].fsStyle = TBSTYLE_CHECK;
	tbb[1].dwData = 0;
	tbb[1].iString = lppilPlugInf->nEncryptString;
	
	tbb[2].iBitmap = nSignBMP;
	tbb[2].idCommand = IDC_SIGN_PGP;
	tbb[2].fsState = TBSTATE_ENABLED;
	tbb[2].fsStyle = TBSTYLE_CHECK;
	tbb[2].dwData = 0;
	tbb[2].iString = lppilPlugInf->nSignString;

	tbb[3].iBitmap = nPGPkeysBMP;
	tbb[3].idCommand = IDC_PGPKEYS;
	tbb[3].fsState = TBSTATE_ENABLED;
	tbb[3].fsStyle = TBSTYLE_BUTTON;
	tbb[3].dwData = 0;
	tbb[3].iString = lppilPlugInf->nPGPKeysString;
	
	//we must send TB_BUTTONSTRUCTSIZE before sending TB_ADDBITMAP 
	//or TB_ADDBUTTONS  message NOTE: this message has side effects
	SendMessage(lppilPlugInf->hToolbar, TB_BUTTONSTRUCTSIZE, 
			(WPARAM) sizeof(TBBUTTON), 0);

	//add the buttons
	lResult = SendMessage(lppilPlugInf->hToolbar, TB_ADDBUTTONS, 4, (LPARAM) &tbb);
	pgpAssert(TRUE == lResult);
	if(TRUE == lResult)//if successful
	{
		//retrieve and store the index of pgpkeys button
		pgpAssert(-1 == lppilPlugInf->nPGPKeysButton);

⌨️ 快捷键说明

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