summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2004-06-17 14:54:22 +0000
committerRüdiger Timm <rt@openoffice.org>2004-06-17 14:54:22 +0000
commitb60eb3b6a709a5f871c541bb84a6d30a32ca50c7 (patch)
tree371685b3eed12cef98a875fc2dd06dbccdf946b6 /shell
parent5843f59afff250a7e67fb85bdae29204cfe82e68 (diff)
INTEGRATION: CWS defaultmailer (1.5.164); FILE MERGED
2004/06/08 10:32:20 obr 1.5.164.1: #i21321#,#i28378#,103347 cmdmail is now unix only and auto-detects the command line profile to use
Diffstat (limited to 'shell')
-rwxr-xr-xshell/source/cmdmail/cmdmailsuppl.cxx252
1 files changed, 169 insertions, 83 deletions
diff --git a/shell/source/cmdmail/cmdmailsuppl.cxx b/shell/source/cmdmail/cmdmailsuppl.cxx
index a900627686f6..ffbe7d7158ca 100755
--- a/shell/source/cmdmail/cmdmailsuppl.cxx
+++ b/shell/source/cmdmail/cmdmailsuppl.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: cmdmailsuppl.cxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: rt $ $Date: 2004-06-17 11:34:39 $
+ * last change: $Author: rt $ $Date: 2004-06-17 15:54:22 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -67,6 +67,10 @@
#include <osl/diagnose.h>
#endif
+#ifndef _OSL_THREAD_H_
+#include <osl/thread.h>
+#endif
+
#ifndef _OSL_PROCESS_H_
#include <osl/process.h>
#endif
@@ -75,6 +79,10 @@
#include <osl/file.hxx>
#endif
+#ifndef _RTL_STRBUF_HXX_
+#include <rtl/strbuf.hxx>
+#endif
+
#ifndef _CMDMAILSUPPL_HXX_
#include "cmdmailsuppl.hxx"
#endif
@@ -103,6 +111,10 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#endif
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
//------------------------------------------------------------------------
// namespace directives
//------------------------------------------------------------------------
@@ -115,6 +127,8 @@ using com::sun::star::container::XNameAccess;
using com::sun::star::container::NoSuchElementException;
using rtl::OUString;
using rtl::OUStringToOString;
+using rtl::OString;
+using rtl::OStringBuffer;
using osl::MutexGuard;
using osl::FileBase;
@@ -127,7 +141,8 @@ using namespace com::sun::star::lang;
// defines
//------------------------------------------------------------------------
-#define COMP_IMPL_NAME "com.sun.star.comp.system.SimpleCommandMail"
+#define COMP_IMPL_NAME "com.sun.star.comp.system.SimpleCommandMail2"
+#define SMGR_SINGLETON "/singleton/com.sun.star.lang.theServiceManager"
//------------------------------------------------------------------------
// helper functions
@@ -148,10 +163,17 @@ namespace // private
//
//-------------------------------------------------
-CmdMailSuppl::CmdMailSuppl( const Reference< XMultiServiceFactory >& xServiceManager ) :
- WeakComponentImplHelper4< XSimpleMailClientSupplier, XSimpleMailClient, XEventListener, XServiceInfo >( m_aMutex ),
- m_xServiceManager( xServiceManager )
+CmdMailSuppl::CmdMailSuppl( const Reference< XComponentContext >& xContext ) :
+ WeakImplHelper3< XSimpleMailClientSupplier, XSimpleMailClient, XServiceInfo >()
{
+ Reference< XMultiComponentFactory > xServiceManager = xContext->getServiceManager();
+
+ if ( xServiceManager.is() ) {
+ m_xConfigurationProvider = Reference< XMultiServiceFactory > (
+ xServiceManager->createInstanceWithContext(
+ OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ), xContext ),
+ UNO_QUERY );
+ }
}
//-------------------------------------------------
@@ -189,74 +211,164 @@ Reference< XSimpleMailMessage > SAL_CALL CmdMailSuppl::createSimpleMailMessage(
void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailMessage >& xSimpleMailMessage, sal_Int32 aFlag )
throw (IllegalArgumentException, Exception, RuntimeException)
{
- MutexGuard aGuard( m_aMutex );
- OUString aCommandLine;
+ if ( ! xSimpleMailMessage.is() )
+ {
+ throw ::com::sun::star::lang::IllegalArgumentException(
+ OUString(RTL_CONSTASCII_USTRINGPARAM( "No message specified" )),
+ static_cast < XSimpleMailClient * > (this), 1 );
+ }
- // create config manager if not already done so
- if( m_xServiceManager.is() && !m_xConfigurationProvider.is() )
+ if( ! m_xConfigurationProvider.is() )
{
- try
- {
- m_xConfigurationProvider = Reference< XMultiServiceFactory > (
- m_xServiceManager->createInstance(
- OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" ) ),
- UNO_QUERY );
+ throw ::com::sun::star::uno::Exception(
+ OUString(RTL_CONSTASCII_USTRINGPARAM( "Can not access configuration" )),
+ static_cast < XSimpleMailClient * > (this) );
+ }
- Reference< XComponent > xComponent =
- Reference< XComponent >( m_xConfigurationProvider, UNO_QUERY );
+ OStringBuffer aBuffer;
- if( xComponent.is() )
- xComponent->addEventListener( static_cast < XEventListener * > (this) );
- }
+ OUString aProgramURL;
+ if ( osl_Process_E_None != osl_getExecutableFile(&aProgramURL.pData) )
+ {
+ throw ::com::sun::star::uno::Exception(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("Cound not determine executable path")),
+ static_cast < XSimpleMailClient * > (this));
+ }
- // release service manager instance on runtime exceptions
- catch ( RuntimeException e )
+ OUString aProgram;
+ if ( FileBase::E_None != FileBase::getSystemPathFromFileURL(aProgramURL, aProgram))
+ {
+ throw ::com::sun::star::uno::Exception(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("Cound not convert executable path")),
+ static_cast < XSimpleMailClient * > (this));
+ }
+
+ // The mail client launchers are expected to be in the same directory as the main
+ // executable, so prefixing the launchers with the path of the executable including
+ // the last slash
+ OString aTmp = OUStringToOString(aProgram, osl_getThreadTextEncoding());
+ sal_Int32 nIndex = aTmp.lastIndexOf('/');
+ if (nIndex > 0)
+ aBuffer.append(aTmp.copy(0, nIndex+1));
+
+ aBuffer.append("senddoc ");
+
+ try
+ {
+ // Query XNameAccess interface of the org.openoffice.Office.Common/ExternalMailer
+ // configuration node to retriece the users preferred email application. This may
+ // transparently by redirected to e.g. the corresponding GConf setting in GNOME.
+ OUString aConfigRoot = OUString(
+ RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Office.Common/ExternalMailer" ) );
+
+ PropertyValue aProperty;
+ aProperty.Name = OUString::createFromAscii( "nodepath" );
+ aProperty.Value = makeAny( aConfigRoot );
+
+ Sequence< Any > aArgumentList( 1 );
+ aArgumentList[0] = makeAny( aProperty );
+
+ Reference< XNameAccess > xNameAccess =
+ Reference< XNameAccess > (
+ m_xConfigurationProvider->createInstanceWithArguments(
+ OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" ),
+ aArgumentList ),
+ UNO_QUERY );
+
+ if( xNameAccess.is() )
{
- m_xServiceManager.clear();
- OSL_TRACE( "ShellExec: can not instanciate configuration provider." );
- throw e;
+ OUString aMailer;
+
+ // Retrieve the value for "Program" node and append it feed senddoc with it
+ // using the (undocumented) --mailclient switch
+ xNameAccess->getByName( OUString::createFromAscii( "Program" ) ) >>= aMailer;
+
+ if( aMailer.getLength() )
+ {
+ // make sure we have a system path
+ FileBase::getSystemPathFromFileURL( aMailer, aMailer );
+
+ aBuffer.append("--mailclient ");
+ aBuffer.append(OUStringToOString( aMailer, osl_getThreadTextEncoding() ));
+ aBuffer.append(" ");
+ }
}
+
}
- if( m_xConfigurationProvider.is() )
+ catch( RuntimeException e )
{
- try
- {
- OUString aConfigRoot = OUString::createFromAscii( "org.openoffice.Office.Common/ExternalMailer" );
+ m_xConfigurationProvider.clear();
+ OSL_TRACE( "RuntimeException caught accessing configuration provider." );
+ OSL_TRACE( OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
+ throw e;
+ }
- PropertyValue aProperty;
- aProperty.Name = OUString::createFromAscii( "nodepath" );
- aProperty.Value = makeAny( aConfigRoot );
+ // Append originator if set in the message
+ if ( xSimpleMailMessage->getOriginator().getLength() > 0 )
+ {
+ aBuffer.append("--from \"");
+ aBuffer.append(OUStringToOString(xSimpleMailMessage->getOriginator(), osl_getThreadTextEncoding()));
+ aBuffer.append("\" ");
+ }
- Sequence< Any > aArgumentList( 1 );
- aArgumentList[0] = makeAny( aProperty );
+ // Append receipient if set in the message
+ if ( xSimpleMailMessage->getRecipient().getLength() > 0 )
+ {
+ aBuffer.append("--to \"");
+ aBuffer.append(OUStringToOString(xSimpleMailMessage->getRecipient(), osl_getThreadTextEncoding()));
+ aBuffer.append("\" ");
+ }
- // query the configured external mail program
- Reference< XNameAccess > xNameAccess =
- Reference< XNameAccess > (
- m_xConfigurationProvider->createInstanceWithArguments(
- OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" ),
- aArgumentList ),
- UNO_QUERY );
+ // Append carbon copy receipients set in the message
+ Sequence< OUString > aStringList = xSimpleMailMessage->getCcRecipient();
+ sal_Int32 n, nmax = aStringList.getLength();
+ for ( n = 0; n < nmax; n++ )
+ {
+ aBuffer.append("--cc \"");
+ aBuffer.append(OUStringToOString(aStringList[n], osl_getThreadTextEncoding()));
+ aBuffer.append("\" ");
+ }
- if( xNameAccess.is() )
- {
- OUString aProgram, aProfile;
+ // Append blind carbon copy receipients set in the message
+ aStringList = xSimpleMailMessage->getBccRecipient();
+ nmax = aStringList.getLength();
+ for ( n = 0; n < nmax; n++ )
+ {
+ aBuffer.append("--bcc \"");
+ aBuffer.append(OUStringToOString(aStringList[n], osl_getThreadTextEncoding()));
+ aBuffer.append("\" ");
+ }
- // save the registered program and commmand line profile
- xNameAccess->getByName( OUString::createFromAscii( "Program" ) ) >>= aProgram;
- xNameAccess->getByName( OUString::createFromAscii( "CommandProfile" ) ) >>= aProfile;
+ // Append subject if set in the message
+ if ( xSimpleMailMessage->getSubject().getLength() > 0 )
+ {
+ aBuffer.append("--subject \"");
+ aBuffer.append(OUStringToOString(xSimpleMailMessage->getSubject(), osl_getThreadTextEncoding()));
+ aBuffer.append("\" ");
+ }
+
+ // Append attachments set in the message
+ aStringList = xSimpleMailMessage->getAttachement();
+ nmax = aStringList.getLength();
+ for ( n = 0; n < nmax; n++ )
+ {
+ aBuffer.append("--attach \"");
+ aBuffer.append(OUStringToOString(aStringList[n], RTL_TEXTENCODING_UTF8));
+ aBuffer.append("\" ");
+ }
- if( aProgram.getLength() )
- {
- // convert to file url
- FileBase::getFileURLFromSystemPath( aProgram, aProgram );
+ OString cmd = aBuffer.makeStringAndClear();
+ if ( 0 != pclose(popen(cmd.getStr(), "w")) )
+ {
+ throw ::com::sun::star::uno::Exception(
+ OUString(RTL_CONSTASCII_USTRINGPARAM( "No mail client configured" )),
+ static_cast < XSimpleMailClient * > (this) );
+ }
- OUString aProgramConfig = OUString::createFromAscii( "base" );
- aConfigRoot += OUString::createFromAscii( "/Profiles/['" );
- aConfigRoot += aProfile;
- aConfigRoot += OUString::createFromAscii( "']" );
+#if 0
+ OUString aCommandLine;
// create name access to format strings
aProperty.Value = makeAny( aConfigRoot + OUString::createFromAscii( "/FormatStrings" ) );
@@ -442,13 +554,6 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
OSL_TRACE( OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
}
- catch( RuntimeException e )
- {
- m_xConfigurationProvider.clear();
- OSL_TRACE( "CmdMail: configuration provider." );
- OSL_TRACE( OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
- throw e;
- }
catch( Exception e )
{
@@ -457,27 +562,8 @@ void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailM
}
}
- throw ::com::sun::star::uno::Exception( OUString(), static_cast < XSimpleMailClient * > (this) );
-}
-
-//------------------------------------------------
-// XEventListener
-//------------------------------------------------
-
-void SAL_CALL CmdMailSuppl::disposing( const ::com::sun::star::lang::EventObject& aEvent )
- throw(::com::sun::star::uno::RuntimeException)
-{
- MutexGuard aGuard( m_aMutex );
-
- if( m_xServiceManager == aEvent.Source )
- {
- m_xServiceManager.clear();
- }
- else if( m_xConfigurationProvider == aEvent.Source )
- {
- m_xConfigurationProvider.clear();
- }
+#endif
}
// -------------------------------------------------