Skip to content

Commit

Permalink
[imap] Gracefully handle bodystructure where boundaries are reported …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Valério Valério committed Mar 13, 2015
1 parent 1378d06 commit 71c77ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 14 additions & 4 deletions qmf/src/libraries/qmfclient/qmailmessage.cpp
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion qmf/src/plugins/messageservices/imap/imapstructure.cpp
Expand Up @@ -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());
}
}
}
}
Expand Down

0 comments on commit 71c77ea

Please sign in to comment.