mail

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 17 Imported by: 0 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.

Documentation

Overview

Package mail reads the places HEY keeps postings — a box, a label, a collection, a bundle's unseen threads, a contact's threads — through one Source type and one page read, so a caller never has to know which endpoint a source is served by.

Index

Constants

View Source
const (
	EntryKindMessage       = "message"
	EntryKindAnnouncement  = "announcement"
	EntryKindSignUpMessage = "sign_up_message"
	EntryKindComment       = "comment"
	EntryKindAccessNotice  = "access_notice"
)

The kinds of entry HEY serves in a thread, as Entry#kind names them: the entryable's class, underscored.

Variables

View Source
var ErrNoReplyableEntry = errors.New("no emailed message to reply to")

ErrNoReplyableEntry is ReplyTarget's refusal: nothing in the thread was ever emailed, so there is nothing a reply or a forward could answer.

Functions

func AddressAt added in v1.8.0

func AddressAt(s string, pos int) (start, end int)

AddressAt returns the byte range of the recipient a cursor at byte offset pos is in, commas excluded, split the way SplitAddresses splits: the part of a list that someone typing at pos is writing.

func BareAddress added in v1.8.0

func BareAddress(recipient string) string

BareAddress returns the address a recipient names, without its display name, angle brackets or comments: "Jane Doe <jane@example.com> (work)" and "jane@example.com (Jane Doe)" are both jane@example.com. A recipient HEY's parser would refuse, or text with no address in it, is returned trimmed, as written.

func ConfirmDelivered added in v1.8.0

func ConfirmDelivered(ctx context.Context, client *hey.Client, sent *generated.SentMessage) error

ConfirmDelivered checks that a message HEY answered for was delivered, and returns a NotDeliveredError when it was not.

HEY answers a delivery with the entry that went out and the thread it went out on (entries/_sent.jbuilder). When it refuses one — the account has reached its sending limit, or the delivery could not be queued — it keeps the message as a draft and redirects to the draft's edit page instead (EntryResponses), whatever the format asked for. The SDK follows that redirect, so the answer a caller gets is the draft: an id and no thread. That is the sign looked for here, and it is confirmed before anything is said, because the edit page is served only while the message is still a draft — HEY answers 422 for one that went out, Undo Send's held ones included.

A HEY that predates the ids answers a delivery with no id at all, and is taken at its word. So is an answer whose confirmation could not be read: telling somebody a message was not sent when it was would have them send it twice.

func FormatAddress added in v1.8.0

func FormatAddress(name, address string) string

FormatAddress writes a recipient the way a person would type it: the bare address when there is no name to add, and Name <address> otherwise, quoting a name that holds a character that would split or end it, as the mail gem HEY parses with does.

func InternalEntryLabel added in v1.8.0

func InternalEntryLabel(kind, author string) (heading, tag string, internal bool)

InternalEntryLabel answers how text output names an entry that stays inside HEY — a note or a share notice, visible to everyone with access to the thread and never emailed — so it is not read as a message that went out: a heading naming the author in place of a From line, and a tag saying what it is. The author is placed as given, so a caller hands it over already made safe for where it is going. internal is false for every other kind.

func InvalidAddress added in v1.8.0

func InvalidAddress(lists ...[]string) string

InvalidAddress returns the first recipient HEY would certainly not deliver to, or "" when there is none.

HEY does not refuse a bad recipient: it drops it. A message left with nobody is saved as a draft and answered with a redirect to it, and a message with somebody left goes to them alone. Either way the sender is not told, so an address is checked here against HEY's own rule (LenientMailFieldsParser): it has a part before the @ and a domain after it; the domain ends in a public suffix, or in localdomain; and it is no longer than HEY keeps.

Refusing an address HEY would deliver to is worse than the silence this prevents, so the check leans towards letting an address through. HEY parses with Ruby's mail gem, which accepts more than net/mail does — quoted parts, comments, stray spaces — and an address net/mail cannot parse is judged on what it can still see.

func ReadNamedBox added in v1.8.0

func ReadNamedBox(ctx context.Context, client *hey.Client, kind, page string) (box *generated.BoxShowResponse, named bool, err error)

ReadNamedBox reads the page of a box HEY serves on a route of its own, which pages the box in its own order, beginning at the page cursor (empty for the first page). named is false, and nothing is read, for a kind with no route of its own: only /boxes/{id} serves that one. This is the one table of those routes, so hey box's first page and every page after it come from the same place.

func ReplyTarget added in v1.8.0

func ReplyTarget(ctx context.Context, client *hey.Client, topic *generated.Topic) (generated.Entry, error)

ReplyTarget answers the entry a reply to the topic — or a forward of it — answers: HEY's Topic#last_replyable_entry, the newest replyable entry, never a note or a share notice posted after it. The topic's own first page is looked at first; only a page with nothing replyable on it sends the search down the entry index, newest first, through client, which must be bound to the thread's account. HEY picks by id among the replyable entries, so a page does too.

func ReplyableEntry added in v1.8.0

func ReplyableEntry(kind string) bool

ReplyableEntry reports whether HEY lets a reply or a forward answer an entry of this kind: haystack's Entry#replyable?, which asks the entryable, and only a Message, an Announcement and a SignUp::Message say yes. A note (comment), a share notice (access_notice), an auto response and a delivery error are never emailed and are never replied to. An empty kind is an entry shaped before HEY served one, and is taken to be the message it then always was.

func SplitAddresses added in v1.8.0

func SplitAddresses(s string) []string

SplitAddresses splits a comma-separated recipient list, leaving a comma inside a quoted name, a comment or angle brackets where it is: "Bryan, Annie" <annie@example.com> is one recipient.

func TopicIDIn

func TopicIDIn(appURL string) int64

TopicIDIn reads the thread out of a posting's URL, which is the only place HEY's posting JSON says which topic a posting is: `_posting.jbuilder` serves no topic and no topic_id, and the web app follows the URL. A URL that addresses something else — a contact page, a bundle view — has no topic and answers zero.

func TopicIDOf added in v1.0.0

func TopicIDOf(posting generated.Posting) int64

TopicIDOf resolves the thread a posting opens: its own app_url, or — for a bundle, whose app_url is its sender's contact page — its app_bundle_url. HEY points that at a topic exactly when the bundle holds one unseen thread (haystack's `bundle_posting` route), which is the thread the bundle row opens in the web app. A bundle with several unseen threads opens a bundle view of its own, and one with none opens the contact, so neither names a topic and both answer zero.

Types

type Collection

type Collection struct {
	ID   int64
	Name string
}

Collection is a collection a posting's topic belongs to.

type Contact

type Contact struct {
	ID           int64
	Name         string
	EmailAddress string
}

Contact is who a posting came from.

type Entry

type Entry struct {
	ID                    int64
	CreatedAt             time.Time
	Creator               Contact
	Sender                Contact
	AlternativeSenderName string
	// Kind is HEY's Entry#kind: a message, or a note (comment) or share notice
	// (access_notice) that was never emailed. See InternalEntryLabel.
	Kind     string
	Summary  string
	Body     htmlutil.Markdown
	BodyHTML string
	// BodyState is what became of the body when the entry came through threadload:
	// hydrated, bodyless, over_limit or failed. Empty for an entry read another way.
	BodyState string
}

Entry is one message in a thread. CreatedAt is the time HEY served, not a string of it, for the reason Posting gives: a date formatted and parsed back is a date a reader east of UTC reads as yesterday's.

Body is Markdown, converted once here at the edge, and BodyHTML keeps the HTML HEY served so the image and attachment extractors still have the attributes Markdown drops.

func LoadedEntry

func LoadedEntry(loaded threadload.Entry) Entry

LoadedEntry describes an entry threadload read: the message when there is one, and what became of the body either way.

func NewEntry

func NewEntry(entry generated.Entry, message generated.Message) Entry

NewEntry describes a thread's entry against the message HEY served for it. A topic lists its entries and each message is read on its own, and the two disagree about what they carry: an entry read as part of a bundle has no creator and no timestamp of its own, and a message read directly has a subject where the entry has a summary.

type Extenzion

type Extenzion struct {
	ID   int64
	Name string
}

Extenzion is the HEY extension — a group address — a posting arrived through.

type Folder

type Folder struct {
	ID   int64
	Name string
}

Folder is a label a posting is filed under.

type Kind

type Kind string

Kind is which of HEY's posting endpoints a Source is served by.

const (
	KindBox        Kind = "box"
	KindFolder     Kind = "folder"
	KindCollection Kind = "collection"
	KindBundle     Kind = "bundle"
	KindContact    Kind = "contact"
)

type NotDeliveredError added in v1.8.0

type NotDeliveredError struct {
	DraftID int64
}

NotDeliveredError is a send HEY refused: it kept the message as a draft instead, and DraftID names that draft.

func (*NotDeliveredError) Error added in v1.8.0

func (e *NotDeliveredError) Error() string

type Page

type Page struct {
	Postings []generated.Posting
	Cursor   string
	Total    int
}

Page is one page of a source's postings. Cursor is whatever the next read needs to carry on where this page stopped — a geared_pagination cursor for a label or a collection, HEY's own next_history_url for a box — and is empty at the end of the list. Total is HEY's count of everything in the source, zero where it does not say.

func ReadPage

func ReadPage(ctx context.Context, client *hey.Client, source Source, cursor string) (Page, error)

ReadPage reads the page of a source that begins at cursor. An empty cursor reads the first page.

func ReadSeenPage added in v1.3.0

func ReadSeenPage(ctx context.Context, client *hey.Client, cursor string) (Page, error)

ReadSeenPage reads a page of the Imbox's Previously Seen postings, which HEY serves on their own route ordered by when they were seen — the Imbox's own pages order seen postings last, which is why the box cannot stand in for this. There is no Source parameter: the route is account-scoped and names the Imbox itself. An empty cursor reads the first page.

type Posting

type Posting struct {
	ID int64
	// BoxID is the box this row is in, which HEY serves on every posting. A list can
	// draw rows from several boxes at once — a search, a label, a contact's threads —
	// so the box a thread files out of is the row's own rather than the list's.
	BoxID                 int64
	TopicID               int64
	CreatedAt             time.Time
	Name                  string
	Summary               string
	AlternativeSenderName string
	Seen                  bool
	// IsBundle marks a row that is a bundle of one contact's unseen threads. It comes
	// from the posting's kind — HEY's `bundled` flag means filed *inside* a bundle.
	IsBundle          bool
	BubbledUp         bool
	Muted             bool
	VisibleEntryCount int32
	Creator           Contact
	Extenzions        []Extenzion
	Folders           []Folder
	Collections       []Collection
}

Posting is one row of a source: a thread, a bundle or a single entry as HEY lists it. The timestamps are the ones HEY served, so whatever shows one decides how it reads — formatting a time into a string and parsing it back is how a reader east of UTC ends up looking at yesterday's date.

func NewPosting

func NewPosting(posting generated.Posting) Posting

NewPosting describes one posting HEY answered with. Its text is sanitized here, once, so that every row, picker and notice that shows a posting shows it inert.

func Postings

func Postings(postings []generated.Posting) []Posting

Postings describes a page of postings HEY answered with.

type ReplyPrefill added in v1.4.0

type ReplyPrefill struct {
	Subject        string
	ActingSenderID int64
	Sender         ReplySender
	Addressed      ReplyRecipients
}

ReplyPrefill is how a reply starts out, as HEY prefills it: the "Re: …" subject it goes out under, the sender it goes out as, and who it goes out to. The prefill's quoted content is deliberately not carried: a reply's content is the writer's body alone — the server appends the quoted original at delivery (auto_quoting defaults on), so echoing the prefill's quote back would double it.

func ReplyPrefillFromServer added in v1.4.0

func ReplyPrefillFromServer(ctx context.Context, client *hey.Client, entryID int64) (ReplyPrefill, bool)

ReplyPrefillFromServer asks HEY how a reply to the entry starts out (GET /entries/{id}/replies/new): the "Re: …" subject the reply carries; the sender it goes out as — resolved from the entry's own to and from addresses, so a thread on a shared or alternate address answers as that address, not the account default, and named only when it differs from the acting user; and its recipients — the entry's sender moved onto the To line and the acting user's own addresses, aliases and catch-alls excluded — the exclusion no client can compute locally, and the reason a reply used to be able to CC its writer back to themselves. A false answer sends the caller to its local fallback: a failed read needs one, and so does an empty recipient list — on a thread with yourself, everyone HEY excludes is everyone there is, and the local list is what keeps that reply addressable. The subject and sender are answered even when the recipients are not — only they need the fallback, not what HEY already supplied.

type ReplyRecipients added in v1.4.0

type ReplyRecipients struct {
	To  []string
	CC  []string
	BCC []string
}

ReplyRecipients is who a reply goes out to, in HEY's three kinds of addressing.

func ReplyRecipientsFor added in v1.11.0

func ReplyRecipientsFor(message generated.Message) ReplyRecipients

ReplyRecipientsFor answers who a reply to this message goes to when HEY's own prefill is out of reach: the message's own recipients, with whoever sent it moved onto the To line. That is what HEY does in Entry::Addressed#participating_contacts_in_reply_by_kind, so a reply reaches the person who wrote the message as well as everyone they wrote to. The people it blind copied stay off the reply, as HEY leaves them off, unless they are all the audience there is: see keepsBlindCopied.

type ReplySender added in v1.7.0

type ReplySender struct {
	ID           int64  `json:"id"`
	Name         string `json:"name"`
	EmailAddress string `json:"email_address"`
}

ReplySender is the configured identity a reply goes out as.

type Source

type Source struct {
	Kind      Kind
	ID        int64
	Name      string
	BoxKind   string
	AppURL    string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Source is a place postings are read from. BoxKind carries HEY's own kind for a box (hey.BoxKindImbox and friends), which is what tells the named box routes apart; it is empty for a label or a collection.

func BoxSource

func BoxSource(box *generated.BoxShowResponse) Source

BoxSource describes the box HEY answered with.

func BundleSource added in v1.4.0

func BundleSource(postingID int64, contact generated.Contact) Source

BundleSource describes a bundle posting as a source: the unseen threads it groups, named for the bundled contact. The ID is the bundle row's own box item id, which is what the unseen route is addressed by.

func CollectionSource

func CollectionSource(collection *generated.CollectionWithPostings) Source

CollectionSource describes the collection HEY answered with.

func ContactSource added in v1.4.0

func ContactSource(contact *generated.ContactDetail) Source

ContactSource describes a contact as a source: every thread they are on, seen and unseen — the list HEY heads with the contact's entries_title.

func FolderSource

func FolderSource(folder *generated.FolderWithPostings) Source

FolderSource describes the label HEY answered with.

func ListedBoxSource

func ListedBoxSource(box generated.Box) Source

ListedBoxSource describes a box from HEY's list of them, which names the boxes without serving any of their postings or URLs.

func (Source) Coverable

func (s Source) Coverable() bool

Coverable reports whether cover art belongs over this source's seen postings. Only the Imbox is coverable, which is haystack's rule in Box::Imbox#coverable?.

Jump to

Keyboard shortcuts

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