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

📄 recipients.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
								rgPropVals[ulDisplayName].Value.lpszA;
						
					szPutNull = strstr(szName, " (E-mail)");
					if (szPutNull)
						*szPutNull = 0;
						
					szName = NULL;
					if (ulOriginalName != ULONG_MAX)
						szName = aEntries[ulRow].
									rgPropVals[ulOriginalName].Value.lpszA;

					if (szName == NULL)
					{
						szName = aEntries[ulRow].
									rgPropVals[ulDisplayName].Value.lpszA;
		
						if (!strcmp(szAddrType, "EX"))
						{
							szName = szRecip;
							while (strstr(szName, "cn=") != NULL)
								szName = strstr(szName, "cn=") + 1;
							
							if (szName == szRecip)
								szName = aEntries[ulRow].
											rgPropVals[ulDisplayName].
											Value.lpszA;
							else
								szName += 2;
						}
					}

					MAPIAllocateBuffer(256, (void **)
						&(newAddress.aEntries[0].rgPropVals[0].Value.lpszA));

					strcpy(newAddress.aEntries[0].rgPropVals[0].Value.lpszA,
						szName);

					result = pContainer->ResolveNames(
								(LPSPropTagArray) &propTags, 0, 
								(LPADRLIST) &newAddress, 
								(FlagList *) &flags);

					if (flags.ulFlag[0] == MAPI_RESOLVED)
					{
						ulNumProxies = newAddress.aEntries[0].
										rgPropVals[1].Value.MVszA.cValues;

						pszProxy = newAddress.aEntries[0].
									rgPropVals[1].Value.MVszA.lppszA;
					}
				}

				if ((ulProxy == ULONG_MAX) && 
					(flags.ulFlag[0] == MAPI_AMBIGUOUS))
				{
					ULONG ulSearch;
					ULONG ulMatch = 0;
					BOOL bWait;
					HANDLE hSem;
					
					if (_pGALRows == NULL)
					{
						HWND hGAL;

						hGAL = CreateDialog(UIGetInstance(), 
								MAKEINTRESOURCE(IDD_GAL), prds->hwndParent,
								GALDlgProc);

						ShowWindow(hGAL, SW_SHOW);

						_beginthread(FetchGlobalAddressList, 0, 
							(void *) pContainer);
						
						bWait = TRUE;
						do
						{
							UpdateWindow(hGAL);
							Sleep(1000);

							hSem = CreateSemaphore(NULL, 0, 1, 
									"pgpFetchGlobalAddressList");
							
							if ((hSem != NULL) && 
								(GetLastError() == ERROR_ALREADY_EXISTS))
								;
							else
								bWait = FALSE;
							
							CloseHandle(hSem);
						}
						while (bWait);

						DestroyWindow(hGAL);
					}
					
					ulMatch = ULONG_MAX;
					
					if (_pGALRows != NULL)
					{
						for (ulSearch=0; ulSearch<_pGALRows->cRows; 
								ulSearch++)
						{
							if (!stricmp(szRecip,
								_pGALRows->aRow[ulSearch].lpProps[0].
									Value.lpszA))
							{
								ulMatch = ulSearch;
								ulSearch = _pGALRows->cRows - 1;
							}
						}
					}

					if (ulMatch != ULONG_MAX)
					{
						ulNumProxies = _pGALRows->aRow[ulMatch].
										lpProps[1].Value.MVszA.cValues;

						pszProxy = _pGALRows->aRow[ulMatch].
									lpProps[1].Value.MVszA.lppszA;
					}
				}
				else if (ulProxy != ULONG_MAX)
				{
					ulNumProxies = aEntries[ulRow].
									rgPropVals[ulProxy].Value.MVszA.cValues;

					pszProxy = aEntries[ulRow].
								rgPropVals[ulProxy].Value.MVszA.lppszA;
				}

				if (pszProxy != NULL)
				{
					if (GetSMTPAddress(ulNumProxies, pszProxy, prds, 
							pdwRecipIndex, pdwNumRecip, szSMTP, &bRecipAdded))
					{
						szRecip = szSMTP;
						bGotSMTP = TRUE;
					}
					else
						bGotSMTP = FALSE;
				}
				else
					bGotSMTP = FALSE;
			}
		}

		if (!bGotSMTP && !bRecipAdded && (ulIndex == ulEmailAddr))
		{
			char *szNameCopy;
			char *szLastName;
			char *szFirstName;
			
			if (ulOriginalName == ULONG_MAX)
				ulIndex = ulDisplayName;
			else
				ulIndex = ulOriginalName;
			
			szRecip = aEntries[ulRow].rgPropVals[ulIndex].Value.lpszA;
			szNameCopy = (char *) calloc(1, strlen(szRecip) + 1);
			strcpy(szNameCopy, szRecip);
			
			szLastName = strtok(szNameCopy, ",");
			
			if (szLastName != NULL)
			{
				szFirstName = szLastName + strlen(szLastName) + 2;
				strcpy(szRecip, szFirstName);
				strcat(szRecip, " ");
				strcat(szRecip, szLastName);
			}
			
			free(szNameCopy);
			bGotSMTP = TRUE;
		}

		if (bGotSMTP)
		{
			// Make sure the recipient e-mail address is not
			// a null string
			nRecipLength = strlen(szRecip);
			if (!nRecipLength)
			{
				(*pdwNumRecip)--;
				continue;
			}
			
			// Finally, make sure the address has at least one
			// printable non-space character in it
			for (nChar=0; nChar<nRecipLength; nChar++)
			{
				if (isgraph(szRecip[nChar]))
					break;
			}
			
			if (nChar >= nRecipLength)
			{
				(*pdwNumRecip)--;
				continue;
			}
			
			(prds->szRecipientArray)[*pdwRecipIndex] = 
				(char *) calloc(1, nRecipLength+1);
			
			strcpy((prds->szRecipientArray)[*pdwRecipIndex], szRecip);
			(*pdwRecipIndex)++;
		}
	}

	return;
}


BOOL GetSMTPAddress(ULONG ulNum, LPSTR *lppszProxy,
					RECIPIENTDIALOGSTRUCT *prds,
					DWORD *pdwRecipIndex, DWORD *pdwNumRecip,
					char *szAddress, BOOL *pbRecipAdded)
{
	BOOL			bMatch = FALSE;
	BOOL			bReturn = FALSE;
	BOOL			*pbSMTP = NULL;
	BOOL			bFoundSMTP = FALSE;
	const char *	szNewAddress = NULL;
	ULONG			ulIndex;
	PGPFilterRef	filter;
	PGPKeySetRef	userKeySet;
	PGPKeySetRef	matchKeySet;
	PGPUInt32		nNumKeys;
	DWORD			dwNumNew = 0;
	PGPError		err;

	userKeySet = prds->OriginalKeySetRef;
	*pbRecipAdded = FALSE;

	pbSMTP = (BOOL *) calloc(sizeof(BOOL), ulNum);

	for (ulIndex=0; ulIndex<ulNum; ulIndex++)
	{
		if (!_strnicmp("smtp", lppszProxy[ulIndex], 4))
		{
			pbSMTP[ulIndex] = TRUE;
			bFoundSMTP = TRUE;
		}
	}

	if (!bFoundSMTP)
	{
		if (pbSMTP != NULL)
			free(pbSMTP);

		return FALSE;
	}

	ulIndex = 0;
	while ((ulIndex < ulNum) && !bMatch)
	{
		if (pbSMTP[ulIndex])
		{
			dwNumNew++;
			szNewAddress = lppszProxy[ulIndex] + 5;

			PGPNewUserIDEmailFilter(PGPGetKeySetContext(userKeySet), 
				szNewAddress, kPGPMatchEqual, &filter);
			err = PGPFilterKeySet(userKeySet, filter, &matchKeySet);
			
			if (IsntNull(matchKeySet))
			{
				PGPCountKeys(matchKeySet, &nNumKeys);
				if (nNumKeys > 0)
					bMatch = TRUE;
			}
			
			PGPFreeKeySet(matchKeySet);
			PGPFreeFilter(filter);
		}

		ulIndex++;
	}
	
	if (bMatch)
	{
		strcpy(szAddress, szNewAddress);
		bReturn = TRUE;
	}

	if (!bMatch)
	{
		PGPPrefRef prefs = NULL;
		PGPBoolean sync = FALSE;
		PGPUInt32 numServers = 0;
		PGPKeySetRef tempSet = NULL;
		char szTempAddress[1024];

		err = PGPclOpenClientPrefs(PGPGetContextMemoryMgr(prds->Context),
					&prefs);

		if (IsPGPError(err))
			goto AddAllToRecipientDialog;

		PGPGetPrefBoolean(prefs, kPGPPrefKeyServerSyncUnknownKeys, &sync);
		PGPclCloseClientPrefs(prefs, FALSE);

		if (!sync)
			goto AddAllToRecipientDialog;

		ulIndex = 0;
		while ((ulIndex < ulNum) && !bMatch)
		{
			if (pbSMTP[ulIndex])
			{
				szNewAddress = lppszProxy[ulIndex] + 5;
				
				strcpy(szTempAddress, "<");
				strcat(szTempAddress, szNewAddress);
				strcat(szTempAddress, ">");
				
				err = PGPclSearchServerForUserID(prds->Context, 
						prds->tlsContext, prds->hwndParent, szTempAddress, 
						PGPCL_DEFAULTSERVER, prds->OriginalKeySetRef, 
						&tempSet);
				
				if(IsntPGPError(err) && PGPKeySetRefIsValid(tempSet))
				{
					PGPUInt32		numKeys;
					PGPKeySetRef	newKeySet = NULL;
					
					err = PGPCountKeys(tempSet, &numKeys);
					if(IsntPGPError(err) && (numKeys > 0))
					{
						PGPclQueryAddKeys(prds->Context, prds->tlsContext, 
							prds->hwndParent, tempSet, NULL);
						
						PGPAddKeys(tempSet, prds->OriginalKeySetRef);
						PGPCommitKeyRingChanges(prds->OriginalKeySetRef);
						
						(*pdwNumRecip)++;
						prds->szRecipientArray = 
							(char **) realloc(prds->szRecipientArray, 
							sizeof(char *) * (*pdwNumRecip));
						
						(prds->szRecipientArray)[*pdwRecipIndex] = 
							(char *) calloc(1, strlen(szNewAddress)+1);
						
						strcpy((prds->szRecipientArray)[*pdwRecipIndex], 
							szNewAddress);
						
						(*pdwRecipIndex)++;
						bMatch = TRUE;
						*pbRecipAdded = TRUE;
					}
					
					PGPFreeKeySet(tempSet);
				}
				
				if (bMatch)
					(*pdwNumRecip)--;
			}

			ulIndex++;
		}
	}


AddAllToRecipientDialog:

	if (!bMatch)
	{
		(*pdwNumRecip) += dwNumNew-1;
		prds->szRecipientArray = (char **) 
			realloc(prds->szRecipientArray, sizeof(char *) * (*pdwNumRecip));

		for (ulIndex=0; ulIndex<ulNum; ulIndex++)
		{
			if (pbSMTP[ulIndex])
			{
				szNewAddress = lppszProxy[ulIndex] + 5;
	
				(prds->szRecipientArray)[*pdwRecipIndex] = 
					(char *) calloc(1, strlen(szNewAddress)+1);
			
				strcpy((prds->szRecipientArray)[*pdwRecipIndex], 
					szNewAddress);
				(*pdwRecipIndex)++;

				*pbRecipAdded = TRUE;
			}
		}
	}

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

	return bReturn;
}


BOOL CALLBACK GALDlgProc(HWND hDlg, 
						 UINT uMsg, 
						 WPARAM wParam,
						 LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_INITDIALOG:
		SetFocus(hDlg);
		SetActiveWindow(hDlg);
		break;
	}

	return FALSE;
}


void FetchGlobalAddressList(void *pArgs)
{
	HANDLE hSem;
	LPABCONT pContainer	= (LPABCONT) pArgs;
	LPMAPITABLE pGALTable = NULL;
	SizedSPropTagArray(2, galPropTags) = {2, 
		{PR_EMAIL_ADDRESS, PR_EMS_AB_PROXY_ADDRESSES}};
	
	hSem = CreateSemaphore(NULL, 0, 1, "pgpFetchGlobalAddressList");

	if (pContainer != NULL)
	{
		if (_pGALRows != NULL)
		{
			FreeProws(_pGALRows);
			_pGALRows = NULL;
		}

		if (pContainer->GetContentsTable(0, &pGALTable) == S_OK)
		{
			if (pGALTable != NULL)
				HrQueryAllRows(pGALTable, (LPSPropTagArray) &galPropTags,
					NULL, NULL, 0, &_pGALRows);
		}
	}
	
	if (pGALTable != NULL)
		pGALTable->Release();

	CloseHandle(hSem);
	_endthread();
}


/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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