/[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 4 by twoaday, Sat Mar 25 09:02:36 2006 UTC revision 11 by twoaday, Mon Apr 3 17:10:15 2006 UTC
# 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    
32  /* Global plugin structure. */  /* Global plugin structure. */
33  static plugin_ctx_t oe_plug;  static plugin_ctx_t oe_plug;
34    
35    /* We show a warning for the attachment problem, but only once. */
36    static int attach_warn_shown = 0;
37    
38    
39    /* Display a warning that the attachments of the mail will be
40       sent in cleartext. */
41    static void
42    show_attachment_warn (HWND hwnd)
43    {
44        if (attach_warn_shown)
45            return;
46    
47        MessageBox (hwnd, _("GPGOE is unable to secure attachments.\r\n"
48                            "As a result the data attached to this mail is NOT encrypted."),
49                    _("GPG Plug-in Warning"), MB_ICONWARNING|MB_OK);
50        attach_warn_shown = 1;
51    }
52    
53    
54  /* Display a warning that the mail will be sent in clear. */  /* Display a warning that the mail will be sent in clear. */
55  static void  static void
# Line 37  show_plaintext_warn (HWND hwnd, int rc) Line 58  show_plaintext_warn (HWND hwnd, int rc)
58      const char *fmt, *s;      const char *fmt, *s;
59      char *p;      char *p;
60    
61      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"
62                "Error description: %s.");
63      s = gpgme_strerror (rc);      s = gpgme_strerror (rc);
64      p = xcalloc (1, strlen (fmt)+ strlen (s)+2);      p = xcalloc (1, strlen (fmt)+ strlen (s)+2);
65      sprintf (p, fmt, s);      sprintf (p, fmt, s);
# Line 123  window_is_inbox (HWND to_hwnd) Line 145  window_is_inbox (HWND to_hwnd)
145  }  }
146    
147    
148    /* Check if the attach listview control contains at least one entry.
149       Return 1 if the mail has attachments. */
150    int
151    mail_has_attachments (plugin_ctx_t ctx)
152    {
153        HWND attach;
154    
155        attach = FindWindowEx (ctx->addr_wnd, NULL, "SysListView32", NULL);
156        return attach && ListView_GetItemCount (attach) > 0;
157    }
158    
159    
160  /* Initialize the plugin context:  /* Initialize the plugin context:
161     Find all windows the plugin need to handle messages.     Find all windows the plugin need to handle messages.
162     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
# Line 131  window_is_inbox (HWND to_hwnd) Line 165  window_is_inbox (HWND to_hwnd)
165  int  int
166  plugin_init (plugin_ctx_t ctx, HWND main, int is_inbox)  plugin_init (plugin_ctx_t ctx, HWND main, int is_inbox)
167  {  {
168        /* store original clipboard text. */
169        free_if_alloc (ctx->orig_text);
170        ctx->orig_text = get_clip_text (NULL);
171    
172      ctx->sign = 0;      ctx->sign = 0;
173      ctx->encrypt = 0;      ctx->encrypt = 0;
174    
# Line 161  plugin_init (plugin_ctx_t ctx, HWND main Line 199  plugin_init (plugin_ctx_t ctx, HWND main
199  }  }
200    
201    
202    /* Clear the clipboard contents. */
203  static void  static void
204  clear_clipboard (void)  clear_clipboard (void)
205  {  {
# Line 170  clear_clipboard (void) Line 209  clear_clipboard (void)
209  }  }
210    
211    
212    /* Restore the clipboard data. */
213    static void
214    restore_clipboard (plugin_ctx_t ctx)
215    {
216        if (!ctx->orig_text)
217            return;
218        set_clip_text (NULL, ctx->orig_text, strlen (ctx->orig_text));
219        free_if_alloc (ctx->orig_text);
220    }
221    
222    
223  /* Subclass dialog procedure for the outlook message window. */  /* Subclass dialog procedure for the outlook message window. */
224  LRESULT CALLBACK  LRESULT CALLBACK
225  oe_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)  oe_proc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
# Line 183  oe_proc (HWND hwnd, UINT msg, WPARAM wpa Line 233  oe_proc (HWND hwnd, UINT msg, WPARAM wpa
233          initialized = SetTimer (hwnd, 1, 1000, NULL);          initialized = SetTimer (hwnd, 1, 1000, NULL);
234    
235      switch (msg) {      switch (msg) {
236      case WM_CREATE:          case WM_CREATE:
237            /* we need to load this lib here otherwise the richedit
238               control would not be displayed. */
239            LoadLibrary ("RichEd32.Dll");
240          initialized = 0;          initialized = 0;
241          plugin_new (&oe_plug);          plugin_new (&oe_plug);
242          break;          break;
243    
244      case WM_DESTROY:      case WM_DESTROY:
245          plugin_release (oe_plug);          plugin_release (oe_plug);
246            encr_msg = sign_msg = 0;
247          break;          break;
248    
249      case WM_TIMER:      case WM_TIMER:      
         clear_clipboard ();  
250          KillTimer (hwnd, initialized);          KillTimer (hwnd, initialized);
251          plugin_reset (oe_plug);          plugin_reset (oe_plug);
252          plugin_init (oe_plug, hwnd, 1);          plugin_init (oe_plug, hwnd, 1);
253          if (window_is_inbox (oe_plug->to_wnd)) {          if (window_is_inbox (oe_plug->to_wnd)) {
254                clear_clipboard ();
255              rc = oe_handle_mail (oe_plug);              rc = oe_handle_mail (oe_plug);
256              if (rc)              if (rc)
257                  show_error (hwnd, _("GPG Plug-in Error"), MB_ICONERROR|MB_OK,                  show_error (hwnd, _("GPG Plug-in Error"), MB_ICONERROR|MB_OK,
# Line 225  oe_proc (HWND hwnd, UINT msg, WPARAM wpa Line 279  oe_proc (HWND hwnd, UINT msg, WPARAM wpa
279          if (encr_msg || sign_msg) {          if (encr_msg || sign_msg) {
280              plugin_init (oe_plug, hwnd, 0);              plugin_init (oe_plug, hwnd, 0);
281              if (encr_msg) {              if (encr_msg) {
282                  SendMessage (hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_ENCRYPT, 0), 0);                  SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE5_ENCRYPT, 0), 0);
283                  oe_plug->encrypt = 1;                  oe_plug->encrypt = 1;
284              }              }
285              if (sign_msg) {              if (sign_msg) {
286                  SendMessage (hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_SIGN, 0), 0);                  SendMessage (hwnd, WM_COMMAND, MAKEWPARAM (ID_OE5_SIGN, 0), 0);
287                  oe_plug->sign = 1;                  oe_plug->sign = 1;
288              }              }
289              rc = oe_handle_mail (oe_plug);              rc = oe_handle_mail (oe_plug);
290              if (rc)              if (rc)
291                  show_plaintext_warn (hwnd, rc);                  show_plaintext_warn (hwnd, rc);
292                restore_clipboard (oe_plug);
293                if (mail_has_attachments (oe_plug))
294                    show_attachment_warn (hwnd);
295          }          }
296          break;            break;  
297      }      }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26