E-MailRelay

gsmtpclientreply.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 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 gsmtpclientreply.h
19///
20
21#ifndef G_SMTP_CLIENT_REPLY_H
22#define G_SMTP_CLIENT_REPLY_H
23
24#include "gdef.h"
25#include "gstringarray.h"
26#include <string>
27
28 namespace GSmtp
29{
30 class ClientReply ;
31}
32
33//| \class GSmtp::ClientReply
34/// Encapsulates SMTP replies from a remote client, or replies from
35/// a client filter, or the result of a TLS handshake.
36///
37 class GSmtp::ClientReply
38{
39 public:
40 enum class Value
41 {
42 Invalid = 0 ,
43 Internal_start = 1 ,
44 Internal_filter_ok = 2 ,
45 Internal_filter_abandon = 3 ,
46 Internal_filter_error = 4 ,
47 Internal_secure = 5 ,
48 ServiceReady_220 = 220 ,
49 Ok_250 = 250 ,
50 Authenticated_235 = 235 ,
51 Challenge_334 = 334 ,
52 OkForData_354 = 354 ,
53 SyntaxError_500 = 500 ,
54 SyntaxError_501 = 501 ,
55 NotImplemented_502 = 502 ,
56 BadSequence_503 = 503 ,
57 NotAuthenticated_535 = 535 ,
58 NotAvailable_454 = 454
59 } ;
60
61 static bool valid( const G::StringArray & ) ;
62 ///< Returns true if the reply text is syntactivally valid
63 ///< but possibly incomplete.
64
65 static bool complete( const G::StringArray & ) ;
66 ///< Returns true if the reply text is valid() and complete.
67
68 explicit ClientReply( const G::StringArray & text , char sep = '\n' ) ;
69 ///< Constructor taking lines of text from the remote SMTP client.
70 ///< If there is more than one line in the SMTP response (eg. in
71 ///< the EHLO response) then the resulting text() value is a
72 ///< concatenation using the given separator.
73 ///<
74 ///< Precondition: complete(text)
75
76 static ClientReply ok() ;
77 ///< Factory function returning a generic 'Ok' reply object
78 ///< with a value() of 250.
79
80 static ClientReply secure() ;
81 ///< Factory function for Internal_secure.
82
83 static ClientReply filterOk() ;
84 ///< Factory function for Internal_filter_ok.
85
86 static ClientReply filterAbandon() ;
87 ///< Factory function for Internal_filter_abandon.
88
89 static ClientReply filterError( const std::string & response , const std::string & filter_reason ) ;
90 ///< Factory function for Internal_filter_error.
91
92 static ClientReply start() ;
93 ///< Factory function for Internal_start.
94
95 bool positive() const ;
96 ///< Returns true if value() is between 100 and 399.
97
98 bool positiveCompletion() const ;
99 ///< Returns true if value() is between 200 and 299.
100
101 bool is( Value v ) const ;
102 ///< Returns true if the value() is as given.
103
104 int value() const ;
105 ///< Returns the numeric value of the reply.
106
107 std::string text() const ;
108 ///< Returns the text of the reply, with some whitespace
109 ///< normalisation and no tabs.
110
111 int doneCode() const ;
112 ///< Returns -1 for filterAbandon() or -2 for filterError()
113 ///< or zero if less than 100 or value().
114 /// \see GSmtp::ClientProtocol::doneSignal()
115
116 std::string errorText() const ;
117 ///< Returns the empty string if positiveCompletion()
118 ///< or non-empty text() or "error".
119
120 std::string reason() const ;
121 ///< Returns the filter-reason text from a filterError() reply
122 ///< or the empty string.
123
124 private:
125 ClientReply() ;
126 static bool isDigit( char ) ;
127 static bool validLine( const std::string & line , std::string & , std::size_t , std::size_t ) ;
128 static ClientReply internal( Value , int ) ;
129
130 private:
131 int m_value {0} ;
132 int m_done_code {0} ;
133 std::string m_text ;
134 std::string m_filter_reason ; // if Internal_filter_error
135} ;
136
137#endif
GSmtp::ClientReply
Encapsulates SMTP replies from a remote client, or replies from a client filter, or the result of a T...
Definition: gsmtpclientreply.h:38
GSmtp::ClientReply::errorText
std::string errorText() const
Returns the empty string if positiveCompletion() or non-empty text() or "error".
Definition: gsmtpclientreply.cpp:178
GSmtp::ClientReply::positiveCompletion
bool positiveCompletion() const
Returns true if value() is between 200 and 299.
Definition: gsmtpclientreply.cpp:158
GSmtp::ClientReply::secure
static ClientReply secure()
Factory function for Internal_secure.
Definition: gsmtpclientreply.cpp:53
GSmtp::ClientReply::filterAbandon
static ClientReply filterAbandon()
Factory function for Internal_filter_abandon.
Definition: gsmtpclientreply.cpp:68
GSmtp::ClientReply::value
int value() const
Returns the numeric value of the reply.
Definition: gsmtpclientreply.cpp:163
GSmtp::ClientReply::text
std::string text() const
Returns the text of the reply, with some whitespace normalisation and no tabs.
Definition: gsmtpclientreply.cpp:188
GSmtp::ClientReply::start
static ClientReply start()
Factory function for Internal_start.
Definition: gsmtpclientreply.cpp:58
GSmtp::ClientReply::positive
bool positive() const
Returns true if value() is between 100 and 399.
Definition: gsmtpclientreply.cpp:153
GSmtp::ClientReply::reason
std::string reason() const
Returns the filter-reason text from a filterError() reply or the empty string.
Definition: gsmtpclientreply.cpp:183
GSmtp::ClientReply::filterOk
static ClientReply filterOk()
Factory function for Internal_filter_ok.
Definition: gsmtpclientreply.cpp:63
GSmtp::ClientReply::ok
static ClientReply ok()
Factory function returning a generic 'Ok' reply object with a value() of 250.
Definition: gsmtpclientreply.cpp:33
GSmtp::ClientReply::complete
static bool complete(const G::StringArray &)
Returns true if the reply text is valid() and complete.
Definition: gsmtpclientreply.cpp:123
GSmtp::ClientReply::is
bool is(Value v) const
Returns true if the value() is as given.
Definition: gsmtpclientreply.cpp:168
GSmtp::ClientReply::filterError
static ClientReply filterError(const std::string &response, const std::string &filter_reason)
Factory function for Internal_filter_error.
Definition: gsmtpclientreply.cpp:73
GSmtp::ClientReply::doneCode
int doneCode() const
Returns -1 for filterAbandon() or -2 for filterError() or zero if less than 100 or value().
Definition: gsmtpclientreply.cpp:173
GSmtp::ClientReply::valid
static bool valid(const G::StringArray &)
Returns true if the reply text is syntactivally valid but possibly incomplete.
Definition: gsmtpclientreply.cpp:109
gstringarray.h
GSmtp
SMTP classes.
Definition: gadminserver.h:42
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30