38 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptContext.h" /* for passphrase_s */ |
39 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
40 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
41 |
|
#include "wptUTF8.h" |
42 |
|
|
43 |
|
|
44 |
/* Encrypt the contents of the clipboard with the keys in @rset. |
/* Encrypt the contents of the clipboard with the keys in @rset. |
58 |
return err; |
return err; |
59 |
|
|
60 |
gpgme_set_armor (ctx, 1); |
gpgme_set_armor (ctx, 1); |
61 |
|
gpgme_set_textmode (ctx, 1); |
62 |
|
|
63 |
err = gpg_data_new_from_clipboard (&plain, 0); |
err = gpg_data_new_from_clipboard (&plain, 0); |
64 |
if (err) |
if (err) |
95 |
gpgme_invalid_key_t k; |
gpgme_invalid_key_t k; |
96 |
gpgme_key_t key; |
gpgme_key_t key; |
97 |
size_t len=0; |
size_t len=0; |
98 |
char *p; |
char *uid, *p; |
99 |
|
|
100 |
if (!ctx) |
if (!ctx) |
101 |
return -1; |
return -1; |
104 |
return -1; |
return -1; |
105 |
|
|
106 |
for (k=res->invalid_recipients; k; k = k->next) { |
for (k=res->invalid_recipients; k; k = k->next) { |
107 |
get_pubkey (k->fpr, &key); |
if (get_pubkey (k->fpr, &key)) |
108 |
|
continue; |
109 |
len += (32 + 16 + strlen (key->uids->name) + 2) + 4; |
len += (32 + 16 + strlen (key->uids->name) + 2) + 4; |
110 |
} |
} |
111 |
|
|
112 |
p = (char *)calloc (1, len+64); |
p = (char *)calloc (1, len+64); |
113 |
if (!p) |
if (!p) |
114 |
BUG (NULL); |
BUG (NULL); |
115 |
sprintf (p, _("Recipients unsuable for encryption:\n")); |
strcpy (p, _("Recipients unsuable for encryption:\n")); |
116 |
for (k = res->invalid_recipients; k; k = k->next) { |
for (k = res->invalid_recipients; k; k = k->next) { |
117 |
get_pubkey (k->fpr, &key); |
if (get_pubkey (k->fpr, &key)) |
118 |
|
continue; |
119 |
|
uid = utf8_to_native (key->uids->name); |
120 |
strcat (p, key->subkeys->keyid+8); |
strcat (p, key->subkeys->keyid+8); |
121 |
strcat (p, " : "); |
strcat (p, " : "); |
122 |
strcat (p, key->uids->name); |
strcat (p, uid); |
123 |
strcat (p, "\n"); |
strcat (p, "\n"); |
124 |
|
safe_free (uid); |
125 |
} |
} |
126 |
msg_box (dlg, p, _("Encryption"), MB_ERR); |
msg_box (dlg, p, _("Encryption"), MB_ERR); |
127 |
free (p); |
free (p); |
138 |
gpgme_key_t *rset; |
gpgme_key_t *rset; |
139 |
gpgme_ctx_t ctx=NULL; |
gpgme_ctx_t ctx=NULL; |
140 |
gpgme_error_t err; |
gpgme_error_t err; |
141 |
refresh_cache_s rcs = {0}; |
int force_trust = 0; |
|
int force_trust = 0, opt = 0; |
|
|
int kmode = reg_prefs.keylist_mode? KEYLIST_ENCRYPT_MIN : KEYLIST_ENCRYPT; |
|
142 |
int n; |
int n; |
143 |
|
|
144 |
switch( msg ) { |
switch (msg) { |
145 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
146 |
SetWindowText( dlg, _("Encryption") ); |
SetWindowText (dlg, _("Encryption")); |
147 |
kc = keycache_get_ctx( KEYCACHE_PUB ); |
SetDlgItemText (dlg, IDC_ENCRYPT_FNDCMD, _("&Find")); |
148 |
if( !kc ) |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
149 |
BUG( NULL ); |
kc = keycache_get_ctx (KEYCACHE_PUB); |
150 |
lv = keylist_load (GetDlgItem( dlg, IDC_ENCRYPT_KEYLIST ), kc, NULL, |
if (!kc) |
151 |
kmode, KEY_SORT_USERID); |
BUG (NULL); |
152 |
center_window( dlg, NULL ); |
lv = keylist_load (GetDlgItem (dlg, IDC_ENCRYPT_KEYLIST), kc, NULL, |
153 |
SetForegroundWindow( dlg ); |
KEYLIST_ENCRYPT_MIN, KEY_SORT_USERID); |
154 |
set_active_window( dlg ); |
center_window (dlg, NULL); |
155 |
|
SetForegroundWindow (dlg); |
156 |
return TRUE; |
return TRUE; |
157 |
|
|
158 |
case WM_DESTROY: |
case WM_DESTROY: |
|
reset_active_window( ); |
|
159 |
if( lv ) { |
if( lv ) { |
160 |
keylist_delete( lv ); |
keylist_delete( lv ); |
161 |
lv = NULL; |
lv = NULL; |
168 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
169 |
if (notify && notify->code == NM_DBLCLK && |
if (notify && notify->code == NM_DBLCLK && |
170 |
notify->idFrom == IDC_ENCRYPT_KEYLIST) |
notify->idFrom == IDC_ENCRYPT_KEYLIST) |
171 |
PostMessage( dlg, WM_COMMAND, MAKEWPARAM( IDOK, 0 ), 0); |
PostMessage( dlg, WM_COMMAND, MAKEWPARAM( IDOK, 0 ), 0 ); |
172 |
if (notify && notify->code == LVN_COLUMNCLICK && |
if (notify && notify->code == LVN_COLUMNCLICK && |
173 |
notify->idFrom == IDC_ENCRYPT_KEYLIST ) { |
notify->idFrom == IDC_ENCRYPT_KEYLIST ) { |
174 |
NMLISTVIEW *p = (LPNMLISTVIEW) lparam; |
NMLISTVIEW *p = (LPNMLISTVIEW) lparam; |
195 |
case IDOK: |
case IDOK: |
196 |
rset = keylist_get_recipients (lv, &force_trust, &n); |
rset = keylist_get_recipients (lv, &force_trust, &n); |
197 |
if (!n) { |
if (!n) { |
198 |
msg_box (dlg, _("You must select at least one key."), _("Encryption"), MB_ERR); |
msg_box (dlg, _("You must select at least one key."), |
199 |
free (rset); |
_("Encryption"), MB_ERR); |
200 |
|
safe_free (rset); |
201 |
return FALSE; |
return FALSE; |
202 |
} |
} |
203 |
err = gpg_clip_encrypt (rset, force_trust, &ctx); |
err = gpg_clip_encrypt (rset, force_trust, &ctx); |
206 |
msg_box (dlg, gpgme_strerror (err), _("Encryption"), MB_ERR); |
msg_box (dlg, gpgme_strerror (err), _("Encryption"), MB_ERR); |
207 |
if (ctx) |
if (ctx) |
208 |
gpgme_release (ctx); |
gpgme_release (ctx); |
209 |
free (rset); |
safe_free (rset); |
210 |
return FALSE; |
return FALSE; |
211 |
} |
} |
212 |
else |
else |
223 |
case IDC_ENCRYPT_FNDCMD: |
case IDC_ENCRYPT_FNDCMD: |
224 |
{ |
{ |
225 |
char tmpbuf[64]; |
char tmpbuf[64]; |
|
int n; |
|
226 |
|
|
227 |
n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1); |
n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1); |
228 |
if (!n) |
if (!n) |