mirror of https://github.com/arendst/Tasmota.git
Merge pull request #11025 from gemu2015/sendmail
remove spiffs from sendmail lib
This commit is contained in:
commit
49d9cf3ce5
|
@ -405,12 +405,13 @@ bool ESP_Mail_Client::readMail(IMAPSession *imap, bool closeSession)
|
||||||
if (!SD.exists(imap->_config->storage.saved_path))
|
if (!SD.exists(imap->_config->storage.saved_path))
|
||||||
createDirs(imap->_config->storage.saved_path);
|
createDirs(imap->_config->storage.saved_path);
|
||||||
}
|
}
|
||||||
else if (!_flashOk && imap->_storageType == esp_mail_file_storage_type_flash)
|
else if (!_flashOk && imap->_storageType == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
_flashOk = FLASH_FS.begin();
|
// _flashOk = FLASH_FS.begin();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cHeader(imap)->part_headers.size() > 0)
|
if (cHeader(imap)->part_headers.size() > 0)
|
||||||
|
@ -602,13 +603,13 @@ bool ESP_Mail_Client::readMail(IMAPSession *imap, bool closeSession)
|
||||||
}
|
}
|
||||||
else if (imap->_storageType == esp_mail_file_storage_type_flash)
|
else if (imap->_storageType == esp_mail_file_storage_type_flash)
|
||||||
{
|
{
|
||||||
if (_flashOk)
|
if (_flashOk) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
SPIFFS.end();
|
// SPIFFS.end();
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
FLASH_FS.end();
|
// FLASH_FS.end();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
_flashOk = false;
|
_flashOk = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2752,13 +2753,13 @@ bool ESP_Mail_Client::sendAttachments(SMTPSession *smtp, SMTP_Message *msg, cons
|
||||||
if (!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd)
|
if (!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd)
|
||||||
_sdOk = sdTest();
|
_sdOk = sdTest();
|
||||||
|
|
||||||
if (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash)
|
if (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
_flashOk = FLASH_FS.begin();
|
// _flashOk = FLASH_FS.begin();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
if ((!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) || (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash))
|
if ((!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) || (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -2815,9 +2816,9 @@ bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_At
|
||||||
}
|
}
|
||||||
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
|
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
file_existed = SPIFFS.exists(filepath.c_str());
|
//file_existed = SPIFFS.exists(filepath.c_str());
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
file_existed = FLASH_FS.exists(filepath.c_str());
|
//file_existed = FLASH_FS.exists(filepath.c_str());
|
||||||
#endif
|
#endif
|
||||||
} else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
|
} else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
|
||||||
file_existed = ufsp->exists(filepath.c_str());
|
file_existed = ufsp->exists(filepath.c_str());
|
||||||
|
@ -2838,9 +2839,9 @@ bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_At
|
||||||
}
|
}
|
||||||
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
|
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
file_existed = SPIFFS.exists(filepath.c_str());
|
//file_existed = SPIFFS.exists(filepath.c_str());
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
file_existed = FLASH_FS.exists(filepath.c_str());
|
//file_existed = FLASH_FS.exists(filepath.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
|
else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
|
||||||
|
@ -2882,9 +2883,9 @@ bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_At
|
||||||
}
|
}
|
||||||
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
|
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
file = SPIFFS.open(filepath.c_str(), FILE_READ);
|
//file = SPIFFS.open(filepath.c_str(), FILE_READ);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
file = FLASH_FS.open(filepath.c_str(), "r");
|
//file = FLASH_FS.open(filepath.c_str(), "r");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
|
else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
|
||||||
|
@ -2997,13 +2998,13 @@ bool ESP_Mail_Client::sendInline(SMTPSession *smtp, SMTP_Message *msg, const std
|
||||||
if (!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd)
|
if (!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd)
|
||||||
_sdOk = sdTest();
|
_sdOk = sdTest();
|
||||||
|
|
||||||
if (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash)
|
if (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
_flashOk = FLASH_FS.begin();
|
// _flashOk = FLASH_FS.begin();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
if ((!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) || (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash))
|
if ((!_sdOk && att->file.storage_type == esp_mail_file_storage_type_sd) || (!_flashOk && att->file.storage_type == esp_mail_file_storage_type_flash))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -5694,13 +5695,13 @@ void ESP_Mail_Client::saveHeader(IMAPSession *imap)
|
||||||
prepareFilePath(imap, headerFilePath, true);
|
prepareFilePath(imap, headerFilePath, true);
|
||||||
if (imap->_storageType == esp_mail_file_storage_type_sd && !_sdOk)
|
if (imap->_storageType == esp_mail_file_storage_type_sd && !_sdOk)
|
||||||
_sdOk = sdTest();
|
_sdOk = sdTest();
|
||||||
else if (imap->_storageType == esp_mail_file_storage_type_flash && !_flashOk)
|
else if (imap->_storageType == esp_mail_file_storage_type_flash && !_flashOk) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
_flashOk = FLASH_FS.begin();
|
// _flashOk = FLASH_FS.begin();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
if (_sdOk || _flashOk)
|
if (_sdOk || _flashOk)
|
||||||
{
|
{
|
||||||
if (file)
|
if (file)
|
||||||
|
@ -5708,13 +5709,13 @@ void ESP_Mail_Client::saveHeader(IMAPSession *imap)
|
||||||
|
|
||||||
if (imap->_storageType == esp_mail_file_storage_type_sd)
|
if (imap->_storageType == esp_mail_file_storage_type_sd)
|
||||||
file = SD.open(headerFilePath.c_str(), FILE_WRITE);
|
file = SD.open(headerFilePath.c_str(), FILE_WRITE);
|
||||||
else if (imap->_storageType == esp_mail_file_storage_type_flash)
|
else if (imap->_storageType == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
file = SPIFFS.open(headerFilePath.c_str(), FILE_WRITE);
|
// file = SPIFFS.open(headerFilePath.c_str(), FILE_WRITE);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
file = FLASH_FS.open(headerFilePath.c_str(), "w");
|
// file = FLASH_FS.open(headerFilePath.c_str(), "w");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
|
@ -5932,13 +5933,13 @@ bool ESP_Mail_Client::handleAttachment(IMAPSession *imap, char *buf, int bufLen,
|
||||||
|
|
||||||
if (imap->_storageType == esp_mail_file_storage_type_sd && !_sdOk)
|
if (imap->_storageType == esp_mail_file_storage_type_sd && !_sdOk)
|
||||||
_sdOk = sdTest();
|
_sdOk = sdTest();
|
||||||
else if (imap->_storageType == esp_mail_file_storage_type_flash && !_flashOk)
|
else if (imap->_storageType == esp_mail_file_storage_type_flash && !_flashOk) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
_flashOk = FLASH_FS.begin();
|
// _flashOk = FLASH_FS.begin();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
if (_sdOk || _flashOk)
|
if (_sdOk || _flashOk)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -5962,12 +5963,13 @@ bool ESP_Mail_Client::handleAttachment(IMAPSession *imap, char *buf, int bufLen,
|
||||||
|
|
||||||
if (imap->_storageType == esp_mail_file_storage_type_sd)
|
if (imap->_storageType == esp_mail_file_storage_type_sd)
|
||||||
file = SD.open(filePath.c_str(), FILE_WRITE);
|
file = SD.open(filePath.c_str(), FILE_WRITE);
|
||||||
else if (imap->_storageType == esp_mail_file_storage_type_flash)
|
else if (imap->_storageType == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
|
// file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
file = FLASH_FS.open(filePath.c_str(), "w");
|
// file = FLASH_FS.open(filePath.c_str(), "w");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6362,12 +6364,13 @@ void ESP_Mail_Client::decodeText(IMAPSession *imap, char *buf, int bufLen, int &
|
||||||
|
|
||||||
if (imap->_storageType == esp_mail_file_storage_type_sd)
|
if (imap->_storageType == esp_mail_file_storage_type_sd)
|
||||||
file = SD.open(filePath.c_str(), FILE_WRITE);
|
file = SD.open(filePath.c_str(), FILE_WRITE);
|
||||||
else if (imap->_storageType == esp_mail_file_storage_type_flash)
|
else if (imap->_storageType == esp_mail_file_storage_type_flash) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
|
// file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
file = FLASH_FS.open(filePath.c_str(), "w");
|
// file = FLASH_FS.open(filePath.c_str(), "w");
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7294,12 +7297,13 @@ bool IMAPSession::connect(ESP_Mail_Session *sesssion, IMAP_Config *config)
|
||||||
{
|
{
|
||||||
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_sd && !MailClient._sdOk)
|
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_sd && !MailClient._sdOk)
|
||||||
MailClient._sdOk = MailClient.sdTest();
|
MailClient._sdOk = MailClient.sdTest();
|
||||||
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_flash && !MailClient._flashOk)
|
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_flash && !MailClient._flashOk) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
// MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
MailClient._flashOk = FLASH_FS.begin();
|
// MailClient._flashOk = FLASH_FS.begin();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MailClient.imapAuth(this);
|
return MailClient.imapAuth(this);
|
||||||
|
@ -7978,12 +7982,14 @@ bool SMTPSession::connect(ESP_Mail_Session *config)
|
||||||
{
|
{
|
||||||
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_sd && !MailClient._sdOk)
|
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_sd && !MailClient._sdOk)
|
||||||
MailClient._sdOk = MailClient.sdTest();
|
MailClient._sdOk = MailClient.sdTest();
|
||||||
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_flash && !MailClient._flashOk)
|
if (_sesson_cfg->certificate.cert_file_storage_type == esp_mail_file_storage_type::esp_mail_file_storage_type_flash && !MailClient._flashOk) {
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
// MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
MailClient._flashOk = FLASH_FS.begin();
|
// MailClient._flashOk = FLASH_FS.begin();
|
||||||
#endif
|
#endif
|
||||||
|
MailClient._flashOk = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return MailClient.smtpAuth(this);
|
return MailClient.smtpAuth(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <WiFiClientSecure.h>
|
#include <WiFiClientSecure.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <SPIFFS.h>
|
//#include <SPIFFS.h>
|
||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
#include "wcs/esp32/ESP_Mail_HTTPClient32.h"
|
#include "wcs/esp32/ESP_Mail_HTTPClient32.h"
|
||||||
#include "extras/ESPTimeHelper.h"
|
#include "extras/ESPTimeHelper.h"
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
/*
|
/*
|
||||||
* Customized version of ESP32 HTTPClient Library.
|
* Customized version of ESP32 HTTPClient Library.
|
||||||
*
|
*
|
||||||
* v 1.1.1
|
* v 1.1.1
|
||||||
*
|
*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
* Copyright (c) 2021 K. Suwatchai (Mobizt)
|
* Copyright (c) 2021 K. Suwatchai (Mobizt)
|
||||||
*
|
*
|
||||||
* HTTPClient Arduino library for ESP32
|
* HTTPClient Arduino library for ESP32
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||||
* This file is part of the HTTPClient for Arduino.
|
* This file is part of the HTTPClient for Arduino.
|
||||||
* Port to ESP32 by Evandro Luis Copercini (2017),
|
* Port to ESP32 by Evandro Luis Copercini (2017),
|
||||||
* changed fingerprints to CA verification.
|
* changed fingerprints to CA verification.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -205,8 +205,9 @@ void ESP_Mail_HTTPClient32::setCertFile(const char *caCertFile, esp_mail_file_st
|
||||||
bool t = false;
|
bool t = false;
|
||||||
_certType = 2;
|
_certType = 2;
|
||||||
|
|
||||||
if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_flash)
|
if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_flash) {
|
||||||
t = SPIFFS.begin(true);
|
// t = SPIFFS.begin(true);
|
||||||
|
}
|
||||||
else if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_sd)
|
else if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_sd)
|
||||||
t = SD.begin();
|
t = SD.begin();
|
||||||
if (!t)
|
if (!t)
|
||||||
|
@ -215,8 +216,8 @@ void ESP_Mail_HTTPClient32::setCertFile(const char *caCertFile, esp_mail_file_st
|
||||||
File f;
|
File f;
|
||||||
if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_flash)
|
if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_flash)
|
||||||
{
|
{
|
||||||
if (SPIFFS.exists(caCertFile))
|
//if (SPIFFS.exists(caCertFile))
|
||||||
f = SPIFFS.open(caCertFile, FILE_READ);
|
// f = SPIFFS.open(caCertFile, FILE_READ);
|
||||||
}
|
}
|
||||||
else if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_sd)
|
else if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_sd)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
/*
|
/*
|
||||||
* Customized version of ESP32 HTTPClient Library.
|
* Customized version of ESP32 HTTPClient Library.
|
||||||
*
|
*
|
||||||
* v 1.1.1
|
* v 1.1.1
|
||||||
*
|
*
|
||||||
* The MIT License (MIT)
|
* The MIT License (MIT)
|
||||||
* Copyright (c) 2021 K. Suwatchai (Mobizt)
|
* Copyright (c) 2021 K. Suwatchai (Mobizt)
|
||||||
*
|
*
|
||||||
* HTTPClient Arduino library for ESP32
|
* HTTPClient Arduino library for ESP32
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||||
* This file is part of the HTTPClient for Arduino.
|
* This file is part of the HTTPClient for Arduino.
|
||||||
* Port to ESP32 by Evandro Luis Copercini (2017),
|
* Port to ESP32 by Evandro Luis Copercini (2017),
|
||||||
* changed fingerprints to CA verification.
|
* changed fingerprints to CA verification.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <SPIFFS.h>
|
//#include <SPIFFS.h>
|
||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#include "ESP_Mail_WCS32.h"
|
#include "ESP_Mail_WCS32.h"
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ public:
|
||||||
* \param host - Host name without protocols.
|
* \param host - Host name without protocols.
|
||||||
* \param port - Server's port.
|
* \param port - Server's port.
|
||||||
* \return True as default.
|
* \return True as default.
|
||||||
* If no certificate string provided, use (const char*)NULL to CAcert param
|
* If no certificate string provided, use (const char*)NULL to CAcert param
|
||||||
*/
|
*/
|
||||||
bool begin(const char *host, uint16_t port);
|
bool begin(const char *host, uint16_t port);
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ public:
|
||||||
* Establish http connection if header provided and send it, send payload if provided.
|
* Establish http connection if header provided and send it, send payload if provided.
|
||||||
* \param header - The header string (constant chars array).
|
* \param header - The header string (constant chars array).
|
||||||
* \param payload - The payload string (constant chars array), optional.
|
* \param payload - The payload string (constant chars array), optional.
|
||||||
* \return http status code, Return zero if new http connection and header and/or payload sent
|
* \return http status code, Return zero if new http connection and header and/or payload sent
|
||||||
* with no error or no header and payload provided. If obly payload provided, no new http connection was established.
|
* with no error or no header and payload provided. If obly payload provided, no new http connection was established.
|
||||||
*/
|
*/
|
||||||
int send(const char *header, const char *payload);
|
int send(const char *header, const char *payload);
|
||||||
|
@ -138,7 +138,7 @@ public:
|
||||||
* Send extra header without making new http connection (if send has been called)
|
* Send extra header without making new http connection (if send has been called)
|
||||||
* \param header - The header string (constant chars array).
|
* \param header - The header string (constant chars array).
|
||||||
* \return True if header sending success.
|
* \return True if header sending success.
|
||||||
* Need to call send with header first.
|
* Need to call send with header first.
|
||||||
*/
|
*/
|
||||||
bool send(const char *header);
|
bool send(const char *header);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Customized version of WiFiClientSecure.cpp
|
Customized version of WiFiClientSecure.cpp
|
||||||
|
|
||||||
WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries
|
WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries
|
||||||
- Mostly compatible with Arduino WiFi shield library and standard
|
- Mostly compatible with Arduino WiFi shield library and standard
|
||||||
WiFiClient/ServerSecure (except for certificate handling).
|
WiFiClient/ServerSecure (except for certificate handling).
|
||||||
|
@ -53,6 +53,9 @@ extern "C"
|
||||||
#include <c_types.h>
|
#include <c_types.h>
|
||||||
#include <coredecls.h>
|
#include <coredecls.h>
|
||||||
|
|
||||||
|
//#define Optimistic_yield(A) optimistic_yield(A);ESP.wdtFeed();
|
||||||
|
#define Optimistic_yield(A) optimistic_yield(A)
|
||||||
|
|
||||||
#if !CORE_MOCK
|
#if !CORE_MOCK
|
||||||
|
|
||||||
// The BearSSL thunks in use for now
|
// The BearSSL thunks in use for now
|
||||||
|
@ -315,7 +318,7 @@ namespace ESP_Mail
|
||||||
// Ensure we yield if we need multiple fragments to avoid WDT
|
// Ensure we yield if we need multiple fragments to avoid WDT
|
||||||
if (sent_bytes)
|
if (sent_bytes)
|
||||||
{
|
{
|
||||||
optimistic_yield(1000);
|
Optimistic_yield(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get BearSSL to a state where we can send
|
// Get BearSSL to a state where we can send
|
||||||
|
@ -519,7 +522,7 @@ namespace ESP_Mail
|
||||||
|
|
||||||
for (int no_work = 0; blocking || no_work < 2;)
|
for (int no_work = 0; blocking || no_work < 2;)
|
||||||
{
|
{
|
||||||
optimistic_yield(100);
|
Optimistic_yield(100);
|
||||||
|
|
||||||
if (loopTimeout)
|
if (loopTimeout)
|
||||||
{
|
{
|
||||||
|
@ -555,10 +558,10 @@ namespace ESP_Mail
|
||||||
|
|
||||||
if (!blocking && len > availForWrite)
|
if (!blocking && len > availForWrite)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
writes on WiFiClient will block if len > availableForWrite()
|
writes on WiFiClient will block if len > availableForWrite()
|
||||||
this is needed to prevent available() calls from blocking
|
this is needed to prevent available() calls from blocking
|
||||||
on dropped connections
|
on dropped connections
|
||||||
*/
|
*/
|
||||||
len = availForWrite;
|
len = availForWrite;
|
||||||
}
|
}
|
||||||
|
@ -662,7 +665,7 @@ namespace ESP_Mail
|
||||||
{
|
{
|
||||||
_handshake_done = true;
|
_handshake_done = true;
|
||||||
}
|
}
|
||||||
optimistic_yield(1000);
|
Optimistic_yield(1000);
|
||||||
}
|
}
|
||||||
return _handshake_done;
|
return _handshake_done;
|
||||||
}
|
}
|
||||||
|
@ -885,7 +888,7 @@ namespace ESP_Mail
|
||||||
ctx->match_fingerprint = _use_fingerprint ? _fingerprint : nullptr;
|
ctx->match_fingerprint = _use_fingerprint ? _fingerprint : nullptr;
|
||||||
ctx->allow_self_signed = _allow_self_signed ? 1 : 0;
|
ctx->allow_self_signed = _allow_self_signed ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Some constants uses to init the server/client contexts
|
// Some constants uses to init the server/client contexts
|
||||||
// Note that suites_P needs to be copied to RAM before use w/BearSSL!
|
// Note that suites_P needs to be copied to RAM before use w/BearSSL!
|
||||||
|
@ -2047,7 +2050,7 @@ namespace ESP_Mail
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
optimistic_yield(100);
|
Optimistic_yield(100);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2116,4 +2119,4 @@ namespace ESP_Mail
|
||||||
|
|
||||||
#endif /* ESP8266 */
|
#endif /* ESP8266 */
|
||||||
|
|
||||||
#endif /* ESP_Mail_WCS_CPP */
|
#endif /* ESP_Mail_WCS_CPP */
|
||||||
|
|
|
@ -1,11 +1,22 @@
|
||||||
#ifdef USE_ESP32MAIL
|
#ifdef USE_ESP32MAIL
|
||||||
|
|
||||||
|
|
||||||
#include <ESP_Mail_Client.h>
|
#include <ESP_Mail_Client.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ESP8266
|
||||||
#ifndef SEND_MAIL32_MINRAM
|
#ifndef SEND_MAIL32_MINRAM
|
||||||
|
#undef SEND_MAIL32_MINRAM
|
||||||
|
#define SEND_MAIL32_MINRAM 13*1024
|
||||||
|
#endif
|
||||||
|
#endif // ESP8266
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
#ifndef SEND_MAIL32_MINRAM
|
||||||
|
#undef SEND_MAIL32_MINRAM
|
||||||
#define SEND_MAIL32_MINRAM 30*1024
|
#define SEND_MAIL32_MINRAM 30*1024
|
||||||
#endif
|
#endif
|
||||||
|
#endif // ESP32
|
||||||
|
|
||||||
#define xPSTR(a) a
|
#define xPSTR(a) a
|
||||||
#define MAX_ATTCHMENTS 8
|
#define MAX_ATTCHMENTS 8
|
||||||
char *attachments[MAX_ATTCHMENTS];
|
char *attachments[MAX_ATTCHMENTS];
|
||||||
|
@ -13,6 +24,9 @@ uint8_t num_attachments;
|
||||||
void script_send_email_body(void(*func)(char *));
|
void script_send_email_body(void(*func)(char *));
|
||||||
String html_content = "";
|
String html_content = "";
|
||||||
SMTP_Message *email_mptr;
|
SMTP_Message *email_mptr;
|
||||||
|
SMTPSession *smtp;
|
||||||
|
//SMTPSession smtp;
|
||||||
|
void smtpCallback(SMTP_Status status);
|
||||||
|
|
||||||
//#define DEBUG_EMAIL_PORT
|
//#define DEBUG_EMAIL_PORT
|
||||||
|
|
||||||
|
@ -30,17 +44,22 @@ uint16_t SendMail(char *buffer) {
|
||||||
uint16_t status = 0;
|
uint16_t status = 0;
|
||||||
uint16_t blen;
|
uint16_t blen;
|
||||||
char *endcmd;
|
char *endcmd;
|
||||||
SMTPSession smtp;
|
|
||||||
ESP_Mail_Session session;
|
ESP_Mail_Session session;
|
||||||
SMTP_Message message;
|
SMTP_Message message;
|
||||||
email_mptr = &message;
|
email_mptr = &message;
|
||||||
|
smtp = new SMTPSession();
|
||||||
|
if (!smtp) {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
// return if not enough memory
|
// return if not enough memory
|
||||||
uint32_t mem = ESP.getFreeHeap();
|
uint32_t mem = ESP.getFreeHeap();
|
||||||
//AddLog(LOG_LEVEL_INFO, PSTR("heap: %d"),mem);
|
//AddLog(LOG_LEVEL_INFO, PSTR("heap: %d"),mem);
|
||||||
if (mem < SEND_MAIL32_MINRAM) {
|
if (mem < SEND_MAIL32_MINRAM) {
|
||||||
// return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG_EMAIL_PORT
|
||||||
|
AddLog(LOG_LEVEL_INFO, PSTR("heap: %d"),mem);
|
||||||
|
#endif
|
||||||
|
|
||||||
while (*buffer==' ') buffer++;
|
while (*buffer==' ') buffer++;
|
||||||
|
|
||||||
|
@ -154,15 +173,14 @@ uint16_t SendMail(char *buffer) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//smtp.debug(true);
|
//smtp->debug(true);
|
||||||
smtp.debug(false);
|
smtp->debug(false);
|
||||||
|
// smtp->callback(smtpCallback);
|
||||||
|
|
||||||
message.clearRecipients();
|
message.clearRecipients();
|
||||||
message.clearCc();
|
message.clearCc();
|
||||||
message.clearBcc();
|
message.clearBcc();
|
||||||
|
|
||||||
//smtp.callback(smtpCallback);
|
|
||||||
|
|
||||||
session.server.host_name = mserv;
|
session.server.host_name = mserv;
|
||||||
session.server.port = port;
|
session.server.port = port;
|
||||||
session.login.email = user;
|
session.login.email = user;
|
||||||
|
@ -201,17 +219,18 @@ uint16_t SendMail(char *buffer) {
|
||||||
|
|
||||||
/* Connect to server with the session config */
|
/* Connect to server with the session config */
|
||||||
delay(0);
|
delay(0);
|
||||||
if (!smtp.connect(&session))
|
if (!smtp->connect(&session))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
/* Start sending the Email and close the session */
|
/* Start sending the Email and close the session */
|
||||||
delay(0);
|
delay(0);
|
||||||
|
|
||||||
if (!MailClient.sendMail(&smtp, &message, true)) {
|
if (!MailClient.sendMail(smtp, &message, true)) {
|
||||||
Serial.println("Error sending Email, " + smtp.errorReason());
|
Serial.println("Error sending Email, " + smtp->errorReason());
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (smtp) delete smtp;
|
||||||
for (uint32_t cnt = 0; cnt < MAX_ATTCHMENTS; cnt++) {
|
for (uint32_t cnt = 0; cnt < MAX_ATTCHMENTS; cnt++) {
|
||||||
if (attachments[cnt]) {
|
if (attachments[cnt]) {
|
||||||
free(attachments[cnt]);
|
free(attachments[cnt]);
|
||||||
|
@ -322,4 +341,35 @@ void attach_Data(char *name, uint8_t *buff, uint32_t len) {
|
||||||
email_mptr->resetAttachItem(att);
|
email_mptr->resetAttachItem(att);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Callback function to get the Email sending status */
|
||||||
|
void smtpCallback(SMTP_Status status)
|
||||||
|
{
|
||||||
|
/* Print the current status */
|
||||||
|
Serial.println(status.info());
|
||||||
|
|
||||||
|
/* Print the sending result */
|
||||||
|
if (status.success())
|
||||||
|
{
|
||||||
|
Serial.println("----------------");
|
||||||
|
Serial.printf("Message sent success: %d\n", status.completedCount());
|
||||||
|
Serial.printf("Message sent failled: %d\n", status.failedCount());
|
||||||
|
Serial.println("----------------\n");
|
||||||
|
struct tm dt;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < smtp->sendingResult.size(); i++)
|
||||||
|
{
|
||||||
|
/* Get the result item */
|
||||||
|
SMTP_Result result = smtp->sendingResult.getItem(i);
|
||||||
|
localtime_r(&result.timesstamp, &dt);
|
||||||
|
|
||||||
|
Serial.printf("Message No: %d\n", i + 1);
|
||||||
|
Serial.printf("Status: %s\n", result.completed ? "success" : "failed");
|
||||||
|
Serial.printf("Date/Time: %d/%d/%d %d:%d:%d\n", dt.tm_year + 1900, dt.tm_mon + 1, dt.tm_mday, dt.tm_hour, dt.tm_min, dt.tm_sec);
|
||||||
|
Serial.printf("Recipient: %s\n", result.recipients);
|
||||||
|
Serial.printf("Subject: %s\n", result.subject);
|
||||||
|
}
|
||||||
|
Serial.println("----------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
#endif // USE_ESP32MAIL
|
#endif // USE_ESP32MAIL
|
||||||
|
|
|
@ -2924,7 +2924,7 @@ const char kWebCommands[] PROGMEM = "|" // No prefix
|
||||||
#ifdef USE_EMULATION
|
#ifdef USE_EMULATION
|
||||||
D_CMND_EMULATION "|"
|
D_CMND_EMULATION "|"
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SENDMAIL
|
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
|
||||||
D_CMND_SENDMAIL "|"
|
D_CMND_SENDMAIL "|"
|
||||||
#endif
|
#endif
|
||||||
D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|"
|
D_CMND_WEBSERVER "|" D_CMND_WEBPASSWORD "|" D_CMND_WEBLOG "|" D_CMND_WEBREFRESH "|" D_CMND_WEBSEND "|" D_CMND_WEBCOLOR "|"
|
||||||
|
@ -2934,7 +2934,7 @@ void (* const WebCommand[])(void) PROGMEM = {
|
||||||
#ifdef USE_EMULATION
|
#ifdef USE_EMULATION
|
||||||
&CmndEmulation,
|
&CmndEmulation,
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_SENDMAIL
|
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
|
||||||
&CmndSendmail,
|
&CmndSendmail,
|
||||||
#endif
|
#endif
|
||||||
&CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor,
|
&CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor,
|
||||||
|
@ -2966,7 +2966,7 @@ void CmndEmulation(void)
|
||||||
}
|
}
|
||||||
#endif // USE_EMULATION
|
#endif // USE_EMULATION
|
||||||
|
|
||||||
#ifdef USE_SENDMAIL
|
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
|
||||||
void CmndSendmail(void)
|
void CmndSendmail(void)
|
||||||
{
|
{
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
|
|
|
@ -4325,7 +4325,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
||||||
ResponseAppend_P(PSTR("%s"), tmp);
|
ResponseAppend_P(PSTR("%s"), tmp);
|
||||||
goto next_line;
|
goto next_line;
|
||||||
}
|
}
|
||||||
#ifdef USE_SENDMAIL
|
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
|
||||||
else if (!strncmp(lp, "mail", 4)) {
|
else if (!strncmp(lp, "mail", 4)) {
|
||||||
lp+=5;
|
lp+=5;
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
|
@ -4680,10 +4680,9 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
||||||
|
|
||||||
uint8_t script_xsns_index = 0;
|
uint8_t script_xsns_index = 0;
|
||||||
|
|
||||||
|
|
||||||
void ScripterEvery100ms(void) {
|
void ScripterEvery100ms(void) {
|
||||||
|
|
||||||
if (Settings.rule_enabled && (TasmotaGlobal.uptime > 4)) {
|
if (bitRead(Settings.rule_enabled, 0) && (TasmotaGlobal.uptime > 4)) {
|
||||||
ResponseClear();
|
ResponseClear();
|
||||||
uint16_t script_tele_period_save = TasmotaGlobal.tele_period;
|
uint16_t script_tele_period_save = TasmotaGlobal.tele_period;
|
||||||
TasmotaGlobal.tele_period = 2;
|
TasmotaGlobal.tele_period = 2;
|
||||||
|
@ -4695,7 +4694,7 @@ void ScripterEvery100ms(void) {
|
||||||
Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data);
|
Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.rule_enabled) {
|
if (bitRead(Settings.rule_enabled, 0)) {
|
||||||
if (glob_script_mem.fast_script == 99) Run_Scripter(">F", 2, 0);
|
if (glob_script_mem.fast_script == 99) Run_Scripter(">F", 2, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7161,7 +7160,7 @@ nextwebline:
|
||||||
#endif //USE_SCRIPT_WEB_DISPLAY
|
#endif //USE_SCRIPT_WEB_DISPLAY
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_SENDMAIL
|
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
|
||||||
|
|
||||||
void script_send_email_body(void(*func)(char *)) {
|
void script_send_email_body(void(*func)(char *)) {
|
||||||
uint8_t msect = Run_Scripter(">m", -2, 0);
|
uint8_t msect = Run_Scripter(">m", -2, 0);
|
||||||
|
|
Loading…
Reference in New Issue