diff --git a/src/ESP_Mail_Client.cpp b/src/ESP_Mail_Client.cpp index d76b0492..ab5ba1ec 100644 --- a/src/ESP_Mail_Client.cpp +++ b/src/ESP_Mail_Client.cpp @@ -767,7 +767,8 @@ void ESP_Mail_Client::splitToken(const char *str, MB_VECTOR &tk, cons MB_String tmp; while (pp != NULL) { - strsep(&end, delim); + // See RFC2047.h + ESP_MAIL_STRSEP(&end, delim); if (strlen(pp) > 0) { tmp = pp; diff --git a/src/ESP_Mail_IMAP.h b/src/ESP_Mail_IMAP.h index 29629fca..4a119227 100644 --- a/src/ESP_Mail_IMAP.h +++ b/src/ESP_Mail_IMAP.h @@ -3658,7 +3658,8 @@ void ESP_Mail_Client::parseFoldersResponse(IMAPSession *imap, char *buf, bool li while (pp != NULL) { - strsep(&end, " "); + // See RFC2047.h + ESP_MAIL_STRSEP(&end, " "); count++; if (count >= tkPos && strlen(pp) > 0) @@ -3923,7 +3924,8 @@ bool ESP_Mail_Client::getFlags(IMAPSession *imap, char *buf, esp_mail_imap_respo while (pp != NULL) { - strsep(&end, " "); + // See RFC2047.h + ESP_MAIL_STRSEP(&end, " "); count++; if (count >= tkPos && strlen(pp) > 0) { diff --git a/src/extras/Networks_Provider.h b/src/extras/Networks_Provider.h index 9add6247..fb731594 100644 --- a/src/extras/Networks_Provider.h +++ b/src/extras/Networks_Provider.h @@ -10,6 +10,8 @@ #include "SDK_Version_Common.h" +#define ESP_MAIL_STRSEP strsep + #if defined(ESP32) || defined(ESP8266) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || __has_include() ||__has_include() || __has_include() #if !defined(ESP_MAIL_DISABLE_ONBOARD_WIFI) @@ -28,6 +30,12 @@ #include #endif +#if __has_include() +#undef ESP_MAIL_STRSEP +#define ESP_MAIL_STRSEP strsepImpl +#define ESP_MAIL_USE_STRSEP_IMPL +#endif + #if !defined(ARDUINO_RASPBERRY_PI_PICO_W) && !defined(MB_ARDUINO_ARCH_SAMD) && !__has_include() #define ESP_MAIL_HAS_WIFI_DISCONNECT #endif diff --git a/src/extras/RFC2047.cpp b/src/extras/RFC2047.cpp index a4e237d3..544b787c 100644 --- a/src/extras/RFC2047.cpp +++ b/src/extras/RFC2047.cpp @@ -77,8 +77,8 @@ void RFC2047_Decoder::rfc2047DecodeWord(char *d, const char *s, size_t dlen) while (pp != NULL) { - - strsep(&end, "?"); + // See RFC2047.h + ESP_MAIL_STRSEP(&end, "?"); count++; switch (count) { @@ -153,7 +153,7 @@ void RFC2047_Decoder::rfc2047DecodeWord(char *d, const char *s, size_t dlen) } break; } - + pp = end; } diff --git a/src/extras/RFC2047.h b/src/extras/RFC2047.h index ca4b5bdb..58df80aa 100644 --- a/src/extras/RFC2047.h +++ b/src/extras/RFC2047.h @@ -11,6 +11,7 @@ #include #include "ESP_Mail_FS.h" #include "MB_FS.h" +#include "Networks_Provider.h" #if defined(ESP32) #if defined(BOARD_HAS_PSRAM) && defined(ESP_Mail_USE_PSRAM) @@ -20,9 +21,9 @@ #define strfcpy(A, B, C) strncpy(A, B, C), *(A + (C)-1) = 0 - - -static char *__attribute__((used)) strsep(char **stringp, const char *delim) +#if defined(ESP_MAIL_USE_STRSEP_IMPL) +// This is strsep implementation because strdup may not available in some platform. +static char *__attribute__((used)) strsepImpl(char **stringp, const char *delim) { char *rv = *stringp; if (rv) @@ -36,14 +37,16 @@ static char *__attribute__((used)) strsep(char **stringp, const char *delim) return rv; } +#endif + enum { - ENCOTHER, - ENC7BIT, - ENC8BIT, - ENCQUOTEDPRINTABLE, - ENCBASE64, - ENCBINARY + ENCOTHER, + ENC7BIT, + ENC8BIT, + ENCQUOTEDPRINTABLE, + ENCBASE64, + ENCBINARY }; __attribute__((used)) static const char *Charset = "utf-8"; @@ -78,14 +81,14 @@ class RFC2047_Decoder { public: - RFC2047_Decoder(); - ~RFC2047_Decoder(); - void decode(MB_FS *mbfs, char *d, const char *s, size_t dlen); + RFC2047_Decoder(); + ~RFC2047_Decoder(); + void decode(MB_FS *mbfs, char *d, const char *s, size_t dlen); private: - void rfc2047DecodeWord(char *d, const char *s, size_t dlen); - char *safe_strdup(const char *s); - MB_FS *mbfs = nullptr; + void rfc2047DecodeWord(char *d, const char *s, size_t dlen); + char *safe_strdup(const char *s); + MB_FS *mbfs = nullptr; }; #endif // RFC2047_H \ No newline at end of file