Documentation ¶
Overview ¶
Package email provide a library for working with Internet Message Format as defined by RFC 5322.
Index ¶
- Variables
- func IsValidLocal(local []byte) bool
- type Body
- type ContentType
- type Field
- type FieldType
- type Header
- func (hdr *Header) Boundary() []byte
- func (hdr *Header) ContentType() *ContentType
- func (hdr *Header) DKIM(n int) (dkimHeader *Header)
- func (hdr *Header) Filter(ft FieldType) (fields []*Field)
- func (hdr *Header) PushTop(f *Field)
- func (hdr *Header) Relaxed() []byte
- func (hdr *Header) Simple() []byte
- type MIME
- type Mailbox
- type Message
- type Param
Constants ¶
This section is empty.
Variables ¶
var ( // Parameter for Text Media Type, RFC 2046 section 4.1. ParamNameCharset = []byte("charset") //nolint: gochecknoglobals // Parameters for "application/octet-stream", RFC 2046 section 4.5.1. ParamNameType = []byte("type") //nolint: gochecknoglobals ParamNamePadding = []byte("padding") //nolint: gochecknoglobals // Parameter for "multipart", RFC 2046 section 5.1. ParamNameBoundary = []byte("boundary") //nolint: gochecknoglobals // PArameters for "mulitpart/partial", RFC 2046 section 5.2.2. ParamNameID = []byte("id") //nolint: gochecknoglobals ParamNameNumber = []byte("number") //nolint: gochecknoglobals ParamNameTotal = []byte("total") //nolint: gochecknoglobals )
List of known parameter name in header field's value.
Functions ¶
func IsValidLocal ¶
IsValidLocal will return true if local part contains valid characters. Local part must,
- start or end without dot character,
- contains only printable US-ASCII characters, excluding special characters
- no multiple sequence of dots.
List of special characters,
"(" / ")" / "<" / ">" / "[" / "]" / ":" / ";" / "@" / "\" / "," / "." / DQUOTE
Types ¶
type Body ¶
type Body struct { // Parts contains one or more message body. Parts []*MIME // contains filtered or unexported fields }
Body represent single or multiple message body parts.
func (*Body) Relaxed ¶
Relaxed canonicalize the original body with "relaxed" algorithm as defined in RFC 6376 section 3.4.4. It remove all trailing whitespaces, reduce sequence of whitespaces inside line into single space, and remove all empty line at the end of body. If body is not empty and not end with CRLF, a CRLF is added.
This function is expensive for message with large body, its better if we call it once and store it somewhere.
func (*Body) Simple ¶
Simple canonicalize the original body with "simple" algorithm as defined in RFC 6376 section 3.4.3. Basically, it converts "*CRLF" at the end of body to a single CRLF. If no message body or no trailing CRLF, a CRLF is added.
type ContentType ¶
ContentType represent MIME header "Content-Type" field.
func ParseContentType ¶
func ParseContentType(raw []byte) (ct *ContentType, err error)
ParseContentType parse content type from raw bytes.
func (*ContentType) GetParamValue ¶
func (ct *ContentType) GetParamValue(name []byte) []byte
GetParamValue return parameter value related to specific name.
func (*ContentType) String ¶
func (ct *ContentType) String() string
String return text representation of this instance.
type Field ¶
type Field struct { // Type of field, the numeric representation of field name. Type FieldType // Name contains "relaxed" canonicalization of field name. Name []byte // Value contains "relaxed" canonicalization of field value. Value []byte // ContentType contains unpacked value of field with Name // "Content-Type" or nil if still packed. ContentType *ContentType // contains filtered or unexported fields }
Field represent field name and value in header.
func ParseField ¶
ParseField create and initialize Field by parsing a single line message header field from raw input.
If raw input contains multiple lines, the rest of lines will be returned.
On error, it will return nil Field, and rest will contains the beginning of invalid input.
type FieldType ¶
type FieldType int
FieldType represent numerical identification of field name.
const ( FieldTypeOptional FieldType = iota // The origination date field, RFC 5322 section 3.6.1. FieldTypeDate // Originator fields, RFC 5322 section 3.6.2. FieldTypeFrom FieldTypeSender FieldTypeReplyTo // Destination fields, RFC 5322 section 3.6.3. FieldTypeTo FieldTypeCC FieldTypeBCC // Identitication fields, RFC 5322 section 3.6.4. FieldTypeMessageID FieldTypeInReplyTo FieldTypeReferences // Informational fields, RFC 5322 section 3.6.5. FieldTypeSubject FieldTypeComments FieldTypeKeywords // Resent fields, RFC 5322 section 3.6.6. FieldTypeResentDate FieldTypeResentFrom FieldTypeResentSender FieldTypeResentTo FieldTypeResentCC FieldTypeResentBCC FieldTypeResentMessageID // Trace fields, RFC 5322 section 3.6.7. FieldTypeReturnPath FieldTypeReceived // MIME header fields, RFC 2045 FieldTypeMIMEVersion FieldTypeContentType FieldTypeContentTransferEncoding FieldTypeContentID FieldTypeContentDescription // DKIM Signature, RFC 6376. FieldTypeDKIMSignature )
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header represent list of fields in message.
func ParseHeader ¶
ParseHeader parse the raw header from top to bottom.
Raw header that start with CRLF indicate an empty header. In this case, it will return nil Header, indicating that no header was parsed, and the leading CRLF is removed on returned "rest".
The raw header may end with optional CRLF, an empty line that separate header from body of message.
On success it will return the rest of raw input (possible message's body) without leading CRLF.
func (*Header) Boundary ¶
Boundary return the message body boundary defined in Content-Type. If no field Content-Type or no boundary it will return nil.
func (*Header) ContentType ¶
func (hdr *Header) ContentType() *ContentType
ContentType return the unpacked value of field "Content-Type", or nil if no field Content-Type exist or there is an error when unpacking.
func (*Header) DKIM ¶
DKIM return sub-header of the "n" DKIM-Signature, start from the top. If no DKIM-Signature found it will return nil.
For example, to get the second DKIM-Signature from the top, call it with "n=2", but if no second DKIM-Signature it will return nil.
func (*Header) Filter ¶
Filter specific field type. If multiple fields type exist it will return all of them.
type MIME ¶
MIME represent part of message body with their header and content.
func ParseBodyPart ¶
ParseBodyPart parse one body part using boundary and return the rest of body.
type Mailbox ¶
type Mailbox struct { Name []byte Local []byte Domain []byte Address []byte // contains filtered or unexported fields }
Mailbox represent an invidual mailbox.
func ParseAddress ¶
ParseAddress parse raw address into single or multiple mailboxes. Raw address can be a group of address, list of mailbox, or single mailbox.
A group of address have the following syntax,
DisplayName ":" mailbox-list ";" [comment]
List of mailbox (mailbox-list) have following syntax,
mailbox *("," mailbox)
A single mailbox have following syntax,
[DisplayName] ["<"] local "@" domain [">"]
The angle bracket is optional, but both must be provided.
DisplayName, local, and domain can have comment before and/or after it,
[comment] text [comment]
A comment have the following syntax,
"(" text [comment] ")"
type Message ¶
type Message struct { Header *Header Body *Body DKIMSignature *dkim.Signature // contains filtered or unexported fields }
Message represent an unpacked internet message format.
func ParseMessage ¶
ParseMessage parse the raw message header and body.
func (*Message) CanonHeader ¶
CanonHeader generate the canonicalization of sub-header and DKIM-Signature field.
func (*Message) DKIMSign ¶
DKIMSign sign the message using the private key and signature. The only required fields in signature is SDID and Selector, any other required fields that are empty will be initialized with default values.
Upon calling this function, any field values in header and body MUST be already encoded.
func (*Message) DKIMVerify ¶
DKIMVerify verify the message signature using DKIM.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package dkim provide a library to parse and create DKIM-Signature header field value, as defined in RFC 6376, DomainKeys Identified Mail (DKIM) Signatures.
|
Package dkim provide a library to parse and create DKIM-Signature header field value, as defined in RFC 6376, DomainKeys Identified Mail (DKIM) Signatures. |
Package maildir provide a library to manage email using maildir format.
|
Package maildir provide a library to manage email using maildir format. |