2 * MAPISendMail implementation
4 * Copyright 2005 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mapi
);
39 /**************************************************************************
40 * MAPISendMail (MAPI32.211)
45 * session [I] Handle to a MAPI session.
46 * uiparam [I] Parent window handle.
47 * message [I] Pointer to a MAPIMessage structure.
49 * reserved [I] Reserved, pass 0.
52 * Success: SUCCESS_SUCCESS
53 * Failure: MAPI_E_FAILURE
56 * This is a temporary hack.
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 char *mailto
= NULL
, *escape
= NULL
;
70 char empty_string
[] = "";
74 TRACE( "(0x%08x 0x%08lx %p 0x%08x 0x%08x)\n", session
, uiparam
,
75 message
, flags
, reserved
);
77 if (!message
) return MAPI_E_FAILURE
;
79 for (i
= 0; i
< message
->nRecipCount
; i
++)
81 if (!message
->lpRecips
)
83 WARN("No recipients found\n");
84 return MAPI_E_FAILURE
;
87 address
= message
->lpRecips
[i
].lpszAddress
;
90 switch (message
->lpRecips
[i
].ulRecipClass
)
93 TRACE( "From: %s\n", debugstr_a(address
) );
96 TRACE( "To: %s\n", debugstr_a(address
) );
97 to_size
+= lstrlenA( address
) + 1;
100 TRACE( "Cc: %s\n", debugstr_a(address
) );
101 cc_size
+= lstrlenA( address
) + 1;
104 TRACE( "Bcc: %s\n", debugstr_a(address
) );
105 bcc_size
+= lstrlenA( address
) + 1;
108 TRACE( "Unknown recipient class: %d\n",
109 message
->lpRecips
[i
].ulRecipClass
);
113 FIXME("Name resolution and entry identifiers not supported\n");
115 if (message
->nFileCount
) FIXME("Ignoring attachments\n");
117 subject
= message
->lpszSubject
? message
->lpszSubject
: "";
118 body
= message
->lpszNoteText
? message
->lpszNoteText
: "";
120 TRACE( "Subject: %s\n", debugstr_a(subject
) );
121 TRACE( "Body: %s\n", debugstr_a(body
) );
123 subj_size
= lstrlenA( subject
);
124 body_size
= lstrlenA( body
);
126 ret
= MAPI_E_INSUFFICIENT_MEMORY
;
129 to
= HeapAlloc( GetProcessHeap(), 0, to_size
);
135 cc
= HeapAlloc( GetProcessHeap(), 0, cc_size
);
141 bcc
= HeapAlloc( GetProcessHeap(), 0, bcc_size
);
146 if (message
->lpOriginator
)
147 TRACE( "From: %s\n", debugstr_a(message
->lpOriginator
->lpszAddress
) );
149 for (i
= 0; i
< message
->nRecipCount
; i
++)
151 address
= message
->lpRecips
[i
].lpszAddress
;
154 switch (message
->lpRecips
[i
].ulRecipClass
)
157 if (to_count
) lstrcatA( to
, "," );
158 lstrcatA( to
, address
);
162 if (cc_count
) lstrcatA( cc
, "," );
163 lstrcatA( cc
, address
);
167 if (bcc_count
) lstrcatA( bcc
, "," );
168 lstrcatA( bcc
, address
);
174 ret
= MAPI_E_FAILURE
;
175 size
= sizeof(format
) + to_size
+ cc_size
+ bcc_size
+ subj_size
+ body_size
;
177 mailto
= HeapAlloc( GetProcessHeap(), 0, size
);
178 if (!mailto
) goto exit
;
180 sprintf( mailto
, format
, to
? to
: "", subject
, cc
? cc
: "", bcc
? bcc
: "", body
);
183 res
= UrlEscapeA( mailto
, empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
184 if (res
!= E_POINTER
) goto exit
;
186 escape
= HeapAlloc( GetProcessHeap(), 0, size
);
187 if (!escape
) goto exit
;
189 res
= UrlEscapeA( mailto
, escape
, &size
, URL_ESCAPE_SPACES_ONLY
);
190 if (res
!= S_OK
) goto exit
;
192 if ((UINT_PTR
)ShellExecuteA( NULL
, "open", escape
, NULL
, NULL
, 0 ) > 32)
193 ret
= SUCCESS_SUCCESS
;
196 HeapFree( GetProcessHeap(), 0, to
);
197 HeapFree( GetProcessHeap(), 0, cc
);
198 HeapFree( GetProcessHeap(), 0, bcc
);
199 HeapFree( GetProcessHeap(), 0, mailto
);
200 HeapFree( GetProcessHeap(), 0, escape
);