Skip to main content

Compress mail

PyPI - Version PyPI - Python Version

blog X (formerly Twitter) Follow

compress-mail is a simple command line tool that is used with Dovecot to compress Maildir format files.


Table of Contents

Introduction

compress-mail is a simple command line tool that is used with Dovecot to compress Maildir format files.

It follows Dovecot best practices, including its own implementation of the maildirlock program, originally written in C and that is buggy. The Dovecot authors suggest using dsync (doveadm sync), but this only does whole mailboxes, not individual folders, and is more time consuming to configure.

compress-mail uses Maildir flags to mark which files have already been compressed, and thus skips them on subsequent runs, so it is safe to run multiple times.

It will also skip anything that doesn't have the S= size flag. The reasoning is from the Dovecot authors, who say:

All mails must have ,S=<size> in their filename where contains the original uncompressed mail size, otherwise there will be problems with quota calculation as well as other potential random failures. Note that if the filename doesn't contain the ,S=<size> before compression, adding it afterwards changes the base filename and thus the message UID. The safest thing to do is simply to not compress such files.

I found that if I just move those mails to a temp folder and back again in a MUA (like Thunderbird), it will automatically add the ,S=<size> to the filenames.

Installation

The recommended way to install compress-mail is to use pipx.

After getting pipx installed, simply run:

pipx install compress-mail

Please don't use pip system-wide.

You can of course also install it using classic virtualenvs.

Usage

Usage help can be obtained by running compress-mail --help.

If you have a normal Maildir structure like the following:

drwx------ 2 user group  2363392 Mar 31 08:42 cur
-rw------- 1 user group   242824 Mar 30 15:41 dovecot.index
-rw------- 1 user group 15596760 Mar 31 08:18 dovecot.index.cache
-rw------- 1 user group    26224 Mar 31 08:42 dovecot.index.log
-rw------- 1 user group       97 Feb 15  2019 dovecot-keywords
-rw------- 1 user group   953295 Mar 31 08:18 dovecot-uidlist
-rw------- 1 user group        0 Mar  2  2011 maildirfolder
drwx------ 2 user group    36864 Mar 31 08:17 new
drwx------ 2 user group   270336 Mar 31 08:18 tmp

.Trash
├── cur
├── new
└── tmp

All you need to do is run:

user@host:~$ compress-mail --basedir .Trash --compression zstd

Metadata

Release files for compress-mail 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for compress-mail 1.0.9
File Size Uploaded
compress_mail-1.0.9.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for compress-mail 1.0.9
File Interpreter ABI Platform
compress_mail-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / compress_mail-1.0.9.tar.gz

Download URL compress_mail-1.0.9.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8d30fe5265dc8ce5bbc5f39273a05b2973e9a9b02638d5bbe5ad354a5011288c
BLAKE2b-256 checksum
How to use checksums
8a614484a69bd3d8378498e94ce8fb7bb5d83d72e6d661a1656eee00aafad392
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / compress_mail-1.0.9-py3-none-any.whl

Download URL compress_mail-1.0.9-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf56da1170d9856f81a000adf9a39c43a8475682ddd491d92b676ca056159af5
BLAKE2b-256 checksum
How to use checksums
e37a3fd250dc4c2462f34457679c2a4fd924448bd22a3805d44c706963c9242f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.5

2 release files

1.0.3

2 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page