Tim Baas
Tim Baas

Reputation: 6185

UTF-8 Encoding Character set

I'm working on an e-mail app for fun and practice in Ruby and one of the mails has this subject:

=?UTF-8?B?4p22IEFuZHJvaWQgc3RpY2sgbWsgODA5aXYgKyB1c2IyZXRoZXJuZXQgYWRh?=\r\n
      =?UTF-8?B?cHRlciAtNDYlIOKdtyBKb3NlcGggSm9zZXBoIGtldWtlbmNhcnJvdXNlbCAt?=\r\n
      =?UTF-8?B?NTUlIOKduCA0IENlcnJ1dGkgYm94ZXJzaG9ydHMgLTcxJSDinbkgQXJub3Zh?=\r\n
      =?UTF-8?B?IDkwIEc0IHRhYmxldCAtNDIl?=

I found out I look at a Base64 string and the parts between =?UTF-8?B? and ?= need to be decoded from Base64 to UTF-8.

Can someone explain how I need to decode a string like this in Ruby?

Upvotes: 0

Views: 101

Answers (1)

Малъ Скрылевъ
Малъ Скрылевъ

Reputation: 16507

Try the Base64 module of , see example:

require "base64"

enc   = Base64.encode64('Send reinforcements')
                # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
plain = Base64.decode64(enc)
                # -> "Send reinforcements"

Since the =?UTF-8?B? is set the proper or encoding, in which the original string was coded, it is required to be present in email messages. I believe strings without the defined codepage are defaulted to

Upvotes: 1

Related Questions