fn deliver_to_one_server(
    email: &PreparedEmail,
    internal_message_status: &mut InternalMessageStatus,
    config: &Config,
    mx_delivery: &MxDelivery
) -> bool {

    let mut deferred_some: bool = false;

    // Per-MX version of the prepared email
    let mut mx_prepared_email = email.clone();

    // Rebuild the 'To:' list; only add recipients for *this* MX server,
    // and for which delivery has not already completed
    mx_prepared_email.to = mx_delivery.recipients
        .iter()
        .filter_map(|r| {
            if internal_message_status.recipients[*r].result.completed() {
                None
            } else {
                Some(
                    internal_message_status.recipients[*r]
                        .smtp_email_addr
                        .clone(),
                )
            }
        })
        .collect();

    // Skip this MX server if no addresses to deliver to
    // (this can happen if a previous server already handled its recipients and
    // the filter_map above removed them all)
    if mx_prepared_email.to.is_empty() {
        return true;
    }

    // Actually deliver to this SMTP server
    // 'attempt' field in results will be set to 1
    let result = crate::worker::smtp::smtp_delivery(
        &mx_prepared_email,
        &*mx_delivery.mx_server,
        mx_delivery.mx_port,
        config);

    // Fix 'attempt' field in results on a per-recipient basis (not a per-mx basis)
    for r in &mx_delivery.recipients {
        // If the result is deferred, and the previous result was deferred, then
        // bump the attempt number and update the reason message
        if let DeliveryResult::Deferred(_, ref newmsg) = result {
            deferred_some = true;
            let mut data: Option<u8> = None;
            if let DeliveryResult::Deferred(attempts, _) =
                internal_message_status.recipients[*r].result
            {
                data = Some(attempts);
            }
            if data.is_some() {
                let attempts = data.unwrap();
                internal_message_status.recipients[*r].result =
                    DeliveryResult::Deferred(attempts + 1, newmsg.clone());
                continue;
            }
        }

        // For everyone else, just take the result
        internal_message_status.recipients[*r].result = result.clone();
    }

    !deferred_some
}
// Organize delivery for one-SMTP-delivery per MX server, and then use smtp_deliver()
// Returns true only if all recipient deliveries have been completed (rather than deferred)
Organize delivery for one-SMTP-delivery per MX server, and then use smtp_deliver()
Returns true only if all recipient deliveries have been completed (rather than deferred)
Organize delivery for one - SMTP - delivery per MX server and then use smtp_deliver () Returns true only if all recipient deliveries have been completed ( rather than deferred )
fn deliver_to_one_server(
    email: &PreparedEmail,
    internal_message_status: &mut InternalMessageStatus,
    config: &Config,
    mx_delivery: &MxDelivery
) -> bool {
    let mut deferred_some: bool = false;
    // Per-MX version of the prepared email
    let mut mx_prepared_email = email.clone();
    // Rebuild the 'To:' list; only add recipients for *this* MX server,
    // and for which delivery has not already completed
    mx_prepared_email.to = mx_delivery.recipients
        .iter()
        .filter_map(|r| {
            if internal_message_status.recipients[*r].result.completed() {
                None
            } else {
                Some(
                    internal_message_status.recipients[*r]
                        .smtp_email_addr
                        .clone(),
                )
            }
        })
        .collect();
    // Skip this MX server if no addresses to deliver to
    // (this can happen if a previous server already handled its recipients and
    // the filter_map above removed them all)
    if mx_prepared_email.to.is_empty() {
        return true;
    }
    // Actually deliver to this SMTP server
    // 'attempt' field in results will be set to 1
    let result = crate::worker::smtp::smtp_delivery(
        &mx_prepared_email,
        &*mx_delivery.mx_server,
        mx_delivery.mx_port,
        config);
    // Fix 'attempt' field in results on a per-recipient basis (not a per-mx basis)
    for r in &mx_delivery.recipients {
        // If the result is deferred, and the previous result was deferred, then
        // bump the attempt number and update the reason message
        if let DeliveryResult::Deferred(_, ref newmsg) = result {
            deferred_some = true;
            let mut data: Option<u8> = None;
            if let DeliveryResult::Deferred(attempts, _) =
                internal_message_status.recipients[*r].result
            {
                data = Some(attempts);
            }
            if data.is_some() {
                let attempts = data.unwrap();
                internal_message_status.recipients[*r].result =
                    DeliveryResult::Deferred(attempts + 1, newmsg.clone());
                continue;
            }
        }
        // For everyone else, just take the result
        internal_message_status.recipients[*r].result = result.clone();
    }
    !deferred_some
}
fn deliver_to_one_server ( email : & PreparedEmail , internal_message_status : & mut InternalMessageStatus , config : & Config , mx_delivery : & MxDelivery ) -> bool { let mut deferred_some : bool = false ; // Per-MX version of the prepared email let mut mx_prepared_email = email . clone ( ) ; // Rebuild the 'To:' list; only add recipients for *this* MX server, // and for which delivery has not already completed mx_prepared_email . to = mx_delivery . recipients . iter ( ) . filter_map ( | r | { if internal_message_status . recipients [ * r ] . result . completed ( ) { None } else { Some ( internal_message_status . recipients [ * r ] . smtp_email_addr . clone ( ) , ) } } ) . collect ( ) ; // Skip this MX server if no addresses to deliver to // (this can happen if a previous server already handled its recipients and // the filter_map above removed them all) if mx_prepared_email . to . is_empty ( ) { return true ; } // Actually deliver to this SMTP server // 'attempt' field in results will be set to 1 let result = crate :: worker :: smtp :: smtp_delivery ( & mx_prepared_email , & * mx_delivery . mx_server , mx_delivery . mx_port , config ) ; // Fix 'attempt' field in results on a per-recipient basis (not a per-mx basis) for r in & mx_delivery . recipients { // If the result is deferred, and the previous result was deferred, then // bump the attempt number and update the reason message if let DeliveryResult :: Deferred ( _ , ref newmsg ) = result { deferred_some = true ; let mut data : Option < u8 > = None ; if let DeliveryResult :: Deferred ( attempts , _ ) = internal_message_status . recipients [ * r ] . result { data = Some ( attempts ) ; } if data . is_some ( ) { let attempts = data . unwrap ( ) ; internal_message_status . recipients [ * r ] . result = DeliveryResult :: Deferred ( attempts + 1 , newmsg . clone ( ) ) ; continue ; } } // For everyone else, just take the result internal_message_status . recipients [ * r ] . result = result . clone ( ) ; } ! deferred_some }
Organize delivery for one-SMTP-delivery per MX server, and then use smtp_deliver()
Returns true only if all recipient deliveries have been completed (rather than deferred)
Organize delivery for one - SMTP - delivery per MX server and then use smtp_deliver () Returns true only if all recipient deliveries have been completed ( rather than deferred )
email
&PreparedEmail
internal_message_status
&mut InternalMessageStatus
config
&Config
mx_delivery
&MxDelivery
email
&PreparedEmail
internal_message_status
&mut InternalMessageStatus
config
&Config
mx_delivery
&MxDelivery