Created
June 30, 2014 20:27
-
-
Save vkryukov/4d53f84080bf088f087b to your computer and use it in GitHub Desktop.
go.enmime library example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prints the expected result: