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 isort utility to sort Python imports:

$ pip install isort
$ isort --apply

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, unless we introduce huge changes to the project.

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.3.0 (2016-08-11)

  • User-friendly progress bar.

  • Decrease memory usage on large datasets. Closes #19, #8 and #3.

  • Attempt several encodings when parsing message body. Closes #32.

  • Fixed comparison issue in Python 3. Closes #34.

  • Add a set of basic deduplication unittests.

1.2.0 (2016-03-29)

  • Use logger to output messages to the user.

  • Activate tests on Python 3.3, PyPy and PyPy3.

  • Fix date parsing. See #33.

  • Fix decoding of unicode header value. Closes #24 and #32.

1.1.0 (2016-01-10)

  • Add Python 3.4 and 3.5 support. Closes #30.

  • Add default isort configuration.

  • Remove hackish default encoding forcing in main code.

1.0.2 (2015-12-22)

  • Fix AttributeError on message instance. Closes #28.

  • Various fixes of references to internal variables introduced by a switch to more Pythonic classes in 1.0.0.

  • Remove Message-ID from the list of default canonical headers.

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.3.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distributions

maildir_deduplicate-1.3.0-py2.7.egg (19.1 kB view details)

Uploaded Source

maildir_deduplicate-1.3.0-py2-none-any.whl (25.0 kB view details)

Uploaded Python 2

File details

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

File metadata

File hashes

Hashes for maildir-deduplicate-1.3.0.tar.gz
Algorithm Hash digest
SHA256 63b0dd606b94faaaff700954c182d4552eb4134711cd253d306daecbfbb68320
MD5 6a9667ee9a48e68a40aa8e76ca53cace
BLAKE2b-256 5f3dd95713cad45ebdbb3b427208bd01d20b2737389392851519191dd967f401

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for maildir_deduplicate-1.3.0-py2.7.egg
Algorithm Hash digest
SHA256 3d3897e9c158b9c9bc7c1f611cc314a2349d380a1b07a72447cf65157e1960b5
MD5 9c159e2e6224ab009ed84b3569c4fb31
BLAKE2b-256 2ca17640ce934824948e78e2d855522e5ce56ff59c2a214b54a966761c83d0b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for maildir_deduplicate-1.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 3794ecd1d63e97bf9de48887cd5ab6dccec2bb361577f9c1875ce2da8caf0da3
MD5 7ee8d00ea9462877d38b4aa1ec532b16
BLAKE2b-256 33523b1bc1a83346f71f54fed622302d9e491a41a1a4b9b29d2d635b3df9614b

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