mbox

package module
v0.0.0-...-16857f2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: GPL-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Purpose

RedGrittyBrick mbox is a software library written in the language "go" (golang) which can be used to read the e-mail files in the "mbox" format that are created by the e-mail program Thunderbird.

Thunderbird creates a local cache of e-mail massages, even for remote email servers which use the IMAP protocol.

You can use this library to read those cached emails, or old or backed-up copies. This can be useful, for example, if your PC has died and you need to recover files from the hard disk or a backup. You can then use this simpler program to review messages without needing to reinstall Thunderbird and without any risk of Thunderbird overwriting the files or performing any clean up that might delete old messages.

Usage

See example/ folder

parser := mbox.New()
msgs, err := parser.IndexFile(fileName)       // index of messages, no contents

strt, end := msgs[n].Start(), msgs[n].End()
text, err := mbox.GetMsg(fileName, strt, end) // raw text
cooked, err := mbox.CookMessage(text)         // readable contents
outline, plain := mbox.Outline(text)          // multipart message structure

Documentation

Overview

The dates found in email headers vary a lot in format and are often malformed

Some real examples

Date: 07 Feb 18 12:03:02                    // E.ON 2 digit year and no offset
Date: 10 Mar 2017 20:37:12 +0100
Date: 9 Mar 2017 16:38:21 +0000             // day can be single digit
Date: 04 May 2017 11:36:05 +0200            // or have leading zero
Date: Tue, 30 Jan 2018 22:54:19 +0000       // can have dayname prefix
Date: Tue, 30 Jan 2018 07:44:40 +0000 (GMT) // and timezone in a (comment)
Date: Mon, 23 Apr 2018 12:51:21 -0400       // B.G. offset can be negative

Some found examples for which mail.ParseDate() returns an error

Date: Fri, 0 Jan 2011 12:20:30 +0100                   // invalid day of month
Received: ... ; 6 May 2004 16:14:42 UT                 // should be UTC
Received: ... ; Fri, 26 Mar 2004 15:30:19 +0000 (GMT)  // (GMT) is comment

type Parser exists only to hold a log level value to enable this library to use the system log library without disrupting library users use of system log methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CookMsg

func CookMsg(text string) (string, error)

Remove all but vital headers, // TODO multipart, HTML, attachments

func GetMsg

func GetMsg(path string, startByte, endByte int64) (string, error)

reads mbox file skipping to specific message

func IsMbox

func IsMbox(path string) bool

returns true if specified file has content superficially like TB Mbox format

func Outline

func Outline(msg string) (string, string)

Returns a string illustrating structure of a multipart message

Types

type ContentType

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

type MsgInfo

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

--------------------------------------------------------------- Items needed to make a list of messages

func (*MsgInfo) Date

func (m *MsgInfo) Date() string

func (*MsgInfo) End

func (m *MsgInfo) End() int64

func (*MsgInfo) From

func (m *MsgInfo) From() string

returns readable form of "From:" header

func (*MsgInfo) Size

func (m *MsgInfo) Size() int

func (*MsgInfo) Start

func (m *MsgInfo) Start() int64

func (*MsgInfo) Subject

func (m *MsgInfo) Subject() string

returns printable form of "Subject:" header data

func (*MsgInfo) To

func (m *MsgInfo) To() string

type MsgList

type MsgList []MsgInfo

func IndexFile

func IndexFile(fileName string) (MsgList, error)

--------------------------------------------------------------- Returns a list of messages in a specified mbox file

func (*MsgList) String

func (l *MsgList) String() string

type Parser

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

func New

func New() *Parser

Constructor

func (Parser) IndexFile

func (p Parser) IndexFile(fileName string) (MsgList, error)

Wraps IndexFile function in a method of Parser so we can manage logging

func (*Parser) LogLevel

func (p *Parser) LogLevel(level int) *Parser

Setter for log level

type State

type State int

--------------------------------------------------------------- Keeps track of which part of a message contains line just read

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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