aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-12-06 13:53:50 -0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-12-06 13:53:50 -0800
commit731bfa7cf45b8b849e63990d933fc65a14a6b860 (patch)
tree0953a7e63b7288a3ee729de02ac2f6d1f9c44d65
parenta1d449e061d163fc0f6cb8c966d9ebf70923b665 (diff)
downloadrails-731bfa7cf45b8b849e63990d933fc65a14a6b860.tar.gz
rails-731bfa7cf45b8b849e63990d933fc65a14a6b860.tar.bz2
rails-731bfa7cf45b8b849e63990d933fc65a14a6b860.zip
Add address wrapping
Makes it easier to deal with addresses that may already have been converted
-rw-r--r--lib/action_mailbox/mail_ext/address_wrapping.rb5
-rw-r--r--test/unit/mail_ext/address_wrapping_test.rb11
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/action_mailbox/mail_ext/address_wrapping.rb b/lib/action_mailbox/mail_ext/address_wrapping.rb
new file mode 100644
index 0000000000..f41087a450
--- /dev/null
+++ b/lib/action_mailbox/mail_ext/address_wrapping.rb
@@ -0,0 +1,5 @@
+class Mail::Address
+ def self.wrap(address)
+ address.is_a?(Mail::Address) ? address : Mail::Address.new(address)
+ end
+end
diff --git a/test/unit/mail_ext/address_wrapping_test.rb b/test/unit/mail_ext/address_wrapping_test.rb
new file mode 100644
index 0000000000..6baa360f3e
--- /dev/null
+++ b/test/unit/mail_ext/address_wrapping_test.rb
@@ -0,0 +1,11 @@
+require_relative '../../test_helper'
+
+module MailExt
+ class AddressWrappingTest < ActiveSupport::TestCase
+ test "wrap" do
+ needing_wrapping = Mail::Address.wrap("david@basecamp.com")
+ wrapping_not_needed = Mail::Address.wrap(Mail::Address.new("david@basecamp.com"))
+ assert_equal needing_wrapping.address, wrapping_not_needed.address
+ end
+ end
+end