---
title: "Email filesystem layout"
date: "2015-10-07"
category: "email"
slug: "email-filesystem-layout"
---

## Overview

All email is stored in [Maildir](https://en.wikipedia.org/wiki/Maildir) format, where each message is a separate file in a directory named `Mail` within a user's [[home-directory-location]].

## Directory Structure

_Directories in bold:_

.
├── **cur**
│   └── 1440231926.M975332P7880V05000DAI00000000000001D1\_0.sol.apnscp.com,S=1254:2,
├── dovecot-acl-list
├── dovecot.index
├── dovecot.index.cache
├── dovecot.index.log
├── dovecot-keywords
├── dovecot.mailbox.log
├── dovecot-uidlist
├── dovecot-uidvalidity
├── dovecot-uidvalidity.4cb493c8
├── **new**
├── **old** |-- **.Spam** | |-- **cur**
| |-- dovecot.index
| |-- dovecot.index.log
| |-- dovecot-keywords
| |-- dovecot-uidlist
| |-- **new**
| \`-- **tmp**
├── subscriptions
└── **tmp** 

## Component Breakdown

### Mail Storage Directories

The `new`, `cur`, and `tmp` directories are the core of the Maildir format. `tmp` is a scratch directory for messages being written to disk. New messages arrive in `new` and move to `cur` once downloaded by a mail client.

### IMAP Folders

Any directory prefixed with a dot (`.`) is a separate IMAP folder (e.g., `.Spam`). Each IMAP folder has its own `new`, `cur`, and `tmp` directories. Folders can be nested using additional dots as separators:

    INBOX
      |-- Billing
      |      |-- Bills
      |      |     \`-- Paid
      |      \`-- Orders
      \`-- Personal

This is represented on the server as:

    .
    |-- .Billing
    |-- .Billing.Bills
    |-- .Billing.Bills.Paid
    |-- .Billing.Orders
    \`-- .Personal

### Dovecot Data Files

Files prefixed with `dovecot` are used internally by the IMAP/POP3 server ([Dovecot](http://www.dovecot.org)) to track email state. Cache files (ending in `.cache`) may become corrupted if you exceed your storage quota, resulting in an [[empty-mailbox]].

### IMAP Subscriptions

The `subscriptions` file lists all folders that appear when you log into an IMAP server. When a folder is subscribed to, its name is written on a separate line. POP3 does not use this file.

### Email Files

Each file under `cur/` or `new/` represents a single email. Metadata is embedded in the filename:

    1440231926.M975332P7880V05000DAI00000000000001D1\_0.sol.apnscp.com,S=1254:2,S
      ^- delivery in unixtime  ^                       ^                     |       ^
                               \`- internal id          |                     |       |
                                                       \`- receiving hostname |       |
                                                                             \`- size |
                                                                                     \`- flags

Filenames follow a convention of the [[determining-platform-version]] but can technically be anything -- Dovecot reconciles any files in `cur/` with its cache. During [[migrating-another-server]], email files are copied verbatim from the old server (with different hostnames in the filename) and still display normally.

Flags include: `T` (trashed), `F` (starred/flagged), and `S` (seen/viewed). The latter two are used in the [[achieving-inbox-zero]] approach.

## Migrating Email

Filenames are inconsequential and only optimize IMAP access. When migrating from a previous provider, email files can be named anything as long as they are placed in the `cur/` directory of the appropriate IMAP folder.

## See Also

- [[pop3-vs-imap-e-mail-protocols]]
- Dovecot wiki: [Mailbox Format > Maildir](http://wiki2.dovecot.org/MailboxFormat/Maildir)
