rails/actionmailbox

Turn all the mail_ext additions into upstream PRs

Opened this issue · 3 comments

dhh commented

We have a range of convenience and ergonomic improvements to Mail in mail_ext. Would be great to get them into a future version of Mail, so we don't have to carry the monkey patches on our vest.

I wanted to give a hand with this issue, I then realized that @jeremy was assigned. So if it is any help here is a patch that would upstream address_equality.rb to https://github.com/mikel/mail:

diff --git a/lib/mail/elements/address.rb b/lib/mail/elements/address.rb
index edf7235..8371303 100644
--- a/lib/mail/elements/address.rb
+++ b/lib/mail/elements/address.rb
@@ -178,6 +178,10 @@ module Mail
       @data && @data.group
     end

+    def ==(other_address)
+      other_address.is_a?(Mail::Address) && to_s == other_address.to_s
+    end
+
     private

     def parse(value = nil)
diff --git a/spec/mail/elements/address_spec.rb b/spec/mail/elements/address_spec.rb
index c5e5ab8..b0bec06 100644
--- a/spec/mail/elements/address_spec.rb
+++ b/spec/mail/elements/address_spec.rb
@@ -166,6 +166,16 @@ describe Mail::Address do
       expect(Mail::Address.new(junk).format).to eq junk
     end

+    it "is equal to another address instance with the same value" do
+      a = Mail::Address.new('Mikel Lindsaar <test@lindsaar.net>')
+      b = Mail::Address.new('Mikel Lindsaar <test@lindsaar.net>')
+      expect(a).to eq(b)
+    end
+
+    it "is equal to itself" do
+      a = Mail::Address.new('Mikel Lindsaar <test@lindsaar.net>')
+      expect(a).to eq(a)
+    end
   end

   describe "assigning values directly" do

Thanks @orhantoy! Would you please submit a pull request to https://github.com/mikel/mail/pulls?

mikel commented

This sounds great @dhh, @jeremy and @orhantoy