[#2529] concerns about Proc,lambda,block — "David A. Black" <dblack@...>
Hi --
>>>>> "D" == David A Black <dblack@wobblini.net> writes:
Hi --
Hi,
On Tue, 2 Mar 2004 08:44:25 +0900, Yukihiro Matsumoto wrote:
Hi,
On Wednesday, 3 March 2004 at 8:00:09 +0900, Yukihiro Matsumoto wrote:
Hi,
Hi,
On Wed, Mar 03, 2004 at 07:51:10AM +0900, Yukihiro Matsumoto wrote:
Hi,
On Thu, 4 Mar 2004, Yukihiro Matsumoto wrote:
Hi,
[#2575] Comment football being played... with lib/test/unit.rb — Nathaniel Talbott <nathaniel@...>
[Resent because I accidentally signed it the first time]
[#2577] problem with Net::HTTP in 1.8.1 — Ian Macdonald <ian@...>
Hello,
Hi,
[#2582] One more proc question — Dave Thomas <dave@...>
Sorry about this... :)
Hi,
On Friday, 5 March 2004 at 12:52:15 +0900, Yukihiro Matsumoto wrote:
Hi,
[#2588] Duck typing chapter — Dave Thomas <dave@...>
I've posted a rough first pass at a chapter about duck typing (and
[#2606] Thought about class definitions — Dave Thomas <dave@...>
If we allowed
[#2628] YAML complaint while generating RDoc — Dave Thomas <dave@...>
With the latest CVS, I get
[#2640] patch to tempfile.rb to handle ENAMETOOLONG — Joel VanderWerf <vjoel@...>
[#2644] RDoc proporsal — "H.Yamamoto" <ocean@...2.ccsnet.ne.jp>
Hi, rubyists.
[#2646] Problems rdoc'ing cvs... — Hugh Sasse Staff Elec Eng <hgs@...>
I have just done
On Friday, March 12, 2004, 4:15:42 AM, Dave wrote:
On Fri, 12 Mar 2004, Dave Thomas wrote:
[#2661] Pathological slowdown in 1.8 — Ryan Davis <ryand@...>
Hi all,
[#2697] lib/ruby/1.9/yaml.rb:193: [BUG] Segmentation fault — Mauricio Fern疣dez <batsman.geo@...>
Mauricio Fern疣dez wrote:
On Sun, Mar 28, 2004 at 09:42:42AM +0900, why the lucky stiff wrote:
[#2703] Proposed patch to add SSL support to net/pop.rb — Daniel Hobe <daniel@...>
This patch adds support to Net::POP for doing POP over SSL. Modeled on how
This is v2 of the patch. Cleaned up a bit and added some more docs.
v3 of the patch:
Hi,
I agree that there are a lot of arguments to #start, but I think it is the
On Tue, 30 Mar 2004 16:24:17 +0900, Daniel Hobe wrote:
On Wed, 31 Mar 2004 13:27:31 +0900, Daniel Hobe wrote:
On Tue, Mar 30, 2004 at 04:05:06PM +0900, Minero Aoki wrote:
[#2709] typos in lib/singleton.rb — Ian Macdonald <ian@...>
Hello,
[#2713] more spelling and grammar fixes — Ian Macdonald <ian@...>
Hello,
> Hello,
Hi,
Re: Proposed patch to add SSL support to net/pop.rb
v3 of the patch: A few more cleanups. I've tested this against the courier POP server but not with APOP. -- Daniel Hobe <daniel@nightrunner.com> http://www.nightrunner.com
Attachments (1)
--- /home/hobe/downloads/ruby/ruby/lib/net/pop.rb 2004-03-25 19:38:12.000000000 -0800
+++ pop.rb 2004-03-27 18:26:03.000000000 -0800
@@ -141,10 +141,25 @@
#
# # Use APOP authentication if $isapop == true
# pop = Net::POP3.APOP($is_apop).new('apop.example.com', 110)
-# pop.start(YourAccount', 'YourPassword') {|pop|
+# pop.start('YourAccount', 'YourPassword') {|pop|
# # Rest code is same.
# }
-#
+#
+# === Using SSL
+# The net/pop library supports POP3 over SSL.
+# See documentaion of Net::POP3.new() for argument descriptions
+# To use SSL:
+#
+# require 'net/pop'
+#
+#
+# pop = Net::POP3.start('pop.example.com', 995,
+# 'YourAccount', 'YourPassword',false,true,
+# '/etc/ssl/certs',OpenSSL::SSL::VERIFY_PEER) {|pop|
+# # Rest code is same.
+# }
+#
+#
# === Fetch Only Selected Mail Using `UIDL' POP Command
#
# If your POP server provides UIDL functionality,
@@ -170,6 +185,11 @@
require 'digest/md5'
require 'timeout'
+begin
+ require "openssl"
+rescue LoadError
+end
+
module Net
# Non-authentication POP3 protocol error
@@ -200,6 +220,11 @@
def POP3.default_port
110
end
+
+ # The default port for POP3S connections, port 995
+ def POP3.default_ssl_port
+ 995
+ end
def POP3.socket_type #:nodoc: obsolete
Net::InternetMessageIO
@@ -228,7 +253,8 @@
# yielding it to the +block+.
# This method is equivalent to:
#
- # Net::POP3.start(address, port, account, password) {|pop|
+ # Net::POP3.start(address, port, account, password,
+ # isapop, usessl, certs, verify) {|pop|
# pop.each_mail do |m|
# yield m
# end
@@ -245,8 +271,10 @@
#
def POP3.foreach( address, port = nil,
account = nil, password = nil,
- isapop = false, &block ) # :yields: message
- start(address, port, account, password, isapop) {|pop|
+ isapop = false, usessl = false, certs = nil,
+ verify = nil, &block ) # :yields: message
+ start(address, port, account, password, isapop, usessl, certs, verify) {
+ |pop|
pop.each_mail(&block)
}
end
@@ -265,8 +293,10 @@
#
def POP3.delete_all( address, port = nil,
account = nil, password = nil,
- isapop = false, &block )
- start(address, port, account, password, isapop) {|pop|
+ isapop = false, usessl = false, certs = nil,
+ verify = nil, &block )
+ start(address, port, account, password, isapop, usessl, certs, verify) {
+ |pop|
pop.delete_all(&block)
}
end
@@ -282,11 +312,18 @@
# # Example 2: APOP
# Net::POP3.auth_only('pop.example.com', 110,
# 'YourAccount', 'YourPassword', true)
- #
+ #
+ # # Example 3: POP over SSL
+ # Net::POP3.auth_only('pop.example.com', 995,
+ # 'YourAccount', 'YourPassword',false,true,
+ # '/etc/ssl/certs',OpenSSL::SSL::VERIFY_PEER)
+ #
def POP3.auth_only( address, port = nil,
account = nil, password = nil,
- isapop = false )
- new(address, port, isapop).auth_only account, password
+ isapop = false, usessl = false, certs = nil,
+ verify = nil)
+ new(address, port, isapop, usessl, certs, verify).auth_only(
+ account, password)
end
# Starts a pop3 session, attempts authentication, and quits.
@@ -294,7 +331,7 @@
# This method raises POPAuthenticationError if authentication fails.
def auth_only( account, password )
raise IOError, 'opening already opened POP session' if started?
- start(account, password) {
+ start( account, password ) {
;
}
end
@@ -304,7 +341,7 @@
#
# Creates a new POP3 object and open the connection. Equivalent to
- # Net::POP3.new(address, port, isapop).start(account, password)
+ # Net::POP3.new(address, port, isapop, usessl, certs, verify).start(account, password)
#
# If +block+ is provided, yields the newly-opened POP3 object to it,
# and automatically closes it at the end of the session.
@@ -320,21 +357,41 @@
#
def POP3.start( address, port = nil,
account = nil, password = nil,
- isapop = false, &block ) # :yield: pop
- new(address, port, isapop).start(account, password, &block)
+ isapop = false, usessl = false, certs = nil,
+ verify = nil, &block ) # :yield: pop
+ new(address, port, isapop, usessl, certs, verify).start(
+ account, password, &block)
end
# Creates a new POP3 object.
- # +address+ is the hostname or ip address of your POP3 server.
- # The optional +port+ is the port to connect to; it defaults to 110.
+ # +addr+ is the hostname or ip address of your POP3 server.
+ # The optional +port+ is the port to connect to; it defaults to 110 or 995
+ # if +usessl+ = +true+.
# The optional +isapop+ specifies whether this connection is going
# to use APOP authentication; it defaults to +false+.
+ # The optional +usessl+ specifies whether to use ssl to connect to the
+ # POP3 server; it defaults to +false+.
+ # The optional +certs+ indicates the path or file containing the CA
+ # cert of the server; it defaults to +nil+.
+ # The optional +verify+ parameter determines what kind of verification to
+ # perform on the server certificate; it defaults to
+ # OpenSSL::SSL::VERIFY_PEER.
# This method does *not* open the TCP connection.
- def initialize( addr, port = nil, isapop = false )
+ def initialize( addr, port = nil, isapop = false,
+ usessl = false, certs = nil, verify = nil)
+
@address = addr
- @port = port || self.class.default_port
+ @usessl = usessl
+ if port
+ @port = port
+ else
+ @usessl ? self.class.default_ssl_port : self.class.default_port
+ end
@apop = isapop
-
+
+ @certs = certs
+ @verify = verify
+
@command = nil
@socket = nil
@started = false
@@ -425,9 +482,23 @@
end
def do_start( account, password )
- @socket = InternetMessageIO.new(timeout(@open_timeout) {
- TCPSocket.open(@address, @port)
- })
+ s = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
+ if @usessl
+ unless defined?(OpenSSL)
+ raise "SSL extension not installed"
+ end
+ sslctx = OpenSSL::SSL::SSLContext.new
+ @verify = OpenSSL::SSL::VERIFY_PEER if @verify.nil?
+ sslctx.verify_mode = @verify
+ sslctx.ca_file = @certs if @certs && FileTest::file?(@certs)
+ sslctx.ca_path = @certs if @certs && FileTest::directory?(@certs)
+ s = OpenSSL::SSL::SSLSocket.new(s, sslctx)
+ s.sync_close = true
+ s.connect
+ end
+
+ @socket = InternetMessageIO.new(s)
+
logging "POP session started: #{@address}:#{@port} (#{@apop ? 'APOP' : 'POP'})"
@socket.read_timeout = @read_timeout
@socket.debug_output = @debug_output