/[gpgoe]/trunk/src/OEProc.c
ViewVC logotype

Diff of /trunk/src/OEProc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1  
changed lines
  Added in v.16

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26