maildir

package module
v0.0.0-...-eed2685 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2018 License: MIT Imports: 15 Imported by: 0

README

The maildir package provides an interface to mailboxes in the Maildir format.

Documentation can be found online here:
https://godoc.org/github.com/luksen/maildir

This is what I used as a reference:
- https://en.wikipedia.org/wiki/Maildir
- http://www.qmail.org/qmail-manual-html/man5/maildir.html
- http://cr.yp.to/proto/maildir.html

Documentation

Overview

Package maildir provides an interface to mailboxes in the Maildir format.

Index

Constants

View Source
const CreateMode = 0700

CreateMode holds the permissions used when creating a directory.

Variables

This section is empty.

Functions

func Key

func Key() (string, error)

Key generates a new unique key as described in the Maildir specification. For the third part of the key (delivery identifier) it uses an internal counter, the process id and a cryptographical random number to ensure uniqueness among messages delivered in the same second.

Types

type Delivery

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

Delivery represents an ongoing message delivery to the mailbox. It implements the WriteCloser interface. When associated Close function is called, the underlying file is moved from tmp to new directory.

func (*Delivery) Abort

func (d *Delivery) Abort() error

Abort closes the underlying file and removes it completely.

func (*Delivery) Close

func (d *Delivery) Close() (string, error)

Close closes the underlying file and moves it to new.

func (*Delivery) Write

func (d *Delivery) Write(p []byte) error

Write takes in supplied slice of bytes representing the actual mail contents to be written into mail file in the delivery process.

type Dir

type Dir string

A Dir represents a single directory in a Maildir mailbox.

func (Dir) Check

func (d Dir) Check() error

Check takes in supplied directory and performs compliance checks to Maildir folder layout. It does not change anything in file system in case it encounters an error.

func (Dir) Clean

func (d Dir) Clean() error

Clean removes old files from tmp and should be run periodically. This does not use access time but modification time for portability reasons.

func (Dir) Create

func (d Dir) Create() error

Create creates the directory structure for a Maildir. If the desired Maildir already exists, it returns an error.

func (Dir) Filename

func (d Dir) Filename(key string) (string, error)

Filename returns the path to the file corresponding to the key.

func (Dir) Flags

func (d Dir) Flags(key string, isKey bool) (string, error)

Flags returns the flags for a message sorted in ascending order. See the documentation of SetFlags for details.

func (Dir) Header

func (d Dir) Header(key string) (*mail.Header, error)

Header returns the corresponding mail header to a key.

func (Dir) Keys

func (d Dir) Keys() ([]string, error)

Keys returns a list of file names to use as keys in order to access mails in the cur directory of a Maildir.

func (Dir) Message

func (d Dir) Message(key string) (*mail.Message, error)

Message returns a message by key.

func (Dir) Move

func (d Dir) Move(target Dir, key string) error

Move moves a message from this Maildir to another.

func (Dir) NewDelivery

func (d Dir) NewDelivery() (*Delivery, error)

NewDelivery creates a new Delivery.

func (Dir) Purge

func (d Dir) Purge(key string) error

Purge removes the actual file behind this message.

func (Dir) Remove

func (d Dir) Remove() error

Remove deletes an entire Maildir from stable storage.

func (Dir) SetFlags

func (d Dir) SetFlags(key string, flags string, isKey bool) (string, error)

SetFlags appends an info section to the filename according to the given flags. This function removes duplicates and sorts the flags, but doesn't check whether they conform with the Maildir specification.

The following flags are listed in the specification (http://cr.yp.to/proto/maildir.html):

Flag "D" (draft): the user considers this message a draft; toggled at user discretion.
Flag "F" (flagged): user-defined flag; toggled at user discretion.
Flag "P" (passed): the user has resent/forwarded/bounced this message to someone else.
Flag "R" (replied): the user has replied to this message.
Flag "S" (seen): the user has viewed this message, though perhaps he didn't read all the way through it.
Flag "T" (trashed): the user has moved this message to the trash; the trash will be emptied by a later user action.

func (Dir) SetInfo

func (d Dir) SetInfo(key, info string, isKey bool) (string, error)

SetInfo sets the info part of file name. Only use this if you plan on using a non-standard info part.

func (Dir) Unseen

func (d Dir) Unseen() ([]string, error)

Unseen moves messages from new to cur and returns their keys. This means the messages are now known to the application. To find out whether a user has seen a message, use Flags().

type FlagError

type FlagError struct {
	Info         string // the encountered info section
	Experimental bool   // info section starts with 1
}

A FlagError occurs when a non-standard info section is encountered.

func (*FlagError) Error

func (e *FlagError) Error() string

type KeyError

type KeyError struct {
	Key string // the (invalid) key
	N   int    // number of matches (!= 1)
}

A KeyError occurs when a key matches more or less than one message.

func (*KeyError) Error

func (e *KeyError) Error() string

Jump to

Keyboard shortcuts

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