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 "syscmdmail.hxx"
26*ae77b8caSAriel Constenla-Haile #include "cmdmailmsg.hxx"
27*ae77b8caSAriel Constenla-Haile 
28*ae77b8caSAriel Constenla-Haile #include <com/sun/star/system/MailClientFlags.hpp>
29*ae77b8caSAriel Constenla-Haile #include <com/sun/star/container/XNameAccess.hpp>
30*ae77b8caSAriel Constenla-Haile #include <com/sun/star/beans/PropertyValue.hpp>
31*ae77b8caSAriel Constenla-Haile #include <com/sun/star/beans/XPropertySet.hpp>
32*ae77b8caSAriel Constenla-Haile 
33*ae77b8caSAriel Constenla-Haile #include <osl/file.hxx>
34*ae77b8caSAriel Constenla-Haile #include <osl/thread.hxx>
35*ae77b8caSAriel Constenla-Haile #include <rtl/bootstrap.hxx>
36*ae77b8caSAriel Constenla-Haile #include <rtl/strbuf.hxx>
37*ae77b8caSAriel Constenla-Haile 
38*ae77b8caSAriel Constenla-Haile #include <unistd.h>
39*ae77b8caSAriel Constenla-Haile 
40*ae77b8caSAriel Constenla-Haile using com::sun::star::beans::PropertyValue;
41*ae77b8caSAriel Constenla-Haile using com::sun::star::container::XNameAccess;
42*ae77b8caSAriel Constenla-Haile using com::sun::star::system::XMailClient;
43*ae77b8caSAriel Constenla-Haile using com::sun::star::system::XMailMessage;
44*ae77b8caSAriel Constenla-Haile using rtl::OString;
45*ae77b8caSAriel Constenla-Haile using rtl::OStringBuffer;
46*ae77b8caSAriel Constenla-Haile using rtl::OUString;
47*ae77b8caSAriel Constenla-Haile using rtl::OUStringToOString;
48*ae77b8caSAriel Constenla-Haile 
49*ae77b8caSAriel Constenla-Haile using namespace com::sun::star::lang;
50*ae77b8caSAriel Constenla-Haile using namespace com::sun::star::system::MailClientFlags;
51*ae77b8caSAriel Constenla-Haile using namespace com::sun::star::uno;
52*ae77b8caSAriel Constenla-Haile 
53*ae77b8caSAriel Constenla-Haile #define COMP_SERVICE_NAME  "com.sun.star.system.SystemMailProvider"
54*ae77b8caSAriel Constenla-Haile #define COMP_IMPL_NAME     "com.sun.star.comp.system.unx.SystemMailProvider"
55*ae77b8caSAriel Constenla-Haile 
56*ae77b8caSAriel Constenla-Haile namespace shell
57*ae77b8caSAriel Constenla-Haile {
58*ae77b8caSAriel Constenla-Haile 
59*ae77b8caSAriel Constenla-Haile namespace
60*ae77b8caSAriel Constenla-Haile {
escapeDoubleQuotes(OStringBuffer & rBuffer,const OUString & ustr,rtl_TextEncoding iEncoding)61*ae77b8caSAriel Constenla-Haile     static void escapeDoubleQuotes( OStringBuffer &rBuffer,
62*ae77b8caSAriel Constenla-Haile                                     const OUString &ustr,
63*ae77b8caSAriel Constenla-Haile                                     rtl_TextEncoding iEncoding )
64*ae77b8caSAriel Constenla-Haile     {
65*ae77b8caSAriel Constenla-Haile         const OString rStr( OUStringToOString( ustr, iEncoding ) );
66*ae77b8caSAriel Constenla-Haile         sal_Int32 nIndex = rStr.indexOf('"');
67*ae77b8caSAriel Constenla-Haile         if ( nIndex == -1 )
68*ae77b8caSAriel Constenla-Haile             rBuffer.append( rStr );
69*ae77b8caSAriel Constenla-Haile         else
70*ae77b8caSAriel Constenla-Haile         {
71*ae77b8caSAriel Constenla-Haile             const sal_Char *pStart = rStr.getStr();
72*ae77b8caSAriel Constenla-Haile             const sal_Char *pFrom = pStart;
73*ae77b8caSAriel Constenla-Haile             const sal_Int32 nLen = rStr.getLength();
74*ae77b8caSAriel Constenla-Haile             sal_Int32 nPrev = 0;;
75*ae77b8caSAriel Constenla-Haile             do
76*ae77b8caSAriel Constenla-Haile             {
77*ae77b8caSAriel Constenla-Haile                 rBuffer.append( pFrom, nIndex - nPrev );
78*ae77b8caSAriel Constenla-Haile                 rBuffer.append( RTL_CONSTASCII_STRINGPARAM( "\\\"" ) );
79*ae77b8caSAriel Constenla-Haile                 nIndex++;
80*ae77b8caSAriel Constenla-Haile                 pFrom = pStart + nIndex;
81*ae77b8caSAriel Constenla-Haile                 nPrev = nIndex;
82*ae77b8caSAriel Constenla-Haile             }
83*ae77b8caSAriel Constenla-Haile             while ( ( nIndex = rStr.indexOf( '"' , nIndex ) ) != -1  );
84*ae77b8caSAriel Constenla-Haile 
85*ae77b8caSAriel Constenla-Haile             rBuffer.append( pFrom, nLen - nPrev );
86*ae77b8caSAriel Constenla-Haile         }
87*ae77b8caSAriel Constenla-Haile     }
88*ae77b8caSAriel Constenla-Haile }
89*ae77b8caSAriel Constenla-Haile 
SystemCommandMail(const Reference<XComponentContext> & xContext)90*ae77b8caSAriel Constenla-Haile SystemCommandMail::SystemCommandMail(
91*ae77b8caSAriel Constenla-Haile     const Reference< XComponentContext >& xContext )
92*ae77b8caSAriel Constenla-Haile     : SystemCommandMail_Base( m_aMutex )
93*ae77b8caSAriel Constenla-Haile     , m_xContext( xContext )
94*ae77b8caSAriel Constenla-Haile {
95*ae77b8caSAriel Constenla-Haile     try
96*ae77b8caSAriel Constenla-Haile     {
97*ae77b8caSAriel Constenla-Haile         m_xConfigurationProvider.set(
98*ae77b8caSAriel Constenla-Haile             m_xContext->getServiceManager()->createInstanceWithContext(
99*ae77b8caSAriel Constenla-Haile                 OUString( RTL_CONSTASCII_USTRINGPARAM(
100*ae77b8caSAriel Constenla-Haile                     "com.sun.star.configuration.ConfigurationProvider") ),
101*ae77b8caSAriel Constenla-Haile                 m_xContext ),
102*ae77b8caSAriel Constenla-Haile             UNO_QUERY );
103*ae77b8caSAriel Constenla-Haile     }
104*ae77b8caSAriel Constenla-Haile     catch(...){}
105*ae77b8caSAriel Constenla-Haile }
106*ae77b8caSAriel Constenla-Haile 
~SystemCommandMail()107*ae77b8caSAriel Constenla-Haile SystemCommandMail::~SystemCommandMail()
108*ae77b8caSAriel Constenla-Haile {
109*ae77b8caSAriel Constenla-Haile     m_xConfigurationProvider.clear();
110*ae77b8caSAriel Constenla-Haile     m_xContext.clear();
111*ae77b8caSAriel Constenla-Haile }
112*ae77b8caSAriel Constenla-Haile 
113*ae77b8caSAriel Constenla-Haile Reference< XMailClient > SAL_CALL
queryMailClient()114*ae77b8caSAriel Constenla-Haile SystemCommandMail::queryMailClient()
115*ae77b8caSAriel Constenla-Haile throw ( RuntimeException )
116*ae77b8caSAriel Constenla-Haile {
117*ae77b8caSAriel Constenla-Haile     return Reference< XMailClient >(
118*ae77b8caSAriel Constenla-Haile         static_cast < cppu::OWeakObject * >( this ), UNO_QUERY );
119*ae77b8caSAriel Constenla-Haile }
120*ae77b8caSAriel Constenla-Haile 
121*ae77b8caSAriel Constenla-Haile 
122*ae77b8caSAriel Constenla-Haile Reference< XMailMessage > SAL_CALL
createMailMessage()123*ae77b8caSAriel Constenla-Haile SystemCommandMail::createMailMessage()
124*ae77b8caSAriel Constenla-Haile throw ( RuntimeException )
125*ae77b8caSAriel Constenla-Haile {
126*ae77b8caSAriel Constenla-Haile     return Reference< XMailMessage >(
127*ae77b8caSAriel Constenla-Haile         static_cast< cppu::OWeakObject *>(
128*ae77b8caSAriel Constenla-Haile             new CmdMailMsg() ),
129*ae77b8caSAriel Constenla-Haile         UNO_QUERY );
130*ae77b8caSAriel Constenla-Haile }
131*ae77b8caSAriel Constenla-Haile 
132*ae77b8caSAriel Constenla-Haile 
133*ae77b8caSAriel Constenla-Haile void SAL_CALL
sendMailMessage(const Reference<XMailMessage> & xMailMessage,sal_Int32)134*ae77b8caSAriel Constenla-Haile SystemCommandMail::sendMailMessage(
135*ae77b8caSAriel Constenla-Haile     const Reference< XMailMessage >& xMailMessage,
136*ae77b8caSAriel Constenla-Haile     sal_Int32 /*aFlag*/ )
137*ae77b8caSAriel Constenla-Haile throw (IllegalArgumentException, Exception, RuntimeException)
138*ae77b8caSAriel Constenla-Haile {
139*ae77b8caSAriel Constenla-Haile     osl::ClearableMutexGuard aGuard( m_aMutex );
140*ae77b8caSAriel Constenla-Haile     Reference< XMultiServiceFactory > xConfigurationProvider = m_xConfigurationProvider;
141*ae77b8caSAriel Constenla-Haile     aGuard.clear();
142*ae77b8caSAriel Constenla-Haile 
143*ae77b8caSAriel Constenla-Haile     if ( ! xMailMessage.is() )
144*ae77b8caSAriel Constenla-Haile     {
145*ae77b8caSAriel Constenla-Haile         throw IllegalArgumentException(
146*ae77b8caSAriel Constenla-Haile             OUString(RTL_CONSTASCII_USTRINGPARAM( "No message specified" )),
147*ae77b8caSAriel Constenla-Haile             static_cast < XMailClient * > (this), 1 );
148*ae77b8caSAriel Constenla-Haile     }
149*ae77b8caSAriel Constenla-Haile 
150*ae77b8caSAriel Constenla-Haile     if( ! xConfigurationProvider.is() )
151*ae77b8caSAriel Constenla-Haile     {
152*ae77b8caSAriel Constenla-Haile         throw Exception(
153*ae77b8caSAriel Constenla-Haile             OUString(RTL_CONSTASCII_USTRINGPARAM( "Can not access configuration" )),
154*ae77b8caSAriel Constenla-Haile             static_cast < XMailClient * > (this) );
155*ae77b8caSAriel Constenla-Haile     }
156*ae77b8caSAriel Constenla-Haile 
157*ae77b8caSAriel Constenla-Haile     OStringBuffer aBuffer;
158*ae77b8caSAriel Constenla-Haile     aBuffer.append("\"");
159*ae77b8caSAriel Constenla-Haile 
160*ae77b8caSAriel Constenla-Haile     OUString aProgramURL(RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program/senddoc"));
161*ae77b8caSAriel Constenla-Haile     rtl::Bootstrap::expandMacros(aProgramURL);
162*ae77b8caSAriel Constenla-Haile     OUString aProgram;
163*ae77b8caSAriel Constenla-Haile     if ( osl::FileBase::E_None != osl::FileBase::getSystemPathFromFileURL(aProgramURL, aProgram))
164*ae77b8caSAriel Constenla-Haile     {
165*ae77b8caSAriel Constenla-Haile         throw Exception(
166*ae77b8caSAriel Constenla-Haile             OUString(RTL_CONSTASCII_USTRINGPARAM("Cound not convert executable path")),
167*ae77b8caSAriel Constenla-Haile             static_cast < XMailClient * > (this));
168*ae77b8caSAriel Constenla-Haile     }
169*ae77b8caSAriel Constenla-Haile 
170*ae77b8caSAriel Constenla-Haile     const rtl_TextEncoding iEncoding = osl_getThreadTextEncoding();
171*ae77b8caSAriel Constenla-Haile     aBuffer.append(OUStringToOString(aProgram, iEncoding));
172*ae77b8caSAriel Constenla-Haile     aBuffer.append("\" ");
173*ae77b8caSAriel Constenla-Haile 
174*ae77b8caSAriel Constenla-Haile     try
175*ae77b8caSAriel Constenla-Haile     {
176*ae77b8caSAriel Constenla-Haile         // Query XNameAccess interface of the org.openoffice.Office.Common/ExternalMailer
177*ae77b8caSAriel Constenla-Haile         // configuration node to retriece the users preferred email application. This may
178*ae77b8caSAriel Constenla-Haile         // transparently by redirected to e.g. the corresponding GConf setting in GNOME.
179*ae77b8caSAriel Constenla-Haile         OUString aConfigRoot = OUString(
180*ae77b8caSAriel Constenla-Haile             RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Office.Common/ExternalMailer" ) );
181*ae77b8caSAriel Constenla-Haile 
182*ae77b8caSAriel Constenla-Haile         PropertyValue aProperty;
183*ae77b8caSAriel Constenla-Haile         aProperty.Name = OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath" ));
184*ae77b8caSAriel Constenla-Haile         aProperty.Value = makeAny( aConfigRoot );
185*ae77b8caSAriel Constenla-Haile 
186*ae77b8caSAriel Constenla-Haile         Sequence< Any > aArgumentList( 1 );
187*ae77b8caSAriel Constenla-Haile         aArgumentList[0] = makeAny( aProperty );
188*ae77b8caSAriel Constenla-Haile 
189*ae77b8caSAriel Constenla-Haile         Reference< XNameAccess > xNameAccess =
190*ae77b8caSAriel Constenla-Haile             Reference< XNameAccess > (
191*ae77b8caSAriel Constenla-Haile                 xConfigurationProvider->createInstanceWithArguments(
192*ae77b8caSAriel Constenla-Haile                     OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" )),
193*ae77b8caSAriel Constenla-Haile                     aArgumentList ),
194*ae77b8caSAriel Constenla-Haile                 UNO_QUERY );
195*ae77b8caSAriel Constenla-Haile 
196*ae77b8caSAriel Constenla-Haile         if( xNameAccess.is() )
197*ae77b8caSAriel Constenla-Haile         {
198*ae77b8caSAriel Constenla-Haile             OUString aMailer;
199*ae77b8caSAriel Constenla-Haile 
200*ae77b8caSAriel Constenla-Haile             // Retrieve the value for "Program" node and append it feed senddoc with it
201*ae77b8caSAriel Constenla-Haile             // using the (undocumented) --mailclient switch
202*ae77b8caSAriel Constenla-Haile             xNameAccess->getByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Program") ) ) >>= aMailer;
203*ae77b8caSAriel Constenla-Haile 
204*ae77b8caSAriel Constenla-Haile             if( aMailer.getLength() )
205*ae77b8caSAriel Constenla-Haile             {
206*ae77b8caSAriel Constenla-Haile                 // make sure we have a system path
207*ae77b8caSAriel Constenla-Haile                 osl::FileBase::getSystemPathFromFileURL( aMailer, aMailer );
208*ae77b8caSAriel Constenla-Haile 
209*ae77b8caSAriel Constenla-Haile                 aBuffer.append("--mailclient ");
210*ae77b8caSAriel Constenla-Haile                 aBuffer.append(OUStringToOString( aMailer, iEncoding ));
211*ae77b8caSAriel Constenla-Haile                 aBuffer.append(" ");
212*ae77b8caSAriel Constenla-Haile             }
213*ae77b8caSAriel Constenla-Haile #ifdef MACOSX
214*ae77b8caSAriel Constenla-Haile             else
215*ae77b8caSAriel Constenla-Haile                 aBuffer.append("--mailclient Mail ");
216*ae77b8caSAriel Constenla-Haile #endif
217*ae77b8caSAriel Constenla-Haile         }
218*ae77b8caSAriel Constenla-Haile 
219*ae77b8caSAriel Constenla-Haile     }
220*ae77b8caSAriel Constenla-Haile     catch( RuntimeException e )
221*ae77b8caSAriel Constenla-Haile     {
222*ae77b8caSAriel Constenla-Haile         OSL_TRACE( "RuntimeException caught accessing configuration provider." );
223*ae77b8caSAriel Constenla-Haile         OSL_TRACE( OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
224*ae77b8caSAriel Constenla-Haile         throw e;
225*ae77b8caSAriel Constenla-Haile     }
226*ae77b8caSAriel Constenla-Haile 
227*ae77b8caSAriel Constenla-Haile     // Append body if set in the message
228*ae77b8caSAriel Constenla-Haile     OUString ustr = xMailMessage->getBody();
229*ae77b8caSAriel Constenla-Haile     if ( ustr.getLength() > 0 )
230*ae77b8caSAriel Constenla-Haile     {
231*ae77b8caSAriel Constenla-Haile         aBuffer.append("--body \"");
232*ae77b8caSAriel Constenla-Haile         escapeDoubleQuotes( aBuffer, ustr, iEncoding );
233*ae77b8caSAriel Constenla-Haile         aBuffer.append("\" ");
234*ae77b8caSAriel Constenla-Haile     }
235*ae77b8caSAriel Constenla-Haile 
236*ae77b8caSAriel Constenla-Haile     // Append subject if set in the message
237*ae77b8caSAriel Constenla-Haile     ustr = xMailMessage->getSubject();
238*ae77b8caSAriel Constenla-Haile     if ( ustr.getLength() > 0 )
239*ae77b8caSAriel Constenla-Haile     {
240*ae77b8caSAriel Constenla-Haile         aBuffer.append("--subject \"");
241*ae77b8caSAriel Constenla-Haile         escapeDoubleQuotes( aBuffer, ustr, iEncoding );
242*ae77b8caSAriel Constenla-Haile         aBuffer.append("\" ");
243*ae77b8caSAriel Constenla-Haile     }
244*ae77b8caSAriel Constenla-Haile 
245*ae77b8caSAriel Constenla-Haile     // Append originator if set in the message
246*ae77b8caSAriel Constenla-Haile     if ( xMailMessage->getOriginator().getLength() > 0 )
247*ae77b8caSAriel Constenla-Haile     {
248*ae77b8caSAriel Constenla-Haile         aBuffer.append("--from \"");
249*ae77b8caSAriel Constenla-Haile         aBuffer.append(OUStringToOString(xMailMessage->getOriginator(), iEncoding));
250*ae77b8caSAriel Constenla-Haile         aBuffer.append("\" ");
251*ae77b8caSAriel Constenla-Haile     }
252*ae77b8caSAriel Constenla-Haile 
253*ae77b8caSAriel Constenla-Haile     // Append receipient if set in the message
254*ae77b8caSAriel Constenla-Haile     if ( xMailMessage->getRecipient().getLength() > 0 )
255*ae77b8caSAriel Constenla-Haile     {
256*ae77b8caSAriel Constenla-Haile         aBuffer.append("--to \"");
257*ae77b8caSAriel Constenla-Haile         aBuffer.append(OUStringToOString(xMailMessage->getRecipient(), iEncoding));
258*ae77b8caSAriel Constenla-Haile         aBuffer.append("\" ");
259*ae77b8caSAriel Constenla-Haile     }
260*ae77b8caSAriel Constenla-Haile 
261*ae77b8caSAriel Constenla-Haile     // Append carbon copy receipients set in the message
262*ae77b8caSAriel Constenla-Haile     Sequence< OUString > aStringList = xMailMessage->getCcRecipient();
263*ae77b8caSAriel Constenla-Haile     sal_Int32 n, nmax = aStringList.getLength();
264*ae77b8caSAriel Constenla-Haile     for ( n = 0; n < nmax; n++ )
265*ae77b8caSAriel Constenla-Haile     {
266*ae77b8caSAriel Constenla-Haile         aBuffer.append("--cc \"");
267*ae77b8caSAriel Constenla-Haile         aBuffer.append(OUStringToOString(aStringList[n], iEncoding));
268*ae77b8caSAriel Constenla-Haile         aBuffer.append("\" ");
269*ae77b8caSAriel Constenla-Haile     }
270*ae77b8caSAriel Constenla-Haile 
271*ae77b8caSAriel Constenla-Haile     // Append blind carbon copy receipients set in the message
272*ae77b8caSAriel Constenla-Haile     aStringList = xMailMessage->getBccRecipient();
273*ae77b8caSAriel Constenla-Haile     nmax = aStringList.getLength();
274*ae77b8caSAriel Constenla-Haile     for ( n = 0; n < nmax; n++ )
275*ae77b8caSAriel Constenla-Haile     {
276*ae77b8caSAriel Constenla-Haile         aBuffer.append("--bcc \"");
277*ae77b8caSAriel Constenla-Haile         aBuffer.append(OUStringToOString(aStringList[n], iEncoding));
278*ae77b8caSAriel Constenla-Haile         aBuffer.append("\" ");
279*ae77b8caSAriel Constenla-Haile     }
280*ae77b8caSAriel Constenla-Haile 
281*ae77b8caSAriel Constenla-Haile     // Append attachments set in the message
282*ae77b8caSAriel Constenla-Haile     aStringList = xMailMessage->getAttachement();
283*ae77b8caSAriel Constenla-Haile     nmax = aStringList.getLength();
284*ae77b8caSAriel Constenla-Haile     for ( n = 0; n < nmax; n++ )
285*ae77b8caSAriel Constenla-Haile     {
286*ae77b8caSAriel Constenla-Haile         OUString aSystemPath;
287*ae77b8caSAriel Constenla-Haile         if ( osl::FileBase::E_None == osl::FileBase::getSystemPathFromFileURL(aStringList[n], aSystemPath) )
288*ae77b8caSAriel Constenla-Haile         {
289*ae77b8caSAriel Constenla-Haile             aBuffer.append("--attach \"");
290*ae77b8caSAriel Constenla-Haile             aBuffer.append(OUStringToOString(aSystemPath, iEncoding));
291*ae77b8caSAriel Constenla-Haile             aBuffer.append("\" ");
292*ae77b8caSAriel Constenla-Haile         }
293*ae77b8caSAriel Constenla-Haile     }
294*ae77b8caSAriel Constenla-Haile 
295*ae77b8caSAriel Constenla-Haile     OString cmd = aBuffer.makeStringAndClear();
296*ae77b8caSAriel Constenla-Haile     if ( 0 != pclose(popen(cmd.getStr(), "w")) )
297*ae77b8caSAriel Constenla-Haile     {
298*ae77b8caSAriel Constenla-Haile         throw ::com::sun::star::uno::Exception(
299*ae77b8caSAriel Constenla-Haile             OUString(RTL_CONSTASCII_USTRINGPARAM( "No mail client configured" )),
300*ae77b8caSAriel Constenla-Haile             static_cast < XMailClient * > (this) );
301*ae77b8caSAriel Constenla-Haile     }
302*ae77b8caSAriel Constenla-Haile }
303*ae77b8caSAriel Constenla-Haile 
304*ae77b8caSAriel Constenla-Haile OUString SAL_CALL
getImplementationName()305*ae77b8caSAriel Constenla-Haile SystemCommandMail::getImplementationName(  )
306*ae77b8caSAriel Constenla-Haile throw( RuntimeException )
307*ae77b8caSAriel Constenla-Haile {
308*ae77b8caSAriel Constenla-Haile     return getImplementationName_static();
309*ae77b8caSAriel Constenla-Haile }
310*ae77b8caSAriel Constenla-Haile 
311*ae77b8caSAriel Constenla-Haile sal_Bool SAL_CALL
supportsService(const OUString & ServiceName)312*ae77b8caSAriel Constenla-Haile SystemCommandMail::supportsService(
313*ae77b8caSAriel Constenla-Haile     const OUString& ServiceName )
314*ae77b8caSAriel Constenla-Haile throw( RuntimeException )
315*ae77b8caSAriel Constenla-Haile {
316*ae77b8caSAriel Constenla-Haile     Sequence < OUString > SupportedServicesNames = getSupportedServiceNames_static();
317*ae77b8caSAriel Constenla-Haile 
318*ae77b8caSAriel Constenla-Haile     for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
319*ae77b8caSAriel Constenla-Haile         if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
320*ae77b8caSAriel Constenla-Haile             return sal_True;
321*ae77b8caSAriel Constenla-Haile 
322*ae77b8caSAriel Constenla-Haile     return sal_False;
323*ae77b8caSAriel Constenla-Haile }
324*ae77b8caSAriel Constenla-Haile 
325*ae77b8caSAriel Constenla-Haile Sequence< OUString > SAL_CALL
getSupportedServiceNames()326*ae77b8caSAriel Constenla-Haile SystemCommandMail::getSupportedServiceNames()
327*ae77b8caSAriel Constenla-Haile throw( RuntimeException )
328*ae77b8caSAriel Constenla-Haile {
329*ae77b8caSAriel Constenla-Haile     return getSupportedServiceNames_static();
330*ae77b8caSAriel Constenla-Haile }
331*ae77b8caSAriel Constenla-Haile 
332*ae77b8caSAriel Constenla-Haile Reference< XInterface >
Create(const Reference<XComponentContext> & xContext)333*ae77b8caSAriel Constenla-Haile SystemCommandMail::Create(
334*ae77b8caSAriel Constenla-Haile     const Reference< XComponentContext > &xContext)
335*ae77b8caSAriel Constenla-Haile {
336*ae77b8caSAriel Constenla-Haile     return Reference< XInterface >(
337*ae77b8caSAriel Constenla-Haile         static_cast< cppu::OWeakObject *>(
338*ae77b8caSAriel Constenla-Haile             new SystemCommandMail( xContext ) ) );
339*ae77b8caSAriel Constenla-Haile }
340*ae77b8caSAriel Constenla-Haile 
341*ae77b8caSAriel Constenla-Haile OUString
getImplementationName_static()342*ae77b8caSAriel Constenla-Haile SystemCommandMail::getImplementationName_static()
343*ae77b8caSAriel Constenla-Haile {
344*ae77b8caSAriel Constenla-Haile     return OUString( RTL_CONSTASCII_USTRINGPARAM( COMP_IMPL_NAME ) );
345*ae77b8caSAriel Constenla-Haile }
346*ae77b8caSAriel Constenla-Haile 
347*ae77b8caSAriel Constenla-Haile Sequence< OUString >
getSupportedServiceNames_static()348*ae77b8caSAriel Constenla-Haile SystemCommandMail::getSupportedServiceNames_static()
349*ae77b8caSAriel Constenla-Haile {
350*ae77b8caSAriel Constenla-Haile     Sequence< OUString > aRet(1);
351*ae77b8caSAriel Constenla-Haile     aRet[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( COMP_SERVICE_NAME ) );
352*ae77b8caSAriel Constenla-Haile     return aRet;
353*ae77b8caSAriel Constenla-Haile }
354*ae77b8caSAriel Constenla-Haile 
355*ae77b8caSAriel Constenla-Haile }
356