gverifierstatus.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 
28  is_valid(false) ,
29  is_local(false) ,
30  temporary(false)
31 {
32 }
33 
34 GSmtp::VerifierStatus::VerifierStatus( const std::string & mbox ) :
35  is_valid(true) ,
36  is_local(false) ,
37  temporary(false) ,
38  address(mbox)
39 {
40 }
41 
42 GSmtp::VerifierStatus GSmtp::VerifierStatus::parse( const std::string & line , std::string & mbox )
43 {
44  try
45  {
46  std::string sep( 1U , '|' ) ;
47  VerifierStatus s ;
48  G::StringArray part ;
49  G::Str::splitIntoFields( line , part , sep ) ;
50  mbox = part[0U] ;
51  s.is_valid = part[1U] == "1" ;
52  s.is_local = part[2U] == "1" ;
53  s.temporary = part[3U] == "1" ;
54  s.full_name = part[4U] ;
55  s.address = part[5U] ;
56  s.reason = part[6U] ;
57  s.help = part[7U] ;
58  return s ;
59  }
60  catch( std::exception & )
61  {
62  G_ERROR( "GSmtp::VerifierStatus::parse: invalid stringised status: [" << line << "]" ) ;
63  throw ;
64  }
65 }
66 
67 std::string GSmtp::VerifierStatus::str( const std::string & mbox ) const
68 {
69  std::string sep( 1U , '|' ) ;
70  std::string t( "1" ) ;
71  std::string f( "0" ) ;
72  return
73  mbox + sep +
74  (is_valid?t:f) + sep +
75  (is_local?t:f) + sep +
76  (temporary?t:f) + sep +
77  full_name + sep +
78  address + sep +
79  reason + sep +
80  help ;
81 }
82 
static void splitIntoFields(const std::string &in, Strings &out, const std::string &seperators, char escape= '\0', bool discard_bogus_escapes=true)
Splits the string into fields.
Definition: gstr.cpp:765
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:44
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).
VerifierStatus()
Default constructor for an invalid remote mailbox.
#define G_ERROR(expr)
Definition: glog.h:108
A structure returned by GSmtp::Verifier to describe the status of a rcpt-to recipient.
std::string str(const std::string &to) const
Returns a string representation of the structure plus the original recipient 'to' address...