From 65bc93e218df69e361c262aea0a1ff9269964f19 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 6 Apr 2023 13:01:00 +0700 Subject: [PATCH] Fix SMTP return status code. --- library.json | 2 +- library.properties | 2 +- src/ESP_Mail_Client.cpp | 2 +- src/ESP_Mail_Client.h | 2 +- src/ESP_Mail_Client_Version.h | 4 ++-- src/ESP_Mail_Const.h | 2 +- src/ESP_Mail_Error.h | 2 +- src/ESP_Mail_FS.h | 2 +- src/ESP_Mail_IMAP.h | 2 +- src/ESP_Mail_Print.h | 2 +- src/ESP_Mail_SMTP.h | 45 ++++++++++------------------------- src/extras/MB_Time.h | 2 +- src/extras/RFC2047.cpp | 2 +- src/extras/RFC2047.h | 2 +- 14 files changed, 27 insertions(+), 46 deletions(-) diff --git a/library.json b/library.json index 13040b17..61082bbc 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ESP Mail Client", - "version": "3.1.7", + "version": "3.1.8", "keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino", "description": "Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino Devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.", "repository": { diff --git a/library.properties b/library.properties index e9e0d1ce..68a1a8ae 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=ESP Mail Client -version=3.1.7 +version=3.1.8 author=Mobizt diff --git a/src/ESP_Mail_Client.cpp b/src/ESP_Mail_Client.cpp index a9a9eed7..9b943f96 100644 --- a/src/ESP_Mail_Client.cpp +++ b/src/ESP_Mail_Client.cpp @@ -2,7 +2,7 @@ #define ESP_MAIL_CLIENT_CPP #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/ESP_Mail_Client.h b/src/ESP_Mail_Client.h index 9f9d0c2e..1e552f64 100644 --- a/src/ESP_Mail_Client.h +++ b/src/ESP_Mail_Client.h @@ -2,7 +2,7 @@ #define ESP_MAIL_CLIENT_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/ESP_Mail_Client_Version.h b/src/ESP_Mail_Client_Version.h index 4f6a1f7c..eb150f46 100644 --- a/src/ESP_Mail_Client_Version.h +++ b/src/ESP_Mail_Client_Version.h @@ -3,8 +3,8 @@ #ifndef ESP_MAIL_VERSION -#define ESP_MAIL_VERSION "3.1.7" -#define ESP_MAIL_VERSION_NUM 30107 +#define ESP_MAIL_VERSION "3.1.8" +#define ESP_MAIL_VERSION_NUM 30108 /* The inconsistent file version checking to prevent mixed versions compilation. */ #define VALID_VERSION_CHECK(ver) (ver == ESP_MAIL_VERSION_NUM) diff --git a/src/ESP_Mail_Const.h b/src/ESP_Mail_Const.h index 19810198..f1741c9e 100644 --- a/src/ESP_Mail_Const.h +++ b/src/ESP_Mail_Const.h @@ -6,7 +6,7 @@ #define ESP_MAIL_CONST_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/ESP_Mail_Error.h b/src/ESP_Mail_Error.h index fc058ff4..18e3ea00 100644 --- a/src/ESP_Mail_Error.h +++ b/src/ESP_Mail_Error.h @@ -7,7 +7,7 @@ #define ESP_MAIL_ERROR_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/ESP_Mail_FS.h b/src/ESP_Mail_FS.h index 1064eda5..bb5d4d49 100644 --- a/src/ESP_Mail_FS.h +++ b/src/ESP_Mail_FS.h @@ -6,7 +6,7 @@ #define ESP_MAIL_CONFIG_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/ESP_Mail_IMAP.h b/src/ESP_Mail_IMAP.h index 56558c02..ff49c182 100644 --- a/src/ESP_Mail_IMAP.h +++ b/src/ESP_Mail_IMAP.h @@ -3,7 +3,7 @@ #define ESP_MAIL_IMAP_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/ESP_Mail_Print.h b/src/ESP_Mail_Print.h index db55bf87..3e4f38b8 100644 --- a/src/ESP_Mail_Print.h +++ b/src/ESP_Mail_Print.h @@ -2,7 +2,7 @@ #define ESP_MAIL_PRINT_H_ #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/ESP_Mail_SMTP.h b/src/ESP_Mail_SMTP.h index 8d10489c..d3b59cf0 100644 --- a/src/ESP_Mail_SMTP.h +++ b/src/ESP_Mail_SMTP.h @@ -3,14 +3,14 @@ #define ESP_MAIL_SMTP_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif /** * Mail Client Arduino Library for Espressif's ESP32 and ESP8266, Raspberry Pi RP2040 Pico, and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module * - * Created April 2, 2023 + * Created April 6, 2023 * * This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers. * @@ -2866,10 +2866,9 @@ bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_comman if (smtp->_smtp_cmd == esp_mail_smtp_command::esp_mail_smtp_cmd_start_tls || status.statusCode == 0) getResponseStatus(response, esp_mail_smtp_status_code_0, 0, status); - ret = statusCode == status.statusCode; smtp->_smtpStatus = status; - if (status.statusCode > 0 && (status.statusCode < 400 || status.statusCode == statusCode)) + if (status.statusCode > 0 && status.statusCode == statusCode) ret = true; if (strlen(response) >= minResLen) @@ -2941,42 +2940,24 @@ bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_comman void ESP_Mail_Client::getResponseStatus(const char *buf, esp_mail_smtp_status_code statusCode, int beginPos, struct esp_mail_smtp_response_status_t &status) { - MB_String s; - char *tmp = nullptr; - int p1 = 0; if (statusCode > esp_mail_smtp_status_code_0) { - s = (int)statusCode; - s += esp_mail_str_2; /* " " */ - p1 = strpos(buf, (const char *)s.c_str(), beginPos); - } - - if (p1 != -1) - { - int ofs = s.length() - 2; - if (ofs < 0) - ofs = 1; - - int p2 = strposP(buf, esp_mail_str_2 /* " " */, p1 + ofs); + int numLen = 3; + int textLen = strlen(buf) - numLen - 1; - if (p2 < 4 && p2 > -1) + if (strlen(buf) > numLen && buf[numLen] == ' ' && textLen > 0) { - tmp = allocMem(p2 + 1); - memcpy(tmp, &buf[p1], p2); + char *tmp = allocMem(numLen + 1); + memcpy(tmp, &buf[0], numLen); status.statusCode = atoi(tmp); // release memory freeMem(&tmp); - p1 = p2 + 1; - p2 = strlen(buf); - if (p2 > p1) - { - tmp = allocMem(p2 + 1); - memcpy(tmp, &buf[p1], p2 - p1); - status.text = tmp; - // release memory - freeMem(&tmp); - } + tmp = allocMem(textLen + 1); + memcpy(tmp, &buf[numLen + 1], textLen); + status.text = tmp; + // release memory + freeMem(&tmp); } } } diff --git a/src/extras/MB_Time.h b/src/extras/MB_Time.h index e268db39..09093a83 100644 --- a/src/extras/MB_Time.h +++ b/src/extras/MB_Time.h @@ -2,7 +2,7 @@ #define MB_Time_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/extras/RFC2047.cpp b/src/extras/RFC2047.cpp index f81f55f3..9c05b6f9 100644 --- a/src/extras/RFC2047.cpp +++ b/src/extras/RFC2047.cpp @@ -2,7 +2,7 @@ #define RFC2047_CPP #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif diff --git a/src/extras/RFC2047.h b/src/extras/RFC2047.h index 6bf4a426..5a549751 100644 --- a/src/extras/RFC2047.h +++ b/src/extras/RFC2047.h @@ -4,7 +4,7 @@ #define RFC2047_H #include "ESP_Mail_Client_Version.h" -#if !VALID_VERSION_CHECK(30107) +#if !VALID_VERSION_CHECK(30108) #error "Mixed versions compilation." #endif