diff --git a/examples/SMTP/Custom_Ports/Custom_Ports.ino b/examples/SMTP/Custom_Ports/Custom_Ports.ino index eb500dd8..9bb16b8b 100644 --- a/examples/SMTP/Custom_Ports/Custom_Ports.ino +++ b/examples/SMTP/Custom_Ports/Custom_Ports.ino @@ -281,7 +281,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino b/examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino index 49e6b3b1..603d2778 100644 --- a/examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino +++ b/examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino @@ -303,7 +303,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino b/examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino index 77310cb2..dd2c41c3 100644 --- a/examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino +++ b/examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino @@ -246,7 +246,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/External_Client/BasicClient/Ethernet_BasicClient/Ethernet_BasicClient.ino b/examples/SMTP/External_Client/BasicClient/Ethernet_BasicClient/Ethernet_BasicClient.ino index ae0cb0f3..e7980c28 100644 --- a/examples/SMTP/External_Client/BasicClient/Ethernet_BasicClient/Ethernet_BasicClient.ino +++ b/examples/SMTP/External_Client/BasicClient/Ethernet_BasicClient/Ethernet_BasicClient.ino @@ -293,7 +293,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/External_Client/BasicClient/WiFi_BasicClient/WiFi_BasicClient.ino b/examples/SMTP/External_Client/BasicClient/WiFi_BasicClient/WiFi_BasicClient.ino index 01bb4a86..f4af727e 100644 --- a/examples/SMTP/External_Client/BasicClient/WiFi_BasicClient/WiFi_BasicClient.ino +++ b/examples/SMTP/External_Client/BasicClient/WiFi_BasicClient/WiFi_BasicClient.ino @@ -294,7 +294,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Access_Token/Send_Access_Token.ino b/examples/SMTP/Send_Access_Token/Send_Access_Token.ino index 6ad84f55..d3c61c70 100644 --- a/examples/SMTP/Send_Access_Token/Send_Access_Token.ino +++ b/examples/SMTP/Send_Access_Token/Send_Access_Token.ino @@ -214,7 +214,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Attachment_Blob/Send_Attachment_Blob.ino b/examples/SMTP/Send_Attachment_Blob/Send_Attachment_Blob.ino index 82d8c3fc..e6b984c5 100644 --- a/examples/SMTP/Send_Attachment_Blob/Send_Attachment_Blob.ino +++ b/examples/SMTP/Send_Attachment_Blob/Send_Attachment_Blob.ino @@ -279,7 +279,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Attachment_File/Send_Attachment_File.ino b/examples/SMTP/Send_Attachment_File/Send_Attachment_File.ino index 686f618c..024b540a 100644 --- a/examples/SMTP/Send_Attachment_File/Send_Attachment_File.ino +++ b/examples/SMTP/Send_Attachment_File/Send_Attachment_File.ino @@ -341,7 +341,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Attachment_Flash/Send_Attachment_Flash.ino b/examples/SMTP/Send_Attachment_Flash/Send_Attachment_Flash.ino index abe8fb3d..3d93e244 100644 --- a/examples/SMTP/Send_Attachment_Flash/Send_Attachment_Flash.ino +++ b/examples/SMTP/Send_Attachment_Flash/Send_Attachment_Flash.ino @@ -306,7 +306,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Attachment_PSRAM/Send_Attachment_PSRAM.ino b/examples/SMTP/Send_Attachment_PSRAM/Send_Attachment_PSRAM.ino index 7163f4d9..5a95cf99 100644 --- a/examples/SMTP/Send_Attachment_PSRAM/Send_Attachment_PSRAM.ino +++ b/examples/SMTP/Send_Attachment_PSRAM/Send_Attachment_PSRAM.ino @@ -229,7 +229,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino b/examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino index cb42d0f4..4c680b06 100644 --- a/examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino +++ b/examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino @@ -228,7 +228,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Embedded_Message/Send_Embedded_Message.ino b/examples/SMTP/Send_Embedded_Message/Send_Embedded_Message.ino index ea0f919c..c045477a 100644 --- a/examples/SMTP/Send_Embedded_Message/Send_Embedded_Message.ino +++ b/examples/SMTP/Send_Embedded_Message/Send_Embedded_Message.ino @@ -211,7 +211,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino b/examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino index 8ac98dd1..31a98494 100644 --- a/examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino +++ b/examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino @@ -200,7 +200,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino b/examples/SMTP/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino index 69aa7de6..b9959374 100644 --- a/examples/SMTP/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino +++ b/examples/SMTP/Send_Flash_Message_with_Inline_Image/Send_Flash_Message_with_Inline_Image.ino @@ -277,7 +277,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_HTML/Send_HTML.ino b/examples/SMTP/Send_HTML/Send_HTML.ino index c3c72eb1..eb0f08ba 100644 --- a/examples/SMTP/Send_HTML/Send_HTML.ino +++ b/examples/SMTP/Send_HTML/Send_HTML.ino @@ -199,7 +199,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Parallel_Attachment/Send_Parallel_Attachment.ino b/examples/SMTP/Send_Parallel_Attachment/Send_Parallel_Attachment.ino index a363b9e2..2b366a42 100644 --- a/examples/SMTP/Send_Parallel_Attachment/Send_Parallel_Attachment.ino +++ b/examples/SMTP/Send_Parallel_Attachment/Send_Parallel_Attachment.ino @@ -237,7 +237,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_RFC822_Attachment/Send_RFC822_Attachment.ino b/examples/SMTP/Send_RFC822_Attachment/Send_RFC822_Attachment.ino index defcae44..92a523d9 100644 --- a/examples/SMTP/Send_RFC822_Attachment/Send_RFC822_Attachment.ino +++ b/examples/SMTP/Send_RFC822_Attachment/Send_RFC822_Attachment.ino @@ -260,7 +260,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino b/examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino index 1b6303ea..afe0ef56 100644 --- a/examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino +++ b/examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino @@ -255,7 +255,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Text/Send_Text.ino b/examples/SMTP/Send_Text/Send_Text.ino index 6bde1001..bf053dbd 100644 --- a/examples/SMTP/Send_Text/Send_Text.ino +++ b/examples/SMTP/Send_Text/Send_Text.ino @@ -262,7 +262,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino b/examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino index 3a85e0e7..a95bbee5 100644 --- a/examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino +++ b/examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino @@ -209,7 +209,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/examples/SMTP/Sleep/Sleep.ino b/examples/SMTP/Sleep/Sleep.ino index 7fe7da66..6554e01e 100644 --- a/examples/SMTP/Sleep/Sleep.ino +++ b/examples/SMTP/Sleep/Sleep.ino @@ -252,7 +252,7 @@ void smtpCallback(SMTP_Status status) { // ESP_MAIL_PRINTF used in the examples is for format printing via debug Serial port // that works for all supported Arduino platform SDKs e.g. AVR, SAMD, ESP32 and ESP8266. - // In ESP32 and ESP32, you can use Serial.printf directly. + // In ESP8266 and ESP32, you can use Serial.printf directly. Serial.println("----------------"); ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount()); diff --git a/keywords.txt b/keywords.txt index 1b486e3b..c91a3fa8 100644 --- a/keywords.txt +++ b/keywords.txt @@ -105,6 +105,10 @@ getDateTimeString KEYWORD2 copyMessages KEYWORD2 deleteMessages KEYWORD2 createFolder KEYWORD2 +renameFolder KEYWORD2 +getSubscribesMailboxes KEYWORD2 +subscribe KEYWORD2 +unSubscribe KEYWORD2 deleteFolder KEYWORD2 listen KEYWORD2 stopListen KEYWORD2 diff --git a/library.json b/library.json index e42a32eb..4dd6886d 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ESP Mail Client", - "version": "2.6.1", + "version": "2.6.2", "keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino", "description": "Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino Devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.", "repository": { diff --git a/library.properties b/library.properties index 76f74a2d..14f12517 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=ESP Mail Client -version=2.6.1 +version=2.6.2 author=Mobizt diff --git a/src/ESP_Mail_Client.cpp b/src/ESP_Mail_Client.cpp index b8c9bd8c..556635c1 100644 --- a/src/ESP_Mail_Client.cpp +++ b/src/ESP_Mail_Client.cpp @@ -4,7 +4,7 @@ /** * Mail Client Arduino Library for Espressif's ESP32 and ESP8266 and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module * - * Created November 6, 2022 + * Created November 16, 2022 * * This library allows Espressif's ESP32, ESP8266 and SAMD devices to send and read Email through the SMTP and IMAP servers. * diff --git a/src/ESP_Mail_Client.h b/src/ESP_Mail_Client.h index df849dc2..6809547e 100644 --- a/src/ESP_Mail_Client.h +++ b/src/ESP_Mail_Client.h @@ -4,7 +4,7 @@ /** * Mail Client Arduino Library for Espressif's ESP32 and ESP8266 and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module * - * Created November 6, 2022 + * Created November 16, 2022 * * This library allows Espressif's ESP32, ESP8266 and SAMD devices to send and read Email through the SMTP and IMAP servers. * @@ -209,8 +209,16 @@ class FoldersCollection return fd; } + esp_mail_folder_info_t operator[](size_t index) + { + if (index < _folders.size()) + return _folders[index]; + + return esp_mail_folder_info_t(); + } + private: - void add(struct esp_mail_folder_info_t &fd) { _folders.push_back(fd); }; + void add(struct esp_mail_folder_info_t fd) { _folders.push_back(fd); }; void clear() { for (size_t i = 0; i < _folders.size(); i++) @@ -1219,7 +1227,7 @@ class ESP_Mail_Client bool parseAttachmentResponse(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, MB_String &filePath, bool &downloadRequest, int &octetCount, int &octetLength); // Parse mailbox folder open response - void parseFoldersResponse(IMAPSession *imap, char *buf); + void parseFoldersResponse(IMAPSession *imap, char *buf, bool list); // Prepare alias (short name) file list for unsupported long file name filesystem void prepareFileList(IMAPSession *imap, MB_String &filePath); @@ -1395,6 +1403,15 @@ class IMAPSession template bool createFolder(T folderName) { return mCreateFolder(toStringPtr(folderName)); } + /** Rename folder. + * + * @param currentFolderName The name of folder to rename. + * @param newFolderName The new name of folder to rename. + * @return The boolean value which indicates the success of operation. + */ + template + bool renameFolder(T1 currentFolderName, T2 newFolderName) { return mRenameFolder(toStringPtr(currentFolderName), toStringPtr(newFolderName)); } + /** Delete folder. * * @param folderName The name of folder to delete. @@ -1403,6 +1420,32 @@ class IMAPSession template bool deleteFolder(T folderName) { return mDeleteFolder(toStringPtr(folderName)); } + /** Get subscribes mailboxes. + * + * @param reference The reference name. + * @param mailbox The mailbox name with possible wildcards. + * @param folders The return FoldersCollection that contains the folder info e.g., name, attribute and delimiter. + * @return The boolean value which indicates the success of operation. + */ + template + bool getSubscribesMailboxes(T1 reference, T2 mailbox, FoldersCollection &folders) { return mGetSubscribesMailboxes(toStringPtr(reference), toStringPtr(mailbox), folders); } + + /** Subscribe mailbox. + * + * @param folderName The name of folder to subscribe. + * @return The boolean value which indicates the success of operation. + */ + template + bool subscribe(T folderName) { return mSubscribe(toStringPtr(folderName)); } + + /** Unsubscribe mailbox. + * + * @param folderName The name of folder to unsubscribe. + * @return The boolean value which indicates the success of operation. + */ + template + bool unSubscribe(T folderName) { return mUnSubscribe(toStringPtr(folderName)); } + /** Get UID number in selected or opened mailbox. * * @param msgNum The message number or order in the total message numbers. @@ -1582,7 +1625,16 @@ class IMAPSession bool openMailbox(MB_StringPtr folder, esp_mail_imap_auth_mode mode, bool waitResponse); // Get folders list - bool getMailboxes(FoldersCollection &flders); + bool getMailboxes(FoldersCollection &folders); + + // Get subscribes mailboxes + bool mGetSubscribesMailboxes(MB_StringPtr reference, MB_StringPtr mailbox, FoldersCollection &folders); + + // Subscribe the mailbox + bool mSubscribe(MB_StringPtr folder); + + // Unsubscribe the mailbox + bool mUnSubscribe(MB_StringPtr folder); // Prepend TAG for response status parsing MB_String prependTag(PGM_P tag, PGM_P cmd); @@ -1611,6 +1663,9 @@ class IMAPSession // Create folder bool mCreateFolder(MB_StringPtr folderName); + // Rename folder + bool mRenameFolder(MB_StringPtr currentFolderName, MB_StringPtr newFolderName); + // Copy message bool mCopyMessages(MessageList *toCopy, MB_StringPtr dest); diff --git a/src/ESP_Mail_Client_Version.h b/src/ESP_Mail_Client_Version.h index 9bc1872b..d2415e51 100644 --- a/src/ESP_Mail_Client_Version.h +++ b/src/ESP_Mail_Client_Version.h @@ -3,6 +3,6 @@ #ifndef ESP_MAIL_VERSION -#define ESP_MAIL_VERSION "2.6.1" +#define ESP_MAIL_VERSION "2.6.2" #endif \ No newline at end of file diff --git a/src/ESP_Mail_Const.h b/src/ESP_Mail_Const.h index e92bf5fc..c3bbcc45 100644 --- a/src/ESP_Mail_Const.h +++ b/src/ESP_Mail_Const.h @@ -1,4 +1,4 @@ -// Created October 1, 2022 +// Created November 16, 2022 #pragma once @@ -670,6 +670,9 @@ enum esp_mail_imap_command esp_mail_imap_cmd_plain, esp_mail_imap_cmd_auth, esp_mail_imap_cmd_list, + esp_mail_imap_cmd_lsub, + esp_mail_imap_cmd_subscribe, + esp_mail_imap_cmd_unsubscribe, esp_mail_imap_cmd_select, esp_mail_imap_cmd_examine, esp_mail_imap_cmd_close, @@ -684,6 +687,7 @@ enum esp_mail_imap_command esp_mail_imap_cmd_store, esp_mail_imap_cmd_expunge, esp_mail_imap_cmd_create, + esp_mail_imap_cmd_rename, esp_mail_imap_cmd_delete, esp_mail_imap_cmd_idle, esp_mail_imap_cmd_done, @@ -1960,6 +1964,17 @@ static const char esp_mail_str_340[] PROGMEM = "Mailbox listening stopped"; static const char esp_mail_str_341[] PROGMEM = "> C: Mailbox listening stopped"; static const char esp_mail_str_342[] PROGMEM = " FETCH (UID "; static const char esp_mail_str_354[] PROGMEM = " [UNSEEN "; +static const char esp_mail_str_373[] PROGMEM = "RENAME "; +static const char esp_mail_str_374[] PROGMEM = "> C: Rename folder"; +static const char esp_mail_str_375[] PROGMEM = "> C: Send IMAP command, LSUB"; +static const char esp_mail_str_376[] PROGMEM = "Listing the subscribed mailboxes..."; +static const char esp_mail_str_377[] PROGMEM = "LSUB "; +static const char esp_mail_str_378[] PROGMEM = "> C: Send IMAP command, SUBSCRIBE"; +static const char esp_mail_str_379[] PROGMEM = "Subscribe mailbox..."; +static const char esp_mail_str_380[] PROGMEM = "SUBSCRIBE "; +static const char esp_mail_str_381[] PROGMEM = "> C: Send IMAP command, UNSUBSCRIBE"; +static const char esp_mail_str_382[] PROGMEM = "Unsubscribe mailbox..."; +static const char esp_mail_str_383[] PROGMEM = "UNSUBSCRIBE "; // Tagged static const char esp_mail_imap_response_1[] PROGMEM = "OK "; @@ -1989,6 +2004,7 @@ static const char esp_mail_imap_response_23[] PROGMEM = "MULTIAPPEND"; static const char esp_mail_imap_response_24[] PROGMEM = "UIDPLUS"; static const char esp_mail_imap_response_25[] PROGMEM = "LITERAL+"; static const char esp_mail_imap_response_26[] PROGMEM = "LITERAL-"; +static const char esp_mail_imap_response_27[] PROGMEM = "* LSUB "; #endif diff --git a/src/ESP_Mail_IMAP.h b/src/ESP_Mail_IMAP.h index 907f433f..c0ee9d61 100644 --- a/src/ESP_Mail_IMAP.h +++ b/src/ESP_Mail_IMAP.h @@ -2706,7 +2706,9 @@ bool ESP_Mail_Client::handleIMAPResponse(IMAPSession *imap, int errCode, bool cl else if (imap->_imap_cmd == esp_mail_imap_cmd_capability) parseCapabilityResponse(imap, response, chunkIdx); else if (imap->_imap_cmd == esp_mail_imap_cmd_list) - parseFoldersResponse(imap, response); + parseFoldersResponse(imap, response, true); + else if (imap->_imap_cmd == esp_mail_imap_cmd_lsub) + parseFoldersResponse(imap, response, false); else if (imap->_imap_cmd == esp_mail_imap_cmd_select || imap->_imap_cmd == esp_mail_imap_cmd_examine) parseExamineResponse(imap, response); else if (imap->_imap_cmd == esp_mail_imap_cmd_get_uid) @@ -3325,11 +3327,11 @@ bool ESP_Mail_Client::parseCapabilityResponse(IMAPSession *imap, const char *buf return false; } -void ESP_Mail_Client::parseFoldersResponse(IMAPSession *imap, char *buf) +void ESP_Mail_Client::parseFoldersResponse(IMAPSession *imap, char *buf, bool list) { struct esp_mail_folder_info_t fd; char *tmp = nullptr; - int p1 = strposP(buf, esp_mail_imap_response_4, 0); + int p1 = list ? strposP(buf, esp_mail_imap_response_4, 0): strposP(buf, esp_mail_imap_response_27, 0); int p2 = 0; if (p1 != -1) { @@ -5267,6 +5269,102 @@ bool IMAPSession::getMailboxes(FoldersCollection &folders) return true; } +bool IMAPSession::mGetSubscribesMailboxes(MB_StringPtr reference, MB_StringPtr mailbox, FoldersCollection &folders) +{ + folders.clear(); + + FoldersCollection tmp; + + if (_readCallback) + MailClient.imapCB(this, esp_mail_str_376, true, false); + + if (_debug) + esp_mail_debug_print(esp_mail_str_375, true); + + MB_String cmd = prependTag(esp_mail_str_27, esp_mail_str_377); + cmd += esp_mail_str_136; + cmd += reference; + cmd += esp_mail_str_136; + + cmd += esp_mail_str_131; + + cmd += esp_mail_str_136; + cmd += mailbox; + cmd += esp_mail_str_136; + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + for (size_t i = 0; i < this->_folders.size(); i++) + tmp.add(this->_folders[i]); + + this->_folders.clear(); + + _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_lsub; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + for (size_t i = 0; i < this->_folders.size(); i++) + folders.add(this->_folders[i]); + + this->_folders.clear(); + + for (size_t i = 0; i < tmp.size(); i++) + this->_folders.add(tmp[i]); + + tmp.clear(); + + return true; +} + +bool IMAPSession::mSubscribe(MB_StringPtr folder) +{ + + if (_readCallback) + MailClient.imapCB(this, esp_mail_str_379, true, false); + + if (_debug) + esp_mail_debug_print(esp_mail_str_378, true); + + MB_String cmd = prependTag(esp_mail_str_27, esp_mail_str_380); + cmd += esp_mail_str_136; + cmd += folder; + cmd += esp_mail_str_136; + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_subscribe; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + return true; +} + +bool IMAPSession::mUnSubscribe(MB_StringPtr folder) +{ + + if (_readCallback) + MailClient.imapCB(this, esp_mail_str_382, true, false); + + if (_debug) + esp_mail_debug_print(esp_mail_str_381, true); + + MB_String cmd = prependTag(esp_mail_str_27, esp_mail_str_383); + cmd += esp_mail_str_136; + cmd += folder; + cmd += esp_mail_str_136; + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_unsubscribe; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_LIST_MAILBOXS_FAILED, false)) + return false; + + return true; +} + MB_String IMAPSession::prependTag(PGM_P tag, PGM_P cmd) { MB_String s = tag; @@ -5314,6 +5412,50 @@ bool IMAPSession::mCreateFolder(MB_StringPtr folderName) return true; } +bool IMAPSession::mRenameFolder(MB_StringPtr currentFolderName, MB_StringPtr newFolderName) +{ + if (_debug) + { + esp_mail_debug_print(); + esp_mail_debug_print(esp_mail_str_374, true); + } + + MB_String o = currentFolderName; + MB_String n = newFolderName; + + o.trim(); + n.trim(); + + if (o == n) + return true; + + if (o.length() == 0 || n.length() == 0) + return false; + + MB_String cmd = prependTag(esp_mail_str_27, esp_mail_str_373); + cmd += esp_mail_str_136; + cmd += o; + cmd += esp_mail_str_136; + + cmd += esp_mail_str_131; + + cmd += esp_mail_str_136; + cmd += n; + cmd += esp_mail_str_136; + + if (MailClient.imapSend(this, cmd.c_str(), true) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED) + return false; + + _imap_cmd = esp_mail_imap_command::esp_mail_imap_cmd_rename; + if (!MailClient.handleIMAPResponse(this, IMAP_STATUS_BAD_COMMAND, false)) + return false; + + if (_currentFolder == o) + selectFolder(n.c_str(), false); + + return true; +} + int IMAPSession::getUID(int msgNum) { if (_currentFolder.length() == 0) diff --git a/src/README.md b/src/README.md index 760e56a9..0b886980 100644 --- a/src/README.md +++ b/src/README.md @@ -73,7 +73,7 @@ param **`closeSession`** The option to close the IMAP session after set flag. return **`boolean`** The boolean value indicates the success of operation. ```cpp -bool setFlag(IMAPSession *imap, int msgUID, const char *flags, bool closeSession); +bool setFlag(IMAPSession *imap, int msgUID, flags, bool closeSession); ``` @@ -93,7 +93,7 @@ param **`closeSession`** The option to close the IMAP session after add flag. return **`boolean`** The boolean value indicates the success of operation. ```cpp -bool addFlag(IMAPSession *imap, int msgUID, const char *flags, bool closeSession); +bool addFlag(IMAPSession *imap, int msgUID, flags, bool closeSession); ``` @@ -114,7 +114,7 @@ param **`closeSession`** The option to close the IMAP session after remove flag. return **`boolean`** The boolean value indicates the success of operation. ```cpp -bool removeFlag(IMAPSession *imap, int msgUID, const char *flags, bool closeSession); +bool removeFlag(IMAPSession *imap, int msgUID, flags, bool closeSession); ``` @@ -411,7 +411,7 @@ return **`boolean`** The boolean value which indicates the success of operation. note: the function will exit immediately and return true if the time since previous success folder selection (open) with the same readOnly mode, is less than 5 seconds. ```cpp -bool selectFolder(const char *folderName, bool readOnly = true); +bool selectFolder( folderName, bool readOnly = true); ``` @@ -430,7 +430,7 @@ return **`boolean`** The boolean value which indicates the success of operation. note: the function will exit immediately and return true if the time since previous success folder selection (open) with the same readOnly mode, is less than 5 seconds. ```cpp -bool openFolder(const char *folderName, bool readOnly = true); +bool openFolder( folderName, bool readOnly = true); ``` @@ -444,7 +444,7 @@ param **`folderName`** The mailbox folder name. return **`boolean`** The boolean value which indicates the success of operation. ```cpp -bool closeFolder(const char *folderName); +bool closeFolder( folderName); ``` @@ -459,13 +459,70 @@ param **`folderName`** The name of folder to create. return **`boolean`** The boolean value which indicates the success of operation. ```cpp -bool createFolder(const char *folderName); +bool createFolder( folderName); ``` +#### Get subscribes mailboxes. + +param **`reference`** The reference name. + +param **`mailbox`** The mailbox name with possible wildcards. + +param **`folders`** The return FoldersCollection that contains the folder info e.g., name, attribute and delimiter. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool getSubscribesMailboxes( reference, mailbox, FoldersCollection &folders); +``` + + + + +#### Subscribe mailbox. + +param **`folderName`** The name of folder to subscribe. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool subscribe( folderName) +``` + + + + +#### Unsubscribe mailbox. + +param **`folderName`** The name of folder to unsubscribe. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool unSubscribe( folderName) +``` + + + + + +#### Rename folder. + +param **`currentFolderName`** The name of folder to create. + +param **`newFolderName`** The new name of folder to create. + +return **`boolean`** The boolean value which indicates the success of operation. + +```cpp +bool renameFolder( currentFolderName, newFolderName); +``` + + #### Delete folder. @@ -474,7 +531,7 @@ param **`folderName`** The name of folder to delete.. return **`boolean`** The boolean value which indicates the success of operation. ```cpp -bool deleteFolder(const char *folderName); +bool deleteFolder( folderName); ``` @@ -1138,7 +1195,7 @@ param **`name`** The name of primary recipient param **`email`** The Email address of primary recipient ```cpp -void addRecipient(const char *name, const char *email); +void addRecipient( name, email); ``` @@ -1150,7 +1207,7 @@ void addRecipient(const char *name, const char *email); param **`email`** The Email address of secondary recipient ```cpp -void addCc(const char *email); +void addCc( email); ``` @@ -1162,7 +1219,7 @@ void addCc(const char *email); param **`email`** The Email address of the tertiary recipient ```cpp -void addBcc(const char *email); +void addBcc( email); ``` @@ -1174,7 +1231,7 @@ void addBcc(const char *email); param **`hdr`** The header name and value ```cpp -void addHeader(const char *hdr); +void addHeader( hdr); ```