Skip to content

Commit

Permalink
Better patch for ruby-1.8.6 support without slowing down more modern …
Browse files Browse the repository at this point in the history
…rubies
  • Loading branch information
dball committed Oct 26, 2010
1 parent 2331907 commit 6cbfd9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/mail/encodings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def Encodings.encode_non_usascii(address, charset)
def Encodings.b_value_encode(str, encoding = nil)
return str if str.to_s.ascii_only?
string, encoding = RubyVer.b_value_encode(str, encoding)
lines(string).map do |str|
map_lines(string) do |str|
"=?#{encoding}?B?#{str.chomp}?="
end.join(" ")
end
Expand All @@ -225,7 +225,7 @@ def Encodings.q_value_encode(str, encoding = nil)
return str if str.to_s.ascii_only?
string, encoding = RubyVer.q_value_encode(str, encoding)
string.gsub!("=\r\n", '') # We already have limited the string to the length we want
lines(string).map do |str|
map_lines(string) do |str|
"=?#{encoding}?Q?#{str.chomp.gsub(/ /, '_')}?="
end.join(" ")
end
Expand Down
38 changes: 26 additions & 12 deletions lib/mail/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,35 @@ def underscoreize( str )
str.to_s.downcase.gsub('-', '_')
end

def lines( str )
results = []
str.each_line do |line|
results << line
if RUBY_VERSION <= '1.8.6'

def map_lines( str, &block )
results = []
str.each_line do |line|
results << yield(line)
end
results
end
results
end

def map_with_index( enum, &block )
results = []
enum.each_with_index do |token, i|
results[i] = yield(token, i)
end
results
end

else

def map_with_index( enum, &block )
results = []
enum.each_with_index do |token, i|
results[i] = yield(token, i)
def map_lines( str, &block )
str.each_line.map(&block)
end
results

def map_with_index( enum, &block )
enum.each_with_index.map(&block)
end

end

end
end

0 comments on commit 6cbfd9b

Please sign in to comment.