Is there a way to decode q-encoded strings in Ruby?

前端 未结 6 719
星月不相逢
星月不相逢 2021-01-13 16:05

I\'m working with mails, and names and subjects sometimes come q-encoded, like this:

=?UTF-8?Q?J=2E_Pablo_Fern=C3=A1ndez?=

Is there a way t

6条回答
  •  天命终不由人
    2021-01-13 16:37

    This might help anyone wanting to test an email. delivery.html_part is normally encoded, but can be decoded to a straight HTML body using .decoded.

    test "email test" do
      UserMailer.confirm_email(user).deliver_now
      assert_equal 1, ActionMailer::Base.deliveries.size
      delivery = ActionMailer::Base.deliveries.last
      assert_equal "Please confirm your email", delivery.subject
      assert delivery.html_part.decoded =~ /Click the link below to confirm your email/ # DECODING HERE
    end
    

提交回复
热议问题