1 |
/* OEProc.c - OE window procedures |
/* OEProc.c - OE window procedure |
2 |
* Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz |
* Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of GPGOE. |
* This file is part of GPGOE. |
23 |
#endif |
#endif |
24 |
#include <windows.h> |
#include <windows.h> |
25 |
#include <stdio.h> |
#include <stdio.h> |
26 |
|
#include <commctrl.h> |
27 |
|
|
28 |
#include "gpgme.h" |
#include "gpgme.h" |
29 |
#include "GPGOE.h" |
#include "GPGOE.h" |
30 |
|
|
31 |
|
/* FIXME: I'm not sure if this still works with the Vista version of Express */ |
32 |
|
|
33 |
|
/* Outlook V6.x command IDs. */ |
34 |
|
#define ID_OE_ENCRYPT 40260 |
35 |
|
#define ID_OE_SIGN 40299 |
36 |
|
#define ID_OE_SEND 40411 |
37 |
|
#define ID_OE_PREVMSG 40145 |
38 |
|
#define ID_OE_NEXTMSG 40146 |
39 |
|
#define ID_OE_ATTACH 40237 |
40 |
|
|
41 |
|
/* Outlook select charset IDs. */ |
42 |
|
#define ID_OE_CP_UTF8 42540 |
43 |
|
#define ID_OE_CP_WEUROPE_ISO 42544 |
44 |
|
#define ID_OE_CP_WEUROPE_WINCP 42545 |
45 |
|
#define ID_OE_CP_MEUROPE_ISO 42525 |
46 |
|
#define ID_OE_CP_MEUROPE_WINCP 42526 |
47 |
|
#define ID_OE_CP_LATIN9 42535 |
48 |
|
|
49 |
/* Global plugin structure. */ |
/* Global plugin structure. */ |
50 |
static plugin_ctx_t oe_plug; |
plugin_ctx_t oe_plug; |
51 |
|
|
52 |
|
/* We show a warning for the attachment problem, but only once. */ |
53 |
|
static int attach_warn_shown = 0; |
54 |
|
|
55 |
|
/* One time initialisation finished?. */ |
56 |
|
static int plugin_preload_done = 0; |
57 |
|
|
58 |
|
/* Event to indicate if the plugin is active or not. */ |
59 |
|
HANDLE plugin_active = NULL; |
60 |
|
|
61 |
|
|
62 |
|
/* Display a warning that the attachments of the mail will be |
63 |
|
sent in cleartext. */ |
64 |
|
static void |
65 |
|
show_attachment_warn (HWND hwnd) |
66 |
|
{ |
67 |
|
if (attach_warn_shown) |
68 |
|
return; |
69 |
|
|
70 |
|
MessageBox (hwnd, _("GPGOE is unable to secure attachments.\r\n" |
71 |
|
"As a result the data attached to this mail is NOT encrypted."), |
72 |
|
_("GPG Plug-in Warning"), MB_ICONWARNING|MB_OK); |
73 |
|
attach_warn_shown = 1; |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
/* Display a warning that the mail will be sent in clear. */ |
/* Display a warning that the mail will be sent in clear. */ |
81 |
const char *fmt, *s; |
const char *fmt, *s; |
82 |
char *p; |
char *p; |
83 |
|
|
84 |
fmt = _("WARNING: This message will be sent in cleartext.\r\n%s"); |
fmt = _("WARNING: This message will be sent in cleartext.\r\n\r\n" |
85 |
|
"Error description: %s."); |
86 |
s = gpgme_strerror (rc); |
s = gpgme_strerror (rc); |
87 |
p = xcalloc (1, strlen (fmt)+ strlen (s)+2); |
p = xcalloc (1, strlen (fmt)+ strlen (s)+2); |
88 |
sprintf (p, fmt, s); |
sprintf (p, fmt, s); |
91 |
} |
} |
92 |
|
|
93 |
|
|
94 |
/* Reset the plugin. */ |
/* Reset the plugin state. */ |
95 |
static void |
static void |
96 |
plugin_reset (plugin_ctx_t ctx) |
plugin_reset (plugin_ctx_t ctx) |
97 |
{ |
{ |
105 |
} |
} |
106 |
|
|
107 |
|
|
108 |
|
/* Release plugin context. */ |
109 |
static void |
static void |
110 |
plugin_release (plugin_ctx_t ctx) |
plugin_release (plugin_ctx_t ctx) |
111 |
{ |
{ |
116 |
} |
} |
117 |
|
|
118 |
|
|
119 |
|
/* Create new plugin context. */ |
120 |
static int |
static int |
121 |
plugin_new (plugin_ctx_t *r_ctx) |
plugin_new (plugin_ctx_t *r_ctx) |
122 |
{ |
{ |
144 |
GetWindowThreadProcessId (main, NULL), |
GetWindowThreadProcessId (main, NULL), |
145 |
FALSE); |
FALSE); |
146 |
|
|
147 |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE5_SELECTALL, 0), 0); |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
148 |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE5_COPY, 0), 0); |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE_COPY, 0), 0); |
149 |
|
|
150 |
Sleep (200); |
Sleep (200); |
151 |
|
|
153 |
} |
} |
154 |
|
|
155 |
|
|
156 |
/* Try to figure out if the message is from the inbox or |
/* Try to figure out if the message is from the inbox or the outbox folder. */ |
|
the outbox folder. */ |
|
157 |
int |
int |
158 |
window_is_inbox (HWND to_hwnd) |
window_is_inbox (HWND to_hwnd) |
159 |
{ |
{ |
160 |
/* |
char wclass[200]; |
161 |
XXX: we need to check the express version otherwise early |
|
162 |
V6 versions will not work. |
if (GetDlgCtrlID (to_hwnd) == 1028 && |
163 |
if (GetWindowLong (to_hwnd, GWL_STYLE) & ES_READONLY) |
GetClassName (to_hwnd, wclass, sizeof (wclass)-1) > 0 |
164 |
return 1; |
&& !strcmp (wclass, "RichEdit20W")) |
|
*/ |
|
|
if (GetDlgCtrlID (to_hwnd) == 1028) |
|
165 |
return 1; |
return 1; |
166 |
return 0; |
return 0; |
167 |
} |
} |
168 |
|
|
169 |
|
|
170 |
|
/* Check if the attach listview control contains at least one entry. |
171 |
|
Return the amount of attachments. */ |
172 |
|
int |
173 |
|
mail_count_attachments (plugin_ctx_t ctx) |
174 |
|
{ |
175 |
|
if (!ctx->attach) |
176 |
|
return 0; |
177 |
|
return ListView_GetItemCount (ctx->attach); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
/* Initialize the plugin context: |
/* Initialize the plugin context: |
182 |
Find all windows the plugin need to handle messages. |
Find all windows the plugin need to handle messages. |
183 |
The text of the recipients fields is only used when the message comes |
The text of the recipients fields is only used when the message comes |
184 |
from the outbox, because the inbox fields are readonly. |
from the outbox, because the inbox fields are readonly. */ |
|
>= OE 5.5 uses a newer RichEdit control! */ |
|
185 |
int |
int |
186 |
plugin_init (plugin_ctx_t ctx, HWND main, int is_inbox) |
plugin_init (plugin_ctx_t ctx, HWND main, int is_inbox) |
187 |
{ |
{ |
188 |
|
/* store original clipboard text. */ |
189 |
|
free_if_alloc (ctx->orig_text); |
190 |
|
ctx->orig_text = get_clip_text (NULL); |
191 |
|
|
192 |
ctx->sign = 0; |
ctx->sign = 0; |
193 |
ctx->encrypt = 0; |
ctx->encrypt = 0; |
194 |
|
|
195 |
ctx->main_wnd = main; |
ctx->main_wnd = main; |
196 |
ctx->addr_wnd = FindWindowEx (main, NULL, "OE_Envelope", NULL); |
ctx->addr_wnd = FindWindowEx (main, NULL, "OE_Envelope", NULL); |
197 |
ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RICHEDIT", NULL); |
ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RichEdit20W", NULL); |
198 |
if (!ctx->to_wnd) |
ctx->cc_wnd = FindWindowEx (ctx->addr_wnd, ctx->to_wnd, "RichEdit20W", NULL); |
199 |
ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RichEdit20W", NULL); |
ctx->bcc_wnd = FindWindowEx (ctx->addr_wnd, ctx->cc_wnd, "RichEdit20W", NULL); |
200 |
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); |
|
201 |
ctx->to = NULL; |
ctx->to = NULL; |
202 |
ctx->cc = NULL; |
ctx->cc = NULL; |
203 |
ctx->bcc = NULL; |
ctx->bcc = NULL; |
204 |
|
|
205 |
|
ctx->attach = FindWindowEx (ctx->addr_wnd, NULL, "SysListView32", NULL); |
206 |
|
|
207 |
if (!is_inbox && !window_is_inbox (ctx->to_wnd)) { |
if (!is_inbox && !window_is_inbox (ctx->to_wnd)) { |
208 |
ctx->to = get_address_text (ctx->main_wnd, ctx->to_wnd); |
ctx->to = get_address_text (ctx->main_wnd, ctx->to_wnd); |
209 |
ctx->cc = get_address_text (ctx->main_wnd, ctx->cc_wnd); |
ctx->cc = get_address_text (ctx->main_wnd, ctx->cc_wnd); |
214 |
} |
} |
215 |
|
|
216 |
|
|
217 |
|
/* Clear the clipboard contents. */ |
218 |
static void |
static void |
219 |
clear_clipboard (void) |
clear_clipboard (void) |
220 |
{ |
{ |
224 |
} |
} |
225 |
|
|
226 |
|
|
227 |
|
/* Restore the original clipboard data from the plugin context. */ |
228 |
|
static void |
229 |
|
restore_clipboard (plugin_ctx_t ctx) |
230 |
|
{ |
231 |
|
if (!ctx->orig_text) |
232 |
|
return; |
233 |
|
set_clip_text (NULL, ctx->orig_text, strlen (ctx->orig_text)); |
234 |
|
free_if_alloc (ctx->orig_text); |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
/* Subclass dialog procedure for the outlook message window. */ |
/* Subclass dialog procedure for the outlook message window. */ |
239 |
LRESULT CALLBACK |
LRESULT CALLBACK |
240 |
oe_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
oe_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
241 |
{ |
{ |
242 |
static initialized = 0; |
static int initialized = 0; |
243 |
static int encr_msg = 0; |
static int encr_msg = 0; |
244 |
static int sign_msg = 0; |
static int sign_msg = 0; |
245 |
int rc = 0; |
int rc = 0; |
248 |
initialized = SetTimer (hwnd, 1, 1000, NULL); |
initialized = SetTimer (hwnd, 1, 1000, NULL); |
249 |
|
|
250 |
switch (msg) { |
switch (msg) { |
251 |
case WM_CREATE: |
case WM_CREATE: |
252 |
|
if (!plugin_preload_done) { |
253 |
|
/* We need to load this lib here otherwise the richedit |
254 |
|
control would not be displayed. */ |
255 |
|
LoadLibrary ("RichEd32.Dll"); |
256 |
|
setup_gettext(); |
257 |
|
plugin_active = CreateEvent (NULL, TRUE, FALSE, NULL); |
258 |
|
plugin_preload_done = 1; |
259 |
|
} |
260 |
initialized = 0; |
initialized = 0; |
261 |
plugin_new (&oe_plug); |
plugin_new (&oe_plug); |
262 |
break; |
break; |
263 |
|
|
264 |
case WM_DESTROY: |
case WM_DESTROY: |
265 |
|
ResetEvent (plugin_active); |
266 |
plugin_release (oe_plug); |
plugin_release (oe_plug); |
267 |
|
encr_msg = sign_msg = 0; |
268 |
break; |
break; |
269 |
|
|
270 |
case WM_TIMER: |
case WM_TIMER: |
|
clear_clipboard (); |
|
271 |
KillTimer (hwnd, initialized); |
KillTimer (hwnd, initialized); |
272 |
plugin_reset (oe_plug); |
plugin_reset (oe_plug); |
273 |
plugin_init (oe_plug, hwnd, 1); |
plugin_init (oe_plug, hwnd, 1); |
274 |
if (window_is_inbox (oe_plug->to_wnd)) { |
if (window_is_inbox (oe_plug->to_wnd)) { |
275 |
|
clear_clipboard (); |
276 |
rc = oe_handle_mail (oe_plug); |
rc = oe_handle_mail (oe_plug); |
277 |
if (rc) |
if (rc) |
278 |
show_error (hwnd, _("GPG Plug-in Error"), MB_ICONERROR|MB_OK, |
show_error (hwnd, _("GPG Plug-in Error"), MB_ICONERROR|MB_OK, |
279 |
_("decrypt/verify: %s\n%s"), |
_("decrypt/verify: %s\n%s"), |
280 |
gpgme_strerror (rc), oe_plug->errbuf); |
gpgme_strerror (rc), oe_plug->errbuf); |
281 |
} |
} |
282 |
break; |
break; |
|
} |
|
283 |
|
|
284 |
switch (LOWORD (wparam)) { |
case WM_COMMAND: |
285 |
case ID_OE5_PREVMSG: |
switch (LOWORD (wparam)) { |
286 |
case ID_OE5_NEXTMSG: |
case ID_OE_PREVMSG: |
287 |
SetTimer (hwnd, 1, 1000, NULL); |
case ID_OE_NEXTMSG: |
288 |
|
SetTimer (hwnd, 1, 1000, NULL); |
289 |
|
break; |
290 |
|
|
291 |
|
case ID_OE_CP_UTF8: |
292 |
|
oe_plug->use_utf8 = 1; |
293 |
|
break; |
294 |
|
|
295 |
|
case ID_OE_CP_WEUROPE_ISO: |
296 |
|
case ID_OE_CP_WEUROPE_WINCP: |
297 |
|
case ID_OE_CP_MEUROPE_ISO: |
298 |
|
case ID_OE_CP_MEUROPE_WINCP: |
299 |
|
case ID_OE_CP_LATIN9: |
300 |
|
oe_plug->use_utf8 = 0; |
301 |
|
break; |
302 |
|
|
303 |
|
case ID_OE_ATTACH: |
304 |
|
break; |
305 |
|
|
306 |
|
case ID_OE_ENCRYPT: |
307 |
|
encr_msg ^= 1; |
308 |
|
break; |
309 |
|
|
310 |
|
case ID_OE_SIGN: |
311 |
|
sign_msg ^= 1; |
312 |
|
break; |
313 |
|
|
314 |
|
case ID_OE_SEND: |
315 |
|
if (encr_msg || sign_msg) { |
316 |
|
plugin_init (oe_plug, hwnd, 0); |
317 |
|
if (encr_msg) { |
318 |
|
SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_ENCRYPT, 0), 0); |
319 |
|
oe_plug->encrypt = 1; |
320 |
|
} |
321 |
|
if (sign_msg) { |
322 |
|
SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SIGN, 0), 0); |
323 |
|
oe_plug->sign = 1; |
324 |
|
} |
325 |
|
rc = oe_handle_mail (oe_plug); |
326 |
|
if (rc) |
327 |
|
show_plaintext_warn (hwnd, rc); |
328 |
|
restore_clipboard (oe_plug); |
329 |
|
if (mail_count_attachments (oe_plug) > 0) |
330 |
|
show_attachment_warn (hwnd); |
331 |
|
} |
332 |
|
break; |
333 |
|
} |
334 |
break; |
break; |
|
|
|
|
case ID_OE5_ENCRYPT: |
|
|
encr_msg ^= 1; |
|
|
break; |
|
|
|
|
|
case ID_OE5_SIGN: |
|
|
sign_msg ^= 1; |
|
|
break; |
|
|
|
|
|
case ID_OE5_SEND: |
|
|
if (encr_msg || sign_msg) { |
|
|
plugin_init (oe_plug, hwnd, 0); |
|
|
if (encr_msg) { |
|
|
SendMessage (hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_ENCRYPT, 0), 0); |
|
|
oe_plug->encrypt = 1; |
|
|
} |
|
|
if (sign_msg) { |
|
|
SendMessage (hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_SIGN, 0), 0); |
|
|
oe_plug->sign = 1; |
|
|
} |
|
|
rc = oe_handle_mail (oe_plug); |
|
|
if (rc) |
|
|
show_plaintext_warn (hwnd, rc); |
|
|
} |
|
|
break; |
|
335 |
} |
} |
336 |
|
|
337 |
return CallWindowProc (oe_proc_old, hwnd, msg, wparam, lparam); |
return CallWindowProc (oe_proc_old, hwnd, msg, wparam, lparam); |