Class: Mail::Ruby18
- Inherits:
-
Object
- Object
- Mail::Ruby18
- Defined in:
- lib/mail/version_specific/ruby_1_8.rb
Class Method Summary collapse
- .b_value_decode(str) ⇒ Object
- .b_value_encode(str, encoding) ⇒ Object
- .bracket(str) ⇒ Object
- .decode_base64(str) ⇒ Object
- .encode_base64(str) ⇒ Object
- .escape_bracket(str) ⇒ Object
-
.escape_paren(str) ⇒ Object
Escapes any parenthesis in a string that are unescaped.
- .get_constant(klass, string) ⇒ Object
- .has_constant?(klass, string) ⇒ Boolean
- .param_decode(str, encoding) ⇒ Object
- .param_encode(str) ⇒ Object
- .paren(str) ⇒ Object
- .q_value_decode(str) ⇒ Object
- .q_value_encode(str, encoding) ⇒ Object
Class Method Details
.b_value_decode(str) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 62 def Ruby18.b_value_decode(str) match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m) if match encoding = match[1] str = Ruby18.decode_base64(match[2]) end str end |
.b_value_encode(str, encoding) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 55 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), encoding] end |
.bracket(str) ⇒ Object
33 34 35 36 37 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 33 def Ruby18.bracket( str ) str = $1 if str =~ /^\<(.*)?\>$/ str = escape_bracket( str ) '<' + str + '>' end |
.decode_base64(str) ⇒ Object
39 40 41 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 39 def Ruby18.decode_base64(str) Base64.decode64(str) end |
.encode_base64(str) ⇒ Object
43 44 45 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 43 def Ruby18.encode_base64(str) Base64.encode64(str) end |
.escape_bracket(str) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 24 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 |
.escape_paren(str) ⇒ Object
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
9 10 11 12 13 14 15 16 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 9 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 |
.get_constant(klass, string) ⇒ Object
51 52 53 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 51 def Ruby18.get_constant(klass, string) klass.const_get( string ) end |
.has_constant?(klass, string) ⇒ Boolean
47 48 49 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 47 def Ruby18.has_constant?(klass, string) klass.constants.include?( string ) end |
.param_decode(str, encoding) ⇒ Object
87 88 89 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 87 def Ruby18.param_decode(str, encoding) URI.unescape(str) end |
.param_encode(str) ⇒ Object
91 92 93 94 95 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 91 def Ruby18.param_encode(str) encoding = $KCODE.to_s.downcase language = Configuration.instance.param_encode_language "#{encoding}'#{language}'#{URI.escape(str)}" end |
.paren(str) ⇒ Object
18 19 20 21 22 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 18 def Ruby18.paren( str ) str = $1 if str =~ /^\((.*)?\)$/ str = escape_paren( str ) '(' + str + ')' end |
.q_value_decode(str) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 78 def Ruby18.q_value_decode(str) match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m) if match encoding = match[1] str = Encodings::QuotedPrintable.decode(match[2]) end str end |
.q_value_encode(str, encoding) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/mail/version_specific/ruby_1_8.rb', line 71 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 |