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

前端 未结 6 624
星月不相逢
星月不相逢 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:53

    Ruby includes a method of decoding Quoted-Printable strings:

    puts "Pablo_Fern=C3=A1ndez".unpack "M"
    # => Pablo_Fernández
    

    But this doesn't seem to work on your entire string (including the =?UTF-8?Q? part at the beginning. Maybe you can work it out from there, though.

提交回复
热议问题