Parent

Class Index [+]

Quicksearch

Mail::Ruby19

Public Class Methods

b_value_decode(str) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 51
51:     def Ruby19.b_value_decode(str)
52:       match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/)
53:       if match
54:         encoding = match[1]
55:         str = Ruby19.decode_base64(match[2])
56:         str.force_encoding(fix_encoding(encoding))
57:       end
58:       decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
59:       decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
60:     end
b_value_encode(str, encoding = nil) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 46
46:     def Ruby19.b_value_encode(str, encoding = nil)
47:       encoding = str.encoding.to_s
48:       [Ruby19.encode_base64(str), encoding]
49:     end
bracket( str ) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 24
24:     def Ruby19.bracket( str )
25:       str = $1 if str =~ /^\<(.*)?\>$/
26:       str = escape_bracket( str )
27:       '<' + str + '>'
28:     end
decode_base64(str) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 30
30:     def Ruby19.decode_base64(str)
31:       str.unpack( 'm' ).first
32:     end
encode_base64(str) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 34
34:     def Ruby19.encode_base64(str)
35:       [str].pack( 'm' )
36:     end
escape_bracket( str ) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 19
19:     def Ruby19.escape_bracket( str )
20:       re = /(?<!\\)([\<\>])/          # Only match unescaped brackets
21:       str.gsub(re) { |s| '\' + s }
22:     end
escape_paren( str ) click to toggle source

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

    # File lib/mail/version_specific/ruby_1_9.rb, line 8
 8:     def Ruby19.escape_paren( str )
 9:       re = /(?<!\\)([\(\)])/          # Only match unescaped parens
10:       str.gsub(re) { |s| '\' + s }
11:     end
fix_encoding(encoding) click to toggle source

mails somtimes includes invalid encodings like iso885915 or utf8 so we transform them to iso885915 or utf8 TODO: add this as a test somewhere Encoding.list.map{|e| [e.to_s.upcase==fix_encoding(e.to_s.downcase.gsub(“-”, “”)), e.to_s] }.select {|a,b| !b}

 Encoding.list.map{|e| [e.to_s==fix_encoding(e.to_s), e.to_s] }.select {|a,b| !b}
     # File lib/mail/version_specific/ruby_1_9.rb, line 98
 98:     def Ruby19.fix_encoding(encoding)
 99:       case encoding
100:         # ISO-8859-15, ISO-2022-JP and alike
101:         when /iso-?(\d{4})-?(\w{1,2})/ then return "ISO-#{$1}-#{$2}"
102:         # "ISO-2022-JP-KDDI"  and alike
103:         when /iso-?(\d{4})-?(\w{1,2})-?(\w*)/ then return "ISO-#{$1}-#{$2}-#{$3}"
104:         # UTF-8, UTF-32BE and alike
105:         when /utf-?(\d{1,2})?(\w{1,2})/ then return "UTF-#{$1}#{$2}".gsub(/\A(UTF-(?:16|32))\z/, '\1BE')
106:         # Windows-1252 and alike
107:         when /Windows-?(.*)/ then return "Windows-#{$1}"
108:         #more aliases to be added if needed
109:         else return encoding
110:       end
111:     end
get_constant(klass, string) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 42
42:     def Ruby19.get_constant(klass, string)
43:       klass.const_get( string )
44:     end
has_constant?(klass, string) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 38
38:     def Ruby19.has_constant?(klass, string)
39:       klass.const_defined?( string, false )
40:     end
param_decode(str, encoding) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 78
78:     def Ruby19.param_decode(str, encoding)
79:       string = uri_parser.unescape(str)
80:       string.force_encoding(encoding) if encoding
81:       string
82:     end
param_encode(str) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 84
84:     def Ruby19.param_encode(str)
85:       encoding = str.encoding.to_s.downcase
86:       language = Configuration.instance.param_encode_language
87:       "#{encoding}'#{language}'#{uri_parser.escape(str)}"
88:     end
paren( str ) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 13
13:     def Ruby19.paren( str )
14:       str = $1 if str =~ /^\((.*)?\)$/
15:       str = escape_paren( str )
16:       '(' + str + ')'
17:     end
q_value_decode(str) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 67
67:     def Ruby19.q_value_decode(str)
68:       match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/)
69:       if match
70:         encoding = match[1]
71:         str = Encodings::QuotedPrintable.decode(match[2].gsub(/_/, '=20'))
72:         str.force_encoding(fix_encoding(encoding))
73:       end
74:       decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
75:       decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
76:     end
q_value_encode(str, encoding = nil) click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 62
62:     def Ruby19.q_value_encode(str, encoding = nil)
63:       encoding = str.encoding.to_s
64:       [Encodings::QuotedPrintable.encode(str), encoding]
65:     end
uri_parser() click to toggle source
    # File lib/mail/version_specific/ruby_1_9.rb, line 90
90:     def Ruby19.uri_parser
91:       @uri_parser ||= URI::Parser.new
92:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.