@@ -218,11 +218,8 @@ mod tests {
218218 use num_traits:: FromPrimitive ;
219219
220220 use super :: * ;
221- use crate :: chat:: { get_chat_msgs, send_msg} ;
222- use crate :: ephemeral:: Timer ;
223- use crate :: message:: delete_msgs;
224- use crate :: receive_imf:: receive_imf_from_inbox;
225- use crate :: test_utils:: { E2EE_INFO_MSGS , TestContext , TestContextManager } ;
221+ use crate :: chat:: send_msg;
222+ use crate :: test_utils:: TestContext ;
226223
227224 #[ test]
228225 fn test_downloadstate_values ( ) {
@@ -294,230 +291,4 @@ mod tests {
294291
295292 Ok ( ( ) )
296293 }
297-
298- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
299- async fn test_partial_receive_imf ( ) -> Result < ( ) > {
300- let t = TestContext :: new_alice ( ) . await ;
301-
302- let header = "Received: (Postfix, from userid 1000); Mon, 4 Dec 2006 14:51:39 +0100 (CET)\n \
303- 304- 305- Subject: foo\n \
306- Message-ID: <[email protected] >\n \ 307- Chat-Version: 1.0\n \
308- Date: Sun, 22 Mar 2020 22:37:57 +0000\
309- Content-Type: text/plain";
310-
311- receive_imf_from_inbox (
312- & t,
313- 314- header. as_bytes ( ) ,
315- false ,
316- Some ( 100000 ) ,
317- )
318- . await ?;
319- let msg = t. get_last_msg ( ) . await ;
320- assert_eq ! ( msg. download_state( ) , DownloadState :: Available ) ;
321- assert_eq ! ( msg. get_subject( ) , "foo" ) ;
322- assert ! (
323- msg. get_text( )
324- . contains( & stock_str:: partial_download_msg_body( & t, 100000 ) . await )
325- ) ;
326-
327- receive_imf_from_inbox (
328- & t,
329- 330- format ! ( "{header}\n \n 100k text..." ) . as_bytes ( ) ,
331- false ,
332- None ,
333- )
334- . await ?;
335- let msg = t. get_last_msg ( ) . await ;
336- assert_eq ! ( msg. download_state( ) , DownloadState :: Done ) ;
337- assert_eq ! ( msg. get_subject( ) , "foo" ) ;
338- assert_eq ! ( msg. get_text( ) , "100k text..." ) ;
339-
340- Ok ( ( ) )
341- }
342-
343- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
344- async fn test_partial_download_and_ephemeral ( ) -> Result < ( ) > {
345- let t = TestContext :: new_alice ( ) . await ;
346- let chat_id = t
347- . create_chat_with_contact ( "bob" , "[email protected] " ) 348- . await
349- . id ;
350- chat_id
351- . set_ephemeral_timer ( & t, Timer :: Enabled { duration : 60 } )
352- . await ?;
353-
354- // download message from bob partially, this must not change the ephemeral timer
355- receive_imf_from_inbox (
356- & t,
357- 358- b"From: Bob <[email protected] >\n \ 359- 360- Chat-Version: 1.0\n \
361- Subject: subject\n \
362- Message-ID: <[email protected] >\n \ 363- Date: Sun, 14 Nov 2021 00:10:00 +0000\
364- Content-Type: text/plain",
365- false ,
366- Some ( 100000 ) ,
367- )
368- . await ?;
369- assert_eq ! (
370- chat_id. get_ephemeral_timer( & t) . await ?,
371- Timer :: Enabled { duration: 60 }
372- ) ;
373-
374- Ok ( ( ) )
375- }
376-
377- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
378- async fn test_status_update_expands_to_nothing ( ) -> Result < ( ) > {
379- let alice = TestContext :: new_alice ( ) . await ;
380- let bob = TestContext :: new_bob ( ) . await ;
381- let chat_id = alice. create_chat ( & bob) . await . id ;
382-
383- let file = alice. get_blobdir ( ) . join ( "minimal.xdc" ) ;
384- tokio:: fs:: write ( & file, include_bytes ! ( "../test-data/webxdc/minimal.xdc" ) ) . await ?;
385- let mut instance = Message :: new ( Viewtype :: File ) ;
386- instance. set_file_and_deduplicate ( & alice, & file, None , None ) ?;
387- let _sent1 = alice. send_msg ( chat_id, & mut instance) . await ;
388-
389- alice
390- . send_webxdc_status_update ( instance. id , r#"{"payload":7}"# )
391- . await ?;
392- alice. flush_status_updates ( ) . await ?;
393- let sent2 = alice. pop_sent_msg ( ) . await ;
394- let sent2_rfc724_mid = sent2. load_from_db ( ) . await . rfc724_mid ;
395-
396- // not downloading the status update results in an placeholder
397- receive_imf_from_inbox (
398- & bob,
399- & sent2_rfc724_mid,
400- sent2. payload ( ) . as_bytes ( ) ,
401- false ,
402- Some ( sent2. payload ( ) . len ( ) as u32 ) ,
403- )
404- . await ?;
405- let msg = bob. get_last_msg ( ) . await ;
406- let chat_id = msg. chat_id ;
407- assert_eq ! (
408- get_chat_msgs( & bob, chat_id) . await ?. len( ) ,
409- E2EE_INFO_MSGS + 1
410- ) ;
411- assert_eq ! ( msg. download_state( ) , DownloadState :: Available ) ;
412-
413- // downloading the status update afterwards expands to nothing and moves the placeholder to trash-chat
414- // (usually status updates are too small for not being downloaded directly)
415- receive_imf_from_inbox (
416- & bob,
417- & sent2_rfc724_mid,
418- sent2. payload ( ) . as_bytes ( ) ,
419- false ,
420- None ,
421- )
422- . await ?;
423- assert_eq ! ( get_chat_msgs( & bob, chat_id) . await ?. len( ) , E2EE_INFO_MSGS ) ;
424- assert ! (
425- Message :: load_from_db_optional( & bob, msg. id)
426- . await ?
427- . is_none( )
428- ) ;
429-
430- Ok ( ( ) )
431- }
432-
433- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
434- async fn test_mdn_expands_to_nothing ( ) -> Result < ( ) > {
435- let bob = TestContext :: new_bob ( ) . await ;
436- let raw = b"Subject: Message opened\n \
437- Date: Mon, 10 Jan 2020 00:00:00 +0000\n \
438- Chat-Version: 1.0\n \
439- Message-ID: <[email protected] >\n \ 440- 441- 442- Content-Type: multipart/report; report-type=disposition-notification;\n \t \
443- boundary=\" kJBbU58X1xeWNHgBtTbMk80M5qnV4N\" \n \
444- \n \
445- \n \
446- --kJBbU58X1xeWNHgBtTbMk80M5qnV4N\n \
447- Content-Type: text/plain; charset=utf-8\n \
448- \n \
449- bla\n \
450- \n \
451- \n \
452- --kJBbU58X1xeWNHgBtTbMk80M5qnV4N\n \
453- Content-Type: message/disposition-notification\n \
454- \n \
455- Reporting-UA: Delta Chat 1.88.0\n \
456- Original-Recipient: rfc822;[email protected] \n \ 457- Final-Recipient: rfc822;[email protected] \n \ 458- Original-Message-ID: <[email protected] >\n \ 459- Disposition: manual-action/MDN-sent-automatically; displayed\n \
460- \n \
461- \n \
462- --kJBbU58X1xeWNHgBtTbMk80M5qnV4N--\n \
463- ";
464-
465- // not downloading the mdn results in an placeholder
466- receive_imf_from_inbox ( & bob
, "[email protected] " , raw
, false , Some ( raw
. len ( ) as u32 ) ) . await ?
; 467- let msg = bob. get_last_msg ( ) . await ;
468- let chat_id = msg. chat_id ;
469- assert_eq ! ( get_chat_msgs( & bob, chat_id) . await ?. len( ) , 1 ) ;
470- assert_eq ! ( msg. download_state( ) , DownloadState :: Available ) ;
471-
472- // downloading the mdn afterwards expands to nothing and deletes the placeholder directly
473- // (usually mdn are too small for not being downloaded directly)
474- receive_imf_from_inbox ( & bob
, "[email protected] " , raw
, false , None ) . await ?
; 475- assert_eq ! ( get_chat_msgs( & bob, chat_id) . await ?. len( ) , 0 ) ;
476- assert ! (
477- Message :: load_from_db_optional( & bob, msg. id)
478- . await ?
479- . is_none( )
480- ) ;
481-
482- Ok ( ( ) )
483- }
484-
485- /// Tests that fully downloading the message
486- /// works even if the Message-ID already exists
487- /// in the database assigned to the trash chat.
488- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
489- async fn test_partial_download_trashed ( ) -> Result < ( ) > {
490- let mut tcm = TestContextManager :: new ( ) ;
491- let alice = & tcm. alice ( ) . await ;
492-
493- let imf_raw =
b"From: Bob <[email protected] >\n \ 494- 495- Chat-Version: 1.0\n \
496- Subject: subject\n \
497- Message-ID: <[email protected] >\n \ 498- Date: Sun, 14 Nov 2021 00:10:00 +0000\
499- Content-Type: text/plain";
500-
501- // Download message from Bob partially.
502- let partial_received_msg =
503- receive_imf_from_inbox ( alice
, "[email protected] " , imf_raw
, false , Some ( 100000 ) ) 504- . await ?
505- . unwrap ( ) ;
506- assert_eq ! ( partial_received_msg. msg_ids. len( ) , 1 ) ;
507-
508- // Delete the received message.
509- // Not it is still in the database,
510- // but in the trash chat.
511- delete_msgs ( alice, & [ partial_received_msg. msg_ids [ 0 ] ] ) . await ?;
512-
513- // Fully download message after deletion.
514- let full_received_msg =
515- receive_imf_from_inbox ( alice
, "[email protected] " , imf_raw
, false , None ) . await ?
; 516-
517- // The message does not reappear.
518- // However, `receive_imf` should not fail.
519- assert ! ( full_received_msg. is_none( ) ) ;
520-
521- Ok ( ( ) )
522- }
523294}
0 commit comments