fixes from GEMU2015

This commit is contained in:
Jason2866 2021-06-03 16:17:41 +02:00
parent 96ce74bdd8
commit dba5cf2902
3 changed files with 84 additions and 66 deletions

View File

@ -2746,20 +2746,16 @@ bool ESP_Mail_Client::sendAttachments(SMTPSession *smtp, SMTP_Message *msg, cons
else
{
if (att->file.storage_type == esp_mail_file_storage_type_univ) {
} else {
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 = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH);
_flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH);
#elif defined(ESP8266)
//_flashOk = ESP_MAIL_FLASH_FS.begin();
_flashOk = ESP_MAIL_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))
{
@ -2812,13 +2808,12 @@ bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_At
if (att->file.storage_type == esp_mail_file_storage_type_sd) {
file_existed = ESP_MAIL_SD_FS.exists(filepath.c_str());
}
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
}
else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
} else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
file_existed = ESP_MAIL_FLASH_FS.exists(filepath.c_str());
} else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
file_existed = ufsp->exists(filepath.c_str());
}
}
if (!file_existed)
{
@ -2832,11 +2827,10 @@ bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_At
if (att->file.storage_type == esp_mail_file_storage_type_sd) {
file_existed = ESP_MAIL_SD_FS.exists(filepath.c_str());
}
else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
}
else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
} else if (att->file.storage_type == esp_mail_file_storage_type_flash) {
file_existed = ESP_MAIL_FLASH_FS.exists(filepath.c_str());
} else if (att->file.storage_type == esp_mail_file_storage_type_univ) {
file_existed = ufsp->exists(filepath.c_str());
}
}
@ -2861,17 +2855,16 @@ bool ESP_Mail_Client::openFileRead(SMTPSession *smtp, SMTP_Message *msg, SMTP_At
if (att->file.storage_type == esp_mail_file_storage_type_sd) {
file = ESP_MAIL_SD_FS.open(filepath.c_str(), FILE_READ);
}
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)
//file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), FILE_READ);
file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), FILE_READ);
#elif defined(ESP8266)
//file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), "r");
file = ESP_MAIL_FLASH_FS.open(filepath.c_str(), "r");
#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 = ufsp->open(filepath.c_str(), "r");
}
if (!file)
return false;
@ -2904,10 +2897,13 @@ bool ESP_Mail_Client::openFileRead2(SMTPSession *smtp, SMTP_Message *msg, File &
filepath += path;
}
if (storageType == esp_mail_file_storage_type_sd)
if (storageType == esp_mail_file_storage_type_sd) {
file_existed = ESP_MAIL_SD_FS.exists(filepath.c_str());
else if (storageType == esp_mail_file_storage_type_flash)
} else if (storageType == esp_mail_file_storage_type_flash) {
file_existed = ESP_MAIL_FLASH_FS.exists(filepath.c_str());
} else if (storageType == esp_mail_file_storage_type_univ) {
file_existed = ufsp->exists(filepath.c_str());
}
if (!file_existed)
{
@ -3034,18 +3030,16 @@ bool ESP_Mail_Client::sendInline(SMTPSession *smtp, SMTP_Message *msg, const std
}
else
{
if (att->file.storage_type == esp_mail_file_storage_type_univ) {
} else {
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 = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH);
_flashOk = ESP_MAIL_FLASH_FS.begin(FORMAT_FLASH);
#elif defined(ESP8266)
//_flashOk = ESP_MAIL_FLASH_FS.begin();
_flashOk = ESP_MAIL_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))
{
@ -6072,14 +6066,17 @@ void ESP_Mail_Client::saveHeader(IMAPSession *imap)
if (file)
file.close();
if (imap->_storageType == esp_mail_file_storage_type_sd)
if (imap->_storageType == esp_mail_file_storage_type_sd) {
file = ESP_MAIL_SD_FS.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 = ESP_MAIL_FLASH_FS.open(headerFilePath.c_str(), FILE_WRITE);
#elif defined(ESP8266)
file = ESP_MAIL_FLASH_FS.open(headerFilePath.c_str(), "w");
#endif
} else if (imap->_storageType == esp_mail_file_storage_type_univ) {
file = ufsp->open(headerFilePath.c_str(), "w");
}
if (file)
{

View File

@ -2789,10 +2789,18 @@ private:
#endif
};
//#define EMAIL_DEBUG_PRINTLN Serial.println
//#define EMAIL_DEBUG_PRINT Serial.print
#define EMAIL_DEBUG_PRINTLN Tasmota_print
#define EMAIL_DEBUG_PRINT Tasmota_print
extern void Tasmota_print(const char *);
static void __attribute__((used)) esp_mail_debug(const char *msg)
{
delay(0);
Serial.println(msg);
EMAIL_DEBUG_PRINTLN(msg);
}
static void __attribute__((used))
@ -2800,11 +2808,13 @@ esp_mail_debug_line(const char *msg, bool newline)
{
delay(0);
if (newline)
Serial.println(msg);
EMAIL_DEBUG_PRINTLN(msg);
else
Serial.print(msg);
EMAIL_DEBUG_PRINT(msg);
}
extern ESP_Mail_Client MailClient;
extern FS *ufsp;
#endif // ESP_Mail_Client_H

View File

@ -3,19 +3,11 @@
#include <ESP_Mail_Client.h>
#ifdef ESP8266
#ifndef SEND_MAIL32_MINRAM
#undef SEND_MAIL32_MINRAM
#define SEND_MAIL32_MINRAM 13*1024
#define SEND_MAIL32_MINRAM 70*1024
#endif
#endif // ESP8266
#ifdef ESP32
#ifndef SEND_MAIL32_MINRAM
#undef SEND_MAIL32_MINRAM
#define SEND_MAIL32_MINRAM 30*1024
#endif
#endif // ESP32
#define xPSTR(a) a
#define MAX_ATTCHMENTS 8
@ -41,7 +33,7 @@ uint16_t SendMail(char *buffer) {
const char *to;
const char *subject;
const char *cmd;
uint16_t status = 0;
uint16_t status = 1;
uint16_t blen;
char *endcmd;
ESP_Mail_Session session;
@ -173,8 +165,12 @@ uint16_t SendMail(char *buffer) {
#endif
//smtp->debug(true);
#ifdef DEBUG_EMAIL_PORT
smtp->debug(true);
#else
smtp->debug(false);
#endif
// smtp->callback(smtpCallback);
message.clearRecipients();
@ -219,14 +215,17 @@ uint16_t SendMail(char *buffer) {
/* Connect to server with the session config */
delay(0);
if (!smtp->connect(&session))
if (!smtp->connect(&session)) {
goto exit;
}
/* Start sending the Email and close the session */
delay(0);
if (!MailClient.sendMail(smtp, &message, true)) {
Serial.println("Error sending Email, " + smtp->errorReason());
} else {
status = 0;
}
exit:
@ -372,4 +371,16 @@ if (status.success())
}
}
void Tasmota_print(const char *txt) {
#ifdef DEBUG_EMAIL_PORT
AddLog(LOG_LEVEL_INFO, PSTR("ESP32mail: %s"),txt);
#endif
}
#endif // USE_ESP32MAIL