@@ -254,11 +254,14 @@ fn mimepart_to_data_url(mail: &mailparse::ParsedMail<'_>) -> Result<String> {
254254
255255impl MsgId {
256256 /// Get HTML by database message id.
257- /// This requires `mime_headers` field to be set for the message;
258- /// this is the case at least when `Message.has_html()` returns true
259- /// (we do not save raw mime unconditionally in the database to save space).
257+ /// Returns `Some` at least when `Message.has_html()` is true.
258+ /// NB: we do not save raw mime unconditionally in the database to save space.
260259 /// The corresponding ffi-function is `dc_get_msg_html()`.
261260 pub async fn get_html ( self , context : & Context ) -> Result < Option < String > > {
261+ let param = self . get_param ( context) . await ?;
262+ if let Some ( html) = param. get ( SendHtml ) {
263+ return Ok ( Some ( html. to_string ( ) ) ) ;
264+ }
262265 let rawmime = message:: get_mime_headers ( context, self ) . await ?;
263266
264267 if !rawmime. is_empty ( ) {
@@ -279,9 +282,9 @@ impl MsgId {
279282#[ cfg( test) ]
280283mod tests {
281284 use super :: * ;
282- use crate :: chat;
283- use crate :: chat:: { forward_msgs, save_msgs} ;
285+ use crate :: chat:: { self , Chat , forward_msgs, save_msgs} ;
284286 use crate :: config:: Config ;
287+ use crate :: constants;
285288 use crate :: contact:: ContactId ;
286289 use crate :: message:: { MessengerMessage , Viewtype } ;
287290 use crate :: receive_imf:: receive_imf;
@@ -440,7 +443,7 @@ test some special html-characters as < > and & but also " and &#x
440443 }
441444
442445 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
443- async fn test_html_forwarding ( ) {
446+ async fn test_html_forwarding ( ) -> Result < ( ) > {
444447 // alice receives a non-delta html-message
445448 let mut tcm = TestContextManager :: new ( ) ;
446449 let alice = & tcm. alice ( ) . await ;
@@ -459,31 +462,57 @@ test some special html-characters as < > and & but also " and &#x
459462 assert ! ( html. contains( "this is <b>html</b>" ) ) ;
460463
461464 // alice: create chat with bob and forward received html-message there
462- let chat = alice. create_chat_with_contact ( "" , "bob@example.net" ) . await ;
463- forward_msgs ( alice, & [ msg. get_id ( ) ] , chat . get_id ( ) )
465+ let chat_alice = alice. create_chat_with_contact ( "" , "bob@example.net" ) . await ;
466+ forward_msgs ( alice, & [ msg. get_id ( ) ] , chat_alice . get_id ( ) )
464467 . await
465468 . unwrap ( ) ;
466- let msg = alice. get_last_msg_in ( chat. get_id ( ) ) . await ;
467- assert_eq ! ( msg. get_from_id( ) , ContactId :: SELF ) ;
468- assert_eq ! ( msg. is_dc_message, MessengerMessage :: Yes ) ;
469- assert ! ( msg. is_forwarded( ) ) ;
470- assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
471- assert ! ( msg. has_html( ) ) ;
472- let html = msg. get_id ( ) . get_html ( alice) . await . unwrap ( ) . unwrap ( ) ;
473- assert ! ( html. contains( "this is <b>html</b>" ) ) ;
469+ async fn check_sender ( ctx : & TestContext , chat : & Chat ) {
470+ let msg = ctx. get_last_msg_in ( chat. get_id ( ) ) . await ;
471+ assert_eq ! ( msg. get_from_id( ) , ContactId :: SELF ) ;
472+ assert_eq ! ( msg. is_dc_message, MessengerMessage :: Yes ) ;
473+ assert ! ( msg. is_forwarded( ) ) ;
474+ assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
475+ assert ! ( msg. has_html( ) ) ;
476+ let html = msg. get_id ( ) . get_html ( ctx) . await . unwrap ( ) . unwrap ( ) ;
477+ assert ! ( html. contains( "this is <b>html</b>" ) ) ;
478+ }
479+ check_sender ( alice, & chat_alice) . await ;
474480
475481 // bob: check that bob also got the html-part of the forwarded message
476482 let bob = & tcm. bob ( ) . await ;
477- let chat = bob. create_chat_with_contact ( "" , "alice@example.org" ) . await ;
478- let msg = bob. recv_msg ( & alice. pop_sent_msg ( ) . await ) . await ;
479- assert_eq ! ( chat. id, msg. chat_id) ;
480- assert_ne ! ( msg. get_from_id( ) , ContactId :: SELF ) ;
481- assert_eq ! ( msg. is_dc_message, MessengerMessage :: Yes ) ;
482- assert ! ( msg. is_forwarded( ) ) ;
483- assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
483+ let chat_bob = bob. create_chat_with_contact ( "" , "alice@example.org" ) . await ;
484+ async fn check_receiver ( ctx : & TestContext , chat : & Chat , sender : & TestContext ) {
485+ let msg = ctx. recv_msg ( & sender. pop_sent_msg ( ) . await ) . await ;
486+ assert_eq ! ( chat. id, msg. chat_id) ;
487+ assert_ne ! ( msg. get_from_id( ) , ContactId :: SELF ) ;
488+ assert_eq ! ( msg. is_dc_message, MessengerMessage :: Yes ) ;
489+ assert ! ( msg. is_forwarded( ) ) ;
490+ assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
491+ assert ! ( msg. has_html( ) ) ;
492+ let html = msg. get_id ( ) . get_html ( ctx) . await . unwrap ( ) . unwrap ( ) ;
493+ assert ! ( html. contains( "this is <b>html</b>" ) ) ;
494+ }
495+ check_receiver ( bob, & chat_bob, alice) . await ;
496+
497+ // Finally it appears that alice is bob, so alice can forward the message to herself via
498+ // "bob" profile!
499+ chat:: forward_msgs_2ctx ( alice, & [ msg. get_id ( ) ] , bob, chat_bob. get_id ( ) ) . await ?;
500+ check_sender ( bob, & chat_bob) . await ;
501+ check_receiver ( alice, & chat_alice, bob) . await ;
502+
503+ // Check cross-profile forwarding of long outgoing messages.
504+ let line = "this text with 42 chars is just repeated.\n " ;
505+ let long_txt = line. repeat ( constants:: DC_DESIRED_TEXT_LEN / line. len ( ) + 2 ) ;
506+ let mut msg = Message :: new_text ( long_txt) ;
507+ alice. send_msg ( chat_alice. id , & mut msg) . await ;
508+ let msg = alice. get_last_msg_in ( chat_alice. id ) . await ;
484509 assert ! ( msg. has_html( ) ) ;
485- let html = msg. get_id ( ) . get_html ( bob) . await . unwrap ( ) . unwrap ( ) ;
486- assert ! ( html. contains( "this is <b>html</b>" ) ) ;
510+ let html = msg. id . get_html ( alice) . await ?. unwrap ( ) ;
511+ chat:: forward_msgs_2ctx ( alice, & [ msg. get_id ( ) ] , bob, chat_bob. get_id ( ) ) . await ?;
512+ let msg = bob. get_last_msg_in ( chat_bob. id ) . await ;
513+ assert ! ( msg. has_html( ) ) ;
514+ assert_eq ! ( msg. id. get_html( bob) . await ?. unwrap( ) , html) ;
515+ Ok ( ( ) )
487516 }
488517
489518 #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
0 commit comments