ntdll: Translate signal to trap when trap code is 0 on ARM.
[wine.git] / dlls / winemapi / sendmail.c
blobcfb27e55c95a5a0ad3f1c4e1b999f8a116c15f5c
1 /*
2 * MAPISendMail implementation
4 * Copyright 2005 Hans Leidekker
5 * Copyright 2009 Owen Rudge for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdio.h>
26 #include <stdarg.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winerror.h"
33 #include "mapi.h"
34 #include "winreg.h"
35 #include "shellapi.h"
36 #include "shlwapi.h"
37 #include "winternl.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(winemapi);
42 /* Escapes a string for use in mailto: URL */
43 static char *escape_string(char *in, char *empty_string)
45 HRESULT res;
46 DWORD size;
47 char *escaped = NULL;
49 if (!in)
50 return empty_string;
52 size = 1;
53 res = UrlEscapeA(in, empty_string, &size, URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY);
55 if (res == E_POINTER)
57 escaped = HeapAlloc(GetProcessHeap(), 0, size);
59 if (!escaped)
60 return in;
62 /* If for some reason UrlEscape fails, just send the original text */
63 if (UrlEscapeA(in, escaped, &size, URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY) != S_OK)
65 HeapFree(GetProcessHeap(), 0, escaped);
66 escaped = in;
70 return escaped ? escaped : empty_string;
73 /**************************************************************************
74 * MAPISendMail
76 * Send a message using a native mail client.
78 * PARAMS
79 * session [I] Handle to a MAPI session.
80 * uiparam [I] Parent window handle.
81 * message [I] Pointer to a MAPIMessage structure.
82 * flags [I] Flags.
83 * reserved [I] Reserved, pass 0.
85 * RETURNS
86 * Success: SUCCESS_SUCCESS
87 * Failure: MAPI_E_FAILURE
90 ULONG WINAPI MAPISendMail(LHANDLE session, ULONG_PTR uiparam,
91 lpMapiMessage message, FLAGS flags, ULONG reserved)
93 ULONG ret = MAPI_E_FAILURE;
94 unsigned int i, to_count = 0, cc_count = 0, bcc_count = 0;
95 unsigned int to_size = 0, cc_size = 0, bcc_size = 0, subj_size, body_size;
97 char *to = NULL, *cc = NULL, *bcc = NULL, *subject = NULL, *body = NULL;
98 const char *address;
99 static const char format[] =
100 "mailto:\"%s\"?subject=\"%s\"&cc=\"%s\"&bcc=\"%s\"&body=\"%s\"";
101 static const char smtp[] = "smtp:";
102 char *mailto = NULL, *escape = NULL;
103 char empty_string[] = "";
104 HRESULT res;
105 DWORD size;
107 TRACE("(0x%08lx 0x%08lx %p 0x%08x 0x%08x)\n", session, uiparam,
108 message, flags, reserved);
110 if (!message)
111 return MAPI_E_FAILURE;
113 for (i = 0; i < message->nRecipCount; i++)
115 if (!message->lpRecips)
117 WARN("No recipients found\n");
118 return MAPI_E_FAILURE;
121 address = message->lpRecips[i].lpszAddress;
123 if (address)
125 if (!_strnicmp(address, smtp, sizeof(smtp) - 1))
126 address += sizeof(smtp) - 1;
128 switch (message->lpRecips[i].ulRecipClass)
130 case MAPI_ORIG:
131 TRACE("From: %s\n", debugstr_a(address));
132 break;
134 case MAPI_TO:
135 TRACE("To: %s\n", debugstr_a(address));
136 to_size += lstrlenA(address) + 1;
137 break;
139 case MAPI_CC:
140 TRACE("Cc: %s\n", debugstr_a(address));
141 cc_size += lstrlenA(address) + 1;
142 break;
144 case MAPI_BCC:
145 TRACE("Bcc: %s\n", debugstr_a(address));
146 bcc_size += lstrlenA(address) + 1;
147 break;
149 default:
150 TRACE("Unknown recipient class: %d\n",
151 message->lpRecips[i].ulRecipClass);
154 else
155 FIXME("Name resolution and entry identifiers not supported\n");
158 if (message->nFileCount)
160 FIXME("Ignoring %u attachments:\n", message->nFileCount);
161 for (i = 0; i < message->nFileCount; i++)
162 FIXME("\t%s (%s)\n", debugstr_a(message->lpFiles[i].lpszPathName),
163 debugstr_a(message->lpFiles[i].lpszFileName));
166 /* Escape subject and body */
167 subject = escape_string(message->lpszSubject, empty_string);
168 body = escape_string(message->lpszNoteText, empty_string);
170 TRACE("Subject: %s\n", debugstr_a(subject));
171 TRACE("Body: %s\n", debugstr_a(body));
173 subj_size = lstrlenA(subject);
174 body_size = lstrlenA(body);
176 ret = MAPI_E_INSUFFICIENT_MEMORY;
178 if (to_size)
180 to = HeapAlloc(GetProcessHeap(), 0, to_size);
182 if (!to)
183 goto exit;
185 to[0] = 0;
188 if (cc_size)
190 cc = HeapAlloc(GetProcessHeap(), 0, cc_size);
192 if (!cc)
193 goto exit;
195 cc[0] = 0;
198 if (bcc_size)
200 bcc = HeapAlloc(GetProcessHeap(), 0, bcc_size);
202 if (!bcc)
203 goto exit;
205 bcc[0] = 0;
208 if (message->lpOriginator)
209 TRACE("From: %s\n", debugstr_a(message->lpOriginator->lpszAddress));
211 for (i = 0; i < message->nRecipCount; i++)
213 address = message->lpRecips[i].lpszAddress;
215 if (address)
217 if (!_strnicmp(address, smtp, sizeof(smtp) - 1))
218 address += sizeof(smtp) - 1;
220 switch (message->lpRecips[i].ulRecipClass)
222 case MAPI_TO:
223 if (to_count)
224 lstrcatA(to, ",");
226 lstrcatA(to, address);
227 to_count++;
228 break;
230 case MAPI_CC:
231 if (cc_count)
232 lstrcatA(cc, ",");
234 lstrcatA(cc, address);
235 cc_count++;
236 break;
238 case MAPI_BCC:
239 if (bcc_count)
240 lstrcatA(bcc, ",");
242 lstrcatA(bcc, address);
243 bcc_count++;
244 break;
248 ret = MAPI_E_FAILURE;
249 size = sizeof(format) + to_size + cc_size + bcc_size + subj_size + body_size;
251 mailto = HeapAlloc(GetProcessHeap(), 0, size);
253 if (!mailto)
254 goto exit;
256 sprintf(mailto, format, to ? to : "", subject, cc ? cc : "", bcc ? bcc : "", body);
258 size = 1;
259 res = UrlEscapeA(mailto, empty_string, &size, URL_ESCAPE_SPACES_ONLY);
261 if (res != E_POINTER)
262 goto exit;
264 escape = HeapAlloc(GetProcessHeap(), 0, size);
266 if (!escape)
267 goto exit;
269 res = UrlEscapeA(mailto, escape, &size, URL_ESCAPE_SPACES_ONLY);
271 if (res != S_OK)
272 goto exit;
274 TRACE("Executing winebrowser.exe with parameters '%s'\n", debugstr_a(escape));
276 if ((UINT_PTR) ShellExecuteA(NULL, "open", "winebrowser.exe", escape, NULL, 0) > 32)
277 ret = SUCCESS_SUCCESS;
279 exit:
280 HeapFree(GetProcessHeap(), 0, to);
281 HeapFree(GetProcessHeap(), 0, cc);
282 HeapFree(GetProcessHeap(), 0, bcc);
283 HeapFree(GetProcessHeap(), 0, mailto);
284 HeapFree(GetProcessHeap(), 0, escape);
286 if (subject != empty_string)
287 HeapFree(GetProcessHeap(), 0, subject);
289 if (body != empty_string)
290 HeapFree(GetProcessHeap(), 0, body);
292 return ret;
295 ULONG WINAPI MAPISendDocuments(ULONG_PTR uiparam, LPSTR delim, LPSTR paths,
296 LPSTR filenames, ULONG reserved)
298 return MAPI_E_NOT_SUPPORTED;