summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Caliste <dcaliste@free.fr>2018-12-13 21:06:54 +0100
committerDamien Caliste <dcaliste@free.fr>2018-12-21 12:41:40 +0000
commitbbd0de450702558918b18558f481e8f1e1cf3879 (patch)
tree2f440c08c30bea8d867f6902891a4c35a89495a6
parent7eb16a2a3b907cbc6612e912401e3d1210d041a9 (diff)
Don't download twice part content in case of signed message with IMAP protocol
There is an issue with the current implementation that downloads twice the part content in case of subparts and signed mails. For instance a mail with this layout: 1: multipart/signed 1.1: text/plain 1.2: image/png 2: application/pgp-signature will trigger in mode RetrievalAction::Auto the following requests: 1-HEADER // as a signed part 1-BODY // as a signed part 1.1-BODY // as a text part 2-BODY // as a non attachment part which will result in text/plain part being downloaded twice and appended twice in a text file. To avoid this, this patch don't append to the list of requests any requests that are within a signed part. Change-Id: I654d020acf2a6a1fe26ae53ad667a84e7ea90c2e Reviewed-by: Matthew Vogt <matthew.vogt@qinetic.com.au>
-rw-r--r--src/libraries/qmfclient/qmailmessage.cpp4
-rw-r--r--src/libraries/qmfclient/qmailmessage.h1
-rw-r--r--src/plugins/messageservices/imap/imapstrategy.cpp38
-rw-r--r--src/plugins/messageservices/imap/imapstrategy.h1
4 files changed, 26 insertions, 18 deletions
diff --git a/src/libraries/qmfclient/qmailmessage.cpp b/src/libraries/qmfclient/qmailmessage.cpp
index 48b8b026..7c003ee9 100644
--- a/src/libraries/qmfclient/qmailmessage.cpp
+++ b/src/libraries/qmfclient/qmailmessage.cpp
@@ -5823,6 +5823,10 @@ bool QMailMessagePartContainer::Location::operator==(const QMailMessagePartConta
return toString(true) == other.toString(true);
}
+bool QMailMessagePartContainer::Location::operator!=(const QMailMessagePartContainer::Location &other) const
+{
+ return !(*this == other);
+}
/*!
Returns true if the location object contains the location of a valid message part.
diff --git a/src/libraries/qmfclient/qmailmessage.h b/src/libraries/qmfclient/qmailmessage.h
index 64e64b9c..46f6199b 100644
--- a/src/libraries/qmfclient/qmailmessage.h
+++ b/src/libraries/qmfclient/qmailmessage.h
@@ -298,6 +298,7 @@ public:
const QMailMessagePartContainer::Location &operator=(const QMailMessagePartContainer::Location &other);
bool operator==(const QMailMessagePartContainer::Location &other) const;
+ bool operator!=(const QMailMessagePartContainer::Location &other) const;
bool isValid(bool extended = true) const;
diff --git a/src/plugins/messageservices/imap/imapstrategy.cpp b/src/plugins/messageservices/imap/imapstrategy.cpp
index 86cc5379..916afdfd 100644
--- a/src/plugins/messageservices/imap/imapstrategy.cpp
+++ b/src/plugins/messageservices/imap/imapstrategy.cpp
@@ -1531,6 +1531,7 @@ void ImapFetchSelectedMessagesStrategy::clearSelection()
void ImapFetchSelectedMessagesStrategy::metaDataAnalysis(ImapStrategyContextBase *context,
const QMailMessagePartContainer &partContainer,
const QList<QMailMessagePartContainer::Location> &attachmentLocations,
+ const QMailMessagePartContainer::Location &signedPartLocation,
QList<QPair<QMailMessagePart::Location, uint> > &sectionList,
QList<QPair<QMailMessagePart::Location, int> > &completionSectionList,
QMailMessagePartContainer::Location &preferredBody,
@@ -1578,8 +1579,14 @@ void ImapFetchSelectedMessagesStrategy::metaDataAnalysis(ImapStrategyContextBase
const QMailMessagePart part(partContainer.partAt(i));
const QMailMessageContentDisposition disposition(part.contentDisposition());
- if (part.partCount() > 0) {
- metaDataAnalysis(context, part, attachmentLocations,
+ if (part.location() == signedPartLocation) {
+ completionSectionList.append(qMakePair(part.location(),
+ SectionProperties::HeadersOnly));
+ if (part.location() != preferredBody) {
+ sectionList.append(qMakePair(part.location(), 0));
+ }
+ } else if (part.partCount() > 0) {
+ metaDataAnalysis(context, part, attachmentLocations, signedPartLocation,
sectionList, completionSectionList,
preferredBody, bytesLeft);
} else if (part.partialContentAvailable()) {
@@ -1593,7 +1600,7 @@ void ImapFetchSelectedMessagesStrategy::metaDataAnalysis(ImapStrategyContextBase
} else {
// This is a regular part. Try to download it completely, if it is not the preferred body
// that is already added to the list.
- if (!(part.location() == preferredBody)) {
+ if (part.location() != preferredBody) {
sectionList.append(qMakePair(part.location(), (uint)disposition.size()));
}
}
@@ -1629,12 +1636,21 @@ void ImapFetchSelectedMessagesStrategy::prepareCompletionList(
location.setContainingMessageId(message.id());
completionSectionList.append(qMakePair(location, int(_headerLimit)));
} else {
+ QMailMessagePartContainer::Location signedPartLocation;
+ if (message.status() & QMailMessage::HasSignature) {
+ const QMailMessagePartContainer *signedContainer =
+ QMailCryptographicServiceFactory::findSignedContainer(&message);
+ if (signedContainer && signedContainer->partCount() > 0) {
+ signedPartLocation = signedContainer->partAt(0).location();
+ }
+ }
+
uint bytesLeft = _headerLimit;
int partsToRetrieve = 0;
const int maxParts = 100;
QList<QPair<QMailMessagePart::Location, uint> > sectionList;
QMailMessagePart::Location preferredBody;
- metaDataAnalysis(context, message, attachmentLocations,
+ metaDataAnalysis(context, message, attachmentLocations, signedPartLocation,
sectionList, completionSectionList,
preferredBody, bytesLeft);
@@ -1654,20 +1670,6 @@ void ImapFetchSelectedMessagesStrategy::prepareCompletionList(
}
++it;
}
-
- // Add headers retrieval if undecoded data are required.
- if (message.status() & QMailMessage::HasSignature) {
- const QMailMessagePartContainer *signedContainer =
- QMailCryptographicServiceFactory::findSignedContainer(&message);
- if (signedContainer) {
- const QMailMessagePart &part = signedContainer->partAt(0);
- completionSectionList.append(qMakePair(part.location(),
- SectionProperties::HeadersOnly));
- if (part.multipartType() != QMailMessagePartContainer::MultipartNone)
- completionSectionList.append(qMakePair(part.location(),
- SectionProperties::All));
- }
- }
}
}
}
diff --git a/src/plugins/messageservices/imap/imapstrategy.h b/src/plugins/messageservices/imap/imapstrategy.h
index d49e73db..1f418e44 100644
--- a/src/plugins/messageservices/imap/imapstrategy.h
+++ b/src/plugins/messageservices/imap/imapstrategy.h
@@ -349,6 +349,7 @@ protected:
virtual void metaDataAnalysis(ImapStrategyContextBase *context,
const QMailMessagePartContainer &partContainer,
const QList<QMailMessagePartContainer::Location> &attachmentLocations,
+ const QMailMessagePartContainer::Location &signedPartLocation,
QList<QPair<QMailMessagePart::Location, uint> > &sectionList,
QList<QPair<QMailMessagePart::Location, int> > &completionSectionList,
QMailMessagePart::Location &preferredBody,