ScarletのRuby1.8対応

これまでのあらすじ

昨日の自宅Debianサーバのdist-upgradeでRubyのバージョンが1.6→1.8と一気に上がってしまいました。
これによって、Scarletというメールサーバシステムが動作しなくなってしまいました。
Scarlet

なんに使えるかというと、代表アドレスによる携帯電話アドレスの完全な隠蔽や、コンテンツサイズの削減など色々面白いんじゃないかと思います。

解決編

最近rubyをはじめたばかりなのでよくわかってないのですが、1.6→1.8ってかなり言語仕様が変わったみたいですね。
周辺ライブラリのAPIも変わってるので修正が大変でした…。

最終的に以下のパッチを当てれば動作するようになりました。

Scarlet/deffile.rb
--- deffile.rb  2006-01-04 22:13:23.000000000 +0900
+++ deffile.rb  2006-01-04 23:18:23.000000000 +0900
@@ -72,7 +72,8 @@
     @data = Hash.new()
     begin
       File.open( filename, "r" ).each do |line|
-       next if line =~ /^#/
+       next if line.strip =~ /^$/  # 空行
+       next if line.strip =~ /^#/  # コメント行
        anArray = line.chomp.split( "\t" )
        key = anArray.shift
        @entry.push( key )
Scarlet/scarlet.rb
--- scarlet.rb  2006-01-04 00:25:33.000000000 +0900
+++ scarlet.rb  2006-01-05 00:08:18.000000000 +0900
@@ -312,8 +312,7 @@
       @ql = logQueue
       mainLoop() if ( @qc.pop() == "start" )
     rescue
-      log( SEV_FATAL, "Detected an exception. Stopping ... #{ $! }\n" <<
-       $@.join( "\n" ))
+      log( SEV_FATAL, "Detected an exception. Stopping ... #{ $! }\n" << $@.join( "\n" ))
     end
   end

@@ -404,7 +403,7 @@

       # Parse.
       @mail = SCMail.new( STDIN )
-      log( SEV_INFO, "A mail arrived from '#{ @mail.searchHeader( \"from\" )[0] }' to '#{ @mail.searchHeader( \"to\" )[0] }'." )
+      log( SEV_INFO, "A mail arrived from '" + @mail.searchHeader( "from" )[0] + "' to '" + @mail.searchHeader( "to" )[0] + "'." )

       # Check loop mail.
       if ( @mail.loop?( @sysName ))
@@ -477,8 +476,7 @@
       end

     rescue
-      log( SEV_FATAL, "Detected an exception. Stopping ... #{ $! }\n" <<
-       $@.join( "\n" ))
+      log( SEV_FATAL, "Detected an exception. Stopping ... #{ $! }\n" << $@.join( "\n" ))
     end

     # Any mailer should not return the status 'non-0'.
@@ -509,7 +507,7 @@
          result = ( @mail.searchHeader( attr ).size != 0 )
        else
          @mail.searchHeader( attr ).each do |v|
-           result = true if ( v =~ Regexp::quote( value ))
+           result = true if ( v =~ Regexp::new( Regexp::quote( value ) ) )
          end
        end
        return false if ( notFlag && result ) or ( !notFlag && !result )
@@ -546,30 +544,27 @@
       end

       # Sending message(s) as the result of the cascading operation.
-      logQueue.push([ SEV_INFO,
-       "(dispatch) Took #{ mail.size } message(s). Sending..." ])
+      logQueue.push([ SEV_INFO, "(dispatch) Took #{ mail.size } message(s). Sending..." ])
       mail.each do |aMail|
        mailQueue.push( aMail )
       end

     rescue
-      logQueue.push([ SEV_FATAL,
-       "(dispatch) Detected an exception. Stopping ... #{ $! }\n" <<
-       $@.join( "\n" ) ])
+      logQueue.push([ SEV_FATAL, "(dispatch) Detected an exception. Stopping ... #{ $! }\n" << $@.join( "\n" ) ])
       return
     end
   end

   def parseCondition( cond )
-    CSV::parse( cond )
+    CSV::parse_line( cond )
   end

   def parseOperation( op )
-    CSV::parse( op )
+    CSV::parse_line( op )
   end

   def parseArg( arg )
-    CSV::parse( arg )
+    CSV::parse_line( arg )
   end
 end

@@ -644,12 +639,12 @@

   public
   def SCOp.encode64( str )
-    TMail::HFencoder.encode( str )
+    str # do nothing
   end

   public
   def SCOp.decode64( str )
-    TMail::HFdecoder.decode( str )
+    str # do nothing
   end
 end
Scarlet/op/map_from.rb
--- map_from.rb 2006-01-04 23:49:11.000000000 +0900
+++ map_from.rb 2006-01-04 23:49:39.000000000 +0900
@@ -43,7 +43,7 @@
       next if ( !addr or !mapStr )
       mail.each do |aMail|
        from = aMail.searchHeader( "from" )[0]
-       if ( from =~ Regexp::quote( addr ))
+       if ( from =~ Regexp::new( Regexp::quote( addr ) ) )
          aMail.removeHeader( "from" )
          aMail.addHeader( "From", SCOp::encode64( mapStr ))
          nofMap += 1

んー、試してみたらなんかうまくパッチがあたらないな。

 $ diff -u (修正前ファイル) (修正後ファイル) > (パッチファイル)

でパッチを作って、

 $ patch < (パッチファイル)

であてるんじゃなかったけ?

Hunk #1 FAILED at 43.
1 out of 1 hunk FAILED -- saving rejects to file map_from.rb.rej

とかいって怒られるな。まぁいいや。