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.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:
- 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:
- mail_deduplicate.action.copy_mails(dedup, mails)[source]¶
Copy provided
mailsto a brand new box or an existing one.- Return type:
- mail_deduplicate.action.move_mails(dedup, mails)[source]¶
Move provided
mailsto a brand new box or an existing one.- Return type:
- mail_deduplicate.action.delete_mails(dedup, mails)[source]¶
Remove provided
mailsin-place, from their original boxes.- Return type:
- mail_deduplicate.action.LINK_TEMP_PREFIX = '.mdedup-hardlink-'¶
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
pathreturns for each of them: there would be nothing to link but the whole box.- Return type:
- mail_deduplicate.action.hardlink_blocker(dedup, mail, target)[source]¶
Explain why a mail cannot be replaced by a hardlink to its target.
Returns the reason as a sentence ready to be logged, or
Nonewhen the link can go ahead. Nothing is touched along the way, so a dry run reaches the same verdicts a real run acts on.
- mail_deduplicate.action.replace_by_hardlink(mail_path, target_path)[source]¶
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
maildirrecords the per-folder flags that make the same mail read in one folder and unread in another.- Return type:
- mail_deduplicate.action.hardlink_mails(dedup, mails)[source]¶
Replace provided
mailsin-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:
- 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:
StrEnumDefine all available action IDs.
An action ID joins an operation verb to the subset of mails it applies to: the
*-selectedactions act on the mails kept by the selection, the*-discardedones 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_uniqueexplains 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'¶
- HARDLINK_DISCARDED = 'hardlink-discarded'¶
- 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
*-selectedaction 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