@@ -13,7 +13,7 @@ use crate::config::Config;
1313use crate :: contact:: { Contact , ContactId } ;
1414use crate :: context:: Context ;
1515use crate :: events:: EventType ;
16- use crate :: log:: { LogExt , warn} ;
16+ use crate :: log:: warn;
1717use crate :: message:: Message ;
1818use crate :: message:: { self , MsgId } ;
1919use crate :: mimefactory:: MimeFactory ;
@@ -584,44 +584,77 @@ async fn send_mdn_rfc724_mid(
584584 if context. get_config_bool ( Config :: BccSelf ) . await ? {
585585 add_self_recipients ( context, & mut recipients, encrypted) . await ?;
586586 }
587- let recipients: Vec < _ > = recipients
588- . into_iter ( )
589- . filter_map ( |addr| {
590- async_smtp:: EmailAddress :: new ( addr. clone ( ) )
591- . with_context ( || format ! ( "Invalid recipient: {addr}" ) )
592- . log_err ( context)
593- . ok ( )
594- } )
595- . collect ( ) ;
596-
597- match smtp_send ( context, & recipients, & body, smtp, None ) . await {
598- SendResult :: Success => {
599- if !recipients. is_empty ( ) {
600- info ! ( context, "Successfully sent MDN for {rfc724_mid}." ) ;
587+ #[ cfg( not( test) ) ]
588+ {
589+ use crate :: log:: LogExt ;
590+
591+ let recipients: Vec < _ > = recipients
592+ . into_iter ( )
593+ . filter_map ( |addr| {
594+ async_smtp:: EmailAddress :: new ( addr. clone ( ) )
595+ . with_context ( || format ! ( "Invalid recipient: {addr}" ) )
596+ . log_err ( context)
597+ . ok ( )
598+ } )
599+ . collect ( ) ;
600+
601+ match smtp_send ( context, & recipients, & body, smtp, None ) . await {
602+ SendResult :: Success => {
603+ if !recipients. is_empty ( ) {
604+ info ! ( context, "Successfully sent MDN for {rfc724_mid}." ) ;
605+ }
606+ context
607+ . sql
608+ . transaction ( |transaction| {
609+ let mut stmt =
610+ transaction. prepare ( "DELETE FROM smtp_mdns WHERE rfc724_mid = ?" ) ?;
611+ stmt. execute ( ( rfc724_mid, ) ) ?;
612+ for additional_rfc724_mid in additional_rfc724_mids {
613+ stmt. execute ( ( additional_rfc724_mid, ) ) ?;
614+ }
615+ Ok ( ( ) )
616+ } )
617+ . await ?;
618+ Ok ( true )
601619 }
602- context
603- . sql
604- . transaction ( |transaction| {
605- let mut stmt =
606- transaction. prepare ( "DELETE FROM smtp_mdns WHERE rfc724_mid = ?" ) ?;
607- stmt. execute ( ( rfc724_mid, ) ) ?;
608- for additional_rfc724_mid in additional_rfc724_mids {
609- stmt. execute ( ( additional_rfc724_mid, ) ) ?;
610- }
611- Ok ( ( ) )
612- } )
613- . await ?;
614- Ok ( true )
615- }
616- SendResult :: Retry => {
617- info ! (
618- context,
619- "Temporary SMTP failure while sending an MDN for {rfc724_mid}."
620- ) ;
621- Ok ( false )
620+ SendResult :: Retry => {
621+ info ! (
622+ context,
623+ "Temporary SMTP failure while sending an MDN for {rfc724_mid}."
624+ ) ;
625+ Ok ( false )
626+ }
627+ SendResult :: Failure ( err) => Err ( err) ,
622628 }
623- SendResult :: Failure ( err) => Err ( err) ,
624629 }
630+ #[ cfg( test) ]
631+ {
632+ let _ = smtp;
633+ context
634+ . sql
635+ . transaction ( |t| {
636+ t. execute (
637+ "INSERT INTO smtp (rfc724_mid, recipients, mime, msg_id)
638+ VALUES (?, ?, ?, ?)" ,
639+ ( rfc724_mid, recipients. join ( " " ) , body, u32:: MAX ) ,
640+ ) ?;
641+ let mut stmt = t. prepare ( "DELETE FROM smtp_mdns WHERE rfc724_mid = ?" ) ?;
642+ stmt. execute ( ( rfc724_mid, ) ) ?;
643+ for additional_rfc724_mid in additional_rfc724_mids {
644+ stmt. execute ( ( additional_rfc724_mid, ) ) ?;
645+ }
646+ Ok ( ( ) )
647+ } )
648+ . await ?;
649+ Ok ( true )
650+ }
651+ }
652+
653+ #[ cfg( test) ]
654+ pub ( crate ) async fn queue_mdn ( context : & Context ) -> Result < ( ) > {
655+ let queued = send_mdn ( context, & mut Smtp :: new ( ) ) . await ?;
656+ assert ! ( queued) ;
657+ Ok ( ( ) )
625658}
626659
627660/// Tries to send a single MDN. Returns true if more MDNs should be sent.
0 commit comments