27 |
#include "gpgme.h" |
#include "gpgme.h" |
28 |
#include "GPGOE.h" |
#include "GPGOE.h" |
29 |
|
|
|
|
|
30 |
/* Global DLL module handle. */ |
/* Global DLL module handle. */ |
31 |
HINSTANCE mod_hinst_dll; |
HINSTANCE mod_hinst_dll; |
32 |
|
|
33 |
|
/* Outlook Express old window procedure. */ |
34 |
|
WNDPROC oe_proc_old; |
35 |
|
|
36 |
/* DLL hook handle for the CBT function. */ |
/* DLL hook handle for the CBT function. */ |
37 |
static HHOOK ctb_hook = NULL; |
static HHOOK ctb_hook = NULL; |
38 |
|
|
39 |
/* Outlook Express window handle. */ |
/* Outlook Express window handle. */ |
40 |
static HWND oe_hwnd = NULL; |
static HWND oe_hwnd = NULL; |
41 |
|
|
42 |
/* Outlook Express old window procedure. */ |
/* We need a shared section to define variables which |
43 |
WNDPROC oe_proc_old; |
will keep their values in all address spaces. */ |
44 |
|
#ifdef __GNUC__ |
45 |
|
#define ATTR_SEC __attribute__((section (".SHARDAT"), shared)) |
46 |
|
#else |
47 |
|
#define ATTR_SEC |
48 |
|
#pragma data_seg(".SHARDAT") |
49 |
|
#endif |
50 |
|
static int gpgoe_active_modes ATTR_SEC = 0; |
51 |
|
#ifndef __GNUC__ |
52 |
|
#pragma data_seg() |
53 |
|
#endif |
54 |
|
#undef ATTR_SEC |
55 |
|
|
56 |
|
|
57 |
|
/* Supported plug-in modes. */ |
58 |
|
enum gpgoe_mode_t { |
59 |
|
GPGOE_MODE_NORMAL = 0, |
60 |
|
GPGOE_MODE_PLAINREPLY = 1 /* decrypt mails before a reply. */ |
61 |
|
}; |
62 |
|
|
63 |
|
|
64 |
/* Main DLL entry point. */ |
/* Main DLL entry point. */ |
86 |
|
|
87 |
|
|
88 |
/* Quick and dirty check if the dialog is a common dialog |
/* Quick and dirty check if the dialog is a common dialog |
89 |
and the 'File Save' style. */ |
and the 'File {Open, Save}' style. */ |
90 |
static int |
static int |
91 |
is_filesave_dlg (HWND h) |
is_common_file_dlg (HWND h) |
92 |
{ |
{ |
93 |
HWND button = GetDlgItem (h, 1040); |
HWND button = GetDlgItem (h, 1040); |
94 |
char wclass[200]; |
char wclass[200]; |
102 |
} |
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
/* CTB hook procedure. |
/* CTB hook procedure. |
107 |
Monitors the creation of all windows and subclass the window |
Monitors the creation of all windows and subclass the window |
108 |
if it belongs to the Outlook Express message class. */ |
if it belongs to the Outlook Express (message) class. */ |
109 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
110 |
ctb_proc (int code, WPARAM wparam, LPARAM lparam) |
ctb_proc (int code, WPARAM wparam, LPARAM lparam) |
111 |
{ |
{ |
132 |
else |
else |
133 |
oe_hwnd = hwnd; |
oe_hwnd = hwnd; |
134 |
} |
} |
135 |
|
|
136 |
|
if ((gpgoe_active_modes & GPGOE_MODE_PLAINREPLY) && |
137 |
|
!strcmp (wclass, "Outlook Express Browser Class")) { |
138 |
|
oe_main_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC); |
139 |
|
if (!oe_main_proc_old) |
140 |
|
show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK, |
141 |
|
"Could not get window procedure ec=%d", |
142 |
|
(int)GetLastError ()); |
143 |
|
else if (!SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_main_proc)) |
144 |
|
show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK, |
145 |
|
"Could not set window procedure: ec=%d", |
146 |
|
(int)GetLastError ()); |
147 |
|
} |
148 |
break; |
break; |
149 |
|
|
150 |
#if 0 |
#if 0 |
154 |
char wclass[200]; |
char wclass[200]; |
155 |
|
|
156 |
if (GetClassName (hwnd, wclass, sizeof (wclass)-1) <= 0 || |
if (GetClassName (hwnd, wclass, sizeof (wclass)-1) <= 0 || |
157 |
!strstr (wclass, "#32770") || !is_filesave_dlg (hwnd)) |
!strstr (wclass, "#32770") || !is_common_file_dlg (hwnd)) |
158 |
break; |
break; |
159 |
of_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC); |
of_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC); |
160 |
SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)of_proc); |
SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)of_proc); |
161 |
} |
} |
162 |
break; |
break; |
163 |
#endif |
#endif |
164 |
} |
} |
165 |
return CallNextHookEx (ctb_hook, code, wparam, lparam); |
return CallNextHookEx (ctb_hook, code, wparam, lparam); |
166 |
} |
} |
167 |
|
|
168 |
|
|
169 |
/* Initialize the hooks. |
/* Initialize the hooks; a named mutex prevents that the |
170 |
To prevent double initialisation, we use a named mutex. */ |
initialisation is done twice. |
171 |
|
Return value: 0 on success. */ |
172 |
int |
int |
173 |
gpgoe_initialize (void) |
gpgoe_initialize (void) |
174 |
{ |
{ |
180 |
} |
} |
181 |
|
|
182 |
|
|
183 |
/* Deinitialize the hooks and close all handles. */ |
/* Deinitialize the hooks and close all handles. |
184 |
|
Return value: 0 on success. */ |
185 |
int |
int |
186 |
gpgoe_remove (void) |
gpgoe_remove (void) |
187 |
{ |
{ |
|
int rc = 0; |
|
188 |
HANDLE hd; |
HANDLE hd; |
189 |
|
int rc; |
190 |
|
|
191 |
hd = CreateMutex (NULL, TRUE, "gpgoe"); |
hd = CreateMutex (NULL, TRUE, "gpgoe"); |
192 |
if (GetLastError() == ERROR_ALREADY_EXISTS) { |
if (GetLastError() == ERROR_ALREADY_EXISTS) { |
197 |
rc = UnhookWindowsHookEx (ctb_hook); |
rc = UnhookWindowsHookEx (ctb_hook); |
198 |
return rc ? 0 : (int)GetLastError (); |
return rc ? 0 : (int)GetLastError (); |
199 |
} |
} |
200 |
|
|
201 |
|
|
202 |
|
/* Change the active plug-in modes, enable mode @mode. */ |
203 |
|
void |
204 |
|
gpgoe_set_active_modes (int mode) |
205 |
|
{ |
206 |
|
gpgoe_active_modes = mode; |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
int |
211 |
|
gpgoe_get_active_modes (void) |
212 |
|
{ |
213 |
|
return gpgoe_active_modes; |
214 |
|
} |
215 |
|
|