1 |
/* OEMainProc.c - window procedure for the main window |
2 |
* Copyright (C) 2006 Timo Schulz |
3 |
* |
4 |
* This file is part of GPGOE. |
5 |
* |
6 |
* GPGOE is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU Lesser General Public License as published by |
8 |
* the Free Software Foundation; either version 2.1 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* GPGOE is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
*/ |
16 |
|
17 |
#include <windows.h> |
18 |
#include <stdio.h> |
19 |
|
20 |
#include "gpgme.h" |
21 |
#include "GPGOE.h" |
22 |
|
23 |
|
24 |
/* Outlook symbolic command IDs. */ |
25 |
#define ID_OE_REPLY 40176 |
26 |
#define ID_OE_REPLY_ALL 40177 |
27 |
|
28 |
/* Original window procedure of the main window. */ |
29 |
WNDPROC oe_main_proc_old; |
30 |
|
31 |
|
32 |
/* Move the keyboard focus to the message window |
33 |
to copy the text to the clipboard. */ |
34 |
static HWND |
35 |
set_focus (int is_main_wnd) |
36 |
{ |
37 |
HWND brows, msgv, doc, mime, msg; |
38 |
|
39 |
if (is_main_wnd) { |
40 |
brows = FindWindowEx (NULL, NULL, "Outlook Express Browser Class", NULL); |
41 |
msgv = FindWindowEx (brows, NULL, "Outlook Express Message View", NULL); |
42 |
} |
43 |
else { |
44 |
msgv = FindWindowEx (NULL, NULL, "ATH_Note", NULL); |
45 |
brows = msgv; |
46 |
} |
47 |
doc = FindWindowEx (msgv, NULL, "ME_DocHost", NULL ); |
48 |
mime = FindWindowEx (doc, NULL, "##MimeEdit_Server", NULL); |
49 |
msg = FindWindowEx (mime, NULL, "Internet Explorer_Server", NULL); |
50 |
|
51 |
SetForegroundWindow (brows); |
52 |
|
53 |
AttachThreadInput (GetCurrentThreadId (), |
54 |
GetWindowThreadProcessId (brows, NULL), |
55 |
TRUE); |
56 |
|
57 |
SetFocus (brows); |
58 |
SetFocus (msg); |
59 |
SetFocus (doc); |
60 |
SetFocus (mime); |
61 |
SetFocus (msg); |
62 |
|
63 |
AttachThreadInput (GetCurrentThreadId (), |
64 |
GetWindowThreadProcessId (brows, NULL), |
65 |
FALSE); |
66 |
|
67 |
return brows; |
68 |
} |
69 |
|
70 |
|
71 |
/* Copy body of the current message to the clipboard and then return |
72 |
the clipboard data (which is the message). */ |
73 |
static char* |
74 |
get_current_message (void) |
75 |
{ |
76 |
HWND main_hwnd; |
77 |
|
78 |
main_hwnd = set_focus (1); |
79 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
80 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_COPY, 0), 0); |
81 |
|
82 |
/* even so SendMessage() should wait, we wait for safety reasons. */ |
83 |
Sleep (200); |
84 |
return get_clip_text (NULL); |
85 |
} |
86 |
|
87 |
|
88 |
/* Paste the quoted message text @body into the reply message window. */ |
89 |
static void |
90 |
paste_quoted_text (const char *body) |
91 |
{ |
92 |
HWND msg_hwnd; |
93 |
|
94 |
set_clip_text (NULL, body, strlen (body)); |
95 |
msg_hwnd = set_focus (0); |
96 |
SetForegroundWindow (msg_hwnd); |
97 |
SendMessage (msg_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
98 |
SendMessage (msg_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_PASTE, 0), 0); |
99 |
} |
100 |
|
101 |
|
102 |
/* Subclass dialog procedure for the outlook main window. */ |
103 |
LRESULT CALLBACK |
104 |
oe_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
105 |
{ |
106 |
static int timer = 0; |
107 |
static char *body = NULL; |
108 |
char *tmp; |
109 |
|
110 |
switch (msg) { |
111 |
case WM_DESTROY: |
112 |
/*free_pass_cache ();*/ |
113 |
break; |
114 |
|
115 |
case WM_COMMAND: |
116 |
switch (LOWORD (wparam)) { |
117 |
case ID_OE_REPLY: |
118 |
case ID_OE_REPLY_ALL: |
119 |
tmp = get_current_message (); |
120 |
if (!tmp || !strstr (tmp, "BEGIN PGP MESSAGE")) { |
121 |
xfree (tmp); |
122 |
break; |
123 |
} |
124 |
if (oe_decrypt_msg (hwnd, &tmp)) { |
125 |
xfree (tmp); |
126 |
break; |
127 |
} |
128 |
quote_msg_text (tmp, &body); |
129 |
xfree (tmp); |
130 |
timer = SetTimer (hwnd, 1, 1000, NULL); |
131 |
break; |
132 |
} |
133 |
break; |
134 |
|
135 |
case WM_TIMER: |
136 |
KillTimer (hwnd, timer); |
137 |
paste_quoted_text (body); |
138 |
xfree (body); body = NULL; |
139 |
break; |
140 |
} |
141 |
|
142 |
return CallWindowProc (oe_main_proc_old, hwnd, msg, wparam, lparam); |
143 |
} |