#include "smtp.hpp" #include "message/sender.hpp" #include namespace smtp::service { static constexpr char HOST_PROPERTY[] = "Host"; static constexpr char USER_PROPERTY[] = "User"; static constexpr char PORT_PROPERTY[] = "Port"; // // Constructors // Smtp::Smtp( ConnectionPtr connection, manage::Settings const& settings, manage::Mail const& mail_to ) :mSettingsStorage(settings), mMailTo(mail_to) { // std::string from{"claiff@mail.ru"}; // std::string to{"claiff1990@gmail.com"}; // std::list cc{"claiff@mail.ru"}; // std::string subject{"subject"}; // std::string text{"text"}; // mSettingsStorage.CheckAndSetSettings({true, true, "claiff@mail.ru","nZZbXq7FbwWAqpPpy3YL", "smtp.mail.ru", "" }); //message::Sender{ mSettingsStorage, mMailTo }.Send( "claiff@mail.ru", "subject", "text" ); //settings.SetSettings(manage::SettingsFields{false,false,"claiff@mail.ru","nZZbXq7FbwWAqpPpy3YL","smtp.mail.ru",""}); manage::MailsSet add_mail{"gfdgdf@fd.ru"}; //mMailTo.AddMailsToSend( add_mail ); mMailTo.DeleteMailToSend({"gfdgdf@fd.ru", "rwer", "fedsfsd"}); // CreateService( connection ); // CreateInterface( connection ); } // // Private methods // void Smtp::CreateService( ConnectionPtr connection ) { static constexpr char SMTP_BUS_NAME[] = "xyz.openbmc_project.SMTP"; connection->request_name( SMTP_BUS_NAME ); } void Smtp::CreateInterface( ConnectionPtr connection ) { static constexpr char SMTP_OBJECT_NAME[] = "/xyz/openbmc_project/SMTP"; static constexpr char SMTP_INTERFACE_NAME[] = "xyz.openbmc_project.SMTP"; mObjectServer = std::make_shared( connection ); mInterface = mObjectServer->add_interface( SMTP_OBJECT_NAME, SMTP_INTERFACE_NAME ); AddProperties(); AddMethods(); mInterface->initialize(); } void Smtp::AddProperties() { mInterface->register_property( HOST_PROPERTY, mSettingsStorage.GetHost(), sdbusplus::asio::PropertyPermission::readOnly ); mInterface->register_property( USER_PROPERTY, mSettingsStorage.GetUserName(), sdbusplus::asio::PropertyPermission::readOnly ); mInterface->register_property( PORT_PROPERTY, mSettingsStorage.GetPort(), sdbusplus::asio::PropertyPermission::readOnly ); } void Smtp::AddMethods() { static constexpr char SMTP_SEND_MESSAGE_METHOD_NAME[] = "SendMail"; static constexpr char SMTP_CHANGE_PARAMETERS_METHOD_NAME[] = "ChangeParameters"; mInterface->register_method(SMTP_SEND_MESSAGE_METHOD_NAME, [this]( std::string const& mail_from, std::string const& theme, std::string const& text ) { return message::Sender{ mSettingsStorage, mMailTo }.Send( mail_from, theme, text );}); mInterface->register_method(SMTP_CHANGE_PARAMETERS_METHOD_NAME, [this]( bool is_need_auth, bool is_need_ssl, std::string const& user, std::string const& password, std::string const& host, std::string const& port ) { return RefreshSettings( is_need_auth, is_need_ssl, user, password, host, port);}); } bool Smtp::RefreshSettings( bool is_need_auth, bool is_need_ssl, std::string const& user, std::string const& password, std::string const& host, std::string const& port ) { auto is_settings_norm = mSettingsStorage.SetSettings({is_need_auth, is_need_ssl, user, password, host, port}); if(!is_settings_norm) { return false; } mInterface->set_property(HOST_PROPERTY, host); mInterface->set_property(USER_PROPERTY, user); mInterface->set_property(PORT_PROPERTY, port); return true; } }