po: Update Russian translation.
[wine/multimedia.git] / dlls / winemapi / sendmail.c
blob93f0569a5a90ed55999cbd63f3d6f0e363fda3ff
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 "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(winemapi);
41 /**************************************************************************
42 * MAPISendMail
44 * Send a message using a native mail client.
46 * PARAMS
47 * session [I] Handle to a MAPI session.
48 * uiparam [I] Parent window handle.
49 * message [I] Pointer to a MAPIMessage structure.
50 * flags [I] Flags.
51 * reserved [I] Reserved, pass 0.
53 * RETURNS
54 * Success: SUCCESS_SUCCESS
55 * Failure: MAPI_E_FAILURE
58 ULONG WINAPI MAPISendMail(LHANDLE session, ULONG_PTR uiparam,
59 lpMapiMessage message, FLAGS flags, ULONG reserved)
61 ULONG ret = MAPI_E_FAILURE;
62 unsigned int i, to_count = 0, cc_count = 0, bcc_count = 0;
63 unsigned int to_size = 0, cc_size = 0, bcc_size = 0, subj_size, body_size;
65 char *to = NULL, *cc = NULL, *bcc = NULL;
66 const char *address, *subject, *body;
67 static const char format[] =
68 "mailto:\"%s\"?subject=\"%s\"&cc=\"%s\"&bcc=\"%s\"&body=\"%s\"";
69 static const char smtp[] = "smtp:";
70 char *mailto = NULL, *escape = NULL;
71 char empty_string[] = "";
72 HRESULT res;
73 DWORD size;
75 TRACE("(0x%08lx 0x%08lx %p 0x%08x 0x%08x)\n", session, uiparam,
76 message, flags, reserved);
78 if (!message)
79 return MAPI_E_FAILURE;
81 for (i = 0; i < message->nRecipCount; i++)
83 if (!message->lpRecips)
85 WARN("No recipients found\n");
86 return MAPI_E_FAILURE;
89 address = message->lpRecips[i].lpszAddress;
91 if (address)
93 if (!strncasecmp(address, smtp, sizeof(smtp) - 1))
94 address += sizeof(smtp) - 1;
96 switch (message->lpRecips[i].ulRecipClass)
98 case MAPI_ORIG:
99 TRACE("From: %s\n", debugstr_a(address));
100 break;
102 case MAPI_TO:
103 TRACE("To: %s\n", debugstr_a(address));
104 to_size += lstrlenA(address) + 1;
105 break;
107 case MAPI_CC:
108 TRACE("Cc: %s\n", debugstr_a(address));
109 cc_size += lstrlenA(address) + 1;
110 break;
112 case MAPI_BCC:
113 TRACE("Bcc: %s\n", debugstr_a(address));
114 bcc_size += lstrlenA(address) + 1;
115 break;
117 default:
118 TRACE("Unknown recipient class: %d\n",
119 message->lpRecips[i].ulRecipClass);
122 else
123 FIXME("Name resolution and entry identifiers not supported\n");
126 if (message->nFileCount)
127 FIXME("Ignoring attachments\n");
129 subject = message->lpszSubject ? message->lpszSubject : "";
130 body = message->lpszNoteText ? message->lpszNoteText : "";
132 TRACE("Subject: %s\n", debugstr_a(subject));
133 TRACE("Body: %s\n", debugstr_a(body));
135 subj_size = lstrlenA(subject);
136 body_size = lstrlenA(body);
138 ret = MAPI_E_INSUFFICIENT_MEMORY;
140 if (to_size)
142 to = HeapAlloc(GetProcessHeap(), 0, to_size);
144 if (!to)
145 goto exit;
147 to[0] = 0;
150 if (cc_size)
152 cc = HeapAlloc(GetProcessHeap(), 0, cc_size);
154 if (!cc)
155 goto exit;
157 cc[0] = 0;
160 if (bcc_size)
162 bcc = HeapAlloc(GetProcessHeap(), 0, bcc_size);
164 if (!bcc)
165 goto exit;
167 bcc[0] = 0;
170 if (message->lpOriginator)
171 TRACE("From: %s\n", debugstr_a(message->lpOriginator->lpszAddress));
173 for (i = 0; i < message->nRecipCount; i++)
175 address = message->lpRecips[i].lpszAddress;
177 if (address)
179 if (!strncasecmp(address, smtp, sizeof(smtp) - 1))
180 address += sizeof(smtp) - 1;
182 switch (message->lpRecips[i].ulRecipClass)
184 case MAPI_TO:
185 if (to_count)
186 lstrcatA(to, ",");
188 lstrcatA(to, address);
189 to_count++;
190 break;
192 case MAPI_CC:
193 if (cc_count)
194 lstrcatA(cc, ",");
196 lstrcatA(cc, address);
197 cc_count++;
198 break;
200 case MAPI_BCC:
201 if (bcc_count)
202 lstrcatA(bcc, ",");
204 lstrcatA(bcc, address);
205 bcc_count++;
206 break;
210 ret = MAPI_E_FAILURE;
211 size = sizeof(format) + to_size + cc_size + bcc_size + subj_size + body_size;
213 mailto = HeapAlloc(GetProcessHeap(), 0, size);
215 if (!mailto)
216 goto exit;
218 sprintf(mailto, format, to ? to : "", subject, cc ? cc : "", bcc ? bcc : "", body);
220 size = 1;
221 res = UrlEscapeA(mailto, empty_string, &size, URL_ESCAPE_SPACES_ONLY);
223 if (res != E_POINTER)
224 goto exit;
226 escape = HeapAlloc(GetProcessHeap(), 0, size);
228 if (!escape)
229 goto exit;
231 res = UrlEscapeA(mailto, escape, &size, URL_ESCAPE_SPACES_ONLY);
233 if (res != S_OK)
234 goto exit;
236 TRACE("Executing winebrowser.exe with parameters '%s'\n", debugstr_a(escape));
238 if ((UINT_PTR) ShellExecuteA(NULL, "open", "winebrowser.exe", escape, NULL, 0) > 32)
239 ret = SUCCESS_SUCCESS;
241 exit:
242 HeapFree(GetProcessHeap(), 0, to);
243 HeapFree(GetProcessHeap(), 0, cc);
244 HeapFree(GetProcessHeap(), 0, bcc);
245 HeapFree(GetProcessHeap(), 0, mailto);
246 HeapFree(GetProcessHeap(), 0, escape);
248 return ret;
251 ULONG WINAPI MAPISendDocuments(ULONG_PTR uiparam, LPSTR delim, LPSTR paths,
252 LPSTR filenames, ULONG reserved)
254 return MAPI_E_NOT_SUPPORTED;