PHPackages                             jaypha/maildir - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. jaypha/maildir

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

jaypha/maildir
==============

Maildir format

v0.6.0(4y ago)376BSL-1.0PHPPHP ^5.4 || ^7CI failing

Since Dec 28Pushed 4y agoCompare

[ Source](https://github.com/jaypha/maildir)[ Packagist](https://packagist.org/packages/jaypha/maildir)[ RSS](/packages/jaypha-maildir/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

Maildir
=======

[](#maildir)

Written by Jason den Dulk

Classes to read and write files using the maildir and maildir++ formats.

Maildir is a common format used to store emails on a computer. Maildir++ is an extension to Maildir to support multiple folders and quotas.

The Maildir spec can be found at .

The Maildir++ spec can be found at .

**Breaking Changes** in verison 0.6.0. See change log.

*This version is the final addition to be made. If no bug reports are made in a year, I will upgrade to 1.0.0.*

### Requirements

[](#requirements)

PHP v5.4.0 or greater.

### Installation

[](#installation)

```
composer require jaypha/maildir

```

### Using Quotas

[](#using-quotas)

To utilize quotas, create the maildir++ subtree with `$useQuotas` set to true. For quotas to work properly, you should stick to the `MaildirPlusPlus` methods `deliver()`, `move()`, `trash()`and emptyTrash(). The Maildir `save()` and `delete()` methods will still work, but the quotas file will not be updated until resetQuotas is called.

Remeber that the maildir++ specification recommends that the quotas file be reset roughly every fifteen minutes. Do so by calling `resetQuotas()`.

API
---

[](#api)

### class Maildir

[](#class-maildir)

#### How filenames are used in this class

[](#how-filenames-are-used-in-this-class)

In this class, the name returned by `save()`, and accepted by other functions do not include the flag settings. So while the actual filename on the disk may change as flags are set and cleared, the name used with this class does not.

#### Static Methods

[](#static-methods)

`Maildir Maildir::create(string $rootDir)`

Create a Maildir. `$rootDir` must exist. Will create the subdirectories and return a Maildir instance.

`void Maildir::destroy(string $rootDir)`

Destroys a maildir structure. Removes the cur, new and tmp directories. Does not affect anything else.

`bool MailDir::isMaildir($dir)`

Tests if the given `$dir` contains a maildir structure

`string MailDir::createName()`

Creates a suitable unique name using the guidelines set in the maildir specification.

#### Properties

[](#properties)

`string $rootDir` (read only)

The root directory of the maildir subtree

#### Methods

[](#methods)

`__construct(string $rootDir)`

Create a Maildir instance for `$rootDir`. The necessary subdirectories must already exist.

`string save($contents)`

Save `$contents` into a Maildir file. `$contents` can be a string or a resource (stream). Returns the name of the file.

`void touch(string $name)`

Forces the file for `$name` to be moved into the 'cur' directory.

`bool isNew(string $name)`

Returns true if the file for `$name` has not yet been transferred to 'cur'.

`bool exists(string $name)`

Returns true if the file for `$name` exists either in cur or new.

`string fetch(string $name)`

Fetches the contents of the file. The file is moved to the 'cur' directory, but the 'S' flag is not set.

`resource fetchAsStream(string $name)`

Fetches the contents of the file as a stream resource, suitable for large files. The file is moved to the 'cur' directory, but the 'S' flag is not set.

`mixed getPath(string $name)`

Gets the file path for `$name`. Returns `false` if `$name` is not in the maildir.

`void delete(string $name)`

Removes the file for `$name`. Will remove the file from either the 'new' or 'cur' directory

`bool hasFlag(string $name, string $flag)`

Returns true if the file has the flag set.

`void setFlag(string $name, string $flag)`

Sets the flag

`void clearFlag(string $name, string $flag)`

Clears the flag

`generator getNames()`

Yields the list of names stored in the maildir.

`generator getFiles()`

Yields the list of files stored in the maildir, indexed by name.

`generator getStreams()`

Like `getFiles()`, but yields streams rather that file contents.

### class MaildirPlusPlus

[](#class-maildirplusplus)

#### How folder names are used in this class.

[](#how-folder-names-are-used-in-this-class)

Folder names use the logical format given in the Maildir++ specification, utilizing the '/' separator.

#### Static Methods

[](#static-methods-1)

`MaildirPlusPlus MaildirPlusPlus::create(string $rootDir, $useQuotas = false)`

Creates a Maildir++ directory structure. Creates folders for Inbox, Sent, Drafts and Trash.

`MaildirPlusPlus::destroy(string $rootDir)`

Destorys the Maildir++ structure. Removes all maildir folders.

#### Properties

[](#properties-1)

`string $rootDir` (read only)

The root directory of the maildir++ subtree

#### Methods

[](#methods-1)

`__construct(string $rootDir)`

Create a MaildirPlusPlus instance for `$rootDir`. This creates Maildir instances for each folder as well as the inbox.

`Maildir createFolder(string $folderName, Maildir $parent = null)`

Create a maildir folder for `$foldername`. If `$parent` is provided, it will be used as the logical "parent" of the new folder.

`mixed getFolder(string $folderName)`

Get the folder for `$folderName`. Returns a `Maildir` if found, `false` otherwise.

`void deleteFolder(string $folderName)`

Removes the folder `$folderName`.

`mixed locate(string $name)`

Retrieves the name of the folder the file is currently lcoated in. Returns `false`if file not found.

`mixed deliver($contents)`

Attempts to save a file to subtree. Returns the name if successful. Returns false if the quota would be exceeded.

`void move(string $name, string $toFolder)`

Moves a file to the `$toFolder`. The file will always be placed in the cur directory of the destination folder.

`void trash(string $name)`

Moves file to the Trash folder. Also sets the "T" flag.

`void emptyTrash()`

Deletes all files in the Trash folder.

`void setQuotas(mixed $sizeQuota, mixed $countQuota)`

Sets the quota for total file size and file count. If either is set to `null`, no quota will be set for that parameter.

`array getQuotas()`

Returns the quotas set by setQuotas as an associative array, 'size' for size quota, 'count' for count quota. `null` value indicates no quota set.

`void resetQuotas()`

Re-calculates the total size and count of all the (non-trashed) files in the subtree, and writes it to maildirsize. Accordng to the maildir++ specification. This should be done roughly every fifteen minutes. If your program does something like that, this is the method to call.

`array getSizeAndCount()`

Returns the total file size and file count for the subtree, using the maildirsize file if quotas are being used

Change Log
----------

[](#change-log)

#### Version 0.6.0

[](#version-060)

**Breaking Changes**

- `MaildirPlusPlus` no longer inherits from `Maildir`. Use `getFolder("Inbox")` to get the inbox maildir.
- `Maildir::makeCurrent()` has been renamed to `touch()` and is now public.
- `$parentDir` has been changed to `$rootDir`.
- Deprecated function arguments are now dropped.

**Other changes**

- **Quotas support!** Added quota support functions to MaildirPlusPlus.
- Added isMaildir, rootDir, getPath, fetchAsStream and getStreams to Maildir.
- Maildir::createName is now public.

**Notes**

I decided to make MaildirPlusPlus no longer inherit from Maildir because I believe that MaildirPlusPlus represents a collection of Maildirs rather than a Maildir in its own right. While it could technichally masquerade as a Maildir; semantically, it doesn't really have an 'is\_a' relationship with Maildir. So I removed it out of a desire to engage in good programming practice.

#### Version 0.5.0

[](#version-050)

- Added getNames and getFiles to allow iteration over the maildir contents.

#### Version 0.4.1

[](#version-041)

- Removed string constraint on save to allow passing streams.

#### Version 0.4.0

[](#version-040)

- Added locate function
- Move and trash no longer require an origin folder name.

#### Version 0.3.0

[](#version-030)

- Added destroy function to Maildir
- Added maildir++ support.

#### Version 0.2.0

[](#version-020)

- Added delete function
- Removed trash and emptyTrash from Maildir.

License
-------

[](#license)

Copyright (C) 2018-21 Jaypha.
Distributed under the Boost Software License, Version 1.0.
See [http://www.boost.org/LICENSE\_1\_0.txt](http://www.boost.org/LICENSE_1_0.txt)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~154 days

Recently: every ~227 days

Total

7

Last Release

1766d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ca39c239f426fd20c6348188dc7cf2b2ff3783ebb5d44bd886572a8ec53b24f?d=identicon)[jaypha](/maintainers/jaypha)

---

Top Contributors

[![jaypha](https://avatars.githubusercontent.com/u/1052990?v=4)](https://github.com/jaypha "jaypha (7 commits)")

---

Tags

maildirmaildir-instance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jaypha-maildir/health.svg)

```
[![Health](https://phpackages.com/badges/jaypha-maildir/health.svg)](https://phpackages.com/packages/jaypha-maildir)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
