Leosac  0.8.0
Open Source Access Control
SMTPModule.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
23 #include "modules/AsioModule.hpp"
24 #include "modules/smtp/SMTPFwd.hpp"
27 #include "tools/ToolsFwd.hpp"
28 #include "tools/bs2.hpp"
30 #include <boost/asio/io_service.hpp>
31 #include <boost/asio/steady_timer.hpp>
32 #include <curl/curl.h>
33 #include <nlohmann/json.hpp>
34 
35 namespace Leosac
36 {
37 namespace Module
38 {
39 namespace SMTP
40 {
42 
43 class SMTPModule : public AsioModule
44 {
45  public:
46  SMTPModule(zmqpp::context &ctx, zmqpp::socket *pipe,
47  const boost::property_tree::ptree &cfg, CoreUtilsPtr utils);
48 
49  ~SMTPModule();
50 
57  void async_send_mail(const MailInfo &mail);
58 
59  private:
64 
69 
74 
78  void process_config();
79 
81 
86 
87  void setup_database();
88 
89  bool prepare_curl(const MailInfo &mail);
90 
91  bool send_mail(CURL *curl, const MailInfo &mail);
92  static constexpr const char *wshandler_getconfig = "module.smtp.getconfig";
93  static constexpr const char *wshandler_setconfig = "module.smtp.setconfig";
94  static constexpr const char *wshandler_sendmail = "module.smtp.sendmail";
95 
96  virtual void on_service_event(const service_event::Event &) override;
97 
105  void register_ws_handlers();
106 };
107 }
108 }
109 }
Leosac::Module::SMTP::SMTPModule::send_mail
bool send_mail(CURL *curl, const MailInfo &mail)
Definition: SMTPModule.cpp:238
Leosac::Module::SMTP::SMTPModule
Definition: SMTPModule.hpp:43
Leosac::Module::SMTP::SMTPModule::setup_database
void setup_database()
Definition: SMTPModule.cpp:268
Leosac::Module::SMTP::SMTPModule::~SMTPModule
~SMTPModule()
Definition: SMTPModule.cpp:74
Leosac::Module::SMTP::SMTPModule::handle_ws_smtp_setconfig
json handle_ws_smtp_setconfig(const WebSockAPI::RequestContext &, const json &)
Process the websocket request "smtp.setconfig".
Definition: SMTPModule.cpp:312
Leosac::Module::SMTP::SMTPModule::on_service_event
virtual void on_service_event(const service_event::Event &) override
Function invoked when a service event is triggered.
Definition: SMTPModule.cpp:354
Leosac::Module::SMTP::SMTPModule::handle_ws_smtp_sendmail
json handle_ws_smtp_sendmail(const WebSockAPI::RequestContext &, const json &)
Process thesocket request "smtp.sendmail".
Definition: SMTPModule.cpp:341
AsioModule.hpp
ServiceRegistry.hpp
json
nlohmann::json json
Definition: WSServer.cpp:76
Leosac::Module::SMTP::SMTPModule::handle_ws_smtp_getconfig
json handle_ws_smtp_getconfig(const WebSockAPI::RequestContext &, const json &)
Process the websocket request "smtp.getconfig".
Definition: SMTPModule.cpp:300
RequestContext.hpp
Leosac::Module::SMTP::SMTPModule::register_ws_handlers
void register_ws_handlers()
Attempt to register websocket handlers against the websocket service, if available.
Definition: SMTPModule.cpp:381
bs2.hpp
Leosac::MailInfo
Definition: Mail.hpp:30
PolymorphicAuditSerializer.hpp
ToolsFwd.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::AsioModule
This is a base class for boost::asio 'aware' module.
Definition: AsioModule.hpp:40
Leosac::Module::SMTP::SMTPConfigUPtr
std::unique_ptr< SMTPConfig > SMTPConfigUPtr
Definition: SMTPFwd.hpp:34
Leosac::Module::SMTP::SMTPModule::async_send_mail
void async_send_mail(const MailInfo &mail)
Asynchronously and thread-safely send an email.
Definition: SMTPModule.cpp:425
Leosac::Module::SMTP::SMTPModule::process_config
void process_config()
Process the configuration file.
Definition: SMTPModule.cpp:88
Leosac::Module::SMTP::json
nlohmann::json json
Definition: SMTPModule.hpp:41
Leosac::Module::SMTP::SMTPModule::prepare_curl
bool prepare_curl(const MailInfo &mail)
Definition: SMTPModule.cpp:142
Leosac::Module::SMTP::SMTPModule::SMTPModule
SMTPModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
Definition: SMTPModule.cpp:43
SMTPFwd.hpp
WebSockFwd.hpp
Leosac::Module::SMTP::SMTPModule::wshandler_setconfig
static constexpr const char * wshandler_setconfig
Definition: SMTPModule.hpp:93
Leosac::service_event::Event
Definition: ServiceRegistry.hpp:37
Leosac::Module::WebSockAPI::RequestContext
Holds valuable pointer to provide context to a request.
Definition: RequestContext.hpp:36
Leosac::Module::SMTP::SMTPModule::use_database_
bool use_database_
Definition: SMTPModule.hpp:80
Leosac::Module::SMTP::SMTPModule::wshandler_sendmail
static constexpr const char * wshandler_sendmail
Definition: SMTPModule.hpp:94
Leosac::CoreUtilsPtr
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
Leosac::Module::SMTP::SMTPModule::smtp_config_
SMTPConfigUPtr smtp_config_
Configuration: either load from XML or database.
Definition: SMTPModule.hpp:85
Leosac::Module::SMTP::SMTPModule::wshandler_getconfig
static constexpr const char * wshandler_getconfig
Definition: SMTPModule.hpp:92