summaryrefslogtreecommitdiff
path: root/src/management/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/management/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/management/mail.cpp')
-rw-r--r--src/management/mail.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/management/mail.cpp b/src/management/mail.cpp
new file mode 100644
index 0000000..5c3c276
--- /dev/null
+++ b/src/management/mail.cpp
@@ -0,0 +1,71 @@
+#include <algorithm>
+
+#include "mail.hpp"
+
+namespace smtp::manage
+{
+ Mail::Mail( file::Mail const& file_reader )
+ : mFileReader( file_reader )
+ {
+ mMails = mFileReader.Read();
+ }
+
+ MailsSet Mail::GetMailToSend() const
+ {
+ return mMails;
+ }
+
+ 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 = GetMailsAfterDelete( 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;
+ }
+
+ MailsSet Mail::GetItersectionMails( MailsSet const& mail_to_send )
+ {
+ MailsSet result;
+
+ auto sorted_mail_to_send = mail_to_send;
+ sorted_mail_to_send.sort();
+ mMails.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::GetMailsAfterDelete( 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;
+ }
+}