Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to only act on duplicate messages #204

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mail_deduplicate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Config:
default_conf = {
"dry_run": False,
"input_format": False,
"only_act_on_duplicates": False,
"force_unlock": False,
"hash_only": False,
"hash_headers": HASH_HEADERS,
Expand Down
9 changes: 9 additions & 0 deletions mail_deduplicate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ def validate_regexp(ctx, param, value):
"supports maildir and mbox format. Use this option to open up other box "
"format, or bypass unreliable detection.",
)
@click.option(
"-o",
"--only-act-on-duplicates",
is_flag=True,
default=False,
help="Perform any actions only on duplicate messages, not on unique messages.",
)
@click.option(
"-u",
"--force-unlock",
Expand Down Expand Up @@ -239,6 +246,7 @@ def mdedup(
ctx,
dry_run,
input_format,
only_act_on_duplicates,
force_unlock,
hash_only,
hash_header,
Expand Down Expand Up @@ -346,6 +354,7 @@ def mdedup(
conf = Config(
dry_run=dry_run,
input_format=input_format,
only_act_on_duplicates=only_act_on_duplicates,
force_unlock=force_unlock,
hash_only=hash_only,
hash_headers=hash_header,
Expand Down
19 changes: 12 additions & 7 deletions mail_deduplicate/deduplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
("mail_hashes", "Number of unique hashes."),
(
"mail_unique",
"Number of unique mails (which where automatically added to selection).",
"Number of unique mails (which where automatically added to selection "
"unless --only-act-on-duplicates was passed on the command line).",
),
(
"mail_duplicates",
Expand Down Expand Up @@ -404,9 +405,10 @@ def select_all(self):
if mail_count == 1:
logger.debug("Add unique message to selection.")
self.stats["mail_unique"] += 1
self.stats["mail_selected"] += 1
self.stats["set_single"] += 1
candidates = mail_set
if self.conf.only_act_on_duplicates is False:
self.stats["mail_selected"] += 1
self.stats["set_single"] += 1
candidates = mail_set

# We need to resort to a selection strategy to discriminate mails
# within the set.
Expand Down Expand Up @@ -457,9 +459,12 @@ def check_stats(self):
# Mail grouping by hash.
assert self.stats["mail_retained"] >= self.stats["mail_unique"]
assert self.stats["mail_retained"] >= self.stats["mail_duplicates"]
assert self.stats["mail_retained"] == (
self.stats["mail_unique"] + self.stats["mail_duplicates"]
)
if self.conf.only_act_on_duplicates:
assert self.stats["mail_retained"] == self.stats["mail_duplicates"]
else:
assert self.stats["mail_retained"] == (
self.stats["mail_unique"] + self.stats["mail_duplicates"]
)
# Mail selection stats.
assert self.stats["mail_retained"] >= self.stats["mail_skipped"]
assert self.stats["mail_retained"] >= self.stats["mail_discarded"]
Expand Down