Deduplicate mails from a set of maildir folders.
Project description
Maildir Deduplicate
Command-line tool to deduplicate mails from a set of maildir folders.
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.n → 0.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.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file maildir-deduplicate-1.0.0.tar.gz
.
File metadata
- Download URL: maildir-deduplicate-1.0.0.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5582abe6712f54a2f45963cf1aa7d351e58731fa04e5a5d3a012807be7cb4c2 |
|
MD5 | c66cb79e6c6fafbcffd990134de00608 |
|
BLAKE2b-256 | ab26c93e3c52a823dede9f34552f6204e3be1bf5eee672c1cd830def7f6940bb |
File details
Details for the file maildir_deduplicate-1.0.0-py2.7.egg
.
File metadata
- Download URL: maildir_deduplicate-1.0.0-py2.7.egg
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1961ddce820b634ffb2596b3d3287f018a6e597b5e06599e65d81fdbc906272 |
|
MD5 | 804903489c0feb2671517f6263819b4e |
|
BLAKE2b-256 | b1ff0177386ffa422529a3c6f0279039f2ae9dc7bd0c3b451479fd099b4b305b |
File details
Details for the file maildir_deduplicate-1.0.0-py2-none-any.whl
.
File metadata
- Download URL: maildir_deduplicate-1.0.0-py2-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f12d02a225c6b2aeb80943d27b348ee9e4af0b2fd559b8c9c65e8a276b781dc |
|
MD5 | 23593a322e0edafc71ac6cb9b9e07a0f |
|
BLAKE2b-256 | c92d3e18d7f530476236995c027088c6de9332758e1945397e2bcb2f5992fcbd |