E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gverifierstatus.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 // gverifierstatus.cpp
19 //
20
21 #include "gdef.h"
22 #include "gsmtp.h"
23 #include "gverifier.h"
24 #include "gverifierstatus.h"
25 #include "gstr.h"
26
27 GSmtp::VerifierStatus::VerifierStatus() :
28 is_valid(false) ,
29 is_local(false) ,
30 temporary(false) ,
31 abort(false)
32 {
33 }
34
35 GSmtp::VerifierStatus::VerifierStatus( const std::string & mbox ) :
36 is_valid(true) ,
37 is_local(false) ,
38 temporary(false) ,
39 abort(false) ,
40 address(mbox)
41 {
42 }
43
44 GSmtp::VerifierStatus GSmtp::VerifierStatus::parse( const std::string & line , std::string & mbox )
45 {
46 try
47 {
48 std::string sep( 1U , '|' ) ;
49 VerifierStatus s ;
50 G::StringArray part ;
51 G::Str::splitIntoFields( line , part , sep ) ;
52 if( part.size() != 9U ) throw std::runtime_error( "incorrect number of parts" ) ;
53 size_t i = 0U ;
54 mbox = part.at(i++) ;
55 s.is_valid = part.at(i++) == "1" ;
56 s.is_local = part.at(i++) == "1" ;
57 s.temporary = part.at(i++) == "1" ;
58 s.abort = part.at(i++) == "1" ;
59 s.full_name = part.at(i++) ;
60 s.address = part.at(i++) ;
61 s.response = part.at(i++) ;
62 s.reason = part.at(i++) ;
63 return s ;
64 }
65 catch( std::exception & )
66 {
67 G_ERROR( "GSmtp::VerifierStatus::parse: invalid stringised status: [" << line << "]" ) ;
68 throw ;
69 }
70 }
71
72 std::string GSmtp::VerifierStatus::str( const std::string & mbox ) const
73 {
74 std::string sep( 1U , '|' ) ;
75 std::string t( "1" ) ;
76 std::string f( "0" ) ;
77 return
78 mbox + sep +
79 (is_valid?t:f) + sep +
80 (is_local?t:f) + sep +
81 (temporary?t:f) + sep +
82 (abort?t:f) + sep +
83 full_name + sep +
84 address + sep +
85 response + sep +
86 reason ;
87 }
88
89 /// \file gverifierstatus.cpp
gverifierstatus.h
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
GSmtp::VerifierStatus::parse
static VerifierStatus parse(const std::string &str, std::string &to_ref)
Parses a str() string into a structure and a recipient 'to' address (by reference).
Definition: gverifierstatus.cpp:44
GSmtp::VerifierStatus::VerifierStatus
VerifierStatus()
Default constructor for an invalid remote mailbox.
Definition: gverifierstatus.cpp:27
gverifier.h
gstr.h
GSmtp::VerifierStatus
A structure returned by GSmtp::Verifier to describe the status of a 'rcpt-to' recipient.
Definition: gverifierstatus.h:51
gsmtp.h
G::Str::splitIntoFields
static void splitIntoFields(const std::string &in, StringArray &out, const std::string &separators, char escape= '\0', bool remove_escapes=true)
Splits the string into fields.
Definition: gstr.cpp:975
GSmtp::VerifierStatus::str
std::string str(const std::string &to) const
Returns a string representation of the structure plus the original recipient 'to' address...
Definition: gverifierstatus.cpp:72