25#include <com/sun/star/mail/MailException.hpp>
27#include <osl/diagnose.h>
35 class MailDeliveryNotifier
38 MailDeliveryNotifier(uno::Reference<mail::XMailMessage> message) :
39 message_(std::move(message))
43 { listener->mailDelivered(message_); }
46 uno::Reference<mail::XMailMessage> message_;
49 class MailDeliveryErrorNotifier
52 MailDeliveryErrorNotifier(
54 uno::Reference<mail::XMailMessage> message,
55 OUString error_message) :
56 m_mail_dispatcher(std::move(xMailDispatcher)),
57 m_message(std::move(message)),
58 m_error_message(std::move(error_message))
62 { listener->mailDeliveryError(m_mail_dispatcher, m_message, m_error_message); }
66 uno::Reference<mail::XMailMessage> m_message;
67 OUString m_error_message;
73 m_xMailserver(
std::move( mailserver )),
75 m_bShutdownRequested( false )
81 throw uno::RuntimeException();
108 uno::Reference<mail::XMailMessage> message;
119 OSL_PRECOND(!
isStarted(),
"MailDispatcher is already started!");
129 thread_status_guard.clear();
135 OSL_PRECOND(
isStarted(),
"MailDispatcher not started!");
145 thread_status_guard.clear();
180 std::for_each( aClonedListenerVector.begin(), aClonedListenerVector.end(),
181 MailDeliveryNotifier(message) );
183 catch (
const mail::MailException&
ex)
186 std::for_each( aClonedListenerVector.begin(), aClonedListenerVector.end(),
187 MailDeliveryErrorNotifier(
this, message,
ex.Message) );
189 catch (
const uno::RuntimeException&
ex)
192 std::for_each( aClonedListenerVector.begin(), aClonedListenerVector.end(),
193 MailDeliveryErrorNotifier(
this, message,
ex.Message) );
199 osl_setThreadName(
"MailDispatcher");
224 thread_status_guard.clear();
227 message_container_guard.clear();
233 message_container_guard.clear();
234 thread_status_guard.clear();
236 for(
const auto & l : aListenerListcloned)
std::vector<::rtl::Reference< IMailDispatcherListener > > m_aListenerVector
css::uno::Reference< css::mail::XSmtpService > m_xMailserver
::osl::Mutex m_aThreadStatusMutex
MailDispatcher(css::uno::Reference< css::mail::XSmtpService > xMailService)
void sendMailMessageNotifyListener(css::uno::Reference< css::mail::XMailMessage > const &message)
void enqueueMailMessage(css::uno::Reference< css::mail::XMailMessage > const &xMailMessage)
Enqueue a mail message for delivery.
void start()
Start sending mail messages asynchronously.
::osl::Condition m_aRunCondition
::osl::Condition m_aWakeupCondition
void stop()
Stop sending mail messages.
std::list< css::uno::Reference< css::mail::XMailMessage > > m_aXMessageList
css::uno::Reference< css::mail::XMailMessage > dequeueMailMessage()
Dequeues a mail message.
std::vector<::rtl::Reference< IMailDispatcherListener > > cloneListener()
virtual void SAL_CALL run() override
virtual ~MailDispatcher() override
Shutdown the mail dispatcher.
bool m_bShutdownRequested
bool isStarted() const
Check whether the mail dispatcher is started or not.
::osl::Mutex m_aListenerContainerMutex
::osl::Mutex m_aMessageContainerMutex
::rtl::Reference< MailDispatcher > m_xSelfReference
void addListener(::rtl::Reference< IMailDispatcherListener > const &listener)
Register a listener for mail dispatcher events.
void shutdown()
Request shutdown of the mail dispatcher thread.
virtual void SAL_CALL onTerminated() override
std::vector< ::rtl::Reference< IMailDispatcherListener > > MailDispatcherListenerContainer_t
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)