mail_deduplicate.action module

Actions performed once the selection is settled: copy, move, delete or hardlink.

Each action ID pairs an operation verb with the subset of mails it applies to, and Action.perform() routes one to the other.

mail_deduplicate.action.export_box(dedup)[source]

Context manager for export box operations.

Return type:

Generator[Mailbox | None, None, None]

mail_deduplicate.action.dry_run_prefix(dedup)[source]

Marks a summary as describing what a run would have done.

A dry run reports through the same trail as a real one, and this prefix does for the trail’s closing summary what outcome() does for each of its lines.

Return type:

str

mail_deduplicate.action.outcome(dedup, done)[source]

Words what happened to a mail, for its line of the trail.

A dry run touches no mail, so it says what the action would have done to each of them, where a real run reports it as done.

Return type:

str

mail_deduplicate.action.copy_mails(dedup, mails)[source]

Copy provided mails to a brand new box or an existing one.

Return type:

None

mail_deduplicate.action.move_mails(dedup, mails)[source]

Move provided mails to a brand new box or an existing one.

Return type:

None

mail_deduplicate.action.delete_mails(dedup, mails)[source]

Remove provided mails in-place, from their original boxes.

Return type:

None

Prefix of the temporary link a mail is replaced through.

Every folder-based format skips dot-prefixed files when listing its mails, so a temporary left behind by an interrupted run is never read back as one.

mail_deduplicate.action.has_own_file(mail)[source]

Whether the mail is backed by a file holding it alone.

File-based boxes pack all their mails into the box’s single file, which is what path returns for each of them: there would be nothing to link but the whole box.

Return type:

bool

Explain why a mail cannot be replaced by a hardlink to its target.

Returns the reason as a sentence ready to be logged, or None when the link can go ahead. Nothing is touched along the way, so a dry run reaches the same verdicts a real run acts on.

Return type:

str | None

Point a mail’s own path at the file backing another mail.

The link is created under a temporary name in the mail’s own directory, then renamed over it: the rename is atomic and shares the mail’s filesystem by construction, so the mail is never missing from its box, whatever interrupts the run. The mail also keeps its file name, which is where maildir records the per-folder flags that make the same mail read in one folder and unread in another.

Return type:

None

Replace provided mails in-place by a hardlink to the copy kept in their set.

The mails stay right where they are, under their own name: only the content they are backed by is shared with the copy that survived the selection, so the disk space they took is reclaimed.

Return type:

None

mail_deduplicate.action.OPERATIONS: dict[str, Callable[[Deduplicate, Collection[DedupMailMixin]], None]] = {'copy': <function copy_mails>, 'delete': <function delete_mails>, 'hardlink': <function hardlink_mails>, 'move': <function move_mails>}

The operation functions above, keyed by the verb half of an action ID.

All share the same signature: the deduplication they report to, and the mails they apply to.

class mail_deduplicate.action.Action(*values)[source]

Bases: StrEnum

Define all available action IDs.

An action ID joins an operation verb to the subset of mails it applies to: the *-selected actions act on the mails kept by the selection, the *-discarded ones on the mails it discarded.

The mails that have no duplicate belong to the selection, and so do the mails with too few headers to be hashed: the copy and move actions carry them into the box they build. spares_unique explains why the delete one leaves them behind.

COPY_SELECTED = 'copy-selected'
COPY_DISCARDED = 'copy-discarded'
MOVE_SELECTED = 'move-selected'
MOVE_DISCARDED = 'move-discarded'
DELETE_SELECTED = 'delete-selected'
DELETE_DISCARDED = 'delete-discarded'
property verb: str

The operation half of the action ID, keying into OPERATIONS.

property removes_mails: bool

Whether the action removes mails from their boxes: a move or a delete.

property acts_on_discarded: bool

Whether the action applies to the discarded mails, not the selected ones.

property spares_unique: bool

Whether the action must leave the mails that have no duplicate alone.

A mail alone in its duplicate set is kept, so it belongs to the selection every *-selected action targets. So does a mail with too few headers to be hashed, which joins no set at all. Copying and moving it is what makes the exported box hold the whole deduplicated corpus rather than its duplicates only, and neither loses it. Deleting it does: no strategy ever ruled on that mail, nothing was written anywhere else, and there is no other copy of it to fall back on. So the deletion applies to the mails a strategy really picked. See: https://github.com/kdeldycke/mail-deduplicate/issues/1053

targets(dedup)[source]

The subset of mails this action applies to.

Return type:

set[DedupMailMixin]

perform(dedup)[source]

Perform the action on the subset of mails it targets.

Return type:

None