Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/mime-version-capitalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikel authored Nov 30, 2022
2 parents 68a5fac + 6c43c9b commit 2191975
Show file tree
Hide file tree
Showing 93 changed files with 254 additions and 122 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,19 @@ Compatibility:

Features:

* Updated README to improve around sending multipart mail @kapfenho
* Add delivery_interceptors method to Mail class to fetch registered interceptors @ghousemohamed

Code Improvements:

* Use Rake's default rakelib/ directory @olleolleolle
* refactor: Use Dir.glob only once in gemspec's "files" directive @olleolleolle
* Configure RSpec's zero-monkey patching mode @olleolleolle

Bug Fixes:

* Regression: Preserve message-level charset when adding parts (related to Rails ActionMailer) @shields
* Regression: Adding a part should not reset the mail's charset to nil @railsbob


Please check [2-8-stable](https://github.com/mikel/mail/blob/2-8-stable/CHANGELOG.rdoc) for previous changes.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ gem 'jruby-openssl', :platforms => :jruby
gem 'mini_mime'

gem 'byebug', :platforms => :mri

gem "strscan", ">= 3.0.2.pre1"
105 changes: 75 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,21 @@ simple as possible.... (asking a lot from a mail library)

```ruby
mail = Mail.deliver do
to '[email protected]'
from 'Mikel Lindsaar <[email protected]>'
subject 'First multipart email sent with Mail'

text_part do
body 'This is plain text'
end

html_part do
content_type 'text/html; charset=UTF-8'
body '<h1>This is HTML</h1>'
part :content_type => "multipart/mixed" do |p1|
p1.part :content_type => "multipart/related" do |p2|
p2.part :content_type => "multipart/alternative",
:content_disposition => "inline" do |p3|
p3.part :content_type => "text/plain; charset=utf-8",
:body => "Here is the attachment you wanted\n"
p3.part :content_type => "text/html; charset=utf-8",
:body => "<h1>Funky Title</h1><p>Here is the attachment you wanted</p>\n"
end
end
add_file '/path/to/myfile.pdf'
end
from "Mikel Lindsaar <[email protected]>"
to "[email protected]"
subject "First multipart email sent with Mail"
end
```

Expand All @@ -425,34 +428,76 @@ so desire...
```
puts mail.to_s #=>
To: [email protected]
Date: Tue, 26 Apr 2022 20:12:07 +0200
From: Mikel Lindsaar <[email protected]>
To: [email protected]
Message-ID: <[email protected]>
Subject: First multipart email sent with Mail
Content-Type: multipart/alternative;
boundary=--==_mimepart_4a914f0c911be_6f0f1ab8026659
Message-ID: <[email protected]>
Date: Mon, 24 Aug 2009 00:15:46 +1000
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=\"--==_mimepart_626835f733867_10873fdfa3c2ffd494636\";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_4a914f0c911be_6f0f1ab8026659
Content-ID: <[email protected]>
Date: Mon, 24 Aug 2009 00:15:46 +1000
MIME-Version: 1.0
Content-Type: text/plain
----==_mimepart_626835f733867_10873fdfa3c2ffd494636
Content-Type: multipart/mixed;
boundary=\"--==_mimepart_626835f73382a_10873fdfa3c2ffd494518\";
charset=UTF-8
Content-Transfer-Encoding: 7bit
This is plain text
----==_mimepart_4a914f0c911be_6f0f1ab8026659
Content-Type: text/html; charset=UTF-8
Content-ID: <[email protected]>
Date: Mon, 24 Aug 2009 00:15:46 +1000
MIME-Version: 1.0
----==_mimepart_626835f73382a_10873fdfa3c2ffd494518
Content-Type: multipart/related;
boundary=\"--==_mimepart_626835f7337f5_10873fdfa3c2ffd494438\";
charset=UTF-8
Content-Transfer-Encoding: 7bit
<h1>This is HTML</h1>
----==_mimepart_4a914f0c911be_6f0f1ab8026659--
----==_mimepart_626835f7337f5_10873fdfa3c2ffd494438
Content-Type: multipart/alternative;
boundary=\"--==_mimepart_626835f733702_10873fdfa3c2ffd494376\";
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content-ID: <[email protected]>
----==_mimepart_626835f733702_10873fdfa3c2ffd494376
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: 7bit
Here is the attachment you wanted
----==_mimepart_626835f733702_10873fdfa3c2ffd494376
Content-Type: text/html;
charset=utf-8
Content-Transfer-Encoding: 7bit
<h1>Funky Title</h1><p>Here is the attachment you wanted</p>
----==_mimepart_626835f733702_10873fdfa3c2ffd494376--
----==_mimepart_626835f7337f5_10873fdfa3c2ffd494438--
----==_mimepart_626835f73382a_10873fdfa3c2ffd494518--
----==_mimepart_626835f733867_10873fdfa3c2ffd494636
Content-Type: text/plain;
charset=UTF-8;
filename=myfile.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=myfile.txt
Content-ID: <6
[email protected]>
Hallo,
Test
End
----==_mimepart_626835f733867_10873fdfa3c2ffd494636--
```

Mail inserts the content transfer encoding, the mime version,
Expand Down Expand Up @@ -602,7 +647,7 @@ Mail.defaults do
delivery_method :test # in practice you'd do this in spec_helper.rb
end

describe "sending an email" do
RSpec.describe "sending an email" do
include Mail::Matchers

before(:each) do
Expand Down
3 changes: 0 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ RSpec::Core::RakeTask.new(:spec) do |t|
t.ruby_opts = '-w'
t.rspec_opts = %w(--backtrace --color)
end

# load custom rake tasks
Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].sort.each { |ext| load ext }
5 changes: 5 additions & 0 deletions lib/mail/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def self.inform_interceptors(mail)
end
end

# Returns a list of registered delivery interceptors.
def self.delivery_interceptors
@@delivery_interceptors
end

protected

RANDOM_TAG='%x%x_%x%x%d%x'
Expand Down
8 changes: 6 additions & 2 deletions lib/mail/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,7 @@ def mime_type
# Returns the character set defined in the content type field
def charset
if @header
has_content_type? ? content_type_parameters['charset'] : @charset
has_content_type? && !multipart? ? content_type_parameters['charset'] : @charset
else
@charset
end
Expand Down Expand Up @@ -2066,7 +2066,11 @@ def add_multipart_alternate_header

def add_boundary
unless body.boundary && boundary
header['content-type'] = 'multipart/mixed' unless header['content-type']
unless header['content-type']
_charset = charset
header['content-type'] = 'multipart/mixed'
header['content-type'].parameters[:charset] = _charset
end
header['content-type'].parameters[:boundary] = ContentTypeField.generate_boundary
body.boundary = boundary
end
Expand Down
2 changes: 1 addition & 1 deletion mail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Gem::Specification.new do |s|
s.add_development_dependency('rdoc')
s.add_development_dependency('rufo')

s.files = %w[ README.md MIT-LICENSE ] + Dir.glob("lib/**/*")
s.files = Dir.glob(%w[ README.md MIT-LICENSE lib/**/* ])
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions spec/mail/attachments_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def check_decoded(actual, expected)
expect(actual).to eq expected.dup.force_encoding(Encoding::BINARY)
end

describe "Attachments" do
RSpec.describe "Attachments" do

before(:each) do
@mail = Mail.new
Expand Down Expand Up @@ -211,7 +211,7 @@ def check_decoded(actual, expected)

end

describe "reading emails with attachments" do
RSpec.describe "reading emails with attachments" do
describe "test emails" do

it "should find the attachment using content location" do
Expand Down Expand Up @@ -311,7 +311,7 @@ def check_decoded(actual, expected)
end
end

describe "attachment order" do
RSpec.describe "attachment order" do
it "should be preserved instead when content type exists" do
mail = Mail.new do
to "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Body do
RSpec.describe Mail::Body do

# 3.5 Overall message syntax
#
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(values)
end
end

describe Mail::Configuration do
RSpec.describe Mail::Configuration do

describe "network configurations" do

Expand Down
2 changes: 1 addition & 1 deletion spec/mail/core_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# frozen_string_literal: true
require 'spec_helper'

describe Object do
RSpec.describe Object do

end
2 changes: 1 addition & 1 deletion spec/mail/elements/address_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::AddressList do
RSpec.describe Mail::AddressList do

describe "parsing" do
it "should parse an address list" do
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/elements/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Address do
RSpec.describe Mail::Address do

describe "functionality" do

Expand Down
2 changes: 1 addition & 1 deletion spec/mail/elements/date_time_element_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::DateTimeElement do
RSpec.describe Mail::DateTimeElement do

it "should parse a date" do
date_text = 'Wed, 27 Apr 2005 14:15:31 -0700'
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/elements/envelope_from_element_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::EnvelopeFromElement do
RSpec.describe Mail::EnvelopeFromElement do

describe "parsing a from envelope string" do
it "should parse a full field" do
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/elements/message_ids_element_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::MessageIdsElement do
RSpec.describe Mail::MessageIdsElement do

it "should parse a message_id" do
msg_id_text = '<[email protected]>'
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/elements/phrase_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::PhraseList do
RSpec.describe Mail::PhraseList do

describe "parsing" do
it "should parse a phrase list" do
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/elements/received_element_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::ReceivedElement do
RSpec.describe Mail::ReceivedElement do

it "should raise an error if the input is nil" do
received = Mail::ReceivedElement.new(nil)
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/encoding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe "mail encoding" do
RSpec.describe "mail encoding" do

it "should allow you to assign an email-wide charset" do
mail = Mail.new
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/encodings/base64_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Encodings::Base64 do
RSpec.describe Mail::Encodings::Base64 do

it "should encode base 64 from text" do
result = "VGhpcyBpcyBhIHRlc3Q=\r\n"
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/encodings/quoted_printable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Encodings::QuotedPrintable do
RSpec.describe Mail::Encodings::QuotedPrintable do

it "should encode quoted printable from text" do
result = "This is\r\na test=\r\n"
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/encodings/transfer_encoding_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Encodings::TransferEncoding do
RSpec.describe Mail::Encodings::TransferEncoding do
it "accepts blank message_encoding" do
expect(described_class.negotiate('', '7bit', '')).to eq Mail::Encodings::SevenBit
expect(described_class.negotiate('', '8bit', '')).to eq Mail::Encodings::EightBit
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/encodings/unix_to_unix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Encodings::UnixToUnix do
RSpec.describe Mail::Encodings::UnixToUnix do
def decode(str)
Mail::Encodings::UnixToUnix.decode(str)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/mail/encodings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::Encodings do
RSpec.describe Mail::Encodings do

describe "base64 Encoding" do

Expand Down
2 changes: 1 addition & 1 deletion spec/mail/example_emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe "Test emails" do
RSpec.describe "Test emails" do

describe "from RFC2822" do

Expand Down
2 changes: 1 addition & 1 deletion spec/mail/field_list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'

describe Mail::FieldList do
RSpec.describe Mail::FieldList do
it "should be able to add new fields" do
fl = Mail::FieldList.new
fl << Mail::Field.parse("To: [email protected]")
Expand Down
Loading

0 comments on commit 2191975

Please sign in to comment.