capybara-email icon indicating copy to clipboard operation
capybara-email copied to clipboard

Failed to open email which contain non-ascii symbols in "to" field

Open shir opened this issue 11 years ago • 4 comments

If I send in my application email to address which contain utf-8 symbols ("antoinette.cormier@oconnell.рф"), then open_email("antoinette.cormier@oconnell.рф") returns nil. It's because email.to in email/dsl.rb:23 returns this address encoded as "=?UTF-8?B?YW50b2luZXR0ZS5jb3JtaWVyQG9jb25uZWxsLtGA0YQ=?=" referenced to RFC 6539

shir avatar Jul 30 '14 12:07 shir

Not sure who should decode this value "capybara-email" or "mail" gem.

But here is one of quick fix. Create file spec/support/capybara_email.rb with content:

module Capybara::Email::DSL
  def emails_sent_to(recipient)
    self.current_emails = all_emails.select { |email| [email.to, email.cc, email.bcc].flatten.compact.map{ |a| Mail::Encodings.value_decode(a) }.include?(recipient) }.map do |email|
      driver = Capybara::Email::Driver.new(email)
      Capybara::Node::Email.new(Capybara.current_session, driver)
    end
  end
end

Make sure that support files are included in spec_helper.rb/rails_helper.rb

shir avatar Jul 30 '14 12:07 shir

@shir is this a failing test or a fix?

bcardarella avatar Jul 30 '14 14:07 bcardarella

@bcardarella it's a quick fix in last comment.

shir avatar Jul 30 '14 14:07 shir

@shir after digging around some I believe this is an issue with the mail gem

bcardarella avatar Jul 30 '14 15:07 bcardarella