1 |
/* wptMAPI.cpp |
/* wptMAPI.cpp - MAPI interface for sending keys. |
2 |
* Copyright (C) 2003, 2004 Timo Schulz |
* Copyright (C) 2003, 2004, 2005, 2006 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; |
#include "wptCommonCtl.h" |
35 |
static LPMAPILOGOFF mapi_logoff = NULL; |
#include "wptKeyManager.h" |
36 |
static LPMAPISENDDOCUMENTS mapi_send_documents = NULL; |
|
37 |
static LPMAPISENDMAIL mapi_send_mail = NULL; |
|
38 |
static HINSTANCE hlib = NULL; |
static LPMAPILOGON mapi_logon = NULL; |
39 |
static int init = 0; |
static LPMAPILOGOFF mapi_logoff = NULL; |
40 |
|
static LPMAPISENDDOCUMENTS mapi_send_documents = NULL; |
41 |
#define load_one_fnc(cast, hlib, name) (cast)GetProcAddress ((hlib), name) |
static LPMAPISENDMAIL mapi_send_mail = NULL; |
42 |
|
static HINSTANCE hlib = NULL; |
43 |
|
static int init = 0; |
44 |
int |
|
45 |
mapi_init (void) |
#define load_one_fnc(cast, hlib, name) (cast)GetProcAddress ((hlib), name) |
46 |
{ |
|
47 |
if (init) |
|
48 |
return 0; |
/* Load MAPI library and set function pointers. |
49 |
|
Return value: 0 on success. */ |
50 |
hlib = LoadLibrary ("MAPI32.DLL"); |
int |
51 |
if (!hlib) |
mapi_init (void) |
52 |
return -1; |
{ |
53 |
|
if (init) |
54 |
mapi_logon = load_one_fnc (LPMAPILOGON, hlib, "MAPILogon"); |
return 0; |
55 |
mapi_logoff = load_one_fnc (LPMAPILOGOFF, hlib, "MAPILogoff"); |
|
56 |
mapi_send_documents = load_one_fnc (LPMAPISENDDOCUMENTS, hlib, "MAPISendDocuments"); |
hlib = LoadLibrary ("MAPI32.DLL"); |
57 |
mapi_send_mail = load_one_fnc (LPMAPISENDMAIL, hlib, "MAPISendMail"); |
if (!hlib) |
58 |
if (!mapi_logon || !mapi_logoff || !mapi_send_documents || !mapi_send_mail) |
return -1; |
59 |
return -1; |
|
60 |
init = 1; |
mapi_logon = load_one_fnc (LPMAPILOGON, hlib, "MAPILogon"); |
61 |
|
mapi_logoff = load_one_fnc (LPMAPILOGOFF, hlib, "MAPILogoff"); |
62 |
return 0; |
mapi_send_documents = load_one_fnc (LPMAPISENDDOCUMENTS, hlib, "MAPISendDocuments"); |
63 |
} /* mapi_init */ |
mapi_send_mail = load_one_fnc (LPMAPISENDMAIL, hlib, "MAPISendMail"); |
64 |
|
if (!mapi_logon || !mapi_logoff || !mapi_send_documents || !mapi_send_mail) |
65 |
|
return -1; |
66 |
void |
init = 1; |
67 |
mapi_deinit (void) |
|
68 |
{ |
return 0; |
69 |
if (hlib) { |
} |
70 |
FreeLibrary (hlib); |
|
71 |
hlib = NULL; |
|
72 |
init = 0; |
/* Free library and cleanup. */ |
73 |
} |
void |
74 |
} /* mapi_deinit */ |
mapi_deinit (void) |
75 |
|
{ |
76 |
|
if (hlib) { |
77 |
int |
FreeLibrary (hlib); |
78 |
mapi_send_ascfile (char * ascfile) |
hlib = NULL; |
79 |
{ |
init = 0; |
80 |
LHANDLE hd; |
} |
81 |
int rc; |
} |
82 |
|
|
83 |
if (!init) |
|
84 |
return 0; |
/* Send the file given in @ascfile via the MAPI mechanism. */ |
85 |
|
int |
86 |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
mapi_send_ascfile (char *ascfile) |
87 |
if (rc != SUCCESS_SUCCESS) { |
{ |
88 |
MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK); |
LHANDLE hd; |
89 |
goto fail; |
int rc; |
90 |
} |
|
91 |
rc = mapi_send_documents (0, ";", ascfile, NULL, 0); |
if (!init) |
92 |
if (rc == MAPI_E_USER_ABORT) |
return 0; |
93 |
rc = SUCCESS_SUCCESS; |
|
94 |
if (rc != SUCCESS_SUCCESS) |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
95 |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK); |
if (rc != SUCCESS_SUCCESS) { |
96 |
|
MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK); |
97 |
fail: |
goto fail; |
98 |
mapi_logoff (hd, 0, 0, 0); |
} |
99 |
return rc; |
rc = mapi_send_documents (0, ";", ascfile, NULL, 0); |
100 |
} |
if (rc == MAPI_E_USER_ABORT) |
101 |
|
rc = SUCCESS_SUCCESS; |
102 |
|
if (rc != SUCCESS_SUCCESS) |
103 |
int |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK); |
104 |
mapi_send_pubkey (const char * keyid, char * keyfile) |
|
105 |
{ |
fail: |
106 |
LHANDLE hd; |
mapi_logoff (hd, 0, 0, 0); |
107 |
const char * fmt; |
return rc; |
108 |
char * keyinf = NULL; |
} |
109 |
int rc; |
|
110 |
|
|
111 |
if (!init) |
static void |
112 |
return 0; |
free_mapi_msg (MapiMessage *msg) |
113 |
|
{ |
114 |
fmt = _("GPG Public Key of %s"); |
if (!msg) |
115 |
keyinf = new char[strlen (fmt) + strlen (keyid) + 2]; |
return; |
116 |
if (!keyinf) |
safe_free (msg->lpszSubject); |
117 |
BUG (0); |
safe_free (msg->lpszNoteText); |
118 |
sprintf (keyinf, fmt, keyid); |
safe_free (msg); |
119 |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
} |
120 |
if (rc != SUCCESS_SUCCESS) { |
|
121 |
MessageBox (NULL, _("MAPI Login failed."), "MAPI", MB_ICONWARNING|MB_OK); |
|
122 |
goto fail; |
static void |
123 |
} |
free_recip_tab (MapiRecipDesc *recip, size_t n) |
124 |
rc = mapi_send_documents (0, ";", keyfile, keyinf, 0); |
{ |
125 |
if (rc == MAPI_E_USER_ABORT) |
size_t i; |
126 |
rc = SUCCESS_SUCCESS; |
|
127 |
if (rc != SUCCESS_SUCCESS) |
if (!recip) |
128 |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ICONERROR|MB_OK); |
return; |
129 |
|
if (!n) |
130 |
fail: |
return; |
131 |
mapi_logoff (hd, 0, 0, 0); |
for (i=0; i < n; i++) |
132 |
free_if_alloc (keyinf); |
safe_free (recip[i].lpszName); |
133 |
return rc; |
safe_free (recip); |
134 |
} /* mapi_send_pubkey */ |
} |
135 |
|
|
136 |
|
|
137 |
static void |
static void |
138 |
free_mapi_msg (MapiMessage * msg) |
free_files_tab (MapiFileDesc *files, size_t n) |
139 |
{ |
{ |
140 |
if (!msg) |
size_t i; |
141 |
return; |
|
142 |
safe_free (msg->lpszSubject); |
if (!files) |
143 |
safe_free (msg->lpszNoteText); |
return; |
144 |
safe_free (msg); |
if (!n) |
145 |
} /* free_mapi_msg */ |
return; |
146 |
|
for (i=0; i < n; i++) { |
147 |
|
safe_free (files[i].lpszFileName); |
148 |
static void |
safe_free (files[i].lpszPathName); |
149 |
free_recip_tab (MapiRecipDesc * recip, size_t n) |
} |
150 |
{ |
safe_free (files); |
151 |
size_t i; |
} |
152 |
|
|
153 |
if (!recip) |
|
154 |
return; |
/* Same as mapi_send_pubkey but there is an additional note. */ |
155 |
if (!n) |
int |
156 |
return; |
mapi_send_pubkey_ext (winpt_key_t key, const char *keyfile, int flags) |
157 |
for (i=0; i < n; i++) |
{ |
158 |
safe_free (recip[i].lpszName); |
LHANDLE hd; |
159 |
safe_free (recip); |
MapiMessage *msg; |
160 |
} /* free_recip_tab */ |
MapiRecipDesc *recip; |
161 |
|
MapiFileDesc *attch; |
162 |
|
gpgme_key_t to = key->ctx; |
163 |
static void |
char *p, *kinf; |
164 |
free_files_tab (MapiFileDesc * files, size_t n) |
const char *s; |
165 |
{ |
int rc; |
166 |
size_t i; |
|
167 |
|
if (!init) |
168 |
if (!files) |
return 0; |
169 |
return; |
|
170 |
if (!n) |
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
171 |
return; |
if (rc != SUCCESS_SUCCESS) { |
172 |
for (i=0; i < n; i++) { |
MessageBox (NULL, "MAPI Login failed.", "MAPI", MB_ICONWARNING|MB_OK); |
173 |
safe_free (files[i].lpszFileName); |
return rc; |
174 |
safe_free (files[i].lpszPathName); |
} |
175 |
} |
|
176 |
safe_free (files); |
msg = (MapiMessage *)calloc (1, sizeof *msg); |
177 |
} /* free_files_tab */ |
if (!msg) |
178 |
|
BUG (0); |
179 |
|
p = msg->lpszSubject = strdup ("OpenPGP Public Key"); |
180 |
|
if (!p) |
181 |
static gpgme_recipients_t |
BUG (0); |
182 |
conv_recipients (gpgme_recipients_t rset) |
|
183 |
{ |
s = "Attached is this OpenPGP public key:\n%s\n\n" |
184 |
gpgme_recipients_t r; |
"Import this key via the clipboard or the Key Manager to\n" |
185 |
gpgme_error_t rc; |
"exchange encrypted mails with the key holder and to be able\n" |
186 |
void * ctx=NULL; |
"to verify its signatures.\n" |
187 |
const char * s; |
"\n" |
188 |
|
"If you don't have WinPT, you can download it at http://www.winpt.org"; |
189 |
/* we need to convert the recipients to email addresses so |
kinf = km_key_get_info (key, 0); |
190 |
GPG can handle them. */ |
p = (char*)malloc (strlen (s) + strlen (kinf) + 2); |
191 |
rc = gpgme_recipients_new (&r); |
sprintf (p, s, kinf); |
192 |
if (rc) |
free_if_alloc (kinf); |
193 |
return NULL; |
|
194 |
gpgme_recipients_enum_open (rset, &ctx); |
p = msg->lpszNoteText = p; |
195 |
|
if (!p) |
196 |
while ((s=gpgme_recipients_enum_read (rset, &ctx))) { |
BUG (0); |
197 |
char * p, * q, * buf; |
|
198 |
if (!(p = strchr (s, '<')) || !(q = strchr (s, '>'))) |
/* If the key was signed, we assume it shall be sent back to the owner. */ |
199 |
continue; |
if (flags) { |
200 |
buf = (char * )calloc (1, (q-s)-(p-s)+2); |
recip = (MapiRecipDesc *)calloc (1, sizeof *recip); |
201 |
strncpy (buf, s+(p-s)+1, (q-s)-(p-s)-1); |
if (!recip) |
202 |
gpgme_recipients_add_name (r, buf); |
BUG (0); |
203 |
safe_free (buf); |
recip[0].ulRecipClass = MAPI_TO; |
204 |
} |
p = recip[0].lpszName = strdup (to->uids->uid); |
205 |
return r; |
if (!p) |
206 |
} /* conv_recipients */ |
BUG (0); |
207 |
|
msg->lpRecips = recip; |
208 |
|
msg->nRecipCount = 1; |
209 |
static char * |
} |
210 |
secure_attachment (gpgme_recipients_t rset, const char * fname) |
else { |
211 |
{ |
msg->lpRecips = recip = NULL; |
212 |
char tmpdir[512+32], * p; |
msg->nRecipCount = 0; |
213 |
gpgme_recipients_t addrs; |
} |
214 |
gpgme_ctx_t ctx; |
|
215 |
gpgme_error_t rc; |
msg->nFileCount = 1; |
216 |
|
attch = (MapiFileDesc *)calloc (1, sizeof *attch); |
217 |
if (strlen (fname) > 200) |
if (!attch) |
218 |
BUG (0); |
BUG (0); |
219 |
GetTempPath (sizeof tmpdir-200, tmpdir); |
attch[0].lpszFileName = strdup (keyfile); |
220 |
p = strrchr (fname, '\\'); |
attch[0].lpszPathName = strdup (keyfile); |
221 |
if (!p) |
msg->lpFiles = attch; |
222 |
strcat (tmpdir, fname); |
|
223 |
else |
rc = mapi_send_mail (hd, 0, msg, MAPI_DIALOG , 0); |
224 |
strcat (tmpdir, fname+(p-fname)+1); |
if (rc == MAPI_E_USER_ABORT) |
225 |
strcat (tmpdir, ".asc"); |
rc = SUCCESS_SUCCESS; |
226 |
|
if (rc != SUCCESS_SUCCESS) |
227 |
rc = gpgme_new (&ctx); |
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ERR); |
228 |
if (rc) |
|
229 |
return NULL; |
free_recip_tab (recip, 1); |
230 |
gpgme_control (ctx, GPGME_CTRL_ARMOR, 1); |
free_files_tab (attch, 1); |
231 |
gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1); |
free_mapi_msg (msg); |
232 |
addrs = conv_recipients (rset); |
mapi_logoff (hd, 0, 0, 0); |
233 |
if (!addrs) { |
|
234 |
msg_box (NULL, _("No valid mail addresses found."), _("Secure Attachment"), MB_ERR); |
return 0; |
235 |
gpgme_release (NULL); |
} |
236 |
return NULL; |
|
237 |
} |
|
238 |
rc = gpgme_op_file_encrypt (ctx, addrs, fname, tmpdir); |
|
239 |
if (rc) |
int |
240 |
log_box (_("Secure Attachment"), MB_ERR, _("Could not encrypt '%s'"), fname); |
mapi_send_pubkey (const char *keyid, char *keyfile) |
241 |
gpgme_recipients_release (addrs); |
{ |
242 |
gpgme_release (ctx); |
winpt_key_s key; |
243 |
return strdup (tmpdir); |
|
244 |
} /* secure_attachment */ |
memset (&key, 0, sizeof (key)); |
245 |
|
if (winpt_get_pubkey (keyid, &key)) |
246 |
|
return -1; |
247 |
static char * |
return mapi_send_pubkey_ext (&key, keyfile, 0); |
248 |
secure_message (gpgme_recipients_t rset, const char * data) |
} |
|
{ |
|
|
gpgme_recipients_t addrs; |
|
|
gpgme_error_t rc; |
|
|
gpgme_data_t in, out; |
|
|
gpgme_ctx_t ctx; |
|
|
char * p; |
|
|
size_t n=0; |
|
|
|
|
|
rc = gpgme_new (&ctx); |
|
|
if (rc) |
|
|
return NULL; |
|
|
gpgme_control (ctx, GPGME_CTRL_ARMOR, 1); |
|
|
gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1); |
|
|
|
|
|
addrs = conv_recipients (rset); |
|
|
rc = gpgme_data_new_from_mem (&in, data, strlen (data), 1); |
|
|
if (rc) { |
|
|
gpgme_release (ctx); |
|
|
return NULL; |
|
|
} |
|
|
gpgme_data_new (&out); |
|
|
|
|
|
rc = gpgme_op_encrypt (ctx, addrs, in, out); |
|
|
if (rc) |
|
|
log_box (_("Secure Message"), MB_ERR, "Could not encrypt the data"); |
|
|
|
|
|
p = gpgme_data_release_and_return_string (out); |
|
|
|
|
|
gpgme_data_release (in); |
|
|
gpgme_release (ctx); |
|
|
gpgme_recipients_release (addrs); |
|
|
|
|
|
return p; |
|
|
} /* secure_message */ |
|
|
|
|
|
|
|
|
int |
|
|
mapi_send_message (gpgme_recipients_t rset, const char * msgtxt, |
|
|
const char * subject, const char ** files, size_t nfiles) |
|
|
{ |
|
|
LHANDLE hd; |
|
|
MapiMessage * msg; |
|
|
MapiRecipDesc * recip; |
|
|
MapiFileDesc * attch; |
|
|
char * p; |
|
|
const char * s; |
|
|
void * ctx=NULL; |
|
|
size_t n, i=0; |
|
|
int rc; |
|
|
|
|
|
if (!init) |
|
|
return 0; |
|
|
|
|
|
rc = mapi_logon (0, NULL, NULL, MAPI_LOGON_UI, 0, &hd); |
|
|
if (rc != SUCCESS_SUCCESS) { |
|
|
MessageBox (NULL, "MAPI Login failed.", "MAPI", MB_ICONWARNING|MB_OK); |
|
|
return rc; |
|
|
} |
|
|
|
|
|
msg = (MapiMessage *)calloc (1, sizeof * msg); |
|
|
p = msg->lpszSubject = strdup (subject); |
|
|
if (!p) |
|
|
BUG (0); |
|
|
p = msg->lpszNoteText = secure_message (rset, msgtxt); |
|
|
if (!p) |
|
|
BUG (0); |
|
|
n = msg->nRecipCount = gpgme_recipients_count (rset); |
|
|
recip = (MapiRecipDesc *)calloc (n+1, sizeof * recip); |
|
|
|
|
|
gpgme_recipients_enum_open (rset, &ctx); |
|
|
while ((s = gpgme_recipients_enum_read (rset, &ctx))) { |
|
|
if (!i) |
|
|
recip[i].ulRecipClass = MAPI_TO; |
|
|
else |
|
|
recip[i].ulRecipClass = MAPI_CC; |
|
|
p = recip[i].lpszName = strdup (s); |
|
|
if (!p) |
|
|
BUG (0); |
|
|
i++; |
|
|
} |
|
|
msg->lpRecips = recip; |
|
|
|
|
|
if (nfiles) { |
|
|
msg->nFileCount = nfiles; |
|
|
attch = (MapiFileDesc *)calloc (nfiles+1, sizeof * attch); |
|
|
for (i=0; i < nfiles; i++) { |
|
|
char * p = secure_attachment (rset, *files); |
|
|
if (!p) |
|
|
continue; |
|
|
attch[i].lpszFileName = strdup (*files); |
|
|
attch[i].lpszPathName = strdup (p); |
|
|
files++; |
|
|
safe_free (p); |
|
|
} |
|
|
msg->lpFiles = attch; |
|
|
} |
|
|
|
|
|
rc = mapi_send_mail (hd, 0, msg, 0, 0); |
|
|
if (rc == MAPI_E_USER_ABORT) |
|
|
rc = SUCCESS_SUCCESS; |
|
|
if (rc != SUCCESS_SUCCESS) |
|
|
MessageBox (NULL, _("Could not sent mail."), "MAPI", MB_ERR); |
|
|
|
|
|
free_recip_tab (recip, n); |
|
|
free_files_tab (attch, nfiles); |
|
|
free_mapi_msg (msg); |
|
|
mapi_logoff (hd, 0, 0, 0); |
|
|
|
|
|
return 0; |
|
|
} /* mapi_send_message */ |
|
|
|
|
|
|
|
|
static int |
|
|
add_recipient (gpgme_recipients_t * r_rset, const char * addr) |
|
|
{ |
|
|
gpgme_keycache_t pub = keycache_get_ctx (1); |
|
|
gpgme_key_t key; |
|
|
gpgme_error_t rc; |
|
|
const char * s; |
|
|
|
|
|
if (!*r_rset) |
|
|
gpgme_recipients_new (&(*r_rset)); |
|
|
rc = gpgme_keycache_find_key (pub, addr, 0, &key); |
|
|
if (rc) { |
|
|
log_box (_("Add Recipient"), MB_ERR, _("Could not find key for '%s'"), addr); |
|
|
return -1; |
|
|
} |
|
|
s = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, NULL, 0); |
|
|
if (s) |
|
|
gpgme_recipients_add_name (*r_rset, s); |
|
|
return 0; |
|
|
} /* add_recipient */ |
|
|
|
|
|
|
|
|
static int |
|
|
add_all_recipients (HWND dlg, int itemid, gpgme_recipients_t * r_rset) |
|
|
{ |
|
|
char buf[1024], * p; |
|
|
int n=0; |
|
|
|
|
|
n = GetDlgItemText (dlg, itemid, buf, sizeof buf-10); |
|
|
if (!n) |
|
|
return -1; |
|
|
p = strtok (buf, ";,"); |
|
|
while (p != NULL) { |
|
|
add_recipient (&*r_rset, p); |
|
|
p = strtok (NULL, ";,"); |
|
|
} |
|
|
return 0; |
|
|
} /* add_all_recipients */ |
|
|
|
|
|
|
|
|
BOOL CALLBACK |
|
|
winpt_mail_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
|
|
{ |
|
|
static gpgme_recipients_t rset=NULL; |
|
|
char subject[128]; |
|
|
char * msgbuf; |
|
|
int n; |
|
|
|
|
|
switch (msg) { |
|
|
case WM_INITDIALOG: |
|
|
center_window (dlg); |
|
|
SetForegroundWindow (dlg); |
|
|
break; |
|
|
|
|
|
case WM_COMMAND: |
|
|
switch (LOWORD (wparam)) { |
|
|
case IDOK: |
|
|
add_all_recipients (dlg, IDC_PMAIL_TO, &rset); |
|
|
add_all_recipients (dlg, IDC_PMAIL_CC, &rset); |
|
|
if (!gpgme_recipients_count (rset)) { |
|
|
msg_box (dlg, _("Please enter a recipient."), _("Mail"), MB_ERR); |
|
|
return FALSE; |
|
|
} |
|
|
n=GetDlgItemText (dlg, IDC_PMAIL_SUBJECT, subject, sizeof subject-1); |
|
|
if (!n) |
|
|
strcpy (subject, ""); |
|
|
n = SendDlgItemMessage (dlg, IDC_PMAIL_MSG, WM_GETTEXTLENGTH, 0, 0); |
|
|
if (!n) { |
|
|
msg_box (dlg, _("Please enter a message."), _("Mail"), MB_ERR); |
|
|
return FALSE; |
|
|
} |
|
|
msgbuf = (char * )calloc (1, n+2); |
|
|
GetDlgItemText (dlg, IDC_PMAIL_MSG, msgbuf, n+1); |
|
|
mapi_send_message (rset, msgbuf, subject, NULL, 0); |
|
|
safe_free (msgbuf); |
|
|
EndDialog (dlg, TRUE); |
|
|
break; |
|
|
|
|
|
case IDCANCEL: |
|
|
EndDialog (dlg, FALSE); |
|
|
break; |
|
|
} |
|
|
break; |
|
|
} |
|
|
|
|
|
return FALSE; |
|
|
} /* winpt_mail_proc */ |
|