From dcbaf61e4968734d9b3bc41f704ea04d54746cea Mon Sep 17 00:00:00 2001 From: eportnov Date: Tue, 13 Sep 2022 11:13:33 +0300 Subject: add file reading --- src/message/builder/cc.cpp | 12 ++++++++++-- src/message/builder/cc.hpp | 1 + src/message/sender.cpp | 27 +++++++++++++-------------- src/message/sender.hpp | 18 +++++++++--------- 4 files changed, 33 insertions(+), 25 deletions(-) (limited to 'src/message') diff --git a/src/message/builder/cc.cpp b/src/message/builder/cc.cpp index 55d70ff..9863abf 100644 --- a/src/message/builder/cc.cpp +++ b/src/message/builder/cc.cpp @@ -21,11 +21,19 @@ namespace smtp::message::builder return result; } - for(const auto& cc : mMailTo) + for( const auto& cc : mMailTo ) { - result += "Cc: " + cc + "\r\n"; + if( !IsFirstElement( cc ) ) + { + result += "Cc: " + cc + "\r\n"; + } } return result; } + + bool Cc::IsFirstElement( std::string const& cc ) const + { + return cc == mMailTo.front(); + } } diff --git a/src/message/builder/cc.hpp b/src/message/builder/cc.hpp index 340c7cd..a06b374 100644 --- a/src/message/builder/cc.hpp +++ b/src/message/builder/cc.hpp @@ -15,6 +15,7 @@ namespace smtp::message::builder std::string Get() const override; private: + bool IsFirstElement( std::string const& cc ) const; std::list const& mMailTo; }; } diff --git a/src/message/sender.cpp b/src/message/sender.cpp index cabcb8f..20b8e9c 100644 --- a/src/message/sender.cpp +++ b/src/message/sender.cpp @@ -16,8 +16,9 @@ namespace smtp::message // // Constructors/Destructors // - Sender::Sender( service::Settings const& settings_storage ) - : mSettingsStorage( settings_storage ) + Sender::Sender( manage::Settings const& settings_storage, manage::Mail const& mail_to ) + : mSettingsStorage( settings_storage ), + mMailTo( mail_to ) { } @@ -26,8 +27,7 @@ namespace smtp::message //Public methods // - bool Sender::Send( std::string const& mail_from, std::string const& mail_to, std::list const& cc, - std::string const& subject, std::string const& text ) + bool Sender::Send( std::string const& mail_from, std::string const& subject, std::string const& text ) { CURLcode result = CURLE_OK; curl_slist *recipients = NULL; @@ -38,8 +38,8 @@ namespace smtp::message { return false; } - FillRecipients( curl, mail_to, cc, recipients ); - UpdateMailText( mail_from, mail_to, cc, subject, text); + FillRecipients( curl, recipients ); + UpdateMailText( mail_from, subject, text); result = curl_easy_perform(curl); @@ -79,24 +79,23 @@ namespace smtp::message return true; } - void Sender::UpdateMailText( std::string const& mail_from, std::string const& mail_to, std::list const& cc, - std::string const& subject, std::string const& text ) const + void Sender::UpdateMailText( std::string const& mail_from, std::string const& subject, std::string const& text ) const { + auto mail_to = mMailTo.GetMailToSend(); auto text_decorator = std::make_shared( text ); text_decorator->Apply( std::make_shared( subject ) ) - .Apply( std::make_shared( cc ) ) + .Apply( std::make_shared( mail_to ) ) .Apply( std::make_shared( mail_from ) ) - .Apply( std::make_shared( mail_to ) ) + .Apply( std::make_shared( mail_to.front() ) ) .Apply( std::make_shared() ); mText = text_decorator->Get(); std::cout << mText << std::endl; } - void Sender::FillRecipients( CURL* curl, std::string const& mail_to, std::list const& cc, curl_slist* recipients ) + void Sender::FillRecipients( CURL* curl, curl_slist* recipients ) { - recipients = curl_slist_append( recipients, mail_to.c_str() ); - - for( const auto& recipient : cc ) + auto mail_to = mMailTo.GetMailToSend(); + for( const auto& recipient : mail_to ) { recipients = curl_slist_append( recipients, recipient.c_str() ); } diff --git a/src/message/sender.hpp b/src/message/sender.hpp index e75faa8..11afd6f 100644 --- a/src/message/sender.hpp +++ b/src/message/sender.hpp @@ -5,8 +5,8 @@ #include -#include "service/settings.hpp" - +#include "managment/settings.hpp" +#include "managment/mail.hpp" namespace smtp::message { struct WriteThis @@ -17,20 +17,20 @@ namespace smtp::message class Sender { public: - Sender( service::Settings const& settings_storage ); + Sender( manage::Settings const& settings_storage, manage::Mail const& mail_to ); ~Sender() = default; - bool Send( std::string const& mail_from, std::string const& mail_to, std::list const& cc, - std::string const& subject, std::string const& text ); + bool Send( std::string const& mail_from, std::string const& subject, std::string const& text ); private: - void UpdateMailText( std::string const& mail_from, std::string const& mail_to, std::list const& cc, - std::string const& subject, std::string const& textt ) const; + void UpdateMailText( std::string const& mail_from, std::string const& subject, std::string const& textt ) const; void InitSenders( std::string const& mail_from, std::list const& mail_to ); - void FillRecipients( CURL* curl, std::string const& mail_to, std::list const& cc, curl_slist* recipients ); + void FillRecipients(CURL* curl, curl_slist* recipients ); std::string GetHostPortData() const; static size_t ReadCallBack( void *ptr, size_t size, size_t nmemb, void *userp ); - service::Settings const& mSettingsStorage; + manage::Settings const& mSettingsStorage; + manage::Mail const& mMailTo; + bool InitCurl( CURL* curl, WriteThis const& upload_ctx, std::string const& mail_from ); }; } -- cgit v1.2.3