20#include <config_folders.h>
22#include <osl/thread.h>
24#include <rtl/bootstrap.hxx>
26#include <osl/file.hxx>
27#include <rtl/strbuf.hxx>
30#include <com/sun/star/system/SimpleMailClientFlags.hpp>
31#include <com/sun/star/container/XNameAccess.hpp>
32#include <com/sun/star/configuration/theDefaultProvider.hpp>
33#include <com/sun/star/beans/PropertyValue.hpp>
34#include <com/sun/star/uno/XComponentContext.hpp>
38using com::sun::star::beans::PropertyValue;
39using com::sun::star::system::XSimpleMailClientSupplier;
40using com::sun::star::system::XSimpleMailClient;
41using com::sun::star::system::XSimpleMailMessage;
42using com::sun::star::system::XSimpleMailMessage2;
43using com::sun::star::container::XNameAccess;
47using namespace com::sun::star::system::SimpleMailClientFlags;
61 return static_cast < XSimpleMailClient *
> (
this);
73void appendShellWord(OStringBuffer & buffer, OUString
const & word,
bool strict)
76 if (!word.convertToString(
77 &sys, osl_getThreadTextEncoding(),
79 ? (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
80 | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)
81 : OUSTRING_TO_OSTRING_CVTFLAGS)))
83 throw css::uno::Exception(
84 (
"Could not convert \"" + word +
"\" to encoding #"
85 + OUString::number(osl_getThreadTextEncoding())),
86 css::uno::Reference<css::uno::XInterface>());
89 for (sal_Int32 i = 0;
i != sys.getLength(); ++
i) {
94 throw css::uno::Exception(
95 "Could not convert word containing NUL, \"" + word +
"\"",
96 css::uno::Reference<css::uno::XInterface>());
100 buffer.append(
"'\\''");
114 if ( ! xSimpleMailMessage.is() )
116 throw css::lang::IllegalArgumentException(
"No message specified" ,
117 static_cast < XSimpleMailClient *
> (
this), 1 );
122 throw css::uno::Exception(
"Can not access configuration" ,
123 static_cast < XSimpleMailClient *
> (
this) );
127 OUString aProgramURL(
"$BRAND_BASE_DIR/" LIBO_LIBEXEC_FOLDER
"/senddoc");
128 rtl::Bootstrap::expandMacros(aProgramURL);
131 if ( FileBase::E_None != FileBase::getSystemPathFromFileURL(aProgramURL, aProgram))
133 throw css::uno::Exception(
"Could not convert executable path",
134 static_cast < XSimpleMailClient *
> (
this));
138 appendShellWord(
aBuffer, aProgram,
true);
146 PropertyValue aProperty;
147 aProperty.Name =
"nodepath";
148 aProperty.Value <<= OUString(
"org.openoffice.Office.Common/ExternalMailer");
154 "com.sun.star.configuration.ConfigurationAccess",
158 if( xNameAccess.is() )
164 xNameAccess->getByName(
"Program") >>= aMailer;
166 if( !aMailer.isEmpty() )
169 FileBase::getSystemPathFromFileURL( aMailer, aMailer );
171 aBuffer.append(
" --mailclient ");
172 appendShellWord(
aBuffer, aMailer,
true);
176 aBuffer.append(
" --mailclient Mail");
192 OUString sBody = xMessage->getBody();
193 if ( sBody.getLength() > 0 )
196 appendShellWord(
aBuffer, sBody,
false);
206 if ( !xSimpleMailMessage->getOriginator().isEmpty() )
209 appendShellWord(
aBuffer, xSimpleMailMessage->getOriginator(),
false);
213 if ( !xSimpleMailMessage->getRecipient().isEmpty() )
216 appendShellWord(
aBuffer, xSimpleMailMessage->getRecipient(),
false);
221 for (
const auto& rString : std::as_const(
aStringList) )
224 appendShellWord(
aBuffer, rString,
false);
228 aStringList = xSimpleMailMessage->getBccRecipient();
229 for (
const auto& rString : std::as_const(
aStringList) )
232 appendShellWord(
aBuffer, rString,
false);
236 if ( !xSimpleMailMessage->getSubject().isEmpty() )
239 appendShellWord(
aBuffer, xSimpleMailMessage->getSubject(),
false);
243 aStringList = xSimpleMailMessage->getAttachement();
244 for (
const auto& rString : std::as_const(
aStringList) )
246 OUString aSystemPath;
247 if ( FileBase::E_None == FileBase::getSystemPathFromFileURL(rString, aSystemPath) )
250 appendShellWord(
aBuffer, aSystemPath,
true);
254 OString cmd =
aBuffer.makeStringAndClear();
255 FILE * f = popen(cmd.getStr(),
"w");
256 if (f ==
nullptr || pclose(f) != 0)
258 throw css::uno::Exception(
"No mail client configured",
259 static_cast < XSimpleMailClient *
> (
this) );
267 return "com.sun.star.comp.system.SimpleCommandMail";
277 return {
"com.sun.star.system.SimpleCommandMail" };
280extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
282 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
css::uno::Reference< css::lang::XMultiServiceFactory > m_xConfigurationProvider
CmdMailSuppl(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual css::uno::Reference< css::system::XSimpleMailMessage > SAL_CALL createSimpleMailMessage() override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL sendSimpleMailMessage(const css::uno::Reference< css::system::XSimpleMailMessage > &xSimpleMailMessage, sal_Int32 aFlag) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::system::XSimpleMailClient > SAL_CALL querySimpleMailClient() override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * shell_CmdMailSuppl_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define TOOLS_WARN_EXCEPTION(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const std::u16string_view aStringList[]
std::unique_ptr< char[]> aBuffer