Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Net::POP3#enable_starttls for support STARTTLS #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

krhitoshi
Copy link

@krhitoshi krhitoshi commented Jun 9, 2024

The Net::POP3#enable_starttls method supports the POP3 STARTTLS extension [RFC 2595].

I believe it is valuable to offer a secure option for port 110 access because there are still many servers that support STARTTLS.
My own motivation for this feature is to ensure the correct settings for the POP servers I have set up.

I have tried to keep this PR as concise as possible.

I chose the term starttls instead of startssl because the STLS command means STARTTLS.

Net::POP3#enable_starttls shares @ssl_params with Net::POP3#enable_ssl (pop3s) to reduce code changes.

Its usage is the same as Net::POP3#enable_ssl.
Net::POP3#enable_starttls must also be called before the connection is established.

Example:

pop = Net::POP3.new("pop.example.com")
pop.set_debug_output $stderr
pop.enable_starttls
pop.start("account", "password") do |c|
  c.mails
end

Example session:

POP session started: pop.example.com: (POP)
-> "+OK Dovecot ready.\r\n"
<- "STLS\r\n"
-> "+OK Begin TLS negotiation now.\r\n"
<- "USER account\r\n"
-> "+OK\r\n"
<- "PASS password\r\n"
-> "+OK Logged in.\r\n"
<- "STAT\r\n"
-> "+OK 9 7191\r\n"
<- "LIST\r\n"
-> "+OK 9 messages:\r\n"
-> "1 1097\r\n"
… (omitted)
-> "9 750\r\n"
-> ".\r\n"
<- "QUIT\r\n"
-> "+OK Logging out.\r\n"

(I wish I could implement a feature where Net::POP3#enable_starttls can be called after the connection.
However, I decided against it because Net::POP3#start includes the authentication process, and implementing such a feature would require more extensive code changes.)

Regarding tests, I was unsure how to test TLS connections, so I only added tests for the default ports.

Thank you for maintaining this useful gem!

@krhitoshi krhitoshi marked this pull request as ready for review June 9, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant