Skip to content

Commit

Permalink
Fix SMTP return status code.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 6, 2023
1 parent bd38360 commit 65bc93e
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 46 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP Mail Client

version=3.1.7
version=3.1.8

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_IMAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 13 additions & 32 deletions src/ESP_Mail_SMTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<char *>(p2 + 1);
memcpy(tmp, &buf[p1], p2);
char *tmp = allocMem<char *>(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<char *>(p2 + 1);
memcpy(tmp, &buf[p1], p2 - p1);
status.text = tmp;
// release memory
freeMem(&tmp);
}
tmp = allocMem<char *>(textLen + 1);
memcpy(tmp, &buf[numLen + 1], textLen);
status.text = tmp;
// release memory
freeMem(&tmp);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/extras/MB_Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/extras/RFC2047.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/extras/RFC2047.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 65bc93e

Please sign in to comment.