maildir

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package maildir provide a library to manage message (email), and its folder, using maildir format.

This library use the following file name format for tmp message,

epoch ".M" usec "_P" pid "_Q" counter "." hostname

and the following format for new message,

epoch ".M" usec "_P" pid "_V" dev "_I" inode "_Q" counter "." hostname ",S=" size ":2"

The epoch is Unix timestamp--number of elapsed seconds, usec is the 6 digits of micro seconds, pid is the process ID of the program, dev is the file device number, inode is the file inode number, counter is a auto increment number start from 0, hostname is the system host name, and size is the message size.

References,

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Folder

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

Folder is a directory under maildir that store messages per file. A folder contains three directories: tmp, new, and cur; and an empty file "maildirfolder" to indicate a directory is a folder.

func CreateFolder

func CreateFolder(maildir, name string) (folder *Folder, err error)

CreateFolder create folder under directory maildir, populate all required sub directories and file. A folder must start with dot '.' and does not contains unicode control character.

func NewFolder

func NewFolder(maildir, name string) (folder *Folder, err error)

NewFolder initialize folder from directory maildir. It will return an error if the one of the directory is not exist or does not have permission to write, or "maildirfolder" file is not exist.

func (*Folder) Delete

func (folder *Folder) Delete(file string) (err error)

Delete hard delete a message file in "cur". It will return no error if the file does not exist.

func (*Folder) Fetch

func (folder *Folder) Fetch(file string) (fileCur string, msg []byte, err error)

Fetch fetch the content of file from folder "new" directory. If the file exist, move it to the "cur" and add suffix ":2" to the file name. If the file does not exist, it will return nil without an error.

func (*Folder) Get

func (folder *Folder) Get(file string) (msg []byte, err error)

Get the content of file from "cur" directory. It will return nil without an error if file is not exist.

type Manager

type Manager struct {
	// Folder embeded as the main maildir.
	Folder
	// contains filtered or unexported fields
}

Manager manage messages and folders in single file system. This is the main Maildir.

func NewManager

func NewManager(dir string) (mg *Manager, err error)

NewManager create new maildir Manager in directory and initialize the hostname, pid, and counter for generating unique name.

func (*Manager) Incoming

func (mg *Manager) Incoming(msg []byte) (fnNew string, err error)

Incoming save message received from external MTA in directory "${dir}/tmp/${unique}". Upon success, hard link it to "${dir}/new/${unique}" and delete the temporary file, and return the path of new file.

func (*Manager) OutgoingQueue

func (mg *Manager) OutgoingQueue(msg []byte) (nameTmp string, err error)

OutgoingQueue save the message in temporary queue directory before sending it to external MTA or processed.

When mail is coming from MUA and received by server, the mail need to be successfully stored into disk by server, before replying with "250 OK" to client.

On success it will return the file name.

Jump to

Keyboard shortcuts

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