From: zimba-tm Date: 2005-12-03T11:28:35+09:00 Subject: POP3 and SMTP with SSL support ------=_Part_5996_12113177.1133576909329 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello ruby-talk, recently, I wanted to use ruby to connect to my gmail accout. Gmail supports POP3S and SMTP with TLS authentication. Ruby's stdlib don't support OpenSSL for those protocols. It was pretty easy to add SSL support to POP3. There was a working version for ruby 1.6 found on this ML, and I just had to adapt it. I have joined a working example to this email for interested people. It doesn't support specified certificates, so it's pretty useless for real security. All happy, I thought that it would be that easy for SMTP. My bad. SMTP doesn't work the same way. Here's the RFC : http://www.ietf.org/rfc/rfc2487.txt What I want, is start a thread on this subject here. It looks like ruby's support to those protocols is not complete. Is it worth starting a new project on rubyforge ? Would those changes be integrated in the stdlib ? I'm ready to get a bit involved here, but I would need some help from other people too. -- Cheers, zimba http://zimba.oree.ch ------=_Part_5996_12113177.1133576909329 Content-Type: application/octet-stream; name=pop3s.rb Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="pop3s.rb" # by Minero Aoki require 'net/pop' require 'protocols' module Net class POP3s < POP3 def POP3s.default_port 995 end def POP3s.socket_type Net::InternetMessageIOs end end end =begin require 'net/pop' require 'ssl' module Net class POP3S < POP3 def POP3S.default_port 995 end def POP3S.socket_type Net::SSLSocket end def on_connect @socket.ssl_connect end end end =end ------=_Part_5996_12113177.1133576909329 Content-Type: application/octet-stream; name=protocols.rb Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="protocols.rb" require 'openssl' module Net class InternetMessageIOs < InternetMessageIO def connect( open_timeout ) super ctx = OpenSSL::SSL::SSLContext.new('SSLv23') ctx.key = nil ctx.cert = nil @socket = OpenSSL::SSL::SSLSocket.new(@socket, ctx) @socket.connect return '' end end end ------=_Part_5996_12113177.1133576909329 Content-Type: application/octet-stream; name=fetchmail.rb Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fetchmail.rb" require 'pop3s' username = 'zimba.tm' password = '********' pop = Net::POP3s.new('pop.googlemail.com') pop.start(username, password) # (1) if pop.mails.empty? puts 'No mail.' else i = 0 pop.mails.each do |m| # or "pop.mails.each ..." # (2) puts m.to_s + " " File.open("inbox/#{i}", 'w') do |f| f.write m.pop end m.delete i += 1 end puts "#{pop.mails.size} mails popped." end pop.finish ------=_Part_5996_12113177.1133576909329--