Skip to content

Instantly share code, notes, and snippets.

@vkryukov
Created June 30, 2014 20:27
Show Gist options
  • Save vkryukov/4d53f84080bf088f087b to your computer and use it in GitHub Desktop.
Save vkryukov/4d53f84080bf088f087b to your computer and use it in GitHub Desktop.
go.enmime library example
package main
import (
"bytes"
"fmt"
"log"
"net/mail"
enmime "github.com/jhillyerd/go.enmime"
)
const myMessage = `Content-Type: multipart/alternative;
boundary="===============5769616449556512256=="
MIME-Version: 1.0
To: test@test.com
From: test@gmail.com
Cc:
Subject: =?utf-8?b?0J/RgNC40LLQtdGC?=
Date: Mon, 30 Jun 2014 18:29:38 -0000
--===============5769616449556512256==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
0K3RgtC+INC80L7RkSDRgdC+0L7QsdGJ0LXQvdC40LUu
--===============5769616449556512256==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
0K3RgtC+INC80L7RkSDRgdC+0L7QsdGJ0LXQvdC40LUu
--===============5769616449556512256==--`
func main() {
msg, err := mail.ReadMessage(bytes.NewBufferString(myMessage))
if err != nil {
log.Fatal("Cannot parse myMessage.")
}
mime, _ := enmime.ParseMIMEBody(msg)
fmt.Printf("Subject: %s\n", mime.GetHeader("Subject"))
fmt.Printf("Body:\n%s\n", mime.Html)
}
@vkryukov
Copy link
Author

Prints the expected result:

Subject: Привет
Body:
Это моё сообщение.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment