Commit 3ee82827 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

AutocryptHeadersJob: ensure reproducable order of Autocrypt-Gossip headers

Also solves random failing of messagecomposer-autocryptheadersjobtest
parent 07bc3977
Pipeline #75651 passed with stage
in 25 minutes and 5 seconds
Autocrypt-Gossip: addr=bob@autocrypt.example; keydata=
mDMEXEcE6RYJKwYBBAHaRw8BAQdAPPy13Q7Y8w2VPRkksrijrn9o8u59ra1c2CJiHFpbM2G0FWJ
vYkBhdXRvY3J5cHQuZXhhbXBsZYiWBBMWCAA+FiEE8FQeqC0xAKoa3zse4w5v3UWQH4IFAlxHBO
kCGwMFCQPCZwAFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQ4w5v3UWQH4IfwAEA3lujohz3N
j9afUnaGUXN7YboIzQsmpgGkN8thyb/slIBAKwdJyg1SurKqHnxy3Wl/DBzOrR12/pN7nScn0+x
4sgBuDgEXEcE6RIKKwYBBAGXVQEFAQEHQJSU7QErtJOYXsIagw2qwnVbt31ooVEx8Xcb476NCbF
jAwEIB4h4BBgWCAAgFiEE8FQeqC0xAKoa3zse4w5v3UWQH4IFAlxHBOkCGwwACgkQ4w5v3UWQH4
LlHQEAlwUBfUU8ORC0RAS/dzlZSEm7+ImY12Wv8QGUCx5zPbUA/3YH84ZOAQDbmV/C+R//0WVNb
Gfav9X5KYmiratYR7oL
Autocrypt-Gossip: addr=carol@autocrypt.example; keydata=
mDMEXEcE6RYJKwYBBAHaRw8BAQdAKiHXLyIgys0xGLa+vS+BLtUDydKd3A1E9DpSozOBdfa0F2N
hcm9sQGF1dG9jcnlwdC5leGFtcGxliJYEExYIAD4WIQSt8CGd+u2e0+MFQA8EcmYYsmQnEgUCXE
......@@ -16,6 +7,15 @@ Autocrypt-Gossip: addr=carol@autocrypt.example; keydata=
jF3YDAQgHiHgEGBYIACAWIQSt8CGd+u2e0+MFQA8EcmYYsmQnEgUCXEcE6QIbDAAKCRAEcmYYsm
QnEtI2AQDc+PCbtyj9BfNTtqxSD3JMTXlbHDDxuZ84+nXfEVuivQD9Hl5eunlZnm76voE9rgjPw
6h3ReWkUrgbT7fX4YsHdws=
Autocrypt-Gossip: addr=bob@autocrypt.example; keydata=
mDMEXEcE6RYJKwYBBAHaRw8BAQdAPPy13Q7Y8w2VPRkksrijrn9o8u59ra1c2CJiHFpbM2G0FWJ
vYkBhdXRvY3J5cHQuZXhhbXBsZYiWBBMWCAA+FiEE8FQeqC0xAKoa3zse4w5v3UWQH4IFAlxHBO
kCGwMFCQPCZwAFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQ4w5v3UWQH4IfwAEA3lujohz3N
j9afUnaGUXN7YboIzQsmpgGkN8thyb/slIBAKwdJyg1SurKqHnxy3Wl/DBzOrR12/pN7nScn0+x
4sgBuDgEXEcE6RIKKwYBBAGXVQEFAQEHQJSU7QErtJOYXsIagw2qwnVbt31ooVEx8Xcb476NCbF
jAwEIB4h4BBgWCAAgFiEE8FQeqC0xAKoa3zse4w5v3UWQH4IFAlxHBOkCGwwACgkQ4w5v3UWQH4
LlHQEAlwUBfUU8ORC0RAS/dzlZSEm7+ImY12Wv8QGUCx5zPbUA/3YH84ZOAQDbmV/C+R//0WVNb
Gfav9X5KYmiratYR7oL
Content-Type: text/plain
Hi Bob and Carol,
......
......@@ -23,6 +23,10 @@
#include <KMime/Content>
#include <KMime/Headers>
#include <QByteArray>
#include <map>
using namespace MessageComposer;
class MessageComposer::AutocryptHeadersJobPrivate : public ContentJobBasePrivate
......@@ -33,12 +37,24 @@ public:
{
}
~AutocryptHeadersJobPrivate()
{
// clean up in case of cancelled job
for (const auto &[key, header] : gossipHeaders) {
delete header;
}
gossipHeaders.clear();
}
void emitGpgError(const GpgME::Error &error);
void emitNotFoundError(const QByteArray &addr, const QByteArray &fingerprint);
void fillHeaderData(KMime::Headers::Generic *header, const QByteArray &addr, bool preferEncrypted, const QByteArray &keydata);
void finishOnLastSubJob();
KMime::Content *content = nullptr;
KMime::Message *skeletonMessage = nullptr;
// used to ensure consistent order based on key order, not random one by async subjobs delivering
std::map<QByteArray, KMime::Headers::Generic *> gossipHeaders;
bool preferEncrypted = false;
int subJobs = 0;
......@@ -50,6 +66,23 @@ public:
Q_DECLARE_PUBLIC(AutocryptHeadersJob)
};
void AutocryptHeadersJobPrivate::finishOnLastSubJob()
{
Q_Q(AutocryptHeadersJob);
if (subJobs > 0) {
return;
}
for (const auto &[key, header] : gossipHeaders) {
content->appendHeader(header);
}
gossipHeaders.clear();
resultContent = content;
q->emitResult();
};
void AutocryptHeadersJobPrivate::emitGpgError(const GpgME::Error &error)
{
Q_Q(AutocryptHeadersJob);
......@@ -198,10 +231,7 @@ void AutocryptHeadersJob::process()
d->skeletonMessage->setHeader(autocrypt);
d->skeletonMessage->assemble();
if (d->subJobs < 1) {
d->resultContent = d->content;
emitResult();
}
d->finishOnLastSubJob();
});
d->subJobs++;
job->start(QStringList(QString::fromLatin1(d->recipientKey.primaryFingerprint())));
......@@ -240,12 +270,9 @@ void AutocryptHeadersJob::process()
auto header = new KMime::Headers::Generic("Autocrypt-Gossip");
d->fillHeaderData(header, key.userID(0).email(), false, keydata);
d->content->appendHeader(header);
d->gossipHeaders.insert({QByteArray(key.primaryFingerprint()), header});
if (d->subJobs < 1) {
d->resultContent = d->content;
emitResult();
}
d->finishOnLastSubJob();
});
d->subJobs++;
......
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