E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gfilter.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // gfilter.cpp
19 //
20
21 #include "gdef.h"
22 #include "gsmtp.h"
23 #include "gfilter.h"
24 #include "gstr.h"
25
26 std::string GSmtp::Filter::str( bool server_side ) const
27 {
28 std::string part1 = response().empty() ? "ok=1" : "ok=0" ;
29 std::string part2( abandoned() ? "abandon" : "" ) ;
30 std::string part3( special() ? (server_side?"rescan":"break") : "" ) ;
31
32 std::ostringstream ss ;
33 ss
34 << G::Str::join( " " , part1 , part2 , part3 ) << " "
35 << "response=[" << response() << "]" ;
36 if( reason() != response() )
37 ss << " reason=[" << reason() << "]" ;
38
39 return ss.str() ;
40 }
41
42 GSmtp::Filter::~Filter()
43 {
44 }
45
46 GSmtp::Filter::Exit::Exit( int exit_code , bool server_side ) :
47 result(f_fail) ,
48 special(false)
49 {
50 if( exit_code == 0 )
51 {
52 result = f_ok ;
53 }
54 else if( exit_code >= 1 && exit_code < 100 )
55 {
56 result = f_fail ;
57 }
58 else if( exit_code == 100 )
59 {
60 result = f_abandon ;
61 }
62 else if( exit_code == 101 )
63 {
64 result = f_ok ;
65 }
66 if( server_side )
67 {
68 const bool rescan = true ;
69 if( exit_code == 102 )
70 {
71 result = f_abandon ; special = rescan ;
72 }
73 else if( exit_code == 103 )
74 {
75 result = f_ok ; special = rescan ;
76 }
77 else if( exit_code == 104 && server_side )
78 {
79 result = f_fail ; special = rescan ;
80 }
81 }
82 else // client-side
83 {
84 const bool stop_scanning = true ;
85 if( exit_code == 102 )
86 {
87 result = f_ok ; special = stop_scanning ;
88 }
89 else if( exit_code == 103 )
90 {
91 result = f_ok ;
92 }
93 else if( exit_code == 104 )
94 {
95 result = f_abandon ; special = stop_scanning ;
96 }
97 else if( exit_code == 105 )
98 {
99 result = f_fail ; special = stop_scanning ;
100 }
101 }
102 }
103
104 bool GSmtp::Filter::Exit::ok() const
105 {
106 return result == f_ok ;
107 }
108
109 bool GSmtp::Filter::Exit::abandon() const
110 {
111 return result == f_abandon ;
112 }
113
114 bool GSmtp::Filter::Exit::fail() const
115 {
116 return result == f_fail ;
117 }
118
119 /// \file gfilter.cpp
GSmtp::Filter::str
std::string str(bool server_side) const
Returns a diagnostic string for logging.
Definition: gfilter.cpp:26
GSmtp::Filter::~Filter
virtual ~Filter()
Destructor.
Definition: gfilter.cpp:42
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...
gstr.h
GSmtp::Filter::special
virtual bool special() const =0
Returns true if the filter indicated special handling is required.
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:1023
gfilter.h
gsmtp.h