From d981f7230bc641614c590717e16ac694762d92ac Mon Sep 17 00:00:00 2001 From: claiff Date: Fri, 23 Sep 2022 17:30:29 +0300 Subject: add mail error with empty file add boolean settings ssl and auth --- src/checker/errors/mail/empty.cpp | 2 +- src/management/builder/mail.cpp | 4 ++-- src/message/sender.cpp | 13 ++++++++++--- src/message/sender.hpp | 3 +-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/checker/errors/mail/empty.cpp b/src/checker/errors/mail/empty.cpp index 06f6f4c..a893fbb 100644 --- a/src/checker/errors/mail/empty.cpp +++ b/src/checker/errors/mail/empty.cpp @@ -4,6 +4,6 @@ namespace smtp::checker::errors::settings { bool Empty::Check( std::string const& line ) const { - return !line.empty(); + return !line.empty() && line != " "; } } diff --git a/src/management/builder/mail.cpp b/src/management/builder/mail.cpp index f72803f..f7e882d 100644 --- a/src/management/builder/mail.cpp +++ b/src/management/builder/mail.cpp @@ -1,5 +1,6 @@ #include "mail.hpp" #include "file/mail.hpp" +#include "checker/errors/mail/empty.hpp" namespace smtp::manage::builder { @@ -15,8 +16,7 @@ namespace smtp::manage::builder checker::RegistratorMails Mail::BuildErrorRegistrator() const { checker::RegistratorMails result; - - + result.Add( std::make_shared < checker::errors::settings::Empty >()); return result; } diff --git a/src/message/sender.cpp b/src/message/sender.cpp index 85c5d5d..a7e3128 100644 --- a/src/message/sender.cpp +++ b/src/message/sender.cpp @@ -76,11 +76,18 @@ namespace smtp::message { return false; } - curl_easy_setopt( curl, CURLOPT_USERNAME, mSettingsStorage.GetUserName().c_str()); - curl_easy_setopt( curl, CURLOPT_PASSWORD, mSettingsStorage.GetPassword().c_str()); + + if( mSettingsStorage.IsNeedAuth()) + { + curl_easy_setopt( curl, CURLOPT_USERNAME, mSettingsStorage.GetUserName().c_str()); + curl_easy_setopt( curl, CURLOPT_PASSWORD, mSettingsStorage.GetPassword().c_str()); + } + curl_easy_setopt( curl, CURLOPT_URL, GetHostPortData().c_str()); - curl_easy_setopt( curl, CURLOPT_USE_SSL, ( long ) CURLUSESSL_ALL ); + mSettingsStorage.IsNeedSsl() ? curl_easy_setopt( curl, CURLOPT_USE_SSL, ( long ) CURLUSESSL_ALL ) : + curl_easy_setopt( curl, CURLOPT_USE_SSL, ( long ) CURLUSESSL_NONE ); + curl_easy_setopt( curl, CURLOPT_MAIL_FROM, mail_from.c_str()); curl_easy_setopt( curl, CURLOPT_READFUNCTION, ReadCallBack ); diff --git a/src/message/sender.hpp b/src/message/sender.hpp index ba5953e..3118319 100644 --- a/src/message/sender.hpp +++ b/src/message/sender.hpp @@ -22,6 +22,7 @@ namespace smtp::message bool Send( std::string const& mail_from, std::string const& subject, std::string const& text ); private: + bool InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from ); void UpdateMailText( std::string const& mail_from, std::string const& subject, std::string const& textt ) const; void FillRecipients(CURL* curl, curl_slist* recipients ); std::string GetHostPortData() const; @@ -29,8 +30,6 @@ namespace smtp::message manage::Settings& mSettingsStorage; manage::Mail const& mMailTo; - - bool InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from ); }; } -- cgit v1.2.3