Skip to main content

Deduplicate mails from a set of maildir folders.

Project description

Maildir Deduplicate

Command-line tool to deduplicate mails from a set of maildir folders.

Stable release: Last release Software license Requirements freshness Popularity

Development: Unit-tests status Coverage Status Code Quality

Install

This package is available on PyPi, so you can install the latest stable release and its dependencies with a simple pip call:

$ pip install maildir-deduplicate

See also pip installation instructions.

Usage

List global options and commands:

$ mdedup --help
Usage: mdedup [OPTIONS] COMMAND [ARGS]...

  CLI for maildirs content analysis and deletion.

Options:
  --version      Show the version and exit.
  -v, --verbose  Print much more debug statements.
  --help         Show this message and exit.

Commands:
  deduplicate  Deduplicate maildirs content.
  hash         Hash a single mail.

Deduplication command specific options:

$ mdedup deduplicate --help
Usage: mdedup deduplicate [OPTIONS] [MAILDIRS]...

  Deduplicate mails from a set of maildir folders.

  Removal strategies for each set of mail duplicates:
      - older: remove all but the newest message (determined by ctime).
      - newer: remove all but the oldest message (determined by ctime).
      - smaller: Remove all but largest message.
      - matching: Remove duplicates whose file path matches the regular
        expression provided via the --regexp parameter.
      - not-matching: Remove duplicates whose file path does not match the
        regular expression provided via the --regexp parameter.

Options:
  --strategy [not-matching|smaller|matching|newer|older]
                                  Removal strategy to apply on found
                                  duplicates.
  -r, --regexp REGEXP             Regular expression for file path. Required
                                  in matching and not-matching strategies.
  -n, --dry-run                   Do not actually remove anything; just show
                                  what would be removed.
  -s, --show-diffs                Show diffs between duplicates even if they
                                  are within the thresholds.
  -i, --message-id                Use Message-ID header as hash key. This is
                                  not recommended: the default is to compute a
                                  digest of the whole header with selected
                                  headers removed.
  -S, --size-threshold BYTES      Specify maximum allowed difference between
                                  size of duplicates. Set to -1 for no
                                  threshold.
  -D, --diff-threshold BYTES      Specify maximum allowed difference between
                                  size of duplicates. Set to -1 for no
                                  threshold.
  --help                          Show this message and exit.

Hashing command specific options:

$ mdedup hash --help
Usage: mdedup hash [OPTIONS] MESSAGE

  Take a single mail message and show its canonicalised form and hash.

  This is essentially provided for debugging why two messages do not have
  the same hash when you expect them to (or vice-versa).

  To get the message from STDIN, use a dash in place of the filename:
      cat mail.txt | mdedup hash -

Options:
  -i, --message-id  Use Message-ID header as hash key. This is not
                    recommended: the default is to compute a digest of the
                    whole header with selected headers removed.
  --help            Show this message and exit.

Details

This script reads all mails in a given list of maildir folders and subfolders, then automatically detects, lists, and optionally deletes any duplicate mails.

Duplicate detection is done by cherry-picking certain headers, in some cases doing some minor tweaking of the values to reduce them to a canonical form, and then computing a digest of those headers concatenated together.

Note that we deliberately limit this to certain headers due to the effects that mailing list software can have on not only the mail header but the body; it can potentially:

  • append a footer to a list body, thus changing the Content-Length header;

  • create a new path described by the Received headers which would not be contained in any copy of the mail saved locally at the time it was sent to the list;

  • munge the Reply-To header even though it’s a bad idea;

  • add plenty of other random headers which a copy saved locally at sending-time would not have, such as X-Mailman-Version, Precedence, X-BeenThere, List-*, Sender, Errors-To, and so on;

  • add a prefix to the Subject header.

Another difficulty is the lack of guarantee that Message-ID is unique or even present. Yes, certain broken mail servers which must remain nameless are guilty of this :-(

For added protection against accidentally removing mails due to false positives, duplicates are verified by comparing body sizes and also diff’ing the contents. If the sizes or contents differ by more than a threshold, they are not counted as duplicates.

Development

Check out latest development branch:

$ git clone git@github.com:kdeldycke/maildir-deduplicate.git
$ cd ./maildir-deduplicate
$ python ./setup.py develop

Run unit-tests:

$ python ./setup.py nosetests

Run PEP8 and Pylint code style checks:

$ pip install pep8 pylint
$ pep8 maildir-deduplicate
$ pylint --rcfile=setup.cfg maildir-deduplicate

Stability policy

Here is a bunch of rules we’re trying to follow regarding stability:

  • Patch releases (0.x.n0.x.(n+1) upgrades) are bug-fix only. These releases must not break anything and keeps backward-compatibility with 0.x.* and 0.(x-1).* series.

  • Minor releases (0.n.*0.(n+1).0 upgrades) includes any non-bugfix changes. These releases must be backward-compatible with any 0.n.* version but are allowed to drop compatibility with the 0.(n-1).* series and below.

  • Major releases (n.*.*(n+1).0.0 upgrades) are not planned yet: we’re still in beta and the final feature set of the 1.0.0 release is not decided yet.

Release process

Start from the develop branch:

$ git clone git@github.com:kdeldycke/maildir-deduplicate.git
$ git checkout develop

Revision should already be set to the next version, so we just need to set the released date in the changelog:

$ vi ./CHANGES.rst

Create a release commit, tag it and merge it back to master branch:

$ git add ./maildir-deduplicate/__init__.py ./CHANGES.rst
$ git commit -m "Release vX.Y.Z"
$ git tag "vX.Y.Z"
$ git push
$ git push --tags
$ git checkout master
$ git pull
$ git merge "vX.Y.Z"
$ git push

Push packaging to the test cheeseshop:

$ pip install wheel
$ python ./setup.py register -r testpypi
$ python ./setup.py clean
$ rm -rf ./build ./dist
$ python ./setup.py sdist bdist_egg bdist_wheel upload -r testpypi

Publish packaging to PyPi:

$ python ./setup.py register -r pypi
$ python ./setup.py clean
$ rm -rf ./build ./dist
$ python ./setup.py sdist bdist_egg bdist_wheel upload -r pypi

Bump revision back to its development state:

$ pip install bumpversion
$ git checkout develop
$ bumpversion --verbose patch
$ git add ./maildir-deduplicate/__init__.py ./CHANGES.rst
$ git commit -m "Post release version bump."
$ git push

Now if the next revision is no longer bug-fix only:

$ bumpversion --verbose minor
$ git add ./maildir-deduplicate/__init__.py ./CHANGES.rst
$ git commit -m "Next release no longer bug-fix only. Bump revision."
$ git push

Contributors

History

This script was initially released in 2010, and was living in a messy GitHub repository.

After some years, the script basically outgrew its initial intent, and moved in 2013 to its own repository.

It then continued to be updated as a stand-alone script before being properly packaged into the current form. The last known working version of the stand-alone script is available in the legacy branch.

License

This software is licensed under the GNU General Public License v2 or later (GPLv2+).

ChangeLog

1.0.1 (2015-11-23)

  • Switch from coveralls.io to codecov.io.

1.0.0 (2015-10-03)

  • Fix package version parsing.

  • Add installation instructions. Closes #21.

  • Add PEP8 and PyLint configuration.

  • Add bumpversion configuration.

  • Rework CLI around click framework. Closes #26.

0.1.0 (2014-12-15)

  • Package the script for proper distribution.

0.0.1 (2011-04-27)

  • First external contribution.

0.0.0 (2010-06-08)

  • First commit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maildir-deduplicate-1.0.1.tar.gz (22.1 kB view details)

Uploaded Source

Built Distributions

maildir_deduplicate-1.0.1-py2.7.egg (17.8 kB view details)

Uploaded Source

maildir_deduplicate-1.0.1-py2-none-any.whl (23.2 kB view details)

Uploaded Python 2

File details

Details for the file maildir-deduplicate-1.0.1.tar.gz.

File metadata

File hashes

Hashes for maildir-deduplicate-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b97d8cc981d9549be1a1e152968d3fe04861be42f2898ef83602200985b812be
MD5 6347e2e9761d0d6e08e11c0cb98ff11c
BLAKE2b-256 f6a6726b7e6f967a3b241b025a3dfc1e3c363bb6423cb8d930db2cb1dbc669c5

See more details on using hashes here.

File details

Details for the file maildir_deduplicate-1.0.1-py2.7.egg.

File metadata

File hashes

Hashes for maildir_deduplicate-1.0.1-py2.7.egg
Algorithm Hash digest
SHA256 6d3cd63ae6c0513229292fab73aec9315cc3f93f5f5e58f2ed338a48fcbd2991
MD5 812b6a696810c5b7c3192d0688958b83
BLAKE2b-256 e2661ae2c02113ccf72a434bb2da077572dea4d10d47e37ea5876e56ccdcd481

See more details on using hashes here.

File details

Details for the file maildir_deduplicate-1.0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for maildir_deduplicate-1.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 60704825a7588cfce456d3fa8799847417ef9398ed62f7eed392925692b901af
MD5 f077cecf6abe6ffccebf46ebb3bb5b0e
BLAKE2b-256 3e18d613738e386242c5790f67e1eb4c239964a1e46a3e7683c45508f13f6241

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page