Skip to content

Commit

Permalink
Add IMAP functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Nov 17, 2022
1 parent ce85600 commit 5d291d2
Show file tree
Hide file tree
Showing 30 changed files with 319 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/SMTP/Custom_Ports/Custom_Ports.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Ethernet/ESP32/Send_Text/Send_Text.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Ethernet/ESP8266/Send_Text/Send_Text.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Send_Access_Token/Send_Access_Token.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Send_Camera_Image/ESP_Camera/ESP_Camera.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Send_Enriched_Text/Send_Enriched_Text.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Send_HTML/Send_HTML.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Send_Reuse_Session/Send_Reuse_Session.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Send_Text/Send_Text.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Send_Text_Flowed/Send_Text_Flowed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/SMTP/Sleep/Sleep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 4 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP Mail Client

version=2.6.1
version=2.6.2

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
63 changes: 59 additions & 4 deletions src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1395,6 +1403,15 @@ class IMAPSession
template <typename T = const char *>
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 <typename T1 = const char *, typename T2 = const char *>
bool renameFolder(T1 currentFolderName, T2 newFolderName) { return mRenameFolder(toStringPtr(currentFolderName), toStringPtr(newFolderName)); }

/** Delete folder.
*
* @param folderName The name of folder to delete.
Expand All @@ -1403,6 +1420,32 @@ class IMAPSession
template <typename T = const char *>
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 <typename T1 = const char *, typename T2 = const char *>
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 <typename T = const char *>
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 <typename T = const char *>
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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#ifndef ESP_MAIL_VERSION

#define ESP_MAIL_VERSION "2.6.1"
#define ESP_MAIL_VERSION "2.6.2"

#endif
18 changes: 17 additions & 1 deletion src/ESP_Mail_Const.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Created October 1, 2022
// Created November 16, 2022

#pragma once

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 ";
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 5d291d2

Please sign in to comment.