+require 'thread'
require 'lockfile'
require 'mime/types'
require 'pathname'
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
a = Message.new
a.header.add "Content-Disposition", "attachment; filename=#{filename.inspect}"
a.header.add "Content-Type", "#{mime_type}; name=#{filename.inspect}"
- a.header.add "Content-Transfer-Encoding", encoding
+ a.header.add "Content-Transfer-Encoding", encoding if encoding
a.body =
case encoding
when "base64"
[payload].pack "m"
when "quoted-printable"
[payload].pack "M"
- when "7bit", "8bit"
+ when "7bit", "8bit", nil
payload
else
- raise EncodingUnsupportedError, t.encoding
+ raise EncodingUnsupportedError, encoding.inspect
end
a
end
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