Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
PIM Messagelib
Commits
f3b280b6
Commit
f3b280b6
authored
Jan 28, 2021
by
Sandro Knauß
🐝
Browse files
run clang-format
parent
1d7e8331
Changes
35
Expand all
Hide whitespace changes
Inline
Side-by-side
messagecomposer/autotests/autocryptheadersjobtest.cpp
View file @
f3b280b6
...
...
@@ -6,32 +6,32 @@
#include
"autocryptheadersjobtest.h"
#include
"qtest_messagecomposer.h"
#include
"cryptofunctions.h"
#include
"qtest_messagecomposer.h"
#include
"setupenv.h"
#include
<KMime/Content>
#include
<Libkleo/Enum>
#include
<MessageComposer/Composer>
#include
<MessageComposer/AutocryptHeadersJob>
#include
<MessageComposer/Composer>
#include
<MessageComposer/Util>
#include
<QGpgME/Protocol>
#include
<QGpgME/KeyListJob>
#include
<QGpgME/Protocol>
#include
<gpgme++/verificationresult.h>
#include
<gpgme++/decryptionresult.h>
#include
<gpgme++/verificationresult.h>
#include
<stdlib.h>
#include
<KCharsets>
#include
<stdlib.h>
#include
<MessageComposer/TransparentJob>
#include
<QDebug>
#include
<QTest>
#include
<keylistresult.h>
#include
<MessageComposer/TransparentJob>
#include
<decryptionresult.h>
#include
<keylistresult.h>
QTEST_MAIN
(
AutocryptHeadersJobTest
)
...
...
@@ -58,7 +58,7 @@ void AutocryptHeadersJobTest::testAutocryptHeader()
content
.
setBody
(
"This is an example e-mail with Autocrypt header and Ed25519+Cv25519 key (key
\n
fingerprint: ) as defined in Level 1 revision 1.1.
\n
"
);
auto
job
=
QGpgME
::
openpgp
()
->
keyListJob
(
false
);
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
auto
res
=
job
->
exec
(
QStringList
(
QString
::
fromLatin1
(
skeletonMessage
.
from
()[
0
].
addresses
()[
0
])),
false
,
ownKeys
);
auto
aJob
=
new
AutocryptHeadersJob
(
&
composer
);
...
...
@@ -100,7 +100,7 @@ void AutocryptHeadersJobTest::testContentChained()
content
.
setBody
(
"This is an example e-mail with Autocrypt header and Ed25519+Cv25519 key (key
\n
fingerprint: ) as defined in Level 1 revision 1.1.
\n
"
);
auto
job
=
QGpgME
::
openpgp
()
->
keyListJob
(
false
);
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
auto
res
=
job
->
exec
(
QStringList
(
QString
::
fromLatin1
(
skeletonMessage
.
from
()[
0
].
addresses
()[
0
])),
false
,
ownKeys
);
auto
aJob
=
new
AutocryptHeadersJob
(
&
composer
);
...
...
@@ -136,17 +136,18 @@ void AutocryptHeadersJobTest::testAutocryptGossipHeader()
skeletonMessage
.
from
(
true
)
->
from7BitString
(
"Alice <alice@autocrypt.example>"
);
KMime
::
Content
content
;
content
.
setBody
(
"Hi Bob and Carol,
\n
"
"
\n
"
"I wanted to introduce the two of you to each other.
\n
"
"
\n
"
"I hope you are both doing well! You can now both
\"
reply all
\"
here,
\n
"
"and the thread will remain encrypted.
\n
"
);
content
.
setBody
(
"Hi Bob and Carol,
\n
"
"
\n
"
"I wanted to introduce the two of you to each other.
\n
"
"
\n
"
"I hope you are both doing well! You can now both
\"
reply all
\"
here,
\n
"
"and the thread will remain encrypted.
\n
"
);
auto
job
=
QGpgME
::
openpgp
()
->
keyListJob
(
false
);
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
job
->
exec
(
QStringList
(
QString
::
fromLatin1
(
skeletonMessage
.
from
()[
0
].
addresses
()[
0
])),
false
,
ownKeys
);
std
::
vector
<
GpgME
::
Key
>
keys
;
std
::
vector
<
GpgME
::
Key
>
keys
;
job
->
exec
(
QStringList
({
QStringLiteral
(
"bob@autocrypt.example"
),
QStringLiteral
(
"carol@autocrypt.example"
)}),
false
,
keys
);
auto
aJob
=
new
AutocryptHeadersJob
(
&
composer
);
...
...
@@ -175,21 +176,22 @@ void AutocryptHeadersJobTest::testSetGnupgHome()
skeletonMessage
.
from
(
true
)
->
from7BitString
(
"Alice <alice@autocrypt.example>"
);
KMime
::
Content
content
;
content
.
setBody
(
"Hi Bob and Carol,
\n
"
"
\n
"
"I wanted to introduce the two of you to each other.
\n
"
"
\n
"
"I hope you are both doing well! You can now both
\"
reply all
\"
here,
\n
"
"and the thread will remain encrypted.
\n
"
);
content
.
setBody
(
"Hi Bob and Carol,
\n
"
"
\n
"
"I wanted to introduce the two of you to each other.
\n
"
"
\n
"
"I hope you are both doing well! You can now both
\"
reply all
\"
here,
\n
"
"and the thread will remain encrypted.
\n
"
);
auto
exportJob
=
QGpgME
::
openpgp
()
->
keyListJob
(
false
);
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
exportJob
->
exec
(
QStringList
(
QString
::
fromLatin1
(
skeletonMessage
.
from
()[
0
].
addresses
()[
0
])),
false
,
ownKeys
);
std
::
vector
<
GpgME
::
Key
>
keys
;
std
::
vector
<
GpgME
::
Key
>
keys
;
exportJob
->
exec
(
QStringList
({
QStringLiteral
(
"bob@autocrypt.example"
),
QStringLiteral
(
"carol@autocrypt.example"
)}),
false
,
keys
);
QTemporaryDir
dir
;
{
// test with an empty gnupg Home
{
// test with an empty gnupg Home
auto
aJob
=
new
AutocryptHeadersJob
(
&
composer
);
QVERIFY
(
aJob
);
...
...
@@ -204,7 +206,7 @@ void AutocryptHeadersJobTest::testSetGnupgHome()
// Populate Keyring with needed keys.
Test
::
populateKeyring
(
dir
.
path
(),
ownKeys
[
0
]);
for
(
const
auto
key
:
keys
)
{
for
(
const
auto
key
:
keys
)
{
Test
::
populateKeyring
(
dir
.
path
(),
key
);
}
auto
aJob
=
new
AutocryptHeadersJob
(
&
composer
);
...
...
@@ -234,17 +236,18 @@ void AutocryptHeadersJobTest::testStripSenderKey()
skeletonMessage
.
from
(
true
)
->
from7BitString
(
"Alice <alice@autocrypt.example>"
);
KMime
::
Content
content
;
content
.
setBody
(
"Hi Bob and Carol,
\n
"
"
\n
"
"I wanted to introduce the two of you to each other.
\n
"
"
\n
"
"I hope you are both doing well! You can now both
\"
reply all
\"
here,
\n
"
"and the thread will remain encrypted.
\n
"
);
content
.
setBody
(
"Hi Bob and Carol,
\n
"
"
\n
"
"I wanted to introduce the two of you to each other.
\n
"
"
\n
"
"I hope you are both doing well! You can now both
\"
reply all
\"
here,
\n
"
"and the thread will remain encrypted.
\n
"
);
auto
job
=
QGpgME
::
openpgp
()
->
keyListJob
(
false
);
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
std
::
vector
<
GpgME
::
Key
>
ownKeys
;
job
->
exec
(
QStringList
(
QString
::
fromLatin1
(
skeletonMessage
.
from
()[
0
].
addresses
()[
0
])),
false
,
ownKeys
);
std
::
vector
<
GpgME
::
Key
>
keys
;
std
::
vector
<
GpgME
::
Key
>
keys
;
job
->
exec
(
QStringList
({
QStringLiteral
(
"bob@autocrypt.example"
),
QStringLiteral
(
"carol@autocrypt.example"
)}),
false
,
keys
);
keys
.
push_back
(
ownKeys
[
0
]);
...
...
@@ -263,5 +266,5 @@ void AutocryptHeadersJobTest::testStripSenderKey()
content
.
assemble
();
auto
referenceFile
=
QStringLiteral
(
"autocryptgossipheader.mbox"
);
Test
::
compareFile
(
&
content
,
QStringLiteral
(
MAIL_DATA_DIR
"/"
)
+
referenceFile
);
Test
::
compareFile
(
&
content
,
QStringLiteral
(
MAIL_DATA_DIR
"/"
)
+
referenceFile
);
}
messagecomposer/autotests/autocryptheadersjobtest.h
View file @
f3b280b6
...
...
@@ -9,7 +9,8 @@
#include
<QObject>
namespace
MessageComposer
{
namespace
MessageComposer
{
class
AutocryptHeadersJob
;
}
...
...
messagecomposer/autotests/cryptocomposertest.cpp
View file @
f3b280b6
...
...
@@ -629,8 +629,8 @@ void CryptoComposerTest::testSetGnupgHome()
QCOMPARE
(
composer
.
exec
(),
false
);
}
const
std
::
vector
<
GpgME
::
Key
>
&
keys
=
Test
::
getKeys
();
for
(
const
auto
key
:
keys
)
{
const
std
::
vector
<
GpgME
::
Key
>
&
keys
=
Test
::
getKeys
();
for
(
const
auto
key
:
keys
)
{
Test
::
populateKeyring
(
dir
.
path
(),
key
);
}
...
...
@@ -695,7 +695,7 @@ void CryptoComposerTest::testAutocryptHeaders()
QCOMPARE
(
composer
.
exec
(),
false
);
}
for
(
const
auto
key
:
keys
)
{
for
(
const
auto
key
:
keys
)
{
Test
::
populateKeyring
(
dir
.
path
(),
key
);
}
...
...
@@ -722,7 +722,9 @@ void CryptoComposerTest::testAutocryptHeaders()
}
QVERIFY
(
message
->
headerByType
(
"autocrypt"
));
QVERIFY
(
message
->
headerByType
(
"Autocrypt"
)
->
asUnicodeString
().
startsWith
(
QStringLiteral
(
"addr=me@me.me; keydata= mQENBEr9ij4BCADaFvyhzV7IrCAr/sCvfoPerAd4dYIGTeCeBmInu3p4oEG0rXTB2zL2t9zd7jV"
)));
QVERIFY
(
message
->
headerByType
(
"Autocrypt"
)
->
asUnicodeString
()
.
startsWith
(
QStringLiteral
(
"addr=me@me.me; keydata= mQENBEr9ij4BCADaFvyhzV7IrCAr/sCvfoPerAd4dYIGTeCeBmInu3p4oEG0rXTB2zL2t9zd7jV"
)));
QVERIFY
(
!
message
->
headerByType
(
"autocrypt-gossip"
));
QCOMPARE
(
message
->
from
()
->
asUnicodeString
(),
QString
::
fromLocal8Bit
(
"me@me.me"
));
QCOMPARE
(
message
->
to
()
->
asUnicodeString
(),
QString
::
fromLocal8Bit
(
"you@you.you"
));
...
...
@@ -735,7 +737,6 @@ void CryptoComposerTest::testAutocryptGossip_data()
QTest
::
addColumn
<
bool
>
(
"sign"
);
QTest
::
addColumn
<
QStringList
>
(
"recipients"
);
QString
data
(
QStringLiteral
(
"All happy families are alike; each unhappy family is unhappy in its own way."
));
QStringList
recipients
({
QStringLiteral
(
"you@you.you"
)});
...
...
@@ -797,7 +798,6 @@ void CryptoComposerTest::testAutocryptGossip()
if
(
sign
||
encrypt
)
{
ComposerTestUtil
::
verify
(
sign
,
encrypt
,
message
.
data
(),
data
.
toUtf8
(),
Kleo
::
OpenPGPMIMEFormat
,
Headers
::
CE7Bit
);
}
MimeTreeParser
::
SimpleObjectTreeSource
testSource
;
...
...
@@ -811,14 +811,16 @@ void CryptoComposerTest::testAutocryptGossip()
QCOMPARE
(
nh
.
headers
(
"autocrypt-gossip"
,
message
.
data
()).
size
(),
2
);
auto
headers
=
QStringList
();
for
(
const
auto
header
:
nh
.
headers
(
"autocrypt-gossip"
,
message
.
data
()))
{
for
(
const
auto
header
:
nh
.
headers
(
"autocrypt-gossip"
,
message
.
data
()))
{
headers
.
append
(
header
->
asUnicodeString
());
}
headers
.
sort
();
QVERIFY
(
headers
[
0
].
startsWith
(
QStringLiteral
(
"addr=leo@kdab.com; keydata= mQINBEr4pSwBEADG/B1VaoxT7mnQfwekkY+f8wkqFVLvTwN0W59Ze/pxmuRf/iS0tZjsEiPK0za"
)));
QVERIFY
(
headers
[
1
].
startsWith
(
QStringLiteral
(
"addr=you@you.com; keydata= mI0ESw2YuAEEALakcld4goNkwIL5gMETM3R+zI+AoJcuQWUpvS7AqwyR9/UAkVd3D+r32CgWhFi"
)));
QVERIFY
(
headers
[
0
].
startsWith
(
QStringLiteral
(
"addr=leo@kdab.com; keydata= mQINBEr4pSwBEADG/B1VaoxT7mnQfwekkY+f8wkqFVLvTwN0W59Ze/pxmuRf/iS0tZjsEiPK0za"
)));
QVERIFY
(
headers
[
1
].
startsWith
(
QStringLiteral
(
"addr=you@you.com; keydata= mI0ESw2YuAEEALakcld4goNkwIL5gMETM3R+zI+AoJcuQWUpvS7AqwyR9/UAkVd3D+r32CgWhFi"
)));
}
else
{
QCOMPARE
(
nh
.
headers
(
"autocrypt-gossip"
,
message
.
data
()).
size
(),
0
);
}
...
...
@@ -826,7 +828,6 @@ void CryptoComposerTest::testAutocryptGossip()
QCOMPARE
(
message
->
to
()
->
asUnicodeString
(),
recipients
.
join
(
QStringLiteral
(
", "
)));
}
// Helper methods
void
CryptoComposerTest
::
fillComposerData
(
Composer
*
composer
,
const
QString
&
data
)
{
...
...
messagecomposer/autotests/encryptjobtest.cpp
View file @
f3b280b6
...
...
@@ -258,7 +258,7 @@ void EncryptJobTest::testSetGnupgHome()
KMime
::
Content
content
;
content
.
setBody
(
"one flew over the cuckoo's nest"
);
const
std
::
vector
<
GpgME
::
Key
>
&
keys
=
Test
::
getKeys
();
const
std
::
vector
<
GpgME
::
Key
>
&
keys
=
Test
::
getKeys
();
const
QStringList
recipients
=
{
QStringLiteral
(
"test@kolab.org"
)};
...
...
@@ -275,7 +275,7 @@ void EncryptJobTest::testSetGnupgHome()
QCOMPARE
(
eJob
->
exec
(),
false
);
}
for
(
const
auto
key
:
keys
)
{
for
(
const
auto
key
:
keys
)
{
Test
::
populateKeyring
(
dir
.
path
(),
key
);
}
auto
eJob
=
new
EncryptJob
(
&
composer
);
...
...
messagecomposer/autotests/keyresolvertest.h
View file @
f3b280b6
...
...
@@ -7,8 +7,8 @@
#ifndef KEYRESOLVERTEST_H
#define KEYRESOLVERTEST_H
#include
<QObject>
#include
<QDir>
#include
<QObject>
class
KeyResolverTest
:
public
QObject
{
...
...
@@ -20,6 +20,7 @@ private Q_SLOTS:
void
cleanup
();
void
testAutocrypt
();
private:
QDir
baseDir
;
};
...
...
messagecomposer/autotests/setupenv.cpp
View file @
f3b280b6
...
...
@@ -83,7 +83,7 @@ KMime::Message::Ptr Test::loadMessageFromFile(const QString &filename)
return
msg
;
}
void
Test
::
compareFile
(
KMime
::
Content
*
content
,
const
QString
&
referenceFile
)
void
Test
::
compareFile
(
KMime
::
Content
*
content
,
const
QString
&
referenceFile
)
{
QFileInfo
fi
(
referenceFile
);
const
QString
actualFile
=
fi
.
fileName
();
...
...
@@ -112,24 +112,27 @@ void Test::compareFile(const QString &outFile, const QString &referenceFile)
QCOMPARE
(
proc
.
exitCode
(),
0
);
}
void
Test
::
populateKeyring
(
const
QString
&
gnupgHome
,
const
GpgME
::
Key
&
key
)
void
Test
::
populateKeyring
(
const
QString
&
gnupgHome
,
const
GpgME
::
Key
&
key
)
{
QEventLoop
loop
;
const
QGpgME
::
Protocol
*
proto
(
QGpgME
::
openpgp
());
auto
exportJob
=
proto
->
publicKeyExportJob
(
false
);
QObject
::
connect
(
exportJob
,
&
QGpgME
::
ExportJob
::
result
,
[
&
gnupgHome
,
&
loop
](
const
GpgME
::
Error
&
result
,
const
QByteArray
&
keyData
,
const
QString
&
auditLogAsHtml
,
const
GpgME
::
Error
&
auditLogError
){
Q_UNUSED
(
auditLogAsHtml
);
Q_UNUSED
(
auditLogError
);
loop
.
quit
();
QVERIFY
(
!
result
);
populateKeyring
(
gnupgHome
,
keyData
);
});
QObject
::
connect
(
exportJob
,
&
QGpgME
::
ExportJob
::
result
,
[
&
gnupgHome
,
&
loop
](
const
GpgME
::
Error
&
result
,
const
QByteArray
&
keyData
,
const
QString
&
auditLogAsHtml
,
const
GpgME
::
Error
&
auditLogError
)
{
Q_UNUSED
(
auditLogAsHtml
);
Q_UNUSED
(
auditLogError
);
loop
.
quit
();
QVERIFY
(
!
result
);
populateKeyring
(
gnupgHome
,
keyData
);
});
QStringList
patterns
=
{
QString
::
fromUtf8
(
key
.
primaryFingerprint
())};
exportJob
->
start
(
patterns
);
loop
.
exec
();
}
void
Test
::
populateKeyring
(
const
QString
&
gnupgHome
,
const
QByteArray
&
keydata
)
void
Test
::
populateKeyring
(
const
QString
&
gnupgHome
,
const
QByteArray
&
keydata
)
{
const
QGpgME
::
Protocol
*
proto
(
QGpgME
::
openpgp
());
auto
importJob
=
proto
->
importJob
();
...
...
messagecomposer/autotests/setupenv.h
View file @
f3b280b6
...
...
@@ -49,12 +49,12 @@ void compareFile(const QString &outFile, const QString &referenceFile);
/**
* Adds keydata into keyring insinde gnupgHome.
*/
void
populateKeyring
(
const
QString
&
gnupgHome
,
const
QByteArray
&
keydata
);
void
populateKeyring
(
const
QString
&
gnupgHome
,
const
QByteArray
&
keydata
);
/**
* Adds keydata into keyring insinde gnupgHome.
*/
void
populateKeyring
(
const
QString
&
gnupgHome
,
const
GpgME
::
Key
&
key
);
void
populateKeyring
(
const
QString
&
gnupgHome
,
const
GpgME
::
Key
&
key
);
}
}
...
...
messagecomposer/autotests/signjobtest.cpp
View file @
f3b280b6
...
...
@@ -295,5 +295,4 @@ void SignJobTest::testProtectedHeadersOverwrite()
result
->
assemble
();
Test
::
compareFile
(
result
->
contents
().
at
(
0
),
QStringLiteral
(
MAIL_DATA_DIR
"/"
)
+
referenceFile
);
}
messagecomposer/src/composer/composer.cpp
View file @
f3b280b6
...
...
@@ -11,9 +11,9 @@
#include
"imagescaling/imagescaling.h"
#include
"imagescaling/imagescalingutils.h"
#include
"job/attachmentjob.h"
#include
"job/autocryptheadersjob.h"
#include
"job/encryptjob.h"
#include
"job/jobbase_p.h"
#include
"job/autocryptheadersjob.h"
#include
"job/maintextjob.h"
#include
"job/multipartjob.h"
#include
"job/signencryptjob.h"
...
...
@@ -215,7 +215,7 @@ void ComposerPrivate::composeStep2()
mainJob
=
multipartJob
;
}
if
(
autocryptEnabled
)
{
if
(
autocryptEnabled
)
{
auto
autocryptJob
=
new
AutocryptHeadersJob
();
autocryptJob
->
setSkeletonMessage
(
skeletonMessage
);
autocryptJob
->
setGnupgHome
(
gnupgHome
);
...
...
messagecomposer/src/composer/composer.h
View file @
f3b280b6
...
...
@@ -62,7 +62,6 @@ public:
void
setGnupgHome
(
const
QString
&
path
);
Q_REQUIRED_RESULT
QString
gnupgHome
()
const
;
/// Sets if this message being composed is an auto-saved message
/// if so, might need different handling, such as no crypto attachments.
void
setAutoSave
(
bool
isAutoSave
);
...
...
messagecomposer/src/composer/composerviewbase.cpp
View file @
f3b280b6
...
...
@@ -606,12 +606,14 @@ inline bool showKeyApprovalDialog()
}
}
// nameless namespace
bool
ComposerViewBase
::
addKeysToContext
(
const
QString
&
gnupgHome
,
const
QVector
<
QPair
<
QStringList
,
std
::
vector
<
GpgME
::
Key
>
>
>
&
data
,
const
std
::
map
<
QByteArray
,
QString
>
&
autocryptMap
)
bool
ComposerViewBase
::
addKeysToContext
(
const
QString
&
gnupgHome
,
const
QVector
<
QPair
<
QStringList
,
std
::
vector
<
GpgME
::
Key
>>>
&
data
,
const
std
::
map
<
QByteArray
,
QString
>
&
autocryptMap
)
{
bool
needSpecialContext
=
false
;
for
(
const
auto
&
p
:
data
)
{
for
(
const
auto
k
:
p
.
second
)
{
for
(
const
auto
&
p
:
data
)
{
for
(
const
auto
k
:
p
.
second
)
{
const
auto
it
=
autocryptMap
.
find
(
k
.
primaryFingerprint
());
if
(
it
!=
autocryptMap
.
end
())
{
needSpecialContext
=
true
;
...
...
@@ -633,31 +635,36 @@ bool ComposerViewBase::addKeysToContext(const QString &gnupgHome, const QVector<
const
auto
storage
=
MessageCore
::
AutocryptStorage
::
self
();
QEventLoop
loop
;
int
runningJobs
=
0
;
for
(
const
auto
&
p
:
data
)
{
for
(
const
auto
k
:
p
.
second
)
{
for
(
const
auto
&
p
:
data
)
{
for
(
const
auto
k
:
p
.
second
)
{
const
auto
it
=
autocryptMap
.
find
(
k
.
primaryFingerprint
());
if
(
it
==
autocryptMap
.
end
())
{
qDebug
()
<<
"Adding "
<<
k
.
primaryFingerprint
()
<<
"via Export/Import"
;
auto
exportJob
=
proto
->
publicKeyExportJob
(
false
);
connect
(
exportJob
,
&
QGpgME
::
ExportJob
::
result
,
[
&
gnupgHome
,
&
proto
,
&
runningJobs
,
&
loop
,
&
k
](
const
GpgME
::
Error
&
result
,
const
QByteArray
&
keyData
,
const
QString
&
auditLogAsHtml
,
const
GpgME
::
Error
&
auditLogError
){
Q_UNUSED
(
auditLogAsHtml
);
Q_UNUSED
(
auditLogError
);
if
(
result
)
{
qCWarning
(
MESSAGECOMPOSER_LOG
)
<<
"Failed to export "
<<
k
.
primaryFingerprint
()
<<
result
.
asString
();
connect
(
exportJob
,
&
QGpgME
::
ExportJob
::
result
,
[
&
gnupgHome
,
&
proto
,
&
runningJobs
,
&
loop
,
&
k
](
const
GpgME
::
Error
&
result
,
const
QByteArray
&
keyData
,
const
QString
&
auditLogAsHtml
,
const
GpgME
::
Error
&
auditLogError
)
{
Q_UNUSED
(
auditLogAsHtml
);
Q_UNUSED
(
auditLogError
);
if
(
result
)
{
qCWarning
(
MESSAGECOMPOSER_LOG
)
<<
"Failed to export "
<<
k
.
primaryFingerprint
()
<<
result
.
asString
();
--
runningJobs
;
if
(
runningJobs
<
1
)
{
loop
.
quit
();
}
}
auto
importJob
=
proto
->
importJob
();
QGpgME
::
Job
::
context
(
importJob
)
->
setEngineHomeDirectory
(
gnupgHome
.
toUtf8
().
constData
());
importJob
->
exec
(
keyData
);
importJob
->
deleteLater
();
--
runningJobs
;
if
(
runningJobs
<
1
)
{
loop
.
quit
();
}
}
auto
importJob
=
proto
->
importJob
();
QGpgME
::
Job
::
context
(
importJob
)
->
setEngineHomeDirectory
(
gnupgHome
.
toUtf8
().
constData
());
importJob
->
exec
(
keyData
);
importJob
->
deleteLater
();
--
runningJobs
;
if
(
runningJobs
<
1
)
{
loop
.
quit
();
}
});
QStringList
patterns
;
patterns
<<
QString
::
fromUtf8
(
k
.
primaryFingerprint
());
...
...
messagecomposer/src/composer/composerviewbase.h
View file @
f3b280b6
...
...
@@ -321,10 +321,9 @@ private:
void
addSendLaterItem
(
const
Akonadi
::
Item
&
item
);
void
addCustomHeaders
(
const
KMime
::
Message
::
Ptr
&
message
);
bool
addKeysToContext
(
const
QString
&
gnupgHome
,
const
QVector
<
QPair
<
QStringList
,
std
::
vector
<
GpgME
::
Key
>
>
>
&
data
,
const
std
::
map
<
QByteArray
,
QString
>
&
autocryptMap
);
const
QVector
<
QPair
<
QStringList
,
std
::
vector
<
GpgME
::
Key
>
>
>
&
data
,
const
std
::
map
<
QByteArray
,
QString
>
&
autocryptMap
);
KMime
::
Message
::
Ptr
m_msg
;
MessageComposer
::
AttachmentControllerBase
*
m_attachmentController
=
nullptr
;
...
...
messagecomposer/src/composer/keyresolver.cpp
View file @
f3b280b6
...
...
@@ -1765,7 +1765,6 @@ std::vector<GpgME::Key> Kleo::KeyResolver::getEncryptionKeys(const QString &pers
if
(
!
gossipKey
.
isNull
()
&&
ValidEncryptionKey
(
gossipKey
))
{
qCDebug
(
MESSAGECOMPOSER_LOG
)
<<
"Found an valid autocrypt gossip key."
;
matchingKeys
.
push_back
(
gossipKey
);
}
}
}
...
...
messagecomposer/src/composer/keyresolver.h
View file @
f3b280b6
...
...
@@ -230,7 +230,7 @@ public:
std
::
vector
<
GpgME
::
Key
>
encryptToSelfKeysFor
(
CryptoMessageFormat
f
)
const
;
/** If Autocrypt keys are used to find valid PGP Keys
*/
*/
void
setAutocryptEnabled
(
bool
autocryptEnabled
);
std
::
map
<
QByteArray
,
QString
>
useAutocrypt
()
const
;
...
...
messagecomposer/src/job/autocryptheadersjob.cpp
View file @
f3b280b6
...
...
@@ -13,16 +13,15 @@
#include
"messagecomposer_debug.h"
#include
<gpgme++/gpgmepp_version.h>
#include
<gpgme++/context.h>
#include
<QGpgME/Protocol>
#include
<QGpgME/ExportJob>
#include
<QGpgME/Protocol>
#include
<gpgme++/context.h>
#include
<gpgme++/gpgmepp_version.h>
#include
<KCodecs/KCodecs>
#include
<KMime/Headers>
#include
<KMime/Content>
#include
<KLocalizedString>
#include
<KMime/Content>
#include
<KMime/Headers>
using
namespace
MessageComposer
;
...
...
@@ -36,7 +35,7 @@ public:
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
fillHeaderData
(
KMime
::
Headers
::
Generic
*
header
,
const
QByteArray
&
addr
,
bool
preferEncrypted
,
const
QByteArray
&
keydata
);
KMime
::
Content
*
content
=
nullptr
;
KMime
::
Message
*
skeletonMessage
=
nullptr
;
...
...
@@ -56,10 +55,11 @@ void AutocryptHeadersJobPrivate::emitGpgError(const GpgME::Error &error)
Q_Q
(
AutocryptHeadersJob
);
Q_ASSERT
(
error
);
const
QString
msg
=
i18n
(
"<p>An error occurred while trying to export "
"the key from the backend:</p>"
"<p><b>%1</b></p>"
,
QString
::
fromLocal8Bit
(
error
.
asString
()));
const
QString
msg
=
i18n
(
"<p>An error occurred while trying to export "
"the key from the backend:</p>"
"<p><b>%1</b></p>"
,
QString
::
fromLocal8Bit
(
error
.
asString
()));
q
->
setError
(
KJob
::
UserDefinedError
);
q
->
setErrorText
(
msg
);
q
->
emitResult
();
...
...
@@ -68,18 +68,18 @@ void AutocryptHeadersJobPrivate::emitGpgError(const GpgME::Error &error)
void
AutocryptHeadersJobPrivate
::
emitNotFoundError
(
const
QByteArray
&
addr
,
const
QByteArray
&
fingerprint
)
{
Q_Q
(
AutocryptHeadersJob
);
const
QString
msg
=
i18n
(
"<p>An error occurred while trying to export "
"the key from the backend:</p>"
"<p><b>No vaild key found for user %1 (%2)</b></p>"
,
QString
::
fromLatin1
(
addr
),
QString
::
fromLatin1
(
fingerprint
));
const
QString
msg
=
i18n
(
"<p>An error occurred while trying to export "
"the key from the backend:</p>"
"<p><b>No vaild key found for user %1 (%2)</b></p>"
,
QString
::
fromLatin1
(
addr
),
QString
::
fromLatin1
(
fingerprint
));
q
->
setError
(
KJob
::
UserDefinedError
);
q
->
setErrorText
(
msg
);
q
->
emitResult
();
}
void
AutocryptHeadersJobPrivate
::
fillHeaderData
(
KMime
::
Headers
::
Generic
*
header
,
const
QByteArray
&
addr
,
bool
preferEncrypted
,
const
QByteArray
&
keydata
)
void
AutocryptHeadersJobPrivate
::
fillHeaderData
(
KMime
::
Headers
::
Generic
*
header
,
const
QByteArray
&
addr
,
bool
preferEncrypted
,
const
QByteArray
&
keydata
)
{
QByteArray
parameters
=
"addr="
+
addr
+
"; "
;
if
(
preferEncrypted
)
{
...
...
@@ -91,8 +91,8 @@ void AutocryptHeadersJobPrivate::fillHeaderData(KMime::Headers::Generic* header,
const
auto
lineLength
=
76
;
auto
start
=
0
;
auto
column
=
1
;
while
(
start
<
length
)
{
const
auto
midLength
=
std
::
min
(
length
-
start
,
lineLength
-
column
);
while
(
start
<
length
)
{
const
auto
midLength
=
std
::
min
(
length
-
start
,
lineLength
-
column
);
parameters
+=
encoded
.
mid
(
start
,
midLength
);
start
+=
midLength
;
column
+=
midLength
;
...
...
@@ -130,14 +130,14 @@ void AutocryptHeadersJob::setSkeletonMessage(KMime::Message *skeletonMessage)
d
->
skeletonMessage
=
skeletonMessage
;
}
void
AutocryptHeadersJob
::
setGnupgHome
(
const
QString
&
path
)
void
AutocryptHeadersJob
::
setGnupgHome
(
const
QString
&
path
)
{
Q_D
(
AutocryptHeadersJob
);
d
->
gnupgHome
=
path
;
}
void
AutocryptHeadersJob
::
setSenderKey
(
const
GpgME
::
Key
&
key
)
void
AutocryptHeadersJob
::
setSenderKey
(
const
GpgME
::
Key
&
key
)
{
Q_D
(
AutocryptHeadersJob
);
...
...
@@ -161,7 +161,7 @@ void AutocryptHeadersJob::setGossipKeys(const std::vector<GpgME::Key> &gossipKey
void
AutocryptHeadersJob
::
process
()
{
Q_D
(
AutocryptHeadersJob
);
Q_ASSERT
(
d
->
resultContent
==
nullptr
);
// Not processed before.
Q_ASSERT
(
d
->
resultContent
==
nullptr
);
// Not processed before.
// if setContent hasn't been called, we assume that a subjob was added