Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subject encoded email (RFC2047). Decodes wrong

Tags:

email

go

I'm writing app in Golang. I need to decode email subject.

Original subject:

Raport z eksportu ogłoszeń nieruchomości

Encoded subject:

=?utf-8?B?RG9tLmV1IC0gcmFwb3J0IHogZWtzcG9ydHUgb2fFgm9zemXF?=  =?utf-8?B?hCBuaWVydWNob21vxZtjaQ==?=^M

Decoded subject: "Raport z eksportu ogłosze▒ ▒ nieruchomości"

I use github.com/famz/RFC2047 to decode email subjects.

My code is simple:

RFC2047.Decode(msg.Header.Get("Subject"))

Why, after decoding the subject is broken? Other subjects are correctly decoded. Is this a bad encoded subject?

like image 637
JakubKubera Avatar asked Dec 26 '22 03:12

JakubKubera


1 Answers

That subject is incorrectly encoded. It was broken into two MIME encoded-words (because the encoded line would be longer than 76 characters), but it was split in the middle of the ń character.

If you join the two parts into a single encoded string, you get back the original subject:

s := "=?utf-8?B?RG9tLmV1IC0gcmFwb3J0IHogZWtzcG9ydHUgb2fFgm9zemXFhCBuaWVydWNob21vxZtjaQ==?="
fmt.Println(RFC2047.Decode(s))

// Dom.eu - raport z eksportu ogłoszeń nieruchomości
like image 53
JimB Avatar answered Jan 08 '23 08:01

JimB