delete from hateblo.jp where 1=1;

タイトルに意味はありません。

redmineにメールでファイルを添付すると化ける件についての対応

リビジョン 3859時点のパッチだから、今はもう使えないかもしれない or 本家で対応済みかもしれない
今後同じ事案が発生したとき、もう1回調べて書かないといけないから、ゴミを残しておく。

Index: app/models/attachment.rb
Method: sanitize_filename

===================================================================
--- app/models/attachment.rb    (リビジョン 3859)
+++ app/models/attachment.rb    (作業コピー)
@@ -168,6 +168,22 @@
     # NOTE: File.basename doesn't work right with Windows paths on Unix
     # INCORRECT: just_filename = File.basename(value.gsub('\\\\', '/')) 
 
+    if m = just_filename.match('^=\\?([A-Za-z0-9\\-]+)\\?([A-Za-z0-9])\\?(.+)\\?=')
+      #just_filename = Base64.decode_b(just_filename)
+      case m[2].downcase
+      when 'b'
+        #filename_encoded = Base64.decode_b(m[3])
+        filename_encoded = m[3].unpack("m")[0]
+      else
+        filename_encoded = m[3].unpack("M")[0]
+      end
+      begin
+        just_filename = Iconv.conv('UTF-8', m[1], filename_encoded)
+      rescue Iconv::Failure
+        # do nothing here and try the next encoding
+      end
+    end
+
     # Finally, replace all non alphanumeric, hyphens or periods with underscore
     @filename = just_filename.gsub(/[^\w\.\-]/,'_') 
   end
参考文献