[#41778] [Bug #3515] FreeBSD wrongly raises ECONNRESET on close(2) — Yui NARUSE <redmine@...>

Bug #3515: FreeBSD wrongly raises ECONNRESET on close(2)

12 messages 2010/07/02

[ruby-dev:41889] [Feature:trunk] improvement of sample in lib/imap.rb: password input

From: Nobuyoshi Nakada <nobu@...>
Date: 2010-07-29 03:17:59 UTC
List: ruby-dev #41889
なかだです。

lib/net/imap.rbを直接実行すると使える簡易IMAPクライアントを、パ
スワードの入力にIO#noechoを使うようにしてみました。また、実際に
必要になるまでパスワードの入力を遅らせるようにもしています。


Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 28780)
+++ lib/net/imap.rb	(working copy)
@@ -3485,12 +3485,27 @@
   end

+  begin
+    require 'io/console'
+  rescue LoadError
+    def _noecho(&block)
+      system("stty", "-echo")
+      begin
+        yield STDIN
+      ensure
+        system("stty", "echo")
+      end
+    end
+  else
+    def _noecho(&block)
+      STDIN.noecho(&block)
+    end
+  end
+
   def get_password
     print "password: "
-    system("stty", "-echo")
     begin
-      return gets.chop
+      return _noecho(&:gets).chomp
     ensure
-      system("stty", "echo")
-      print "\n"
+      puts
     end
   end
@@ -3543,5 +3558,7 @@
   imap = Net::IMAP.new($host, :port => $port, :ssl => $ssl)
   begin
-    password = get_password
+    class << password = method(:get_password)
+      alias to_str call
+    end
     imap.authenticate($auth, $user, password)
     while true


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next