Skip to content
GitLab
Menu
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
c5f862eb
Commit
c5f862eb
authored
Nov 18, 2020
by
Sandro Knauß
🐝
Browse files
messasgecore/autocrypt: Add changed flag.
parent
a6031151
Changes
4
Hide whitespace changes
Inline
Side-by-side
messagecore/autotests/autocryptrecipienttest.cpp
View file @
c5f862eb
...
...
@@ -216,6 +216,58 @@ void AutocryptRecipientTest::test_coreUpdateLogic()
QCOMPARE
(
obj
.
value
(
QStringLiteral
(
"autocrypt_timestamp"
)).
toString
(),
messageDate
.
toString
(
Qt
::
ISODate
));
}
}
void
AutocryptRecipientTest
::
test_changedLogic
()
{
MimeTreeParser
::
NodeHelper
nodeHelper
;
auto
message
=
readAndParseMail
(
QStringLiteral
(
"html.mbox"
));
HeaderMixupNodeHelper
mixin
(
&
nodeHelper
,
message
.
data
());
// Set a date header, that we know to pass the update logic
auto
messageDate
=
QDateTime
::
currentDateTime
().
addYears
(
-
1
);
message
->
date
()
->
setDateTime
(
messageDate
);
auto
recipient
=
AutocryptRecipient
();
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
recipient
.
updateFromMessage
(
mixin
);
QCOMPARE
(
recipient
.
hasChanged
(),
true
);
recipient
.
setChangedFlag
(
false
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
{
// Do not update when passing the same message a second time
recipient
.
updateFromMessage
(
mixin
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
}
{
// Do not update, if the header date is in the future
auto
newDate
=
QDateTime
::
currentDateTime
().
addDays
(
2
);
message
->
date
()
->
setDateTime
(
newDate
);
recipient
.
updateFromMessage
(
mixin
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
}
{
// Update the timestamp and count, if we have a new mail
auto
newDate
=
QDateTime
::
currentDateTime
().
addDays
(
-
2
);
message
->
date
()
->
setDateTime
(
newDate
);
messageDate
=
newDate
;
recipient
.
updateFromMessage
(
mixin
);
QCOMPARE
(
recipient
.
hasChanged
(),
true
);
recipient
.
setChangedFlag
(
false
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
}
{
// Do not update when parsing an older mail
message
->
date
()
->
setDateTime
(
messageDate
.
addDays
(
-
1
));
recipient
.
updateFromMessage
(
mixin
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
}
}
void
AutocryptRecipientTest
::
test_gpgKey
()
{
MimeTreeParser
::
NodeHelper
nodeHelper
;
...
...
@@ -360,6 +412,62 @@ void AutocryptRecipientTest::test_gossipUpdateLogic()
}
}
void
AutocryptRecipientTest
::
test_changedLogicGossip
()
{
MimeTreeParser
::
NodeHelper
nodeHelper
;
auto
message
=
readAndParseMail
(
QStringLiteral
(
"html.mbox"
));
HeaderMixupNodeHelper
mixin
(
&
nodeHelper
,
message
.
data
());
KMime
::
Headers
::
Generic
gossipHeader
(
"Autocrypt-Gossip"
);
QByteArray
keydata
(
"mDMEXEcE6RYJKwYBBAHaRw8BAQdAPPy13Q7Y8w2VPRkksrijrn9o8u59ra1c2CJiHFpbM2G0FWJvYkBhdXRvY3J5cHQuZXhhbXBsZYiWBBMWCAA+FiEE8FQeqC0xAKoa3zse4w5v3UWQH4IFAlxHBOkCGwMFCQPCZwAFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQ4w5v3UWQH4IfwAEA3lujohz3Nj9afUnaGUXN7YboIzQsmpgGkN8thyb/slIBAKwdJyg1SurKqHnxy3Wl/DBzOrR12/pN7nScn0+x4sgBuDgEXEcE6RIKKwYBBAGXVQEFAQEHQJSU7QErtJOYXsIagw2qwnVbt31ooVEx8Xcb476NCbFjAwEIB4h4BBgWCAAgFiEE8FQeqC0xAKoa3zse4w5v3UWQH4IFAlxHBOkCGwwACgkQ4w5v3UWQH4LlHQEAlwUBfUU8ORC0RAS/dzlZSEm7+ImY12Wv8QGUCx5zPbUA/3YH84ZOAQDbmV/C+R//0WVNbGfav9X5KYmiratYR7oL"
);
gossipHeader
.
from7BitString
(
"addr=bob@autocrypt.example; keydata=
\n
"
+
keydata
);
// Set a date header, that we know to pass the update logic
auto
messageDate
=
QDateTime
::
currentDateTime
().
addYears
(
-
1
);
message
->
date
()
->
setDateTime
(
messageDate
);
auto
recipient
=
AutocryptRecipient
();
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
recipient
.
updateFromGossip
(
mixin
,
&
gossipHeader
);
QCOMPARE
(
recipient
.
hasChanged
(),
true
);
recipient
.
setChangedFlag
(
false
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
// Do not update when passing the same message a second time
recipient
.
updateFromGossip
(
mixin
,
&
gossipHeader
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
{
// Do not update, if the header date is in the future
auto
newDate
=
QDateTime
::
currentDateTime
().
addDays
(
2
);
message
->
date
()
->
setDateTime
(
newDate
);
recipient
.
updateFromGossip
(
mixin
,
&
gossipHeader
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
}
{
// Update the timestamp and count, if we have a new mail
auto
newDate
=
QDateTime
::
currentDateTime
().
addDays
(
-
2
);
message
->
date
()
->
setDateTime
(
newDate
);
messageDate
=
newDate
;
recipient
.
updateFromGossip
(
mixin
,
&
gossipHeader
);
QCOMPARE
(
recipient
.
hasChanged
(),
true
);
recipient
.
setChangedFlag
(
false
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
}
// Do not update when parsing an older mail
message
->
date
()
->
setDateTime
(
messageDate
.
addDays
(
-
1
));
recipient
.
updateFromGossip
(
mixin
,
&
gossipHeader
);
QCOMPARE
(
recipient
.
hasChanged
(),
false
);
}
void
AutocryptRecipientTest
::
test_gossipKey
()
{
MimeTreeParser
::
NodeHelper
nodeHelper
;
...
...
messagecore/autotests/autocryptrecipienttest.h
View file @
c5f862eb
...
...
@@ -17,9 +17,11 @@ private Q_SLOTS:
void
test_firstAutocryptHeader
();
void
test_initiateWithNoAutocryptHeader
();
void
test_coreUpdateLogic
();
void
test_changedLogic
();
void
test_gpgKey
();
void
test_setGossipHeader
();
void
test_gossipUpdateLogic
();
void
test_changedLogicGossip
();
void
test_gossipKey
();
};
...
...
messagecore/src/autocrypt/autocryptrecipient.cpp
View file @
c5f862eb
...
...
@@ -63,12 +63,14 @@ public:
int
count_have_ach
;
int
count_no_ach
;
bool
prefer_encrypt
;
bool
changed
;
};
AutocryptRecipientPrivate
::
AutocryptRecipientPrivate
()
:
count_have_ach
(
0
)
,
count_no_ach
(
0
)
,
prefer_encrypt
(
false
)
,
changed
(
false
)
{
}
...
...
@@ -117,7 +119,9 @@ void AutocryptRecipient::updateFromMessage ( const HeaderMixupNodeHelper& mixup
if
(
d
->
autocrypt_timestamp
.
isValid
()
&&
effectiveDate
<=
d
->
autocrypt_timestamp
)
{
return
;
}
d
->
autocrypt_timestamp
=
effectiveDate
;
d
->
changed
=
true
;
if
(
!
d
->
counting_since
.
isValid
())
{
d
->
counting_since
=
effectiveDate
;
...
...
@@ -175,6 +179,7 @@ void AutocryptRecipient::updateFromGossip(const HeaderMixupNodeHelper& mixup, co
return
;
}
d
->
changed
=
true
;
d
->
gossip_timestamp
=
effectiveDate
;
d
->
gossip_key
=
params
[
"keydata"
].
replace
(
' '
,
QByteArray
());
}
...
...
@@ -185,6 +190,18 @@ QByteArray AutocryptRecipient::toJson ( QJsonDocument::JsonFormat format ) const
return
d
->
toJson
(
format
);
}
bool
AutocryptRecipient
::
hasChanged
()
const
{
const
Q_D
(
AutocryptRecipient
);
return
d
->
changed
;
}
void
AutocryptRecipient
::
setChangedFlag
(
bool
changed
)
{
Q_D
(
AutocryptRecipient
);
d
->
changed
=
changed
;
}
GpgME
::
Key
gpgKey
(
const
QByteArray
&
keydata
)
{
assert
(
QGpgME
::
openpgp
());
// Make sure, that openpgp backend is loaded
...
...
messagecore/src/autocrypt/autocryptrecipient.h
View file @
c5f862eb
...
...
@@ -43,6 +43,9 @@ public:
void
updateFromGossip
(
const
HeaderMixupNodeHelper
&
mixup
,
const
KMime
::
Headers
::
Base
*
header
);
QByteArray
toJson
(
QJsonDocument
::
JsonFormat
format
)
const
;
bool
hasChanged
()
const
;
void
setChangedFlag
(
bool
changed
);
GpgME
::
Key
gpgKey
()
const
;
GpgME
::
Key
gossipKey
()
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment