33#include < openssl/x509_vfy.h>
44#include < string>
55#include < utility>
6+ #include " serveroptionsanalyzer.h"
67#include " smtpclienterrors.h"
78#include " socketerrors.h"
89#include " sslerrors.h"
@@ -268,8 +269,20 @@ int SecureSMTPClientBase::getServerSecureIdentification() {
268269 if (tls_command_return_code != EHLO_SUCCESS_CODE) {
269270 return tls_command_return_code;
270271 }
272+ std::string returnedOptions = getLastServerResponse ();
273+ // Check that the last returned option has no hyphen otherwise options are
274+ // still missing from the server.
275+ while (!ServerOptionsAnalyzer::containsAllOptions (returnedOptions)) {
276+ int replyCode = getServerReply ();
277+ if (replyCode == -1 ) {
278+ return SSL_CLIENT_INITSECURECLIENT_TIMEOUT;
279+ } else if (replyCode != EHLO_SUCCESS_CODE) {
280+ return replyCode;
281+ }
282+ returnedOptions += " \n " + std::string (getLastServerResponse ());
283+ }
271284 // Inspect the returned values for authentication options
272- setAuthenticationOptions (SMTPClientBase::extractAuthenticationOptions (getLastServerResponse ()));
285+ setAuthenticationOptions (SMTPClientBase::extractAuthenticationOptions (returnedOptions. c_str ()));
273286 return EHLO_SUCCESS_CODE;
274287}
275288
@@ -283,10 +296,6 @@ int SecureSMTPClientBase::sendCommand(const char *pCommand, int pErrorCode) {
283296}
284297
285298int SecureSMTPClientBase::sendCommandWithFeedback (const char *pCommand, int pErrorCode, int pTimeoutCode) {
286- unsigned int waitTime {0 };
287- int bytes_received {0 };
288- char outbuf[SERVERRESPONSE_BUFFER_LENGTH];
289-
290299 // Check if we are in the TLS mode of before it
291300 if (mBIO == nullptr ) {
292301 return sendRawCommand (pCommand, pErrorCode, pTimeoutCode);
@@ -297,8 +306,21 @@ int SecureSMTPClientBase::sendCommandWithFeedback(const char *pCommand, int pErr
297306 return pErrorCode;
298307 }
299308
309+ int serverReplyCode = getServerReply ();
310+ if (serverReplyCode != -1 ) {
311+ return serverReplyCode;
312+ }
313+
314+ cleanup ();
315+ return pTimeoutCode;
316+ }
317+
318+ int SecureSMTPClientBase::getServerReply () {
319+ unsigned int waitTime {0 };
320+ int bytes_received {0 };
321+ char outbuf[SERVERRESPONSE_BUFFER_LENGTH];
300322 while ((bytes_received = BIO_read (mBIO , outbuf, SERVERRESPONSE_BUFFER_LENGTH)) <= 0 && waitTime < getCommandTimeout ()) {
301- sleep (1 );
323+ crossPlatformSleep (1 );
302324 waitTime += 1 ;
303325 }
304326 if (waitTime < getCommandTimeout ()) {
@@ -307,7 +329,5 @@ int SecureSMTPClientBase::sendCommandWithFeedback(const char *pCommand, int pErr
307329 addCommunicationLogItem (outbuf, " s" );
308330 return extractReturnCode (outbuf);
309331 }
310-
311- cleanup ();
312- return pTimeoutCode;
332+ return -1 ;
313333}
0 commit comments