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



50
51
52
53
54
55
56
57
58
# File 'lib/mail/version_specific/ruby_1_9.rb', line 50

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



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

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

.bracket(str) ⇒ Object



23
24
25
26
27
# File 'lib/mail/version_specific/ruby_1_9.rb', line 23

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

.decode_base64(str) ⇒ Object



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

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

.encode_base64(str) ⇒ Object



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

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

.escape_bracket(str) ⇒ Object



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

def Ruby19.escape_bracket( str )
  re = /(?<!\\)([\<\>])/          # Only match unescaped brackets
  str.gsub(re) { |s| '\\' + s }
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



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

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

.has_constant?(klass, string) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/mail/version_specific/ruby_1_9.rb', line 37

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

.param_decode(str, encoding) ⇒ Object



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

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

.param_encode(str) ⇒ Object



81
82
83
84
85
# File 'lib/mail/version_specific/ruby_1_9.rb', line 81

def Ruby19.param_encode(str)
  encoding = str.encoding.to_s.downcase
  language = 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



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

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



60
61
62
63
# File 'lib/mail/version_specific/ruby_1_9.rb', line 60

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