Skip to content

Commit

Permalink
Fixed issue and add new feature for IMAP.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jun 13, 2022
1 parent 78aa94f commit 97fcddb
Show file tree
Hide file tree
Showing 24 changed files with 1,809 additions and 494 deletions.
7 changes: 7 additions & 0 deletions examples/IMAP/Read_Single_Email/Read_Single_Email.ino
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ void setup()
*/
config.fetch.uid = imap.getUID(imap.selectedFolder().msgCount());

// or fetch via the message sequence number
// config.fetch.number = imap.selectedFolder().msgCount();

// if both config.fetch.uid and config.fetch.number were set,
// then total 2 messages will be fetched i.e. one using uid and other using number.


/* Set seen flag */

// The message with "Seen" flagged means the message was already read or seen by user.
Expand Down
33 changes: 13 additions & 20 deletions examples/IMAP/Read_Single_Email_Loop/Read_Single_Email_Loop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -266,30 +266,23 @@ void loop()
sign = -1;
}

int uid = imap.getUID(msgNum);
/* Message number to fetch or read */
config.fetch.number = msgNum;

// UID must be greater than 0
if (uid > 0)
{

/* Message UID to fetch or read */
config.fetch.uid = uid;
/* Set seen flag */
// config.fetch.set_seen = true;

/* Set seen flag */
// config.fetch.set_seen = true;

/** Read or search the Email and keep the TCP session to open
* The second parameter is for close the session.
*/
/** Read or search the Email and keep the TCP session to open
* The second parameter is for close the session.
*/

// When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status,
// as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag
// to message, see the Set_Flags.ino example.
MailClient.readMail(&imap, false);
// When message was fetched or read, the /Seen flag will not set or message remained in unseen or unread status,
// as this is the purpose of library (not UI application), user can set the message status as read by set \Seen flag
// to message, see the Set_Flags.ino example.
MailClient.readMail(&imap, false);

/* Clear all stored data in IMAPSession object */
imap.empty();
}
/* Clear all stored data in IMAPSession object */
imap.empty();

msgNum += sign;
}
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.4.0",
"version": "2.4.1",
"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.4.0
version=2.4.1

author=Mobizt

Expand Down
51 changes: 49 additions & 2 deletions 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 June 7, 2022
* Created June 13, 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 @@ -356,8 +356,45 @@ MB_String ESP_Mail_Client::mGetBase64(MB_StringPtr str)
return encodeBase64Str((uint8_t *)(data.c_str()), data.length());
}

int ESP_Mail_Client::readLine(ESP_MAIL_TCP_CLIENT *client, char *buf, int bufLen, bool crlf, int &count)
{
int ret = -1;
char c = 0;
char _c = 0;
int idx = 0;
if (!client->connected())
return idx;
while (client->available() && idx < bufLen)
{
ret = client->read();
if (ret > -1)
{
c = (char)ret;
strcat_c(buf, c);
idx++;
count++;
if (_c == '\r' && c == '\n')
{
if (!crlf)
{
buf[idx - 2] = 0;
idx -= 2;
}
return idx;
}
_c = c;

if (idx >= bufLen - 1)
return idx;
}
if (!client->connected())
return idx;
}
return idx;
}

#if defined(ESP32_TCP_CLIENT) || defined(ESP8266_TCP_CLIENT)
void ESP_Mail_Client::setSecure(ESP_MAIL_TCP_CLIENT &client, ESP_Mail_Session *session, std::shared_ptr<const char> caCert)
void ESP_Mail_Client::setCACert(ESP_MAIL_TCP_CLIENT &client, ESP_Mail_Session *session, std::shared_ptr<const char> caCert)
{

client.setMBFS(mbfs);
Expand Down Expand Up @@ -493,6 +530,16 @@ bool ESP_Mail_Client::authFailed(char *buf, int bufLen, int &chunkIdx, int ofs)
return ret;
}

MB_String ESP_Mail_Client::getXOAUTH2String(const MB_String &email, const MB_String &accessToken)
{
MB_String raw = esp_mail_str_285;
raw += email;
raw += esp_mail_str_286;
raw += accessToken;
raw += esp_mail_str_287;
return encodeBase64Str((const unsigned char *)raw.c_str(), raw.length());
}

unsigned char *ESP_Mail_Client::decodeBase64(const unsigned char *src, size_t len, size_t *out_len)
{
unsigned char *out, *pos, block[4], tmp;
Expand Down
Loading

0 comments on commit 97fcddb

Please sign in to comment.