summaryrefslogtreecommitdiff
path: root/src/message/queue_sender.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/message/queue_sender.cpp')
-rw-r--r--src/message/queue_sender.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/message/queue_sender.cpp b/src/message/queue_sender.cpp
index 8f0172a..9dbc8eb 100644
--- a/src/message/queue_sender.cpp
+++ b/src/message/queue_sender.cpp
@@ -5,12 +5,13 @@ namespace smtp::message
{
QueueSender::QueueSender( manage::Settings const& settings_storage,
manage::Mail& mail_to,
- thread::Queue& message_queue)
+ thread::Queue& message_queue,
+ std::shared_ptr<sdbusplus::asio::connection> connection )
: mSettingsStorage( settings_storage )
, mMailTo( mail_to )
, mMessageQueue( message_queue )
+ , mConnection( connection )
{
-
}
void QueueSender::SendMessages()
@@ -33,7 +34,36 @@ namespace smtp::message
std::string QueueSender::GetDefaultMailfrom() const
{
- return "cp2-5422";
+ static const std::string SERVICE_NAME = "org.freedesktop.hostname1";
+ static const std::string PATH_NAME = "/org/freedesktop/hostname1";
+ static const std::string INTERFACE_NAME = "org.freedesktop.hostname1";
+ static const std::string FUNCTION_NAME = "Hostname";
+ static const std::string PROPERTIES_INTERFACE = "org.freedesktop.DBus.Properties";
+ static const std::string PROPERTIES_GETTER_NAME = "Get";
+ static const std::string DEFAULT_HOST = "cp2-5422";
+
+ std::string result = DEFAULT_HOST;
+
+ mConnection->async_method_call(
+ [&result]( const boost::system::error_code& error_code, std::variant<std::monostate, std::string>& host_name) mutable{
+ if (error_code.value() == EBADR ||
+ error_code == boost::system::errc::host_unreachable)
+ {
+ return;
+ }
+ if (error_code)
+ {
+ return;
+ }
+ auto host_as_string = std::get_if<std::string>(&host_name);
+ if(host_as_string)
+ {
+ result = *host_as_string;
+ }
+ },
+ SERVICE_NAME, PATH_NAME, PROPERTIES_INTERFACE, PROPERTIES_GETTER_NAME, INTERFACE_NAME,
+ FUNCTION_NAME);
+ return result;
}
}