textproto

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2019 License: MIT Imports: 7 Imported by: 94

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteHeader

func WriteHeader(w io.Writer, h Header) error

WriteHeader writes a MIME header to w.

Types

type Header struct {
	// contains filtered or unexported fields
}

A Header represents the key-value pairs in a message header.

The header representation is idempotent: if the header can be read and written, the result will be exactly the same as the original (including whitespace). This is required for e.g. DKIM.

Mutating the header is restricted: the only two allowed operations are inserting a new header field at the top and deleting a header field. This is again necessary for DKIM.

Example
package main

import (
	"fmt"

	"github.com/emersion/go-message/textproto"
)

func main() {
	var h textproto.Header
	h.Add("From", "<root@nsa.gov>")
	h.Add("To", "<root@gchq.gov.uk>")
	h.Set("Subject", "Tonight's dinner")

	fmt.Println("From: ", h.Get("From"))
	fmt.Println("Has Received: ", h.Has("Received"))

	fmt.Println("Header fields:")
	fields := h.Fields()
	for fields.Next() {
		fmt.Println("  ", fields.Key())
	}
}
Output:

func ReadHeader

func ReadHeader(r *bufio.Reader) (Header, error)

ReadHeader reads a MIME header from r. The header is a sequence of possibly continued Key: Value lines ending in a blank line.

func (*Header) Add

func (h *Header) Add(k, v string)

Add adds the key, value pair to the header. It prepends to any existing fields associated with key.

func (*Header) Copy added in v0.10.1

func (h *Header) Copy() Header

Copy creates an independent copy of the header.

func (*Header) Del

func (h *Header) Del(k string)

Del deletes the values associated with key.

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) Get

func (h *Header) Get(k string) string

Get gets the first value associated with the given key. If there are no values associated with the key, Get returns "".

func (*Header) Has

func (h *Header) Has(k string) bool

Has checks whether the header has a field with the specified key.

func (*Header) Set

func (h *Header) Set(k, v string)

Set sets the header fields associated with key to the single field value. It replaces any existing values associated with key.

type HeaderFields

type HeaderFields interface {
	// Next advances to the next header field. It returns true on success, or
	// false if there is no next field.
	Next() (more bool)
	// Key returns the key of the current field.
	Key() string
	// Value returns the value of the current field.
	Value() string
	// Del deletes the current field.
	Del()
}

HeaderFields iterates over header fields. Its cursor starts before the first field of the header. Use Next to advance from field to field.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL