Skip to content

Commit f5aebf1

Browse files
committed
Handle empty IMAP parts from Outlook.com servers
Cherry-pick fix from upstream mailcore2 PR #1621. Outlook.com IMAP server sometimes omits message parts and returns them as zero-length when there is a vCalendar part in the message. Previously this would cause a MAILIMAP_ERROR_FETCH error, failing the entire fetch. This fix: 1. Adds mOutlookServer detection based on hostname 2. When fetching from Outlook and encountering a NULL/empty part, returns zero-length data instead of an error This allows messages with vCalendar attachments to be fetched successfully from Outlook.com accounts. Upstream: MailCore/mailcore2#1621
1 parent f67ccbb commit f5aebf1

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

Vendor/mailcore2/src/core/imap/MCIMAPSession.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ void IMAPSession::init()
401401
mRamblerRuServer = false;
402402
mHermesServer = false;
403403
mQipServer = false;
404+
mOutlookServer = false;
404405
mLastFetchedSequenceNumber = 0;
405406
mCurrentFolder = NULL;
406407
pthread_mutex_init(&mIdleLock, NULL);
@@ -733,6 +734,7 @@ void IMAPSession::connect(ErrorCode * pError)
733734
mRamblerRuServer = (mHostname->locationOfString(MCSTR(".rambler.ru")) != -1);
734735
mHermesServer = (mWelcomeString->locationOfString(MCSTR("Hermes")) != -1);
735736
mQipServer = (mWelcomeString->locationOfString(MCSTR("QIP IMAP server")) != -1);
737+
mOutlookServer = (mHostname->locationOfString(MCSTR(".outlook.com")) != -1);
736738
}
737739

738740
mState = STATE_CONNECTED;
@@ -2066,10 +2068,9 @@ void IMAPSession::expunge(String * folder, ErrorCode * pError)
20662068
* pError = ErrorNone;
20672069
}
20682070

2069-
static int
2070-
fetch_imap(mailimap * imap, bool identifier_is_uid, uint32_t identifier,
2071-
struct mailimap_fetch_type * fetch_type,
2072-
char ** result, size_t * result_len)
2071+
int IMAPSession::fetch_imap(mailimap * imap, bool identifier_is_uid, uint32_t identifier,
2072+
struct mailimap_fetch_type * fetch_type,
2073+
char ** result, size_t * result_len)
20732074
{
20742075
int r;
20752076
struct mailimap_msg_att * msg_att;
@@ -2126,13 +2127,21 @@ fetch_imap(mailimap * imap, bool identifier_is_uid, uint32_t identifier,
21262127
}
21272128

21282129
mailimap_fetch_list_free(fetch_result);
2129-
2130-
if (text == NULL)
2131-
return MAILIMAP_ERROR_FETCH;
2132-
2130+
2131+
if (text == NULL) {
2132+
if (mOutlookServer) {
2133+
// Outlook.com IMAP server omits some parts and returns them as
2134+
// zero-length when there is a vCalendar part in the message
2135+
text_length = 0;
2136+
}
2137+
else {
2138+
return MAILIMAP_ERROR_FETCH;
2139+
}
2140+
}
2141+
21332142
* result = text;
21342143
* result_len = text_length;
2135-
2144+
21362145
return MAILIMAP_NO_ERROR;
21372146
}
21382147

@@ -2803,8 +2812,8 @@ Array * IMAPSession::fetchMessagesByNumberWithExtraHeaders(String * folder, IMAP
28032812
return result;
28042813
}
28052814

2806-
static int fetch_rfc822(mailimap * session, bool identifier_is_uid,
2807-
uint32_t identifier, char ** result, size_t * result_len)
2815+
int IMAPSession::fetch_rfc822(mailimap * session, bool identifier_is_uid,
2816+
uint32_t identifier, char ** result, size_t * result_len)
28082817
{
28092818
struct mailimap_section * section;
28102819
struct mailimap_fetch_att * fetch_att;

Vendor/mailcore2/src/core/imap/MCIMAPSession.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ namespace mailcore {
277277
bool mRamblerRuServer;
278278
bool mHermesServer;
279279
bool mQipServer;
280-
280+
bool mOutlookServer;
281+
281282
unsigned int mLastFetchedSequenceNumber;
282283
String * mCurrentFolder;
283284
pthread_mutex_t mIdleLock;
@@ -326,6 +327,10 @@ namespace mailcore {
326327
bool wholePart, uint32_t offset, uint32_t length,
327328
Encoding encoding, IMAPProgressCallback * progressCallback, ErrorCode * pError);
328329
void storeLabels(String * folder, bool identifier_is_uid, IndexSet * identifiers, IMAPStoreFlagsRequestKind kind, Array * labels, ErrorCode * pError);
330+
int fetch_imap(struct mailimap * imap, bool identifier_is_uid, uint32_t identifier,
331+
struct mailimap_fetch_type * fetch_type, char ** result, size_t * result_len);
332+
int fetch_rfc822(struct mailimap * session, bool identifier_is_uid,
333+
uint32_t identifier, char ** result, size_t * result_len);
329334
};
330335

331336
}

0 commit comments

Comments
 (0)