Class: Mail::Ruby19

Inherits:
Object
  • Object
show all
Defined in:
lib/mail/version_specific/ruby_1_9.rb

Class Method Summary collapse

Class Method Details

.b_value_decode(str) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/mail/version_specific/ruby_1_9.rb', line 39

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

.b_value_encode(str, encoding = nil) ⇒ Object



34
35
36
37
# File 'lib/mail/version_specific/ruby_1_9.rb', line 34

def Ruby19.b_value_encode(str, encoding = nil)
  encoding = str.encoding.to_s
  [Ruby19.encode_base64(str), encoding]
end

.decode_base64(str) ⇒ Object



18
19
20
# File 'lib/mail/version_specific/ruby_1_9.rb', line 18

def Ruby19.decode_base64(str)
  str.unpack( 'm' ).first.force_encoding(Encoding::BINARY)
end

.encode_base64(str) ⇒ Object



22
23
24
# File 'lib/mail/version_specific/ruby_1_9.rb', line 22

def Ruby19.encode_base64(str)
  [str].pack( 'm' )
end

.escape_paren(str) ⇒ Object

Escapes any parenthesis in a string that are unescaped this uses a Ruby 1.9.1 regexp feature of negative look behind



7
8
9
10
# File 'lib/mail/version_specific/ruby_1_9.rb', line 7

def Ruby19.escape_paren( str )
  re = /(?<!\\)([\(\)])/          # Only match unescaped parens
  str.gsub(re) { |s| '\\' + s }
end

.get_constant(klass, string) ⇒ Object



30
31
32
# File 'lib/mail/version_specific/ruby_1_9.rb', line 30

def Ruby19.get_constant(klass, string)
  klass.const_get( string.to_sym )
end

.has_constant?(klass, string) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/mail/version_specific/ruby_1_9.rb', line 26

def Ruby19.has_constant?(klass, string)
  klass.constants.include?( string.to_sym )
end

.param_decode(str, encoding) ⇒ Object



64
65
66
67
68
# File 'lib/mail/version_specific/ruby_1_9.rb', line 64

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

.param_encode(str) ⇒ Object



70
71
72
73
74
# File 'lib/mail/version_specific/ruby_1_9.rb', line 70

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

.paren(str) ⇒ Object



12
13
14
15
16
# File 'lib/mail/version_specific/ruby_1_9.rb', line 12

def Ruby19.paren( str )
  str = $1 if str =~ /^\((.*)?\)$/
  str = escape_paren( str )
  '(' + str + ')'
end

.q_value_decode(str) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/mail/version_specific/ruby_1_9.rb', line 54

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

.q_value_encode(str, encoding = nil) ⇒ Object



49
50
51
52
# File 'lib/mail/version_specific/ruby_1_9.rb', line 49

def Ruby19.q_value_encode(str, encoding = nil)
  encoding = str.encoding.to_s
  [Encodings::QuotedPrintable.encode(str), encoding]
end