Commit 71c77ea2 authored by Valério Valério's avatar Valério Valério

[imap] Gracefully handle bodystructure where boundaries are reported as NIL.

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.
parent 1378d062
......@@ -3948,8 +3948,13 @@ const QMailMessagePart& QMailMessagePartContainerPrivate::partAt(const QMailMess
const QList<QMailMessagePart>* partList = &_messageParts;
foreach (uint index, location.d->_indices) {
part = &(partList->at(index - 1));
partList = &(part->impl<const QMailMessagePartContainerPrivate>()->_messageParts);
if (index >= 0 && index <= partList->size()) {
part = &(partList->at(index - 1));
partList = &(part->impl<const QMailMessagePartContainerPrivate>()->_messageParts);
} else {
qMailLog(Messaging) << Q_FUNC_INFO << "Invalid index, container does not have a part at " << index;
Q_ASSERT(false);
}
}
Q_ASSERT(part);
......@@ -3962,8 +3967,13 @@ QMailMessagePart& QMailMessagePartContainerPrivate::partAt(const QMailMessagePar
QList<QMailMessagePart>* partList = &_messageParts;
foreach (uint index, location.d->_indices) {
part = &((*partList)[index - 1]);
partList = &(part->impl<QMailMessagePartContainerPrivate>()->_messageParts);
if (index >= 0 && index <= partList->size()) {
part = &((*partList)[index - 1]);
partList = &(part->impl<QMailMessagePartContainerPrivate>()->_messageParts);
} else {
qMailLog(Messaging) << Q_FUNC_INFO << "Invalid index, container does not have a part at " << index;
Q_ASSERT(false);
}
}
return *part;
......
......@@ -435,7 +435,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());
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment