1999-01-19 23:59:39 -05:00
|
|
|
require "kconv"
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
def decode64(str)
|
|
|
|
str.unpack("m")[0]
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def decode_b(str)
|
|
|
|
str.gsub!(/=\?ISO-2022-JP\?B\?([!->@-~]+)\?=/i) {
|
|
|
|
decode64($1)
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
str = Kconv::toeuc(str)
|
|
|
|
str.gsub!(/=\?SHIFT_JIS\?B\?([!->@-~]+)\?=/i) {
|
|
|
|
decode64($1)
|
|
|
|
}
|
|
|
|
str = Kconv::toeuc(str)
|
1998-01-16 07:13:05 -05:00
|
|
|
str.gsub!(/\n/, ' ')
|
|
|
|
str.gsub!(/\0/, '')
|
1999-01-19 23:59:39 -05:00
|
|
|
str
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def encode64(bin)
|
1999-01-19 23:59:39 -05:00
|
|
|
[bin].pack("m")
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def b64encode(bin, len = 60)
|
|
|
|
encode64(bin).scan(/.{1,#{len}}/o) do
|
|
|
|
print $&, "\n"
|
|
|
|
end
|
|
|
|
end
|