Skip to content

refactor(smtp): introduce smtp::Connection structure - #8803

Merged
link2xt merged 1 commit into
mainfrom
link2xt/smtp-connection-single-option
Oct 12, 2026
Merged

link2xt merged 1 commit into
mainfrom
link2xt/smtp-connection-single-option

Conversation

@link2xt

@link2xt link2xt commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

It is now impossible for SMTP client to be connected without having a From address and transport_id available.

Follow-up to 7073049

@link2xt
link2xt force-pushed the link2xt/smtp-connection-single-option branch from 5d46f4c to 1ae87aa Compare October 6, 2026 20:53
@link2xt
link2xt added this pull request to stack #8807 October 7, 2026 02:46
@link2xt
link2xt force-pushed the link2xt/smtp-connection-single-option branch 2 times, most recently from 18e098e to 368bfac Compare October 7, 2026 12:47
@link2xt link2xt changed the title refactor(smtp): make it impossible connect without From address and transport_id refactor(smtp): introduce smtp::Connection structure Oct 7, 2026
@link2xt
link2xt marked this pull request as ready for review October 7, 2026 12:48
@link2xt
link2xt force-pushed the link2xt/smtp-connection-single-option branch 5 times, most recently from be16966 to 6158cee Compare October 9, 2026 21:18

@Hocuri Hocuri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring, good to clean up some old code

Comment thread src/smtp.rs Outdated
Comment on lines +355 to +361
let transport_id = connection.transport_id;
if let Err(err) = record_success(context, transport_id).await {
warn!(
context,
"Failed to record successful use of transport {transport_id} in smtp_success table: {err:#}."
);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I find log_err easier to read than if let Err … warn!, since if let Err … warn! 'hides' the most important thing, namely the call to record_success.

Suggested change
let transport_id = connection.transport_id;
if let Err(err) = record_success(context, transport_id).await {
warn!(
context,
"Failed to record successful use of transport {transport_id} in smtp_success table: {err:#}."
);
}
record_success(context, connection.transport_id)
.await
.with_context(|| {
format!("Failed to record successful use of transport {transport_id}")
})
.log_err(context)
.ok();

Comment thread src/smtp.rs Outdated
let send_result = connection
.send(context, recipients, message.as_bytes())
.await;
smtp.last_send_error = send_result.as_ref().err().map(|e| e.to_string());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use the alternate formatting now, otherwise the .context("Envelope error")? will swallow the inner error

Suggested change
smtp.last_send_error = send_result.as_ref().err().map(|e| e.to_string());
smtp.last_send_error = send_result.as_ref().err().map(|e| format!("{e:#}"));

Comment thread src/smtp/send.rs
Comment on lines 14 to 19
pub enum Error {
#[error("Envelope error: {}", _0)]
Envelope(anyhow::Error),
#[error("Send error: {}", _0)]
SmtpSend(async_smtp::error::Error),
#[error("SMTP has no transport")]
NoTransport,
#[error("{}", _0)]
Other(#[from] anyhow::Error),
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...or maybe this is where we need to use the alternate formatting? Anyways, can't hurt to use it in both places.

pub enum Error {
    #[error("Send error: {:#}", _0)]
    SmtpSend(async_smtp::error::Error),
    #[error("{:#}", _0)]
    Other(#[from] anyhow::Error),
}

(Github doesn't support to post this as a suggestion, since there are deleted lines in the diff)

It is now impossible for SMTP client to be connected
without having a From address and transport_id available.

Follow-up to 7073049
@link2xt
link2xt force-pushed the link2xt/smtp-connection-single-option branch from 6158cee to cb6a92a Compare October 12, 2026 22:22
@link2xt
link2xt merged commit 5510fb5 into main Oct 12, 2026
30 checks passed
@link2xt
link2xt deleted the link2xt/smtp-connection-single-option branch October 12, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants