Leosac  0.7.0
OpenSourceAccessControl
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 <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 }
json handle_ws_smtp_sendmail(const WebSockAPI::RequestContext &, const json &)
Process thesocket request "smtp.sendmail".
Definition: SMTPModule.cpp:341
void process_config()
Process the configuration file.
Definition: SMTPModule.cpp:88
json handle_ws_smtp_getconfig(const WebSockAPI::RequestContext &, const json &)
Process the websocket request "smtp.getconfig".
Definition: SMTPModule.cpp:300
This is the header file for a generated source file, GitSHA1.cpp.
void register_ws_handlers()
Attempt to register websocket handlers against the websocket service, if available.
Definition: SMTPModule.cpp:381
SMTPModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
Definition: SMTPModule.cpp:43
static constexpr const char * wshandler_getconfig
Definition: SMTPModule.hpp:92
bool send_mail(CURL *curl, const MailInfo &mail)
Definition: SMTPModule.cpp:238
SMTPConfigUPtr smtp_config_
Configuration: either load from XML or database.
Definition: SMTPModule.hpp:85
static constexpr const char * wshandler_sendmail
Definition: SMTPModule.hpp:94
json handle_ws_smtp_setconfig(const WebSockAPI::RequestContext &, const json &)
Process the websocket request "smtp.setconfig".
Definition: SMTPModule.cpp:312
std::unique_ptr< SMTPConfig > SMTPConfigUPtr
Definition: SMTPFwd.hpp:34
This is a base class for boost::asio &#39;aware&#39; module.
Definition: AsioModule.hpp:40
nlohmann::json json
Definition: SMTPModule.hpp:41
bool prepare_curl(const MailInfo &mail)
Definition: SMTPModule.cpp:142
static constexpr const char * wshandler_setconfig
Definition: SMTPModule.hpp:93
nlohmann::json json
Definition: WSServer.cpp:76
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
Holds valuable pointer to provide context to a request.
void async_send_mail(const MailInfo &mail)
Asynchronously and thread-safely send an email.
Definition: SMTPModule.cpp:425
virtual void on_service_event(const service_event::Event &) override
Function invoked when a service event is triggered.
Definition: SMTPModule.cpp:354