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

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

    The most efficient and up to date solution it seems to use the value_decode method of the Mail gem.

    > Mail::Encodings.value_decode("=?UTF-8?Q?Greg_of_Google?=")
    => "Greg of Google"
    

    https://www.rubydoc.info/github/mikel/mail/Mail/Encodings#value_decode-class_method

提交回复
热议问题