@@ -10,6 +10,7 @@ use num_traits::FromPrimitive;
10
10
use once_cell:: sync:: Lazy ;
11
11
use regex:: Regex ;
12
12
13
+ use crate :: aheader:: EncryptPreference ;
13
14
use crate :: chat:: { self , Chat , ChatId , ChatIdBlocked , ProtectionStatus } ;
14
15
use crate :: config:: Config ;
15
16
use crate :: constants:: { Blocked , Chattype , ShowEmails , DC_CHAT_ID_TRASH } ;
@@ -171,6 +172,29 @@ pub(crate) async fn receive_imf_inner(
171
172
Ok ( mime_parser) => mime_parser,
172
173
} ;
173
174
175
+ let rcvd_timestamp = smeared_time ( context) ;
176
+
177
+ // Sender timestamp is allowed to be a bit in the future due to
178
+ // unsynchronized clocks, but not too much.
179
+ let sent_timestamp = mime_parser
180
+ . get_header ( HeaderDef :: Date )
181
+ . and_then ( |value| mailparse:: dateparse ( value) . ok ( ) )
182
+ . map_or ( rcvd_timestamp, |value| min ( value, rcvd_timestamp + 60 ) ) ;
183
+
184
+ crate :: peerstate:: maybe_do_aeap_transition ( context, & mut mime_parser) . await ?;
185
+ if let Some ( peerstate) = & mime_parser. decryption_info . peerstate {
186
+ peerstate
187
+ . handle_fingerprint_change ( context, sent_timestamp)
188
+ . await ?;
189
+ // When peerstate is set to Mutual, it's saved immediately to not lose that fact in case
190
+ // of an error. Otherwise we don't save peerstate until get here to reduce the number of
191
+ // calls to save_to_db() and not to degrade encryption if a mail wasn't parsed
192
+ // successfully.
193
+ if peerstate. prefer_encrypt != EncryptPreference :: Mutual {
194
+ peerstate. save_to_db ( & context. sql ) . await ?;
195
+ }
196
+ }
197
+
174
198
info ! ( context, "Receiving message {rfc724_mid:?}, seen={seen}..." ) ;
175
199
176
200
// check, if the mail is already in our database.
@@ -232,15 +256,6 @@ pub(crate) async fn receive_imf_inner(
232
256
)
233
257
. await ?;
234
258
235
- let rcvd_timestamp = smeared_time ( context) ;
236
-
237
- // Sender timestamp is allowed to be a bit in the future due to
238
- // unsynchronized clocks, but not too much.
239
- let sent_timestamp = mime_parser
240
- . get_header ( HeaderDef :: Date )
241
- . and_then ( |value| mailparse:: dateparse ( value) . ok ( ) )
242
- . map_or ( rcvd_timestamp, |value| min ( value, rcvd_timestamp + 60 ) ) ;
243
-
244
259
update_verified_keys ( context, & mut mime_parser, from_id) . await ?;
245
260
246
261
let received_msg;
0 commit comments