/[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 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 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    #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. */  /* We show a warning for the attachment problem, but only once. */
51  static int attach_warn_shown = 0;  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  /* Display a warning that the attachments of the mail will be
62     sent in cleartext. */     sent in cleartext. */
# Line 68  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 82  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 92  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 119  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 128  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.  /* Check if the attach listview control contains at least one entry.
170     Return 1 if the mail has attachments. */     Return the amount of attachments. */
171  int  int
172  mail_has_attachments (plugin_ctx_t ctx)  mail_count_attachments (plugin_ctx_t ctx)
173  {  {
174      HWND attach;      if (!ctx->attach)
175            return 0;
176      attach = FindWindowEx (ctx->addr_wnd, NULL, "SysListView32", NULL);      return ListView_GetItemCount (ctx->attach);
     return attach && ListView_GetItemCount (attach) > 0;  
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  {  {
# Line 174  plugin_init (plugin_ctx_t ctx, HWND main Line 193  plugin_init (plugin_ctx_t ctx, HWND main
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 209  clear_clipboard (void) Line 223  clear_clipboard (void)
223  }  }
224    
225    
226  /* Restore the clipboard data. */  /* Restore the original clipboard data from the plugin context. */
227  static void  static void
228  restore_clipboard (plugin_ctx_t ctx)  restore_clipboard (plugin_ctx_t ctx)
229  {  {
# Line 234  oe_proc (HWND hwnd, UINT msg, WPARAM wpa Line 248  oe_proc (HWND hwnd, UINT msg, WPARAM wpa
248    
249      switch (msg) {      switch (msg) {
250      case WM_CREATE:      case WM_CREATE:
251          /* we need to load this lib here otherwise the richedit          if (!plugin_preload_done) {
252             control would not be displayed. */              /* we need to load this lib here otherwise the richedit
253          LoadLibrary ("RichEd32.Dll");                 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;          encr_msg = sign_msg = 0;
267          break;          break;
# Line 258  oe_proc (HWND hwnd, UINT msg, WPARAM wpa Line 278  oe_proc (HWND hwnd, UINT msg, WPARAM wpa
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);  
             restore_clipboard (oe_plug);  
             if (mail_has_attachments (oe_plug))  
                 show_attachment_warn (hwnd);  
         }  
         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.11  
changed lines
  Added in v.16

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26