39void GSmtp::ServerSend::sendChallenge(
const std::string & challenge )
44void GSmtp::ServerSend::sendGreeting(
const std::string & text ,
bool enabled )
47 send(
"220 " + text ) ;
52void GSmtp::ServerSend::sendReadyForTls()
54 send(
"220 ready to start tls" ,
true ) ;
57void GSmtp::ServerSend::sendInvalidArgument()
59 send(
"501 invalid argument" ) ;
62void GSmtp::ServerSend::sendAuthenticationCancelled()
64 send(
"501 authentication cancelled" ) ;
67void GSmtp::ServerSend::sendInsecureAuth(
bool with_starttls_help )
69 if( with_starttls_help )
70 send(
"504 unsupported authentication mechanism: use starttls" ) ;
72 send(
"504 unsupported authentication mechanism" ) ;
75void GSmtp::ServerSend::sendBadMechanism(
const std::string & preferred )
77 if( preferred.empty() )
78 send(
"504 unsupported authentication mechanism" ) ;
80 send(
"432 " +
G::Str::upper(preferred) +
" password transition needed" ) ;
83void GSmtp::ServerSend::sendAuthDone(
bool ok )
86 send(
"235 authentication successful" ) ;
88 send(
"535 authentication failed" ) ;
91void GSmtp::ServerSend::sendBadDataOutOfSequence()
93 send(
"503 invalid data command with binarymime -- use RSET to resynchronise" ) ;
96void GSmtp::ServerSend::sendOutOfSequence()
98 send(
"503 command out of sequence -- use RSET to resynchronise" ) ;
101void GSmtp::ServerSend::sendMissingParameter()
103 send(
"501 parameter required" ) ;
106void GSmtp::ServerSend::sendQuitOk()
111void GSmtp::ServerSend::sendVerified(
const std::string & user )
113 send(
"250 " + user ) ;
116void GSmtp::ServerSend::sendCannotVerify()
118 send(
"252 cannot vrfy" ) ;
121void GSmtp::ServerSend::sendNotVerified(
const std::string & response ,
bool temporary )
123 send( (temporary?
"450":
"550") + std::string(1U,
' ') + response ) ;
126void GSmtp::ServerSend::sendWillAccept(
const std::string & user )
128 send(
"252 cannot verify but will accept: " + user ) ;
131void GSmtp::ServerSend::sendUnrecognised(
const std::string & )
133 send(
"500 command unrecognized" ) ;
136void GSmtp::ServerSend::sendNotImplemented()
138 send(
"502 command not implemented" ) ;
141void GSmtp::ServerSend::sendAuthRequired(
bool with_starttls_help )
143 if( with_starttls_help )
144 send(
"530 authentication required: use starttls" ) ;
146 send(
"530 authentication required" ) ;
149void GSmtp::ServerSend::sendDisabled()
151 send(
"421 service not available" ) ;
154void GSmtp::ServerSend::sendEncryptionRequired(
bool with_starttls_help )
156 if( with_starttls_help )
157 send(
"530 encryption required: use starttls" ) ;
159 send(
"530 encryption required" ) ;
162void GSmtp::ServerSend::sendNoRecipients()
164 send(
"554 no valid recipients" ) ;
167void GSmtp::ServerSend::sendTooBig()
169 send(
"552 message size exceeds fixed maximum message size" ) ;
172void GSmtp::ServerSend::sendDataReply()
174 send(
"354 start mail input -- end with <CRLF>.<CRLF>" ) ;
177void GSmtp::ServerSend::sendRsetReply()
179 send(
"250 state reset" ) ;
182void GSmtp::ServerSend::sendMailReply(
const std::string & from )
184 sendOk(
"sender <" + from +
"> OK" ) ;
187void GSmtp::ServerSend::sendCompletionReply(
bool ok ,
int response_code ,
const std::string & response )
190 sendOk(
"message processed" ) ;
191 else if( response_code >= 400 && response_code < 600 )
192 send(
G::Str::fromInt(response_code).append(1U,
' ').append(response) ) ;
194 send(
"452 " + response ) ;
197void GSmtp::ServerSend::sendFailed()
199 send(
"554 transaction failed" ) ;
202void GSmtp::ServerSend::sendRcptReply(
const std::string & to ,
bool is_local )
205 sendOk( std::string(
"recipient <").append(to).append(is_local?
"> ":
"> ").append(
"OK") ) ;
208void GSmtp::ServerSend::sendBadFrom(
const std::string & response_extra )
210 std::string response =
"553 mailbox name not allowed" ;
211 if( !response_extra.empty() )
213 response.append(
": " ) ;
214 response.append( response_extra ) ;
219void GSmtp::ServerSend::sendBadTo(
const std::string & to ,
const std::string & text ,
bool temporary )
222 std::string(temporary?
"450":
"550") ,
227void GSmtp::ServerSend::sendEhloReply(
const Advertise & advertise )
229 static constexpr std::string_view crlf(
"\015\012" , 2U ) ;
231 std::ostringstream ss ;
234 if( advertise.max_size != 0U )
235 ss <<
"250-SIZE " << advertise.max_size << crlf ;
237 if( !advertise.mechanisms.empty() )
238 ss <<
"250-AUTH " <<
G::Str::join(
" ",advertise.mechanisms) << crlf ;
240 if( advertise.starttls )
241 ss <<
"250-STARTTLS" << crlf ;
244 ss <<
"250-VRFY" << crlf ;
246 if( advertise.chunking )
247 ss <<
"250-CHUNKING" << crlf ;
249 if( advertise.binarymime )
250 ss <<
"250-BINARYMIME" << crlf ;
252 if( advertise.pipelining )
253 ss <<
"250-PIPELINING" << crlf ;
255 if( advertise.smtputf8 )
256 ss <<
"250-SMTPUTF8" << crlf ;
258 ss <<
"250 8BITMIME" ;
263void GSmtp::ServerSend::sendHeloReply()
268void GSmtp::ServerSend::sendOk(
const std::string & text )
270 send( std::string(
"250 ").append(text) ) ;
274void GSmtp::ServerSend::sendOk()
280void GSmtp::ServerSend::send(
const char * line )
282 send( std::string(line) ) ;
285void GSmtp::ServerSend::send( std::string line_in ,
bool go_secure )
288 static const char * crlf =
"\015\012" ;
289 m_sender->protocolSend(
G::Str::printable(line_in).append(crlf,2U) , go_secure || sendFlush() ) ;
291 m_sender->protocolSecure() ;
294void GSmtp::ServerSend::send(
const std::ostringstream & ss )
296 std::string s = ss.str() ;
298 G_LOG(
"GSmtp::ServerSend: tx>>: \"" << f() <<
"\"" ) ;
299 static const char * crlf =
"\015\012" ;
300 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(std::string_view, std::string_view line_break={})
Encodes the given string, optionally inserting line-breaks to limit the line length.
static std::string join(std::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(std::string_view)
Returns a copy of 's' in which all seven-bit lower-case characters have been replaced by upper-case c...
static bool isPrintableAscii(std::string_view s) noexcept
Returns true if every character is between 0x20 and 0x7e inclusive.
A zero-copy string field iterator where the field separators are short fixed strings.
bool enabled() noexcept
Returns true if pop code is built in.