Skip to content

Commit

Permalink
Drop support for rubies under 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Apr 19, 2022
1 parent 6e5db59 commit c08d569
Show file tree
Hide file tree
Showing 42 changed files with 195 additions and 1,002 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ jobs:
fail-fast: false
matrix:
include:
- docker-image: 'silvioq/ruby-1.8.7'
bundler-version: '1.17.3'
- docker-image: 'library/ruby:1.9'
bundler-version: '1.17.3'
- docker-image: 'library/ruby:2.0'
bundler-version: '1.17.3'
- docker-image: 'library/ruby:2.2'
bundler-version: '1.17.3'
- docker-image: 'library/ruby:2.3'
- docker-image: 'library/ruby:2.4'
- docker-image: 'library/ruby:2.5'
- docker-image: 'library/ruby:2.6'
- docker-image: 'library/ruby:2.7'
Expand All @@ -33,8 +23,6 @@ jobs:
container: ${{ matrix.docker-image }}
steps:
- uses: actions/checkout@v2
- name: Install bundler ${{ matrix.bundler-version }}
run: gem install bundler ${{ matrix.bundler-version && format('{0} {1}', '-v', matrix.bundler-version) || '' }}
- name: Install dependencies
run: bundle install
- name: Run tests
Expand Down
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ pull request merged quickly:
5. Add a spec for your change. Only refactoring and documentation changes
require no new specs. If you are adding functionality or fixing a bug, we need
a spec!
6. Test the spec _at_ _least_ against MRI-1.9.3 and MRI-1.8.7
6. Test the spec on supported rubies.
7. Update the README if needed to reflect your change / addition
8. Update the CHANGELOG and give yourself credit
9. With all specs passing push your changes back to your fork
10. Send me a pull request.
- If it needs any changes, please push or force push to the same branch you made the pull request from. GitHub will just update the pull request with your changes.

Note, specs that break MRI 1.8.7 or 1.9.3 will not be accepted.

At this point you're waiting on us. We like to at least comment on, if not
accept, pull requests within three business days (and, typically, one business
day). We may suggest some changes or improvements or alternatives.
Expand Down
25 changes: 2 additions & 23 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,14 @@ source 'https://rubygems.org'

gemspec

# For testing against ActiveSupport::Multibyte::Chars
if RUBY_VERSION < '1.9.3'
gem 'activesupport', '< 4'
gem 'i18n', '< 0.7'
elsif RUBY_VERSION < '2.2.2'
gem 'activesupport', '< 5'
elsif RUBY_VERSION < '2.7.0'
if RUBY_VERSION < '2.7.0'
gem 'activesupport', '< 6'
else
gem 'activesupport', :git => 'https://github.com/rails/rails', :branch => 'main'
end

gem 'tlsmail', '~> 0.0.1' if RUBY_VERSION <= '1.8.6'
gem 'jruby-openssl', :platforms => :jruby

gem 'rufo', '< 0.4' if RUBY_VERSION < '2.3.5'
gem 'rake', '< 11.0' if RUBY_VERSION < '1.9.3'
if RUBY_VERSION < '2.0'
gem 'rdoc', '< 4.3'
elsif RUBY_VERSION < '2.2.2'
gem 'rdoc', '< 6'
end

gem 'mini_mime'

if RUBY_VERSION >= '2.0'
gem 'byebug', :platforms => :mri
elsif RUBY_VERSION >= '1.9'
gem 'debugger', :platforms => :mri
else
gem 'ruby-debug', :platforms => :mri
end
gem 'byebug', :platforms => :mri
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ implementation that makes generating, sending and parsing email a no
brainer.

It is also designed from the ground up to work with the more modern versions
of Ruby. This is because Ruby > 1.9 handles text encodings much more wonderfully
than Ruby 1.8.x and so these features have been taken full advantage of in this
library allowing Mail to handle a lot more messages more cleanly than TMail.
Mail does run on Ruby 1.8.x... it's just not as fun to code.
of Ruby. Modern Rubies handle text encodings much more wonderfully than before
so these features have been taken full advantage of in this library allowing
Mail to handle a lot more messages more cleanly than TMail.

Finally, Mail has been designed with a very simple object oriented system
that really opens up the email messages you are parsing, if you know what
Expand Down Expand Up @@ -48,7 +47,7 @@ our documentation, add new features—up to you! Thank you for pitching in.

## Compatibility

Mail supports Ruby 1.8.7+, including JRuby and Rubinius.
Mail supports Ruby 2.5+, including JRuby and Rubinius.

Every Mail commit is tested by GitHub Actions on [all supported Ruby versions](https://github.com/mikel/mail/blob/master/.github/workflows/test.yml).

Expand Down
19 changes: 2 additions & 17 deletions lib/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,11 @@ module Mail # :doc:
require 'net/smtp'
require 'mini_mime'

if RUBY_VERSION <= '1.8.6'
begin
require 'tlsmail'
rescue LoadError
raise "You need to install tlsmail if you are using ruby <= 1.8.6"
end
end

if RUBY_VERSION >= "1.9.0"
require 'mail/version_specific/ruby_1_9'
RubyVer = Ruby19
else
require 'mail/version_specific/ruby_1_8'
RubyVer = Ruby18
end
require 'mail/version_specific/ruby_1_9'
RubyVer = Ruby19

require 'mail/version'

require 'mail/core_extensions/string'
require 'mail/core_extensions/smtp'
require 'mail/indifferent_hash'

require 'mail/multibyte'
Expand Down
5 changes: 1 addition & 4 deletions lib/mail/attachments_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ def guess_encoding
end

def set_mime_type(filename)
# Have to do this because MIME::Types is not Ruby 1.9 safe yet
if RUBY_VERSION >= '1.9'
filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
end
filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)

@mime_type = MiniMime.lookup_by_filename(filename)
@mime_type && @mime_type.content_type
Expand Down
28 changes: 0 additions & 28 deletions lib/mail/core_extensions/smtp.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/mail/core_extensions/string.rb

This file was deleted.

71 changes: 21 additions & 50 deletions lib/mail/encodings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def Encodings.transcode_charset(str, from_charset, to_charset = 'UTF-8')
# param_encode_language 'jp'
# end
#
# The character set used for encoding will either be the value of $KCODE for
# Ruby < 1.9 or the encoding on the string passed in.
# The character set used for encoding will be the encoding on the string passed in.
#
# Example:
#
Expand Down Expand Up @@ -99,8 +98,8 @@ def Encodings.param_decode(str, encoding)
# the =?<encoding>?[QB]?<string>?=" format.
#
# The output type needs to be :decode to decode the input string or :encode to
# encode the input string. The character set used for encoding will either be
# the value of $KCODE for Ruby < 1.9 or the encoding on the string passed in.
# encode the input string. The character set used for encoding will be the
# encoding on the string passed in.
#
# On encoding, will only send out Base64 encoded strings.
def Encodings.decode_encode(str, output_type)
Expand All @@ -111,7 +110,7 @@ def Encodings.decode_encode(str, output_type)
if str.ascii_only?
str
else
Encodings.b_value_encode(str, find_encoding(str))
Encodings.b_value_encode(str, str.encoding)
end
end
end
Expand Down Expand Up @@ -145,13 +144,8 @@ def Encodings.unquote_and_convert_to(str, to_encoding)
output
elsif to_encoding
begin
if RUBY_VERSION >= '1.9'
output.encode(to_encoding)
else
require 'iconv'
Iconv.iconv(to_encoding, 'UTF-8', output).first
end
rescue Iconv::IllegalSequence, Iconv::InvalidEncoding, Errno::EINVAL
output.encode(to_encoding)
rescue Errno::EINVAL
# the 'from' parameter specifies a charset other than what the text
# actually is...not much we can do in this case but just return the
# unconverted text.
Expand All @@ -176,42 +170,23 @@ def Encodings.address_encode(address, charset = 'utf-8')
def Encodings.encode_non_usascii(address, charset)
return address if address.ascii_only? or charset.nil?

# With KCODE=u we can't use regexps on other encodings. Go ASCII.
with_ascii_kcode do
# Encode all strings embedded inside of quotes
address = address.gsub(/("[^"]*[^\/]")/) { |s| Encodings.b_value_encode(unquote(s), charset) }

# Then loop through all remaining items and encode as needed
tokens = address.split(/\s/)

map_with_index(tokens) do |word, i|
if word.ascii_only?
word
else
previous_non_ascii = i>0 && tokens[i-1] && !tokens[i-1].ascii_only?
if previous_non_ascii #why are we adding an extra space here?
word = " #{word}"
end
Encodings.b_value_encode(word, charset)
end
end.join(' ')
end
end
# Encode all strings embedded inside of quotes
address = address.gsub(/("[^"]*[^\/]")/) { |s| Encodings.b_value_encode(unquote(s), charset) }

# Then loop through all remaining items and encode as needed
tokens = address.split(/\s/)

if RUBY_VERSION < '1.9'
# With KCODE=u we can't use regexps on other encodings. Go ASCII.
def Encodings.with_ascii_kcode #:nodoc:
if $KCODE
$KCODE, original_kcode = '', $KCODE
map_with_index(tokens) do |word, i|
if word.ascii_only?
word
else
previous_non_ascii = i>0 && tokens[i-1] && !tokens[i-1].ascii_only?
if previous_non_ascii #why are we adding an extra space here?
word = " #{word}"
end
Encodings.b_value_encode(word, charset)
end
yield
ensure
$KCODE = original_kcode if original_kcode
end
else
def Encodings.with_ascii_kcode #:nodoc:
yield
end
end.join(' ')
end

# Encode a string with Base64 Encoding and returns it ready to be inserted
Expand Down Expand Up @@ -270,10 +245,6 @@ def Encodings.q_value_decode(str)
RubyVer.q_value_decode(str)
end

def Encodings.find_encoding(str)
RUBY_VERSION >= '1.9' ? str.encoding : $KCODE
end

# Gets the encoding type (Q or B) from the string.
def Encodings.value_encoding_from_string(str)
str[ENCODED_VALUE, 1]
Expand Down
10 changes: 2 additions & 8 deletions lib/mail/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,8 @@ def method_missing(name, *args, &block)
field.send(name, *args, &block)
end

if RUBY_VERSION >= '1.9.2'
def respond_to_missing?(method_name, include_private)
field.respond_to?(method_name, include_private) || super
end
else
def respond_to?(method_name, include_private = false)
field.respond_to?(method_name, include_private) || super
end
def respond_to_missing?(method_name, include_private)
field.respond_to?(method_name, include_private) || super
end

FIELD_ORDER_LOOKUP = Hash[%w[
Expand Down
6 changes: 1 addition & 5 deletions lib/mail/fields/unstructured_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def initialize(name, value, charset = nil)
charset ||=
if value.respond_to?(:encoding)
value.encoding
elsif RUBY_VERSION < '1.9'
$KCODE
end

super name, value.to_s, charset
Expand Down Expand Up @@ -186,9 +184,7 @@ def encode_crlf(value)
end

def normalized_encoding
encoding = charset.to_s.upcase.gsub('_', '-')
encoding = 'UTF-8' if encoding == 'UTF8' # Ruby 1.8.x and $KCODE == 'u'
encoding
charset.to_s.upcase.gsub('_', '-')
end
end
end
2 changes: 1 addition & 1 deletion lib/mail/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def initialize(*args, &block)
# m.to '[email protected]'
# end
if block_given?
if block.arity.zero? || (RUBY_VERSION < '1.9' && block.arity < 1)
if block.arity.zero?
instance_eval(&block)
else
yield self
Expand Down
Loading

0 comments on commit c08d569

Please sign in to comment.