Documentation
¶
Overview ¶
Package gofastemail extracts email into the shared go-fast document model, gofastcore.Document.
It reads a single message (.eml: RFC 5322 with MIME), a mailbox (.mbox: mboxo, mboxrd and mboxcl2), an Outlook message (.msg: MS-OXMSG) and a TNEF stream (winmail.dat: MS-OXTNEF). Their gofastcore.Source.Format is eml, mbox, msg and tnef. The format is decided from the bytes, never from a name: a compound file is an Outlook message, a file that begins with an mbox "From " line is a mailbox, a file that begins with the TNEF signature is a winmail.dat, and a file that begins with a header field is a message.
Every message is a part of kind message: a .eml, .msg or winmail.dat is a document of one part, a mailbox has a part for each message. A part begins with a heading holding the subject and a paragraph with the headers a mail program shows; in a mailbox every other header is a note. For a single message the headers are in Metadata.Extra. The text/plain body (or an Outlook message's PR_BODY) becomes paragraphs, quotes and the signature; pictures shown in the message are image blocks, unless Options.Images is gofastcore.ImagesNone.
HTML and RTF bodies, other alternatives, attachments and attached messages are handed to Options.Child through Options.ExtractChild and appended to Document.Children; this package reads none of those formats itself. Without a Child function each is listed with a child.not_extracted warning, except a winmail.dat inside a message (and a message attached inside one) and an Outlook message attached to an Outlook message, which this package reads whether or not there is a Child function (still through ExtractChild, so the depth limit and the budgets apply); what they hold goes to the caller's Child in turn.
Character sets decoded: UTF-8, US-ASCII, ISO-8859-1, -9, -11 and -15, windows-874 and windows-1250 to 1258, Mac OS Roman, UTF-16 in .msg files, Shift_JIS, GBK and GB2312, EUC-KR, Big5, GB18030, EUC-JP and ISO-2022-JP. Any other set is not guessed at: bytes outside ASCII become U+FFFD with a text.unmapped_glyphs warning.
The limits are those of gofastcore.Limits (MaxInputBytes, MaxDecodedBytes, MaxTextBytes, MaxParts for the messages of a mailbox, MaxDepth) and the fields of Extractor (MaxMessageBytes, MaxHeaderBytes, MaxMIMEDepth, MaxMIMEParts). Where one is reached the file is read as far as it goes and a warning says so; a file larger than MaxInputBytes is an error (gofastcore.ErrLimitExceeded).
The package imports only go-fast-core and the standard library. The command cmd/gofastemail adds go-fast-html and go-fast-rtf to read HTML, plain text, Markdown and RTF bodies and attachments as children.
Index ¶
Constants ¶
const ( // DefaultMaxInputBytes bounds the size of the file. A mailbox is read // one message at a time, so the bound is high. DefaultMaxInputBytes = 16 << 30 // DefaultMaxDecodedBytes bounds the bytes produced by decoding base64 // and quoted-printable, over all the messages and parts of a file and // the documents embedded in it. DefaultMaxDecodedBytes = 2 << 30 )
Defaults for the limits of gofastcore.Options.Limits, used where a limit is zero. A negative limit means no limit.
const ( // DefaultMaxMessageBytes bounds the bytes of one message held in // memory at a time: an .eml file, or one message of a mailbox. DefaultMaxMessageBytes = 256 << 20 // DefaultMaxHeaderBytes bounds the header section of a message or of // a MIME part. DefaultMaxHeaderBytes = 1 << 20 // DefaultMaxMIMEDepth bounds how deeply multipart bodies nest. DefaultMaxMIMEDepth = 32 // DefaultMaxMIMEParts bounds the MIME parts read from one message. DefaultMaxMIMEParts = 10_000 )
Defaults for the settings of Extractor.
const ( // WarnAlternatives: the message has alternative bodies // (multipart/alternative). The blocks are the text/plain alternative; // every other alternative, which a mail program may show instead and // which can say something else, is extracted as an embedded document. WarnAlternatives = "email.alternatives" // WarnUnknownTransferEncoding: a part declares a transfer encoding // other than base64, quoted-printable, 7bit, 8bit or binary. Its bytes // are taken as they are. WarnUnknownTransferEncoding = "email.unknown_transfer_encoding" )
Warning codes specific to this library. Each states a fact about the message. The codes shared by all go-fast libraries are in gofastcore; this library raises these of them besides the ones about limits and embedded documents:
text.unmapped_glyphs text in a character set this library does not
decode, or bytes not valid in the one declared;
the message names the character set and the
bytes appear as U+FFFD
input.repaired a header section ended by a line that is not a
header, a multipart body with no closing
boundary or no boundary at all, base64 with
characters outside its alphabet, a compressed
RTF body that cannot be read, a damaged TNEF
stream (cut short, a wrong checksum, an
unreadable property list), an Outlook compound
file whose short streams cannot be read
(severity error: the properties in them are
missing)
input.external_reference
an Outlook attachment by reference names a file
outside the message, or a message/external-body
part names content elsewhere; nothing is fetched
part.no_text a message with no text at all
const ( // AttrRole: "headers" on the block of the headers a mail program // shows; "signature" on a block of the signature. AttrRole = gofastcore.AttrRole // AttrChildren: on the headers block, the indexes in // Document.Children of the documents that came from this message, // comma separated. AttrChildren = "children" )
Keys of Block.Attrs this library sets.
const ( RoleHeaders = gofastcore.RoleHeaders RoleSignature = gofastcore.RoleSignature // the value of textbody.RoleSignature // NoteHeaders: a note block that holds the headers a mail program does // not show, one "Name: value" per line (in a mailbox). No display // reason: the format declares none. NoteHeaders = gofastcore.NoteHeaders // NotePreamble and NoteEpilogue: the text of a multipart body before // its first part and after its last, which no mail program shows. No // display reason: the format declares none. NotePreamble = gofastcore.NoteMIMEPreamble NoteEpilogue = gofastcore.NoteMIMEEpilogue )
Values of Attrs["role"] and of the note type this library uses. They are core's values (gofastcore.RoleHeaders, NoteHeaders and so on).
const DefaultMaxParts = 1_000_000
DefaultMaxParts bounds the messages read from a mailbox when Limits.MaxParts is zero.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Extractor ¶
type Extractor struct {
// MaxMessageBytes bounds the bytes of one message held in memory: an
// .eml file, or one message of a mailbox. A longer message is read to
// that length, with a limit.exceeded warning on its part.
MaxMessageBytes int64
// MaxHeaderBytes bounds the header section of a message or MIME part.
MaxHeaderBytes int
// MaxMIMEDepth bounds how deeply multipart bodies nest.
MaxMIMEDepth int
// MaxMIMEParts bounds the MIME parts read from one message.
MaxMIMEParts int
}
Extractor extracts email: a single message (.eml), a mailbox (.mbox), an Outlook message (.msg) and a TNEF stream (winmail.dat). The zero value is ready to use and safe for concurrent use. Its fields are the settings only this library has; everything else is in gofastcore.Options. For each, zero means the default and a negative value no limit.
func (*Extractor) Extract ¶
func (e *Extractor) Extract(ctx context.Context, r io.ReaderAt, size int64, opts *gofastcore.Options) (*gofastcore.Document, error)
Extract reads size bytes from r and returns the document.
The format is decided from the bytes, never from a name: a compound file is an Outlook message, a file that begins with an mbox "From " line is a mailbox, a file that begins with the TNEF signature is a winmail.dat, and a file that begins with a header field is a message. An error wraps one of the gofastcore errors:
- ErrMalformed: the input is none of these.
- ErrUnsupported: a compound file that is not an Outlook message.
- ErrLimitExceeded: the input is larger than Limits.MaxInputBytes.
- ErrNoPartsSelected: Options.Parts selects no message.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gofastemail
command
Command gofastemail extracts email (.eml, .mbox, Outlook .msg, TNEF winmail.dat) into the shared document model of the go-fast libraries and prints it as JSON, Markdown or plain text.
|
Command gofastemail extracts email (.eml, .mbox, Outlook .msg, TNEF winmail.dat) into the shared document model of the go-fast libraries and prints it as JSON, Markdown or plain text. |
|
internal
|
|
|
cfb
Package cfb reads compound files: the container of the legacy Office formats, and of an Outlook message (.msg).
|
Package cfb reads compound files: the container of the legacy Office formats, and of an Outlook message (.msg). |
|
charset
Package charset turns the bytes of a message, in the character set it declares, into UTF-8.
|
Package charset turns the bytes of a message, in the character set it declares, into UTF-8. |
|
clean
Package clean makes extracted strings follow the text conventions of the go-fast model: no control characters other than tab and newline, line breaks as "\n", and the presentation-form ligatures written as their letters where the string is text.
|
Package clean makes extracted strings follow the text conventions of the go-fast model: no control characters other than tab and newline, line breaks as "\n", and the presentation-form ligatures written as their letters where the string is text. |
|
msgtest
Package msgtest writes what the library only reads, for its tests: compound files, and Outlook messages in them.
|
Package msgtest writes what the library only reads, for its tests: compound files, and Outlook messages in them. |
|
rfc822
Package rfc822 reads the parts of an Internet message (RFC 5322) and of MIME (RFC 2045 to 2049, 2231): the header section, encoded words, the parameters of a header, the parts of a multipart body, and the transfer encodings.
|
Package rfc822 reads the parts of an Internet message (RFC 5322) and of MIME (RFC 2045 to 2049, 2231): the header section, encoded words, the parameters of a header, the parts of a multipart body, and the transfer encodings. |
|
rtfcp
Package rtfcp decompresses the compressed RTF that Outlook stores in a message (PR_RTF_COMPRESSED), by the algorithm of [MS-OXRTFCP].
|
Package rtfcp decompresses the compressed RTF that Outlook stores in a message (PR_RTF_COMPRESSED), by the algorithm of [MS-OXRTFCP]. |
|
textbody
Package textbody turns the text of a text/plain body into blocks.
|
Package textbody turns the text of a text/plain body into blocks. |
|
tnef
Package tnef reads the Transport Neutral Encapsulation Format ([MS-OXTNEF]) that Outlook and Exchange attach to Internet mail as winmail.dat (application/ms-tnef): the message's properties, among them its bodies, and its attachments.
|
Package tnef reads the Transport Neutral Encapsulation Format ([MS-OXTNEF]) that Outlook and Exchange attach to Internet mail as winmail.dat (application/ms-tnef): the message's properties, among them its bodies, and its attachments. |