diff options
author | eportnov <eportnov@ibs.ru> | 2022-09-13 15:03:29 +0300 |
---|---|---|
committer | eportnov <eportnov@ibs.ru> | 2022-09-13 15:03:29 +0300 |
commit | bab12f829beb53feb6f48db7a0ef33574740989c (patch) | |
tree | b99540f810072b746d033d6cd8d06aabb75afcad /src | |
parent | a58088ec7a45bb86b155a8ef9514b35b0ba8d1c9 (diff) | |
parent | e8aeea36e6b48e18d27f9d7857cd29524cc8aa1f (diff) | |
download | obmc-sila-smtp-bab12f829beb53feb6f48db7a0ef33574740989c.tar.xz |
Merge branch 'bugfix/write_file'
Diffstat (limited to 'src')
-rw-r--r-- | src/file/converter/file.cpp (renamed from src/file/settings_converter.cpp) | 31 | ||||
-rw-r--r-- | src/file/converter/file.hpp | 30 | ||||
-rw-r--r-- | src/file/converter/full.cpp | 17 | ||||
-rw-r--r-- | src/file/converter/full.hpp | 25 | ||||
-rw-r--r-- | src/file/converter/settings.cpp | 65 | ||||
-rw-r--r-- | src/file/converter/settings.hpp | 30 | ||||
-rw-r--r-- | src/file/mail.cpp | 24 | ||||
-rw-r--r-- | src/file/mail.hpp | 8 | ||||
-rw-r--r-- | src/file/settings.cpp | 39 | ||||
-rw-r--r-- | src/file/settings.hpp | 15 | ||||
-rw-r--r-- | src/file/settings_converter.hpp | 41 | ||||
-rw-r--r-- | src/managment/builder/settings.cpp | 2 | ||||
-rw-r--r-- | src/managment/general.hpp | 21 | ||||
-rw-r--r-- | src/managment/mail.cpp | 57 | ||||
-rw-r--r-- | src/managment/mail.hpp | 17 | ||||
-rw-r--r-- | src/managment/settings.cpp | 5 | ||||
-rw-r--r-- | src/managment/settings.hpp | 7 | ||||
-rw-r--r-- | src/message/builder/cc.cpp | 4 | ||||
-rw-r--r-- | src/message/builder/cc.hpp | 7 | ||||
-rw-r--r-- | src/message/builder/mail_to.cpp | 11 | ||||
-rw-r--r-- | src/message/builder/mail_to.hpp | 8 | ||||
-rw-r--r-- | src/message/sender.cpp | 2 | ||||
-rw-r--r-- | src/service/smtp.cpp | 16 |
23 files changed, 360 insertions, 122 deletions
diff --git a/src/file/settings_converter.cpp b/src/file/converter/file.cpp index c64041f..d0bb032 100644 --- a/src/file/settings_converter.cpp +++ b/src/file/converter/file.cpp @@ -1,11 +1,10 @@ -#include "settings_converter.hpp" +#include "file.hpp" -namespace smtp::file +namespace smtp::file::converter { - - SettingsFields SettingsConverter::Convert( ParsedDataType const& from ) const + manage::SettingsFields File::Convert( manage::SettingsFileDataType const& from ) const { - SettingsFields result; + manage::SettingsFields result; ApplyAuth( result, from ); ApplySsl( result, from ); @@ -17,27 +16,21 @@ namespace smtp::file return result; } - std::unordered_map<std::string, std::string> SettingsConverter::Convert( SettingsFields const& from ) const - { - std::unordered_map<std::string, std::string> result; - return result; - } - - void SettingsConverter::ApplyAuth( SettingsFields &result, ParsedDataType const& from ) const + void File::ApplyAuth( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "need_auth"; ApplyBool(from, FIELD, result.is_need_auth); } - void SettingsConverter::ApplySsl( SettingsFields &result, ParsedDataType const& from ) const + void File::ApplySsl( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "need_ssl"; ApplyBool(from, FIELD, result.is_need_ssl); } - void SettingsConverter::ApplyBool( ParsedDataType const& from, std::string const& search_field, bool& field ) const + void File::ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const { static const std::string TRUE_AS_STRING = "true"; static const std::string FALSE_AS_STRING = "false"; @@ -54,35 +47,35 @@ namespace smtp::file field = ( find->second == TRUE_AS_STRING ) ? true : false; } - void SettingsConverter::ApplyUsername( SettingsFields &result, ParsedDataType const& from ) const + void File::ApplyUsername( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "username"; ApplyString( from, FIELD, result.username ); } - void SettingsConverter::ApplyPassword( SettingsFields &result, ParsedDataType const& from ) const + void File::ApplyPassword( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "password"; ApplyString( from, FIELD, result.password ); } - void SettingsConverter::ApplyHost( SettingsFields &result, ParsedDataType const& from ) const + void File::ApplyHost( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "host"; ApplyString( from, FIELD, result.host ); } - void SettingsConverter::ApplyPort( SettingsFields &result, ParsedDataType const& from ) const + void File::ApplyPort( manage::SettingsFields &result, manage::SettingsFileDataType const& from ) const { static const std::string FIELD = "port"; ApplyString(from, FIELD, result.port); } - void SettingsConverter::ApplyString( ParsedDataType const& from, std::string const& search_field, std::string& field ) const + void File::ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const { auto find = from.find( search_field ); if( find == from.end() ) diff --git a/src/file/converter/file.hpp b/src/file/converter/file.hpp new file mode 100644 index 0000000..63ff6dd --- /dev/null +++ b/src/file/converter/file.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <unordered_map> +#include <string> + +#include "managment/general.hpp" + +namespace smtp::file::converter +{ + class File + { + public: + File() = default; + ~File() = default; + + manage::SettingsFields Convert( manage::SettingsFileDataType const& from ) const; + private: + void ApplyAuth( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplySsl( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyBool( manage::SettingsFileDataType const& from, std::string const& search_field, bool& field ) const; + + void ApplyUsername( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyPassword( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyHost( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyPort( manage::SettingsFields& result, manage::SettingsFileDataType const& from ) const; + void ApplyString( manage::SettingsFileDataType const& from, std::string const& search_field, std::string& field ) const; + }; +} + + diff --git a/src/file/converter/full.cpp b/src/file/converter/full.cpp new file mode 100644 index 0000000..61f5a85 --- /dev/null +++ b/src/file/converter/full.cpp @@ -0,0 +1,17 @@ +#include "full.hpp" +#include "file.hpp" +#include "settings.hpp" + +namespace smtp::file::converter +{ + manage::SettingsFields Full::Convert( ParsedDataType const& from ) const + { + return File{}.Convert( from ); + } + + std::unordered_map<std::string, std::string> Full::Convert( manage::SettingsFields const& from ) const + { + return Settings{}.Convert( from ); + + } +} diff --git a/src/file/converter/full.hpp b/src/file/converter/full.hpp new file mode 100644 index 0000000..5ffccd4 --- /dev/null +++ b/src/file/converter/full.hpp @@ -0,0 +1,25 @@ +#pragma once + +#include <unordered_map> +#include <string> + +#include "managment/general.hpp" + +namespace smtp::file::converter +{ + using ParsedDataType = std::unordered_map<std::string, std::string>; + + class Full + { + public: + Full() = default; + ~Full() = default; + + manage::SettingsFields Convert( std::unordered_map<std::string, std::string> const& from ) const; + std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const; + private: + + }; +} + + diff --git a/src/file/converter/settings.cpp b/src/file/converter/settings.cpp new file mode 100644 index 0000000..809eef8 --- /dev/null +++ b/src/file/converter/settings.cpp @@ -0,0 +1,65 @@ +#include "settings.hpp" + +namespace smtp::file::converter +{ + + ParsedDataType Settings::Convert( manage::SettingsFields const& from ) const + { + ParsedDataType result; + + ApplyPort( from, result ); + ApplyHost( from, result ); + ApplyPassword( from, result ); + ApplyUsername( from, result ); + ApplySsl( from, result ); + ApplyAuth( from, result ); + + return result; + } + + void Settings::ApplyAuth( manage::SettingsFields const& from, ParsedDataType& result ) const + { + static const std::string FIELD = "need_auth"; + static const std::string TRUE_AS_STRING = "true"; + static const std::string FALSE_AS_STRING = "false"; + + from.is_need_auth ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING}); + } + + void Settings::ApplySsl( manage::SettingsFields const& from, ParsedDataType& result ) const + { + static const std::string FIELD = "need_ssl"; + static const std::string TRUE_AS_STRING = "true"; + static const std::string FALSE_AS_STRING = "false"; + + from.is_need_ssl ? result.insert({FIELD, TRUE_AS_STRING}) : result.insert({FIELD, FALSE_AS_STRING}); + } + + void Settings::ApplyUsername( manage::SettingsFields const& from, ParsedDataType& result ) const + { + static const std::string FIELD = "username"; + + result.insert({FIELD, from.username}); + } + + void Settings::ApplyPassword( manage::SettingsFields const& from, ParsedDataType& result ) const + { + static const std::string FIELD = "password"; + + result.insert({FIELD, from.password}); + } + + void Settings::ApplyHost( manage::SettingsFields const& from, ParsedDataType& result ) const + { + static const std::string FIELD = "host"; + + result.insert({FIELD, from.host}); + } + + void Settings::ApplyPort( manage::SettingsFields const& from, ParsedDataType& result ) const + { + static const std::string FIELD = "port"; + + result.insert({FIELD, from.port}); + } +} diff --git a/src/file/converter/settings.hpp b/src/file/converter/settings.hpp new file mode 100644 index 0000000..8f94942 --- /dev/null +++ b/src/file/converter/settings.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include <unordered_map> +#include <string> + +#include "managment/general.hpp" + +namespace smtp::file::converter +{ + using ParsedDataType = std::unordered_map<std::string, std::string>;; + + class Settings + { + public: + Settings() = default; + ~Settings() = default; + + std::unordered_map<std::string, std::string> Convert( manage::SettingsFields const& from ) const; + private: + void ApplyAuth( manage::SettingsFields const& from, ParsedDataType& result ) const; + void ApplySsl( manage::SettingsFields const& from, ParsedDataType& result ) const; + + void ApplyUsername( manage::SettingsFields const& from, ParsedDataType& result ) const; + void ApplyPassword( manage::SettingsFields const& from, ParsedDataType& result ) const; + void ApplyHost( manage::SettingsFields const& from, ParsedDataType& result ) const; + void ApplyPort( manage::SettingsFields const& from, ParsedDataType& result ) const; + }; +} + + diff --git a/src/file/mail.cpp b/src/file/mail.cpp index 14e6228..4da36c5 100644 --- a/src/file/mail.cpp +++ b/src/file/mail.cpp @@ -5,21 +5,21 @@ namespace smtp::file { Mail::Mail( std::string const& path_file ) - : PathFile( path_file ) + : mPathFile( path_file ) { } - std::list<std::string> Mail::Read() const + manage::MailsSet Mail::Read() const { - std::ifstream mail_file{ PathFile }; + std::ifstream mail_file{ mPathFile }; if ( !mail_file.is_open() ) { //TODO new file // std::cerr << "Failed to open pcie_devices database \n"; } std::string line{}; - std::list<std::string> result; + manage::MailsSet result; while ( std::getline( mail_file, line ) ) { @@ -32,6 +32,22 @@ namespace smtp::file return result; } + bool Mail::Write( manage::MailsSet const& data ) const + { + std::ofstream settings_file{ mPathFile }; + if ( !settings_file.is_open() ) + { + //TODO new file + // std::cerr << "Failed to open pcie_devices database \n"; + return false; + } + for( const auto& pair : data ) + { + settings_file << pair << "\n"; + } + return true; + } + std::optional<std::string> Mail::GetMailFromLine( std::string const& line ) const { //TODO parsing diff --git a/src/file/mail.hpp b/src/file/mail.hpp index 0f5ade5..34050bf 100644 --- a/src/file/mail.hpp +++ b/src/file/mail.hpp @@ -1,9 +1,10 @@ #pragma once -#include <list> #include <string> #include <optional> +#include "managment/general.hpp" + namespace smtp::file { class Mail @@ -12,11 +13,12 @@ namespace smtp::file explicit Mail( std::string const& path_file ); ~Mail() = default; - std::list<std::string> Read() const; + manage::MailsSet Read() const; + bool Write( manage::MailsSet const& data ) const; private: std::optional<std::string> GetMailFromLine( std::string const& line ) const; - std::string PathFile; + std::string mPathFile; }; } diff --git a/src/file/settings.cpp b/src/file/settings.cpp index bcb2f3e..4691fda 100644 --- a/src/file/settings.cpp +++ b/src/file/settings.cpp @@ -4,24 +4,22 @@ namespace smtp::file { - Settings::Settings( std::string const& path_file, parser::Settings const& parser, SettingsConverter const& converter) + Settings::Settings( std::string const& path_file) : mPathFile( path_file ) - , mParser( parser ) - , mConverter( converter ) { } - SettingsFields Settings::Read() const + manage::SettingsFields Settings::Read() const { auto parsed_store = GetParsedStore(); - return mConverter.Convert( parsed_store ); + return converter::Full{}.Convert( parsed_store ); } - void Settings::Write( SettingsFields const& settings_fields ) const + bool Settings::Write( manage::SettingsFields const& settings_fields ) const { - auto parsed_data = mConverter.Convert( settings_fields ); - SetParsedData(); + auto parsed_data = converter::Full{}.Convert( settings_fields ); + return SetParsedData( parsed_data ); } ParsedStoreType Settings::GetParsedStore() const @@ -37,14 +35,35 @@ namespace smtp::file while ( std::getline( settings_file, line ) ) { - auto parsed_data = mParser.Parse(line); + auto parsed_data = parser::Settings{}.Parse(line); result.insert( parsed_data ); } return result; } - void Settings::SetParsedData() const + bool Settings::SetParsedData( ParsedStoreType const& parsed_data ) const { + std::ofstream settings_file{ mPathFile }; + if ( !settings_file.is_open() ) + { + //TODO new file + // std::cerr << "Failed to open pcie_devices database \n"; + return false; + } + for( const auto& data : parsed_data ) + { + auto line = BuildParam( data ); + settings_file << line << "\n"; + } + return true; + } + std::string Settings::BuildParam( std::pair<std::string, std::string> const& data) const + { + std::string result; + result += data.first; + result += '='; + result += data.second; + return result; } } diff --git a/src/file/settings.hpp b/src/file/settings.hpp index 62182b1..fb77b1e 100644 --- a/src/file/settings.hpp +++ b/src/file/settings.hpp @@ -3,8 +3,9 @@ #include <list> #include <string> -#include "settings_converter.hpp" +#include "converter/full.hpp" #include "parser/settings.hpp" +#include "managment/general.hpp" namespace smtp::file { @@ -13,19 +14,17 @@ namespace smtp::file class Settings { public: - explicit Settings( std::string const& path_file, parser::Settings const& parser, SettingsConverter const& converter ); + explicit Settings( std::string const& path_file ); ~Settings() = default; - SettingsFields Read() const; - void Write( SettingsFields const& settings_fields ) const; + manage::SettingsFields Read() const; + bool Write( manage::SettingsFields const& settings_fields ) const; private: ParsedStoreType GetParsedStore() const; - void SetParsedData() const; + bool SetParsedData( ParsedStoreType const& parsed_data ) const; + std::string BuildParam( std::pair<std::string, std::string> const& data ) const; std::string mPathFile; - parser::Settings mParser; - SettingsConverter mConverter; - }; } diff --git a/src/file/settings_converter.hpp b/src/file/settings_converter.hpp deleted file mode 100644 index 36041c3..0000000 --- a/src/file/settings_converter.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include <unordered_map> -#include <string> - -namespace smtp::file -{ - struct SettingsFields - { - bool is_need_auth; - bool is_need_ssl; - std::string username; - std::string password; - std::string host; - std::string port; - }; - - using ParsedDataType = std::unordered_map<std::string, std::string>;; - - class SettingsConverter - { - public: - SettingsConverter() = default; - ~SettingsConverter() = default; - - SettingsFields Convert( std::unordered_map<std::string, std::string> const& from ) const; - std::unordered_map<std::string, std::string> Convert( SettingsFields const& from ) const; - private: - void ApplyAuth( SettingsFields& result, ParsedDataType const& from ) const; - void ApplySsl( SettingsFields& result, ParsedDataType const& from ) const; - void ApplyBool( ParsedDataType const& from, std::string const& search_field, bool& field ) const; - - void ApplyUsername( SettingsFields& result, ParsedDataType const& from ) const; - void ApplyPassword( SettingsFields& result, ParsedDataType const& from ) const; - void ApplyHost( SettingsFields& result, ParsedDataType const& from ) const; - void ApplyPort( SettingsFields& result, ParsedDataType const& from ) const; - void ApplyString( ParsedDataType const& from, std::string const& search_field, std::string& field ) const; - }; -} - - diff --git a/src/managment/builder/settings.cpp b/src/managment/builder/settings.cpp index fa9fcea..bfa8fb2 100644 --- a/src/managment/builder/settings.cpp +++ b/src/managment/builder/settings.cpp @@ -12,7 +12,7 @@ namespace smtp::manage::builder file::Settings Settings::GetFileSettings() const { static const std::string PATH = {"/home/eportnov/work/openbmc/build/cp2-5422/workspace/sources/smtp/settings.txt"}; - return file::Settings{PATH, {},{}}; + return file::Settings{PATH}; } } diff --git a/src/managment/general.hpp b/src/managment/general.hpp new file mode 100644 index 0000000..ed1a789 --- /dev/null +++ b/src/managment/general.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include <unordered_map> +#include <string> +#include <list> + +namespace smtp::manage +{ + using SettingsFileDataType = std::unordered_map<std::string, std::string>; + using MailsSet = std::list<std::string>; + + struct SettingsFields + { + bool is_need_auth; + bool is_need_ssl; + std::string username; + std::string password; + std::string host; + std::string port; + }; +} diff --git a/src/managment/mail.cpp b/src/managment/mail.cpp index e43a68c..70c5375 100644 --- a/src/managment/mail.cpp +++ b/src/managment/mail.cpp @@ -1,25 +1,72 @@ +#include <algorithm> + #include "mail.hpp" namespace smtp::manage { - Mail::Mail( file::Mail const& file_reader) + Mail::Mail( file::Mail const& file_reader ) + : mFileReader( file_reader ) { - mMails = file_reader.Read(); + mMails = mFileReader.Read(); + mMails.sort(); } - std::list<std::string> Mail::GetMailToSend() const + MailsSet Mail::GetMailToSend() const { return mMails; } - bool Mail::AddMailToSend() + bool Mail::AddMailsToSend( MailsSet const& mails_to_add ) + { + auto merged_mails = GetMergedMails( mails_to_add ); + + auto result = mFileReader.Write( merged_mails ); + if( result ) + { + mMails = merged_mails; + } + return result; + } + + bool Mail::DeleteMailToSend( MailsSet const& mail_to_send ) { + auto mails_to_delete = GetItersectionMails( mail_to_send ); + auto result_set_after_delete = GetSetAfterDelete( mails_to_delete ); + auto result_of_delete = mFileReader.Write( result_set_after_delete ); + if(result_of_delete) + { + mMails = result_set_after_delete; + } + return result_of_delete; + } + MailsSet Mail::GetMergedMails( MailsSet const& mails_to_add ) + { + auto result = mails_to_add; + result.merge( mMails ); + return result; } - bool Mail::DeleteMailToSend( std::string const& mail_to_send) + MailsSet Mail::GetItersectionMails( MailsSet const& mail_to_send ) const { + MailsSet result; + auto sorted_mail_to_send = mail_to_send; + sorted_mail_to_send.sort(); + std::set_intersection( mMails.cbegin(), mMails.cend(), + sorted_mail_to_send.cbegin(), sorted_mail_to_send.cend(), + std::back_inserter( result )); + return result; + } + + MailsSet Mail::GetSetAfterDelete( MailsSet const& result_set_after_delete) + { + auto result = mMails; + for(const auto& element_to_delete : result_set_after_delete) + { + result.remove( element_to_delete ); + } + return result; } } diff --git a/src/managment/mail.hpp b/src/managment/mail.hpp index 5e14831..644a477 100644 --- a/src/managment/mail.hpp +++ b/src/managment/mail.hpp @@ -1,23 +1,28 @@ #pragma once -#include <list> +#include <set> #include <string> #include "file/mail.hpp" namespace smtp::manage { + class Mail { public: - explicit Mail( file::Mail const& file_reader); + explicit Mail( file::Mail const& file_reader ); ~Mail() = default; - std::list<std::string> GetMailToSend() const; - bool AddMailToSend(); - bool DeleteMailToSend( std::string const& mail_to_send ); + MailsSet GetMailToSend() const; + bool AddMailsToSend( MailsSet const& mails ); + bool DeleteMailToSend(MailsSet const&mail_to_send ); private: - std::list<std::string> mMails; + MailsSet GetMergedMails( MailsSet const& mails_to_add ); + MailsSet GetItersectionMails( MailsSet const& mail_to_send ) const; + MailsSet GetSetAfterDelete( MailsSet const& result_set_after_delete); + MailsSet mMails; + file::Mail mFileReader; }; } diff --git a/src/managment/settings.cpp b/src/managment/settings.cpp index 72396f8..1f597c2 100644 --- a/src/managment/settings.cpp +++ b/src/managment/settings.cpp @@ -3,13 +3,14 @@ namespace smtp::manage { Settings::Settings( file::Settings const& file_reader ) + : mFileReader( file_reader ) { mSettingsFields = file_reader.Read(); } - bool Settings::SetSettings( file::SettingsFields const& settings_fields ) + bool Settings::SetSettings( manage::SettingsFields const& settings_fields )const { - + return mFileReader.Write( settings_fields ); } bool Settings::IsNeedAuth() const noexcept diff --git a/src/managment/settings.hpp b/src/managment/settings.hpp index ff40dc6..ff78af6 100644 --- a/src/managment/settings.hpp +++ b/src/managment/settings.hpp @@ -3,7 +3,7 @@ #include <string> #include "file/settings.hpp" - +#include "managment/general.hpp" namespace smtp::manage { class Settings @@ -12,7 +12,7 @@ namespace smtp::manage explicit Settings( file::Settings const& file_reader ); ~Settings() = default; - bool SetSettings( file::SettingsFields const& settings_fields ); + bool SetSettings( manage::SettingsFields const& settings_fields ) const; bool IsNeedAuth() const noexcept; bool IsNeedSsl() const noexcept; @@ -22,6 +22,7 @@ namespace smtp::manage std::string GetHost() const; std::string GetPort() const; private: - file::SettingsFields mSettingsFields; + file::Settings mFileReader; + manage::SettingsFields mSettingsFields; }; } diff --git a/src/message/builder/cc.cpp b/src/message/builder/cc.cpp index 9863abf..3cf3276 100644 --- a/src/message/builder/cc.cpp +++ b/src/message/builder/cc.cpp @@ -2,7 +2,7 @@ namespace smtp::message::builder { - Cc::Cc( std::list<std::string> const& mail_to ) + Cc::Cc( manage::MailsSet const& mail_to ) : mMailTo( mail_to ) { @@ -34,6 +34,6 @@ namespace smtp::message::builder bool Cc::IsFirstElement( std::string const& cc ) const { - return cc == mMailTo.front(); + return cc == *mMailTo.begin(); } } diff --git a/src/message/builder/cc.hpp b/src/message/builder/cc.hpp index a06b374..dbca4b7 100644 --- a/src/message/builder/cc.hpp +++ b/src/message/builder/cc.hpp @@ -1,22 +1,21 @@ #pragma once -#include <list> - #include "types/idecorator.hpp" #include "types/imessage_builder.hpp" +#include "managment/general.hpp" namespace smtp::message::builder { class Cc : public types::IDecorator<types::IMessageBuilder> { public: - explicit Cc( std::list<std::string> const& mail_to ); + explicit Cc( manage::MailsSet const& mail_to ); ~Cc() override = default; std::string Get() const override; private: bool IsFirstElement( std::string const& cc ) const; - std::list<std::string> const& mMailTo; + manage::MailsSet const& mMailTo; }; } diff --git a/src/message/builder/mail_to.cpp b/src/message/builder/mail_to.cpp index dab1b7f..3ef7e0e 100644 --- a/src/message/builder/mail_to.cpp +++ b/src/message/builder/mail_to.cpp @@ -2,8 +2,8 @@ namespace smtp::message::builder { - MailTo::MailTo( std::string const& mail_to) - : mMailTo( mail_to ) + MailTo::MailTo( manage::MailsSet const& mails ) + : mMailTo( mails ) { } @@ -16,8 +16,13 @@ namespace smtp::message::builder result = mBase->Get(); } - result += "To: " + mMailTo +"\r\n"; + result += "To: " + GetFirstMail() +"\r\n"; return result; } + + std::string MailTo::GetFirstMail() const + { + return *mMailTo.begin(); + } } diff --git a/src/message/builder/mail_to.hpp b/src/message/builder/mail_to.hpp index 5d60d97..1c21684 100644 --- a/src/message/builder/mail_to.hpp +++ b/src/message/builder/mail_to.hpp @@ -1,21 +1,21 @@ #pragma once -#include <list> - #include "types/idecorator.hpp" #include "types/imessage_builder.hpp" +#include "managment/general.hpp" namespace smtp::message::builder { class MailTo : public types::IDecorator<types::IMessageBuilder> { public: - explicit MailTo( std::string const& mail_to ); + explicit MailTo( manage::MailsSet const& mails ); ~MailTo() override = default; std::string Get() const override; private: - std::string const& mMailTo; + std::string GetFirstMail() const; + manage::MailsSet const& mMailTo; }; } diff --git a/src/message/sender.cpp b/src/message/sender.cpp index 20b8e9c..f8950f4 100644 --- a/src/message/sender.cpp +++ b/src/message/sender.cpp @@ -86,7 +86,7 @@ namespace smtp::message text_decorator->Apply( std::make_shared<builder::Subject>( subject ) ) .Apply( std::make_shared<builder::Cc>( mail_to ) ) .Apply( std::make_shared<builder::From>( mail_from ) ) - .Apply( std::make_shared<builder::MailTo>( mail_to.front() ) ) + .Apply( std::make_shared<builder::MailTo>( mail_to ) ) .Apply( std::make_shared<builder::Date>() ); mText = text_decorator->Get(); std::cout << mText << std::endl; diff --git a/src/service/smtp.cpp b/src/service/smtp.cpp index e85dda0..cf3dc45 100644 --- a/src/service/smtp.cpp +++ b/src/service/smtp.cpp @@ -14,14 +14,18 @@ namespace smtp::service 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<std::string> cc{"claiff@mail.ru"}; - std::string subject{"subject"}; - std::string text{"text"}; +// std::string from{"claiff@mail.ru"}; +// std::string to{"claiff1990@gmail.com"}; +// std::list<std::string> 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" ); + //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 ); |