lib/hermeneutics/escape.rb
def unmask cs, tp, txt
        case tp.upcase
          when "B" then                    txt, = txt.unpack "m*"
          when "Q" then txt.tr! "_", " " ; txt, = txt.unpack "M*"
        end
        cs.slice! /\*\w+\z/    # language as in rfc2231, 5.
        case cs
          when /\Autf-?7\z/i then
            # Ruby doesn't seem to do that.
            txt.force_encoding Encoding::US_ASCII
            txt.gsub! /\+([0-9a-zA-Z+\/]*)-?/ do
              if $1.empty? then
                "+"
              else
                s = ("#$1==".unpack "m*").join
                (s.unpack "S>*").map { |x| x.chr Encoding::UTF_8 }.join
              end
            end
            txt.force_encoding Encoding::UTF_8
          when /\Aunknown/i then
            txt.force_encoding Encoding::US_ASCII
          else
            txt.force_encoding cs
        end
        txt
      end
# The standard header content encoding has a word break limit of 64.
#
The standard header content encoding has a word break limit of 64.
The standard header content encoding has a word break limit of 64 .
def unmask cs, tp, txt
        case tp.upcase
          when "B" then                    txt, = txt.unpack "m*"
          when "Q" then txt.tr! "_", " " ; txt, = txt.unpack "M*"
        end
        cs.slice! /\*\w+\z/    
        case cs
          when /\Autf-?7\z/i then
            txt.force_encoding Encoding::US_ASCII
            txt.gsub! /\+([0-9a-zA-Z+\/]*)-?/ do
              if $1.empty? then
                "+"
              else
                s = ("#$1==".unpack "m*").join
                (s.unpack "S>*").map { |x| x.chr Encoding::UTF_8 }.join
              end
            end
            txt.force_encoding Encoding::UTF_8
          when /\Aunknown/i then
            txt.force_encoding Encoding::US_ASCII
          else
            txt.force_encoding cs
        end
        txt
      end
def unmask cs , tp , txt case tp . upcase when "B" then txt , = txt . unpack "m*" when "Q" then txt . tr! "_" , " " ; txt , = txt . unpack "M*" end cs . slice! / \* \w + \z / case cs when / \A utf-?7 \z /i then txt . force_encoding Encoding :: US_ASCII txt . gsub! / \+ ([0-9a-zA-Z+ \/ ]*)-? / do if $1 . empty? then "+" else s = ( "#$1==" . unpack "m*" ) . join ( s . unpack "S>*" ) . map { | x | x . chr Encoding :: UTF_8 } . join end end txt . force_encoding Encoding :: UTF_8 when / \A unknown /i then txt . force_encoding Encoding :: US_ASCII else txt . force_encoding cs end txt end
The standard header content encoding has a word break limit of 64.
The standard header content encoding has a word break limit of 64 .
# language as in rfc2231, 5. # Ruby doesn't seem to do that.
cs
tp
txt