38void GSmtp::ServerSend::sendChallenge(
const std::string & challenge )
43void GSmtp::ServerSend::sendGreeting(
const std::string & text ,
bool enabled )
46 send(
"220 " + text ) ;
51void GSmtp::ServerSend::sendReadyForTls()
53 send(
"220 ready to start tls" ,
true ) ;
56void GSmtp::ServerSend::sendInvalidArgument()
58 send(
"501 invalid argument" ) ;
61void GSmtp::ServerSend::sendAuthenticationCancelled()
63 send(
"501 authentication cancelled" ) ;
66void GSmtp::ServerSend::sendInsecureAuth(
bool with_starttls_help )
68 if( with_starttls_help )
69 send(
"504 unsupported authentication mechanism: use starttls" ) ;
71 send(
"504 unsupported authentication mechanism" ) ;
74void GSmtp::ServerSend::sendBadMechanism(
const std::string & preferred )
76 if( preferred.empty() )
77 send(
"504 unsupported authentication mechanism" ) ;
79 send(
"432 " +
G::Str::upper(preferred) +
" password transition needed" ) ;
82void GSmtp::ServerSend::sendAuthDone(
bool ok )
85 send(
"235 authentication successful" ) ;
87 send(
"535 authentication failed" ) ;
90void GSmtp::ServerSend::sendBadDataOutOfSequence()
92 send(
"503 invalid data command with binarymime -- use RSET to resynchronise" ) ;
95void GSmtp::ServerSend::sendOutOfSequence()
97 send(
"503 command out of sequence -- use RSET to resynchronise" ) ;
100void GSmtp::ServerSend::sendMissingParameter()
102 send(
"501 parameter required" ) ;
105void GSmtp::ServerSend::sendQuitOk()
110void GSmtp::ServerSend::sendVerified(
const std::string & user )
112 send(
"250 " + user ) ;
115void GSmtp::ServerSend::sendCannotVerify()
117 send(
"252 cannot vrfy" ) ;
120void GSmtp::ServerSend::sendNotVerified(
const std::string & response ,
bool temporary )
122 send( (temporary?
"450":
"550") + std::string(1U,
' ') + response ) ;
125void GSmtp::ServerSend::sendWillAccept(
const std::string & user )
127 send(
"252 cannot verify but will accept: " + user ) ;
130void GSmtp::ServerSend::sendUnrecognised(
const std::string & )
132 send(
"500 command unrecognized" ) ;
135void GSmtp::ServerSend::sendNotImplemented()
137 send(
"502 command not implemented" ) ;
140void GSmtp::ServerSend::sendAuthRequired(
bool with_starttls_help )
142 if( with_starttls_help )
143 send(
"530 authentication required: use starttls" ) ;
145 send(
"530 authentication required" ) ;
148void GSmtp::ServerSend::sendDisabled()
150 send(
"421 service not available" ) ;
153void GSmtp::ServerSend::sendEncryptionRequired(
bool with_starttls_help )
155 if( with_starttls_help )
156 send(
"530 encryption required: use starttls" ) ;
158 send(
"530 encryption required" ) ;
161void GSmtp::ServerSend::sendNoRecipients()
163 send(
"554 no valid recipients" ) ;
166void GSmtp::ServerSend::sendTooBig()
168 send(
"552 message size exceeds fixed maximum message size" ) ;
171void GSmtp::ServerSend::sendDataReply()
173 send(
"354 start mail input -- end with <CRLF>.<CRLF>" ) ;
176void GSmtp::ServerSend::sendRsetReply()
178 send(
"250 state reset" ) ;
181void GSmtp::ServerSend::sendMailReply(
const std::string & from )
183 sendOk(
"sender <" + from +
"> OK" ) ;
186void GSmtp::ServerSend::sendCompletionReply(
bool ok ,
int response_code ,
const std::string & response )
189 sendOk(
"message processed" ) ;
190 else if( response_code >= 400 && response_code < 600 )
191 send(
G::Str::fromInt(response_code).append(1U,
' ').append(response) ) ;
193 send(
"452 " + response ) ;
196void GSmtp::ServerSend::sendFailed()
198 send(
"554 transaction failed" ) ;
201void GSmtp::ServerSend::sendRcptReply(
const std::string & to ,
bool is_local )
204 sendOk( std::string(
"recipient <").append(to).append(is_local?
"> ":
"> ").append(
"OK") ) ;
207void GSmtp::ServerSend::sendBadFrom(
const std::string & response_extra )
209 std::string response =
"553 mailbox name not allowed" ;
210 if( !response_extra.empty() )
212 response.append(
": " ) ;
213 response.append( response_extra ) ;
218void GSmtp::ServerSend::sendBadTo(
const std::string & to ,
const std::string & text ,
bool temporary )
221 std::string(temporary?
"450":
"550") ,
226void GSmtp::ServerSend::sendEhloReply(
const Advertise & advertise )
230 std::ostringstream ss ;
233 if( advertise.max_size != 0U )
234 ss <<
"250-SIZE " << advertise.max_size << crlf ;
236 if( !advertise.mechanisms.empty() )
237 ss <<
"250-AUTH " <<
G::Str::join(
" ",advertise.mechanisms) << crlf ;
239 if( advertise.starttls )
240 ss <<
"250-STARTTLS" << crlf ;
243 ss <<
"250-VRFY" << crlf ;
245 if( advertise.chunking )
246 ss <<
"250-CHUNKING" << crlf ;
248 if( advertise.binarymime )
249 ss <<
"250-BINARYMIME" << crlf ;
251 if( advertise.pipelining )
252 ss <<
"250-PIPELINING" << crlf ;
254 if( advertise.smtputf8 )
255 ss <<
"250-SMTPUTF8" << crlf ;
257 ss <<
"250 8BITMIME" ;
262void GSmtp::ServerSend::sendHeloReply()
267void GSmtp::ServerSend::sendOk(
const std::string & text )
269 send( std::string(
"250 ").append(text) ) ;
273void GSmtp::ServerSend::sendOk()
279void GSmtp::ServerSend::send(
const char * line )
281 send( std::string(line) ) ;
284void GSmtp::ServerSend::send( std::string line_in ,
bool go_secure )
287 static const char * crlf =
"\015\012" ;
288 m_sender->protocolSend(
G::Str::printable(line_in).append(crlf,2U) , go_secure || sendFlush() ) ;
290 m_sender->protocolSecure() ;
293void GSmtp::ServerSend::send(
const std::ostringstream & ss )
295 std::string s = ss.str() ;
297 G_LOG(
"GSmtp::ServerSend: tx>>: \"" << f() <<
"\"" ) ;
298 static const char * crlf =
"\015\012" ;
299 m_sender->protocolSend( s.append(crlf,2U) , sendFlush() ) ;
ServerSend(ServerSender *)
Constructor.
void setSender(ServerSender *)
Sets the sender interface pointer.
An interface used by ServerProtocol to send protocol responses.
static std::string encode(string_view, string_view line_break={})
Encodes the given string, optionally inserting line-breaks to limit the line length.
static bool isPrintableAscii(string_view s) noexcept
Returns true if every character is a 7-bit, non-control character (ie.
static std::string join(string_view sep, const StringArray &strings)
Concatenates an array of strings with separators.
static std::string fromInt(int i)
Converts int 'i' to a string.
static std::string printable(const std::string &in, char escape='\\')
Returns a printable representation of the given input string, using chacter code ranges 0x20 to 0x7e ...
static std::string upper(string_view)
Returns a copy of 's' in which all seven-bit lower-case characters have been replaced by upper-case c...
A zero-copy string field iterator where the field separators are short fixed strings.
A class like c++17's std::string_view.
bool enabled() noexcept
Returns true if pop code is built in.