23 |
#endif |
#endif |
24 |
#include <windows.h> |
#include <windows.h> |
25 |
#include <assert.h> |
#include <assert.h> |
26 |
|
#include <commctrl.h> |
27 |
|
|
28 |
#include "resource.h" |
#include "resource.h" |
29 |
#include "gpgme.h" |
#include "gpgme.h" |
30 |
#include "GPGOE.h" |
#include "GPGOE.h" |
32 |
|
|
33 |
/* Valid OpenPGP message types. */ |
/* Valid OpenPGP message types. */ |
34 |
enum { |
enum { |
35 |
PGP_MESSAGE = 1, |
PGP_MESSAGE = 1, |
36 |
PGP_CLEARSIG = 2, |
PGP_CLEARSIG = 2, |
37 |
PGP_SIG = 4, |
PGP_SIG = 4, |
38 |
PGP_KEY = 8, |
PGP_KEY = 8, |
39 |
}; |
}; |
40 |
|
|
41 |
|
|
71 |
{ |
{ |
72 |
set_focus (main_hwnd); |
set_focus (main_hwnd); |
73 |
SetForegroundWindow (main_hwnd); |
SetForegroundWindow (main_hwnd); |
74 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_SELECTALL, 0), 0); |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
75 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM(ID_OE5_COPY, 0), 0); |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_COPY, 0), 0); |
76 |
|
|
77 |
/* even so SendMessage() should wait, we wait for safety reasons. */ |
/* even so SendMessage() should wait, we wait for safety reasons. */ |
78 |
Sleep (200); |
Sleep (200); |
89 |
set_clip_text (NULL, msg, strlen (msg)); |
set_clip_text (NULL, msg, strlen (msg)); |
90 |
set_focus (main_hwnd); |
set_focus (main_hwnd); |
91 |
SetForegroundWindow (main_hwnd); |
SetForegroundWindow (main_hwnd); |
92 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE5_SELECTALL, 0), 0); |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_SELECTALL, 0), 0); |
93 |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE5_PASTE, 0), 0); |
SendMessage (main_hwnd, WM_COMMAND, MAKEWPARAM (ID_OE_PASTE, 0), 0); |
94 |
} |
} |
95 |
|
|
96 |
|
|
233 |
} |
} |
234 |
|
|
235 |
|
|
236 |
|
/* Create gpgme input data object. If @encode is 1, use UTF8 conversion. */ |
237 |
|
gpgme_error_t |
238 |
|
create_in_data (gpgme_data_t *in, const char *buf, int encode) |
239 |
|
{ |
240 |
|
gpgme_error_t err; |
241 |
|
char *enc_buf; |
242 |
|
|
243 |
|
enc_buf = encode? native_to_utf8 (buf) : xstrdup (buf); |
244 |
|
err = gpgme_data_new_from_mem (in, enc_buf, strlen (enc_buf), 1); |
245 |
|
free (enc_buf); |
246 |
|
return err; |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
/* Map gpgme data object to a string. */ |
/* Map gpgme data object to a string. */ |
251 |
void |
void |
252 |
map_gpgme_data (gpgme_data_t out, char **r_msg) |
map_gpgme_data (gpgme_data_t out, char **r_msg) |
325 |
|
|
326 |
err = gpgme_new (&gctx); |
err = gpgme_new (&gctx); |
327 |
if (!err) |
if (!err) |
328 |
err = gpgme_data_new_from_mem (&in, msg, strlen (msg), 1); |
err = create_in_data (&in, msg, ctx->use_utf8); |
329 |
if (!err) |
if (!err) |
330 |
err = gpgme_data_new (&out); |
err = gpgme_data_new (&out); |
331 |
if (!err) { |
if (!err) { |
402 |
|
|
403 |
err = gpgme_new (&gctx); |
err = gpgme_new (&gctx); |
404 |
if (!err) |
if (!err) |
405 |
err = gpgme_data_new_from_mem (&in, *r_msg, strlen (*r_msg), 1); |
err = create_in_data (&in, *r_msg, ctx->use_utf8); |
406 |
if (!err) |
if (!err) |
407 |
err = gpgme_data_new (&out); |
err = gpgme_data_new (&out); |
408 |
if (!err) { |
if (!err) { |
481 |
algo = res->recipients->pubkey_algo; |
algo = res->recipients->pubkey_algo; |
482 |
if (!key) |
if (!key) |
483 |
_snprintf (buf, buflen, _("encrypted with %s key, ID %s\n" |
_snprintf (buf, buflen, _("encrypted with %s key, ID %s\n" |
484 |
"decryption failed: secret keyn not available"), |
"decryption failed: secret key not available"), |
485 |
algo == 1? "RSA" : algo==16? "ELG": "???", |
algo == 1? "RSA" : algo==16? "ELG": "???", |
486 |
res->recipients->keyid+8); |
res->recipients->keyid+8); |
487 |
else { |
else { |
488 |
char *uid = utf8_to_native (key->uids->uid); |
char *uid = utf8_to_native (key->uids->uid); |
489 |
_snprintf (buf, buflen, _("encrypted with %d-bit %s key, ID %s\n" |
_snprintf (buf, buflen, _("encrypted with %d-bit %s key, ID %s\n" |
490 |
"\t\"%s\"\n" |
"\t\"%s\"\n" |
491 |
"decryption failed: secret keyn not available"), |
"decryption failed: secret key not available"), |
492 |
key->subkeys->length, |
key->subkeys->length, |
493 |
algo == 1? "RSA" : algo==16? "ELG": "???", |
algo == 1? "RSA" : algo==16? "ELG": "???", |
494 |
key->subkeys->keyid+8, uid); |
key->subkeys->keyid+8, uid); |
565 |
} |
} |
566 |
|
|
567 |
|
|
568 |
|
static int |
569 |
|
winpt_key_import (void) |
570 |
|
{ |
571 |
|
HWND winpt; |
572 |
|
|
573 |
|
winpt = FindWindow ("WinPT", "WinPT"); |
574 |
|
if (winpt != NULL) { |
575 |
|
PostMessage (winpt, WM_COMMAND, 40014, 0); |
576 |
|
return 0; |
577 |
|
} |
578 |
|
return -1; |
579 |
|
} |
580 |
|
|
581 |
|
|
582 |
|
/* Try to decrypt a PGP/MIME message. */ |
583 |
|
static gpgme_error_t |
584 |
|
oe_handle_pgp_mime_mail (plugin_ctx_t ctx) |
585 |
|
{ |
586 |
|
SetEvent (plugin_active); |
587 |
|
|
588 |
|
/* Select attachment number 0. */ |
589 |
|
AttachThreadInput (GetCurrentThreadId (), |
590 |
|
GetWindowThreadProcessId (ctx->main_wnd, NULL), |
591 |
|
TRUE); |
592 |
|
|
593 |
|
SetFocus (ctx->addr_wnd); |
594 |
|
SetFocus (ctx->attach); |
595 |
|
ListView_SetItemState (ctx->attach, 0, LVIS_SELECTED|LVIS_FOCUSED, |
596 |
|
LVIS_FOCUSED|LVIS_SELECTED); |
597 |
|
|
598 |
|
AttachThreadInput (GetCurrentThreadId (), |
599 |
|
GetWindowThreadProcessId (ctx->main_wnd, NULL), |
600 |
|
FALSE); |
601 |
|
|
602 |
|
SendMessage (ctx->addr_wnd, WM_COMMAND, ID_OE_SAVE_ATT, 0); |
603 |
|
|
604 |
|
ResetEvent (plugin_active); |
605 |
|
|
606 |
|
return 0; |
607 |
|
} |
608 |
|
|
609 |
|
|
610 |
/* This function can be use for all kind of OE messages. |
/* This function can be use for all kind of OE messages. |
611 |
It automatically choose the right procedure to handle the data. */ |
It automatically choose the right procedure to handle the data. */ |
612 |
gpgme_error_t |
gpgme_error_t |
619 |
assert (ctx); |
assert (ctx); |
620 |
|
|
621 |
msg = window_get_message (ctx->main_wnd); |
msg = window_get_message (ctx->main_wnd); |
622 |
|
#if 0 |
623 |
|
if ((!msg || strlen (msg)) < 2 && |
624 |
|
ctx->attach && ListView_GetItemCount (ctx->attach) == 2) { |
625 |
|
free_if_alloc (msg); |
626 |
|
return oe_handle_pgp_mime_mail (ctx); |
627 |
|
} |
628 |
|
#endif |
629 |
if (!msg || strlen (msg) == 2) { |
if (!msg || strlen (msg) == 2) { |
630 |
free_if_alloc (msg); |
free_if_alloc (msg); |
631 |
return 0; |
return 0; |
636 |
msg_type = parse_pgp_id (msg); |
msg_type = parse_pgp_id (msg); |
637 |
|
|
638 |
if (msg_type & PGP_KEY) { |
if (msg_type & PGP_KEY) { |
639 |
MessageBox (ctx->main_wnd, |
if (winpt_key_import ()) |
640 |
|
MessageBox (ctx->main_wnd, |
641 |
_("This mail contains one or more public or secret keys.\n\n" |
_("This mail contains one or more public or secret keys.\n\n" |
642 |
"Please save the mail text in a file to use WinPT to import them."), |
"Please save the mail text in a file to use WinPT to import them."), |
643 |
_("GPG Plug-in Info"), MB_ICONINFORMATION|MB_OK); |
_("GPG Plug-in Info"), MB_ICONINFORMATION|MB_OK); |