Sha256: 1f217e49f9196d74dcef94190dd3948baca5a91b94f5e5f3f9eb7d0887152344

Contents?: true

Size: 1.95 KB

Versions: 18

Compression:

Stored size: 1.95 KB

Contents

# encoding: utf-8
module Mail
  class Ruby19

    # Escapes any parenthesis in a string that are unescaped this uses
    # a Ruby 1.9.1 regexp feature of negative look behind
    def Ruby19.escape_paren( str )
      re = /(?<!\\)([\(\)])/          # Only match unescaped parens
      str.gsub(re) { |s| '\\' + s }
    end

    def Ruby19.paren( str )
      str = $1 if str =~ /^\((.*)?\)$/
      str = escape_paren( str )
      '(' + str + ')'
    end
    
    def Ruby19.decode_base64(str)
      str.unpack( 'm' ).first.force_encoding(Encoding::BINARY)
    end
    
    def Ruby19.encode_base64(str)
      [str].pack( 'm' )
    end
    
    def Ruby19.has_constant?(klass, string)
      klass.constants.include?( string.to_sym )
    end
    
    def Ruby19.get_constant(klass, string)
      klass.const_get( string.to_sym )
    end
    
    def Ruby19.b_value_encode(str, encoding = nil)
      encoding = str.encoding.to_s
      [Ruby19.encode_base64(str), encoding]
    end
    
    def Ruby19.b_value_decode(str)
      match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
      if match
        encoding = match[1]
        str = Ruby19.decode_base64(match[2])
        str.force_encoding(encoding)
      end
      str
    end
    
    def Ruby19.q_value_encode(str, encoding = nil)
      encoding = str.encoding.to_s
      [Encodings::QuotedPrintable.encode(str), encoding]
    end

    def Ruby19.q_value_decode(str)
      match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
      if match
        encoding = match[1]
        str = Encodings::QuotedPrintable.decode(match[2])
        str.force_encoding(encoding)
      end
      str
    end

    def Ruby19.param_decode(str, encoding)
      string = URI.unescape(str)
      string.force_encoding(encoding) if encoding
      string
    end

    def Ruby19.param_encode(str)
      encoding = str.encoding.to_s.downcase
      language = Mail::Configuration.instance.param_encode_language
      "#{encoding}'#{language}'#{URI.escape(str)}"
    end

  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
mail-2.1.3 lib/mail/version_specific/ruby_1_9.rb
kbaum-mail-2.1.2.1 lib/mail/version_specific/ruby_1_9.rb
mail-2.1.2 lib/mail/version_specific/ruby_1_9.rb
mail-2.1.1 lib/mail/version_specific/ruby_1_9.rb
mail-2.1.0 lib/mail/version_specific/ruby_1_9.rb
mail-2.0.5 lib/mail/version_specific/ruby_1_9.rb
mail-2.0.3 lib/mail/version_specific/ruby_1_9.rb
mail-1.6.0 lib/mail/version_specific/ruby_1_9.rb
mail-1.5.4 lib/mail/version_specific/ruby_1_9.rb
mail-1.5.3 lib/mail/version_specific/ruby_1_9.rb
mail-1.5.2 lib/mail/version_specific/ruby_1_9.rb
mail-1.5.1 lib/mail/version_specific/ruby_1_9.rb
mail-1.5.0 lib/mail/version_specific/ruby_1_9.rb
mail-1.4.3 lib/mail/version_specific/ruby_1_9.rb
mail-1.4.2 lib/mail/version_specific/ruby_1_9.rb
mail-1.4.1 lib/mail/version_specific/ruby_1_9.rb
mail-1.4.0 lib/mail/version_specific/ruby_1_9.rb
mail-1.3.5 lib/mail/version_specific/ruby_1_9.rb