[Gpgoe-commits] r16 - trunk/src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 11 08:56:23 CEST 2006


Author: twoaday
Date: 2006-04-11 08:56:23 +0200 (Tue, 11 Apr 2006)
New Revision: 16

Modified:
   trunk/src/GPGOE.c
   trunk/src/GPGOE.h
   trunk/src/GPGOE.rc
   trunk/src/Makefile.am
   trunk/src/OECrypto.c
   trunk/src/OEDlgEncrypt.c
   trunk/src/OEDlgViewer.c
   trunk/src/OEMisc.c
   trunk/src/OEPassphraseCBDlg.c
   trunk/src/OEProc.c
   trunk/src/resource.h
Log:


Modified: trunk/src/GPGOE.c
===================================================================
--- trunk/src/GPGOE.c	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/GPGOE.c	2006-04-11 06:56:23 UTC (rev 16)
@@ -27,20 +27,19 @@
 #include "gpgme.h"
 #include "GPGOE.h"
 
-
 /* Global DLL module handle. */
 HINSTANCE mod_hinst_dll;
 
+/* Outlook Express old window procedure. */
+WNDPROC oe_proc_old;
+
 /* DLL hook handle for the CBT function. */
 static HHOOK ctb_hook = NULL;
 
 /* Outlook Express window handle. */
 static HWND oe_hwnd = NULL;
 
-/* Outlook Express old window procedure. */
-WNDPROC oe_proc_old;
 
-
 /* Main DLL entry point. */
 BOOL WINAPI
 DllMain (HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
@@ -66,9 +65,9 @@
 
 
 /* Quick and dirty check if the dialog is a common dialog
-   and the 'File Save' style. */
+   and the 'File {Open, Save}' style. */
 static int 
-is_filesave_dlg (HWND h)
+is_common_file_dlg (HWND h)
 {
     HWND button = GetDlgItem (h, 1040);
     char wclass[200];
@@ -82,9 +81,10 @@
 }
 
 
+
 /* CTB hook procedure.
    Monitors the creation of all windows and subclass the window
-   if it belongs to the Outlook Express message class. */
+   if it belongs to the Outlook Express (message) class. */
 static LRESULT CALLBACK 
 ctb_proc (int code, WPARAM wparam, LPARAM lparam)
 {
@@ -111,29 +111,42 @@
 	    else
 		oe_hwnd = hwnd;
         }
+
+	if (!strcmp (wclass, "Outlook Express Browser Class")) {
+	    oe_main_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC);
+	    if (!oe_main_proc_old)
+		show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
+			    "Could not get window procedure ec=%d",
+			    (int)GetLastError ());
+	    else if (!SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_main_proc))
+		show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
+			    "Could not set window procedure: ec=%d",
+			    (int)GetLastError ());
+	}
 	break;
 
+    case HCBT_ACTIVATE:
 #if 0
-    case HCBT_ACTIVATE:
 	if (plugin_active != NULL && 
 	    WaitForSingleObject (plugin_active, 0) == WAIT_OBJECT_0) {
 	    char wclass[200];
 
 	    if (GetClassName (hwnd, wclass, sizeof (wclass)-1) <= 0 ||
-		!strstr (wclass, "#32770") || !is_filesave_dlg (hwnd))
+		!strstr (wclass, "#32770") || !is_common_file_dlg (hwnd))
 		break;
 	    of_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC);
 	    SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)of_proc);
 	}
+#endif
 	break;
-#endif
     }	
     return CallNextHookEx (ctb_hook, code, wparam, lparam);
 }
 
 
-/* Initialize the hooks.
-   To prevent double initialisation, we use a named mutex. */
+/* Initialize the hooks; a named mutex prevents that the
+   initialisation is done twice.
+   Return value: 0 on success. */
 int
 gpgoe_initialize (void)
 {
@@ -145,12 +158,13 @@
 }
 
 
-/* Deinitialize the hooks and close all handles. */
+/* Deinitialize the hooks and close all handles.
+   Return value: 0 on success. */
 int
 gpgoe_remove (void)
 {
-    int rc = 0;
     HANDLE hd;
+    int rc;
 
     hd = CreateMutex (NULL, TRUE, "gpgoe");
     if (GetLastError() == ERROR_ALREADY_EXISTS) {

Modified: trunk/src/GPGOE.h
===================================================================
--- trunk/src/GPGOE.h	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/GPGOE.h	2006-04-11 06:56:23 UTC (rev 16)
@@ -27,7 +27,7 @@
 
 
 #include <malloc.h>
-/* wrapper around free. */
+/* safe wrapper around free. */
 #define free_if_alloc(ptr) \
 do { \
     if (ptr) free (ptr); \
@@ -45,7 +45,7 @@
 
 #define wipememory(_ptr,_len) wipememory2 (_ptr,0,_len)
 
-/* Dialog IDs for clipboard operations. */
+/* Dialog IDs for the various operations. */
 #define ID_OE_SELECTALL	    40125
 #define ID_OE_COPY	    40484
 #define ID_OE_PASTE	    40231
@@ -85,6 +85,7 @@
 
 /* Viewer context. */
 struct viewer_ctx_s {
+    HWND main_wnd;
     const char *msg;
 };
 typedef struct viewer_ctx_s *viewer_ctx_t;
@@ -95,17 +96,32 @@
 /*EXPORT*/ int gpgoe_remove (void);
 
 /*-- OEProc.c --*/
+extern plugin_ctx_t oe_plug;
 extern HINSTANCE mod_hinst_dll;
+extern HANDLE plugin_active;
+
+/* support for the mailer window. */
 extern WNDPROC oe_proc_old;
+LRESULT CALLBACK oe_proc (HWND hwnd, UINT msg, 
+			  WPARAM wparam, LPARAM lparam);
+
+/* support for the common dialogs. */
 extern WNDPROC of_proc_old;
-extern HANDLE plugin_active;
-LRESULT CALLBACK oe_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
-LRESULT CALLBACK of_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
+LRESULT CALLBACK of_proc (HWND hwnd, UINT msg, 
+			  WPARAM wparam, LPARAM lparam);
 
+/* support for the main window. */
+extern WNDPROC oe_main_proc_old;
+LRESULT CALLBACK oe_main_proc (HWND hwnd, UINT msg, 
+			       WPARAM wparam, LPARAM lparam);
+
+
 /*-- OECrypto.c --*/
 gpgme_error_t oe_handle_mail (plugin_ctx_t ctx);
+gpgme_error_t oe_decrypt_msg (HWND main_wnd, char **r_msg);
 
 /*-- OEMisc.c --*/
+void center_window (HWND hwndChild, HWND parent);
 char* utf8_to_native (const char *string);
 char* native_to_utf8 (const char *string);
 char* get_clip_text (HWND hwnd);
@@ -115,6 +131,7 @@
 void* xcalloc (size_t n, size_t m);
 char* xstrdup (const char *s);
 void xfree (void *p);
+void quote_msg_text (const char *inp, char **r_outp);
 
 /*-- dialogs --*/
 BOOL CALLBACK encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, 
@@ -134,6 +151,7 @@
 			     int prev_was_bad, int fd);
 void free_pass_cb (pass_cb_t cb);
 pass_cb_t new_pass_cb (HWND main);
+void free_pass_cache (void);
 
 /*-- OENLS.c --*/
 int setup_gettext (void);

Modified: trunk/src/GPGOE.rc
===================================================================
--- trunk/src/GPGOE.rc	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/GPGOE.rc	2006-04-11 06:56:23 UTC (rev 16)
@@ -66,8 +66,8 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,7,0,0
- PRODUCTVERSION 0,7,0,0
+ FILEVERSION 0,8,0,0
+ PRODUCTVERSION 0,8,0,0
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -110,7 +110,7 @@
 // Dialog
 //
 
-IDD_DECRYPT DIALOG DISCARDABLE  0, 0, 233, 106
+IDD_DECRYPT DIALOG DISCARDABLE  0, 0, 233, 130
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Decryption"
 FONT 8, "MS Sans Serif"
@@ -120,8 +120,10 @@
     LTEXT           "Please enter your passphrase",IDC_DECRYPT_PWDINFO,5,51,
                     212,8
     EDITTEXT        IDC_DECRYPT_PWD,5,65,214,12,ES_PASSWORD | ES_AUTOHSCROLL
-    DEFPUSHBUTTON   "&OK",IDOK,121,87,50,14
-    PUSHBUTTON      "&Cancel",IDCANCEL,174,87,50,14
+    DEFPUSHBUTTON   "&OK",IDOK,121,111,50,14
+    PUSHBUTTON      "&Cancel",IDCANCEL,174,111,50,14
+    CONTROL         "&Hide typing",IDC_DECRYPT_HIDE,"Button",BS_AUTOCHECKBOX | 
+                    WS_TABSTOP,136,80,81,9
 END
 
 IDD_ENCRYPT DIALOG DISCARDABLE  0, 0, 280, 167
@@ -176,7 +178,7 @@
         LEFTMARGIN, 2
         RIGHTMARGIN, 226
         TOPMARGIN, 3
-        BOTTOMMARGIN, 101
+        BOTTOMMARGIN, 125
     END
 
     IDD_ENCRYPT, DIALOG

Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/Makefile.am	2006-04-11 06:56:23 UTC (rev 16)
@@ -15,9 +15,10 @@
 	OEMisc.c \
 	OEPassphraseCBDlg.c \
 	OEProc.c \
-	OENLS.c
+	OENLS.c \
+	OEMainProc.c
 
-gpgoe_LDADD = GPGOE.def $(GPGME_LIBS) -lkernel32 -ladvapi32
+gpgoe_LDADD = GPGOE.def $(GPGME_LIBS) -lkernel32 -ladvapi32 -lgdi32
 
 resource.o: resource.rc resource.h
 

Modified: trunk/src/OECrypto.c
===================================================================
--- trunk/src/OECrypto.c	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/OECrypto.c	2006-04-11 06:56:23 UTC (rev 16)
@@ -242,7 +242,7 @@
 
     enc_buf = encode? native_to_utf8 (buf) : xstrdup (buf);
     err = gpgme_data_new_from_mem (in, enc_buf, strlen (enc_buf), 1);
-    free (enc_buf);
+    free_if_alloc (enc_buf);
     return err;
 }
 
@@ -265,8 +265,7 @@
 /* Try to extract the needed key information and retrieve
    the keys if possible. */
 static gpgme_error_t
-get_keys (plugin_ctx_t ctx, recip_list_t *r_list, 
-	  gpgme_key_t **r_keys, int *r_n)
+get_keys (plugin_ctx_t ctx, recip_list_t *r_list, gpgme_key_t **r_keys)
 {
     gpgme_key_t *keys;
     recip_list_t addrs = NULL, n;
@@ -298,7 +297,6 @@
     }
     *r_list = addrs;
     *r_keys = keys;
-    *r_n = nkeys;
     return 0;
 }
 
@@ -314,12 +312,11 @@
     gpgme_ctx_t gctx = NULL;
     gpgme_data_t in = NULL, out = NULL;
     recip_list_t list = NULL;
-    int nkeys=0;
     char *msg = *r_msg;
 
     assert (ctx);
 
-    err = get_keys (ctx, &list, &keys, &nkeys);
+    err = get_keys (ctx, &list, &keys);
     if (err)
 	return err;
 
@@ -338,7 +335,7 @@
     gpgme_release (gctx);
     gpgme_data_release (in);
     release_recipient (list);
-    free (keys);
+    free_if_alloc (keys);
 
     if (err)
 	gpgme_data_release (out);
@@ -392,11 +389,10 @@
     gpgme_key_t *keys;
     pass_cb_t cb_val;
     recip_list_t list = NULL;
-    int ec, nkeys = 0;
 
-    ec = get_keys (ctx, &list, &keys, &nkeys);
-    if (ec)
-	return ec;
+    err = get_keys (ctx, &list, &keys);
+    if (err)
+	return err;
 
     cb_val = new_pass_cb (ctx->main_wnd);
 
@@ -416,7 +412,7 @@
     gpgme_release (gctx);
     gpgme_data_release (in);
     release_recipient (list);
-    free (keys);
+    free_if_alloc (keys);
     free_pass_cb (cb_val);
 
     if (err)
@@ -499,6 +495,41 @@
 }
 
 
+/* Decrypt the message given in @r_msg.
+   The old message will be freed and replaced with the plaintext. */
+gpgme_error_t
+oe_decrypt_msg (HWND main_wnd, char **r_msg)
+{
+    gpgme_ctx_t gctx = NULL;
+    gpgme_data_t in = NULL, out = NULL;
+    gpgme_error_t err;
+    pass_cb_t cb_val;
+    char *msg = *r_msg;
+
+    cb_val = new_pass_cb (main_wnd);
+    err = gpgme_new (&gctx);
+    if (!err)
+	err = gpgme_data_new_from_mem (&in, msg, strlen (msg), 1);
+    if (!err)
+	err = gpgme_data_new (&out);
+    if (!err) {
+	gpgme_set_passphrase_cb (gctx, passphrase_cb, cb_val);
+	err = gpgme_op_decrypt (gctx, in, out);
+    }
+
+    gpgme_release (gctx);
+    gpgme_data_release (in);
+    free_pass_cb (cb_val);
+    
+    if (err)
+	gpgme_data_release (out);
+    else
+	map_gpgme_data (out, r_msg);
+
+    return err;
+}
+
+
 /* Decrypt the message @r_msg. If the type @type is actually a signature,
    the verify function is called instead of decryption. */
 static gpgme_error_t
@@ -649,6 +680,7 @@
 	if (!rc && (msg_type & PGP_MESSAGE) && msg && strlen (msg) > 0) {
 	    struct viewer_ctx_s viewer;
 	    viewer.msg = msg;
+	    viewer.main_wnd = ctx->main_wnd;
 	    DialogBoxParam (mod_hinst_dll, (LPCTSTR)IDD_VIEWER, ctx->main_wnd,
 			    viewer_dlg_proc, (LPARAM)&viewer);
 	}

Modified: trunk/src/OEDlgEncrypt.c
===================================================================
--- trunk/src/OEDlgEncrypt.c	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/OEDlgEncrypt.c	2006-04-11 06:56:23 UTC (rev 16)
@@ -170,7 +170,7 @@
 	    SendMessage (lb, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)t->addr);	
     }
     SetWindowText (dlg, _("Select Recipient for Encryption"));
-    SetForegroundWindow (dlg);
+    SetForegroundWindow (dlg);    
 }
 
 
@@ -190,6 +190,7 @@
 	ctx = (plugin_ctx_t)lparam;
 	assert (ctx);
 	on_init_dialog (dlg, msg, wparam, lparam);
+	center_window (dlg, ctx->main_wnd);
 	return TRUE;
 
     case WM_NOTIFY:

Modified: trunk/src/OEDlgViewer.c
===================================================================
--- trunk/src/OEDlgViewer.c	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/OEDlgViewer.c	2006-04-11 06:56:23 UTC (rev 16)
@@ -45,33 +45,6 @@
 }
 
 
-/* Prepend '> ' to line line in the buffer @inp
-   and store the result in @r_outp. */
-static void
-quote_msg_text (const char *inp, char **r_outp)
-{
-    size_t i, n=0;
-    char *p;
-    char *outp;
-
-    for (i=0; i < strlen (inp); i++) {
-	if (inp[i] == '\r')
-	    n += 4;
-    }
-    outp = xcalloc (1, strlen (inp) + 1 + n + 1);
-    p = strtok ((char *)inp, "\r");
-    while (p != NULL) {
-	if (*p == '\n')
-	    p++;
-	strcat (outp, "> ");
-	strcat (outp, p);
-	strcat (outp, "\r\n");
-	p = strtok (NULL, "\r");
-    }
-    *r_outp = outp;
-}
-
-
 /* Text viewer dialog box procedure. */
 BOOL CALLBACK
 viewer_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
@@ -90,6 +63,7 @@
 	SetDlgItemText (dlg, IDC_VIEWER_TEXT2, viewer->msg);
 	SetForegroundWindow (dlg);
 	SetFocus (GetDlgItem (dlg, IDOK));
+	center_window (dlg, viewer->main_wnd);
 	return FALSE;
 	
     case WM_SYSCOMMAND:

Modified: trunk/src/OEMisc.c
===================================================================
--- trunk/src/OEMisc.c	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/OEMisc.c	2006-04-11 06:56:23 UTC (rev 16)
@@ -30,6 +30,7 @@
 #include "GPGOE.h"
 
 
+/* Convert the string from the native code page  to UTF8. */
 char*
 native_to_utf8 (const char *string)
 {
@@ -165,7 +166,7 @@
     SetClipboardData (CF_TEXT, clipmem);
     GlobalUnlock (clipmem);
     CloseClipboard ();
-    GlobalFree (clipmem);
+    GlobalFree (clipmem);  
     
     return 0;
 }
@@ -213,3 +214,70 @@
     va_end (ptr);
     MessageBox (hwnd, buffer, caption, type);
 }
+
+
+/* Prepend '> ' to line line in the buffer @inp
+   and store the result in @r_outp. */
+void
+quote_msg_text (const char *inp, char **r_outp)
+{
+    size_t i, n=0;
+    char *p;
+    char *outp;
+
+    for (i=0; i < strlen (inp); i++) {
+	if (inp[i] == '\r')
+	    n += 4;
+    }
+    outp = xcalloc (1, strlen (inp) + 1 + n + 1);
+    p = strtok ((char *)inp, "\r");
+    while (p != NULL) {
+	if (*p == '\n')
+	    p++;
+	strcat (outp, "> ");
+	strcat (outp, p);
+	strcat (outp, "\r\n");
+	p = strtok (NULL, "\r");
+    }
+    *r_outp = outp;
+}
+
+
+/* Center the window @hwndChild over the parent window @parent. */
+void
+center_window (HWND hwndChild, HWND parent) 
+{     
+    HWND hwndParent;
+    RECT rChild, rParent;
+    HDC hdc;
+    int wChild, hChild, wParent, hParent;
+    int wScreen, hScreen, xNew, yNew;
+    int flags = SWP_NOSIZE | SWP_NOZORDER;
+
+    hwndParent = parent;
+    if (hwndParent == NULL)
+	hwndParent = GetDesktopWindow ();
+    GetWindowRect (hwndChild, &rChild);     
+    wChild = rChild.right - rChild.left;     
+    hChild = rChild.bottom - rChild.top;
+
+    GetWindowRect (hwndParent, &rParent);     
+    wParent = rParent.right - rParent.left;     
+    hParent = rParent.bottom - rParent.top;      
+    
+    hdc = GetDC (hwndChild);     
+    wScreen = GetDeviceCaps (hdc, HORZRES);     
+    hScreen = GetDeviceCaps (hdc, VERTRES);     
+    ReleaseDC (hwndChild, hdc);      
+    xNew = rParent.left + ((wParent - wChild) /2);     
+    if (xNew < 0)
+	xNew = 0;
+    else if ((xNew+wChild) > wScreen) 
+	xNew = wScreen - wChild;
+    yNew = rParent.top  + ((hParent - hChild) /2);
+    if (yNew < 0)
+	yNew = 0;
+    else if ((yNew+hChild) > hScreen)
+	yNew = hScreen - hChild;
+    SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, flags);
+}

Modified: trunk/src/OEPassphraseCBDlg.c
===================================================================
--- trunk/src/OEPassphraseCBDlg.c	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/OEPassphraseCBDlg.c	2006-04-11 06:56:23 UTC (rev 16)
@@ -28,17 +28,89 @@
 #include "GPGOE.h"
 
 
+/* Structure for the passphrase cache. */
+struct pass_cache_s {
+    struct pass_cache_s *next;
+    char *keyid;
+    char *pass;
+};
+typedef struct pass_cache_s *pass_cache_t;
+
 /* Structure for the passphrase callback. */
 struct pass_cb_s {
     const char *uid_hint;
     const char *passphrase_info;
+    char keyid[8+2];
     char *pass;
-    HWND main_hwnd;
+    pass_cache_t cache;
+    HWND main_wnd;
     int cancel;
     int prev_was_bad;
 };
 
 
+/* Global passphrase cache. */
+static pass_cache_t the_cache = NULL;
+
+
+/* Release the passphrase cache @ctx and invalidate all passphrases. */
+static void
+invalidate_cache (pass_cache_t ctx)
+{
+    pass_cache_t c;
+
+    while (ctx) {
+	c = ctx->next;
+	free_if_alloc (ctx->keyid);
+	wipememory (ctx->pass, strlen (ctx->pass));
+	free_if_alloc (ctx->pass);
+	ctx = c;
+    }
+}
+
+/* Put the passphrase @pass into the passphrase cache @ctx. */
+static void
+passphrase_put (pass_cache_t *ctx, const char *keyid, const char *pass)
+{
+    pass_cache_t c, n;
+
+    /* check if the item is already present. */
+    for (n = *ctx; n; n = n->next) {
+	if (!strcmp (n->keyid, keyid))
+	    return;
+    }
+
+    c = xcalloc (1, sizeof *c);
+    c->keyid = xstrdup (keyid);
+    c->pass = xstrdup (pass);
+
+    if (!*ctx)
+	*ctx = c;
+    else {
+	for (n = *ctx; n->next; n = n->next)
+	    ;
+	n->next = c;
+    }
+}
+
+
+/* Return the passphrase for the key with the keyid @keyid
+   or NULL if the passphrase was not cached for this key. */
+static const char*
+passphrase_get (pass_cache_t ctx, const char *keyid)
+{
+    pass_cache_t c;
+
+    for (c = ctx; c; c = c->next) {
+	if (!strcmp (c->keyid, keyid))
+	    return c->pass;
+    }
+    return NULL;
+}
+
+
+
+
 /* Extract public key algorithm from passwd info. */
 const char*
 get_pubkey_algo (const char *passphrase_info)
@@ -48,7 +120,7 @@
     /* AA6F7AB7DD3B4A21 E71D9BC8C93A8529 1 0 */
     assert (strlen (passphrase_info) > pos);
     switch (atol (passphrase_info+pos)) {
-    case 1: return "RSA";
+    case  1: return "RSA";
     case 17: return "DSA";
     case 16: return "ELG";
     }
@@ -61,7 +133,7 @@
 pass_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
 {
     static pass_cb_t ctx;
-    char *info, keyid[8+2] = {0};
+    char *info;
     int n;
     
     switch (msg) {
@@ -70,10 +142,9 @@
 	assert (ctx);
 	if (ctx->uid_hint && ctx->passphrase_info) {
 	    char *utf8_uid = utf8_to_native (ctx->uid_hint+17);
-	    memcpy (keyid, ctx->passphrase_info+8, 8);
-	    info = xcalloc (1, strlen (utf8_uid) +  strlen (keyid) + 32);
+	    info = xcalloc (1, strlen (utf8_uid) +  strlen (ctx->keyid) + 32);
 	    sprintf (info, _("%s\n%s key, ID %s"), utf8_uid, 
-			    get_pubkey_algo (ctx->passphrase_info), keyid);
+			    get_pubkey_algo (ctx->passphrase_info), ctx->keyid);
 	    SetDlgItemText (dlg, IDC_DECRYPT_MSG, info);
 	    free_if_alloc (utf8_uid);
 	    free_if_alloc (info);
@@ -83,11 +154,23 @@
 	SetDlgItemText (dlg, IDC_DECRYPT_PWDINFO, _("Please enter your passphrase"));
 	SendDlgItemMessage (dlg, IDC_DECRYPT_PWD, EM_SETPASSWORDCHAR, 
 			    (WPARAM)(UINT)'*', 0);
+	CheckDlgButton (dlg, IDC_DECRYPT_HIDE, BST_CHECKED);
 	SetWindowText (dlg, _("Decryption"));
 	SetForegroundWindow (dlg);
+	center_window (dlg, ctx->main_wnd);
 	break;
 
     case WM_COMMAND:
+	if (HIWORD (wparam) == BN_CLICKED &&
+	    LOWORD (wparam) == IDC_DECRYPT_HIDE) {
+	    HWND hwnd;
+	    hwnd = GetDlgItem (dlg, IDC_DECRYPT_PWD);
+	    SendMessage (hwnd, EM_SETPASSWORDCHAR, 
+			 IsDlgButtonChecked (dlg, IDC_DECRYPT_HIDE)? '*' : 0, 0);
+	    SetFocus (hwnd);
+	    break;
+	}
+
 	switch (LOWORD (wparam)) {
 	case IDCANCEL:
 	    ctx->cancel = 1;
@@ -102,7 +185,7 @@
 	    else
 		SetDlgItemText (dlg, IDC_DECRYPT_PWDINFO,
 				_("Please enter your passphrase"));
-	    n = SendDlgItemMessage (dlg, IDC_DECRYPT_PWD, 
+	    n = SendDlgItemMessage (dlg, IDC_DECRYPT_PWD,
 				    WM_GETTEXTLENGTH, 0, 0);
 	    if (n < 1) {
 		MessageBox (dlg, _("Please enter your passphrase"),
@@ -112,6 +195,8 @@
 	    ctx->cancel = 0;
 	    ctx->pass = xcalloc (1, n+2);
 	    GetDlgItemText (dlg, IDC_DECRYPT_PWD, ctx->pass, n+1);
+
+	    /*passphrase_put (&the_cache, ctx->keyid, ctx->pass);*/
 	    EndDialog (dlg, TRUE);
 	    break;
 	}
@@ -130,6 +215,7 @@
 {
     pass_cb_t cb = (pass_cb_t)hook;
     HANDLE fp = (HANDLE)fd;
+    const char *pass;
     DWORD nwritten = 0;
     
     cb->prev_was_bad = prev_was_bad;
@@ -140,10 +226,15 @@
     if (!cb->pass && !cb->cancel) {
 	cb->uid_hint = uid_hint;
 	cb->passphrase_info = passphrase_info;
-	DialogBoxParam (mod_hinst_dll, (LPCTSTR)IDD_DECRYPT,
-			cb->main_hwnd, pass_cb_dlg_proc, (LPARAM)cb);
+	memset (cb->keyid, 0, sizeof (cb->keyid));
+	memcpy (cb->keyid, cb->passphrase_info+8, 8);
+
+	if (the_cache && (pass=passphrase_get (the_cache, cb->keyid)))
+	    cb->pass = xstrdup (pass);
+	else
+	    DialogBoxParam (mod_hinst_dll, (LPCTSTR)IDD_DECRYPT,
+			    cb->main_wnd, pass_cb_dlg_proc, (LPARAM)cb);
     }
-
     if (cb->cancel)
 	WriteFile (fp, "\n", 1, &nwritten, NULL);
     else if (cb->pass != NULL) {
@@ -161,7 +252,7 @@
     pass_cb_t cb_val;
 
     cb_val = xcalloc (1, sizeof *cb_val);
-    cb_val->main_hwnd = main;
+    cb_val->main_wnd = main;
     return cb_val;
 }
 
@@ -179,3 +270,12 @@
     }
     free_if_alloc (cb);
 }
+
+
+/* Release the passphrase cache. */
+void
+free_pass_cache (void)
+{
+    invalidate_cache (the_cache);
+    the_cache = NULL;
+}

Modified: trunk/src/OEProc.c
===================================================================
--- trunk/src/OEProc.c	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/OEProc.c	2006-04-11 06:56:23 UTC (rev 16)
@@ -1,4 +1,4 @@
-/* OEProc.c - OE window procedures 
+/* OEProc.c - OE window procedure
  *	Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz
  *
  * This file is part of GPGOE.
@@ -34,6 +34,7 @@
 #define ID_OE_SEND	    40411
 #define ID_OE_PREVMSG	    40145
 #define ID_OE_NEXTMSG	    40146
+#define ID_OE_ATTACH	    40237
 
 /* Outlook select charset IDs. */
 #define ID_OE_CP_UTF8		42540
@@ -44,7 +45,7 @@
 #define ID_OE_CP_LATIN9		42535
 
 /* Global plugin structure. */
-static plugin_ctx_t oe_plug;
+plugin_ctx_t oe_plug;
 
 /* We show a warning for the attachment problem, but only once. */
 static int attach_warn_shown = 0;
@@ -56,16 +57,7 @@
 HANDLE plugin_active = NULL;
 
 
-/* Return the Outlook main window handle. */
-HWND
-outlook_get_main_window (void)
-{
-    if (!oe_plug)
-	return GetActiveWindow ();
-    return oe_plug->main_wnd;
-}
 
-
 /* Display a warning that the attachments of the mail will be
    sent in cleartext. */
 static void
@@ -160,19 +152,16 @@
 }
 
 
-/* Try to figure out if the message is from the inbox or 
-   the outbox folder. */
+/* Try to figure out if the message is from the inbox or the outbox folder. */
 int
 window_is_inbox (HWND to_hwnd)
 {
-    /*
-    XXX: we need to check the express version otherwise early
-         V6 versions will not work.
-    if (GetWindowLong (to_hwnd, GWL_STYLE) & ES_READONLY)
+    char wclass[200];
+
+    if (GetDlgCtrlID (to_hwnd) == 1028 &&
+	GetClassName (to_hwnd, wclass, sizeof (wclass)-1) > 0
+	&& !strcmp (wclass, "RichEdit20W"))
 	return 1;
-    */
-    if (GetDlgCtrlID (to_hwnd) == 1028)
-	return 1;
     return 0;
 }
 
@@ -191,8 +180,7 @@
 /* Initialize the plugin context:
    Find all windows the plugin need to handle messages.
    The text of the recipients fields is only used when the message comes
-   from the outbox, because the inbox fields are readonly.
-   >= OE 5.5 uses a newer RichEdit control! */
+   from the outbox, because the inbox fields are readonly. */
 int
 plugin_init (plugin_ctx_t ctx, HWND main, int is_inbox)
 {
@@ -205,17 +193,10 @@
 
     ctx->main_wnd = main;
     ctx->addr_wnd = FindWindowEx (main, NULL, "OE_Envelope", NULL);
-    ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RICHEDIT", NULL);
-    if (!ctx->to_wnd)
-	ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RichEdit20W", NULL);
-    ctx->cc_wnd = FindWindowEx (ctx->addr_wnd, ctx->to_wnd, "RICHEDIT", NULL);
-    if (!ctx->cc_wnd)
-	ctx->cc_wnd = FindWindowEx (ctx->addr_wnd, ctx->to_wnd, 
-				    "RichEdit20W", NULL);
-    ctx->bcc_wnd = FindWindowEx (ctx->addr_wnd, ctx->cc_wnd, "RICHEDIT", NULL);
-    if (!ctx->bcc_wnd)
-	ctx->bcc_wnd = FindWindowEx (ctx->addr_wnd, ctx->cc_wnd, 
-				     "RichEdit20W", NULL);
+    ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RichEdit20W", NULL);
+    ctx->cc_wnd = FindWindowEx (ctx->addr_wnd, ctx->to_wnd, "RichEdit20W", NULL);
+    ctx->bcc_wnd = FindWindowEx (ctx->addr_wnd, ctx->cc_wnd, "RichEdit20W", NULL);
+
     ctx->to = NULL;
     ctx->cc = NULL;
     ctx->bcc = NULL;
@@ -272,13 +253,9 @@
 	       control would not be displayed. */
 	    LoadLibrary ("RichEd32.Dll");
 	    setup_gettext();
-	    plugin_active = CreateEvent (NULL, TRUE, /*TRUE*/FALSE, NULL);
+	    plugin_active = CreateEvent (NULL, TRUE, FALSE, NULL);
 	    plugin_preload_done = 1;
 	}
-	/*
-	else
-	    SetEvent (plugin_active);
-	*/
 	initialized = 0;
 	plugin_new (&oe_plug);
 	break;
@@ -322,6 +299,9 @@
 	    oe_plug->use_utf8 = 0;
 	    break;
 
+	case ID_OE_ATTACH:
+	    break;
+
 	case ID_OE_ENCRYPT:
 	    encr_msg ^= 1;
 	    break;

Modified: trunk/src/resource.h
===================================================================
--- trunk/src/resource.h	2006-04-10 05:39:33 UTC (rev 15)
+++ trunk/src/resource.h	2006-04-11 06:56:23 UTC (rev 16)
@@ -19,6 +19,7 @@
 #define IDC_SIGN_KEYLIST                1009
 #define IDC_VIEWER_QUOTE                1010
 #define IDC_VIEWER_TEXT2                1013
+#define IDC_DECRYPT_HIDE                1014
 
 // Next default values for new objects
 // 
@@ -26,7 +27,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        108
 #define _APS_NEXT_COMMAND_VALUE         40001
-#define _APS_NEXT_CONTROL_VALUE         1014
+#define _APS_NEXT_CONTROL_VALUE         1015
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif



More information about the Gpgoe-commits mailing list