message

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package message holds the email types shared by the IMAP connector, the rules engine and the model adapters. Bodies live in memory only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(s string) string

Clean makes untrusted text safe to show a model: it drops control and invisible formatting characters (zero-width spaces and joiners, bidi overrides, BOMs, soft hyphens), turns every kind of space into a plain one and collapses blank runs.

Types

type Raw

type Raw struct {
	Header         []byte    // BODY.PEEK[HEADER]
	Text           []byte    // start of BODY.PEEK[TEXT], at most 64 KB
	Flags          []string  // IMAP flags at fetch time, e.g. \Seen
	InternalDate   time.Time // when the server received it
	Size           int64     // RFC822.SIZE in bytes
	HasAttachment  bool      // from BODYSTRUCTURE
	AttachmentExts []string  // lower-case, no dot, e.g. "pdf"
}

Raw is one message as fetched from the server with BODY.PEEK, before parsing.

type Summary

type Summary struct {
	AccountID      int64
	From           string // address only
	FromName       string
	FromDomain     string
	To             []string
	Cc             []string
	DeliveredTo    []string
	Subject        string
	Body           string              // plain text, control characters stripped, truncated to BODY_CHARS
	Headers        map[string][]string // canonical MIME header keys
	ListID         string
	HasAttachment  bool
	AttachmentExts []string
	SizeKB         float64
	ReceivedAt     time.Time

	// Signals.
	IsContact     bool   // sender is in the contacts index
	RepliedBefore bool   // the user has sent mail to this sender
	IsBulk        bool   // List-Unsubscribe or Precedence: bulk/list
	IsNoreply     bool   // noreply@-style sender
	DMARC         string // pass | fail | none
}

Summary is the parsed email that conditions are matched against and that models are shown. Addresses and domains are lower-cased.

func Parse

func Parse(raw *Raw, accountID int64, bodyChars int) (*Summary, error)

Parse turns a fetched message into the Summary that rules and models see. The body is plain text (HTML is converted), stripped of control and invisible characters and cut to bodyChars characters; zero or less keeps it whole. IsContact and RepliedBefore are left false: the caller fills them from the contacts index.

Raw.Text may stop mid-message, so a body that ends early is used as far as it goes.

Jump to

Keyboard shortcuts

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