Skip to content

Commit

Permalink
Fix iCloud IMAP response header paring issue #92 and add option for I…
Browse files Browse the repository at this point in the history
…MAP header parsing.
  • Loading branch information
mobizt committed Sep 12, 2021
1 parent a5e8ff0 commit 422c016
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 131 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mail Client Arduino Library v1.4.1
# Mail Client Arduino Library v1.4.2


[![Join the chat at https://gitter.im/mobizt/ESP_Mail_Client](https://badges.gitter.im/mobizt/ESP_Mail_Client.svg)](https://gitter.im/mobizt/ESP_Mail_Client?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down Expand Up @@ -148,7 +148,7 @@ The flash (upload) result shows in the command prompt window will look similar t
If the custom built WiFiNINA firmware was installed, the debug message will show the library version with WiFiNINA firmware version which followed by built number (+21060).

```
> C: ESP Mail Client v1.4.1, Fw v1.4.5+21060
> C: ESP Mail Client v1.4.2, Fw v1.4.5+21060
```

## Library Instalation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ void setup()
/* Set to report the download progress via the default serial port */
config.enable.download_status = true;

/* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud
, to allow case sensitive parse, uncomment below line*/
//config.enable.header_case_sesitive = true;

/* Set the limit of number of messages in the search results */
config.limit.search = 5;

Expand Down
4 changes: 4 additions & 0 deletions examples/IMAP/Read_Single_Email/Read_Single_Email.ino
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ void setup()
/* Set to report the download progress via the default serial port */
config.enable.download_status = true;

/* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud
, to allow case sensitive parse, uncomment below line*/
//config.enable.header_case_sesitive = true;

/* Set the limit of number of messages in the search results */
config.limit.search = 5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ void setup()
/* Set to report the download progress via the default serial port */
config.enable.download_status = true;

/* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud
, to allow case sensitive parse, uncomment below line*/
//config.enable.header_case_sesitive = true;

/* Set the limit of number of messages in the search results */
config.limit.search = 5;

Expand Down
4 changes: 4 additions & 0 deletions examples/IMAP/Search_Emails/Search_Emails.ino
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ void setup()
/* Set to report the download progress via the default serial port */
config.enable.download_status = true;

/* Header fields parsing is case insensitive by default to avoid uppercase header in some server e.g. iCloud
, to allow case sensitive parse, uncomment below line*/
//config.enable.header_case_sesitive = true;

/* Set the limit of number of messages in the search results */
config.limit.search = 5;

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": "1.4.1",
"version": "1.4.2",
"keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino",
"description": "E-Mail Client Arduino Library that supports Espressif ESP32, ESP8266 and SAMD21 devices with built-in U-blox NINA-W102 module. This allows embedded devices to send and read Email which various types of content and attacment are supported. The library also supports Ethernet connection (ESP8266 and ESP32) through secure (SSL) and non-secure ports.",
"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=1.4.1
version=1.4.2

author=Mobizt

Expand Down
251 changes: 137 additions & 114 deletions src/ESP_Mail_Client.cpp

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#ifndef ESP_Mail_Client_H
#define ESP_Mail_Client_H

#define ESP_MAIL_VERSION "1.4.1"
#define ESP_MAIL_VERSION "1.4.2"

/**
* Mail Client Arduino Library for Espressif's ESP32 and ESP8266 and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module
*
* Version: 1.4.1
* Released: September 11, 2021
* Version: 1.4.2
* Released: September 12, 2021
*
* Updates:
* - Fix ESP8266 Arduino Core SDK v2.7.4 and earlier compilation error #91.
* - Add comment to ESP8266 Ethernet example for supported ESP8266 Arduino Core SDK version.
* - Update ESP8266 Ethernet workaround.
* - Fix iCloud IMAP response header paring issue #92, which iCloud always returns uppercase header fields.
* - Add IMAP config option to enable case sensitive header parsing.
* - Update IMAP examples comment for header parse option.
*
*
* 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 @@ -50,6 +50,7 @@
#include "extras/RFC2047.h"
#include "extras/ESPTimeHelper/ESPTimeHelper.h"
#include <time.h>
#include <ctype.h>

#if defined(ESP32) || defined(ESP8266)

Expand Down Expand Up @@ -1118,6 +1119,9 @@ struct esp_mail_imap_enable_config_t

/* To sort the message UID of the search result in descending order */
bool recent_sort = false;

/* To allow case sesitive in header parsing */
bool header_case_sesitive = false;
};

struct esp_mail_imap_limit_config_t
Expand Down Expand Up @@ -2284,8 +2288,8 @@ class ESP_Mail_Client
char *newS(size_t len);
char *newS(char *p, size_t len);
char *newS(char *p, size_t len, char *d);
bool strcmpP(const char *buf, int ofs, PGM_P beginH);
int strposP(const char *buf, PGM_P beginH, int ofs);
bool strcmpP(const char *buf, int ofs, PGM_P beginH, bool caseSensitive = true);
int strposP(const char *buf, PGM_P beginH, int ofs, bool caseSensitive = true);
char *strP(PGM_P pgm);
void appendP(std::string &buf, PGM_P p, bool empty);
char *intStr(int value);
Expand Down Expand Up @@ -2351,14 +2355,14 @@ class ESP_Mail_Client
void imapCB(IMAPSession *imap, const char *info, bool success);
int readLine(WiFiClient *stream, char *buf, int bufLen, bool crlf, int &count);
int getMSGNUM(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, bool &endSearch, int &nump, const char *key, const char *pc);
void handleHeader(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, struct esp_mail_message_header_t &header, int &headerState, int &octetCount);
void handleHeader(IMAPSession *imap, char *buf, int bufLen, int &chunkIdx, struct esp_mail_message_header_t &header, int &headerState, int &octetCount, bool caseSensitive = true);
void setHeader(IMAPSession *imap, char *buf, struct esp_mail_message_header_t &header, int state);
void handlePartHeader(IMAPSession *imap, char *buf, int &chunkIdx, struct esp_mail_message_part_info_t &part);
char *subStr(const char *buf, PGM_P beginH, PGM_P endH, int beginPos, int endPos = 0);
void handlePartHeader(IMAPSession *imap, char *buf, int &chunkIdx, struct esp_mail_message_part_info_t &part, bool caseSensitive = true);
char *subStr(const char *buf, PGM_P beginH, PGM_P endH, int beginPos, int endPos = 0, bool caseSensitive = true);
struct esp_mail_message_part_info_t *cPart(IMAPSession *imap);
struct esp_mail_message_header_t *cHeader(IMAPSession *imap);
void strcat_c(char *str, char c);
int strpos(const char *haystack, const char *needle, int offset);
int strpos(const char *haystack, const char *needle, int offset, bool caseSensitive = true);
char *stristr(const char *str1, const char *str2);
char *rstrstr(const char *haystack, const char *needle);
int rstrpos(const char *haystack, const char *needle, int offset);
Expand Down
4 changes: 3 additions & 1 deletion src/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ESP Mail Client Arduino Library for ESP32, ESP8266, SAMD21


The detail and usage of the available functions in the latest version (1.4.1) are showed below.
The detail and usage of the available functions in the latest version (1.4.2) are showed below.


## Global functions
Expand Down Expand Up @@ -1283,6 +1283,8 @@ This property has the sub properties

##### [boolean] recent_sort - To sort the message UID of the search result in descending order.

##### [boolean] header_case_sesitive - To allow case sesitive in header parsing.

```C++
esp_mail_imap_enable_config_t enable;
```
Expand Down

0 comments on commit 422c016

Please sign in to comment.