E-MailRelay
gsmtpserverparser.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2023 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 gsmtpserverparser.h
19///
20
21#ifndef G_SMTP_SERVER_PARSER_H
22#define G_SMTP_SERVER_PARSER_H
23
24#include "gdef.h"
25#include "gstringview.h"
26#include <string>
27
28namespace GSmtp
29{
30 class ServerParser ;
31}
32
33//| \class GSmtp::ServerParser
34/// A static mix-in class for GSmtp::ServerProtocol to do SMTP command
35/// parsing. Also provides mailboxStyle() to check a mailbox's
36/// character-set.
37///
38/// See also RFC-5321 4.1.2.
39///
41{
42public:
43 enum class MailboxStyle
44 {
45 Invalid , // eg. NUL or CRLF
46 Ascii , // printable ASCII (RFC-5321 4.1.2)
47 Utf8 // other (RFC-6531)
48 } ;
49 struct AddressCommand /// mail-from or rcpt-to
50 {
51 AddressCommand() = default ;
52 AddressCommand( const std::string & e ) : error(e) {}
53 std::string error ;
54 std::string address ; // SMTP form, possibly quoted and escaped
55 bool utf8address {false} ; // ServerParser::mailboxStyle()
56 std::size_t tailpos {std::string::npos} ;
57 std::size_t size {0U} ;
58 std::string auth ;
59 std::string body ; // 7BIT, 8BITMIME, BINARYMIME
60 bool smtputf8 {false} ; // SMTPUTF8 option
61 } ;
62
63 static MailboxStyle mailboxStyle( const std::string & mailbox ) ;
64 ///< Classifies the given mailbox name.
65 ///< See also RFC-5198.
66
68 ///< Parses a MAIL-FROM command.
69
71 ///< Parses a RCPT-TO command.
72
73 static std::pair<std::size_t,bool> parseBdatSize( G::string_view ) ;
74 ///< Parses a BDAT command.
75
76 static std::pair<bool,bool> parseBdatLast( G::string_view ) ;
77 ///< Parses a BDAT LAST command.
78
79 static std::string parseHeloPeerName( const std::string & ) ;
80 ///< Parses the peer name from an HELO/EHLO command.
81
82 static std::string parseVrfy( const std::string & ) ;
83 ///< Parses a VRFY command.
84
85private:
86 enum class Conversion
87 {
88 None ,
89 ValidXtext ,
90 Upper
91 } ;
92 static AddressCommand parseAddressPart( G::string_view ) ;
93 static std::size_t parseMailNumericValue( G::string_view , G::string_view , AddressCommand & ) ;
94 static std::string parseMailStringValue( G::string_view , G::string_view , AddressCommand & , Conversion = Conversion::None ) ;
95 static bool parseMailBoolean( G::string_view , G::string_view , AddressCommand & ) ;
96} ;
97
98#endif
A static mix-in class for GSmtp::ServerProtocol to do SMTP command parsing.
static MailboxStyle mailboxStyle(const std::string &mailbox)
Classifies the given mailbox name.
static std::string parseVrfy(const std::string &)
Parses a VRFY command.
static std::pair< std::size_t, bool > parseBdatSize(G::string_view)
Parses a BDAT command.
static std::pair< bool, bool > parseBdatLast(G::string_view)
Parses a BDAT LAST command.
static AddressCommand parseMailFrom(G::string_view)
Parses a MAIL-FROM command.
static AddressCommand parseRcptTo(G::string_view)
Parses a RCPT-TO command.
static std::string parseHeloPeerName(const std::string &)
Parses the peer name from an HELO/EHLO command.
A class like c++17's std::string_view.
Definition: gstringview.h:51
SMTP classes.
Definition: gadminserver.h:42