Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Mayeu/maildir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maildir

A maildir manipulation library for Elixir

Warning

It is very much a work in progress. Things may breaks without any warning! Everything details after this may not be implemente yet. I'll update this file as the work progress.

Usage

A maildir is simply a string representing a path to the maildir folder.

iex> my_maildir = "/home/doctor/Maildir"

Still, there is an Maildir.open function defined to check that the path given indeed contains the 3 folders cur, new, tmp. This function return the path given if it is indeed a maildir, or :error otherwise.

iex> my_maildir = Maildir.open("/home/doctor/Maildir")
"/home/doctor/Maildir"
iex> my_maildir = Maildir.open("/home/doctor/not_a_maildir")
:error

A message (Maildir.Message) is defined as follow:

iex> defmodule Maildir.Message do
...>   defstruct maildir: nil, folder: :tmp, uniq: nil, info: nil
...> end

The maildir field is effectively the path to the maildir, folder is one of the :cur, :new or :tmp folder, uniq is the uniq part of the message, and info its info part.

The content of a message is not kept in memory, it is written to disk as soon as it is created.

iex> Maildir.add("/home/doctor/Maildir", "Doctor! We need you!")
{:ok, %Maildir.Message{maildir: "/home/doctor/Maildir", folder: :new, uniq: "so_uniq_string", info: nil}}

The library does not assume anything about the content of the file, nor try to parse the message. That is the job of your e-mail parser.

Thus, creating or adding a message in the maildir will always works, as long as the content is not the empty string.

You can list all the new message in the Maildir:

iex> Maildir.list(my_maildir, :new)
[%Maildir.Message{...}, %Maildir.Message{...},...]
iex> Maildir.list(my_maildir, :cur)
[%Maildir.Message{...}, %Maildir.Message{...},...]

Processing a message move it from new to cur:

iex> Maildir.Message.process(my_message)
:ok

And everywhere a function take a message struct as argument, you can pass a string representing the message fullpath instead:

iex> Maildir.Message.process("/home/doctor/Maildir/new/1111.2ec459f.tardis")
:ok

Steps

  1. Implementing the original Maildir specification
  2. Implementing the Maildir++ extension
  3. Implementing the Dovecot Maildir extension
  4. Profit

Resources

About

Maildir manipulation library for Elixir

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages