mime

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mime provides MIME message parsing using enmime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StripHTML

func StripHTML(rawHTML string) string

StripHTML removes HTML tags, decodes entities, and normalizes whitespace. Block elements are converted to line breaks for readable plain text output.

Note: Preformatted content (<pre>, <code>) loses its whitespace formatting as all runs of spaces are collapsed. This is acceptable for email preview where preserving exact code formatting is less important than readability.

Types

type Address

type Address struct {
	Name   string
	Email  string
	Domain string // Extracted from email for aggregation
}

Address represents an email address with optional display name.

type Attachment

type Attachment struct {
	Filename    string
	ContentType string
	ContentID   string
	Size        int
	ContentHash string // SHA-256 of content
	Content     []byte
	IsInline    bool
}

Attachment represents a file attachment or inline part.

type Message

type Message struct {
	Subject     string
	Date        time.Time
	From        []Address
	To          []Address
	Cc          []Address
	Bcc         []Address
	ReplyTo     []Address
	MessageID   string
	InReplyTo   string
	References  []string
	BodyText    string
	BodyHTML    string
	Attachments []Attachment
	Errors      []string // Non-fatal parsing errors
}

Message represents a parsed email message.

func Parse

func Parse(raw []byte) (*Message, error)

Parse parses raw MIME data into a Message.

func (*Message) GetBodyText

func (m *Message) GetBodyText() string

GetBodyText returns the best available body text. Prefers plain text, falls back to stripped HTML.

func (*Message) GetFirstFrom

func (m *Message) GetFirstFrom() Address

GetFirstFrom returns the first From address, or empty if none.

Jump to

Keyboard shortcuts

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