From d676bc1e0e90d69d4c843460be5ad352e60d8a28 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Sun, 3 Jan 2016 04:51:34 +0100 Subject: Gracefully handle bodystructure where boundaries are reported as NIL. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some servers (e.g mail.ru) report boundaries as NIL for multipart messages. from my understanding of RFC2046 this is invalid, but we can gracefully handle those by setting them to empty. Avoids crash when requesting a partAt() for a message that does not exist, this happened due to NIL boundaries, but no need to crash in such cases. Change-Id: I676e444184ad1ca39f93bc8d18635f134a315d0a Done-with: Valério Valério Reviewed-by: Valerio Valerio --- src/libraries/qmfclient/qmailmessage.cpp | 18 ++++++++++++++---- src/plugins/messageservices/imap/imapstructure.cpp | 7 ++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/libraries/qmfclient/qmailmessage.cpp b/src/libraries/qmfclient/qmailmessage.cpp index c7c075b6..da8b74b7 100644 --- a/src/libraries/qmfclient/qmailmessage.cpp +++ b/src/libraries/qmfclient/qmailmessage.cpp @@ -3942,8 +3942,13 @@ const QMailMessagePart& QMailMessagePartContainerPrivate::partAt(const QMailMess const QList* partList = &_messageParts; foreach (uint index, location.d->_indices) { - part = &(partList->at(index - 1)); - partList = &(part->impl()->_messageParts); + if (index >= 0 && index <= partList->size()) { + part = &(partList->at(index - 1)); + partList = &(part->impl()->_messageParts); + } else { + qMailLog(Messaging) << Q_FUNC_INFO << "Invalid index, container does not have a part at " << index; + Q_ASSERT(false); + } } Q_ASSERT(part); @@ -3956,8 +3961,13 @@ QMailMessagePart& QMailMessagePartContainerPrivate::partAt(const QMailMessagePar QList* partList = &_messageParts; foreach (uint index, location.d->_indices) { - part = &((*partList)[index - 1]); - partList = &(part->impl()->_messageParts); + if (index >= 0 && index <= partList->size()) { + part = &((*partList)[index - 1]); + partList = &(part->impl()->_messageParts); + } else { + qMailLog(Messaging) << Q_FUNC_INFO << "Invalid index, container does not have a part at " << index; + Q_ASSERT(false); + } } return *part; diff --git a/src/plugins/messageservices/imap/imapstructure.cpp b/src/plugins/messageservices/imap/imapstructure.cpp index a634d9ef..a962d089 100644 --- a/src/plugins/messageservices/imap/imapstructure.cpp +++ b/src/plugins/messageservices/imap/imapstructure.cpp @@ -427,7 +427,12 @@ void setMultipartFromDescription(const QStringList &structure, QMailMessagePartC } for ( ; (it != end) && ((it + 1) != end); it += 2) { if ((*it).trimmed().toUpper() == "BOUNDARY") { - container->setBoundary((*(it + 1)).toLatin1()); + const QString boundary((*(it + 1))); + if (boundary.toUpper() == "NIL") { + container->setBoundary(QByteArray()); + } else { + container->setBoundary(boundary.toLatin1()); + } } } } -- cgit v1.2.3