summaryrefslogtreecommitdiff
path: root/src/file/mail.cpp
diff options
context:
space:
mode:
authorclaiff <claiff@mail.ru>2022-09-21 16:05:06 +0300
committerclaiff <claiff@mail.ru>2022-09-21 16:05:06 +0300
commitee8c175e9eae4faccdf913578fb30d09c200204f (patch)
treec2244021130919d5360d130fd3b38954a096687b /src/file/mail.cpp
parenta282ae6418c85db1aae5a2823dd37d56e56e5249 (diff)
parent641c95dcf8c6585caaa6e79d4bec9b53fd666369 (diff)
downloadobmc-sila-smtp-ee8c175e9eae4faccdf913578fb30d09c200204f.tar.xz
Merge branch 'master' into feature/logger
# Conflicts: # CMakeLists.txt # src/file/mail.cpp # src/file/settings.cpp # src/management/logger.cpp # src/management/logger.hpp # src/message/sender.cpp # src/message/sender.hpp
Diffstat (limited to 'src/file/mail.cpp')
-rw-r--r--src/file/mail.cpp91
1 files changed, 41 insertions, 50 deletions
diff --git a/src/file/mail.cpp b/src/file/mail.cpp
index 1453535..cf5fe26 100644
--- a/src/file/mail.cpp
+++ b/src/file/mail.cpp
@@ -5,59 +5,50 @@
namespace smtp::file
{
- Mail::Mail( std::string const& path_file )
- : mPathFile( path_file )
- {
- }
+ Mail::Mail( std::string const& path_file, checker::RegistratorMails const& registrator_errors )
+ : mPathFile( path_file )
+ , mRegistratorErrors( registrator_errors )
+ {
+ }
- manage::MailsSet Mail::Read() const
- {
- std::ifstream mail_file{mPathFile, std::fstream::in};
- if( !mail_file.is_open())
- {
- logger::LoggerSet::GetInstance()->LogError( "Unable to open file to read " + mPathFile );
- return {};
- }
- std::string line{};
- manage::MailsSet result;
+ manage::MailsSet Mail::Read() const
+ {
+ std::ifstream mail_file{ mPathFile, std::fstream::in };
+ if ( !mail_file.is_open() )
+ {
+ manage::Logger::LogError( "Unable to open file to read " + mPathFile );
+ return {};
+ }
+ std::string line{};
+ manage::MailsSet result;
- while( std::getline( mail_file, line ))
- {
- auto parsed_data = GetMailFromLine( line );
- if( parsed_data )
+ while ( std::getline( mail_file, line ) )
+ {
+ if( mRegistratorErrors.Check( line ) )
{
- result.push_back( *parsed_data );
+ result.push_back( line );
}
- }
- mail_file.close();
- return result;
- }
-
- bool Mail::Write( manage::MailsSet const& data ) const
- {
- std::ofstream mail_file{mPathFile, std::fstream::out | std::fstream::trunc};
- if( !mail_file.is_open())
- {
- logger::LoggerSet::GetInstance()->LogError( "Unable to open file to write " + mPathFile );
- return false;
- }
- for( const auto& pair: data )
- {
- mail_file << pair << "\n";
- }
- mail_file.close();
- return true;
- }
-
- std::optional < std::string > Mail::GetMailFromLine( std::string const& line ) const
- {
- //TODO registrator if checking parsing
- auto pos = line.find( '@' );
- if( pos == std::string::npos )
- {
- return {};
- }
- return line;
- }
+ }
+ mail_file.close();
+ return result;
+ }
+ bool Mail::Write( manage::MailsSet const& data ) const
+ {
+ std::ofstream mail_file{ mPathFile, std::fstream::out | std::fstream::trunc };
+ if ( !mail_file.is_open() )
+ {
+ manage::Logger::LogError( "Unable to open file to write " + mPathFile );
+ return false;
+ }
+ for( const auto& mail : data )
+ {
+ if( mRegistratorErrors.Check( mail ) )
+ {
+ mail_file << mail << "\n";
+ }
+ }
+ mail_file.close();
+ return true;
+ }
}