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 |
* You should have received a copy of the GNU Lesser General Public License |
17 |
* along with GPGOE; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
20 |
|
21 |
#include <windows.h> |
22 |
#include <stdio.h> |
23 |
|
24 |
#include "gpgme.h" |
25 |
#include "GPGOE.h" |
26 |
|
27 |
|
28 |
/* Outlook symbolic command IDs. */ |
29 |
#define ID_OE_REPLY 40176 |
30 |
#define ID_OE_REPLY_ALL 40177 |
31 |
|
32 |
/* Original window procedure of the main window. */ |
33 |
WNDPROC oe_main_proc_old; |
34 |
|
35 |
|
36 |
/* Move the keyboard focus to the message window |
37 |
to copy the text to the clipboard. */ |
38 |
static HWND |
39 |
set_focus (int is_main_wnd) |
40 |
{ |
41 |
HWND brows, msgv, doc, mime, msg; |
42 |
|
43 |
if (is_main_wnd) { |
44 |
brows = FindWindowEx (NULL, NULL, "Outlook Express Browser Class", NULL); |
45 |
msgv = FindWindowEx (brows, NULL, "Outlook Express Message View", NULL); |
46 |
} |
47 |
else { |
48 |
msgv = FindWindowEx (NULL, NULL, "ATH_Note", NULL); |
49 |
brows = msgv; |
50 |
} |
51 |
doc = FindWindowEx (msgv, NULL, "ME_DocHost", NULL ); |
52 |
mime = FindWindowEx (doc, NULL, "##MimeEdit_Server", NULL); |
53 |
msg = FindWindowEx (mime, NULL, "Internet Explorer_Server", NULL); |
54 |
|
55 |
SetForegroundWindow (brows); |
56 |
|
57 |
AttachThreadInput (GetCurrentThreadId (), |
58 |
GetWindowThreadProcessId (brows, NULL), |
59 |
TRUE); |
60 |
|
61 |
SetFocus (brows); |
62 |
SetFocus (msg); |
63 |
SetFocus (doc); |
64 |
SetFocus (mime); |
65 |
SetFocus (msg); |
66 |
|
67 |
AttachThreadInput (GetCurrentThreadId (), |
68 |
GetWindowThreadProcessId (brows, NULL), |
69 |
FALSE); |
70 |
|
71 |
return brows; |
72 |
} |
73 |
|
74 |
|
75 |
/* Copy body of the current message to the clipboard and then return |
76 |
the clipboard data (which is the message). */ |
77 |
static char* |
78 |
get_current_message (void) |
79 |
{ |
80 |
HWND main_hwnd; |
81 |
|
82 |
main_hwnd = set_focus (1); |
83 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
84 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_COPY, 0), 0); |
85 |
|
86 |
/* even so SendMessage() should wait, we wait for safety reasons. */ |
87 |
Sleep (200); |
88 |
return get_clip_text (NULL); |
89 |
} |
90 |
|
91 |
|
92 |
/* Paste the quoted message text @body into the reply message window. */ |
93 |
static void |
94 |
paste_quoted_text (const char *body) |
95 |
{ |
96 |
HWND msg_hwnd; |
97 |
|
98 |
set_clip_text (NULL, body, strlen (body)); |
99 |
msg_hwnd = set_focus (0); |
100 |
SetForegroundWindow (msg_hwnd); |
101 |
SendMessage (msg_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
102 |
SendMessage (msg_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_PASTE, 0), 0); |
103 |
} |
104 |
|
105 |
|
106 |
/* Subclass dialog procedure for the outlook main window. */ |
107 |
LRESULT CALLBACK |
108 |
oe_main_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) |
109 |
{ |
110 |
static int timer = 0; |
111 |
static char *body = NULL; |
112 |
char *tmp; |
113 |
|
114 |
switch (msg) { |
115 |
case WM_DESTROY: |
116 |
/*free_pass_cache ();*/ |
117 |
break; |
118 |
|
119 |
case WM_COMMAND: |
120 |
switch (LOWORD (wparam)) { |
121 |
case ID_OE_REPLY: |
122 |
case ID_OE_REPLY_ALL: |
123 |
tmp = get_current_message (); |
124 |
if (!tmp || !strstr (tmp, "BEGIN PGP MESSAGE")) { |
125 |
xfree (tmp); |
126 |
break; |
127 |
} |
128 |
if (oe_decrypt_msg (hwnd, &tmp)) { |
129 |
xfree (tmp); |
130 |
break; |
131 |
} |
132 |
quote_msg_text (tmp, &body); |
133 |
xfree (tmp); |
134 |
timer = SetTimer (hwnd, 1, 1000, NULL); |
135 |
break; |
136 |
} |
137 |
break; |
138 |
|
139 |
case WM_TIMER: |
140 |
KillTimer (hwnd, timer); |
141 |
paste_quoted_text (body); |
142 |
xfree (body); body = NULL; |
143 |
break; |
144 |
} |
145 |
|
146 |
return CallWindowProc (oe_main_proc_old, hwnd, msg, wparam, lparam); |
147 |
} |