class Maildir

Overview

Class for generating unique file names for new messages

Included Modules

Defined in:

maildir.cr
message.cr
serializer/base.cr
serializer/json.cr
serializer/yaml.cr
unique_name.cr
version.cr

Constant Summary

DEFAULT_SERIALIZER = Maildir::Serializer::Base.new

Default serializer.

FOLDER_MARKER = "maildirfolder"
FOLDER_PREFIX = "."

Maildir++ folders live in the root maildir as sibling directories whose name is the folder name prefixed with a dot; nesting is expressed by joining the name components with a dot too (".Parent.Child"). Every folder also carries an empty "maildirfolder" file, so that other tools recognize it as a folder rather than as a maildir in its own right.

FOLDER_SEPARATOR = "."
SUBDIRS = {"tmp", "new", "cur"}
VERSION = "6.1.0"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(path, create = true) #

Create a new maildir at +path+. If +create+ is true, will ensure that the required subdirectories exist.


[View source]

Class Method Detail

def self.fsync=(fsync : Bool) #

Sets whether messages are fsynced before delivery. Turning this off trades the crash-safety guarantee above for throughput, which can be worth it on rotational or network storage when the data is reproducible anyway.


[View source]
def self.fsync? : Bool #

Returns true if messages are fsynced before delivery.


[View source]
def self.maildir?(path) : Bool #

Returns true if +path+ holds a maildir, i.e. has the tmp, new and cur subdirectories.


[View source]
def self.serializer : Maildir::Serializer::Base #

Gets the default serializer.


[View source]
def self.serializer=(serializer : Maildir::Serializer::Base) #

Sets the default serializer.


[View source]

Instance Method Detail

def <=>(other : self) #

Compare maildirs by their paths. Returns 1, 0, or -1.


[View source]
def add(data) #

Writes data object out as a new message. Returns a Maildir::Message. See Maildir::Message.create for more.


[View source]
def create_directories #

Ensure subdirectories exist. This can safely be called multiple times and from several processes at once, but must hit the disk. Avoid calling this if you're certain the directories exist.


[View source]
def cur_path #

[View source]
def delete(key) #

Deletes the message for key by calling destroy() on the message.


[View source]
def folder(name : String, create = true) : Maildir #

Returns the maildir for the named subfolder of this one, creating the directories of the whole chain unless +create+ is false. Names nest with a dot, so these two are the same folder: maildir.folder("a.x") maildir.folder("a").folder("x")


[View source]
def folder? : Bool #

Returns true if this maildir is a Maildir++ folder of another maildir: its directory name is dot-prefixed and it sits inside a maildir. The second condition is what keeps a root maildir which merely lives at a dot-path (say "~/.maildir") from being taken for a folder of its parent directory.

The answer is settled once, on first use, so a maildir doesn't change its mind halfway through if the surrounding directories change.


[View source]
def folder_name : String | Nil #

The Maildir++ name of this folder ("a", "a.x"), or nil for a root maildir.


[View source]
def folders : Array(Maildir) #

Returns this maildir's immediate subfolders, sorted by path. Deeper descendants are reached by asking those folders in turn.


[View source]
def get(key) #

Returns a message object for key


[View source]
def get_stale_tmp(time : Time = Time.utc - 36.hours) #

Finds messages in the tmp folder that have not been modified since +time+. +time+ defaults to 36 hours ago.


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


[View source]
def inspect(io : IO) : Nil #

Friendly inspect method


[View source]
def list(dir : String, options = {} of Symbol => String | Int32 | ::Nil) #

Returns an array of messages from the "new" or "cur" directory, sorted by key. If options[:flags] is specified and dir is "cur", returns only the messages carrying exactly those flags.

E.g. maildir.list("cur", {:flags => "F"}) # => lists all messages with flag "F" maildir.list("cur", {:flags => "FS"}) # => lists all messages with flags "F" and "S"; flags must be specified in ascending ASCII order ("FS" and not "SF") maildir.list("cur", {:flags => ""}) # => lists all messages without any flags This option does not work for the "new" directory

If options[:limit] is specified, returns only so many keys.

E.g. maildir.list("new") # => all new messages maildir.list("cur", {:limit => 10}) # => 10 oldest messages in cur


[View source]
def new_path #

[View source]
def parent : Maildir | Nil #

The maildir this folder is nested in, or nil for a root maildir.


[View source]
def path : String #

[View source]
def root : Maildir #

The root maildir this folder belongs to. Returns self if this maildir is already a root.


[View source]
def serializer : Maildir::Serializer::Base #

Returns own serializer or falls back to the default one. Deliberately does not memoize, so that a later change of Maildir.serializer is picked up by maildirs which don't have a serializer of their own.


[View source]
def serializer=(serializer : Maildir::Serializer::Base | Nil) #

[View source]
def tmp_path #

define methods tmp_path, new_path, & cur_path


[View source]