1 |
/* wptMAPI.cpp |
/* wptMAPI.cpp |
2 |
* Copyright (C) 2003, 2004 Timo Schulz |
* Copyright (C) 2003, 2004, 2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* WinPT is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
* (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
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 |
|
#ifdef HAVE_CONFIG_H |
21 |
#include <windows.h> |
#include <config.h> |
22 |
#include <stdio.h> |
#endif |
23 |
#include <mapi.h> |
|
24 |
|
#include <windows.h> |
25 |
extern HINSTANCE glob_hinst; |
#include <stdio.h> |
26 |
|
#include <mapi.h> |
27 |
#include "../resource.h" |
|
28 |
#include "wptTypes.h" |
#include "resource.h" |
29 |
#include "wptErrors.h" |
#include "wptTypes.h" |
30 |
#include "wptW32API.h" |
#include "wptErrors.h" |
31 |
#include "wptGPG.h" |
#include "wptW32API.h" |
32 |
|
#include "wptGPG.h" |
33 |
|
#include "wptVersion.h" |
34 |
static LPMAPILOGON mapi_logon = NULL; |
|
35 |
static LPMAPILOGOFF mapi_logoff = NULL; |
static LPMAPILOGON mapi_logon = NULL; |
36 |
static LPMAPISENDDOCUMENTS mapi_send_documents = NULL; |
static LPMAPILOGOFF mapi_logoff = NULL; |
37 |
static LPMAPISENDMAIL mapi_send_mail = NULL; |
static LPMAPISENDDOCUMENTS mapi_send_documents = NULL; |
38 |
static HINSTANCE hlib = NULL; |
static LPMAPISENDMAIL mapi_send_mail = NULL; |
39 |
static int init = 0; |
static HINSTANCE hlib = NULL; |
40 |
|
static int init = 0; |
41 |
#define load_one_fnc(cast, hlib, name) (cast)GetProcAddress ((hlib), name) |
|
42 |
|
#define load_one_fnc(cast, hlib, name) (cast)GetProcAddress ((hlib), name) |
43 |
|
|
44 |
int |
|
45 |
mapi_init (void) |
/* Load MAPI library and set function pointers. |
46 |
{ |
Return value: 0 on success. */ |
47 |
if (init) |
int |
48 |
return 0; |
mapi_init (void) |
49 |
|
{ |
50 |
hlib = LoadLibrary ("MAPI32.DLL"); |
if (init) |
51 |
if (!hlib) |
return 0; |
52 |
return -1; |
|
53 |
|
hlib = LoadLibrary ("MAPI32.DLL"); |
54 |
mapi_logon = load_one_fnc (LPMAPILOGON, hlib, "MAPILogon"); |
if (!hlib) |
55 |
mapi_logoff = load_one_fnc (LPMAPILOGOFF, hlib, "MAPILogoff"); |
return -1; |
56 |
mapi_send_documents = load_one_fnc (LPMAPISENDDOCUMENTS, hlib, "MAPISendDocuments"); |
|
57 |
mapi_send_mail = load_one_fnc (LPMAPISENDMAIL, hlib, "MAPISendMail"); |
mapi_logon = load_one_fnc (LPMAPILOGON, hlib, "MAPILogon"); |
58 |
if (!mapi_logon || !mapi_logoff || !mapi_send_documents || !mapi_send_mail) |
mapi_logoff = load_one_fnc (LPMAPILOGOFF, hlib, "MAPILogoff"); |
59 |
return -1; |
mapi_send_documents = load_one_fnc (LPMAPISENDDOCUMENTS, hlib, "MAPISendDocuments"); |
60 |
init = 1; |
mapi_send_mail = load_one_fnc (LPMAPISENDMAIL, hlib, "MAPISendMail"); |
61 |
|
if (!mapi_logon || !mapi_logoff || !mapi_send_documents || !mapi_send_mail) |
62 |
return 0; |
return -1; |
63 |
} /* mapi_init */ |
init = 1; |
64 |
|
|
65 |
|
return 0; |
66 |
void |
} |
67 |
mapi_deinit (void) |
|
68 |
{ |
|
69 |
if (hlib) { |
/* Free library and cleanup. */ |
70 |
FreeLibrary (hlib); |
void |
71 |
hlib = NULL; |
mapi_deinit (void) |
72 |
init = 0; |
{ |
73 |
} |
if (hlib) { |
74 |
} /* mapi_deinit */ |
FreeLibrary (hlib); |
75 |
|
hlib = NULL; |
76 |
|
init = 0; |
77 |
int |
} |
78 |
mapi_send_ascfile (char * ascfile) |
} |
79 |
{ |
|
80 |
LHANDLE hd; |
|
81 |
int rc; |
/* Send the file given in @ascfile via the MAPI mechanism. */ |
82 |
|
int |
83 |
if (!init) |
mapi_send_ascfile (char *ascfile) |
84 |
return 0; |
{ |
85 |
|
LHANDLE hd; |
86 |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
int rc; |
87 |
if (rc != SUCCESS_SUCCESS) { |
|
88 |
MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK); |
if (!init) |
89 |
goto fail; |
return 0; |
90 |
} |
|
91 |
rc = mapi_send_documents (0, ";", ascfile, NULL, 0); |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
92 |
if (rc == MAPI_E_USER_ABORT) |
if (rc != SUCCESS_SUCCESS) { |
93 |
rc = SUCCESS_SUCCESS; |
MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK); |
94 |
if (rc != SUCCESS_SUCCESS) |
goto fail; |
95 |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK); |
} |
96 |
|
rc = mapi_send_documents (0, ";", ascfile, NULL, 0); |
97 |
fail: |
if (rc == MAPI_E_USER_ABORT) |
98 |
mapi_logoff (hd, 0, 0, 0); |
rc = SUCCESS_SUCCESS; |
99 |
return rc; |
if (rc != SUCCESS_SUCCESS) |
100 |
} |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK); |
101 |
|
|
102 |
|
fail: |
103 |
int |
mapi_logoff (hd, 0, 0, 0); |
104 |
mapi_send_pubkey (const char * keyid, char * keyfile) |
return rc; |
105 |
{ |
} |
106 |
LHANDLE hd; |
|
107 |
const char * fmt; |
|
108 |
char * keyinf = NULL; |
/* Send a public key stored in @keyfile with the keyid @keyid |
109 |
int rc; |
via the MAPI mechanism to a mail recipient. |
110 |
|
Return value: SUCCESS_SUCCESS on succes. */ |
111 |
if (!init) |
int |
112 |
return 0; |
mapi_send_pubkey (const char *keyid, char *keyfile) |
113 |
|
{ |
114 |
fmt = _("GPG Public Key of %s"); |
LHANDLE hd; |
115 |
keyinf = new char[strlen (fmt) + strlen (keyid) + 2]; |
const char * fmt; |
116 |
if (!keyinf) |
char * keyinf = NULL; |
117 |
BUG (0); |
int rc; |
118 |
sprintf (keyinf, fmt, keyid); |
|
119 |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
if (!init) |
120 |
if (rc != SUCCESS_SUCCESS) { |
return 0; |
121 |
MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK); |
|
122 |
goto fail; |
fmt = _("GPG Public Key of %s"); |
123 |
} |
keyinf = new char[strlen (fmt) + strlen (keyid) + 2]; |
124 |
rc = mapi_send_documents (0, ";", keyfile, keyinf, 0); |
if (!keyinf) |
125 |
if (rc == MAPI_E_USER_ABORT) |
BUG (0); |
126 |
rc = SUCCESS_SUCCESS; |
sprintf (keyinf, fmt, keyid); |
127 |
if (rc != SUCCESS_SUCCESS) |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
128 |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK); |
if (rc != SUCCESS_SUCCESS) { |
129 |
|
MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK); |
130 |
fail: |
goto fail; |
131 |
mapi_logoff (hd, 0, 0, 0); |
} |
132 |
free_if_alloc (keyinf); |
rc = mapi_send_documents (0, ";", keyfile, keyinf, 0); |
133 |
return rc; |
if (rc == MAPI_E_USER_ABORT) |
134 |
} /* mapi_send_pubkey */ |
rc = SUCCESS_SUCCESS; |
135 |
|
if (rc != SUCCESS_SUCCESS) |
136 |
|
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK); |
137 |
static void |
|
138 |
free_mapi_msg (MapiMessage * msg) |
fail: |
139 |
{ |
mapi_logoff (hd, 0, 0, 0); |
140 |
if (!msg) |
free_if_alloc (keyinf); |
141 |
return; |
return rc; |
142 |
safe_free (msg->lpszSubject); |
} |
143 |
safe_free (msg->lpszNoteText); |
|
144 |
safe_free (msg); |
|
145 |
} /* free_mapi_msg */ |
#if 0 /* low:priority XXX port the code */ |
146 |
|
static void |
147 |
|
free_mapi_msg (MapiMessage * msg) |
148 |
static void |
{ |
149 |
free_recip_tab (MapiRecipDesc * recip, size_t n) |
if (!msg) |
150 |
{ |
return; |
151 |
size_t i; |
safe_free (msg->lpszSubject); |
152 |
|
safe_free (msg->lpszNoteText); |
153 |
if (!recip) |
safe_free (msg); |
154 |
return; |
} /* free_mapi_msg */ |
155 |
if (!n) |
|
156 |
return; |
|
157 |
for (i=0; i < n; i++) |
static void |
158 |
safe_free (recip[i].lpszName); |
free_recip_tab (MapiRecipDesc *recip, size_t n) |
159 |
safe_free (recip); |
{ |
160 |
} /* free_recip_tab */ |
size_t i; |
161 |
|
|
162 |
|
if (!recip) |
163 |
static void |
return; |
164 |
free_files_tab (MapiFileDesc * files, size_t n) |
if (!n) |
165 |
{ |
return; |
166 |
size_t i; |
for (i=0; i < n; i++) |
167 |
|
safe_free (recip[i].lpszName); |
168 |
if (!files) |
safe_free (recip); |
169 |
return; |
} /* free_recip_tab */ |
170 |
if (!n) |
|
171 |
return; |
|
172 |
for (i=0; i < n; i++) { |
static void |
173 |
safe_free (files[i].lpszFileName); |
free_files_tab (MapiFileDesc * files, size_t n) |
174 |
safe_free (files[i].lpszPathName); |
{ |
175 |
} |
size_t i; |
176 |
safe_free (files); |
|
177 |
} /* free_files_tab */ |
if (!files) |
178 |
|
return; |
179 |
|
if (!n) |
180 |
|
return; |
181 |
static gpgme_recipients_t |
for (i=0; i < n; i++) { |
182 |
conv_recipients (gpgme_recipients_t rset) |
safe_free (files[i].lpszFileName); |
183 |
{ |
safe_free (files[i].lpszPathName); |
184 |
gpgme_recipients_t r; |
} |
185 |
gpgme_error_t rc; |
safe_free (files); |
186 |
void * ctx=NULL; |
} /* free_files_tab */ |
187 |
const char * s; |
|
188 |
|
|
189 |
/* we need to convert the recipients to email addresses so |
|
190 |
GPG can handle them. */ |
static gpgme_recipients_t |
191 |
rc = gpgme_recipients_new (&r); |
conv_recipients (gpgme_recipients_t rset) |
192 |
if (rc) |
{ |
193 |
return NULL; |
gpgme_recipients_t r; |
194 |
gpgme_recipients_enum_open (rset, &ctx); |
gpgme_error_t rc; |
195 |
|
void * ctx=NULL; |
196 |
while ((s=gpgme_recipients_enum_read (rset, &ctx))) { |
const char * s; |
197 |
char * p, * q, * buf; |
|
198 |
if (!(p = strchr (s, '<')) || !(q = strchr (s, '>'))) |
/* we need to convert the recipients to email addresses so |
199 |
continue; |
GPG can handle them. */ |
200 |
buf = (char * )calloc (1, (q-s)-(p-s)+2); |
rc = gpgme_recipients_new (&r); |
201 |
strncpy (buf, s+(p-s)+1, (q-s)-(p-s)-1); |
if (rc) |
202 |
gpgme_recipients_add_name (r, buf); |
return NULL; |
203 |
safe_free (buf); |
gpgme_recipients_enum_open (rset, &ctx); |
204 |
} |
|
205 |
return r; |
while ((s=gpgme_recipients_enum_read (rset, &ctx))) { |
206 |
} /* conv_recipients */ |
char * p, * q, * buf; |
207 |
|
if (!(p = strchr (s, '<')) || !(q = strchr (s, '>'))) |
208 |
|
continue; |
209 |
static char * |
buf = (char * )calloc (1, (q-s)-(p-s)+2); |
210 |
secure_attachment (gpgme_recipients_t rset, const char * fname) |
if (!buf) |
211 |
{ |
BUG (0); |
212 |
char tmpdir[512+32], * p; |
strncpy (buf, s+(p-s)+1, (q-s)-(p-s)-1); |
213 |
gpgme_recipients_t addrs; |
gpgme_recipients_add_name (r, buf); |
214 |
gpgme_ctx_t ctx; |
safe_free (buf); |
215 |
gpgme_error_t rc; |
} |
216 |
|
return r; |
217 |
if (strlen (fname) > 200) |
} /* conv_recipients */ |
218 |
BUG (0); |
|
219 |
GetTempPath (sizeof tmpdir-200, tmpdir); |
|
220 |
p = strrchr (fname, '\\'); |
static char * |
221 |
if (!p) |
secure_attachment (gpgme_recipients_t rset, const char *fname) |
222 |
strcat (tmpdir, fname); |
{ |
223 |
else |
char tmpdir[512+32], * p; |
224 |
strcat (tmpdir, fname+(p-fname)+1); |
gpgme_recipients_t addrs; |
225 |
strcat (tmpdir, ".asc"); |
gpgme_ctx_t ctx; |
226 |
|
gpgme_error_t rc; |
227 |
rc = gpgme_new (&ctx); |
|
228 |
if (rc) |
if (strlen (fname) > 200) |
229 |
return NULL; |
BUG (0); |
230 |
gpgme_control (ctx, GPGME_CTRL_ARMOR, 1); |
GetTempPath (sizeof tmpdir-200, tmpdir); |
231 |
gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1); |
p = strrchr (fname, '\\'); |
232 |
addrs = conv_recipients (rset); |
if (!p) |
233 |
if (!addrs) { |
strcat (tmpdir, fname); |
234 |
msg_box (NULL, _("No valid mail addresses found."), _("Secure Attachment"), MB_ERR); |
else |
235 |
gpgme_release (NULL); |
strcat (tmpdir, fname+(p-fname)+1); |
236 |
return NULL; |
strcat (tmpdir, ".asc"); |
237 |
} |
|
238 |
rc = gpgme_op_file_encrypt (ctx, addrs, fname, tmpdir); |
rc = gpgme_new (&ctx); |
239 |
if (rc) |
if (rc) |
240 |
log_box (_("Secure Attachment"), MB_ERR, _("Could not encrypt '%s'"), fname); |
return NULL; |
241 |
gpgme_recipients_release (addrs); |
gpgme_set_armor (ctx, 1); |
242 |
gpgme_release (ctx); |
addrs = conv_recipients (rset); |
243 |
return strdup (tmpdir); |
if (!addrs) { |
244 |
} /* secure_attachment */ |
msg_box (NULL, _("No valid mail addresses found."), _("Secure Attachment"), MB_ERR); |
245 |
|
gpgme_release (NULL); |
246 |
|
return NULL; |
247 |
static char * |
} |
248 |
secure_message (gpgme_recipients_t rset, const char * data) |
rc = gpgme_op_file_encrypt (ctx, addrs, fname, tmpdir); |
249 |
{ |
if (rc) |
250 |
gpgme_recipients_t addrs; |
log_box (_("Secure Attachment"), MB_ERR, _("Could not encrypt '%s'"), fname); |
251 |
gpgme_error_t rc; |
gpgme_recipients_release (addrs); |
252 |
gpgme_data_t in, out; |
gpgme_release (ctx); |
253 |
gpgme_ctx_t ctx; |
return strdup (tmpdir); |
254 |
char * p; |
} /* secure_attachment */ |
255 |
size_t n=0; |
|
256 |
|
|
257 |
rc = gpgme_new (&ctx); |
static gpgme_error_t |
258 |
if (rc) |
secure_message (gpgme_recipients_t rset, const char *data, |
259 |
return NULL; |
char *enc_msg, size_t *r_enclen) |
260 |
gpgme_control (ctx, GPGME_CTRL_ARMOR, 1); |
{ |
261 |
gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1); |
gpgme_recipients_t addrs; |
262 |
|
gpgme_error_t rc; |
263 |
addrs = conv_recipients (rset); |
gpgme_data_t in, out; |
264 |
rc = gpgme_data_new_from_mem (&in, data, strlen (data), 1); |
gpgme_ctx_t ctx; |
265 |
if (rc) { |
char * p; |
266 |
gpgme_release (ctx); |
size_t n=0; |
267 |
return NULL; |
|
268 |
} |
rc = gpgme_new (&ctx); |
269 |
gpgme_data_new (&out); |
if (rc) |
270 |
|
return NULL; |
271 |
rc = gpgme_op_encrypt (ctx, addrs, in, out); |
gpgme_set_armor (ctx, 1); |
272 |
if (rc) |
|
273 |
log_box (_("Secure Message"), MB_ERR, "Could not encrypt the data"); |
addrs = conv_recipients (rset); |
274 |
|
rc = gpgme_data_new_from_mem (&in, data, strlen (data), 1); |
275 |
p = gpgme_data_release_and_return_string (out); |
if (rc) { |
276 |
|
gpgme_release (ctx); |
277 |
gpgme_data_release (in); |
return rc; |
278 |
gpgme_release (ctx); |
} |
279 |
gpgme_recipients_release (addrs); |
gpgme_data_new (&out); |
280 |
|
rc = gpgme_op_encrypt (ctx, addrs, GPGME_ENCRYPT_ALWAYS_TRUST, in, out); |
281 |
return p; |
if (rc) |
282 |
} /* secure_message */ |
log_box (_("Secure Message"), MB_ERR, "Could not encrypt the data"); |
283 |
|
|
284 |
|
*r_enc_msg = gpgme_data_release_and_get_mem (&n); |
285 |
int |
*r_enclen = n; |
286 |
mapi_send_message (gpgme_recipients_t rset, const char * msgtxt, |
|
287 |
const char * subject, const char ** files, size_t nfiles) |
gpgme_data_release (in); |
288 |
{ |
gpgme_release (ctx); |
289 |
LHANDLE hd; |
gpgme_recipients_release (addrs); |
290 |
MapiMessage * msg; |
|
291 |
MapiRecipDesc * recip; |
return rc; |
292 |
MapiFileDesc * attch; |
} /* secure_message */ |
293 |
char * p; |
|
294 |
const char * s; |
|
295 |
void * ctx=NULL; |
int |
296 |
size_t n, i=0; |
mapi_send_message (gpgme_recipients_t rset, const char * msgtxt, |
297 |
int rc; |
const char * subject, const char **files, size_t nfiles) |
298 |
|
{ |
299 |
if (!init) |
LHANDLE hd; |
300 |
return 0; |
MapiMessage * msg; |
301 |
|
MapiRecipDesc * recip; |
302 |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
MapiFileDesc * attch; |
303 |
if (rc != SUCCESS_SUCCESS) { |
char * p; |
304 |
MessageBox (NULL, "MAPI Login failed.", "MAPI", MB_ICONWARNING|MB_OK); |
const char * s; |
305 |
return rc; |
void * ctx=NULL; |
306 |
} |
size_t n, i=0, encmsg_len=0; |
307 |
|
int rc; |
308 |
msg = (MapiMessage *)calloc (1, sizeof * msg); |
|
309 |
p = msg->lpszSubject = strdup (subject); |
if (!init) |
310 |
if (!p) |
return 0; |
311 |
BUG (0); |
|
312 |
p = msg->lpszNoteText = secure_message (rset, msgtxt); |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
313 |
if (!p) |
if (rc != SUCCESS_SUCCESS) { |
314 |
BUG (0); |
MessageBox (NULL, "MAPI Login failed.", "MAPI", MB_ICONWARNING|MB_OK); |
315 |
n = msg->nRecipCount = gpgme_recipients_count (rset); |
return rc; |
316 |
recip = (MapiRecipDesc *)calloc (n+1, sizeof * recip); |
} |
317 |
|
|
318 |
gpgme_recipients_enum_open (rset, &ctx); |
msg = (MapiMessage *)calloc (1, sizeof * msg); |
319 |
while ((s = gpgme_recipients_enum_read (rset, &ctx))) { |
if (!msg) |
320 |
if (!i) |
BUG (0); |
321 |
recip[i].ulRecipClass = MAPI_TO; |
p = msg->lpszSubject = strdup (subject); |
322 |
else |
if (!p) |
323 |
recip[i].ulRecipClass = MAPI_CC; |
BUG (0); |
324 |
p = recip[i].lpszName = strdup (s); |
p = msg->lpszNoteText = secure_message (rset, msgtxt, &p, &encmsg_len); |
325 |
if (!p) |
if (!p) |
326 |
BUG (0); |
BUG (0); |
327 |
i++; |
n = msg->nRecipCount = gpgme_recipients_count (rset); |
328 |
} |
recip = (MapiRecipDesc *)calloc (n+1, sizeof * recip); |
329 |
msg->lpRecips = recip; |
if (!recip) |
330 |
|
BUG (0); |
331 |
if (nfiles) { |
|
332 |
msg->nFileCount = nfiles; |
gpgme_recipients_enum_open (rset, &ctx); |
333 |
attch = (MapiFileDesc *)calloc (nfiles+1, sizeof * attch); |
while ((s = gpgme_recipients_enum_read (rset, &ctx))) { |
334 |
for (i=0; i < nfiles; i++) { |
if (!i) |
335 |
char * p = secure_attachment (rset, *files); |
recip[i].ulRecipClass = MAPI_TO; |
336 |
if (!p) |
else |
337 |
continue; |
recip[i].ulRecipClass = MAPI_CC; |
338 |
attch[i].lpszFileName = strdup (*files); |
p = recip[i].lpszName = strdup (s); |
339 |
attch[i].lpszPathName = strdup (p); |
if (!p) |
340 |
files++; |
BUG (0); |
341 |
safe_free (p); |
i++; |
342 |
} |
} |
343 |
msg->lpFiles = attch; |
msg->lpRecips = recip; |
344 |
} |
|
345 |
|
if (nfiles) { |
346 |
rc = mapi_send_mail (hd, 0, msg, 0, 0); |
msg->nFileCount = nfiles; |
347 |
if (rc == MAPI_E_USER_ABORT) |
attch = (MapiFileDesc *)calloc (nfiles+1, sizeof * attch); |
348 |
rc = SUCCESS_SUCCESS; |
if (!attch) |
349 |
if (rc != SUCCESS_SUCCESS) |
BUG (0); |
350 |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ERR); |
for (i=0; i < nfiles; i++) { |
351 |
|
char * p = secure_attachment (rset, *files); |
352 |
free_recip_tab (recip, n); |
if (!p) |
353 |
free_files_tab (attch, nfiles); |
continue; |
354 |
free_mapi_msg (msg); |
attch[i].lpszFileName = strdup (*files); |
355 |
mapi_logoff (hd, 0, 0, 0); |
attch[i].lpszPathName = strdup (p); |
356 |
|
files++; |
357 |
return 0; |
safe_free (p); |
358 |
} /* mapi_send_message */ |
} |
359 |
|
msg->lpFiles = attch; |
360 |
|
} |
361 |
static int |
|
362 |
add_recipient (gpgme_recipients_t * r_rset, const char * addr) |
rc = mapi_send_mail (hd, 0, msg, 0, 0); |
363 |
{ |
if (rc == MAPI_E_USER_ABORT) |
364 |
gpgme_keycache_t pub = keycache_get_ctx (1); |
rc = SUCCESS_SUCCESS; |
365 |
gpgme_key_t key; |
if (rc != SUCCESS_SUCCESS) |
366 |
gpgme_error_t rc; |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ERR); |
367 |
const char * s; |
|
368 |
|
free_recip_tab (recip, n); |
369 |
if (!*r_rset) |
free_files_tab (attch, nfiles); |
370 |
gpgme_recipients_new (&(*r_rset)); |
free_mapi_msg (msg); |
371 |
rc = gpgme_keycache_find_key (pub, addr, 0, &key); |
gpgme_free (p); |
372 |
if (rc) { |
mapi_logoff (hd, 0, 0, 0); |
373 |
log_box (_("Add Recipient"), MB_ERR, _("Could not find key for '%s'"), addr); |
|
374 |
return -1; |
return 0; |
375 |
} |
} /* mapi_send_message */ |
376 |
s = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, NULL, 0); |
|
377 |
if (s) |
|
378 |
gpgme_recipients_add_name (*r_rset, s); |
static int |
379 |
return 0; |
add_recipient (gpgme_recipients_t *r_rset, const char *addr) |
380 |
} /* add_recipient */ |
{ |
381 |
|
gpg_keycache_t pub = keycache_get_ctx (1); |
382 |
|
gpgme_key_t key; |
383 |
static int |
gpgme_error_t rc; |
384 |
add_all_recipients (HWND dlg, int itemid, gpgme_recipients_t * r_rset) |
char *uid; |
385 |
{ |
|
386 |
char buf[1024], * p; |
if (!*r_rset) |
387 |
int n=0; |
gpgme_recipients_new (&(*r_rset)); |
388 |
|
rc = gpgme_keycache_find_key (pub, addr, 0, &key); |
389 |
n = GetDlgItemText (dlg, itemid, buf, sizeof buf-10); |
if (rc) { |
390 |
if (!n) |
log_box (_("Add Recipient"), MB_ERR, _("Could not find key for '%s'"), addr); |
391 |
return -1; |
return -1; |
392 |
p = strtok (buf, ";,"); |
} |
393 |
while (p != NULL) { |
if (key->uids->uid) { |
394 |
add_recipient (&*r_rset, p); |
uid = utf8_to_wincp2 (key->uids->uid); |
395 |
p = strtok (NULL, ";,"); |
gpgme_recipients_add_name (*r_rset, uid); |
396 |
} |
free_if_alloc (uid); |
397 |
return 0; |
} |
398 |
} /* add_all_recipients */ |
return 0; |
399 |
|
} /* add_recipient */ |
400 |
|
|
401 |
BOOL CALLBACK |
|
402 |
winpt_mail_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
static int |
403 |
{ |
add_all_recipients (HWND dlg, int itemid, gpgme_recipients_t * r_rset) |
404 |
static gpgme_recipients_t rset=NULL; |
{ |
405 |
char subject[128]; |
char buf[1024], * p; |
406 |
char * msgbuf; |
int n=0; |
407 |
int n; |
|
408 |
|
n = GetDlgItemText (dlg, itemid, buf, sizeof buf-10); |
409 |
switch (msg) { |
if (!n) |
410 |
case WM_INITDIALOG: |
return -1; |
411 |
center_window (dlg); |
p = strtok (buf, ";,"); |
412 |
SetForegroundWindow (dlg); |
while (p != NULL) { |
413 |
break; |
add_recipient (&*r_rset, p); |
414 |
|
p = strtok (NULL, ";,"); |
415 |
case WM_COMMAND: |
} |
416 |
switch (LOWORD (wparam)) { |
return 0; |
417 |
case IDOK: |
} /* add_all_recipients */ |
418 |
add_all_recipients (dlg, IDC_PMAIL_TO, &rset); |
|
419 |
add_all_recipients (dlg, IDC_PMAIL_CC, &rset); |
|
420 |
if (!gpgme_recipients_count (rset)) { |
BOOL CALLBACK |
421 |
msg_box (dlg, _("Please enter a recipient."), _("Mail"), MB_ERR); |
winpt_mail_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
422 |
return FALSE; |
{ |
423 |
} |
static gpgme_recipients_t rset=NULL; |
424 |
n=GetDlgItemText (dlg, IDC_PMAIL_SUBJECT, subject, sizeof subject-1); |
char subject[128]; |
425 |
if (!n) |
char * msgbuf; |
426 |
strcpy (subject, ""); |
int n; |
427 |
n = SendDlgItemMessage (dlg, IDC_PMAIL_MSG, WM_GETTEXTLENGTH, 0, 0); |
|
428 |
if (!n) { |
switch (msg) { |
429 |
msg_box (dlg, _("Please enter a message."), _("Mail"), MB_ERR); |
case WM_INITDIALOG: |
430 |
return FALSE; |
center_window (dlg, NULL); |
431 |
} |
SetForegroundWindow (dlg); |
432 |
msgbuf = (char * )calloc (1, n+2); |
break; |
433 |
GetDlgItemText (dlg, IDC_PMAIL_MSG, msgbuf, n+1); |
|
434 |
mapi_send_message (rset, msgbuf, subject, NULL, 0); |
case WM_COMMAND: |
435 |
safe_free (msgbuf); |
switch (LOWORD (wparam)) { |
436 |
EndDialog (dlg, TRUE); |
case IDOK: |
437 |
break; |
add_all_recipients (dlg, IDC_PMAIL_TO, &rset); |
438 |
|
add_all_recipients (dlg, IDC_PMAIL_CC, &rset); |
439 |
case IDCANCEL: |
if (!gpgme_recipients_count (rset)) { |
440 |
EndDialog (dlg, FALSE); |
msg_box (dlg, _("Please enter a recipient."), _("Mail"), MB_ERR); |
441 |
break; |
return FALSE; |
442 |
} |
} |
443 |
break; |
n=GetDlgItemText (dlg, IDC_PMAIL_SUBJECT, subject, sizeof subject-1); |
444 |
} |
if (!n) |
445 |
|
strcpy (subject, ""); |
446 |
return FALSE; |
n = SendDlgItemMessage (dlg, IDC_PMAIL_MSG, WM_GETTEXTLENGTH, 0, 0); |
447 |
} /* winpt_mail_proc */ |
if (!n) { |
448 |
|
msg_box (dlg, _("Please enter a message."), _("Mail"), MB_ERR); |
449 |
|
return FALSE; |
450 |
|
} |
451 |
|
msgbuf = (char * )calloc (1, n+2); |
452 |
|
if (!msgbuf) |
453 |
|
BUG (0); |
454 |
|
GetDlgItemText (dlg, IDC_PMAIL_MSG, msgbuf, n+1); |
455 |
|
mapi_send_message (rset, msgbuf, subject, NULL, 0); |
456 |
|
safe_free (msgbuf); |
457 |
|
EndDialog (dlg, TRUE); |
458 |
|
break; |
459 |
|
|
460 |
|
case IDCANCEL: |
461 |
|
EndDialog (dlg, FALSE); |
462 |
|
break; |
463 |
|
} |
464 |
|
break; |
465 |
|
} |
466 |
|
|
467 |
|
return FALSE; |
468 |
|
} /* winpt_mail_proc */ |
469 |
|
#endif |