Skip to content

Commit

Permalink
Code optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 16, 2023
1 parent fca41a2 commit 149100d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/ESP_Mail_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,8 +1548,11 @@ String ESP_Mail_Client::errorReason(bool isSMTP, int errorCode, const char *msg)
case SMTP_STATUS_SEND_CUSTOM_COMMAND_FAILED:
ret = esp_mail_error_smtp_str_10; /* "send custom command failed" */
break;
case SMTP_STATUS_XOAUTH2_AUTH_FAILED:
ret = esp_mail_error_smtp_str_11; /* "XOAuth2 authenticate failed" */
break;
case SMTP_STATUS_UNDEFINED:
ret = esp_mail_error_smtp_str_11; /* "undefined error" */
ret = esp_mail_error_smtp_str_12; /* "undefined error" */
break;
#endif

Expand Down Expand Up @@ -1780,7 +1783,7 @@ void ESP_Mail_Client::strReplaceP(MB_String &buf, PGM_P name, PGM_P value)
freeMem(&v);
}

bool ESP_Mail_Client::oauthFailed(char *buf, int bufLen, int &chunkIdx, int ofs)
bool ESP_Mail_Client::isOAuthError(char *buf, int bufLen, int &chunkIdx, int ofs)
{
bool ret = false;
if (chunkIdx == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,8 @@ class ESP_Mail_Client
// PGM string replacement
void strReplaceP(MB_String &buf, PGM_P key, PGM_P value);

// Check for OAUTH log in error response
bool oauthFailed(char *buf, int bufLen, int &chunkIdx, int ofs);
// Check for OAuth log in error response
bool isOAuthError(char *buf, int bufLen, int &chunkIdx, int ofs);

// Get SASL XOAUTH2 string
MB_String getXOAUTH2String(const MB_String &email, const MB_String &accessToken);
Expand Down
3 changes: 2 additions & 1 deletion src/ESP_Mail_Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,8 @@ static const char esp_mail_error_smtp_str_7[] PROGMEM = "sender Email address is
static const char esp_mail_error_smtp_str_8[] PROGMEM = "some of the recipient Email address is not valid";
static const char esp_mail_error_smtp_str_9[] PROGMEM = "set recipient failed";
static const char esp_mail_error_smtp_str_10[] PROGMEM = "send custom command failed";
static const char esp_mail_error_smtp_str_11[] PROGMEM = "undefined error";
static const char esp_mail_error_smtp_str_11[] PROGMEM = "XOAuth2 authenticate failed";
static const char esp_mail_error_smtp_str_12[] PROGMEM = "undefined error";
#endif
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/ESP_Mail_Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#define SMTP_STATUS_NO_VALID_SENDER_EXISTED -112
#define SMTP_STATUS_NO_SUPPORTED_AUTH -113
#define SMTP_STATUS_SEND_CUSTOM_COMMAND_FAILED -114
#define SMTP_STATUS_UNDEFINED -115
#define SMTP_STATUS_XOAUTH2_AUTH_FAILED -115
#define SMTP_STATUS_UNDEFINED -116
#endif

#if defined(ENABLE_IMAP)
Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_IMAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ bool ESP_Mail_Client::readMail(IMAPSession *imap, bool closeSession)
saveHeader(imap, true);
}

// save files list file
// save files list to file
if (imap->_storageReady && imap->_sdFileList.length() > 0)
{
MB_String filepath = cHeader(imap)->message_uid;
Expand Down Expand Up @@ -2919,7 +2919,7 @@ bool ESP_Mail_Client::handleIMAPResponse(IMAPSession *imap, int errCode, bool cl
{
if (imap->_imap_cmd == esp_mail_imap_cmd_sasl_auth_oauth)
{
if (oauthFailed(res.response, res.readLen, res.chunkIdx, 2))
if (isOAuthError(res.response, res.readLen, res.chunkIdx, 2))
res.completedResponse = true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_SMTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -2927,9 +2927,9 @@ bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_comman

if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_auth_xoauth2 && smtp->_smtpStatus.statusCode == esp_mail_smtp_status_code_334)
{
if (oauthFailed(response, readLen, chunkIndex, 4))
if (isOAuthError(response, readLen, chunkIndex, 4))
{
smtp->_smtpStatus.errorCode = -1;
smtp->_smtpStatus.errorCode = SMTP_STATUS_XOAUTH2_AUTH_FAILED;
ret = false;
}
}
Expand Down

0 comments on commit 149100d

Please sign in to comment.