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. |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
|
* along with GPGOE; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
16 |
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
19 |
#endif |
#endif |
20 |
#include <windows.h> |
#include <windows.h> |
21 |
#include <stdio.h> |
#include <stdio.h> |
22 |
|
#include <commctrl.h> |
23 |
|
|
24 |
#include "gpgme.h" |
#include "gpgme.h" |
25 |
#include "GPGOE.h" |
#include "GPGOE.h" |
26 |
|
|
27 |
|
/* FIXME: I'm not sure if this still works with the Vista version of Express */ |
28 |
|
|
29 |
|
/* Outlook V6.x command IDs. */ |
30 |
|
#define ID_OE_ENCRYPT 40260 |
31 |
|
#define ID_OE_SIGN 40299 |
32 |
|
#define ID_OE_SEND 40411 |
33 |
|
#define ID_OE_PREVMSG 40145 |
34 |
|
#define ID_OE_NEXTMSG 40146 |
35 |
|
#define ID_OE_ATTACH 40237 |
36 |
|
|
37 |
|
/* Outlook select charset IDs. */ |
38 |
|
#define ID_OE_CP_UTF8 42540 |
39 |
|
#define ID_OE_CP_WEUROPE_ISO 42544 |
40 |
|
#define ID_OE_CP_WEUROPE_WINCP 42545 |
41 |
|
#define ID_OE_CP_MEUROPE_ISO 42525 |
42 |
|
#define ID_OE_CP_MEUROPE_WINCP 42526 |
43 |
|
#define ID_OE_CP_LATIN9 42535 |
44 |
|
|
45 |
/* Global plugin structure. */ |
/* Global plugin structure. */ |
46 |
static plugin_ctx_t oe_plug; |
plugin_ctx_t oe_plug; |
47 |
|
|
48 |
|
/* We show a warning for the attachment problem, but only once. */ |
49 |
|
static int attach_warn_shown = 0; |
50 |
|
|
51 |
|
/* One time initialisation finished?. */ |
52 |
|
static int plugin_preload_done = 0; |
53 |
|
|
54 |
|
/* Event to indicate if the plugin is active or not. */ |
55 |
|
HANDLE plugin_active = NULL; |
56 |
|
|
57 |
|
|
58 |
|
/* Display a warning that the attachments of the mail will be |
59 |
|
sent in cleartext. */ |
60 |
|
static void |
61 |
|
show_attachment_warn (HWND hwnd) |
62 |
|
{ |
63 |
|
if (attach_warn_shown) |
64 |
|
return; |
65 |
|
|
66 |
|
MessageBox (hwnd, _("GPGOE is unable to secure attachments.\r\n" |
67 |
|
"As a result the data attached to this mail is NOT encrypted."), |
68 |
|
_("GPG Plug-in Warning"), MB_ICONWARNING|MB_OK); |
69 |
|
attach_warn_shown = 1; |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
/* Display a warning that the mail will be sent in clear. */ |
/* Display a warning that the mail will be sent in clear. */ |
77 |
const char *fmt, *s; |
const char *fmt, *s; |
78 |
char *p; |
char *p; |
79 |
|
|
80 |
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" |
81 |
|
"Error description: %s."); |
82 |
s = gpgme_strerror (rc); |
s = gpgme_strerror (rc); |
83 |
p = xcalloc (1, strlen (fmt)+ strlen (s)+2); |
p = xcalloc (1, strlen (fmt)+ strlen (s)+2); |
84 |
sprintf (p, fmt, s); |
sprintf (p, fmt, s); |
87 |
} |
} |
88 |
|
|
89 |
|
|
90 |
/* Reset the plugin. */ |
/* Reset the plugin state. */ |
91 |
static void |
static void |
92 |
plugin_reset (plugin_ctx_t ctx) |
plugin_reset (plugin_ctx_t ctx) |
93 |
{ |
{ |
101 |
} |
} |
102 |
|
|
103 |
|
|
104 |
|
/* Release plugin context. */ |
105 |
static void |
static void |
106 |
plugin_release (plugin_ctx_t ctx) |
plugin_release (plugin_ctx_t ctx) |
107 |
{ |
{ |
112 |
} |
} |
113 |
|
|
114 |
|
|
115 |
|
/* Create new plugin context. */ |
116 |
static int |
static int |
117 |
plugin_new (plugin_ctx_t *r_ctx) |
plugin_new (plugin_ctx_t *r_ctx) |
118 |
{ |
{ |
140 |
GetWindowThreadProcessId (main, NULL), |
GetWindowThreadProcessId (main, NULL), |
141 |
FALSE); |
FALSE); |
142 |
|
|
143 |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE5_SELECTALL, 0), 0); |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
144 |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE5_COPY, 0), 0); |
SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE_COPY, 0), 0); |
145 |
|
|
146 |
Sleep (200); |
Sleep (200); |
147 |
|
|
149 |
} |
} |
150 |
|
|
151 |
|
|
152 |
/* 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. */ |
|
153 |
int |
int |
154 |
window_is_inbox (HWND to_hwnd) |
window_is_inbox (HWND to_hwnd) |
155 |
{ |
{ |
156 |
/* |
char wclass[200]; |
157 |
XXX: we need to check the express version otherwise early |
|
158 |
V6 versions will not work. |
if (GetDlgCtrlID (to_hwnd) == 1028 && |
159 |
if (GetWindowLong (to_hwnd, GWL_STYLE) & ES_READONLY) |
GetClassName (to_hwnd, wclass, sizeof (wclass)-1) > 0 |
160 |
return 1; |
&& !strcmp (wclass, "RichEdit20W")) |
|
*/ |
|
|
if (GetDlgCtrlID (to_hwnd) == 1028) |
|
161 |
return 1; |
return 1; |
162 |
return 0; |
return 0; |
163 |
} |
} |
164 |
|
|
165 |
|
|
166 |
|
/* Check if the attach listview control contains at least one entry. |
167 |
|
Return the amount of attachments. */ |
168 |
|
int |
169 |
|
mail_count_attachments (plugin_ctx_t ctx) |
170 |
|
{ |
171 |
|
if (!ctx->attach) |
172 |
|
return 0; |
173 |
|
return ListView_GetItemCount (ctx->attach); |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
/* Initialize the plugin context: |
/* Initialize the plugin context: |
178 |
Find all windows the plugin need to handle messages. |
Find all windows the plugin need to handle messages. |
179 |
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 |
180 |
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! */ |
|
181 |
int |
int |
182 |
plugin_init (plugin_ctx_t ctx, HWND main, int is_inbox) |
plugin_init (plugin_ctx_t ctx, HWND main, int is_inbox) |
183 |
{ |
{ |
184 |
|
/* store original clipboard text. */ |
185 |
|
free_if_alloc (ctx->orig_text); |
186 |
|
ctx->orig_text = get_clip_text (NULL); |
187 |
|
|
188 |
ctx->sign = 0; |
ctx->sign = 0; |
189 |
ctx->encrypt = 0; |
ctx->encrypt = 0; |
190 |
|
|
191 |
ctx->main_wnd = main; |
ctx->main_wnd = main; |
192 |
ctx->addr_wnd = FindWindowEx (main, NULL, "OE_Envelope", NULL); |
ctx->addr_wnd = FindWindowEx (main, NULL, "OE_Envelope", NULL); |
193 |
ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RICHEDIT", NULL); |
ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RichEdit20W", NULL); |
194 |
if (!ctx->to_wnd) |
ctx->cc_wnd = FindWindowEx (ctx->addr_wnd, ctx->to_wnd, "RichEdit20W", NULL); |
195 |
ctx->to_wnd = FindWindowEx (ctx->addr_wnd, NULL, "RichEdit20W", NULL); |
ctx->bcc_wnd = FindWindowEx (ctx->addr_wnd, ctx->cc_wnd, "RichEdit20W", NULL); |
196 |
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); |
|
197 |
ctx->to = NULL; |
ctx->to = NULL; |
198 |
ctx->cc = NULL; |
ctx->cc = NULL; |
199 |
ctx->bcc = NULL; |
ctx->bcc = NULL; |
200 |
|
|
201 |
|
ctx->attach = FindWindowEx (ctx->addr_wnd, NULL, "SysListView32", NULL); |
202 |
|
|
203 |
if (!is_inbox && !window_is_inbox (ctx->to_wnd)) { |
if (!is_inbox && !window_is_inbox (ctx->to_wnd)) { |
204 |
ctx->to = get_address_text (ctx->main_wnd, ctx->to_wnd); |
ctx->to = get_address_text (ctx->main_wnd, ctx->to_wnd); |
205 |
ctx->cc = get_address_text (ctx->main_wnd, ctx->cc_wnd); |
ctx->cc = get_address_text (ctx->main_wnd, ctx->cc_wnd); |
210 |
} |
} |
211 |
|
|
212 |
|
|
213 |
|
/* Clear the clipboard contents. */ |
214 |
static void |
static void |
215 |
clear_clipboard (void) |
clear_clipboard (void) |
216 |
{ |
{ |
220 |
} |
} |
221 |
|
|
222 |
|
|
223 |
|
/* Restore the original clipboard data from the plugin context. */ |
224 |
|
static void |
225 |
|
restore_clipboard (plugin_ctx_t ctx) |
226 |
|
{ |
227 |
|
if (!ctx->orig_text) |
228 |
|
return; |
229 |
|
set_clip_text (NULL, ctx->orig_text, strlen (ctx->orig_text)); |
230 |
|
free_if_alloc (ctx->orig_text); |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
/* Subclass dialog procedure for the outlook message window. */ |
/* Subclass dialog procedure for the outlook message window. */ |
235 |
LRESULT CALLBACK |
LRESULT CALLBACK |
236 |
oe_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
oe_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
237 |
{ |
{ |
238 |
static initialized = 0; |
static int initialized = 0; |
239 |
static int encr_msg = 0; |
static int encr_msg = 0; |
240 |
static int sign_msg = 0; |
static int sign_msg = 0; |
241 |
int rc = 0; |
int rc = 0; |
244 |
initialized = SetTimer (hwnd, 1, 1000, NULL); |
initialized = SetTimer (hwnd, 1, 1000, NULL); |
245 |
|
|
246 |
switch (msg) { |
switch (msg) { |
247 |
case WM_CREATE: |
case WM_CREATE: |
248 |
|
if (!plugin_preload_done) { |
249 |
|
/* We need to load this lib here otherwise the richedit |
250 |
|
control would not be displayed. */ |
251 |
|
LoadLibrary ("RichEd32.Dll"); |
252 |
|
setup_gettext(); |
253 |
|
plugin_active = CreateEvent (NULL, TRUE, FALSE, NULL); |
254 |
|
plugin_preload_done = 1; |
255 |
|
} |
256 |
initialized = 0; |
initialized = 0; |
257 |
plugin_new (&oe_plug); |
plugin_new (&oe_plug); |
258 |
break; |
break; |
259 |
|
|
260 |
case WM_DESTROY: |
case WM_DESTROY: |
261 |
|
ResetEvent (plugin_active); |
262 |
plugin_release (oe_plug); |
plugin_release (oe_plug); |
263 |
|
encr_msg = sign_msg = 0; |
264 |
break; |
break; |
265 |
|
|
266 |
case WM_TIMER: |
case WM_TIMER: |
|
clear_clipboard (); |
|
267 |
KillTimer (hwnd, initialized); |
KillTimer (hwnd, initialized); |
268 |
plugin_reset (oe_plug); |
plugin_reset (oe_plug); |
269 |
plugin_init (oe_plug, hwnd, 1); |
plugin_init (oe_plug, hwnd, 1); |
270 |
if (window_is_inbox (oe_plug->to_wnd)) { |
if (window_is_inbox (oe_plug->to_wnd)) { |
271 |
|
clear_clipboard (); |
272 |
rc = oe_handle_mail (oe_plug); |
rc = oe_handle_mail (oe_plug); |
273 |
if (rc) |
if (rc) |
274 |
show_error (hwnd, _("GPG Plug-in Error"), MB_ICONERROR|MB_OK, |
show_error (hwnd, _("GPG Plug-in Error"), MB_ICONERROR|MB_OK, |
275 |
_("decrypt/verify: %s\n%s"), |
_("decrypt/verify: %s\n%s"), |
276 |
gpgme_strerror (rc), oe_plug->errbuf); |
gpgme_strerror (rc), oe_plug->errbuf); |
277 |
} |
} |
278 |
break; |
break; |
|
} |
|
279 |
|
|
280 |
switch (LOWORD (wparam)) { |
case WM_COMMAND: |
281 |
case ID_OE5_PREVMSG: |
switch (LOWORD (wparam)) { |
282 |
case ID_OE5_NEXTMSG: |
case ID_OE_PREVMSG: |
283 |
SetTimer (hwnd, 1, 1000, NULL); |
case ID_OE_NEXTMSG: |
284 |
|
SetTimer (hwnd, 1, 1000, NULL); |
285 |
|
break; |
286 |
|
|
287 |
|
case ID_OE_CP_UTF8: |
288 |
|
oe_plug->use_utf8 = 1; |
289 |
|
break; |
290 |
|
|
291 |
|
case ID_OE_CP_WEUROPE_ISO: |
292 |
|
case ID_OE_CP_WEUROPE_WINCP: |
293 |
|
case ID_OE_CP_MEUROPE_ISO: |
294 |
|
case ID_OE_CP_MEUROPE_WINCP: |
295 |
|
case ID_OE_CP_LATIN9: |
296 |
|
oe_plug->use_utf8 = 0; |
297 |
|
break; |
298 |
|
|
299 |
|
case ID_OE_ATTACH: |
300 |
|
break; |
301 |
|
|
302 |
|
case ID_OE_ENCRYPT: |
303 |
|
encr_msg ^= 1; |
304 |
|
break; |
305 |
|
|
306 |
|
case ID_OE_SIGN: |
307 |
|
sign_msg ^= 1; |
308 |
|
break; |
309 |
|
|
310 |
|
case ID_OE_SEND: |
311 |
|
if (encr_msg || sign_msg) { |
312 |
|
plugin_init (oe_plug, hwnd, 0); |
313 |
|
if (encr_msg) { |
314 |
|
SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_ENCRYPT, 0), 0); |
315 |
|
oe_plug->encrypt = 1; |
316 |
|
} |
317 |
|
if (sign_msg) { |
318 |
|
SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SIGN, 0), 0); |
319 |
|
oe_plug->sign = 1; |
320 |
|
} |
321 |
|
rc = oe_handle_mail (oe_plug); |
322 |
|
if (rc) |
323 |
|
show_plaintext_warn (hwnd, rc); |
324 |
|
restore_clipboard (oe_plug); |
325 |
|
if (mail_count_attachments (oe_plug) > 0) |
326 |
|
show_attachment_warn (hwnd); |
327 |
|
} |
328 |
|
break; |
329 |
|
} |
330 |
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; |
|
331 |
} |
} |
332 |
|
|
333 |
return CallWindowProc (oe_proc_old, hwnd, msg, wparam, lparam); |
return CallWindowProc (oe_proc_old, hwnd, msg, wparam, lparam); |