Skip to content

Commit

Permalink
Handle email when written with %2B instead of + (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbevp authored Nov 16, 2023
1 parent 7777a0b commit 02d9633
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/mailboxes/newsletter_mailbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ def recipients
# NOTE: `mail.received` can be an instance of `Mail::ReceivedField` or an array of instances
received = Array.wrap(mail.received).first&.decoded&.match(/<([a-z@\d\.\-\+]+)>/i)
arr.push(received[1]) if received.present?
arr
arr.map { |email| email.gsub('%2B', '+') }
end
end
15 changes: 15 additions & 0 deletions test/mailboxes/newsletter_mailbox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ class NewsletterMailboxTest < ActionMailbox::TestCase
assert_equal 'Hello world!', Entry.last.title
end

test 'should find newsletter if plus was written as `%2B`' do
assert_difference 'Entry.count' do
receive_inbound_email_from_mail do |mail|
mail.to '[email protected]'
mail.cc = "newsletter-#{@newsletter.id}%2B#{@newsletter.public_id}@example.com"
mail.from '"me" <[email protected]>'
mail.subject 'Hello world!'
mail.body 'Hello?'
end
end

assert_equal 'me <[email protected]>', Entry.last.author
assert_equal 'Hello world!', Entry.last.title
end

test 'should bounce email when public id is mismatched' do
assert_no_difference 'Entry.count' do
receive_inbound_email_from_mail do |mail|
Expand Down

0 comments on commit 02d9633

Please sign in to comment.