/[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 11 by twoaday, Mon Apr 3 17:10:15 2006 UTC revision 12 by twoaday, Fri Apr 7 10:46:41 2006 UTC
# Line 28  Line 28 
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    
38    /* Outlook select charset IDs. */
39    #define ID_OE_CP_UTF8           42540
40    #define ID_OE_CP_WEUROPE_ISO    42544
41    #define ID_OE_CP_WEUROPE_WINCP  42545
42    #define ID_OE_CP_MEUROPE_ISO    42525
43    #define ID_OE_CP_MEUROPE_WINCP  42526
44    #define ID_OE_CP_LATIN9         42535
45    
46  /* Global plugin structure. */  /* Global plugin structure. */
47  static plugin_ctx_t oe_plug;  static plugin_ctx_t oe_plug;
# Line 35  static plugin_ctx_t oe_plug; Line 49  static plugin_ctx_t oe_plug;
49  /* We show a warning for the attachment problem, but only once. */  /* We show a warning for the attachment problem, but only once. */
50  static int attach_warn_shown = 0;  static int attach_warn_shown = 0;
51    
52    /* One time initialisation finished?. */
53    static int plugin_preload_done = 0;
54    
55    /* Event to indicate if the plugin is active or not. */
56    HANDLE plugin_active = NULL;
57    
58    
59    /* Return the Outlook main window handle. */
60    HWND
61    outlook_get_main_window (void)
62    {
63        if (!oe_plug)
64            return GetActiveWindow ();
65        return oe_plug->main_wnd;
66    }
67    
68    
69  /* Display a warning that the attachments of the mail will be  /* Display a warning that the attachments of the mail will be
70     sent in cleartext. */     sent in cleartext. */
# Line 68  show_plaintext_warn (HWND hwnd, int rc) Line 98  show_plaintext_warn (HWND hwnd, int rc)
98  }  }
99    
100    
101  /* Reset the plugin. */  /* Reset the plugin state. */
102  static void  static void
103  plugin_reset (plugin_ctx_t ctx)  plugin_reset (plugin_ctx_t ctx)
104  {  {
# Line 82  plugin_reset (plugin_ctx_t ctx) Line 112  plugin_reset (plugin_ctx_t ctx)
112  }  }
113    
114    
115    /* Release plugin context. */
116  static void  static void
117  plugin_release (plugin_ctx_t ctx)  plugin_release (plugin_ctx_t ctx)
118  {  {
# Line 92  plugin_release (plugin_ctx_t ctx) Line 123  plugin_release (plugin_ctx_t ctx)
123  }  }
124    
125    
126    /* Create new plugin context. */
127  static int  static int
128  plugin_new (plugin_ctx_t *r_ctx)  plugin_new (plugin_ctx_t *r_ctx)
129  {      {    
# Line 119  get_address_text (HWND main, HWND edit) Line 151  get_address_text (HWND main, HWND edit)
151                        GetWindowThreadProcessId (main, NULL),                        GetWindowThreadProcessId (main, NULL),
152                        FALSE);                        FALSE);
153    
154      SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE5_SELECTALL, 0), 0);      SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0);
155      SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE5_COPY, 0), 0);      SendMessage (main, WM_COMMAND, MAKEWPARAM (ID_OE_COPY, 0), 0);
156            
157      Sleep (200);      Sleep (200);
158    
# Line 146  window_is_inbox (HWND to_hwnd) Line 178  window_is_inbox (HWND to_hwnd)
178    
179    
180  /* Check if the attach listview control contains at least one entry.  /* Check if the attach listview control contains at least one entry.
181     Return 1 if the mail has attachments. */     Return the amount of attachments. */
182  int  int
183  mail_has_attachments (plugin_ctx_t ctx)  mail_count_attachments (plugin_ctx_t ctx)
184  {  {
185      HWND attach;      if (!ctx->attach)
186            return 0;
187      attach = FindWindowEx (ctx->addr_wnd, NULL, "SysListView32", NULL);      return ListView_GetItemCount (ctx->attach);
     return attach && ListView_GetItemCount (attach) > 0;  
188  }  }
189    
190    
# Line 189  plugin_init (plugin_ctx_t ctx, HWND main Line 220  plugin_init (plugin_ctx_t ctx, HWND main
220      ctx->cc = NULL;      ctx->cc = NULL;
221      ctx->bcc = NULL;      ctx->bcc = NULL;
222    
223        ctx->attach = FindWindowEx (ctx->addr_wnd, NULL, "SysListView32", NULL);
224    
225      if (!is_inbox && !window_is_inbox (ctx->to_wnd)) {      if (!is_inbox && !window_is_inbox (ctx->to_wnd)) {
226          ctx->to = get_address_text (ctx->main_wnd, ctx->to_wnd);          ctx->to = get_address_text (ctx->main_wnd, ctx->to_wnd);
227          ctx->cc = get_address_text (ctx->main_wnd, ctx->cc_wnd);          ctx->cc = get_address_text (ctx->main_wnd, ctx->cc_wnd);
# Line 209  clear_clipboard (void) Line 242  clear_clipboard (void)
242  }  }
243    
244    
245  /* Restore the clipboard data. */  /* Restore the original clipboard data from the plugin context. */
246  static void  static void
247  restore_clipboard (plugin_ctx_t ctx)  restore_clipboard (plugin_ctx_t ctx)
248  {  {
# Line 234  oe_proc (HWND hwnd, UINT msg, WPARAM wpa Line 267  oe_proc (HWND hwnd, UINT msg, WPARAM wpa
267    
268      switch (msg) {      switch (msg) {
269      case WM_CREATE:      case WM_CREATE:
270          /* we need to load this lib here otherwise the richedit          if (!plugin_preload_done) {
271             control would not be displayed. */              /* we need to load this lib here otherwise the richedit
272          LoadLibrary ("RichEd32.Dll");                 control would not be displayed. */
273                LoadLibrary ("RichEd32.Dll");
274                setup_gettext();
275                plugin_active = CreateEvent (NULL, TRUE, /*TRUE*/FALSE, NULL);
276                plugin_preload_done = 1;
277            }
278            /*
279            else
280                SetEvent (plugin_active);
281            */
282          initialized = 0;          initialized = 0;
283          plugin_new (&oe_plug);          plugin_new (&oe_plug);
284          break;          break;
285    
286      case WM_DESTROY:      case WM_DESTROY:
287            ResetEvent (plugin_active);
288          plugin_release (oe_plug);          plugin_release (oe_plug);
289          encr_msg = sign_msg = 0;          encr_msg = sign_msg = 0;
290          break;          break;
# Line 258  oe_proc (HWND hwnd, UINT msg, WPARAM wpa Line 301  oe_proc (HWND hwnd, UINT msg, WPARAM wpa
301                              _("decrypt/verify: %s\n%s"),                              _("decrypt/verify: %s\n%s"),
302                              gpgme_strerror (rc), oe_plug->errbuf);                              gpgme_strerror (rc), oe_plug->errbuf);
303          }          }
304          break;          break;  
     }  
305    
306      switch (LOWORD (wparam)) {      case WM_COMMAND:
307      case ID_OE5_PREVMSG:          switch (LOWORD (wparam)) {
308      case ID_OE5_NEXTMSG:          case ID_OE_PREVMSG:
309          SetTimer (hwnd, 1, 1000, NULL);          case ID_OE_NEXTMSG:
310                SetTimer (hwnd, 1, 1000, NULL);
311                break;
312    
313            case ID_OE_CP_UTF8:
314                oe_plug->use_utf8 = 1;
315                break;
316    
317            case ID_OE_CP_WEUROPE_ISO:
318            case ID_OE_CP_WEUROPE_WINCP:
319            case ID_OE_CP_MEUROPE_ISO:
320            case ID_OE_CP_MEUROPE_WINCP:
321            case ID_OE_CP_LATIN9:
322                oe_plug->use_utf8 = 0;
323                break;
324    
325            case ID_OE_ENCRYPT:
326                encr_msg ^= 1;
327                break;
328    
329            case ID_OE_SIGN:
330                sign_msg ^= 1;
331                break;
332    
333            case ID_OE_SEND:
334                if (encr_msg || sign_msg) {
335                    plugin_init (oe_plug, hwnd, 0);
336                    if (encr_msg) {
337                        SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_ENCRYPT, 0), 0);
338                        oe_plug->encrypt = 1;
339                    }
340                    if (sign_msg) {
341                        SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SIGN, 0), 0);
342                        oe_plug->sign = 1;
343                    }
344                    rc = oe_handle_mail (oe_plug);
345                    if (rc)
346                        show_plaintext_warn (hwnd, rc);
347                    restore_clipboard (oe_plug);
348                    if (mail_count_attachments (oe_plug) > 0)
349                        show_attachment_warn (hwnd);
350                }
351                break;
352            }
353          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);  
             restore_clipboard (oe_plug);  
             if (mail_has_attachments (oe_plug))  
                 show_attachment_warn (hwnd);  
         }  
         break;    
354      }      }
355    
356      return CallWindowProc (oe_proc_old, hwnd, msg, wparam, lparam);      return CallWindowProc (oe_proc_old, hwnd, msg, wparam, lparam);

Legend:
Removed from v.11  
changed lines
  Added in v.12

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26