emailparser

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 9 Imported by: 0

README

emailparser

Parse raw email into email struct with text/plain, text/html and attachments
based on https://github.com/kirabou/parseMIMEemail.go

Usage

See emailparser_test.go for full example

import (
    github.com/adambg/emailparser
)

func main() {
    emlObject := Parse([]byte(demoEmail))
    
    fmt.Printf("From: %s", emlObject.From)
	fmt.Printf("To: %s", emlObject.To)
	fmt.Printf("Subject: %s", emlObject.Subject)
	fmt.Printf("Date: %s", emlObject.Date)
	fmt.Printf("BodyHtml: %s", emlObject.BodyHtml)
	fmt.Printf("BodyText: %s", emlObject.BodyText)
	fmt.Printf("ContentType: %s", emlObject.ContentType)
	fmt.Printf("Attchments: %d", len(emlObject.Attachments))
}

The return object is this:

type email struct {
	From        string        `json:"from"`
	To          string        `json:"to"`
	Subject     string        `json:"subject"`
	Date        string        `json:"date"`
	ContentType string        `json:"contenttype"`
	BodyText    string        `json:"bodytext"`
	BodyHtml    string        `json:"bodyhtml"`
	Attachments []attachments `json:"attachments"`
	Error       error         `json:"error"`
}

type attachments struct {
	Mimetype string `json:"mimetype"`
	Filename string `json:"filename"`
	Data     []byte `json:"data"`
}

Documentation

Overview

Parse raw email into email struct with text/plain, text/html and attachments based on https://github.com/kirabou/parseMIMEemail.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(inp []byte) *email

Read a MIME multipart email from stdio and explode its MIME parts into separated files, one for each part.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL