From 942b22b2ef5ba188ea077dd545c5f240a043cf6f Mon Sep 17 00:00:00 2001 From: eportnov Date: Tue, 13 Sep 2022 17:30:47 +0300 Subject: add new interfaces --- src/file/mail.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/file/mail.cpp') diff --git a/src/file/mail.cpp b/src/file/mail.cpp index 4da36c5..1516880 100644 --- a/src/file/mail.cpp +++ b/src/file/mail.cpp @@ -7,12 +7,11 @@ namespace smtp::file Mail::Mail( std::string const& path_file ) : mPathFile( path_file ) { - } manage::MailsSet Mail::Read() const { - std::ifstream mail_file{ mPathFile }; + std::ifstream mail_file{ mPathFile, std::fstream::in }; if ( !mail_file.is_open() ) { //TODO new file @@ -29,13 +28,14 @@ namespace smtp::file result.push_back( *parsed_data ); } } + mail_file.close(); return result; } bool Mail::Write( manage::MailsSet const& data ) const { - std::ofstream settings_file{ mPathFile }; - if ( !settings_file.is_open() ) + std::ofstream mail_file{ mPathFile, std::fstream::out | std::fstream::trunc }; + if ( !mail_file.is_open() ) { //TODO new file // std::cerr << "Failed to open pcie_devices database \n"; @@ -43,8 +43,9 @@ namespace smtp::file } for( const auto& pair : data ) { - settings_file << pair << "\n"; + mail_file << pair << "\n"; } + mail_file.close(); return true; } -- cgit v1.2.3