1
1
//! Internet Message Format reception pipeline.
2
2
3
+ use std:: cmp:: min;
3
4
use std:: convert:: TryFrom ;
4
5
5
6
use anyhow:: { bail, ensure, Result } ;
@@ -18,9 +19,7 @@ use crate::constants::{
18
19
} ;
19
20
use crate :: contact:: { addr_cmp, normalize_name, Contact , Origin , VerifiedStatus } ;
20
21
use crate :: context:: Context ;
21
- use crate :: dc_tools:: {
22
- dc_create_smeared_timestamp, dc_extract_grpid_from_rfc724_mid, dc_smeared_time,
23
- } ;
22
+ use crate :: dc_tools:: { dc_extract_grpid_from_rfc724_mid, dc_smeared_time} ;
24
23
use crate :: download:: DownloadState ;
25
24
use crate :: ephemeral:: { stock_ephemeral_timer_changed, Timer as EphemeralTimer } ;
26
25
use crate :: events:: EventType ;
@@ -106,15 +105,6 @@ pub(crate) async fn dc_receive_imf_inner(
106
105
return Ok ( ( ) ) ;
107
106
}
108
107
109
- let mut sent_timestamp = if let Some ( value) = mime_parser
110
- . get_header ( HeaderDef :: Date )
111
- . and_then ( |value| mailparse:: dateparse ( value) . ok ( ) )
112
- {
113
- value
114
- } else {
115
- dc_create_smeared_timestamp ( context) . await
116
- } ;
117
-
118
108
let rfc724_mid = mime_parser. get_rfc724_mid ( ) . unwrap_or_else ( ||
119
109
// missing Message-IDs may come if the mail was set from this account with another
120
110
// client that relies in the SMTP server to generate one.
@@ -193,6 +183,12 @@ pub(crate) async fn dc_receive_imf_inner(
193
183
. await ?,
194
184
) ;
195
185
186
+ let rcvd_timestamp = dc_smeared_time ( context) . await ;
187
+ let sent_timestamp = mime_parser
188
+ . get_header ( HeaderDef :: Date )
189
+ . and_then ( |value| mailparse:: dateparse ( value) . ok ( ) )
190
+ . map_or ( rcvd_timestamp, |value| min ( value, rcvd_timestamp) ) ;
191
+
196
192
// Add parts
197
193
let chat_id = add_parts (
198
194
context,
@@ -204,7 +200,8 @@ pub(crate) async fn dc_receive_imf_inner(
204
200
server_uid,
205
201
& to_ids,
206
202
rfc724_mid,
207
- & mut sent_timestamp,
203
+ sent_timestamp,
204
+ rcvd_timestamp,
208
205
from_id,
209
206
& mut hidden,
210
207
seen || replace_partial_download,
@@ -406,7 +403,8 @@ async fn add_parts(
406
403
server_uid : u32 ,
407
404
to_ids : & ContactIds ,
408
405
rfc724_mid : String ,
409
- sent_timestamp : & mut i64 ,
406
+ sent_timestamp : i64 ,
407
+ rcvd_timestamp : i64 ,
410
408
from_id : u32 ,
411
409
hidden : & mut bool ,
412
410
seen : bool ,
@@ -455,9 +453,6 @@ async fn add_parts(
455
453
}
456
454
}
457
455
458
- let rcvd_timestamp = dc_smeared_time ( context) . await ;
459
- * sent_timestamp = std:: cmp:: min ( * sent_timestamp, rcvd_timestamp) ;
460
-
461
456
// check if the message introduces a new chat:
462
457
// - outgoing messages introduce a chat with the first to: address if they are sent by a messenger
463
458
// - incoming messages introduce a chat only for known contacts if they are sent by a messenger
@@ -531,7 +526,7 @@ async fn add_parts(
531
526
if let Some ( ( new_chat_id, new_chat_id_blocked) ) = create_or_lookup_group (
532
527
context,
533
528
& mut mime_parser,
534
- * sent_timestamp,
529
+ sent_timestamp,
535
530
if test_normal_chat. is_none ( ) {
536
531
allow_creation
537
532
} else {
@@ -761,7 +756,7 @@ async fn add_parts(
761
756
if let Some ( ( new_chat_id, new_chat_id_blocked) ) = create_or_lookup_group (
762
757
context,
763
758
& mut mime_parser,
764
- * sent_timestamp,
759
+ sent_timestamp,
765
760
allow_creation,
766
761
Blocked :: Not ,
767
762
from_id,
@@ -857,7 +852,7 @@ async fn add_parts(
857
852
// correct message_timestamp, it should not be used before,
858
853
// however, we cannot do this earlier as we need chat_id to be set
859
854
let in_fresh = state == MessageState :: InFresh ;
860
- let sort_timestamp = calc_sort_timestamp ( context, * sent_timestamp, chat_id, in_fresh) . await ?;
855
+ let sort_timestamp = calc_sort_timestamp ( context, sent_timestamp, chat_id, in_fresh) . await ?;
861
856
862
857
// Apply ephemeral timer changes to the chat.
863
858
//
@@ -896,7 +891,7 @@ async fn add_parts(
896
891
chat_id
897
892
) ;
898
893
} else if chat_id
899
- . update_timestamp ( context, Param :: EphemeralSettingsTimestamp , * sent_timestamp)
894
+ . update_timestamp ( context, Param :: EphemeralSettingsTimestamp , sent_timestamp)
900
895
. await ?
901
896
{
902
897
if let Err ( err) = chat_id
@@ -967,7 +962,7 @@ async fn add_parts(
967
962
. update_timestamp (
968
963
context,
969
964
Param :: ProtectionSettingsTimestamp ,
970
- * sent_timestamp,
965
+ sent_timestamp,
971
966
)
972
967
. await ?
973
968
{
@@ -1047,7 +1042,6 @@ async fn add_parts(
1047
1042
Vec :: new ( )
1048
1043
} ;
1049
1044
1050
- let sent_timestamp = * sent_timestamp;
1051
1045
let is_hidden = * hidden;
1052
1046
1053
1047
let mut is_hidden = is_hidden;
@@ -1304,11 +1298,7 @@ async fn calc_sort_timestamp(
1304
1298
}
1305
1299
}
1306
1300
1307
- if sort_timestamp >= dc_smeared_time ( context) . await {
1308
- sort_timestamp = dc_create_smeared_timestamp ( context) . await ;
1309
- }
1310
-
1311
- Ok ( sort_timestamp)
1301
+ Ok ( min ( sort_timestamp, dc_smeared_time ( context) . await ) )
1312
1302
}
1313
1303
1314
1304
async fn lookup_chat_by_reply (
0 commit comments