mbox

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 6 Imported by: 23

README

go-mbox

GoDoc builds.sr.ht status

Package mbox parses the mbox file format into messages and formats messages into mbox files.

License

MIT

Documentation

Overview

Package mbox parses and formats the mbox file format.

As the mbox file format is not standardized this package expects the least common denominator, the so called mboxo format.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormat = errors.New("invalid mbox format")

ErrInvalidFormat is the error returned by the NextMessage method of Reader if its content is malformed in a way that it is not possible to extract a message.

Functions

This section is empty.

Types

type Reader added in v1.0.0

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads an mbox archive.

Example
r := strings.NewReader(`From herp.derp@example.com Thu Jan  1 00:00:01 2015
From: herp.derp@example.com (Herp Derp)
Date: Thu, 01 Jan 2015 00:00:01 +0100
Subject: Test

This is a simple test.

CU.

From derp.herp@example.com Thu Jan  1 00:00:01 2015
From: derp.herp@example.com (Derp Herp)
Date: Thu, 02 Jan 2015 00:00:01 +0100
Subject: Another test

This is another simple test.

Bye.
`)

mr := NewReader(r)
for {
	r, err := mr.NextMessage()
	if err == io.EOF {
		break
	} else if err != nil {
		fmt.Print("Oops, something went wrong!", err)
		return
	}

	msg, err := mail.ReadMessage(r)
	if err != nil {
		fmt.Print("Oops, something went wrong!", err)
		return
	}

	fmt.Printf("Message from %v\n", msg.Header.Get("From"))
}
Output:

Message from herp.derp@example.com (Herp Derp)
Message from derp.herp@example.com (Derp Herp)

func NewReader added in v1.0.0

func NewReader(r io.Reader) *Reader

NewReader returns a new Reader to read messages from mbox file format data provided by io.Reader r.

func (*Reader) NextMessage added in v1.0.0

func (r *Reader) NextMessage() (io.Reader, error)

NextMessage returns the next message text (containing both the header and the body). It will return io.EOF if there are no messages left.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer writes messages to a mbox stream. The Close method must be called to end the stream.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a new Writer that writes messages to w.

func (*Writer) Close added in v1.0.0

func (w *Writer) Close() error

func (*Writer) CreateMessage added in v1.0.0

func (w *Writer) CreateMessage(from string, t time.Time) (io.Writer, error)

CreateMessage appends a message to the mbox stream. The message text (including both the header and the body) should be written to the returned io.Writer.

Jump to

Keyboard shortcuts

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