1ae77b8caSAriel Constenla-Haile /**************************************************************
2ae77b8caSAriel Constenla-Haile *
3ae77b8caSAriel Constenla-Haile * Licensed to the Apache Software Foundation (ASF) under one
4ae77b8caSAriel Constenla-Haile * or more contributor license agreements. See the NOTICE file
5ae77b8caSAriel Constenla-Haile * distributed with this work for additional information
6ae77b8caSAriel Constenla-Haile * regarding copyright ownership. The ASF licenses this file
7ae77b8caSAriel Constenla-Haile * to you under the Apache License, Version 2.0 (the
8ae77b8caSAriel Constenla-Haile * "License"); you may not use this file except in compliance
9ae77b8caSAriel Constenla-Haile * with the License. You may obtain a copy of the License at
10ae77b8caSAriel Constenla-Haile *
11ae77b8caSAriel Constenla-Haile * http://www.apache.org/licenses/LICENSE-2.0
12ae77b8caSAriel Constenla-Haile *
13ae77b8caSAriel Constenla-Haile * Unless required by applicable law or agreed to in writing,
14ae77b8caSAriel Constenla-Haile * software distributed under the License is distributed on an
15ae77b8caSAriel Constenla-Haile * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ae77b8caSAriel Constenla-Haile * KIND, either express or implied. See the License for the
17ae77b8caSAriel Constenla-Haile * specific language governing permissions and limitations
18ae77b8caSAriel Constenla-Haile * under the License.
19ae77b8caSAriel Constenla-Haile *
20ae77b8caSAriel Constenla-Haile *************************************************************/
21ae77b8caSAriel Constenla-Haile
22ae77b8caSAriel Constenla-Haile // MARKER(update_precomp.py): autogen include statement, do not remove
23ae77b8caSAriel Constenla-Haile #include "precompiled_shell.hxx"
24ae77b8caSAriel Constenla-Haile
25ae77b8caSAriel Constenla-Haile #include "sysmailclient.hxx"
26ae77b8caSAriel Constenla-Haile #include "sysmailmsg.hxx"
27ae77b8caSAriel Constenla-Haile
28ae77b8caSAriel Constenla-Haile #include <com/sun/star/system/MailClientFlags.hpp>
29ae77b8caSAriel Constenla-Haile #include <com/sun/star/system/XMailMessage.hpp>
30ae77b8caSAriel Constenla-Haile
31ae77b8caSAriel Constenla-Haile #include <osl/diagnose.h>
32ae77b8caSAriel Constenla-Haile #include <osl/process.h>
33ae77b8caSAriel Constenla-Haile #include <rtl/bootstrap.hxx>
34ae77b8caSAriel Constenla-Haile #include <osl/file.hxx>
35ae77b8caSAriel Constenla-Haile #include <rtl/ustrbuf.hxx>
36ae77b8caSAriel Constenla-Haile
37ae77b8caSAriel Constenla-Haile #define WIN32_LEAN_AND_MEAN
38ae77b8caSAriel Constenla-Haile #if defined _MSC_VER
39ae77b8caSAriel Constenla-Haile #pragma warning(push, 1)
40ae77b8caSAriel Constenla-Haile #endif
41ae77b8caSAriel Constenla-Haile #include <windows.h>
42ae77b8caSAriel Constenla-Haile #include <mapi.h>
43ae77b8caSAriel Constenla-Haile #if defined _MSC_VER
44ae77b8caSAriel Constenla-Haile #pragma warning(pop)
45ae77b8caSAriel Constenla-Haile #endif
46ae77b8caSAriel Constenla-Haile
47ae77b8caSAriel Constenla-Haile #include <process.h>
48ae77b8caSAriel Constenla-Haile #include <vector>
49ae77b8caSAriel Constenla-Haile
50ae77b8caSAriel Constenla-Haile using css::uno::UNO_QUERY;
51ae77b8caSAriel Constenla-Haile using css::uno::Reference;
52ae77b8caSAriel Constenla-Haile using css::uno::Exception;
53ae77b8caSAriel Constenla-Haile using css::uno::RuntimeException;
54ae77b8caSAriel Constenla-Haile using css::uno::Sequence;
55ae77b8caSAriel Constenla-Haile using css::lang::IllegalArgumentException;
56ae77b8caSAriel Constenla-Haile
57ae77b8caSAriel Constenla-Haile using css::system::XMailClient;
58ae77b8caSAriel Constenla-Haile using css::system::XMailMessage;
59ae77b8caSAriel Constenla-Haile using css::system::XMailMessage;
60ae77b8caSAriel Constenla-Haile using css::system::MailClientFlags::NO_USER_INTERFACE;
61ae77b8caSAriel Constenla-Haile using css::system::MailClientFlags::NO_LOGON_DIALOG;
62ae77b8caSAriel Constenla-Haile
63ae77b8caSAriel Constenla-Haile using rtl::OUString;
64ae77b8caSAriel Constenla-Haile using rtl::OUStringBuffer;
65ae77b8caSAriel Constenla-Haile
66ae77b8caSAriel Constenla-Haile namespace shell
67ae77b8caSAriel Constenla-Haile {
68ae77b8caSAriel Constenla-Haile namespace /* private */
69ae77b8caSAriel Constenla-Haile {
70ae77b8caSAriel Constenla-Haile typedef std::vector<rtl::OUString> StringList_t;
71ae77b8caSAriel Constenla-Haile typedef StringList_t::const_iterator StringListIterator_t;
72ae77b8caSAriel Constenla-Haile
73ae77b8caSAriel Constenla-Haile const rtl::OUString TO = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--to"));
74ae77b8caSAriel Constenla-Haile const rtl::OUString CC = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--cc"));
75ae77b8caSAriel Constenla-Haile const rtl::OUString BCC = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--bcc"));
76ae77b8caSAriel Constenla-Haile const rtl::OUString FROM = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--from"));
77ae77b8caSAriel Constenla-Haile const rtl::OUString SUBJECT = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--subject"));
78ae77b8caSAriel Constenla-Haile const rtl::OUString BODY = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--body"));
79ae77b8caSAriel Constenla-Haile const rtl::OUString ATTACH = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--attach"));
80ae77b8caSAriel Constenla-Haile const rtl::OUString FLAG_MAPI_DIALOG = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--mapi-dialog"));
81ae77b8caSAriel Constenla-Haile const rtl::OUString FLAG_MAPI_LOGON_UI = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("--mapi-logon-ui"));
82ae77b8caSAriel Constenla-Haile
quoteString(const OUString & rStr)83ae77b8caSAriel Constenla-Haile static OUString quoteString( const OUString& rStr )
84ae77b8caSAriel Constenla-Haile {
85ae77b8caSAriel Constenla-Haile rtl::OUStringBuffer quoted;
86ae77b8caSAriel Constenla-Haile quoted.append(sal_Unicode('"'));
87ae77b8caSAriel Constenla-Haile quoted.append(rStr);
88ae77b8caSAriel Constenla-Haile quoted.append(sal_Unicode('"'));
89ae77b8caSAriel Constenla-Haile
90ae77b8caSAriel Constenla-Haile return quoted.makeStringAndClear();
91ae77b8caSAriel Constenla-Haile }
92ae77b8caSAriel Constenla-Haile
quoteAndEscape(const OUString & rStr)93ae77b8caSAriel Constenla-Haile static OUString quoteAndEscape( const OUString &rStr )
94ae77b8caSAriel Constenla-Haile {
95ae77b8caSAriel Constenla-Haile OUStringBuffer aBuffer;
96ae77b8caSAriel Constenla-Haile aBuffer.append(sal_Unicode('"'));
97ae77b8caSAriel Constenla-Haile
98ae77b8caSAriel Constenla-Haile sal_Int32 nIndex = rStr.indexOf(sal_Unicode('"'));
99ae77b8caSAriel Constenla-Haile if ( nIndex == -1 )
100ae77b8caSAriel Constenla-Haile aBuffer.append( rStr );
101ae77b8caSAriel Constenla-Haile else
102ae77b8caSAriel Constenla-Haile {
103ae77b8caSAriel Constenla-Haile const sal_Unicode *pStart = rStr.getStr();
104ae77b8caSAriel Constenla-Haile const sal_Unicode *pFrom = pStart;
105ae77b8caSAriel Constenla-Haile const sal_Int32 nLen = rStr.getLength();
106ae77b8caSAriel Constenla-Haile sal_Int32 nPrev = 0;;
107ae77b8caSAriel Constenla-Haile do
108ae77b8caSAriel Constenla-Haile {
109ae77b8caSAriel Constenla-Haile aBuffer.append( pFrom, nIndex - nPrev );
110ae77b8caSAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "\\\"" ) );
111ae77b8caSAriel Constenla-Haile nIndex++;
112ae77b8caSAriel Constenla-Haile pFrom = pStart + nIndex;
113ae77b8caSAriel Constenla-Haile nPrev = nIndex;
114ae77b8caSAriel Constenla-Haile }
115ae77b8caSAriel Constenla-Haile while ( ( nIndex = rStr.indexOf( '"' , nIndex ) ) != -1 );
116ae77b8caSAriel Constenla-Haile
117ae77b8caSAriel Constenla-Haile aBuffer.append( pFrom, nLen - nPrev );
118ae77b8caSAriel Constenla-Haile }
119ae77b8caSAriel Constenla-Haile
120ae77b8caSAriel Constenla-Haile aBuffer.append(sal_Unicode('"'));
121ae77b8caSAriel Constenla-Haile
122ae77b8caSAriel Constenla-Haile return aBuffer.makeStringAndClear();
123ae77b8caSAriel Constenla-Haile }
124ae77b8caSAriel Constenla-Haile
125ae77b8caSAriel Constenla-Haile /** @internal
126ae77b8caSAriel Constenla-Haile look if an alternative program is configured
127ae77b8caSAriel Constenla-Haile which should be used as senddoc executable */
getAlternativeSenddocUrl()128ae77b8caSAriel Constenla-Haile static rtl::OUString getAlternativeSenddocUrl()
129ae77b8caSAriel Constenla-Haile {
130ae77b8caSAriel Constenla-Haile rtl::OUString altSenddocUrl;
131ae77b8caSAriel Constenla-Haile HKEY hkey;
132*599cc5b4SOliver-Rainer Wittmann LONG lret = RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\OpenOffice\\SendAsEMailClient", &hkey);
133ae77b8caSAriel Constenla-Haile if (lret == ERROR_SUCCESS)
134ae77b8caSAriel Constenla-Haile {
135ae77b8caSAriel Constenla-Haile wchar_t buff[MAX_PATH];
136ae77b8caSAriel Constenla-Haile LONG sz = sizeof(buff);
137ae77b8caSAriel Constenla-Haile lret = RegQueryValueW(hkey, NULL, buff, &sz);
138ae77b8caSAriel Constenla-Haile if (lret == ERROR_SUCCESS)
139ae77b8caSAriel Constenla-Haile {
140ae77b8caSAriel Constenla-Haile osl::FileBase::getFileURLFromSystemPath(reinterpret_cast<const sal_Unicode*>(buff), altSenddocUrl);
141ae77b8caSAriel Constenla-Haile }
142ae77b8caSAriel Constenla-Haile RegCloseKey(hkey);
143ae77b8caSAriel Constenla-Haile }
144ae77b8caSAriel Constenla-Haile return altSenddocUrl;
145ae77b8caSAriel Constenla-Haile }
146ae77b8caSAriel Constenla-Haile
147ae77b8caSAriel Constenla-Haile /**
148ae77b8caSAriel Constenla-Haile Returns the absolute file Url of the senddoc executable.
149ae77b8caSAriel Constenla-Haile
150ae77b8caSAriel Constenla-Haile @returns
151ae77b8caSAriel Constenla-Haile the absolute file Url of the senddoc executable. In case
152ae77b8caSAriel Constenla-Haile of an error an empty string will be returned.
153ae77b8caSAriel Constenla-Haile */
getSenddocUrl()154ae77b8caSAriel Constenla-Haile static rtl::OUString getSenddocUrl()
155ae77b8caSAriel Constenla-Haile {
156ae77b8caSAriel Constenla-Haile rtl::OUString senddocUrl = getAlternativeSenddocUrl();
157ae77b8caSAriel Constenla-Haile
158ae77b8caSAriel Constenla-Haile if (senddocUrl.getLength() == 0)
159ae77b8caSAriel Constenla-Haile {
160ae77b8caSAriel Constenla-Haile senddocUrl = rtl::OUString(
161ae77b8caSAriel Constenla-Haile RTL_CONSTASCII_USTRINGPARAM(
162ae77b8caSAriel Constenla-Haile "$OOO_BASE_DIR/program/senddoc.exe"));
163ae77b8caSAriel Constenla-Haile rtl::Bootstrap::expandMacros(senddocUrl); //TODO: detect failure
164ae77b8caSAriel Constenla-Haile }
165ae77b8caSAriel Constenla-Haile return senddocUrl;
166ae77b8caSAriel Constenla-Haile }
167ae77b8caSAriel Constenla-Haile
168ae77b8caSAriel Constenla-Haile /**
169ae77b8caSAriel Constenla-Haile Execute Senddoc.exe which a MAPI wrapper.
170ae77b8caSAriel Constenla-Haile @param rCommandArgs
171ae77b8caSAriel Constenla-Haile [in] the arguments to be passed to Senddoc.exe
172ae77b8caSAriel Constenla-Haile @returns
173ae77b8caSAriel Constenla-Haile <TRUE/> on success.
174ae77b8caSAriel Constenla-Haile */
executeSenddoc(const StringList_t & rCommandArgs)175ae77b8caSAriel Constenla-Haile static bool executeSenddoc(const StringList_t& rCommandArgs)
176ae77b8caSAriel Constenla-Haile {
177ae77b8caSAriel Constenla-Haile rtl::OUString senddocUrl = getSenddocUrl();
178ae77b8caSAriel Constenla-Haile if (senddocUrl.getLength() == 0)
179ae77b8caSAriel Constenla-Haile return false;
180ae77b8caSAriel Constenla-Haile
181ae77b8caSAriel Constenla-Haile oslProcess proc;
182ae77b8caSAriel Constenla-Haile oslProcessError err = osl_Process_E_Unknown;
183ae77b8caSAriel Constenla-Haile
184ae77b8caSAriel Constenla-Haile /* for efficiency reasons we are using a 'bad' cast here
185ae77b8caSAriel Constenla-Haile as a vector or rtl::OUStrings is nothing else than
186ae77b8caSAriel Constenla-Haile an array of pointers to rtl_uString's */
187ae77b8caSAriel Constenla-Haile err = osl_executeProcess(
188ae77b8caSAriel Constenla-Haile senddocUrl.pData,
189ae77b8caSAriel Constenla-Haile (rtl_uString**)&rCommandArgs[0],
190ae77b8caSAriel Constenla-Haile rCommandArgs.size(),
191ae77b8caSAriel Constenla-Haile osl_Process_WAIT | osl_Process_DETACHED,
192ae77b8caSAriel Constenla-Haile NULL,
193ae77b8caSAriel Constenla-Haile NULL,
194ae77b8caSAriel Constenla-Haile NULL,
195ae77b8caSAriel Constenla-Haile 0,
196ae77b8caSAriel Constenla-Haile &proc);
197ae77b8caSAriel Constenla-Haile
198ae77b8caSAriel Constenla-Haile if (err != osl_Process_E_None)
199ae77b8caSAriel Constenla-Haile return false;
200ae77b8caSAriel Constenla-Haile
201ae77b8caSAriel Constenla-Haile oslProcessInfo procInfo;
202ae77b8caSAriel Constenla-Haile procInfo.Size = sizeof(oslProcessInfo);
203ae77b8caSAriel Constenla-Haile osl_getProcessInfo(proc, osl_Process_EXITCODE, &procInfo);
204ae77b8caSAriel Constenla-Haile osl_freeProcessHandle(proc);
205ae77b8caSAriel Constenla-Haile return (procInfo.Code == SUCCESS_SUCCESS);
206ae77b8caSAriel Constenla-Haile }
207ae77b8caSAriel Constenla-Haile } // namespace private
208ae77b8caSAriel Constenla-Haile
209ae77b8caSAriel Constenla-Haile
createMailMessage()210ae77b8caSAriel Constenla-Haile Reference<XMailMessage> SAL_CALL WinSysMailClient::createMailMessage()
211ae77b8caSAriel Constenla-Haile throw (RuntimeException)
212ae77b8caSAriel Constenla-Haile {
213ae77b8caSAriel Constenla-Haile return Reference<XMailMessage>( new WinSysMailMsg() );
214ae77b8caSAriel Constenla-Haile }
215ae77b8caSAriel Constenla-Haile
216ae77b8caSAriel Constenla-Haile /**
217ae77b8caSAriel Constenla-Haile Assemble a command line for SendDoc.exe out of the members
218ae77b8caSAriel Constenla-Haile of the supplied XMailMessage.
219ae77b8caSAriel Constenla-Haile
220ae77b8caSAriel Constenla-Haile @param xMailMessage
221ae77b8caSAriel Constenla-Haile [in] the mail message.
222ae77b8caSAriel Constenla-Haile
223ae77b8caSAriel Constenla-Haile @param aFlags
224ae77b8caSAriel Constenla-Haile [in] different flags to be used with the system mail service.
225ae77b8caSAriel Constenla-Haile
226ae77b8caSAriel Constenla-Haile @param rCommandArgs
227ae77b8caSAriel Constenla-Haile [in|out] a buffer for the command line arguments. The buffer
228ae77b8caSAriel Constenla-Haile is assumed to be empty.
229ae77b8caSAriel Constenla-Haile
230ae77b8caSAriel Constenla-Haile @throws com::sun::star::lang::IllegalArgumentException
231ae77b8caSAriel Constenla-Haile if an invalid file URL has been detected in the attachment list.
232ae77b8caSAriel Constenla-Haile */
assembleCommandLine(const Reference<XMailMessage> & xMailMessage,sal_Int32 aFlag,StringList_t & rCommandArgs)233ae77b8caSAriel Constenla-Haile void WinSysMailClient::assembleCommandLine(
234ae77b8caSAriel Constenla-Haile const Reference<XMailMessage>& xMailMessage,
235ae77b8caSAriel Constenla-Haile sal_Int32 aFlag,
236ae77b8caSAriel Constenla-Haile StringList_t& rCommandArgs)
237ae77b8caSAriel Constenla-Haile {
238ae77b8caSAriel Constenla-Haile OSL_ENSURE(rCommandArgs.size() == 0, "Provided command argument buffer not empty");
239ae77b8caSAriel Constenla-Haile
240ae77b8caSAriel Constenla-Haile rtl::OUString to = xMailMessage->getRecipient();
241ae77b8caSAriel Constenla-Haile if (to.getLength() > 0)
242ae77b8caSAriel Constenla-Haile {
243ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(TO);
244ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(to);
245ae77b8caSAriel Constenla-Haile }
246ae77b8caSAriel Constenla-Haile
247ae77b8caSAriel Constenla-Haile Sequence<rtl::OUString> ccRecipients = xMailMessage->getCcRecipient();
248ae77b8caSAriel Constenla-Haile for (int i = 0; i < ccRecipients.getLength(); i++)
249ae77b8caSAriel Constenla-Haile {
250ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(CC);
251ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(ccRecipients[i]);
252ae77b8caSAriel Constenla-Haile }
253ae77b8caSAriel Constenla-Haile
254ae77b8caSAriel Constenla-Haile Sequence<rtl::OUString> bccRecipients = xMailMessage->getBccRecipient();
255ae77b8caSAriel Constenla-Haile for (int i = 0; i < bccRecipients.getLength(); i++)
256ae77b8caSAriel Constenla-Haile {
257ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(BCC);
258ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(bccRecipients[i]);
259ae77b8caSAriel Constenla-Haile }
260ae77b8caSAriel Constenla-Haile
261ae77b8caSAriel Constenla-Haile rtl::OUString from = xMailMessage->getOriginator();
262ae77b8caSAriel Constenla-Haile if (from.getLength() > 0)
263ae77b8caSAriel Constenla-Haile {
264ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(FROM);
265ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(from);
266ae77b8caSAriel Constenla-Haile }
267ae77b8caSAriel Constenla-Haile
268ae77b8caSAriel Constenla-Haile Sequence<rtl::OUString> attachments = xMailMessage->getAttachement();
269ae77b8caSAriel Constenla-Haile for (int i = 0; i < attachments.getLength(); i++)
270ae77b8caSAriel Constenla-Haile {
271ae77b8caSAriel Constenla-Haile rtl::OUString sysPath;
272ae77b8caSAriel Constenla-Haile osl::FileBase::RC err = osl::FileBase::getSystemPathFromFileURL(attachments[i], sysPath);
273ae77b8caSAriel Constenla-Haile if (err != osl::FileBase::E_None)
274ae77b8caSAriel Constenla-Haile throw IllegalArgumentException(
275ae77b8caSAriel Constenla-Haile rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid attachment file URL")),
276ae77b8caSAriel Constenla-Haile static_cast<XMailClient*>(this),
277ae77b8caSAriel Constenla-Haile 1);
278ae77b8caSAriel Constenla-Haile
279ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(ATTACH);
280ae77b8caSAriel Constenla-Haile rCommandArgs.push_back( quoteString( sysPath ) );
281ae77b8caSAriel Constenla-Haile }
282ae77b8caSAriel Constenla-Haile
283ae77b8caSAriel Constenla-Haile rtl::OUString body = xMailMessage->getBody();
284ae77b8caSAriel Constenla-Haile if (body.getLength()>0)
285ae77b8caSAriel Constenla-Haile {
286ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(BODY);
287ae77b8caSAriel Constenla-Haile rCommandArgs.push_back( quoteAndEscape( body ) );
288ae77b8caSAriel Constenla-Haile }
289ae77b8caSAriel Constenla-Haile
290ae77b8caSAriel Constenla-Haile rtl::OUString subject = xMailMessage->getSubject();
291ae77b8caSAriel Constenla-Haile if (subject.getLength() > 0)
292ae77b8caSAriel Constenla-Haile {
293ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(SUBJECT);
294ae77b8caSAriel Constenla-Haile rCommandArgs.push_back( quoteAndEscape( subject ) );
295ae77b8caSAriel Constenla-Haile }
296ae77b8caSAriel Constenla-Haile
297ae77b8caSAriel Constenla-Haile if (!(aFlag & NO_USER_INTERFACE))
298ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(FLAG_MAPI_DIALOG);
299ae77b8caSAriel Constenla-Haile
300ae77b8caSAriel Constenla-Haile if (!(aFlag & NO_LOGON_DIALOG))
301ae77b8caSAriel Constenla-Haile rCommandArgs.push_back(FLAG_MAPI_LOGON_UI);
302ae77b8caSAriel Constenla-Haile }
303ae77b8caSAriel Constenla-Haile
sendMailMessage(const Reference<XMailMessage> & xMailMessage,sal_Int32 aFlag)304ae77b8caSAriel Constenla-Haile void SAL_CALL WinSysMailClient::sendMailMessage(
305ae77b8caSAriel Constenla-Haile const Reference<XMailMessage>& xMailMessage,
306ae77b8caSAriel Constenla-Haile sal_Int32 aFlag)
307ae77b8caSAriel Constenla-Haile throw (IllegalArgumentException, Exception, RuntimeException)
308ae77b8caSAriel Constenla-Haile {
309ae77b8caSAriel Constenla-Haile validateParameter(xMailMessage, aFlag);
310ae77b8caSAriel Constenla-Haile
311ae77b8caSAriel Constenla-Haile StringList_t senddocParams;
312ae77b8caSAriel Constenla-Haile assembleCommandLine(xMailMessage, aFlag, senddocParams);
313ae77b8caSAriel Constenla-Haile
314ae77b8caSAriel Constenla-Haile if (!executeSenddoc(senddocParams))
315ae77b8caSAriel Constenla-Haile throw Exception(
316ae77b8caSAriel Constenla-Haile rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Send email failed")),
317ae77b8caSAriel Constenla-Haile static_cast<XMailClient*>(this));
318ae77b8caSAriel Constenla-Haile }
319ae77b8caSAriel Constenla-Haile
validateParameter(const Reference<XMailMessage> & xMailMessage,sal_Int32 aFlag)320ae77b8caSAriel Constenla-Haile void WinSysMailClient::validateParameter(
321ae77b8caSAriel Constenla-Haile const Reference<XMailMessage>& xMailMessage,
322ae77b8caSAriel Constenla-Haile sal_Int32 aFlag )
323ae77b8caSAriel Constenla-Haile {
324ae77b8caSAriel Constenla-Haile if (!xMailMessage.is())
325ae77b8caSAriel Constenla-Haile throw IllegalArgumentException(
326ae77b8caSAriel Constenla-Haile rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Empty mail message reference")),
327ae77b8caSAriel Constenla-Haile static_cast<XMailClient*>(this),
328ae77b8caSAriel Constenla-Haile 1);
329ae77b8caSAriel Constenla-Haile
330ae77b8caSAriel Constenla-Haile // #93077#
331ae77b8caSAriel Constenla-Haile OSL_ENSURE(!(aFlag & NO_LOGON_DIALOG), "Flag NO_LOGON_DIALOG has currently no effect");
332ae77b8caSAriel Constenla-Haile
333ae77b8caSAriel Constenla-Haile // check the flags, the allowed range is 0 - (2^n - 1)
334ae77b8caSAriel Constenla-Haile if (aFlag < 0 || aFlag > 3)
335ae77b8caSAriel Constenla-Haile throw IllegalArgumentException(
336ae77b8caSAriel Constenla-Haile rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid flag value")),
337ae77b8caSAriel Constenla-Haile static_cast<XMailClient*>(this),
338ae77b8caSAriel Constenla-Haile 2);
339ae77b8caSAriel Constenla-Haile
340ae77b8caSAriel Constenla-Haile // check if a recipient is specified of the flags NO_USER_INTERFACE is specified
341ae77b8caSAriel Constenla-Haile if ((aFlag & NO_USER_INTERFACE) && !xMailMessage->getRecipient().getLength())
342ae77b8caSAriel Constenla-Haile throw IllegalArgumentException(
343ae77b8caSAriel Constenla-Haile rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No recipient specified")),
344ae77b8caSAriel Constenla-Haile static_cast<XMailClient*>(this),
345ae77b8caSAriel Constenla-Haile 1);
346ae77b8caSAriel Constenla-Haile }
347ae77b8caSAriel Constenla-Haile
348ae77b8caSAriel Constenla-Haile }
349