📄 pgpgwtph.cpp
字号:
pgpAssert(NULL != pOutBuf);
pgpAssert(0 < pgpsBufOutLen);
if(IsPGPError(pgpErrRet) || (NULL == pOutBuf) || (0 >= pgpsBufOutLen))
{
hrRet=E_FAIL;
DisplayMessage(hCtxtWindow, IDS_E_ENCRYPT_SIGN, pgpErrRet);
goto send_cleanup;
}
pgpAssert(NULL != pOutBuf);
pgpAssert(0 < pgpsBufOutLen);
//allocate buffer for the token and parameters
pFinalBuf=(char *)calloc(pgpsBufOutLen+sizeof(szTokenBuf), 1);
pgpAssert(NULL != pFinalBuf);
if(NULL == pFinalBuf)
{
hrRet=E_OUTOFMEMORY;//we do not show user any error lest we might crash
goto send_cleanup;
}
//change the mail body to the encrypted stuff.
sprintf(pFinalBuf, "ItemSetText(\"%S\";10;\"%s\")",
g_gtiLastTokenInfo.bstrMessageId, pOutBuf);
hrRet=Publish(pFinalBuf, &bstrResult);
if(FAILED(hrRet))
{
pgpAssert(FALSE);
DisplayMessage(hCtxtWindow, IDS_E_SET_ENCMSG_TXT, hrRet);
goto send_cleanup;
}
//TODO:any failure after this point should notify about inconsistency
//in the mail - since the body is encrypted already
//for each attachment of the mail. all attachments are expected to be of file kind
for(iAtchMentInd=iNoOfAtchMents-1, bAbort=FALSE; iAtchMentInd >= 0; iAtchMentInd--)
{
PgpGwTrace("Processing attachment (att# %d)\n", iAtchMentInd);
{
char *pszAttachName=NULL;
char szTmpPath[MAX_PATH]={0}, szTmpAtchSavePath[MAX_PATH+12]={0};
char szEncFilePath[MAX_PATH+12]={0};
//get the attachment display name
ZeroMemory(szTokenBuf, sizeof(szTokenBuf));
sprintf(szTokenBuf, "ItemAttachmentGetDisplayName(\"%S\";%d)",
g_gtiLastTokenInfo.bstrMessageId, iAtchMentInd);
hrRet=Publish(szTokenBuf, &bstrResult);
if(FAILED(hrRet))
{
pgpAssert(FALSE);
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_ATT_OPERATION);
goto fileatchtype_cleanup;
}
//convert the wide chars to ansi name
pszAttachName=ConvertToAnsi(bstrResult);
if(NULL == pszAttachName)
{
pgpAssert(FALSE);
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_ATT_OPERATION);
goto fileatchtype_cleanup;
}
//get the temporary file path that we will use for the attachment
dwRet=GetTempPath(sizeof(szTmpPath), szTmpPath);
pgpAssert(dwRet > 0);
if(0 == dwRet)
{
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_ATT_OPERATION);
goto fileatchtype_cleanup;
}
_VERIFY(0 != GetTempFileName(szTmpPath, "55D", 0, szTmpAtchSavePath));
if(0 == szTmpAtchSavePath[0])
{
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_ATT_OPERATION);
goto fileatchtype_cleanup;
}
_VERIFY(TRUE == DeleteFile(szTmpAtchSavePath));//delete the temp file created
//cause we want to use that as a directory name
//make the new temporary directory under temp directory
bRet=CreateDirectory(szTmpAtchSavePath, NULL);
if(FALSE == bRet)
{
dwRet=GetLastError();
pgpAssert(FALSE);
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_ATT_OPERATION);
goto fileatchtype_cleanup;
}
//the encrypted file path should keep the file name same as the attachment name
//we add our extension to the file name so that our app opens when the attachment is opened
sprintf(szEncFilePath, "%s\\%s%s", szTmpAtchSavePath, pszAttachName, PGPEXTENSIONA);
//the temporary file name for attachment is the attachment name
strcat(szTmpAtchSavePath, "\\");
strcat(szTmpAtchSavePath, pszAttachName);
//save the attachment in a file in the temp directory
ZeroMemory(szTokenBuf, sizeof(szTokenBuf));
sprintf(szTokenBuf, "ItemAttachmentSaveAs(\"%S\";%d;\"%s\")",
g_gtiLastTokenInfo.bstrMessageId, iAtchMentInd, szTmpAtchSavePath);
hrRet=Publish(szTokenBuf, &bstrResult);
if(FAILED(hrRet))
{
pgpAssert(FALSE);
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_ATT_OPERATION);
goto fileatchtype_cleanup;
}
//encrypt/sign the attachment as is required to be done
pgpErrRet=EncryptSignFile(g_hInstance, hCtxtWindow, g_pgpContext,
tlsContext, CLIENTNAME, MODULEFILENAME, szTmpAtchSavePath,
prdsRecipDlgStruct, NULL, &polOptions, szEncFilePath,
bEncrypt, bSign, TRUE/*binary*/);
if(IsPGPError(pgpErrRet))
{
hrRet=E_FAIL;
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_ATT_ENCRYPT_SIGN, iAtchMentInd+1, pgpErrRet);
goto fileatchtype_cleanup;
}
//replace the original file attachment with this file
ZeroMemory(szTokenBuf, sizeof(szTokenBuf));
sprintf(szTokenBuf, "ItemAttachmentUpdate(\"%S\";%d;\"%s\")",
g_gtiLastTokenInfo.bstrMessageId, iAtchMentInd, szEncFilePath);
hrRet=Publish(szTokenBuf, &bstrResult);
if(FAILED(hrRet))
{
pgpAssert(FALSE);
bAbort=TRUE;
DisplayMessage(hCtxtWindow, IDS_E_REPLACE_ATT, iAtchMentInd+1, hrRet);
goto fileatchtype_cleanup;
}
fileatchtype_cleanup:
if(NULL != pszAttachName)
{
delete pszAttachName;
pszAttachName=NULL;
}
//delete the temporary file(s)
if(0 != szTmpAtchSavePath[0])
_VERIFY(TRUE == DeleteFile(szTmpAtchSavePath));
//we delete the encrypted file only if we failed in some operation
//this is necessary as groupwise standard handler would like to read
//the contents of the file before sending it. so we just add the
//file to our deferred file deletion list
if((0 != szEncFilePath[0]) && FAILED(hrRet))
_VERIFY(TRUE == DeleteFile(szEncFilePath));
else
_VERIFY(TRUE == g_pccihCmdHash->MarkFileForDeletion(szEncFilePath));
}
if(TRUE == bAbort)//if there was an error to make us abort
goto send_cleanup;
}
//case egwMessage://encapsulated item
// PgpGwTrace("Processing a message attachment (att# %d)\n", iAtchMentInd);
// break;
//case 3://embedded or linked object
// PgpGwTrace("Processing an OLE attachment (att# %d)\n", iAtchMentInd);
// break;
//default:
// PgpGwTrace("Processing an unknown/unsupported attachment (att# %d)\n", iAtchMentInd);
// pgpAssert(FALSE);
// break;
//toggle the encrypt/sign options that were chosen by the user for this mail.
//this is to prevent accidental reencryption/signing in case the send fails
//because of some other reason after we have done our stuff.
g_pccihCmdHash->Lock();
if(TRUE == bEncrypt)//if encrypt was chosen
lpMsgInfo->dwState ^= MIS_AUTO_ENCRYPT_ON_SEND;//we reset the flag
if(TRUE == bSign)//if sign was chosen
lpMsgInfo->dwState ^= MIS_AUTO_SIGN_ON_SEND;
g_pccihCmdHash->UnLock();
//all success so let the token be processed further
iHandleTokenRet=DLL_HAN_NOT_HANDLED;
send_cleanup:
if(NULL != bstrResult)
{
SysFreeString(bstrResult);
bstrResult=NULL;
}
if(NULL != tlsContext)
{
PGPFreeTLSContext(tlsContext);
tlsContext=NULL;
}
if (NULL != polOptions)
{
PGPFreeOptionList(polOptions);
polOptions=NULL;
}
if(NULL != pszTitle)
{
free(pszTitle);
pszTitle=NULL;
}
if(NULL != pOutBuf)
{
pgpAssert(pgpsBufOutLen > 0);
PGPFreeData(pOutBuf);
pOutBuf=NULL;
}
if(NULL != pFinalBuf)
{
free(pFinalBuf);
pFinalBuf=NULL;
}
if(NULL != pAnsiInputBuf)
{
delete pAnsiInputBuf;
pAnsiInputBuf=NULL;
}
if(NULL != pgpksrKeySet)
{
PGPFreeKeySet(pgpksrKeySet);
pgpksrKeySet=NULL;
}
//if we allocated the dialog struct
if(NULL != prdsRecipDlgStruct)
{
if(NULL != prdsRecipDlgStruct->szRecipientArray)
{
//free the pointer to the first token. that would free the
//single buffer in which we keep all the recipient names
pgpAssert(prdsRecipDlgStruct->dwNumRecipients > 0);
pgpAssert(!IsBadWritePtr(prdsRecipDlgStruct->szRecipientArray,
prdsRecipDlgStruct->dwNumRecipients*sizeof(char *)));
if(NULL != prdsRecipDlgStruct->szRecipientArray[0])
{
free(prdsRecipDlgStruct->szRecipientArray[0]);
prdsRecipDlgStruct->szRecipientArray[0]=NULL;
}
//now free the pointer array
free(prdsRecipDlgStruct->szRecipientArray);
prdsRecipDlgStruct->szRecipientArray=NULL;
}
if (NULL != prdsRecipDlgStruct->keydbOriginal)
{
PGPFreeKeyDB(prdsRecipDlgStruct->keydbOriginal);
prdsRecipDlgStruct->keydbOriginal=NULL;
}
if(NULL != prdsRecipDlgStruct->keydbAdded)
{
PGPFreeKeyDB(prdsRecipDlgStruct->keydbAdded);
prdsRecipDlgStruct->keydbAdded=NULL;
}
if(NULL != prdsRecipDlgStruct->keydbSelected)
{
PGPFreeKeyDB(prdsRecipDlgStruct->keydbSelected);
prdsRecipDlgStruct->keydbSelected=NULL;
}
//finally free the dialog struct
free(prdsRecipDlgStruct);
prdsRecipDlgStruct=NULL;
}
return iHandleTokenRet;
}
break;
default:
return DLL_HAN_NOT_HANDLED;
break;
}
// When the end user right-clicks on the toolbar and chooses "Properties"
// the About dialog will display instead of the edit toolbar dialog.
// Is the wTokenID the Toolbar edit token?
/*if (DTKN_BTNBAR_EDIT == lpTokenData->lpToken->wTokenId)
{
// Display the About Dialog instead by publishing a new token.
lpReturn = Publish(L"AboutDlg()");
// If lpReturn = NULL then there was an error,
// otherwise it will be an allocated string that may or may not
// contain a value. You must release it when you are done.
if ( lpReturn )
{
// Evaluate and process the return value here.
// ...
// Cleanup
delete lpReturn;
lpReturn = NULL;
}
//Return the value indicating we processed the token so the
//GroupWise client doesn't have to.
return DLL_HAN_NO_ERROR;
}*/
return DLL_HAN_NOT_HANDLED;
}
////////////////////////////////////////////////////////////////////////////////
// Name: ValidateToken
// Descrip: This method is reserved for later use. Even though it is currently
// not called by GW, it must be included.
////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI ValidateToken(LPMAC_TOKEN lpTokenData, LPVOID lpDataTypeInfo)
{
return 0;
}
void TraceHandleToken(LPTPH_RETURNVAL lpTokenData, HWND hLinkWnd, WORD wMsg)
{
#ifdef _DEBUG
char szBuffer[255]={0};
PgpGwTrace("いいい Token Info いいい\n");
//trace the window details
int iRet=GetWindowText(hLinkWnd, szBuffer, sizeof(szBuffer));
pgpAssert(iRet > 0);
PgpGwTrace("hLinkWnd=%#x\"%s\"\n", hLinkWnd, szBuffer);
//trace the message details
PgpGwTrace("wMsg=%#x\n", wMsg);
//check if tokendata ptr is null
pgpAssert(NULL != lpTokenData);
if(NULL == lpTokenData)
{
PgpGwTrace("lpTokenData=NULL\n");
return;
}
//check if the token ptr in it is null
pgpAssert(NULL != lpTokenData->lpToken);
if(NULL == lpTokenData->lpToken)
{
PgpGwTrace("lpTokenData->lpToken=NULL\n");
return;
}
//dump the details in the token itself
PgpGwTrace("lpTokenData->lpToken->hszCommand=%#x\n", lpTokenData->lpToken->hszCommand);
PgpGwTrace(" Version=%#x\n", lpTokenData->lpToken->Version);
PgpGwTrace(" hszRequestor=%#x\n", lpTokenData->lpToken->hszRequestor);
PgpGwTrace(" dwMacroID=%#x\n", lpTokenData->lpToken->dwMacroID);
PgpGwTrace(" atomApp=%#x\n", lpTokenData->lpToken->atomApp);
PgpGwTrace(" wReserved=%#x\n", lpTokenData->lpToken->wReserved);
PgpGwTrace(" wTokenId=%d", lpTokenData->lpToken->wTokenId);
switch(lpTokenData->lpToken->wTokenId)
{
case BFTKN_SEND_STDMAIL:
PgpGwTrace("(BFTKN_SEND_STDMAIL)\n");
break;
case BFTKN_SEND:
PgpGwTrace("(BFTKN_SEND)\n");
break;
case BFTKN_CLOSE_WINDOW:
PgpGwTrace("(BFTKN_CLOSE_WINDOW)\n");
break;
case BFTKN_READ:
PgpGwTrace("(BFTKN_READ)\n");
break;
case BFTKN_FORWARD:
PgpGwTrace("(BFTKN_FORWARD)\n");
break;
case BFTKN_REPLY:
PgpGwTrace("(BFTKN_REPLY)\n");
break;
case AFTKN_ITEM_MSGID_FROM_VIEW:
PgpGwTrace("(AFTKN_ITEM_MSGID_FROM_VIEW)\n");
break;
case AFTKN_EVENT_NOTIFY:
PgpGwTrace("(AFTKN_EVENT_NOTIFY)\n");
break;
case AFTKN_TYPE_CHAR:
PgpGwTrace("(AFTKN_TYPE_CHAR)\n");
break;
case AFTKN_OPEN_VIEW_TYPE:
PgpGwTrace("(AFTKN_OPEN_VIEW_TYPE)\n");
break;
case DTKN_ATTACH_FILE:
PgpGwTrace("(DTKN_ATTACH_FILE)\n");
break;
case BFTKN_SPELLER:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -