Class: Mail::Ruby18

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

Class Method Summary (collapse)

Class Method Details

+ (Object) b_value_decode(str)



64
65
66
67
68
69
70
71
72
# File 'lib/mail/version_specific/ruby_1_8.rb', line 64

def Ruby18.b_value_decode(str)
  match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
  if match
    encoding = match[1]
    str = Ruby18.decode_base64(match[2])
    str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str)
  end
  str
end

+ (Object) b_value_encode(str, encoding)

Raises:

  • (ArgumentError)


57
58
59
60
61
62
# File 'lib/mail/version_specific/ruby_1_8.rb', line 57

def Ruby18.b_value_encode(str, encoding)
  # Ruby 1.8 requires an encoding to work
  raise ArgumentError, "Must supply an encoding" if encoding.nil?
  encoding = encoding.to_s.upcase.gsub('_', '-')
  [Encodings::Base64.encode(str), fix_encoding(encoding)]
end

+ (Object) bracket(str)



35
36
37
38
39
# File 'lib/mail/version_specific/ruby_1_8.rb', line 35

def Ruby18.bracket( str )
  str = $1 if str =~ /^\<(.*)?\>$/
  str = escape_bracket( str )
  '<' + str + '>'
end

+ (Object) decode_base64(str)



41
42
43
# File 'lib/mail/version_specific/ruby_1_8.rb', line 41

def Ruby18.decode_base64(str)
  Base64.decode64(str) if str
end

+ (Object) encode_base64(str)



45
46
47
# File 'lib/mail/version_specific/ruby_1_8.rb', line 45

def Ruby18.encode_base64(str)
  Base64.encode64(str)
end

+ (Object) escape_bracket(str)



26
27
28
29
30
31
32
33
# File 'lib/mail/version_specific/ruby_1_8.rb', line 26

def Ruby18.escape_bracket( str )
  re = /\\\>/
  str = str.gsub(re) { |s| '>'}
  re = /\\\</
  str = str.gsub(re) { |s| '<'}
  re = /([\<\>])/          # Only match unescaped parens
  str.gsub(re) { |s| '\\' + s }
end

+ (Object) escape_paren(str)

Escapes any parenthesis in a string that are unescaped. This can't use the Ruby 1.9.1 regexp feature of negative look behind so we have to do two replacement, first unescape everything, then re-escape it



11
12
13
14
15
16
17
18
# File 'lib/mail/version_specific/ruby_1_8.rb', line 11

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

+ (Object) get_constant(klass, string)



53
54
55
# File 'lib/mail/version_specific/ruby_1_8.rb', line 53

def Ruby18.get_constant(klass, string)
  klass.const_get( string )
end

+ (Boolean) has_constant?(klass, string)



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

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

+ (Object) param_decode(str, encoding)



94
95
96
# File 'lib/mail/version_specific/ruby_1_8.rb', line 94

def Ruby18.param_decode(str, encoding)
  URI.unescape(str)
end

+ (Object) param_encode(str)



98
99
100
101
102
# File 'lib/mail/version_specific/ruby_1_8.rb', line 98

def Ruby18.param_encode(str)
  encoding = $KCODE.to_s.downcase
  language = Configuration.instance.param_encode_language
  "#{encoding}'#{language}'#{URI.escape(str)}"
end

+ (Object) paren(str)



20
21
22
23
24
# File 'lib/mail/version_specific/ruby_1_8.rb', line 20

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

+ (Object) q_value_decode(str)



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mail/version_specific/ruby_1_8.rb', line 81

def Ruby18.q_value_decode(str)
  match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
  if match
    encoding = match[1]
    string = match[2].gsub(/_/, '=20')
    # Remove trailing = if it exists in a Q encoding
    string = string.sub(/\=$/, '')
    str = Encodings::QuotedPrintable.decode(string)
    str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str)
  end
  str
end

+ (Object) q_value_encode(str, encoding)

Raises:

  • (ArgumentError)


74
75
76
77
78
79
# File 'lib/mail/version_specific/ruby_1_8.rb', line 74

def Ruby18.q_value_encode(str, encoding)
  # Ruby 1.8 requires an encoding to work
  raise ArgumentError, "Must supply an encoding" if encoding.nil?
  encoding = encoding.to_s.upcase.gsub('_', '-')
  [Encodings::QuotedPrintable.encode(str), encoding]
end