maildir

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 10 Imported by: 10

README

go-maildir

GoDoc builds.sr.ht status

A Go library for maildir.

License

MIT

Documentation

Overview

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

Maildir mailboxes are designed to be safe for concurrent delivery. This means that at the same time, multiple processes can deliver to the same mailbox. However only one process can receive and read messages stored in the Maildir.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delivery

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

Delivery represents an ongoing message delivery to the mailbox. It implements the io.WriteCloser interface. On Close the underlying file is moved/relinked to new.

Multiple processes can perform a delivery on the same Maildir concurrently.

func NewDelivery added in v0.2.0

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

NewDelivery creates a new Delivery.

func (*Delivery) Abort

func (d *Delivery) Abort() error

Abort closes the underlying file and removes it completely.

func (*Delivery) Close

func (d *Delivery) Close() error

Close closes the underlying file and moves it to new.

func (*Delivery) Write

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

Write implements io.Writer.

type Dir

type Dir string

A Dir represents a single directory in a Maildir mailbox.

Dir is used by programs receiving and reading messages from a Maildir. Only one process can perform these operations. Programs which only need to deliver new messages to the Maildir should use Delivery.

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

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

Copy copies the message with key from this Maildir to the target, preserving its flags, returning the newly generated key for the target maildir or an error.

func (Dir) Create

func (d Dir) Create(flags []Flag) (key string, w io.WriteCloser, err error)

Create inserts a new message into the Maildir.

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) ([]Flag, error)

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

func (Dir) Init added in v0.2.0

func (d Dir) Init() error

Init creates the directory structure for a Maildir.

If the main directory already exists, it tries to create the subdirectories in there. If an error occurs while creating one of the subdirectories, this function may leave a partially created directory structure.

func (Dir) Key added in v0.3.0

func (d Dir) Key(path string) (string, error)

Key returns the key for the given file path.

func (Dir) Keys

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

Keys returns a slice of valid keys to access messages by.

func (Dir) Move

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

Move moves a message from this Maildir to another.

func (Dir) Open

func (d Dir) Open(key string) (io.ReadCloser, error)

Open reads a message by key.

func (Dir) Remove

func (d Dir) Remove(key string) error

Remove removes the actual file behind this message.

func (Dir) SetFlags

func (d Dir) SetFlags(key string, flags []Flag) 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.

func (Dir) SetInfo

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

Set the info part of the filename. 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().

func (Dir) UnseenCount

func (d Dir) UnseenCount() (int, error)

UnseenCount returns the number of messages in new without looking at them.

func (Dir) Walk added in v0.4.0

func (d Dir) Walk(fn func(key string, flags []Flag) error) error

Walk calls fn for every message.

type Flag

type Flag rune
const (
	// The user has resent/forwarded/bounced this message to someone else.
	FlagPassed Flag = 'P'
	// The user has replied to this message.
	FlagReplied Flag = 'R'
	// The user has viewed this message, though perhaps he didn't read all the
	// way through it.
	FlagSeen Flag = 'S'
	// The user has moved this message to the trash; the trash will be emptied
	// by a later user action.
	FlagTrashed Flag = 'T'
	// The user considers this message a draft; toggled at user discretion.
	FlagDraft Flag = 'D'
	// User-defined flag; toggled at user discretion.
	FlagFlagged Flag = 'F'
)

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

type MailfileError

type MailfileError struct {
	Name string // the name of the mailfile
}

A MailfileError occurs when a mailfile has an invalid format

func (*MailfileError) Error

func (e *MailfileError) Error() string

Directories

Path Synopsis
Package maildirpp implements Maildir++.
Package maildirpp implements Maildir++.

Jump to

Keyboard shortcuts

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