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