dplayx: Introduce impl_from_IDirectPlayLobby3A().
[wine] / dlls / mapi32 / sendmail.c
1 /*
2  * MAPISendMail implementation
3  *
4  * Copyright 2005 Hans Leidekker
5  * Copyright 2009 Owen Rudge for CodeWeavers
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdio.h>
26 #include <stdarg.h>
27
28 #define COBJMACROS
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winerror.h"
33 #include "winuser.h"
34 #include "objbase.h"
35 #include "objidl.h"
36 #include "mapi.h"
37 #include "mapix.h"
38 #include "mapiutil.h"
39 #include "mapidefs.h"
40 #include "winreg.h"
41 #include "shellapi.h"
42 #include "shlwapi.h"
43 #include "wine/debug.h"
44 #include "util.h"
45 #include "res.h"
46
47 WINE_DEFAULT_DEBUG_CHANNEL(mapi);
48
49 #define READ_BUF_SIZE    4096
50
51 #define STORE_UNICODE_OK  0x00040000
52
53 static LPSTR convert_from_unicode(LPCWSTR wstr)
54 {
55     LPSTR str;
56     DWORD len;
57
58     if (!wstr)
59         return NULL;
60
61     len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
62     str = HeapAlloc(GetProcessHeap(), 0, len);
63     WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
64
65     return str;
66 }
67
68 static LPWSTR convert_to_unicode(LPSTR str)
69 {
70     LPWSTR wstr;
71     DWORD len;
72
73     if (!str)
74         return NULL;
75
76     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
77     wstr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
78     MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, len);
79
80     return wstr;
81 }
82
83 /*
84    Internal function to send a message via Extended MAPI. Wrapper around the Simple
85    MAPI function MAPISendMail.
86 */
87 static ULONG sendmail_extended_mapi(LHANDLE mapi_session, ULONG_PTR uiparam, lpMapiMessageW message,
88     FLAGS flags)
89 {
90     ULONG tags[] = {1, 0};
91     char *subjectA = NULL, *bodyA = NULL;
92     ULONG retval = MAPI_E_FAILURE;
93     IMAPISession *session = NULL;
94     BOOL unicode_aware = FALSE;
95     IMAPITable* msg_table;
96     LPSRowSet rows = NULL;
97     IMsgStore* msg_store;
98     IMAPIFolder* folder = NULL, *draft_folder = NULL;
99     LPENTRYID entry_id;
100     LPSPropValue props;
101     ULONG entry_len;
102     DWORD obj_type;
103     IMessage* msg;
104     ULONG values;
105     HRESULT ret;
106
107     TRACE("Using Extended MAPI wrapper for MAPISendMail\n");
108
109     /* Attempt to log on via Extended MAPI */
110
111     ret = MAPILogonEx(0, NULL, NULL, MAPI_EXTENDED | MAPI_USE_DEFAULT | MAPI_NEW_SESSION, &session);
112     TRACE("MAPILogonEx: %x\n", ret);
113
114     if (ret != S_OK)
115     {
116         retval = MAPI_E_LOGIN_FAILURE;
117         goto cleanup;
118     }
119
120     /* Open the default message store */
121
122     if (IMAPISession_GetMsgStoresTable(session, 0, &msg_table) == S_OK)
123     {
124         /* We want the default store */
125         SizedSPropTagArray(2, columns) = {2, {PR_ENTRYID, PR_DEFAULT_STORE}};
126
127         /* Set the columns we want */
128         if (IMAPITable_SetColumns(msg_table, (LPSPropTagArray) &columns, 0) == S_OK)
129         {
130             while (1)
131             {
132                 if (IMAPITable_QueryRows(msg_table, 1, 0, &rows) != S_OK)
133                 {
134                     MAPIFreeBuffer(rows);
135                     rows = NULL;
136                 }
137                 else if (rows->cRows != 1)
138                 {
139                     FreeProws(rows);
140                     rows = NULL;
141                 }
142                 else
143                 {
144                     /* If it's not the default store, try the next row */
145                     if (!rows->aRow[0].lpProps[1].Value.b)
146                     {
147                         FreeProws(rows);
148                         continue;
149                     }
150                 }
151
152                 break;
153             }
154         }
155
156         IMAPITable_Release(msg_table);
157     }
158
159     /* Did we manage to get the right store? */
160     if (!rows)
161         goto logoff;
162
163     /* Open the message store */
164     IMAPISession_OpenMsgStore(session, 0, rows->aRow[0].lpProps[0].Value.bin.cb,
165                               (ENTRYID *) rows->aRow[0].lpProps[0].Value.bin.lpb, NULL,
166                               MDB_NO_DIALOG | MAPI_BEST_ACCESS, &msg_store);
167
168     /* We don't need this any more */
169     FreeProws(rows);
170
171     /* Check if the message store supports Unicode */
172     tags[1] = PR_STORE_SUPPORT_MASK;
173     ret = IMsgStore_GetProps(msg_store, (LPSPropTagArray) tags, 0, &values, &props);
174
175     if ((ret == S_OK) && (props[0].Value.l & STORE_UNICODE_OK))
176         unicode_aware = TRUE;
177     else
178     {
179         /* Don't convert to ANSI */
180         if (flags & MAPI_FORCE_UNICODE)
181         {
182             WARN("No Unicode-capable mail client, and MAPI_FORCE_UNICODE is specified. MAPISendMail failed.\n");
183             retval = MAPI_E_UNICODE_NOT_SUPPORTED;
184             IMsgStore_Release(msg_store);
185             goto logoff;
186         }
187     }
188
189     /* First open the inbox, from which the drafts folder can be opened */
190     if (IMsgStore_GetReceiveFolder(msg_store, NULL, 0, &entry_len, &entry_id, NULL) == S_OK)
191     {
192         IMsgStore_OpenEntry(msg_store, entry_len, entry_id, NULL, 0, &obj_type, (LPUNKNOWN*) &folder);
193         MAPIFreeBuffer(entry_id);
194     }
195
196     tags[1] = PR_IPM_DRAFTS_ENTRYID;
197
198     /* Open the drafts folder, or failing that, try asking the message store for the outbox */
199     if ((folder == NULL) || ((ret = IMAPIFolder_GetProps(folder, (LPSPropTagArray) tags, 0, &values, &props)) != S_OK))
200     {
201         TRACE("Unable to open Drafts folder; opening Outbox instead\n");
202         tags[1] = PR_IPM_OUTBOX_ENTRYID;
203         ret = IMsgStore_GetProps(msg_store, (LPSPropTagArray) tags, 0, &values, &props);
204     }
205
206     if (ret != S_OK)
207         goto logoff;
208
209     IMsgStore_OpenEntry(msg_store, props[0].Value.bin.cb, (LPENTRYID) props[0].Value.bin.lpb,
210         NULL, MAPI_MODIFY, &obj_type, (LPUNKNOWN *) &draft_folder);
211
212     /* Create a new message */
213     if (IMAPIFolder_CreateMessage(draft_folder, NULL, 0, &msg) == S_OK)
214     {
215         ULONG token;
216         SPropValue p;
217
218         /* Define message properties */
219         p.ulPropTag = PR_MESSAGE_FLAGS;
220         p.Value.l = MSGFLAG_FROMME | MSGFLAG_UNSENT;
221
222         IMessage_SetProps(msg, 1, &p, NULL);
223
224         p.ulPropTag = PR_SENTMAIL_ENTRYID;
225         p.Value.bin.cb = props[0].Value.bin.cb;
226         p.Value.bin.lpb = props[0].Value.bin.lpb;
227         IMessage_SetProps(msg, 1,&p, NULL);
228
229         /* Set message subject */
230         if (message->lpszSubject)
231         {
232             if (unicode_aware)
233             {
234                 p.ulPropTag = PR_SUBJECT_W;
235                 p.Value.lpszW = message->lpszSubject;
236             }
237             else
238             {
239                 subjectA = convert_from_unicode(message->lpszSubject);
240
241                 p.ulPropTag = PR_SUBJECT_A;
242                 p.Value.lpszA = subjectA;
243             }
244
245             IMessage_SetProps(msg, 1, &p, NULL);
246         }
247
248         /* Set message body */
249         if (message->lpszNoteText)
250         {
251             LPSTREAM stream = NULL;
252
253             if (IMessage_OpenProperty(msg, unicode_aware ? PR_BODY_W : PR_BODY_A, &IID_IStream, 0,
254                 MAPI_MODIFY | MAPI_CREATE, (LPUNKNOWN*) &stream) == S_OK)
255             {
256                 if (unicode_aware)
257                     IStream_Write(stream, message->lpszNoteText, (lstrlenW(message->lpszNoteText)+1) * sizeof(WCHAR), NULL);
258                 else
259                 {
260                     bodyA = convert_from_unicode(message->lpszNoteText);
261                     IStream_Write(stream, bodyA, strlen(bodyA)+1, NULL);
262                 }
263
264                 IStream_Release(stream);
265             }
266         }
267
268         /* Add message attachments */
269         if (message->nFileCount > 0)
270         {
271             ULONG num_attach = 0;
272             unsigned int i;
273
274             for (i = 0; i < message->nFileCount; i++)
275             {
276                 IAttach* attachment = NULL;
277                 char *filenameA = NULL;
278                 SPropValue prop[4];
279                 LPCWSTR filename;
280                 HANDLE file;
281
282                 if (!message->lpFiles[i].lpszPathName)
283                     continue;
284
285                 /* Open the attachment for reading */
286                 file = CreateFileW(message->lpFiles[i].lpszPathName, GENERIC_READ, FILE_SHARE_READ,
287                     NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
288
289                 if (file == INVALID_HANDLE_VALUE)
290                     continue;
291
292                 /* Check if a display filename has been given; if not, get one ourselves from path name */
293                 filename = message->lpFiles[i].lpszFileName;
294
295                 if (!filename)
296                 {
297                     int j;
298
299                     filename = message->lpFiles[i].lpszPathName;
300
301                     for (j = lstrlenW(message->lpFiles[i].lpszPathName)-1; j >= 0; j--)
302                     {
303                         if (message->lpFiles[i].lpszPathName[i] == '\\' ||
304                             message->lpFiles[i].lpszPathName[i] == '/')
305                         {
306                             filename = &message->lpFiles[i].lpszPathName[i+1];
307                             break;
308                         }
309                     }
310                 }
311
312                 TRACE("Attachment %u path: '%s'; filename: '%s'\n", i, debugstr_w(message->lpFiles[i].lpszPathName),
313                     debugstr_w(filename));
314
315                 /* Create the attachment */
316                 if (IMessage_CreateAttach(msg, NULL, 0, &num_attach, &attachment) != S_OK)
317                 {
318                     TRACE("Unable to create attachment\n");
319                     CloseHandle(file);
320                     continue;
321                 }
322
323                 /* Set the attachment properties */
324                 ZeroMemory(prop, sizeof(prop));
325
326                 prop[0].ulPropTag = PR_ATTACH_METHOD;
327                 prop[0].Value.ul = ATTACH_BY_VALUE;
328
329                 if (unicode_aware)
330                 {
331                     prop[1].ulPropTag = PR_ATTACH_LONG_FILENAME_W;
332                     prop[1].Value.lpszW = (LPWSTR) filename;
333                     prop[2].ulPropTag = PR_ATTACH_FILENAME_W;
334                     prop[2].Value.lpszW = (LPWSTR) filename;
335                 }
336                 else
337                 {
338                     filenameA = convert_from_unicode(filename);
339
340                     prop[1].ulPropTag = PR_ATTACH_LONG_FILENAME_A;
341                     prop[1].Value.lpszA = (LPSTR) filenameA;
342                     prop[2].ulPropTag = PR_ATTACH_FILENAME_A;
343                     prop[2].Value.lpszA = (LPSTR) filenameA;
344
345                 }
346
347                 prop[3].ulPropTag = PR_RENDERING_POSITION;
348                 prop[3].Value.l = -1;
349
350                 if (IAttach_SetProps(attachment, 4, prop, NULL) == S_OK)
351                 {
352                     LPSTREAM stream = NULL;
353
354                     if (IAttach_OpenProperty(attachment, PR_ATTACH_DATA_BIN, &IID_IStream, 0,
355                         MAPI_MODIFY | MAPI_CREATE, (LPUNKNOWN*) &stream) == S_OK)
356                     {
357                         BYTE data[READ_BUF_SIZE];
358                         DWORD size = 0, read, written;
359
360                         while (ReadFile(file, data, READ_BUF_SIZE, &read, NULL) && (read != 0))
361                         {
362                             IStream_Write(stream, data, read, &written);
363                             size += read;
364                         }
365
366                         TRACE("%d bytes written of attachment\n", size);
367
368                         IStream_Commit(stream, STGC_DEFAULT);
369                         IStream_Release(stream);
370
371                         prop[0].ulPropTag = PR_ATTACH_SIZE;
372                         prop[0].Value.ul = size;
373                         IAttach_SetProps(attachment, 1, prop, NULL);
374
375                         IAttach_SaveChanges(attachment, KEEP_OPEN_READONLY);
376                         num_attach++;
377                     }
378                 }
379
380                 CloseHandle(file);
381                 IAttach_Release(attachment);
382
383                 HeapFree(GetProcessHeap(), 0, filenameA);
384             }
385         }
386
387         IMessage_SaveChanges(msg, KEEP_OPEN_READWRITE);
388
389         /* Prepare the message form */
390
391         if (IMAPISession_PrepareForm(session, NULL, msg, &token) == S_OK)
392         {
393             ULONG access = 0, status = 0, message_flags = 0, pc = 0;
394             ULONG pT[2] = {1, PR_MSG_STATUS};
395
396             /* Retrieve message status, flags, access rights and class */
397
398             if (IMessage_GetProps(msg, (LPSPropTagArray) pT, 0, &pc, &props) == S_OK)
399             {
400                 status = props->Value.ul;
401                 MAPIFreeBuffer(props);
402             }
403
404             pT[1] = PR_MESSAGE_FLAGS;
405
406             if (IMessage_GetProps(msg, (LPSPropTagArray) pT, 0, &pc, &props) == S_OK)
407             {
408                 message_flags = props->Value.ul;
409                 MAPIFreeBuffer(props);
410             }
411
412             pT[1] = PR_ACCESS;
413
414             if (IMessage_GetProps(msg, (LPSPropTagArray) pT, 0, &pc, &props) == S_OK)
415             {
416                 access = props->Value.ul;
417                 MAPIFreeBuffer(props);
418             }
419
420             pT[1] = PR_MESSAGE_CLASS_A;
421
422             if (IMessage_GetProps(msg, (LPSPropTagArray) pT, 0, &pc, &props) == S_OK)
423             {
424                 /* Show the message form (edit window) */
425
426                 ret = IMAPISession_ShowForm(session, 0, msg_store, draft_folder, NULL,
427                                             token, NULL, 0, status, message_flags, access,
428                                             props->Value.lpszA);
429
430                 switch (ret)
431                 {
432                     case S_OK:
433                         retval = SUCCESS_SUCCESS;
434                         break;
435
436                     case MAPI_E_USER_CANCEL:
437                         retval = MAPI_E_USER_ABORT;
438                         break;
439
440                     default:
441                         TRACE("ShowForm failure: %x\n", ret);
442                         break;
443                 }
444             }
445         }
446
447         IMessage_Release(msg);
448     }
449
450     /* Free up the resources we've used */
451     IMAPIFolder_Release(draft_folder);
452     if (folder) IMAPIFolder_Release(folder);
453     IMsgStore_Release(msg_store);
454
455     HeapFree(GetProcessHeap(), 0, subjectA);
456     HeapFree(GetProcessHeap(), 0, bodyA);
457
458 logoff: ;
459     IMAPISession_Logoff(session, 0, 0, 0);
460     IMAPISession_Release(session);
461
462 cleanup: ;
463     MAPIUninitialize();
464     return retval;
465 }
466
467 /**************************************************************************
468  *  MAPISendMail        (MAPI32.211)
469  *
470  * Send a mail.
471  *
472  * PARAMS
473  *  session  [I] Handle to a MAPI session.
474  *  uiparam  [I] Parent window handle.
475  *  message  [I] Pointer to a MAPIMessage structure.
476  *  flags    [I] Flags.
477  *  reserved [I] Reserved, pass 0.
478  *
479  * RETURNS
480  *  Success: SUCCESS_SUCCESS
481  *  Failure: MAPI_E_FAILURE
482  *
483  */
484 ULONG WINAPI MAPISendMail( LHANDLE session, ULONG_PTR uiparam,
485     lpMapiMessage message, FLAGS flags, ULONG reserved )
486 {
487     WCHAR msg_title[READ_BUF_SIZE], error_msg[READ_BUF_SIZE];
488
489     /* Check to see if we have a Simple MAPI provider loaded */
490     if (mapiFunctions.MAPISendMail)
491         return mapiFunctions.MAPISendMail(session, uiparam, message, flags, reserved);
492
493     /* Check if we have an Extended MAPI provider - if so, use our wrapper */
494     if (MAPIInitialize(NULL) == S_OK)
495     {
496         MapiMessageW messageW;
497         ULONG ret;
498
499         ZeroMemory(&messageW, sizeof(MapiMessageW));
500
501         /* Convert the entries we need to Unicode */
502         messageW.lpszSubject = convert_to_unicode(message->lpszSubject);
503         messageW.lpszNoteText = convert_to_unicode(message->lpszNoteText);
504         messageW.nFileCount = message->nFileCount;
505
506         if (message->nFileCount && message->lpFiles)
507         {
508             lpMapiFileDescW filesW;
509             unsigned int i;
510
511             filesW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MapiFileDescW) * message->nFileCount);
512
513             for (i = 0; i < message->nFileCount; i++)
514             {
515                 filesW[i].lpszPathName = convert_to_unicode(message->lpFiles[i].lpszPathName);
516                 filesW[i].lpszFileName = convert_to_unicode(message->lpFiles[i].lpszFileName);
517             }
518
519             messageW.lpFiles = filesW;
520         }
521
522         ret = sendmail_extended_mapi(session, uiparam, &messageW, flags);
523
524         /* Now free everything we allocated */
525         if (message->nFileCount && message->lpFiles)
526         {
527             unsigned int i;
528
529             for (i = 0; i < message->nFileCount; i++)
530             {
531                 HeapFree(GetProcessHeap(), 0, messageW.lpFiles[i].lpszPathName);
532                 HeapFree(GetProcessHeap(), 0, messageW.lpFiles[i].lpszFileName);
533             }
534
535             HeapFree(GetProcessHeap(), 0, messageW.lpFiles);
536         }
537
538         HeapFree(GetProcessHeap(), 0, messageW.lpszSubject);
539         HeapFree(GetProcessHeap(), 0, messageW.lpszNoteText);
540
541         return ret;
542     }
543
544     /* Display an error message since we apparently have no mail clients */
545     LoadStringW(hInstMAPI32, IDS_NO_MAPI_CLIENT, error_msg, sizeof(error_msg) / sizeof(WCHAR));
546     LoadStringW(hInstMAPI32, IDS_SEND_MAIL, msg_title, sizeof(msg_title) / sizeof(WCHAR));
547
548     MessageBoxW((HWND) uiparam, error_msg, msg_title, MB_ICONEXCLAMATION);
549
550     return MAPI_E_NOT_SUPPORTED;
551 }
552
553 static lpMapiRecipDesc convert_recipient_from_unicode(lpMapiRecipDescW recipW, lpMapiRecipDesc dest)
554 {
555     lpMapiRecipDesc ret;
556
557     if (!recipW)
558         return NULL;
559
560     if (dest)
561         ret = dest;
562     else
563         ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MapiRecipDesc));
564
565     ret->ulRecipClass = recipW->ulRecipClass;
566     ret->lpszName = convert_from_unicode(recipW->lpszName);
567     ret->lpszAddress = convert_from_unicode(recipW->lpszAddress);
568     ret->ulEIDSize = recipW->ulEIDSize;
569     ret->lpEntryID = recipW->lpEntryID;
570
571     return ret;
572 }
573
574 /**************************************************************************
575  *  MAPISendMailW       (MAPI32.256)
576  *
577  * Send a mail.
578  *
579  * PARAMS
580  *  session  [I] Handle to a MAPI session.
581  *  uiparam  [I] Parent window handle.
582  *  message  [I] Pointer to a MAPIMessageW structure.
583  *  flags    [I] Flags.
584  *  reserved [I] Reserved, pass 0.
585  *
586  * RETURNS
587  *  Success: SUCCESS_SUCCESS
588  *  Failure: MAPI_E_FAILURE
589  *
590  */
591 ULONG WINAPI MAPISendMailW(LHANDLE session, ULONG_PTR uiparam,
592     lpMapiMessageW message, FLAGS flags, ULONG reserved)
593 {
594     WCHAR msg_title[READ_BUF_SIZE], error_msg[READ_BUF_SIZE];
595
596     /* Check to see if we have a Simple MAPI provider loaded */
597     if (mapiFunctions.MAPISendMailW)
598         return mapiFunctions.MAPISendMailW(session, uiparam, message, flags, reserved);
599
600     /* Check if we have an Extended MAPI provider - if so, use our wrapper */
601     if (MAPIInitialize(NULL) == S_OK)
602         return sendmail_extended_mapi(session, uiparam, message, flags);
603
604     if (mapiFunctions.MAPISendMail)
605     {
606         MapiMessage messageA;
607         ULONG ret;
608
609         if (flags & MAPI_FORCE_UNICODE)
610             return MAPI_E_UNICODE_NOT_SUPPORTED;
611
612         /* Convert to ANSI and send to MAPISendMail */
613         ZeroMemory(&messageA, sizeof(MapiMessage));
614
615         messageA.lpszSubject = convert_from_unicode(message->lpszSubject);
616         messageA.lpszNoteText = convert_from_unicode(message->lpszNoteText);
617         messageA.lpszMessageType = convert_from_unicode(message->lpszMessageType);
618         messageA.lpszDateReceived = convert_from_unicode(message->lpszDateReceived);
619         messageA.lpszConversationID = convert_from_unicode(message->lpszConversationID);
620         messageA.flFlags = message->flFlags;
621         messageA.lpOriginator = convert_recipient_from_unicode(message->lpOriginator, NULL);
622         messageA.nRecipCount = message->nRecipCount;
623         messageA.nFileCount = message->nFileCount;
624
625         if (message->nRecipCount && message->lpRecips)
626         {
627             lpMapiRecipDesc recipsA;
628             unsigned int i;
629
630             recipsA = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MapiRecipDesc) * message->nRecipCount);
631
632             for (i = 0; i < message->nRecipCount; i++)
633             {
634                 convert_recipient_from_unicode(&message->lpRecips[i], &recipsA[i]);
635             }
636
637             messageA.lpRecips = recipsA;
638         }
639
640         if (message->nFileCount && message->lpFiles)
641         {
642             lpMapiFileDesc filesA;
643             unsigned int i;
644
645             filesA = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MapiFileDesc) * message->nFileCount);
646
647             for (i = 0; i < message->nFileCount; i++)
648             {
649                 filesA[i].flFlags = message->lpFiles[i].flFlags;
650                 filesA[i].nPosition = message->lpFiles[i].nPosition;
651                 filesA[i].lpszPathName = convert_from_unicode(message->lpFiles[i].lpszPathName);
652                 filesA[i].lpszFileName = convert_from_unicode(message->lpFiles[i].lpszFileName);
653                 filesA[i].lpFileType = message->lpFiles[i].lpFileType;
654             }
655
656             messageA.lpFiles = filesA;
657         }
658
659         ret = mapiFunctions.MAPISendMail(session, uiparam, &messageA, flags, reserved);
660
661         /* Now free everything we allocated */
662         if (message->lpOriginator)
663         {
664             HeapFree(GetProcessHeap(), 0, messageA.lpOriginator->lpszName);
665             HeapFree(GetProcessHeap(), 0, messageA.lpOriginator->lpszAddress);
666             HeapFree(GetProcessHeap(), 0, messageA.lpOriginator);
667         }
668
669         if (message->nRecipCount && message->lpRecips)
670         {
671             unsigned int i;
672
673             for (i = 0; i < message->nRecipCount; i++)
674             {
675                 HeapFree(GetProcessHeap(), 0, messageA.lpRecips[i].lpszName);
676                 HeapFree(GetProcessHeap(), 0, messageA.lpRecips[i].lpszAddress);
677             }
678
679             HeapFree(GetProcessHeap(), 0, messageA.lpRecips);
680         }
681
682         if (message->nFileCount && message->lpFiles)
683         {
684             unsigned int i;
685
686             for (i = 0; i < message->nFileCount; i++)
687             {
688                 HeapFree(GetProcessHeap(), 0, messageA.lpFiles[i].lpszPathName);
689                 HeapFree(GetProcessHeap(), 0, messageA.lpFiles[i].lpszFileName);
690             }
691
692             HeapFree(GetProcessHeap(), 0, messageA.lpFiles);
693         }
694
695         HeapFree(GetProcessHeap(), 0, messageA.lpszSubject);
696         HeapFree(GetProcessHeap(), 0, messageA.lpszNoteText);
697         HeapFree(GetProcessHeap(), 0, messageA.lpszDateReceived);
698         HeapFree(GetProcessHeap(), 0, messageA.lpszConversationID);
699
700         return ret;
701     }
702
703     /* Display an error message since we apparently have no mail clients */
704     LoadStringW(hInstMAPI32, IDS_NO_MAPI_CLIENT, error_msg, sizeof(error_msg) / sizeof(WCHAR));
705     LoadStringW(hInstMAPI32, IDS_SEND_MAIL, msg_title, sizeof(msg_title) / sizeof(WCHAR));
706
707     MessageBoxW((HWND) uiparam, error_msg, msg_title, MB_ICONEXCLAMATION);
708
709     return MAPI_E_NOT_SUPPORTED;
710 }
711
712 ULONG WINAPI MAPISendDocuments(ULONG_PTR uiparam, LPSTR delim, LPSTR paths,
713     LPSTR filenames, ULONG reserved)
714 {
715     if (mapiFunctions.MAPISendDocuments)
716         return mapiFunctions.MAPISendDocuments(uiparam, delim, paths, filenames, reserved);
717
718     return MAPI_E_NOT_SUPPORTED;
719 }