LRESULT WINAPI ReadMailToolbarWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { WNDPROC lpOldProc; lpOldProc = (WNDPROC)GetProp( hwnd, "oldproc" ); switch(msg) { case WM_DESTROY: { // Put back old window proc and SetWindowLong( hwnd, GWL_WNDPROC, (DWORD)lpOldProc ); // remove window property RemoveProp( hwnd, "oldproc" ); break; } case WM_NOTIFY: { static char szTooltip[256] = {0x00}; LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT) lParam;; switch (((LPNMHDR)lParam)->code) { case TTN_NEEDTEXTA: { if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && lpToolTipText->hdr.idFrom <= IDC_MIME ) { int StringId = lpToolTipText->hdr.idFrom - WM_USER - 1000; LoadString (g_hinst, StringId, szTooltip, sizeof(szTooltip)); lpToolTipText->lpszText = szTooltip; if(g_hwndEudoraStatusbar) { SendMessage(g_hwndEudoraStatusbar, SB_SETTEXT, (WPARAM)0, (LPARAM)szTooltip); } return 0; } } case TTN_NEEDTEXTW: { static wchar_t wideBuf[256]; if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && lpToolTipText->hdr.idFrom <= IDC_MIME ) { int StringId = lpToolTipText->hdr.idFrom - WM_USER - 1000; LoadString (g_hinst, StringId, szTooltip, sizeof(szTooltip)); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTooltip, -1, wideBuf, 256); lpToolTipText->lpszText = (char*)wideBuf; if(g_hwndEudoraStatusbar) { SendMessage(g_hwndEudoraStatusbar, SB_SETTEXT, (WPARAM)0, (LPARAM)szTooltip); } return 0; } } } break; } case WM_COMMAND: { HWND hwndParent = NULL; HWND hwndRichEdit = NULL; switch(wParam) { case IDC_DECRYPT: { //char temp[1024]; char* pRichEditText = NULL; long nChar = 0; CHARRANGE chRange = {0,0}; BOOL bMimeMessage = FALSE; BOOL bDecryptSuccessful = FALSE; BOOL bToggle = FALSE; BOOL bSelectedText = FALSE; FINDTEXT ftEncrypted; FINDTEXT ftSigned; long nCharPos = 0; HCURSOR hCursor, hOldCursor; BOOL FYEO; // Find the windows we are interested in... hwndParent = GetParent(hwnd); hwndRichEdit = FindWindowEx(hwndParent, NULL, "RICHEDIT", NULL); // Is the control in Edit Mode bToggle = !SendMessage(hwnd, TB_ISBUTTONCHECKED, 34002, 0); // See if the user has selected text in the window SendMessage(hwndRichEdit, EM_EXGETSEL, (WPARAM)0, (LPARAM) &chRange); bSelectedText = chRange.cpMax - chRange.cpMin; // Prepare to look for our plug-ins // Mime Encrypted Text ftEncrypted.lpstrText = "<0880.0001>"; // Search String ftEncrypted.chrg.cpMin = 0; ftEncrypted.chrg.cpMax = -1; // All Text // Mime Signed Text ftSigned.lpstrText = "<0880.0002>"; // Search String ftSigned.chrg.cpMin = 0; ftSigned.chrg.cpMax = -1; // All Text // Lock window so we do not flash //LockWindowUpdate( hwndRichEdit ); // if not in edit mode place us there if(bToggle) { SendMessage(hwndParent, WM_COMMAND, 34002, 0); SendMessage(hwnd, TB_CHECKBUTTON, 34002, MAKELONG(TRUE, 0)); } // This could take awhile... give some feedback. hCursor = LoadCursor(NULL, IDC_WAIT); hOldCursor = SetCursor(hCursor); // get text of message pRichEditText = GetRichEditContents ( hwndRichEdit, &nChar, FALSE, bSelectedText); if(!bSelectedText) { // see if our mime encrypted text plugin is there nCharPos = SendMessage( hwndRichEdit, EM_FINDTEXT, 0,(LPARAM) &ftEncrypted); if( nCharPos == -1 ) { // if not see if our mime signed text plugin is // there nCharPos = SendMessage( hwndRichEdit, EM_FINDTEXT, 0, (LPARAM) &ftSigned); } // if one of them are there "click" on the plugin if( nCharPos != -1 ) { POINT pt; //MessageBox(NULL, "Click!!", "Decrypt", MB_OK); bMimeMessage = TRUE; SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM) &pt, (LPARAM) nCharPos); SendMessage(hwndRichEdit, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(pt.x + 2, pt.y + 2)); SendMessage(hwndRichEdit, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(pt.x + 2, pt.y + 2)); SendMessage(hwndRichEdit, WM_LBUTTONDBLCLK, MK_LBUTTON, MAKELPARAM(pt.x + 2, pt.y + 2)); } else { // if we were not in edit mode take ourselves // out of edit mode if(bToggle) { SendMessage(hwndParent, WM_COMMAND, 34002, 0); SendMessage(hwnd, TB_CHECKBUTTON, 34002, MAKELONG(FALSE, 0)); } } } // Let the window update itself //LockWindowUpdate( NULL ); // if it was not a mime message then see if there is // any "classic" pgp text if( !bMimeMessage && pRichEditText )//<0880.0004> { // Decrypt Text bDecryptSuccessful = DecryptVerifyRichEditText( &pRichEditText, &nChar, &FYEO); if( bDecryptSuccessful ) { // put it in edit mode so they have to explicitly // save it as cleartext // if there was a MIME message we are already in // edit mode if((FYEO)||(GetSecureViewerPref(g_pgpContext))) { TempestViewer((void *)g_pgpContext,hwnd, pRichEditText,nChar,FYEO); } else { if(bToggle && !bMimeMessage) { SendMessage(hwndParent, WM_COMMAND, 34002, 0); SendMessage(hwnd, TB_CHECKBUTTON, 34002, MAKELONG(TRUE, 0)); } SetRichEditContents (hwndRichEdit, pRichEditText, FALSE, bSelectedText); //MessageBox(NULL, "huh?", "Decrypt", MB_OK); } } } if( pRichEditText ) { // clean up after ourselves HeapFree(GetProcessHeap(), 0, pRichEditText); } SetCursor(hOldCursor); break; } case IDC_KEYMGR: { char szPath[MAX_PATH]; char szPGPkeys[256]; PGPError error = kPGPError_NoErr; LoadString(g_hinst, IDS_PGPKEYSEXE, szPGPkeys, sizeof(szPGPkeys)); error = PGPclGetPGPPath (szPath, sizeof(szPath)); if( IsntPGPError(error) ) { // '/s' keeps it from showing that // damn splash screen strcat(szPath, szPGPkeys); // run it... WinExec(szPath, SW_SHOW); } else { char szError[256]; LoadString(g_hinst, IDS_E_LAUNCHPGPKEYS, szError, sizeof(szError)); MessageBox(NULL, szError, 0, MB_OK); } break; } } } } // Pass all non-custom messages to old window proc return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam ) ; }
LRESULT WINAPI SendMailToolbarWndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { WNDPROC lpOldProc; lpOldProc = (WNDPROC)GetProp( hwnd, "oldproc" ); switch(msg) { case WM_DESTROY: { // Put back old window proc and SetWindowLong( hwnd, GWL_WNDPROC, (DWORD)lpOldProc ); // remove window property RemoveProp( hwnd, "oldproc" ); break; } case WM_NOTIFY: { static char szTooltip[256] = {0x00}; LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT) lParam;; switch (((LPNMHDR)lParam)->code) { case TTN_NEEDTEXTA: { if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && lpToolTipText->hdr.idFrom <= IDC_MIME ) { int StringId = lpToolTipText->hdr.idFrom - WM_USER - 1000; LoadString (g_hinst, StringId, szTooltip, sizeof(szTooltip)); lpToolTipText->lpszText = szTooltip; if(g_hwndEudoraStatusbar) { SendMessage(g_hwndEudoraStatusbar, SB_SETTEXT, (WPARAM)0, (LPARAM)szTooltip); } return 0; } } case TTN_NEEDTEXTW: { static wchar_t wideBuf[256]; if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && lpToolTipText->hdr.idFrom <= IDC_MIME ) { int StringId = lpToolTipText->hdr.idFrom - WM_USER - 1000; LoadString (g_hinst, StringId, szTooltip, sizeof(szTooltip)); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTooltip, -1, wideBuf, 256); lpToolTipText->lpszText = (char*)wideBuf; if(g_hwndEudoraStatusbar) { SendMessage(g_hwndEudoraStatusbar, SB_SETTEXT, (WPARAM)0, (LPARAM)szTooltip); } return 0; } } } break; } case WM_COMMAND: { switch(wParam) { case IDC_SENDMAIL: { HWND hwndSendToolbar = NULL; BOOL bEncrypt = FALSE; BOOL bSign = FALSE; BOOL bPGPMIME = FALSE; BYTE KeyboardStatus[256]; //char temp[100]; // Did the user have the shift key pressed // when they sent mail? GetKeyboardState( KeyboardStatus ); // Get our Toolbar hwndSendToolbar = FindWindowEx(hwnd, NULL, "ToolbarWindow32", NULL); if(hwndSendToolbar) { g_bSendingMail = TRUE; g_hwndSendToolbar = hwndSendToolbar; // set up the Eudora Plugin Menu correctly SendMessage(hwnd, WM_COMMAND, (WPARAM)IDC_PLUGINMENU, 0); // See if the user wants us to use PGPMIME if(SendMessage( hwndSendToolbar, TB_ISBUTTONCHECKED, (WPARAM)IDC_MIME, 0)) { bPGPMIME = TRUE; } // See if the user wants us encrypt the message if(SendMessage( hwndSendToolbar, TB_ISBUTTONCHECKED, (WPARAM)IDC_ENCRYPT, 0)) { bEncrypt = TRUE; } // See if the user wants us sign the message if(SendMessage( hwndSendToolbar, TB_ISBUTTONCHECKED, (WPARAM)IDC_SIGN, 0)) { bSign = TRUE; } } else { int err; char szMessage[256]; char szTitle[256]; LoadString(g_hinst, IDS_E_SENDMAIL, szMessage, sizeof(szMessage)); LoadString(g_hinst, IDS_E_SENDMAILTITLE, szTitle, sizeof(szTitle)); err = MessageBox(NULL, szMessage, szTitle, MB_YESNO|MB_ICONSTOP); if(err == IDNO) { return 0; } } if(!bPGPMIME) { if(!SendMessage(hwnd, WM_COMMAND, IDC_JUSTDOIT, 0)) { return 0; } else { LRESULT lresult; BYTE oldKeyboardStatus[256]; GetKeyboardState( oldKeyboardStatus ); SetKeyboardState( KeyboardStatus ); lresult = CallWindowProc( lpOldProc, hwnd, msg, wParam, lParam ); // reset these keys so they don't "stick" oldKeyboardStatus[VK_SHIFT] = 0; oldKeyboardStatus[VK_CONTROL] = 0; oldKeyboardStatus[VK_MENU] = 0; SetKeyboardState( oldKeyboardStatus ); return lresult; } } break; } case IDC_JUSTDOIT: { HWND hwndSendToolbar = NULL; BOOL bEncrypt = FALSE; BOOL bSign = FALSE; BOOL bEncryptSuccessful = FALSE; HCURSOR hCursor, hOldCursor; //char temp[100]; // Get our Toolbar hwndSendToolbar = FindWindowEx(hwnd, NULL, "ToolbarWindow32", NULL); if(hwndSendToolbar) { // See if the user wants us encrypt the message if(SendMessage( hwndSendToolbar, TB_ISBUTTONCHECKED, (WPARAM)IDC_ENCRYPT, 0)) { bEncrypt = TRUE; } // See if the user wants us sign the message if(SendMessage( hwndSendToolbar, TB_ISBUTTONCHECKED, (WPARAM)IDC_SIGN, 0)) { bSign = TRUE; } } // does the user want us to do anything to the message if(bEncrypt || bSign ) { BOOL bSelectedText = FALSE; CHARRANGE chRange = {0,0}; HWND hwndParent = NULL; HWND hwndRichEdit = NULL; HWND hwndAfxWnd = NULL; HWND hwndHeaders = NULL; char* pRichEditText = NULL; char** pPGPRecipients = NULL; long NumAddresses = 0; long nChar = 0; HEADERDATA hd; // zero out HEADERDATA struct memset(&hd, 0x00, sizeof(hd)); // Find the windows we are interested in... hwndParent = GetParent(hwnd); hwndAfxWnd = FindWindowEx( hwndParent, NULL, "AfxMDIFrame40", NULL); if(!hwndAfxWnd) // 3.04 and 3.05 use new mfc versions { hwndAfxWnd = FindWindowEx( hwndParent, NULL, "AfxMDIFrame42", NULL); if(!hwndAfxWnd) { char szMessage[256]; LoadString(g_hinst, IDS_E_OLDVERSION, szMessage, sizeof(szMessage)); MessageBox(NULL, szMessage, 0, MB_OK); return 0; } } hwndRichEdit = FindWindowEx( hwndAfxWnd, NULL, "RICHEDIT", NULL); hwndHeaders = FindWindowEx( hwndAfxWnd, NULL, "#32770", //Dialog NULL); // See if the user has selected text in the window SendMessage(hwndRichEdit, EM_EXGETSEL, (WPARAM)0, (LPARAM) &chRange); bSelectedText = chRange.cpMax - chRange.cpMin; // if not context menu invoked then we don't // want to do selected text. // this will protect users if(lParam != SENT_FROM_CONTEXT_MENU) { bSelectedText = FALSE; } if(!bSelectedText) { RECT rect; // there is a bug in the richedit control... // so if there is no selected text click in // the lower right corner real quick to // clear up the bug... GetClientRect(hwndRichEdit, &rect); SendMessage(hwndRichEdit, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(rect.right - 5, rect.bottom -5 )); SendMessage(hwndRichEdit, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(rect.right - 5 , rect.bottom -5 )); } // This could take awhile... give some feedback. hCursor = LoadCursor(NULL, IDC_WAIT); hOldCursor = SetCursor(hCursor); // get text of message pRichEditText = GetRichEditContents ( hwndRichEdit, &nChar, FALSE, bSelectedText); // get the email headers GetEudoraHeaders( hwndHeaders, &hd); // now create an appropriate list for pgplib NumAddresses = CreateRecipientListFromEudoraHeaders( &hd, &pPGPRecipients); if( pRichEditText ) { char* pInAttachments = ""; char* pOutAttachments = NULL; // if context menu invoked then we don't // want to do attachments. if(lParam != SENT_FROM_CONTEXT_MENU) { pInAttachments = hd.pAttachments; } // length might have changed nChar = strlen(pRichEditText); // Encrypt Text bEncryptSuccessful = EncryptSignRichEditText( &pRichEditText, &nChar, bEncrypt, bSign, pPGPRecipients, NumAddresses, pInAttachments, &pOutAttachments); if( bEncryptSuccessful ) { SetRichEditContents ( hwndRichEdit, pRichEditText, FALSE, bSelectedText); if(pOutAttachments) { // set the attachments SetEudoraAttachments( hwndHeaders, pOutAttachments); free(pOutAttachments); } else { // Wait for about .5 seconds // so user can see encrypted text... Sleep(500); } } } // want to reset buttons for context menu // regardless of success or failure if( bEncryptSuccessful || lParam == SENT_FROM_CONTEXT_MENU) { // Reset the buttons SendMessage(hwndSendToolbar, TB_CHECKBUTTON, (WPARAM)IDC_ENCRYPT, MAKELPARAM(FALSE,0)); HeapFree(GetProcessHeap(), 0, pRichEditText); } // want to reset buttons for context menu // regardless of success or failure if( bEncryptSuccessful || lParam == SENT_FROM_CONTEXT_MENU) { // Reset the buttons SendMessage(hwndSendToolbar, TB_CHECKBUTTON, (WPARAM)IDC_ENCRYPT, MAKELPARAM(FALSE,0)); SendMessage(hwndSendToolbar, TB_CHECKBUTTON, (WPARAM)IDC_SIGN, MAKELPARAM(FALSE, 0)); SendMessage(hwndSendToolbar, TB_ENABLEBUTTON, (WPARAM)IDC_JUSTDOIT, MAKELPARAM(FALSE, 0)); } // clean up after ourselves FreeRecipientList(pPGPRecipients, NumAddresses); FreeHeaderData(&hd); SetCursor(hOldCursor); } else { // we 'successfully' did nothing to the message bEncryptSuccessful = TRUE; } return bEncryptSuccessful; break; } case IDC_KEYMGR: { char szPath[MAX_PATH]; char szPGPkeys[256]; PGPError error = kPGPError_NoErr; LoadString(g_hinst, IDS_PGPKEYSEXE, szPGPkeys, sizeof(szPGPkeys)); error = PGPclGetPath (kPGPclPGPkeysExeFile, szPath, sizeof(szPath)); if( IsntPGPError(error) ) { PGPclExecute (szPath, SW_SHOW); } else { char szError[256]; LoadString(g_hinst, IDS_E_LAUNCHPGPKEYS, szError, sizeof(szError)); MessageBox(NULL, szError, 0, MB_OK); } break; } } } case WM_ENTERIDLE: { if( g_bSendingMail && g_hwndSendToolbar && wParam == MSGF_MENU ) { g_bInitializeButtons = FALSE; g_bSendingMail = FALSE; g_hwndSendToolbar = NULL; PostMessage(hwnd, WM_KEYDOWN, (WPARAM)VK_ESCAPE, 0x001c0001); PostMessage(hwnd, WM_KEYUP, (WPARAM)VK_ESCAPE, 0x001c0001); } break; } case WM_DRAWITEM: { // control identifier UINT idCtl = (UINT) wParam; // item-drawing information LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam; //char szString[256] = {0x00}; if( g_bSendingMail ) { if(lpdis && lpdis->CtlType == ODT_MENU) { if(*((void**)(lpdis->itemData + 4))) { WPARAM wCommand = 0; BOOL bItemChecked = FALSE; // see if it is already checked if((lpdis->itemState & ODS_CHECKED)) { bItemChecked = TRUE; } // see which plugin this menuitem represents if( !strcmp(*((char**)(lpdis->itemData + 4)), "PGP plugin 1 (use toolbar)") ) { wCommand = IDC_ENCRYPT; // we might be getting a window from a cancel... if( g_bInitializeButtons && bItemChecked) { g_bEncrypt = TRUE; } } else if( !strcmp(*((char**)(lpdis->itemData + 4)), "PGP plugin 2 (use toolbar)") ) { wCommand = IDC_SIGN; // we might be getting a window from a cancel... if( g_bInitializeButtons && bItemChecked) { g_bSign = TRUE; } } if( !g_bInitializeButtons ) { // make sure the window handle is valid if( g_hwndSendToolbar) { if( wCommand ) // is this one of our menus { BOOL bCommandPressed = FALSE; BOOL bPGPMIMEPressed = FALSE; bCommandPressed = SendMessage( g_hwndSendToolbar, TB_ISBUTTONCHECKED, wCommand, 0); bPGPMIMEPressed = SendMessage( g_hwndSendToolbar, TB_ISBUTTONCHECKED, IDC_MIME, 0); if( (bCommandPressed && !bItemChecked && bPGPMIMEPressed) || (bCommandPressed && bItemChecked && !bPGPMIMEPressed) || (!bCommandPressed && bItemChecked)) { SendMessage(hwnd, WM_COMMAND, (WPARAM)lpdis->itemID, 0); } } } } } } } break; } } // Pass all non-custom messages to old window proc return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam ) ; }