recipients.cpp
来自「PGP8.0源码 请认真阅读您的文件包然后写出其具体功能」· C++ 代码 · 共 866 行 · 第 1/2 页
CPP
866 行
rgPropVals[ulAddrType].Value.lpszA;
else
{
(*pdwNumRecip)--;
continue;
}
if (szAddrType)
{
if (strstr(szAddrType, "SMTP"))
bGotSMTP = TRUE;
else if (strstr(szAddrType, "EX"))
{
PGPKeySetRef userKeySet = NULL;
PGPKeySetRef matchKeySet = NULL;
PGPFilterRef filter = NULL;
PGPUInt32 nNumKeys = 0;
PGPNewKeySet(prds->keydbOriginal, &userKeySet);
PGPNewKeyDBObjDataFilter(prds->context,
kPGPUserIDProperty_EmailAddress, szRecip,
strlen(szRecip), kPGPMatchCriterion_SubString,
&filter);
PGPFilterKeySet(userKeySet, filter, &matchKeySet);
if (matchKeySet != NULL)
{
PGPCountKeys(matchKeySet, &nNumKeys);
if (nNumKeys > 0)
bGotSMTP = TRUE;
PGPFreeKeySet(matchKeySet);
}
PGPFreeFilter(filter);
PGPFreeKeySet(userKeySet);
}
if (!bGotSMTP)
{
SizedADRLIST(1, newAddress);
FlagList flags;
newAddress.cEntries = 1;
ulNumProxies = 0;
pszProxy = NULL;
flags.cFlags = 1;
flags.ulFlag[0] = MAPI_UNRESOLVED;
if ((ulProxy == ULONG_MAX) && (pContainer != NULL))
{
char *szName;
char *szNameCopy = NULL;
char *szFirstName = NULL;
char *szLastName = NULL;
char *szPutNull = NULL;
HRESULT result;
SizedSPropTagArray(2, propTags) = {
2, {PR_DISPLAY_NAME, PR_EMS_AB_PROXY_ADDRESSES}};
newAddress.aEntries[0].ulReserved1 = 0;
newAddress.aEntries[0].cValues = 2;
MAPIAllocateBuffer(sizeof(SPropValue)*2, (void **)
&(newAddress.aEntries[0].rgPropVals));
newAddress.aEntries[0].rgPropVals[0].ulPropTag =
PR_DISPLAY_NAME;
newAddress.aEntries[0].rgPropVals[1].ulPropTag =
PR_EMS_AB_PROXY_ADDRESSES;
newAddress.aEntries[0].rgPropVals[1].
Value.MVszA.cValues = 0;
newAddress.aEntries[0].rgPropVals[1].
Value.MVszA.lppszA = NULL;
szName = aEntries[ulRow].
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))
{
ulNumProxies = 0;
pszProxy = NULL;
}
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) &&
(strlen(szLastName) != strlen(szNameCopy)))
{
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,
PGPclRecipientDialogStruct *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 = NULL;
PGPKeySetRef userKeySet = NULL;
PGPKeySetRef matchKeySet = NULL;
PGPUInt32 nNumKeys;
DWORD dwNumNew = 0;
PGPError err;
*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;
}
PGPNewKeySet(prds->keydbOriginal, &userKeySet);
ulIndex = 0;
while ((ulIndex < ulNum) && !bMatch)
{
if (pbSMTP[ulIndex])
{
dwNumNew++;
szNewAddress = lppszProxy[ulIndex] + 5;
PGPNewKeyDBObjDataFilter(prds->context,
kPGPUserIDProperty_EmailAddress, szNewAddress,
strlen(szNewAddress), kPGPMatchCriterion_SubString, &filter);
err = PGPFilterKeySet(userKeySet, filter, &matchKeySet);
if (matchKeySet != NULL)
{
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;
PGPKeyDBRef tempDB = NULL;
char szTempAddress[1024];
err = PGPclPeekClientLibPrefRefs(&prefs, NULL);
if (IsPGPError(err))
goto AddAllToRecipientDialog;
PGPGetPrefBoolean(prefs, kPGPPrefKeyServerSyncUnknownKeys, &sync);
if (!sync)
goto AddAllToRecipientDialog;
ulIndex = 0;
while ((ulIndex < ulNum) && !bMatch && IsntPGPError(err))
{
if (pbSMTP[ulIndex])
{
szNewAddress = lppszProxy[ulIndex] + 5;
strcpy(szTempAddress, "<");
strcat(szTempAddress, szNewAddress);
strcat(szTempAddress, ">");
err = PGPclSearchServerForUserID(prds->context,
prds->tlsContext, prds->hwndParent, szTempAddress,
kPGPclDefaultServer, prds->keydbOriginal,
&tempDB);
if(IsntPGPError(err) && PGPKeyDBRefIsValid(tempDB))
{
PGPUInt32 numKeys;
PGPKeySetRef tempSet = NULL;
err = PGPNewKeySet(tempDB, &tempSet);
if (IsntPGPError(err))
err = PGPCountKeys(tempSet, &numKeys);
if(IsntPGPError(err) && (numKeys > 0))
{
PGPclImportKeys(prds->context, prds->tlsContext,
prds->hwndParent, tempSet, prds->keydbOriginal,
kPGPclNoDialogForValidSingletons);
(*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);
PGPFreeKeyDB(tempDB);
}
if (bMatch)
(*pdwNumRecip)--;
}
ulIndex++;
}
if (err == kPGPError_UserAbort)
{
PGPclPeekClientLibPrefRefs(&prefs, NULL);
PGPSetPrefBoolean(prefs, kPGPPrefKeyServerSyncUnknownKeys, FALSE);
PGPclFlushClientLibPrefs(prefs, kInvalidPGPPrefRef);
}
}
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);
if (userKeySet != NULL)
PGPFreeKeySet(userKeySet);
return bReturn;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?