Skip to content

Commit

Permalink
Fix IMAP multilines untagged response parsing issue #275.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jul 19, 2023
1 parent 1f72c36 commit 85276c1
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void setup()
#endif

Serial.print("Connecting to Wi-Fi");

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
unsigned long ms = millis();
#endif
Expand Down Expand Up @@ -379,7 +379,7 @@ void printSelectedMailboxInfo(SelectedFolderInfo sFolder)
ESP_MAIL_PRINTF("First Unseen Message Number: %d\n", sFolder.unseenIndex());
else
ESP_MAIL_PRINTF("Unseen Messages: No\n");

if (sFolder.modSeqSupported())
ESP_MAIL_PRINTF("Highest Modification Sequence: %d\n", sFolder.highestModSeq());
for (size_t i = 0; i < sFolder.flagCount(); i++)
Expand Down Expand Up @@ -427,14 +427,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
11 changes: 7 additions & 4 deletions examples/IMAP/External_Client/External_Client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ void printSelectedMailboxInfo(SelectedFolderInfo sFolder)
ESP_MAIL_PRINTF("First Unseen Message Number: %d\n", sFolder.unseenIndex());
else
ESP_MAIL_PRINTF("Unseen Messages: No\n");

if (sFolder.modSeqSupported())
ESP_MAIL_PRINTF("Highest Modification Sequence: %d\n", sFolder.highestModSeq());
for (size_t i = 0; i < sFolder.flagCount(); i++)
Expand Down Expand Up @@ -413,12 +413,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void setup()
#endif

Serial.print("Connecting to Wi-Fi");

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
unsigned long ms = millis();
#endif
Expand Down Expand Up @@ -344,7 +344,7 @@ void printSelectedMailboxInfo(SelectedFolderInfo sFolder)
ESP_MAIL_PRINTF("First Unseen Message Number: %d\n", sFolder.unseenIndex());
else
ESP_MAIL_PRINTF("Unseen Messages: No\n");

if (sFolder.modSeqSupported())
ESP_MAIL_PRINTF("Highest Modification Sequence: %d\n", sFolder.highestModSeq());
for (size_t i = 0; i < sFolder.flagCount(); i++)
Expand Down Expand Up @@ -392,14 +392,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void setup()
* in case of lost internet connection for re-listening the mailbox.
*/
config.network_connection_handler = connectWiFi;

// You can use TCP KeepAlive for more reliable of listen (idle) operation, please read this for detail.
// https://github.com/mobizt/ESP-Mail-Client#using-tcp-session-keepalive-in-esp8266-and-esp32
// You can use keepAlive in ESP8266 core version newer than v3.1.2.
Expand Down Expand Up @@ -334,7 +334,7 @@ void printSelectedMailboxInfo(SelectedFolderInfo sFolder)
ESP_MAIL_PRINTF("First Unseen Message Number: %d\n", sFolder.unseenIndex());
else
ESP_MAIL_PRINTF("Unseen Messages: No\n");

if (sFolder.modSeqSupported())
ESP_MAIL_PRINTF("Highest Modification Sequence: %d\n", sFolder.highestModSeq());
for (size_t i = 0; i < sFolder.flagCount(); i++)
Expand Down Expand Up @@ -375,14 +375,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
9 changes: 5 additions & 4 deletions examples/IMAP/Read_Sequence_Set/Read_Sequence_Set.ino
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);


// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
9 changes: 5 additions & 4 deletions examples/IMAP/Read_Single_Email/Read_Single_Email.ino
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);


// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
11 changes: 6 additions & 5 deletions examples/IMAP/Read_Single_Email_Loop/Read_Single_Email_Loop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void setup()
#endif

Serial.print("Connecting to Wi-Fi");

#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
unsigned long ms = millis();
#endif
Expand Down Expand Up @@ -440,7 +440,7 @@ void printSelectedMailboxInfo(SelectedFolderInfo sFolder)
ESP_MAIL_PRINTF("First Unseen Message Number: %d\n", sFolder.unseenIndex());
else
ESP_MAIL_PRINTF("Unseen Messages: No\n");

if (sFolder.modSeqSupported())
ESP_MAIL_PRINTF("Highest Modification Sequence: %d\n", sFolder.highestModSeq());
for (size_t i = 0; i < sFolder.flagCount(); i++)
Expand Down Expand Up @@ -487,14 +487,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
Serial.println("****************************");
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
12 changes: 8 additions & 4 deletions examples/IMAP/Search_And_Read/Search_And_Read.ino
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ void setup()
{
imap_data.search.criteria.clear();

// Mark this message as read
// Mark this message as read
MailClient.addFlag(&imap, msg_uid[i], F("\\Seen"), false /* Close session */, false /* Ignore response */);

// Now Fech message by UID stored in msg_uid
imap_data.fetch.uid = msg_uid[i];

MailClient.readMail(&imap, false /* keep session open for fetching message in opened mailbox later */);
}

Expand Down Expand Up @@ -276,11 +276,15 @@ void printMessageData()

ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
7 changes: 4 additions & 3 deletions examples/IMAP/Search_Emails/Search_Emails.ino
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)
ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
// Message UID
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,15 @@ void printMessages(MB_VECTOR<IMAP_MSG_Item> &msgItems, bool headerOnly)

ESP_MAIL_PRINTF("Number: %d\n", msg.msgNo);
ESP_MAIL_PRINTF("UID: %d\n", msg.UID);
ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);

// The attachment status in search may be true in case the "multipart/mixed"
// content type header was set with no real attachtment included.
ESP_MAIL_PRINTF("Attachment: %s\n", msg.hasAttachment ? "yes" : "no");

ESP_MAIL_PRINTF("Messsage-ID: %s\n", msg.ID);

if (strlen(msg.flags))
ESP_MAIL_PRINTF("Flags: %s\n", msg.flags);
if (strlen(msg.acceptLang))
ESP_MAIL_PRINTF("Accept Language: %s\n", msg.acceptLang);
if (strlen(msg.contentLang))
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": "3.2.0",
"version": "3.2.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=3.2.0
version=3.2.1

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 @@ -2,7 +2,7 @@
#define ESP_MAIL_CLIENT_CPP

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30200)
#if !VALID_VERSION_CHECK(30201)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESP_MAIL_CLIENT_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30200)
#if !VALID_VERSION_CHECK(30201)
#error "Mixed versions compilation."
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#ifndef ESP_MAIL_VERSION

#define ESP_MAIL_VERSION "3.2.0"
#define ESP_MAIL_VERSION_NUM 30200
#define ESP_MAIL_VERSION "3.2.1"
#define ESP_MAIL_VERSION_NUM 30201

/* The inconsistent file version checking to prevent mixed versions compilation. */
#define VALID_VERSION_CHECK(ver) (ver == ESP_MAIL_VERSION_NUM)
Expand Down
4 changes: 3 additions & 1 deletion src/ESP_Mail_Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ESP_MAIL_CONST_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30200)
#if !VALID_VERSION_CHECK(30201)
#error "Mixed versions compilation."
#endif

Expand Down Expand Up @@ -2540,6 +2540,8 @@ struct esp_mail_imap_response_data
long dataTime = millis();
int chunkBufSize = 512;
int chunkIdx = 0;
bool isUntaggedResponse = false;
bool untaggedRespCompleted = false;
bool completedResponse = false;
bool endSearch = false;
struct esp_mail_message_header_t header;
Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define ESP_MAIL_ERROR_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30200)
#if !VALID_VERSION_CHECK(30201)
#error "Mixed versions compilation."
#endif

Expand Down
Loading

0 comments on commit 85276c1

Please sign in to comment.