Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Fix the trucated HTML message body bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 10, 2020
1 parent 973d69a commit 488bd8a
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mail Client Arduino Library for ESP32 v 2.1.1
# Mail Client Arduino Library for ESP32 v 2.1.2

This library allows ESP32 to send Email with/without attachment and receive Email with/without attachment download via SMTP and IMAP servers.

Expand Down
4 changes: 0 additions & 4 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,5 @@ info KEYWORD2
success KEYWORD2
ReadStatus KEYWORD2
status KEYWORD2
startAt KEYWORD2
endAt KEYWORD2
equalTo KEYWORD2
equalTo KEYWORD2

clockReady KEYWORD3
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP32 Mail Client

version=2.1.1
version=2.1.2

author=Mobizt

Expand Down
6 changes: 6 additions & 0 deletions src/ESP32MailHTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
*
*/

#ifndef ESP32MailHTTPClient_CPP
#define ESP32MailHTTPClient_CPP

#ifdef ESP32

#include "ESP32MailHTTPClient.h"

Expand Down Expand Up @@ -192,3 +195,6 @@ void ESP32MailHTTPClient::setDebugCallback(DebugMsgCallback cb)
_debugCallback = std::move(cb);
}

#endif //ESP32

#endif //ESP32MailHTTPClient_CPP
12 changes: 6 additions & 6 deletions src/ESP32MailHTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
*
*/

#ifndef HTTP_CLIENT_ESP32EX_H_
#define HTTP_CLIENT_ESP32EX_H_
#ifndef ESP32MailHTTPClient_H
#define ESP32MailHTTPClient_H

#ifdef ESP32

#include <Arduino.h>
#include <HTTPClient.h>
Expand Down Expand Up @@ -100,8 +102,6 @@ class ESP32MailHTTPClient : public HTTPClient
uint16_t _port = 0;
};

#endif //ESP32


#endif /* ESP32MailHTTPClient_H_ */


#endif //ESP32MailHTTPClient_H
9 changes: 9 additions & 0 deletions src/ESP32TimeHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef ESP32TimeHelper_CPP
#define ESP32TimeHelper_CPP

#ifdef ESP32

#include "ESP32TimeHelper.h"

ESP32TimeHelper::ESP32TimeHelper()
Expand Down Expand Up @@ -180,3 +185,7 @@ void ESP32TimeHelper::getTimeFromSec(int secCount, int &yrs, int &months, int &d
min = _min;
sec = secCount;
}

#endif //ESP32

#endif //ESP32TimeHelper_CPP
12 changes: 9 additions & 3 deletions src/ESP32TimeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef ESP_TIME_HELPER_h
#define ESP_TIME_HELPER_h
#ifndef ESP32TimeHelper_H
#define ESP32TimeHelper_H

#ifdef ESP32


#include <time.h>
#include <Arduino.h>
#include <WiFi.h>
Expand Down Expand Up @@ -64,4 +68,6 @@ class ESP32TimeHelper
const char *dow[20] = {"sunday", "monday", "tuesday", "wednesday", "thurseday", "friday", "saturday"};
};

#endif
#endif //ESP32

#endif //ESP32TimeHelper_H
21 changes: 13 additions & 8 deletions src/ESP32_MailClient.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
*Mail Client Arduino Library for ESP32, version 2.1.1
*Mail Client Arduino Library for ESP32, version 2.1.2
*
* December 13, 2019
* April 10, 2020
*
* This library allows ESP32 to send Email with/without attachment and receive Email with/without attachment download through SMTP and IMAP servers.
*
Expand Down Expand Up @@ -29,6 +29,11 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef ESP32_MailClient_CPP
#define ESP32_MailClient_CPP

#ifdef ESP32

#include "ESP32_MailClient.h"

struct ESP32_MailClient::IMAP_COMMAND_TYPE
Expand Down Expand Up @@ -2343,7 +2348,6 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT
size_t payloadLength = 0;
size_t outputLength;

bool payloadBegin = false;
bool completeResp = false;
bool validResponse = false;
bool downloadReq = false;
Expand Down Expand Up @@ -2417,7 +2421,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT
if (validResponse && imapCommandType == IMAP_COMMAND_TYPE::FETCH_BODY_TEXT && lfCount > 0)
{

if (payloadLength > 0 && charCount < payloadLength - 1 && payloadBegin)
if (payloadLength > 0 && charCount < payloadLength - 1)
{

if (imapData._messageDataInfo[mailIndex][messageDataIndex]._transfer_encoding != ESP32_MAIL_STR_160)
Expand Down Expand Up @@ -2578,7 +2582,7 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT
tmp = lineBuf;
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);

if (imapCommandType == IMAP_COMMAND_TYPE::FETCH_BODY_MIME && lfCount > 0 && !payloadBegin)
if (imapCommandType == IMAP_COMMAND_TYPE::FETCH_BODY_MIME && lfCount > 0)
{

if (payloadLength > 0 && validResponse)
Expand Down Expand Up @@ -3229,9 +3233,6 @@ bool ESP32_MailClient::waitIMAPResponse(IMAPData &imapData, uint8_t imapCommandT
}
}

if (payloadLength > 0 && lfCount > 0 && tmp.length() == 0)
payloadBegin = true;

lineBuf.clear();
lfCount++;
std::string().swap(tmp);
Expand Down Expand Up @@ -4983,3 +4984,7 @@ void SendStatus::empty()
}

ESP32_MailClient MailClient = ESP32_MailClient();

#endif //ESP32

#endif //ESP32_MailClient_CPP
12 changes: 9 additions & 3 deletions src/ESP32_MailClient.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
*Mail Client Arduino Library for ESP32, version 2.1.1
*Mail Client Arduino Library for ESP32, version 2.1.2
*
* December 13, 2019
* April 10, 2020
*
* This library allows ESP32 to send Email with/without attachment and receive Email with/without attachment download through SMTP and IMAP servers.
*
Expand Down Expand Up @@ -29,9 +29,13 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/



#ifndef ESP32_MailClient_H
#define ESP32_MailClient_H

#ifdef ESP32

#include <Arduino.h>
#include "WiFiClientSecureESP32.h"
#include "ETH.h"
Expand Down Expand Up @@ -1895,4 +1899,6 @@ static void __attribute__((used)) ESP32MailDebugLine(const char *msg, bool newli

extern ESP32_MailClient MailClient;

#endif
#endif //ESP32

#endif //ESP32_MailClient_H
7 changes: 7 additions & 0 deletions src/RFC2047.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#ifndef RFC2047_CPP
#define RFC2047_CPP

#ifdef ESP32

#include "RFC2047.h"

RFC2047::RFC2047(){}
Expand Down Expand Up @@ -230,4 +235,6 @@ char *RFC2047::safe_strdup (const char *s)
return (p);
}

#endif //ESP32

#endif //RFC2047_CPP
6 changes: 5 additions & 1 deletion src/RFC2047.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef RFC2047_H
#define RFC2047_H

#ifdef ESP32

#include <Arduino.h>


Expand Down Expand Up @@ -63,4 +65,6 @@ class RFC2047{

};

#endif
#endif //ESP32

#endif //RFC2047_H
11 changes: 10 additions & 1 deletion src/WiFiClientSecureESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef WiFiClientSecureESP32_CPP
#define WiFiClientSecureESP32_CPP

#ifdef ESP32

#include "WiFiClientSecureESP32.h"
#include <lwip/sockets.h>
#include <lwip/netdb.h>
Expand Down Expand Up @@ -385,4 +390,8 @@ void WiFiClientSecureESP32::setSTARTTLS(bool starttls)
void WiFiClientSecureESP32::setDebugCB(DebugMsgCallback cb)
{
sslclient->_debugCallback = std::move(cb);
}
}

#endif //ESP32

#endif //WiFiClientSecureESP32_CPP
13 changes: 10 additions & 3 deletions src/WiFiClientSecureESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef WiFiClientSecureESP32_h
#define WiFiClientSecureESP32_h
#ifndef WiFiClientSecureESP32_H
#define WiFiClientSecureESP32_H

#ifdef ESP32

#include "Arduino.h"
#include "IPAddress.h"
#include <WiFi.h>
Expand Down Expand Up @@ -135,4 +138,8 @@ class WiFiClientSecureESP32 : public WiFiClient
using Print::write;
};

#endif /* _WIFICLIENT_H_ */
#endif //ESP32

#endif //WiFiClientSecureESP32_H


9 changes: 9 additions & 0 deletions src/ssl_client32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
* Additions Copyright (C) 2017 Evandro Luis Copercini, Apache 2.0 License.
*/

#ifndef SSL_CLIENT32_CPP
#define SSL_CLIENT32_CPP

#ifdef ESP32

#include "Arduino.h"
#include <esp32-hal-log.h>
#include <lwip/err.h>
Expand Down Expand Up @@ -842,3 +847,7 @@ void ESP32SSLClientDebugInfo(PGM_P info, sslclient_context32 *ssl_client)
ssl_client->_debugCallback(dbgInfo);
delete[] dbgInfo;
}

#endif //ESP32

#endif //SSL_CLIENT32_CPP
8 changes: 7 additions & 1 deletion src/ssl_client32.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#ifndef SSL_CLIENT32_H
#define SSL_CLIENT32_H

#ifdef ESP32

#include "mbedtls/platform.h"
#include "mbedtls/net.h"
#include "mbedtls/debug.h"
Expand Down Expand Up @@ -107,4 +110,7 @@ bool verify_ssl_fingerprint(sslclient_context32 *ssl_client, const char* fp, con
bool verify_ssl_dn(sslclient_context32 *ssl_client, const char* domain_name);
int starttlsHandshake(sslclient_context32 *ssl_client, int port);
void ESP32SSLClientDebugInfo(PGM_P info, sslclient_context32 *ssl_client);
#endif

#endif //ESP32

#endif //SSL_CLIENT32_H

0 comments on commit 488bd8a

Please sign in to comment.