summaryrefslogtreecommitdiffstats
path: root/shell/source/cmdmail
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /shell/source/cmdmail
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'shell/source/cmdmail')
-rw-r--r--shell/source/cmdmail/cmdmail.component25
-rw-r--r--shell/source/cmdmail/cmdmailentry.cxx69
-rw-r--r--shell/source/cmdmail/cmdmailmsg.cxx214
-rw-r--r--shell/source/cmdmail/cmdmailmsg.hxx106
-rw-r--r--shell/source/cmdmail/cmdmailsuppl.cxx299
-rw-r--r--shell/source/cmdmail/cmdmailsuppl.hxx74
6 files changed, 787 insertions, 0 deletions
diff --git a/shell/source/cmdmail/cmdmail.component b/shell/source/cmdmail/cmdmail.component
new file mode 100644
index 000000000..ea9ce04d2
--- /dev/null
+++ b/shell/source/cmdmail/cmdmail.component
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ -->
+
+<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
+ prefix="cmdmail" xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="com.sun.star.comp.system.SimpleCommandMail">
+ <service name="com.sun.star.system.SimpleCommandMail"/>
+ </implementation>
+</component>
diff --git a/shell/source/cmdmail/cmdmailentry.cxx b/shell/source/cmdmail/cmdmailentry.cxx
new file mode 100644
index 000000000..c82f67493
--- /dev/null
+++ b/shell/source/cmdmail/cmdmailentry.cxx
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <cppuhelper/factory.hxx>
+#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/lang/XSingleComponentFactory.hpp>
+#include "cmdmailsuppl.hxx"
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+using namespace ::cppu;
+using com::sun::star::system::XSimpleMailClientSupplier;
+
+#define COMP_SERVICE_NAME "com.sun.star.system.SimpleCommandMail"
+#define COMP_IMPL_NAME "com.sun.star.comp.system.SimpleCommandMail"
+
+namespace
+{
+ Reference< XInterface > createInstance( const Reference< XComponentContext >& xContext )
+ {
+ return Reference< XInterface >( static_cast< XSimpleMailClientSupplier* >( new CmdMailSuppl( xContext ) ) );
+ }
+}
+
+extern "C"
+{
+
+SAL_DLLPUBLIC_EXPORT void* cmdmail_component_getFactory(
+ const char* pImplName,
+ SAL_UNUSED_PARAMETER void* /*pSrvManager*/,
+ SAL_UNUSED_PARAMETER void* /*pRegistryKey*/ )
+{
+ Reference< XSingleComponentFactory > xFactory;
+
+ if (0 == ::rtl_str_compare( pImplName, COMP_IMPL_NAME ))
+ {
+ xFactory = ::cppu::createSingleComponentFactory(
+ createInstance,
+ COMP_IMPL_NAME,
+ Sequence< OUString > { COMP_SERVICE_NAME } );
+ }
+
+ if (xFactory.is())
+ xFactory->acquire();
+
+ return xFactory.get();
+}
+
+} // extern "C"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/cmdmail/cmdmailmsg.cxx b/shell/source/cmdmail/cmdmailmsg.cxx
new file mode 100644
index 000000000..bd8657577
--- /dev/null
+++ b/shell/source/cmdmail/cmdmailmsg.cxx
@@ -0,0 +1,214 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "cmdmailmsg.hxx"
+
+using com::sun::star::container::NoSuchElementException;
+using com::sun::star::container::XNameAccess;
+using osl::MutexGuard;
+
+using namespace cppu;
+using namespace com::sun::star::uno;
+
+
+void SAL_CALL CmdMailMsg::setBody( const OUString& aBody )
+{
+ MutexGuard aGuard( m_aMutex );
+ m_aBody = aBody;
+}
+
+OUString SAL_CALL CmdMailMsg::getBody( )
+{
+ MutexGuard aGuard( m_aMutex );
+ return m_aBody;
+}
+
+void SAL_CALL CmdMailMsg::setRecipient( const OUString& aRecipient )
+{
+ MutexGuard aGuard( m_aMutex );
+ m_aRecipient = aRecipient;
+}
+
+OUString SAL_CALL CmdMailMsg::getRecipient( )
+{
+ MutexGuard aGuard( m_aMutex );
+ return m_aRecipient;
+}
+
+void SAL_CALL CmdMailMsg::setCcRecipient( const Sequence< OUString >& aCcRecipient )
+{
+ MutexGuard aGuard( m_aMutex );
+ m_CcRecipients = aCcRecipient;
+}
+
+Sequence< OUString > SAL_CALL CmdMailMsg::getCcRecipient( )
+{
+ MutexGuard aGuard( m_aMutex );
+ return m_CcRecipients;
+}
+
+void SAL_CALL CmdMailMsg::setBccRecipient( const Sequence< OUString >& aBccRecipient )
+{
+ MutexGuard aGuard( m_aMutex );
+ m_BccRecipients = aBccRecipient;
+}
+
+Sequence< OUString > SAL_CALL CmdMailMsg::getBccRecipient( )
+{
+ MutexGuard aGuard( m_aMutex );
+ return m_BccRecipients;
+}
+
+void SAL_CALL CmdMailMsg::setOriginator( const OUString& aOriginator )
+{
+ MutexGuard aGuard( m_aMutex );
+ m_aOriginator = aOriginator;
+}
+
+OUString SAL_CALL CmdMailMsg::getOriginator( )
+{
+ MutexGuard aGuard( m_aMutex );
+ return m_aOriginator;
+}
+
+void SAL_CALL CmdMailMsg::setSubject( const OUString& aSubject )
+{
+ MutexGuard aGuard( m_aMutex );
+ m_aSubject = aSubject;
+}
+
+OUString SAL_CALL CmdMailMsg::getSubject( )
+{
+ MutexGuard aGuard( m_aMutex );
+ return m_aSubject;
+}
+
+void SAL_CALL CmdMailMsg::setAttachement( const Sequence< OUString >& aAttachment )
+{
+ MutexGuard aGuard( m_aMutex );
+ m_Attachments = aAttachment;
+}
+
+Sequence< OUString > SAL_CALL CmdMailMsg::getAttachement( )
+{
+ MutexGuard aGuard( m_aMutex );
+ return m_Attachments;
+}
+
+Any SAL_CALL CmdMailMsg::getByName( const OUString& aName )
+{
+ MutexGuard aGuard( m_aMutex );
+
+ if( aName == "body" && !m_aBody.isEmpty() )
+ return makeAny( m_aBody );
+
+ if( aName == "from" && !m_aOriginator.isEmpty() )
+ return makeAny( m_aOriginator );
+
+ else if( aName == "to" && !m_aRecipient.isEmpty() )
+ return makeAny( m_aRecipient );
+
+ else if( aName == "cc" && m_CcRecipients.hasElements() )
+ return makeAny( m_CcRecipients );
+
+ else if( aName == "bcc" && m_BccRecipients.hasElements() )
+ return makeAny( m_BccRecipients );
+
+ else if( aName == "subject" && !m_aSubject.isEmpty() )
+ return makeAny( m_aSubject );
+
+ else if( aName == "attachment" && m_Attachments.hasElements() )
+ return makeAny( m_Attachments );
+
+ throw NoSuchElementException("key not found: " + aName,
+ static_cast < XNameAccess * > (this) );
+}
+
+Sequence< OUString > SAL_CALL CmdMailMsg::getElementNames( )
+{
+ MutexGuard aGuard( m_aMutex );
+
+ sal_Int32 nItems = 0;
+ Sequence< OUString > aRet( 7 );
+
+ if( !m_aBody.isEmpty() )
+ aRet[nItems++] = "body";
+
+ if( !m_aOriginator.isEmpty() )
+ aRet[nItems++] = "from";
+
+ if( !m_aRecipient.isEmpty() )
+ aRet[nItems++] = "to";
+
+ if( m_CcRecipients.hasElements() )
+ aRet[nItems++] = "cc";
+
+ if( m_BccRecipients.hasElements() )
+ aRet[nItems++] = "bcc";
+
+ if( !m_aSubject.isEmpty() )
+ aRet[nItems++] = "subject";
+
+ if( m_Attachments.hasElements() )
+ aRet[nItems++] = "attachment";
+
+ aRet.realloc( nItems );
+ return aRet;
+}
+
+ sal_Bool SAL_CALL CmdMailMsg::hasByName( const OUString& aName )
+{
+ MutexGuard aGuard( m_aMutex );
+
+ if( aName == "body" && !m_aBody.isEmpty() )
+ return true;
+
+ if( aName == "from" && !m_aOriginator.isEmpty() )
+ return true;
+
+ else if( aName == "to" && !m_aRecipient.isEmpty() )
+ return true;
+
+ else if( aName == "cc" && m_CcRecipients.hasElements() )
+ return true;
+
+ else if( aName == "bcc" && m_BccRecipients.hasElements() )
+ return true;
+
+ else if( aName == "subject" && !m_aSubject.isEmpty() )
+ return true;
+
+ else if( aName == "attachment" && m_Attachments.hasElements() )
+ return true;
+
+ return false;
+}
+
+Type SAL_CALL CmdMailMsg::getElementType( )
+{
+ // returning void for multi type container
+ return Type();
+}
+
+sal_Bool SAL_CALL CmdMailMsg::hasElements( )
+{
+ return getElementNames().hasElements();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/cmdmail/cmdmailmsg.hxx b/shell/source/cmdmail/cmdmailmsg.hxx
new file mode 100644
index 000000000..09e1aeaa9
--- /dev/null
+++ b/shell/source/cmdmail/cmdmailmsg.hxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SHELL_SOURCE_CMDMAIL_CMDMAILMSG_HXX
+#define INCLUDED_SHELL_SOURCE_CMDMAIL_CMDMAILMSG_HXX
+
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
+#include <com/sun/star/system/XSimpleMailMessage2.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+
+
+
+class CmdMailMsg :
+ public cppu::WeakImplHelper<
+ css::system::XSimpleMailMessage2,
+ css::container::XNameAccess >
+{
+ OUString m_aBody;
+ OUString m_aRecipient;
+ OUString m_aOriginator;
+ OUString m_aSubject;
+ css::uno::Sequence< OUString > m_CcRecipients;
+ css::uno::Sequence< OUString > m_BccRecipients;
+ css::uno::Sequence< OUString > m_Attachments;
+
+ ::osl::Mutex m_aMutex;
+
+public:
+
+ CmdMailMsg() {};
+
+
+ // XSimpleMailMessage
+
+
+ virtual void SAL_CALL setBody( const OUString& aBody ) override;
+
+ virtual OUString SAL_CALL getBody( ) override;
+
+ virtual void SAL_CALL setRecipient( const OUString& aRecipient ) override;
+
+ virtual OUString SAL_CALL getRecipient( ) override;
+
+ virtual void SAL_CALL setCcRecipient( const css::uno::Sequence< OUString >& aCcRecipient ) override;
+
+ virtual css::uno::Sequence< OUString > SAL_CALL getCcRecipient( ) override;
+
+ virtual void SAL_CALL setBccRecipient( const css::uno::Sequence< OUString >& aBccRecipient ) override;
+
+ virtual css::uno::Sequence< OUString > SAL_CALL getBccRecipient( ) override;
+
+ virtual void SAL_CALL setOriginator( const OUString& aOriginator ) override;
+
+ virtual OUString SAL_CALL getOriginator( ) override;
+
+ virtual void SAL_CALL setSubject( const OUString& aSubject ) override;
+
+ virtual OUString SAL_CALL getSubject( ) override;
+
+ virtual void SAL_CALL setAttachement( const css::uno::Sequence< OUString >& aAttachement ) override;
+
+ virtual css::uno::Sequence< OUString > SAL_CALL getAttachement( ) override;
+
+
+ // XNameAccess
+
+
+ virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
+
+ virtual css::uno::Sequence< OUString > SAL_CALL getElementNames( ) override ;
+
+ virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
+
+
+ // XElementAccess
+
+
+ virtual css::uno::Type SAL_CALL getElementType( ) override;
+
+ virtual sal_Bool SAL_CALL hasElements( ) override;
+
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/cmdmail/cmdmailsuppl.cxx b/shell/source/cmdmail/cmdmailsuppl.cxx
new file mode 100644
index 000000000..bbd0ae07d
--- /dev/null
+++ b/shell/source/cmdmail/cmdmailsuppl.cxx
@@ -0,0 +1,299 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <config_folders.h>
+
+#include <osl/thread.h>
+
+#include <rtl/bootstrap.hxx>
+
+#include <osl/file.hxx>
+#include <rtl/strbuf.hxx>
+#include <sal/log.hxx>
+#include "cmdmailsuppl.hxx"
+#include "cmdmailmsg.hxx"
+#include <com/sun/star/system/SimpleMailClientFlags.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/configuration/theDefaultProvider.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <cppuhelper/supportsservice.hxx>
+#include <tools/diagnose_ex.h>
+
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+using com::sun::star::beans::PropertyValue;
+using com::sun::star::system::XSimpleMailClientSupplier;
+using com::sun::star::system::XSimpleMailClient;
+using com::sun::star::system::XSimpleMailMessage;
+using com::sun::star::system::XSimpleMailMessage2;
+using com::sun::star::container::XNameAccess;
+using osl::FileBase;
+
+using namespace cppu;
+using namespace com::sun::star::system::SimpleMailClientFlags;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::configuration;
+
+namespace
+{
+ Sequence< OUString > Component_getSupportedServiceNames()
+ {
+ Sequence< OUString > aRet { "com.sun.star.system.SimpleCommandMail" };
+ return aRet;
+ }
+
+}
+
+CmdMailSuppl::CmdMailSuppl( const Reference< XComponentContext >& xContext ) :
+ WeakImplHelper< XSimpleMailClientSupplier, XSimpleMailClient, XServiceInfo >()
+{
+ m_xConfigurationProvider = theDefaultProvider::get(xContext);
+}
+
+// XSimpleMailClientSupplier
+
+Reference< XSimpleMailClient > SAL_CALL CmdMailSuppl::querySimpleMailClient( )
+{
+ return static_cast < XSimpleMailClient * > (this);
+}
+
+// XSimpleMailClient
+
+Reference< XSimpleMailMessage > SAL_CALL CmdMailSuppl::createSimpleMailMessage( )
+{
+ return Reference< XSimpleMailMessage >( new CmdMailMsg( ) );
+}
+
+namespace {
+
+void appendShellWord(OStringBuffer & buffer, OUString const & word, bool strict)
+{
+ OString sys;
+ if (!word.convertToString(
+ &sys, osl_getThreadTextEncoding(),
+ (strict
+ ? (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
+ | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)
+ : OUSTRING_TO_OSTRING_CVTFLAGS)))
+ {
+ throw css::uno::Exception(
+ ("Could not convert \"" + word + "\" to encoding #"
+ + OUString::number(osl_getThreadTextEncoding())),
+ css::uno::Reference<css::uno::XInterface>());
+ }
+ buffer.append('\'');
+ for (sal_Int32 i = 0; i != sys.getLength(); ++i) {
+ char c = sys[i];
+ switch (c) {
+ case 0:
+ if (strict) {
+ throw css::uno::Exception(
+ "Could not convert word containing NUL, \"" + word + "\"",
+ css::uno::Reference<css::uno::XInterface>());
+ }
+ break;
+ case '\'':
+ buffer.append("'\\''");
+ break;
+ default:
+ buffer.append(c);
+ break;
+ }
+ }
+ buffer.append('\'');
+}
+
+}
+
+void SAL_CALL CmdMailSuppl::sendSimpleMailMessage( const Reference< XSimpleMailMessage >& xSimpleMailMessage, sal_Int32 /*aFlag*/ )
+{
+ if ( ! xSimpleMailMessage.is() )
+ {
+ throw css::lang::IllegalArgumentException( "No message specified" ,
+ static_cast < XSimpleMailClient * > (this), 1 );
+ }
+
+ if( ! m_xConfigurationProvider.is() )
+ {
+ throw css::uno::Exception( "Can not access configuration" ,
+ static_cast < XSimpleMailClient * > (this) );
+ }
+
+
+ OUString aProgramURL("$BRAND_BASE_DIR/" LIBO_LIBEXEC_FOLDER "/senddoc");
+ rtl::Bootstrap::expandMacros(aProgramURL);
+
+ OUString aProgram;
+ if ( FileBase::E_None != FileBase::getSystemPathFromFileURL(aProgramURL, aProgram))
+ {
+ throw css::uno::Exception("Could not convert executable path",
+ static_cast < XSimpleMailClient * > (this));
+ }
+
+ OStringBuffer aBuffer;
+ appendShellWord(aBuffer, aProgram, true);
+
+ try
+ {
+ // Query XNameAccess interface of the org.openoffice.Office.Common/ExternalMailer
+ // configuration node to retrieve the users preferred email application. This may
+ // transparently by redirected to e.g. the corresponding GConf setting in GNOME.
+ OUString aConfigRoot = "org.openoffice.Office.Common/ExternalMailer";
+
+ PropertyValue aProperty;
+ aProperty.Name = "nodepath";
+ aProperty.Value <<= aConfigRoot;
+
+ Sequence< Any > aArgumentList( 1 );
+ aArgumentList[0] <<= aProperty;
+
+ Reference< XNameAccess > xNameAccess(
+ m_xConfigurationProvider->createInstanceWithArguments(
+ "com.sun.star.configuration.ConfigurationAccess",
+ aArgumentList ),
+ UNO_QUERY );
+
+ if( xNameAccess.is() )
+ {
+ OUString aMailer;
+
+ // Retrieve the value for "Program" node and append it feed senddoc with it
+ // using the (undocumented) --mailclient switch
+ xNameAccess->getByName("Program") >>= aMailer;
+
+ if( !aMailer.isEmpty() )
+ {
+ // make sure we have a system path
+ FileBase::getSystemPathFromFileURL( aMailer, aMailer );
+
+ aBuffer.append(" --mailclient ");
+ appendShellWord(aBuffer, aMailer, true);
+ }
+#ifdef MACOSX
+ else
+ aBuffer.append(" --mailclient Mail");
+#endif
+ }
+
+ }
+
+ catch(const RuntimeException & )
+ {
+ TOOLS_WARN_EXCEPTION("shell", "RuntimeException caught accessing configuration provider" );
+ m_xConfigurationProvider.clear();
+ throw;
+ }
+
+ Reference< XSimpleMailMessage2 > xMessage( xSimpleMailMessage, UNO_QUERY );
+ if ( xMessage.is() )
+ {
+ OUString sBody = xMessage->getBody();
+ if ( sBody.getLength() > 0 )
+ {
+ aBuffer.append(" --body ");
+ appendShellWord(aBuffer, sBody, false);
+ }
+ }
+
+ // Convert from, to, etc. in a best-effort rather than a strict way to the
+ // system encoding, based on the assumption that the relevant address parts
+ // of those strings are ASCII anyway and any problematic characters are only
+ // in the human-readable, informational-only parts:
+
+ // Append originator if set in the message
+ if ( !xSimpleMailMessage->getOriginator().isEmpty() )
+ {
+ aBuffer.append(" --from ");
+ appendShellWord(aBuffer, xSimpleMailMessage->getOriginator(), false);
+ }
+
+ // Append recipient if set in the message
+ if ( !xSimpleMailMessage->getRecipient().isEmpty() )
+ {
+ aBuffer.append(" --to ");
+ appendShellWord(aBuffer, xSimpleMailMessage->getRecipient(), false);
+ }
+
+ // Append carbon copy recipients set in the message
+ Sequence< OUString > aStringList = xSimpleMailMessage->getCcRecipient();
+ for ( const auto& rString : std::as_const(aStringList) )
+ {
+ aBuffer.append(" --cc ");
+ appendShellWord(aBuffer, rString, false);
+ }
+
+ // Append blind carbon copy recipients set in the message
+ aStringList = xSimpleMailMessage->getBccRecipient();
+ for ( const auto& rString : std::as_const(aStringList) )
+ {
+ aBuffer.append(" --bcc ");
+ appendShellWord(aBuffer, rString, false);
+ }
+
+ // Append subject if set in the message
+ if ( !xSimpleMailMessage->getSubject().isEmpty() )
+ {
+ aBuffer.append(" --subject ");
+ appendShellWord(aBuffer, xSimpleMailMessage->getSubject(), false);
+ }
+
+ // Append attachments set in the message
+ aStringList = xSimpleMailMessage->getAttachement();
+ for ( const auto& rString : std::as_const(aStringList) )
+ {
+ OUString aSystemPath;
+ if ( FileBase::E_None == FileBase::getSystemPathFromFileURL(rString, aSystemPath) )
+ {
+ aBuffer.append(" --attach ");
+ appendShellWord(aBuffer, aSystemPath, true);
+ }
+ }
+
+ OString cmd = aBuffer.makeStringAndClear();
+ FILE * f = popen(cmd.getStr(), "w");
+ if (f == nullptr || pclose(f) != 0)
+ {
+ throw css::uno::Exception("No mail client configured",
+ static_cast < XSimpleMailClient * > (this) );
+ }
+}
+
+// XServiceInfo
+
+OUString SAL_CALL CmdMailSuppl::getImplementationName( )
+{
+ return "com.sun.star.comp.system.SimpleCommandMail";
+}
+
+sal_Bool SAL_CALL CmdMailSuppl::supportsService( const OUString& ServiceName )
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+Sequence< OUString > SAL_CALL CmdMailSuppl::getSupportedServiceNames( )
+{
+ return Component_getSupportedServiceNames();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/cmdmail/cmdmailsuppl.hxx b/shell/source/cmdmail/cmdmailsuppl.hxx
new file mode 100644
index 000000000..43915d662
--- /dev/null
+++ b/shell/source/cmdmail/cmdmailsuppl.hxx
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SHELL_SOURCE_CMDMAIL_CMDMAILSUPPL_HXX
+#define INCLUDED_SHELL_SOURCE_CMDMAIL_CMDMAILSUPPL_HXX
+
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <com/sun/star/system/XSimpleMailClient.hpp>
+
+#include <com/sun/star/system/XSimpleMailClientSupplier.hpp>
+
+
+
+
+class CmdMailSuppl :
+ public cppu::WeakImplHelper<
+ css::system::XSimpleMailClientSupplier,
+ css::system::XSimpleMailClient,
+ css::lang::XServiceInfo >
+{
+
+ css::uno::Reference< css::lang::XMultiServiceFactory > m_xConfigurationProvider;
+
+public:
+ explicit CmdMailSuppl( const css::uno::Reference< css::uno::XComponentContext >& xContext );
+
+
+ // XSimpleMailClientSupplier
+
+
+ virtual css::uno::Reference< css::system::XSimpleMailClient > SAL_CALL querySimpleMailClient( ) override;
+
+
+ // XSimpleMailClient
+
+
+ virtual css::uno::Reference< css::system::XSimpleMailMessage > SAL_CALL createSimpleMailMessage( ) override;
+
+ virtual void SAL_CALL sendSimpleMailMessage( const css::uno::Reference< css::system::XSimpleMailMessage >& xSimpleMailMessage, sal_Int32 aFlag ) override;
+
+
+ // XServiceInfo
+
+
+ virtual OUString SAL_CALL getImplementationName( ) override;
+
+ virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
+
+ virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */