Documentation
¶
Overview ¶
Package imapmail reads a dedicated platform mailbox over IMAP for the imap connection kind (#2247): a TLS session, folders opened read-only, searches, header and whole-message fetches, and the reading of a message's MIME parts into plain text the platform can show. Which messages may be shown is internal/mailtrust's.
It only reads. Folders are opened with EXAMINE and bodies fetched with BODY.PEEK, so the server never marks a message seen, and there is no STORE, COPY, MOVE, EXPUNGE, APPEND or send to call.
Index ¶
Constants ¶
const ( // TLSImplicit is IMAPS: TLS from the first byte, port 993. TLSImplicit = "tls" // TLSStartTLS upgrades a port-143 connection before anything is sent. TLSStartTLS = "starttls" )
The two ways a connection reaches the server. Plain IMAP is not one of them: the account's password would cross the network in the clear.
Variables ¶
var ErrAttachmentNotFound = errors.New("imapmail: the message has no attachment at that index")
ErrAttachmentNotFound is the refusal of an attachment index the message does not have.
var ErrNoSuchMessage = errors.New("imapmail: no message with that uid in the folder")
ErrNoSuchMessage is the refusal of a UID the folder does not hold.
Functions ¶
func HTMLToText ¶
HTMLToText reads an HTML body as the text a person reading the message would see, and nothing else: scripts, styles, comments and the document head are dropped, and so is every element a sender hid from the reader (the hidden attribute, aria-hidden, display:none, visibility:hidden, zero font size, zero opacity, zero width or height), which is where an instruction meant only for a model would be put. Images become their alt text; a link keeps its text and, when the address differs from it, the address in brackets. Nothing is fetched.
Types ¶
type Account ¶
type Account struct {
Host string
Port int
TLS string
Username string
Password string
// TLSConfig carries the CA bundle and server name; nil uses the system
// roots and Host.
TLSConfig *tls.Config
// DialTimeout bounds connecting and logging in.
DialTimeout time.Duration
}
Account is how one mailbox is reached.
type Attachment ¶
type Attachment struct {
// Index addresses the attachment within its message, for
// mail_attachment; it is the attachment's position, from zero.
Index int `json:"index"`
Name string `json:"name"`
ContentType string `json:"content_type"`
Size int64 `json:"size"`
}
Attachment is a part a message carries as a file.
func ReadAttachment ¶
func ReadAttachment(raw []byte, index int) (Attachment, []byte, error)
ReadAttachment returns the bytes of attachment index.
type Body ¶
type Body struct {
Text string
// Format is "text" when the message had a plain-text part, "html" when
// the text was read from its HTML, and "none" when it had neither.
Format string
Attachments []Attachment
}
Body is a message's readable text and the files it carries.
type Criteria ¶
type Criteria struct {
// SinceUID returns only messages with a UID above it: a folder's
// watermark.
SinceUID uint32
}
Criteria is what a search narrows by.
type Envelope ¶
type Envelope struct {
UID uint32
Size int64
// Arrived is when the server received the message (INTERNALDATE).
Arrived time.Time
Header []byte
Attachments []Attachment
}
Envelope is what a header fetch returns for one message.
type Headers ¶
type Headers struct {
From string
To []string
Cc []string
Subject string
Date time.Time
MessageID string
InReplyTo string
References []string
AuthResults []string
}
Headers is what the platform reads from a message's header block: the fields the trust policy judges by and the fields a tool reports.
func ReadHeaders ¶
ReadHeaders parses a message's header block (all of a message, or the header section alone as BODY.PEEK[HEADER] returns it).
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one logged-in connection to the account. It is not safe for concurrent use: a tool call opens one, uses it, and closes it.
func Open ¶
Open connects, negotiates TLS, and logs in. ctx bounds the whole session: when it ends, the connection is closed and any command waiting fails.
func (*Session) Examine ¶
Examine opens folder read-only (EXAMINE), so nothing the session does can change it, and returns its UIDVALIDITY and message count.