E-MailRelay

gfilter.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gfilter.cpp
19///
20
21#include "gdef.h"
22#include "gfilter.h"
23#include "gstr.h"
24
25std::string GSmtp::Filter::str( bool server_side ) const
26{
27 std::string part1 = response().empty() ? "ok=1" : "ok=0" ;
28 std::string part2( abandoned() ? "abandon" : "" ) ;
29 std::string part3( special() ? (server_side?"rescan":"break") : "" ) ;
30
31 std::ostringstream ss ;
32 ss
33 << G::Str::join( " " , part1 , part2 , part3 ) << " "
34 << "response=[" << response() << "]" ;
35 if( reason() != response() )
36 ss << " reason=[" << reason() << "]" ;
37
38 return ss.str() ;
39}
40
41GSmtp::Filter::Exit::Exit( int exit_code , bool server_side ) :
42 result(Result::f_fail) ,
43 special(false)
44{
45 if( exit_code == 0 )
46 {
47 result = Result::f_ok ;
48 }
49 else if( exit_code >= 1 && exit_code < 100 )
50 {
51 result = Result::f_fail ;
52 }
53 else if( exit_code == 100 )
54 {
55 result = Result::f_abandon ;
56 }
57 else if( exit_code == 101 )
58 {
59 result = Result::f_ok ;
60 }
61 if( server_side )
62 {
63 const bool rescan = true ;
64 if( exit_code == 102 )
65 {
66 result = Result::f_abandon ; special = rescan ;
67 }
68 else if( exit_code == 103 )
69 {
70 result = Result::f_ok ; special = rescan ;
71 }
72 else if( exit_code == 104 )
73 {
74 result = Result::f_fail ; special = rescan ;
75 }
76 }
77 else // client-side
78 {
79 const bool stop_scanning = true ;
80 if( exit_code == 102 )
81 {
82 result = Result::f_ok ; special = stop_scanning ;
83 }
84 else if( exit_code == 103 )
85 {
86 result = Result::f_ok ;
87 }
88 else if( exit_code == 104 )
89 {
90 result = Result::f_abandon ; special = stop_scanning ;
91 }
92 else if( exit_code == 105 )
93 {
94 result = Result::f_fail ; special = stop_scanning ;
95 }
96 }
97}
98
99 bool GSmtp::Filter::Exit::ok() const
100{
101 return result == Result::f_ok ;
102}
103
104 bool GSmtp::Filter::Exit::abandon() const
105{
106 return result == Result::f_abandon ;
107}
108
109 bool GSmtp::Filter::Exit::fail() const
110{
111 return result == Result::f_fail ;
112}
113
GSmtp::Filter::special
virtual bool special() const =0
Returns true if the filter indicated special handling is required.
GSmtp::Filter::response
virtual std::string response() const =0
Returns a non-empty response string iff the filter failed, or an empty response if successful or aban...
GSmtp::Filter::reason
virtual std::string reason() const =0
Returns a non-empty reason string iff the filter failed, or an empty reason if successful or abandone...
GSmtp::Filter::str
std::string str(bool server_side) const
Returns a diagnostic string for logging.
Definition: gfilter.cpp:25
GSmtp::Filter::abandoned
virtual bool abandoned() const =0
Returns true if the filter result was 'abandoned'.
G::Str::join
static std::string join(const std::string &sep, const StringArray &strings)
Concatenates an array of strings with separators.
Definition: gstr.cpp:1195
gfilter.h
gstr.h