Documentation ¶
Overview ¶
Package message implements reading and writing multipurpose messages.
RFC 2045, RFC 2046 and RFC 2047 defines MIME, and RFC 2183 defines the Content-Disposition header field.
Add this import to your package if you want to handle most common charsets by default:
import ( _ "github.com/unix-world/smartgoext/cloud/imap/message/charset" )
Note, non-UTF-8 charsets are only supported when reading messages. Only UTF-8 is supported when writing messages.
Index ¶
- Variables
- func IsUnknownCharset(err error) bool
- func IsUnknownEncoding(err error) bool
- type Entity
- type Header
- func (h *Header) ContentDisposition() (disp string, params map[string]string, err error)
- func (h *Header) ContentType() (t string, params map[string]string, err error)
- func (h *Header) Copy() Header
- func (h *Header) Fields() HeaderFields
- func (h *Header) FieldsByKey(k string) HeaderFields
- func (h *Header) SetContentDisposition(disp string, params map[string]string)
- func (h *Header) SetContentType(t string, params map[string]string)
- func (h *Header) SetText(k, v string)
- func (h *Header) Text(k string) (string, error)
- type HeaderFields
- type MultipartReader
- type ReadOptions
- type UnknownCharsetError
- type UnknownEncodingError
- type WalkFunc
- type Writer
Constants ¶
This section is empty.
Variables ¶
CharsetReader, if non-nil, defines a function to generate charset-conversion readers, converting from the provided charset into UTF-8. Charsets are always lower-case. utf-8 and us-ascii charsets are handled by default. One of the the CharsetReader's result values must be non-nil.
Importing github.com/emersion/go-message/charset will set CharsetReader to a function that handles most common charsets. Alternatively, CharsetReader can be set to e.g. golang.org/x/net/html/charset.NewReaderLabel.
Functions ¶
func IsUnknownCharset ¶
IsUnknownCharset returns a boolean indicating whether the error is known to report that the charset advertised by the entity is unknown.
func IsUnknownEncoding ¶
IsUnknownEncoding returns a boolean indicating whether the error is known to report that the encoding advertised by the entity is unknown.
Types ¶
type Entity ¶
type Entity struct { Header Header // The entity's header. Body io.Reader // The decoded entity's body. // contains filtered or unexported fields }
An Entity is either a whole message or a one of the parts in the body of a multipart entity.
func New ¶
New makes a new message with the provided header and body. The entity's transfer encoding and charset are automatically decoded to UTF-8.
If the message uses an unknown transfer encoding or charset, New returns an error that verifies IsUnknownCharset, but also returns an Entity that can be read.
func NewMultipart ¶
NewMultipart makes a new multipart message with the provided header and parts. The Content-Type header must begin with "multipart/".
If the message uses an unknown transfer encoding, NewMultipart returns an error that verifies IsUnknownCharset, but also returns an Entity that can be read.
func Read ¶
Read reads a message from r. The message's encoding and charset are automatically decoded to raw UTF-8. Note that this function only reads the message header.
If the message uses an unknown transfer encoding or charset, Read returns an error that verifies IsUnknownCharset or IsUnknownEncoding, but also returns an Entity that can be read.
func ReadWithOptions ¶
func ReadWithOptions(r io.Reader, opts *ReadOptions) (*Entity, error)
ReadWithOptions see Read, but allows overriding some parameters with ReadOptions.
If the message uses an unknown transfer encoding or charset, ReadWithOptions returns an error that verifies IsUnknownCharset or IsUnknownEncoding, but also returns an Entity that can be read.
func (*Entity) MultipartReader ¶
func (e *Entity) MultipartReader() MultipartReader
MultipartReader returns a MultipartReader that reads parts from this entity's body. If this entity is not multipart, it returns nil.
type Header ¶
A Header represents the key-value pairs in a message header.
func HeaderFromMap ¶
HeaderFromMap creates a header from a map of header fields.
This function is provided for interoperability with the standard library. If possible, ReadHeader should be used instead to avoid loosing information. The map representation looses the ordering of the fields, the capitalization of the header keys, and the whitespace of the original header.
func (*Header) ContentDisposition ¶
ContentDisposition parses the Content-Disposition header field, as defined in RFC 2183.
func (*Header) ContentType ¶
ContentType parses the Content-Type header field.
If no Content-Type is specified, it returns "text/plain".
func (*Header) Fields ¶
func (h *Header) Fields() HeaderFields
Fields iterates over all the header fields.
The header may not be mutated while iterating, except using HeaderFields.Del.
func (*Header) FieldsByKey ¶
func (h *Header) FieldsByKey(k string) HeaderFields
FieldsByKey iterates over all fields having the specified key.
The header may not be mutated while iterating, except using HeaderFields.Del.
func (*Header) SetContentDisposition ¶
SetContentDisposition formats the Content-Disposition header field, as defined in RFC 2183.
func (*Header) SetContentType ¶
SetContentType formats the Content-Type header field.
type HeaderFields ¶
type HeaderFields interface { textproto.HeaderFields // Text parses the value of the current field as plaintext. The field // charset is decoded to UTF-8. If the header field's charset is unknown, // the raw field value is returned and the error verifies IsUnknownCharset. Text() (string, error) }
HeaderFields iterates over header fields.
type MultipartReader ¶
type MultipartReader interface { io.Closer // NextPart returns the next part in the multipart or an error. When there are // no more parts, the error io.EOF is returned. // // Entity.Body must be read completely before the next call to NextPart, // otherwise it will be discarded. NextPart() (*Entity, error) }
MultipartReader is an iterator over parts in a MIME multipart body.
type ReadOptions ¶
type ReadOptions struct { // MaxHeaderBytes limits the maximum permissible size of a message header // block. If exceeded, an error will be returned. // // Set to -1 for no limit, set to 0 for the default value (1MB). MaxHeaderBytes int64 }
ReadOptions are options for ReadWithOptions.
type UnknownCharsetError ¶
type UnknownCharsetError struct {
// contains filtered or unexported fields
}
func (UnknownCharsetError) Error ¶
func (u UnknownCharsetError) Error() string
func (UnknownCharsetError) Unwrap ¶
func (u UnknownCharsetError) Unwrap() error
type UnknownEncodingError ¶
type UnknownEncodingError struct {
// contains filtered or unexported fields
}
func (UnknownEncodingError) Error ¶
func (u UnknownEncodingError) Error() string
func (UnknownEncodingError) Unwrap ¶
func (u UnknownEncodingError) Unwrap() error
type WalkFunc ¶
WalkFunc is the type of the function called for each part visited by Walk.
The path argument is a list of multipart indices leading to the part. The root part has a nil path.
If there was an encoding error walking to a part, the incoming error will describe the problem and the function can decide how to handle that error.
Unlike IMAP part paths, indices start from 0 (instead of 1) and a non-multipart message has a nil path (instead of {1}).
If an error is returned, processing stops.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes message entities.
If the message is not multipart, it should be used as a WriteCloser. Don't forget to call Close.
If the message is multipart, users can either use CreatePart to write child parts or Write to directly pipe a multipart message. In any case, Close must be called at the end.
func CreateWriter ¶
CreateWriter creates a new message writer to w. If header contains an encoding, data written to the Writer will automatically be encoded with it. The charset needs to be utf-8 or us-ascii.
func (*Writer) CreatePart ¶
CreatePart returns a Writer to a new part in this multipart entity. If this entity is not multipart, it fails. The body of the part should be written to the returned io.WriteCloser.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package charset provides functions to decode and encode charsets.
|
Package charset provides functions to decode and encode charsets. |
Package mail implements reading and writing mail messages.
|
Package mail implements reading and writing mail messages. |
Package textproto implements low-level manipulation of MIME messages.
|
Package textproto implements low-level manipulation of MIME messages. |