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
23 #include "wine/port.h"
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mapi
);
41 /**************************************************************************
42 * MAPISendMail (MAPI32.211)
47 * session [I] Handle to a MAPI session.
48 * uiparam [I] Parent window handle.
49 * message [I] Pointer to a MAPIMessage structure.
51 * reserved [I] Reserved, pass 0.
54 * Success: SUCCESS_SUCCESS
55 * Failure: MAPI_E_FAILURE
58 * The fallback procedure is a temporary hack.
60 ULONG WINAPI
MAPISendMail( LHANDLE session
, ULONG_PTR uiparam
,
61 lpMapiMessage message
, FLAGS flags
, ULONG reserved
)
63 ULONG ret
= MAPI_E_FAILURE
;
64 unsigned int i
, to_count
= 0, cc_count
= 0, bcc_count
= 0;
65 unsigned int to_size
= 0, cc_size
= 0, bcc_size
= 0, subj_size
, body_size
;
67 char *to
= NULL
, *cc
= NULL
, *bcc
= NULL
;
68 const char *address
, *subject
, *body
;
69 static const char format
[] =
70 "mailto:\"%s\"?subject=\"%s\"&cc=\"%s\"&bcc=\"%s\"&body=\"%s\"";
71 char *mailto
= NULL
, *escape
= NULL
;
72 char empty_string
[] = "";
76 TRACE( "(0x%08x 0x%08lx %p 0x%08x 0x%08x)\n", session
, uiparam
,
77 message
, flags
, reserved
);
79 /* Check to see if we have a Simple MAPI provider loaded */
80 if (mapiFunctions
.MAPISendMail
)
81 return mapiFunctions
.MAPISendMail(session
, uiparam
, message
, flags
, reserved
);
83 /* TODO: Check if we have an Extended MAPI provider, if so, implement
84 wrapper around that. */
86 /* Fall back on our own implementation */
87 if (!message
) return MAPI_E_FAILURE
;
89 for (i
= 0; i
< message
->nRecipCount
; i
++)
91 if (!message
->lpRecips
)
93 WARN("No recipients found\n");
94 return MAPI_E_FAILURE
;
97 address
= message
->lpRecips
[i
].lpszAddress
;
100 switch (message
->lpRecips
[i
].ulRecipClass
)
103 TRACE( "From: %s\n", debugstr_a(address
) );
106 TRACE( "To: %s\n", debugstr_a(address
) );
107 to_size
+= lstrlenA( address
) + 1;
110 TRACE( "Cc: %s\n", debugstr_a(address
) );
111 cc_size
+= lstrlenA( address
) + 1;
114 TRACE( "Bcc: %s\n", debugstr_a(address
) );
115 bcc_size
+= lstrlenA( address
) + 1;
118 TRACE( "Unknown recipient class: %d\n",
119 message
->lpRecips
[i
].ulRecipClass
);
123 FIXME("Name resolution and entry identifiers not supported\n");
125 if (message
->nFileCount
) FIXME("Ignoring attachments\n");
127 subject
= message
->lpszSubject
? message
->lpszSubject
: "";
128 body
= message
->lpszNoteText
? message
->lpszNoteText
: "";
130 TRACE( "Subject: %s\n", debugstr_a(subject
) );
131 TRACE( "Body: %s\n", debugstr_a(body
) );
133 subj_size
= lstrlenA( subject
);
134 body_size
= lstrlenA( body
);
136 ret
= MAPI_E_INSUFFICIENT_MEMORY
;
139 to
= HeapAlloc( GetProcessHeap(), 0, to_size
);
145 cc
= HeapAlloc( GetProcessHeap(), 0, cc_size
);
151 bcc
= HeapAlloc( GetProcessHeap(), 0, bcc_size
);
156 if (message
->lpOriginator
)
157 TRACE( "From: %s\n", debugstr_a(message
->lpOriginator
->lpszAddress
) );
159 for (i
= 0; i
< message
->nRecipCount
; i
++)
161 address
= message
->lpRecips
[i
].lpszAddress
;
164 switch (message
->lpRecips
[i
].ulRecipClass
)
167 if (to_count
) lstrcatA( to
, "," );
168 lstrcatA( to
, address
);
172 if (cc_count
) lstrcatA( cc
, "," );
173 lstrcatA( cc
, address
);
177 if (bcc_count
) lstrcatA( bcc
, "," );
178 lstrcatA( bcc
, address
);
184 ret
= MAPI_E_FAILURE
;
185 size
= sizeof(format
) + to_size
+ cc_size
+ bcc_size
+ subj_size
+ body_size
;
187 mailto
= HeapAlloc( GetProcessHeap(), 0, size
);
188 if (!mailto
) goto exit
;
190 sprintf( mailto
, format
, to
? to
: "", subject
, cc
? cc
: "", bcc
? bcc
: "", body
);
193 res
= UrlEscapeA( mailto
, empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
194 if (res
!= E_POINTER
) goto exit
;
196 escape
= HeapAlloc( GetProcessHeap(), 0, size
);
197 if (!escape
) goto exit
;
199 res
= UrlEscapeA( mailto
, escape
, &size
, URL_ESCAPE_SPACES_ONLY
);
200 if (res
!= S_OK
) goto exit
;
202 if ((UINT_PTR
)ShellExecuteA( NULL
, "open", escape
, NULL
, NULL
, 0 ) > 32)
203 ret
= SUCCESS_SUCCESS
;
206 HeapFree( GetProcessHeap(), 0, to
);
207 HeapFree( GetProcessHeap(), 0, cc
);
208 HeapFree( GetProcessHeap(), 0, bcc
);
209 HeapFree( GetProcessHeap(), 0, mailto
);
210 HeapFree( GetProcessHeap(), 0, escape
);
215 ULONG WINAPI
MAPISendDocuments(ULONG_PTR uiparam
, LPSTR delim
, LPSTR paths
,
216 LPSTR filenames
, ULONG reserved
)
218 if (mapiFunctions
.MAPISendDocuments
)
219 return mapiFunctions
.MAPISendDocuments(uiparam
, delim
, paths
, filenames
, reserved
);
221 return MAPI_E_NOT_SUPPORTED
;