summaryrefslogtreecommitdiff
path: root/src/file/mail/checker_decorator.cpp
blob: 54da9da29d5d1f4d85750fc7b91ab8bb636ecfd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "checker_decorator.hpp"
#include "logger/logger_set.hpp"

namespace smtp::file::mail
{

    //
    //Constructors
    //

    CheckerDecorator::CheckerDecorator( checker::RegistratorMails const& registrator_errors )
        : mRegistratorErrors( registrator_errors )
    {
    }

    //
    //Public methods
    //

    manage::MailsSet CheckerDecorator::Read() const
    {
        manage::MailsSet result;

        if( !mBase )
        {
            return result;
        }

        auto parsed_data = mBase->Read();

        for( auto const& line : parsed_data )
        {
            if( mRegistratorErrors.Check( line ) )
            {
                result.push_back( line );
            }
        }
        return result;
    }

    bool CheckerDecorator::Write( manage::MailsSet const& data ) const
    {
        manage::MailsSet result;

        for( const auto& line : data )
        {
            if( mRegistratorErrors.Check( line ) )
            {
                result.push_back( line );
            }
        }
        if( mBase )
        {
            return mBase->Write(result);
        }
        return false;
    }
}