Skip to content

🔍 Add more detail to Net::IMAP#inspect TLS info#674

Merged
nevans merged 1 commit intomasterfrom
improved-inspect-tls-state
May 7, 2026
Merged

🔍 Add more detail to Net::IMAP#inspect TLS info#674
nevans merged 1 commit intomasterfrom
improved-inspect-tls-state

Conversation

@nevans
Copy link
Copy Markdown
Collaborator

@nevans nevans commented May 5, 2026

Previously, the existence of ssl_ctx without tls_verified? would cause TLS (NOT VERIFIED) to be output. But that isn't quite right: ssl_ctx is assigned immediately, before even sending the STARTTLS command, before calling start_tls_session, and before start_tls_session returns. And those intermediate states are important distinctions for debugging TLS issues.

So this updates Net::IMAP#inspect with two new TLS/PLAINTEXT states:

  • PLAINTEXT (TLS NOT STARTED), when:
    • #starttls has been called (@ssl_ctx has been set),
    • but #start_tls_session hasn't (@sock is a TCPSocket).
  • TLS (NOT ESTABLISHED), when:
    • #start_tls_session was called (@sock is an SSLSocket),
    • but hasn't returned successfully (@sock.session isn't available).

Generally, users will only encounter these states in edge cases. For example:

  • the server responds to STARTTLS with NO or BAD, etc
  • the TLS handshake fails
  • during callbacks user may have added to their ssl_ctx

Previously, the existance of `ssl_ctx` would cause `TLS (NOT VERIFIED)`
to be printed.  But that isn't quite right: `ssl_ctx` is assigned
immediately, before sending the `STARTTLS` command, before calling
`start_tls_session`, and before `start_tls_session` returns.  And those
intermediate states are important distinctions for debugging TLS issues.

So this updates `Net::IMAP#inspect` with two new TLS/PLAINTEXT states:
* `PLAINTEXT (TLS NOT STARTED)`, when:
  * `#starttls` has been called (`@ssl_ctx` has been set),
  * but `#start_tls_session` hasn't (`@sock` is a `TCPSocket`).
* `TLS (NOT ESTABLISHED)`, when:
  * `#start_tls_session` was called (`@sock` is an `SSLSocket`),
  * but hasn't returned successfully (`@sock.session` isn't available).
@nevans nevans added the enhancement New feature or request label May 7, 2026
@nevans nevans merged commit 69988ed into master May 7, 2026
39 checks passed
@nevans nevans deleted the improved-inspect-tls-state branch May 7, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant