remove spiffs from sendmail lib

This commit is contained in:
gemu2015 2021-02-18 16:35:25 +01:00
parent dffdfafac1
commit c528bf20a9
8 changed files with 140 additions and 88 deletions

View File

@ -405,12 +405,13 @@ bool ESP_Mail_Client::readMail(IMAPSession *imap, bool closeSession)
if (!SD.exists(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)
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
#elif defined(ESP8266)
_flashOk = FLASH_FS.begin();
// _flashOk = FLASH_FS.begin();
#endif
}
}
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)
{
if (_flashOk)
if (_flashOk) {
#if defined(ESP32)
SPIFFS.end();
// SPIFFS.end();
#elif defined(ESP8266)
FLASH_FS.end();
// FLASH_FS.end();
#endif
}
_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)
_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)
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
#elif defined(ESP8266)
_flashOk = FLASH_FS.begin();
// _flashOk = FLASH_FS.begin();
#endif
}
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) {
#if defined(ESP32)
file_existed = SPIFFS.exists(filepath.c_str());
//file_existed = SPIFFS.exists(filepath.c_str());
#elif defined(ESP8266)
file_existed = FLASH_FS.exists(filepath.c_str());
//file_existed = FLASH_FS.exists(filepath.c_str());
#endif
} else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
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) {
#if defined(ESP32)
file_existed = SPIFFS.exists(filepath.c_str());
//file_existed = SPIFFS.exists(filepath.c_str());
#elif defined(ESP8266)
file_existed = FLASH_FS.exists(filepath.c_str());
//file_existed = FLASH_FS.exists(filepath.c_str());
#endif
}
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) {
#if defined(ESP32)
file = SPIFFS.open(filepath.c_str(), FILE_READ);
//file = SPIFFS.open(filepath.c_str(), FILE_READ);
#elif defined(ESP8266)
file = FLASH_FS.open(filepath.c_str(), "r");
//file = FLASH_FS.open(filepath.c_str(), "r");
#endif
}
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)
_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)
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
#elif defined(ESP8266)
_flashOk = FLASH_FS.begin();
// _flashOk = FLASH_FS.begin();
#endif
}
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);
if (imap->_storageType == esp_mail_file_storage_type_sd && !_sdOk)
_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)
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
#elif defined(ESP8266)
_flashOk = FLASH_FS.begin();
// _flashOk = FLASH_FS.begin();
#endif
}
if (_sdOk || _flashOk)
{
if (file)
@ -5708,13 +5709,13 @@ void ESP_Mail_Client::saveHeader(IMAPSession *imap)
if (imap->_storageType == esp_mail_file_storage_type_sd)
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)
file = SPIFFS.open(headerFilePath.c_str(), FILE_WRITE);
// file = SPIFFS.open(headerFilePath.c_str(), FILE_WRITE);
#elif defined(ESP8266)
file = FLASH_FS.open(headerFilePath.c_str(), "w");
// file = FLASH_FS.open(headerFilePath.c_str(), "w");
#endif
}
if (file)
{
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)
_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)
_flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
// _flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
#elif defined(ESP8266)
_flashOk = FLASH_FS.begin();
// _flashOk = FLASH_FS.begin();
#endif
}
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)
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)
file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
// file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
#elif defined(ESP8266)
file = FLASH_FS.open(filePath.c_str(), "w");
// file = FLASH_FS.open(filePath.c_str(), "w");
#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)
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)
file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
// file = SPIFFS.open(filePath.c_str(), FILE_WRITE);
#elif defined(ESP8266)
file = FLASH_FS.open(filePath.c_str(), "w");
// file = FLASH_FS.open(filePath.c_str(), "w");
#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)
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)
MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
// MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
#elif defined(ESP8266)
MailClient._flashOk = FLASH_FS.begin();
// MailClient._flashOk = FLASH_FS.begin();
#endif
}
}
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)
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)
MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
// MailClient._flashOk = SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED);
#elif defined(ESP8266)
MailClient._flashOk = FLASH_FS.begin();
// MailClient._flashOk = FLASH_FS.begin();
#endif
MailClient._flashOk = 1;
}
}
return MailClient.smtpAuth(this);
}

View File

@ -48,7 +48,7 @@
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include <FS.h>
#include <SPIFFS.h>
//#include <SPIFFS.h>
#include <ETH.h>
#include "wcs/esp32/ESP_Mail_HTTPClient32.h"
#include "extras/ESPTimeHelper.h"

View File

@ -1,17 +1,17 @@
/*
* Customized version of ESP32 HTTPClient Library.
*
* Customized version of ESP32 HTTPClient Library.
*
* v 1.1.1
*
*
* The MIT License (MIT)
* Copyright (c) 2021 K. Suwatchai (Mobizt)
*
*
* HTTPClient Arduino library for ESP32
*
* Copyright (c) 2015 Markus Sattler. All rights reserved.
* This file is part of the HTTPClient for Arduino.
* Port to ESP32 by Evandro Luis Copercini (2017),
* changed fingerprints to CA verification.
* Port to ESP32 by Evandro Luis Copercini (2017),
* changed fingerprints to CA verification.
*
* This library is free software; you can redistribute it and/or
* 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;
_certType = 2;
if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_flash)
t = SPIFFS.begin(true);
if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_flash) {
// t = SPIFFS.begin(true);
}
else if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_sd)
t = SD.begin();
if (!t)
@ -215,8 +216,8 @@ void ESP_Mail_HTTPClient32::setCertFile(const char *caCertFile, esp_mail_file_st
File f;
if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_flash)
{
if (SPIFFS.exists(caCertFile))
f = SPIFFS.open(caCertFile, FILE_READ);
//if (SPIFFS.exists(caCertFile))
// f = SPIFFS.open(caCertFile, FILE_READ);
}
else if (storageType == esp_mail_file_storage_type::esp_mail_file_storage_type_sd)
{

View File

@ -1,17 +1,17 @@
/*
* Customized version of ESP32 HTTPClient Library.
*
* Customized version of ESP32 HTTPClient Library.
*
* v 1.1.1
*
*
* The MIT License (MIT)
* Copyright (c) 2021 K. Suwatchai (Mobizt)
*
*
* HTTPClient Arduino library for ESP32
*
* Copyright (c) 2015 Markus Sattler. All rights reserved.
* This file is part of the HTTPClient for Arduino.
* Port to ESP32 by Evandro Luis Copercini (2017),
* changed fingerprints to CA verification.
* Port to ESP32 by Evandro Luis Copercini (2017),
* changed fingerprints to CA verification.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -37,7 +37,7 @@
#include <Arduino.h>
#include <WiFiClient.h>
#include <FS.h>
#include <SPIFFS.h>
//#include <SPIFFS.h>
#include <SD.h>
#include "ESP_Mail_WCS32.h"
@ -115,7 +115,7 @@ public:
* \param host - Host name without protocols.
* \param port - Server's port.
* \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);
@ -129,7 +129,7 @@ public:
* Establish http connection if header provided and send it, send payload if provided.
* \param header - The header string (constant chars array).
* \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.
*/
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)
* \param header - The header string (constant chars array).
* \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);

View File

@ -1,6 +1,6 @@
/*
Customized version of WiFiClientSecure.cpp
WiFiClientBearSSL- SSL client/server for esp8266 using BearSSL libraries
- Mostly compatible with Arduino WiFi shield library and standard
WiFiClient/ServerSecure (except for certificate handling).
@ -53,6 +53,9 @@ extern "C"
#include <c_types.h>
#include <coredecls.h>
//#define Optimistic_yield(A) optimistic_yield(A);ESP.wdtFeed();
#define Optimistic_yield(A) optimistic_yield(A)
#if !CORE_MOCK
// 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
if (sent_bytes)
{
optimistic_yield(1000);
Optimistic_yield(1000);
}
// 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;)
{
optimistic_yield(100);
Optimistic_yield(100);
if (loopTimeout)
{
@ -555,10 +558,10 @@ namespace ESP_Mail
if (!blocking && len > availForWrite)
{
/*
/*
writes on WiFiClient will block if len > availableForWrite()
this is needed to prevent available() calls from blocking
on dropped connections
on dropped connections
*/
len = availForWrite;
}
@ -662,7 +665,7 @@ namespace ESP_Mail
{
_handshake_done = true;
}
optimistic_yield(1000);
Optimistic_yield(1000);
}
return _handshake_done;
}
@ -885,7 +888,7 @@ namespace ESP_Mail
ctx->match_fingerprint = _use_fingerprint ? _fingerprint : nullptr;
ctx->allow_self_signed = _allow_self_signed ? 1 : 0;
}
// Some constants uses to init the server/client contexts
// Note that suites_P needs to be copied to RAM before use w/BearSSL!
@ -2047,7 +2050,7 @@ namespace ESP_Mail
if (!result)
{
optimistic_yield(100);
Optimistic_yield(100);
}
return result;
}
@ -2116,4 +2119,4 @@ namespace ESP_Mail
#endif /* ESP8266 */
#endif /* ESP_Mail_WCS_CPP */
#endif /* ESP_Mail_WCS_CPP */

View File

@ -1,11 +1,20 @@
#ifdef USE_ESP32MAIL
#include <ESP_Mail_Client.h>
#ifdef ESP8266
#ifndef SEND_MAIL32_MINRAM
#define SEND_MAIL32_MINRAM 13*1024
#endif
#endif // ESP8266
#ifdef ESP32
#ifndef SEND_MAIL32_MINRAM
#define SEND_MAIL32_MINRAM 30*1024
#endif
#endif // ESP32
#define xPSTR(a) a
#define MAX_ATTCHMENTS 8
char *attachments[MAX_ATTCHMENTS];
@ -13,6 +22,8 @@ uint8_t num_attachments;
void script_send_email_body(void(*func)(char *));
String html_content = "";
SMTP_Message *email_mptr;
SMTPSession smtp;
void smtpCallback(SMTP_Status status);
//#define DEBUG_EMAIL_PORT
@ -30,7 +41,6 @@ uint16_t SendMail(char *buffer) {
uint16_t status = 0;
uint16_t blen;
char *endcmd;
SMTPSession smtp;
ESP_Mail_Session session;
SMTP_Message message;
email_mptr = &message;
@ -39,8 +49,11 @@ uint16_t SendMail(char *buffer) {
uint32_t mem = ESP.getFreeHeap();
//AddLog(LOG_LEVEL_INFO, PSTR("heap: %d"),mem);
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++;
@ -156,13 +169,12 @@ uint16_t SendMail(char *buffer) {
//smtp.debug(true);
smtp.debug(false);
// smtp.callback(smtpCallback);
message.clearRecipients();
message.clearCc();
message.clearBcc();
//smtp.callback(smtpCallback);
session.server.host_name = mserv;
session.server.port = port;
session.login.email = user;
@ -322,4 +334,35 @@ void attach_Data(char *name, uint8_t *buff, uint32_t len) {
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

View File

@ -2924,7 +2924,7 @@ const char kWebCommands[] PROGMEM = "|" // No prefix
#ifdef USE_EMULATION
D_CMND_EMULATION "|"
#endif
#ifdef USE_SENDMAIL
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
D_CMND_SENDMAIL "|"
#endif
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
&CmndEmulation,
#endif
#ifdef USE_SENDMAIL
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
&CmndSendmail,
#endif
&CmndWebServer, &CmndWebPassword, &CmndWeblog, &CmndWebRefresh, &CmndWebSend, &CmndWebColor,
@ -2966,7 +2966,7 @@ void CmndEmulation(void)
}
#endif // USE_EMULATION
#ifdef USE_SENDMAIL
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
void CmndSendmail(void)
{
if (XdrvMailbox.data_len > 0) {

View File

@ -4325,7 +4325,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
ResponseAppend_P(PSTR("%s"), tmp);
goto next_line;
}
#ifdef USE_SENDMAIL
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
else if (!strncmp(lp, "mail", 4)) {
lp+=5;
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;
void ScripterEvery100ms(void) {
if (Settings.rule_enabled && (TasmotaGlobal.uptime > 4)) {
if (bitRead(Settings.rule_enabled, 0) && (TasmotaGlobal.uptime > 4)) {
ResponseClear();
uint16_t script_tele_period_save = TasmotaGlobal.tele_period;
TasmotaGlobal.tele_period = 2;
@ -4695,7 +4694,7 @@ void ScripterEvery100ms(void) {
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);
}
}
@ -7161,7 +7160,7 @@ nextwebline:
#endif //USE_SCRIPT_WEB_DISPLAY
#ifdef USE_SENDMAIL
#if defined(USE_SENDMAIL) || defined(USE_ESP32MAIL)
void script_send_email_body(void(*func)(char *)) {
uint8_t msect = Run_Scripter(">m", -2, 0);