Coder Social home page Coder Social logo

parsemail's Introduction

Parsemail - simple email parsing Go library

Build Status Coverage Status Go Report Card

This library allows for parsing an email message into a more convenient form than the net/mail provides. Where the net/mail just gives you a map of header fields and a io.Reader of its body, Parsemail allows access to all the standard header fields set in RFC5322, html/text body as well as attachements/embedded content as binary streams with metadata.

Simple usage

You just parse a io.Reader that holds the email data. The returned Email struct contains all the standard email information/headers as public fields.

var reader io.Reader // this reads an email message
email, err := parsemail.Parse(reader) // returns Email struct and error
if err != nil {
    // handle error
}

fmt.Println(email.Subject)
fmt.Println(email.From)
fmt.Println(email.To)
fmt.Println(email.HTMLBody)

Retrieving attachments

Attachments are a easily accessible as Attachment type, containing their mime type, filename and data stream.

var reader io.Reader
email, err := parsemail.Parse(reader)
if err != nil {
    // handle error
}

for _, a := range(email.Attachments) {
    fmt.Println(a.Filename)
    fmt.Println(a.ContentType)
    //and read a.Data
}

Retrieving embedded files

You can access embedded files in the same way you can access attachments. They contain the mime type, data stream and content id that is used to reference them through the email.

var reader io.Reader
email, err := parsemail.Parse(reader)
if err != nil {
    // handle error
}

for _, a := range(email.EmbeddedFiles) {
    fmt.Println(a.CID)
    fmt.Println(a.ContentType)
    //and read a.Data
}

parsemail's People

Contributors

dusankasan avatar kevinmichaelchen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.