Documentation
¶
Overview ¶
Package whimap is the imap input of a webhook source (#2247): the platform polls a mailbox and files each new message from an allowed, authenticated sender as one event, written exactly as the HTTP receiver writes a request's events. Compaction into Parquet, the source's table, retention and alerts then treat it like any other source. Attachments are written as managed resources the event names.
Nothing here is a tool. The mail reaches a model or a script only through the source's table and the resources, like every webhook's data.
Index ¶
Constants ¶
const EventType = "mail"
EventType is the event_type of every message an imap source files.
const LockKeyspace int32 = 4713211
LockKeyspace is the advisory-lock space an imap source's poll is held in; the key within it is a hash of the source's name.
const Tick = 15 * time.Second
Tick is how often the poller looks for a source whose poll is due.
Variables ¶
This section is empty.
Functions ¶
func AttachmentsFolder ¶
AttachmentsFolder is the library folder every attachment a source saved sits under, removed with the source.
Types ¶
type Attachment ¶
type Attachment struct {
Name string `json:"name"`
ContentType string `json:"content_type"`
Size int64 `json:"size"`
URI string `json:"uri,omitempty"`
ResourceID string `json:"resource_id,omitempty"`
Skipped string `json:"skipped,omitempty"`
}
Attachment is one file a message carried: the resource it was saved as, or why it was not.
type Config ¶
type Config struct {
Sources Sources
Objects Objects
Bucket string
Recorder Recorder
RawWindows RawWindows
Marks MarkStore
Files Files
Lock Lock
Replica string
Logger *slog.Logger
// Open opens a session; nil is imapmail.Open.
Open func(ctx context.Context, a imapmail.Account) (*imapmail.Session, error)
Now func() time.Time
}
Config assembles a poller.
type External ¶
type External struct {
From string `json:"from"`
To []string `json:"to"`
Cc []string `json:"cc,omitempty"`
Subject string `json:"subject"`
Body string `json:"body"`
}
External is what the message's sender wrote, cleaned of invisible and reordering characters, hidden HTML removed from the body.
type File ¶
File is one attachment to save: the library folder it goes in, its name, type and bytes.
type Files ¶
type Files interface {
PutFile(ctx context.Context, src whsource.Source, f File) (uri, id string, err error)
}
Files saves an attachment as a managed resource in the source's library.
type Mailbox ¶
type Mailbox struct {
// contains filtered or unexported fields
}
Mailbox is what the admin service asks of an imap source: whether its mailbox can be read as configured, and how each folder's polls are going.
func NewMailbox ¶
NewMailbox returns the admin side of the imap input.
type Mark ¶
type Mark struct {
Source string `json:"-"`
Folder string `json:"folder"`
UIDValidity uint32 `json:"uid_validity"`
LastUID uint32 `json:"last_uid"`
Stored int64 `json:"stored"`
// HiddenNotAllowed and HiddenUnauthenticated count the messages the
// sender rules withheld. Nothing else of them is kept.
HiddenNotAllowed int64 `json:"hidden_not_allowed"`
HiddenUnauthenticated int64 `json:"hidden_unauthenticated"`
LastPolledAt *time.Time `json:"last_polled_at,omitempty"`
LastError string `json:"last_error,omitempty"`
}
Mark is where one folder of a source has been read to, and what its polls found.
type MarkStore ¶
type MarkStore interface {
Get(ctx context.Context, source, folder string) (Mark, error)
Put(ctx context.Context, mk Mark) error
}
MarkStore keeps each folder's watermark.
type Marks ¶
type Marks struct {
// contains filtered or unexported fields
}
Marks stores the marks in webhook_imap_marks.
type Objects ¶
type Objects interface {
PutObject(ctx context.Context, bucket, key string, data []byte, contentType string) error
}
Objects writes a segment to the managed-resources bucket.
type Payload ¶
type Payload struct {
Folder string `json:"folder"`
UID uint32 `json:"uid"`
UIDValidity uint32 `json:"uid_validity"`
MessageID string `json:"message_id,omitempty"`
InReplyTo string `json:"in_reply_to,omitempty"`
// References are the thread's earlier Message-IDs.
References []string `json:"references,omitempty"`
Date string `json:"date,omitempty"`
Arrived string `json:"arrived"`
// FromAddress is the sender's address as the From header names it, and
// SenderAuth what the receiving server recorded of it.
FromAddress string `json:"from_address"`
SenderAuth string `json:"sender_auth"`
Size int64 `json:"size"`
BodyFormat string `json:"body_format"`
// BodySkipped says why the body was not read, empty when it was.
BodySkipped string `json:"body_skipped,omitempty"`
Attachments []Attachment `json:"attachments"`
External External `json:"external"`
Notice string `json:"notice"`
}
Payload is one message as its event's payload: what the platform read of it and, under External, everything its sender wrote.
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller polls every imap source on its interval.
type RawWindows ¶
type RawWindows interface {
EnsureRawWindow(ctx context.Context, src whsource.Source, start time.Time) error
}
RawWindows registers a window's raw partition so its events are queryable before compaction.