17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
|
|
|
20 |
#include <windows.h> |
#include <windows.h> |
21 |
#include <stdio.h> |
#include <stdio.h> |
22 |
#include <mapi.h> |
#include <mapi.h> |
72 |
} |
} |
73 |
} /* mapi_deinit */ |
} /* mapi_deinit */ |
74 |
|
|
75 |
|
#if 0 /* low:priority XXX port the code */ |
76 |
int |
int |
77 |
mapi_send_ascfile (char * ascfile) |
mapi_send_ascfile (char *ascfile) |
78 |
{ |
{ |
79 |
LHANDLE hd; |
LHANDLE hd; |
80 |
int rc; |
int rc; |
100 |
|
|
101 |
|
|
102 |
int |
int |
103 |
mapi_send_pubkey (const char * keyid, char * keyfile) |
mapi_send_pubkey (const char *keyid, char *keyfile) |
104 |
{ |
{ |
105 |
LHANDLE hd; |
LHANDLE hd; |
106 |
const char * fmt; |
const char * fmt; |
145 |
|
|
146 |
|
|
147 |
static void |
static void |
148 |
free_recip_tab (MapiRecipDesc * recip, size_t n) |
free_recip_tab (MapiRecipDesc *recip, size_t n) |
149 |
{ |
{ |
150 |
size_t i; |
size_t i; |
151 |
|
|
197 |
if (!(p = strchr (s, '<')) || !(q = strchr (s, '>'))) |
if (!(p = strchr (s, '<')) || !(q = strchr (s, '>'))) |
198 |
continue; |
continue; |
199 |
buf = (char * )calloc (1, (q-s)-(p-s)+2); |
buf = (char * )calloc (1, (q-s)-(p-s)+2); |
200 |
|
if (!buf) |
201 |
|
BUG (0); |
202 |
strncpy (buf, s+(p-s)+1, (q-s)-(p-s)-1); |
strncpy (buf, s+(p-s)+1, (q-s)-(p-s)-1); |
203 |
gpgme_recipients_add_name (r, buf); |
gpgme_recipients_add_name (r, buf); |
204 |
safe_free (buf); |
safe_free (buf); |
208 |
|
|
209 |
|
|
210 |
static char * |
static char * |
211 |
secure_attachment (gpgme_recipients_t rset, const char * fname) |
secure_attachment (gpgme_recipients_t rset, const char *fname) |
212 |
{ |
{ |
213 |
char tmpdir[512+32], * p; |
char tmpdir[512+32], * p; |
214 |
gpgme_recipients_t addrs; |
gpgme_recipients_t addrs; |
228 |
rc = gpgme_new (&ctx); |
rc = gpgme_new (&ctx); |
229 |
if (rc) |
if (rc) |
230 |
return NULL; |
return NULL; |
231 |
gpgme_control (ctx, GPGME_CTRL_ARMOR, 1); |
gpgme_set_armor (ctx, 1); |
|
gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1); |
|
232 |
addrs = conv_recipients (rset); |
addrs = conv_recipients (rset); |
233 |
if (!addrs) { |
if (!addrs) { |
234 |
msg_box (NULL, _("No valid mail addresses found."), _("Secure Attachment"), MB_ERR); |
msg_box (NULL, _("No valid mail addresses found."), _("Secure Attachment"), MB_ERR); |
244 |
} /* secure_attachment */ |
} /* secure_attachment */ |
245 |
|
|
246 |
|
|
247 |
static char * |
static gpgme_error_t |
248 |
secure_message (gpgme_recipients_t rset, const char * data) |
secure_message (gpgme_recipients_t rset, const char *data, |
249 |
|
char *enc_msg, size_t *r_enclen) |
250 |
{ |
{ |
251 |
gpgme_recipients_t addrs; |
gpgme_recipients_t addrs; |
252 |
gpgme_error_t rc; |
gpgme_error_t rc; |
258 |
rc = gpgme_new (&ctx); |
rc = gpgme_new (&ctx); |
259 |
if (rc) |
if (rc) |
260 |
return NULL; |
return NULL; |
261 |
gpgme_control (ctx, GPGME_CTRL_ARMOR, 1); |
gpgme_set_armor (ctx, 1); |
|
gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1); |
|
262 |
|
|
263 |
addrs = conv_recipients (rset); |
addrs = conv_recipients (rset); |
264 |
rc = gpgme_data_new_from_mem (&in, data, strlen (data), 1); |
rc = gpgme_data_new_from_mem (&in, data, strlen (data), 1); |
265 |
if (rc) { |
if (rc) { |
266 |
gpgme_release (ctx); |
gpgme_release (ctx); |
267 |
return NULL; |
return rc; |
268 |
} |
} |
269 |
gpgme_data_new (&out); |
gpgme_data_new (&out); |
270 |
|
rc = gpgme_op_encrypt (ctx, addrs, GPGME_ENCRYPT_ALWAYS_TRUST, in, out); |
|
rc = gpgme_op_encrypt (ctx, addrs, in, out); |
|
271 |
if (rc) |
if (rc) |
272 |
log_box (_("Secure Message"), MB_ERR, "Could not encrypt the data"); |
log_box (_("Secure Message"), MB_ERR, "Could not encrypt the data"); |
273 |
|
|
274 |
p = gpgme_data_release_and_return_string (out); |
*r_enc_msg = gpgme_data_release_and_get_mem (&n); |
275 |
|
*r_enclen = n; |
276 |
|
|
277 |
gpgme_data_release (in); |
gpgme_data_release (in); |
278 |
gpgme_release (ctx); |
gpgme_release (ctx); |
279 |
gpgme_recipients_release (addrs); |
gpgme_recipients_release (addrs); |
280 |
|
|
281 |
return p; |
return rc; |
282 |
} /* secure_message */ |
} /* secure_message */ |
283 |
|
|
284 |
|
|
285 |
int |
int |
286 |
mapi_send_message (gpgme_recipients_t rset, const char * msgtxt, |
mapi_send_message (gpgme_recipients_t rset, const char * msgtxt, |
287 |
const char * subject, const char ** files, size_t nfiles) |
const char * subject, const char **files, size_t nfiles) |
288 |
{ |
{ |
289 |
LHANDLE hd; |
LHANDLE hd; |
290 |
MapiMessage * msg; |
MapiMessage * msg; |
293 |
char * p; |
char * p; |
294 |
const char * s; |
const char * s; |
295 |
void * ctx=NULL; |
void * ctx=NULL; |
296 |
size_t n, i=0; |
size_t n, i=0, encmsg_len=0; |
297 |
int rc; |
int rc; |
298 |
|
|
299 |
if (!init) |
if (!init) |
306 |
} |
} |
307 |
|
|
308 |
msg = (MapiMessage *)calloc (1, sizeof * msg); |
msg = (MapiMessage *)calloc (1, sizeof * msg); |
309 |
|
if (!msg) |
310 |
|
BUG (0); |
311 |
p = msg->lpszSubject = strdup (subject); |
p = msg->lpszSubject = strdup (subject); |
312 |
if (!p) |
if (!p) |
313 |
BUG (0); |
BUG (0); |
314 |
p = msg->lpszNoteText = secure_message (rset, msgtxt); |
p = msg->lpszNoteText = secure_message (rset, msgtxt, &p, &encmsg_len); |
315 |
if (!p) |
if (!p) |
316 |
BUG (0); |
BUG (0); |
317 |
n = msg->nRecipCount = gpgme_recipients_count (rset); |
n = msg->nRecipCount = gpgme_recipients_count (rset); |
318 |
recip = (MapiRecipDesc *)calloc (n+1, sizeof * recip); |
recip = (MapiRecipDesc *)calloc (n+1, sizeof * recip); |
319 |
|
if (!recip) |
320 |
|
BUG (0); |
321 |
|
|
322 |
gpgme_recipients_enum_open (rset, &ctx); |
gpgme_recipients_enum_open (rset, &ctx); |
323 |
while ((s = gpgme_recipients_enum_read (rset, &ctx))) { |
while ((s = gpgme_recipients_enum_read (rset, &ctx))) { |
335 |
if (nfiles) { |
if (nfiles) { |
336 |
msg->nFileCount = nfiles; |
msg->nFileCount = nfiles; |
337 |
attch = (MapiFileDesc *)calloc (nfiles+1, sizeof * attch); |
attch = (MapiFileDesc *)calloc (nfiles+1, sizeof * attch); |
338 |
|
if (!attch) |
339 |
|
BUG (0); |
340 |
for (i=0; i < nfiles; i++) { |
for (i=0; i < nfiles; i++) { |
341 |
char * p = secure_attachment (rset, *files); |
char * p = secure_attachment (rset, *files); |
342 |
if (!p) |
if (!p) |
358 |
free_recip_tab (recip, n); |
free_recip_tab (recip, n); |
359 |
free_files_tab (attch, nfiles); |
free_files_tab (attch, nfiles); |
360 |
free_mapi_msg (msg); |
free_mapi_msg (msg); |
361 |
|
gpgme_free (p); |
362 |
mapi_logoff (hd, 0, 0, 0); |
mapi_logoff (hd, 0, 0, 0); |
363 |
|
|
364 |
return 0; |
return 0; |
368 |
static int |
static int |
369 |
add_recipient (gpgme_recipients_t * r_rset, const char * addr) |
add_recipient (gpgme_recipients_t * r_rset, const char * addr) |
370 |
{ |
{ |
371 |
gpgme_keycache_t pub = keycache_get_ctx (1); |
gpg_keycache_t pub = keycache_get_ctx (1); |
372 |
gpgme_key_t key; |
gpgme_key_t key; |
373 |
gpgme_error_t rc; |
gpgme_error_t rc; |
374 |
const char * s; |
const char * s; |
380 |
log_box (_("Add Recipient"), MB_ERR, _("Could not find key for '%s'"), addr); |
log_box (_("Add Recipient"), MB_ERR, _("Could not find key for '%s'"), addr); |
381 |
return -1; |
return -1; |
382 |
} |
} |
383 |
s = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, NULL, 0); |
s = key->uids->uid; |
384 |
if (s) |
if (s) |
385 |
gpgme_recipients_add_name (*r_rset, s); |
gpgme_recipients_add_name (*r_rset, s); |
386 |
return 0; |
return 0; |
415 |
|
|
416 |
switch (msg) { |
switch (msg) { |
417 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
418 |
center_window (dlg); |
center_window (dlg, NULL); |
419 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
420 |
break; |
break; |
421 |
|
|
437 |
return FALSE; |
return FALSE; |
438 |
} |
} |
439 |
msgbuf = (char * )calloc (1, n+2); |
msgbuf = (char * )calloc (1, n+2); |
440 |
|
if (!msgbuf) |
441 |
|
BUG (0); |
442 |
GetDlgItemText (dlg, IDC_PMAIL_MSG, msgbuf, n+1); |
GetDlgItemText (dlg, IDC_PMAIL_MSG, msgbuf, n+1); |
443 |
mapi_send_message (rset, msgbuf, subject, NULL, 0); |
mapi_send_message (rset, msgbuf, subject, NULL, 0); |
444 |
safe_free (msgbuf); |
safe_free (msgbuf); |
454 |
|
|
455 |
return FALSE; |
return FALSE; |
456 |
} /* winpt_mail_proc */ |
} /* winpt_mail_proc */ |
457 |
|
#endif |