]> git.cworth.org Git - sup/blobdiff - lib/sup/util.rb
Merge branches 'prev-next-improv', 'fix-warnings', 'mime-view', 'charset', 'join...
[sup] / lib / sup / util.rb
index 2164e858c7721daa43e7eadc50a8cc3e9c69320b..ceaf0b8dabc8a83ea451005e9b27bc109823caf1 100644 (file)
@@ -1,3 +1,4 @@
+require 'thread'
 require 'lockfile'
 require 'mime/types'
 require 'pathname'
@@ -61,7 +62,7 @@ module RMail
     end
 
     def charset
-      if header.field?("content-type") && header.fetch("content-type") =~ /charset="?(.*?)"?(;|$)/
+      if header.field?("content-type") && header.fetch("content-type") =~ /charset="?(.*?)"?(;|$)/i
         $1
       end
     end
@@ -600,3 +601,15 @@ class OrderedHash < Hash
   def each; @keys.each { |k| yield k, self[k] } end
 end
 
+## easy thread-safe class for determining who's the "winner" in a race (i.e.
+## first person to hit the finish line
+class FinishLine
+  def initialize
+    @m = Mutex.new
+    @over = false
+  end
+
+  def winner?
+    @m.synchronize { !@over && @over = true }
+  end
+end