The subject of an encoded letter (RFC2047). Decodes incorrectly

I am writing an application in the Golang. I need to decrypt the email subject.

The original question:

Report z eksportu ogłoszeń nieruchomości

Encoded Object:

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

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

I am using github.com/famz/RFC2047 to decode email objects.

My code is simple:

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

Why is the item broken after decoding? Other items are correctly decoded. Is this a poorly encoded subject?

+4
source share
3 answers

If you are using Go 1.5, you can use the new mime package features .

Go, .

:

package main

import (
    "fmt"
    "mime" // When using Go 1.5
    mime "gopkg.in/alexcesaro/quotedprintable.v3" // When using older Go versions
)

func main() {
    s := "=?utf-8?B?RG9tLmV1IC0gcmFwb3J0IHogZWtzcG9ydHUgb2fFgm9zemXF?=  =?utf-8?B?hCBuaWVydWNob21vxZtjaQ==?="
    dec := new(mime.WordDecoder)
    subject, err := dec.DecodeHeader(s)
    if err != nil {
        panic(err)
    }
    fmt.Println(subject)
    // Output:
    // Dom.eu - raport z eksportu ogłoszeń nieruchomości
}
+4

. MIME- ( 76 ), ń.

, :

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

// Dom.eu - raport z eksportu ogłoszeń nieruchomości
+6

In my free time I wrote this function. The function concatenates the parts of a string and returns a single string.

func parseSubject(s string) string {
   patternType := regexp.MustCompile("(?i)=\\?.*?\\?.*?\\?")
   resType := patternType.FindString(s)

   if resType == "" {
      return s
   } else {
      pattern := regexp.MustCompile("(?i)=\\?.*?\\?.*?\\?|\\s+|\\?=")
      res := pattern.ReplaceAllLiteral([]byte(s), []byte(""))

      return resType + string(res) + "?="
   }
}
0
source

All Articles