Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeBase64GBK(raw string) (string, error)
- func GbkToUtf8(s []byte) ([]byte, error)
- func GenContentID(filename string) (string, error)
- func GenMessageID() (string, error)
- func IsGBK(data []byte) bool
- func ParsePart(m *Message, msg *mailfile.Message)
- func ParseParts(m *Message, msg *mailfile.Message)
- type Header
- func (h Header) Add(key, value string)
- func (h Header) AddressList(key string) ([]*mail.Address, error)
- func (h Header) Bcc() []string
- func (h Header) Bytes() ([]byte, error)
- func (h Header) Cc() []string
- func (h Header) ContentDisposition() (string, map[string]string, error)
- func (h Header) ContentType() (string, map[string]string, error)
- func (h Header) Date() (time.Time, error)
- func (h Header) Del(key string)
- func (h Header) From() string
- func (h Header) Get(key string) string
- func (h Header) IsSet(key string) bool
- func (h Header) Save() error
- func (h Header) Set(key, value string)
- func (h Header) SetBcc(emails ...string)
- func (h Header) SetCc(emails ...string)
- func (h Header) SetFrom(email string)
- func (h Header) SetSubject(subject string)
- func (h Header) SetTo(emails ...string)
- func (h Header) Subject() string
- func (h Header) To() []string
- func (h Header) WriteTo(w io.Writer) (int64, error)
- type Message
- func (m *Message) Bytes() ([]byte, error)
- func (m *Message) Format() *mailfile.Message
- func (m *Message) HasBody() bool
- func (m *Message) HasParts() bool
- func (m *Message) HasSubMessage() bool
- func (m *Message) MessagesAll() []*Message
- func (m *Message) MessagesContentTypePrefix(contentTypePrefix string) []*Message
- func (m *Message) MessagesFilter(filter func(*Message) bool) []*Message
- func (m *Message) PartsContentTypePrefix(contentTypePrefix string) []*Message
- func (m *Message) PartsFilter(filter func(*Message) bool) []*Message
- func (m *Message) Payload() interface{}
- func (m *Message) Save() error
- func (m *Message) WriteTo(w io.Writer) (int64, error)
Constants ¶
const ( // MaxHeaderLineLength ... MaxHeaderLineLength = 78 // MaxHeaderTotalLength ... MaxHeaderTotalLength = 998 )
const (
// MaxBodyLineLength ...
MaxBodyLineLength = 76
)
Variables ¶
var ErrHeadersMissingField = errors.New("Message missing header field")
ErrHeadersMissingField ...
Functions ¶
func DecodeBase64GBK ¶ added in v1.0.1
func GenContentID ¶
GenContentID creates and returns a Content-ID, without surrounding angle brackets.
func GenMessageID ¶
GenMessageID creates and returns a Message-ID, without surrounding angle brackets.
func ParseParts ¶
Types ¶
type Header ¶
Header represents the key-value MIME-style pairs in a mail message header. Based on textproto.MIMEHeader and mail.Header.
func NewHeader ¶
NewHeader returns a Header for the most typical use case: a From address, a Subject, and a variable number of To addresses.
func (Header) Add ¶
Add adds the key, value pair to the header. It appends to any existing values associated with key.
func (Header) AddressList ¶
AddressList parses the named header field as a list of addresses.
func (Header) Bytes ¶
Bytes returns the bytes representing this header. It is a convenience method that calls WriteTo on a buffer, returning its bytes.
func (Header) ContentDisposition ¶
ContentDisposition parses and returns the media disposition, any parameters on it, and an error if there is no content disposition header field.
func (Header) ContentType ¶
ContentType parses and returns the content media type, any parameters on it, and an error if there is no content type header field.
func (Header) Get ¶
Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "". Get is a convenience method. For more complex queries, access the map directly.
func (Header) Save ¶
Save adds headers for the "Message-Id", "Date", and "MIME-Version", if missing. An error is returned if the Message-Id can not be created.
type Message ¶
type Message struct { // Header is this message's key-value MIME-style pairs in its header. Header Header // Preamble is any text that appears before the first mime multipart, // and may only be full in the case where this Message has a Content-Type of "multipart". Preamble []byte // Epilogue is any text that appears after the last mime multipart, // and may only be full in the case where this Message has a Content-Type of "multipart". Epilogue []byte // Parts is a slice of Messages contained within this Message, // and is full in the case where this Message has a Content-Type of "multipart". Parts []*Message // SubMessage is an encapsulated message, and is full in the case // where this Message has a Content-Type of "message". SubMessage *Message // Body is a byte array of the body of this message, and is full // whenever this message doesn't have a Content-Type of "multipart" or "message". // The Body is already decoded if the Content-Transfer-Encoding was // quoted-printable or base64, and will be re-encoded when written out // based on the Content-Type. Body []byte }
Message represents a full email message, or a mime-message (such as a single part in a multipart message). It has fields for the Header and the payload, which may take several forms depending on the Content-Type of this message. If the Content-Type is "message", then the payload will be a SubMessage. If the Content-Type is "multipart", then the payload will be Parts, and optionally the Preamble and Epilogue will be full. If the Content-Type is neither "message" nor "multipart", then the payload will be a Body (decoded if quoted-printable or base64).
func ParseMessage ¶
ParseMessage parses and returns a Message from an io.Reader containing the raw text of an email message. (If the raw email is a string or []byte, use strings.NewReader() or bytes.NewReader() to create a reader.) Any "quoted-printable" or "base64" encoded bodies will be decoded.
func (*Message) Bytes ¶
Bytes returns the bytes representing this message. It is a convenience method that calls WriteTo on a buffer, returning its bytes.
func (*Message) HasSubMessage ¶
HasSubMessage returns true if the Content-Type is "message"
func (*Message) MessagesAll ¶
MessagesAll will return a slice of Messages, starting with this message, and followed by all messages contained within this message, recursively. This method is similar to Python's email message "walk" function. This method DOES recurse into sub-messages and sub-parts.
func (*Message) MessagesContentTypePrefix ¶
MessagesContentTypePrefix will return a slice of all Messages that have this contentTypePrefix, potentially including this message and messages contained within this message. contentTypePrefix can be a prefix ("text"), or a full type ("text/html"). This method DOES recurse into sub-messages and sub-parts.
func (*Message) MessagesFilter ¶
MessagesFilter will return a slice of all Messages that match this lambda function, potentially including this message and messages contained within this message. This method DOES recurse into sub-messages and sub-parts.
func (*Message) PartsContentTypePrefix ¶
PartsContentTypePrefix will return a slice of all parts of this message that have this contentTypePrefix. contentTypePrefix can be a prefix ("text"), or a full type ("text/html"). The slice will be empty if this message is not a multipart message. This method does NOT recurse into sub-messages and sub-parts.
func (*Message) PartsFilter ¶
PartsFilter will return a slice of all parts of this message that match this lambda function. The slice will be empty if this message is not a multipart message. This method does NOT recurse into sub-messages and sub-parts.
func (*Message) Payload ¶
func (m *Message) Payload() interface{}
Payload will return the payload of the message, which can only be one the following: Body ([]byte), SubMessage (*Message), or Parts ([]*Message)