emlectomy 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agustín Rojas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: emlectomy
3
+ Version: 0.1.0
4
+ Summary: Surgical removal of the redundancy in an email chain: a clean thread.json + thread.html + attachments from .eml/.msg/.emlx/.mbox
5
+ Author: Agustín Rojas
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/agustinrojas1/emlectomy
8
+ Project-URL: Issues, https://github.com/agustinrojas1/emlectomy/issues
9
+ Keywords: email,eml,msg,emlx,mbox,deduplication,email-thread,llm,ai-agents
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Communications :: Email
16
+ Classifier: Topic :: Text Processing
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Dynamic: license-file
21
+
22
+ # emlectomy
23
+
24
+ **Surgical removal of the redundancy in an email chain.**
25
+
26
+ [![tests](https://github.com/agustinrojas1/emlectomy/actions/workflows/tests.yml/badge.svg)](https://github.com/agustinrojas1/emlectomy/actions/workflows/tests.yml)
27
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
28
+ ![python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)
29
+ ![dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen.svg)
30
+
31
+ Long reply-all chains repeat themselves. Every message quotes every earlier one, forwards
32
+ stack up, signatures and legal disclaimers pile on, and the same PDF gets attached five
33
+ times. That is painful to read and expensive to feed to an LLM.
34
+
35
+ `emlectomy` reads the mess and writes **one folder** with the conversation told once, in
36
+ order, containing only what each person actually added:
37
+
38
+ ```
39
+ python emlectomy.py reply.eml
40
+ ```
41
+
42
+ ```
43
+ emlectomy-out/reply/
44
+ ├── thread.json for agents: chronological messages, only each one's new text
45
+ ├── thread.html for humans: the same clean thread (attachments are links, never embedded)
46
+ └── attachments/ every attached file, safe names, identical files stored once
47
+ ```
48
+
49
+ <p align="center"><img src="https://raw.githubusercontent.com/agustinrojas1/emlectomy/main/docs/screenshot.png" alt="thread.html for a three-message budget chain" width="560"></p>
50
+
51
+ - **One file, zero dependencies.** Python 3.9+ standard library only. Copy `emlectomy.py` and run it.
52
+ - **Linux, macOS, Windows.** CI runs the tests on all three.
53
+ - **Reads** `.eml`, `.msg` (Outlook), `.emlx` (Apple Mail), `.mbox`, folders of them, or stdin.
54
+ - **Agent-friendly JSON.** Flat, chronological, stable field names, attachment paths that resolve.
55
+
56
+ ## Quick start
57
+
58
+ ```bash
59
+ pipx install emlectomy # or: pip install emlectomy
60
+ emlectomy reply.eml --open
61
+ ```
62
+
63
+ No install needed either: grab [`emlectomy.py`](emlectomy.py) and run `python emlectomy.py reply.eml`.
64
+ Try it on the samples in this repo:
65
+
66
+ ```bash
67
+ git clone https://github.com/agustinrojas1/emlectomy
68
+ cd emlectomy
69
+ python emlectomy.py examples/budget-thread.mbox --open
70
+ ```
71
+
72
+ ```
73
+ emlectomy FILE [FILE ...] [-o DIR] [--open] [--print-json] [--keep-signatures]
74
+ ```
75
+
76
+ | Option | |
77
+ |---|---|
78
+ | `FILE` | Mail files or folders. `-` reads one from stdin. Several files are merged into one thread. |
79
+ | `-o DIR` | Output folder. Default: `emlectomy-out/<file name>`. Re-running overwrites the previous output, and it refuses to write into a non-empty folder that isn't an earlier emlectomy output. |
80
+ | `--open` | Open `thread.html` when done. |
81
+ | `--print-json` | Also print `thread.json` to stdout (status goes to stderr). Handy for piping to an agent. |
82
+ | `--keep-signatures` | Don't strip signatures and disclaimers. |
83
+
84
+ ## What it does
85
+
86
+ **Peels quoted history into separate messages.** `>` quotes at any depth, `On … wrote:`
87
+ attributions (English, Spanish, French, German, Italian, Portuguese, Dutch), Outlook
88
+ `-----Original Message-----` and `From: / Sent: / To: / Subject:` blocks, forwarded-message
89
+ blocks, and HTML replies (`blockquote`, Outlook's header block). Each older message gets its
90
+ sender and date from the attribution or header block.
91
+
92
+ **Drops redundant copies.** A quoted message is removed when it is already in the thread,
93
+ matched on normalised text (ignoring re-wrapping, `>` marks and whitespace), near-duplicate
94
+ overlap and paragraph coverage, with sender and date as a sanity check. Two real emails are
95
+ only merged when they share a `Message-ID`, or have the same text, sender and timestamp, so
96
+ two different "Thanks!" replies stay separate.
97
+
98
+ **Strips boilerplate.** Signatures (`-- ` delimiter, or sign-off plus contact block), "Sent
99
+ from my iPhone", confidentiality disclaimers, `[cid:…]` placeholders, "external email"
100
+ banners, Outlook SafeLinks wrappers. Each person's signature is kept once under `participants`.
101
+
102
+ **Deduplicates attachments.** Identical files (SHA-256) are saved and listed once. Inline
103
+ images (e.g. Gmail screenshots) are attached to the message that shows them, and the text
104
+ points at the file: `[image: attachments/image (6).png]`.
105
+
106
+ **Handles inline replies.** When someone answers between quoted lines, the first quote level
107
+ stays next to the answers so they still make sense, and anything quoted deeper is peeled off
108
+ into its own older messages.
109
+
110
+ Emails attached to other emails (an `.eml` forwarded as an attachment, or embedded in a
111
+ `.msg`) are read as messages and merged into the thread rather than listed as files.
112
+
113
+ ## `thread.json`
114
+
115
+ ```json
116
+ {
117
+ "thread": "Q3 budget",
118
+ "base_dir": "/abs/path/emlectomy-out/reply",
119
+ "stats": {
120
+ "emails_read": 3, "message_blocks_seen": 6, "messages_kept": 3,
121
+ "redundant_copies_removed": 3, "signatures_removed": 0,
122
+ "attachments_saved": 1, "duplicate_attachments_skipped": 2
123
+ },
124
+ "participants": [
125
+ {"name": "Alice Johnson", "email": "alice@example.com", "signature": "…"}
126
+ ],
127
+ "messages": [
128
+ {
129
+ "id": 3,
130
+ "from": "Alice Johnson <alice@example.com>",
131
+ "to": ["Bob Smith <bob@example.com>"],
132
+ "date": "2025-03-04T18:00:00+00:00",
133
+ "text": "Agreed with Bob on travel. I will cut it by 30 percent…",
134
+ "attachments": [
135
+ {"name": "budget.pdf", "path": "attachments/budget.pdf",
136
+ "mime": "application/pdf", "size": 45}
137
+ ],
138
+ "source": "email"
139
+ }
140
+ ]
141
+ }
142
+ ```
143
+
144
+ - Messages are oldest first; `id` is the position.
145
+ - Attachment `path`s are relative to the output folder; `base_dir` is its absolute path.
146
+ - `cc` and `subject` appear only when present, and `subject` only when it differs from `thread`.
147
+ - `source` is `email` (a file you gave it), `attached_email`, or `quoted_only` (the original
148
+ wasn't provided, so the message was rebuilt from a quote and its headers may be partial).
149
+ - `date` is `null` with a `date_text` when the date couldn't be parsed.
150
+ - `note` appears only on inline-reply messages.
151
+
152
+ ## Limits
153
+
154
+ - **Heuristics, not magic.** Unusual mail clients or heavily edited quotes can leave a bit of
155
+ repeated text or split a message in the wrong place. `stats` tells you what was removed.
156
+ - **A single `.eml` only contains what it quotes.** Replies on other branches of a
157
+ conversation aren't in it. Give emlectomy more files (or an `.mbox`) to cover more.
158
+ - **Formatting is plain text.** Colours and highlights (for example answers typed in yellow)
159
+ are lost.
160
+ - **`.msg`**: bodies come from the plain-text or HTML property; RTF-only messages aren't decoded.
161
+ - **`.pst` / `.ost`** archives aren't supported. Export to `.mbox` or `.eml` first.
162
+
163
+ ## Development
164
+
165
+ ```bash
166
+ python -m unittest discover -s tests # run the tests
167
+ python tests/fixtures.py # regenerate examples/
168
+ ```
169
+
170
+ The `.msg` tests use a small OLE writer in `tests/fixtures.py` rather than real Outlook files,
171
+ so real-world `.msg` bug reports (with a sample, if you can share one) are especially welcome.
172
+ Issues and pull requests are welcome.
173
+
174
+ ## License
175
+
176
+ [MIT](LICENSE)
@@ -0,0 +1,155 @@
1
+ # emlectomy
2
+
3
+ **Surgical removal of the redundancy in an email chain.**
4
+
5
+ [![tests](https://github.com/agustinrojas1/emlectomy/actions/workflows/tests.yml/badge.svg)](https://github.com/agustinrojas1/emlectomy/actions/workflows/tests.yml)
6
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
+ ![python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)
8
+ ![dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen.svg)
9
+
10
+ Long reply-all chains repeat themselves. Every message quotes every earlier one, forwards
11
+ stack up, signatures and legal disclaimers pile on, and the same PDF gets attached five
12
+ times. That is painful to read and expensive to feed to an LLM.
13
+
14
+ `emlectomy` reads the mess and writes **one folder** with the conversation told once, in
15
+ order, containing only what each person actually added:
16
+
17
+ ```
18
+ python emlectomy.py reply.eml
19
+ ```
20
+
21
+ ```
22
+ emlectomy-out/reply/
23
+ ├── thread.json for agents: chronological messages, only each one's new text
24
+ ├── thread.html for humans: the same clean thread (attachments are links, never embedded)
25
+ └── attachments/ every attached file, safe names, identical files stored once
26
+ ```
27
+
28
+ <p align="center"><img src="https://raw.githubusercontent.com/agustinrojas1/emlectomy/main/docs/screenshot.png" alt="thread.html for a three-message budget chain" width="560"></p>
29
+
30
+ - **One file, zero dependencies.** Python 3.9+ standard library only. Copy `emlectomy.py` and run it.
31
+ - **Linux, macOS, Windows.** CI runs the tests on all three.
32
+ - **Reads** `.eml`, `.msg` (Outlook), `.emlx` (Apple Mail), `.mbox`, folders of them, or stdin.
33
+ - **Agent-friendly JSON.** Flat, chronological, stable field names, attachment paths that resolve.
34
+
35
+ ## Quick start
36
+
37
+ ```bash
38
+ pipx install emlectomy # or: pip install emlectomy
39
+ emlectomy reply.eml --open
40
+ ```
41
+
42
+ No install needed either: grab [`emlectomy.py`](emlectomy.py) and run `python emlectomy.py reply.eml`.
43
+ Try it on the samples in this repo:
44
+
45
+ ```bash
46
+ git clone https://github.com/agustinrojas1/emlectomy
47
+ cd emlectomy
48
+ python emlectomy.py examples/budget-thread.mbox --open
49
+ ```
50
+
51
+ ```
52
+ emlectomy FILE [FILE ...] [-o DIR] [--open] [--print-json] [--keep-signatures]
53
+ ```
54
+
55
+ | Option | |
56
+ |---|---|
57
+ | `FILE` | Mail files or folders. `-` reads one from stdin. Several files are merged into one thread. |
58
+ | `-o DIR` | Output folder. Default: `emlectomy-out/<file name>`. Re-running overwrites the previous output, and it refuses to write into a non-empty folder that isn't an earlier emlectomy output. |
59
+ | `--open` | Open `thread.html` when done. |
60
+ | `--print-json` | Also print `thread.json` to stdout (status goes to stderr). Handy for piping to an agent. |
61
+ | `--keep-signatures` | Don't strip signatures and disclaimers. |
62
+
63
+ ## What it does
64
+
65
+ **Peels quoted history into separate messages.** `>` quotes at any depth, `On … wrote:`
66
+ attributions (English, Spanish, French, German, Italian, Portuguese, Dutch), Outlook
67
+ `-----Original Message-----` and `From: / Sent: / To: / Subject:` blocks, forwarded-message
68
+ blocks, and HTML replies (`blockquote`, Outlook's header block). Each older message gets its
69
+ sender and date from the attribution or header block.
70
+
71
+ **Drops redundant copies.** A quoted message is removed when it is already in the thread,
72
+ matched on normalised text (ignoring re-wrapping, `>` marks and whitespace), near-duplicate
73
+ overlap and paragraph coverage, with sender and date as a sanity check. Two real emails are
74
+ only merged when they share a `Message-ID`, or have the same text, sender and timestamp, so
75
+ two different "Thanks!" replies stay separate.
76
+
77
+ **Strips boilerplate.** Signatures (`-- ` delimiter, or sign-off plus contact block), "Sent
78
+ from my iPhone", confidentiality disclaimers, `[cid:…]` placeholders, "external email"
79
+ banners, Outlook SafeLinks wrappers. Each person's signature is kept once under `participants`.
80
+
81
+ **Deduplicates attachments.** Identical files (SHA-256) are saved and listed once. Inline
82
+ images (e.g. Gmail screenshots) are attached to the message that shows them, and the text
83
+ points at the file: `[image: attachments/image (6).png]`.
84
+
85
+ **Handles inline replies.** When someone answers between quoted lines, the first quote level
86
+ stays next to the answers so they still make sense, and anything quoted deeper is peeled off
87
+ into its own older messages.
88
+
89
+ Emails attached to other emails (an `.eml` forwarded as an attachment, or embedded in a
90
+ `.msg`) are read as messages and merged into the thread rather than listed as files.
91
+
92
+ ## `thread.json`
93
+
94
+ ```json
95
+ {
96
+ "thread": "Q3 budget",
97
+ "base_dir": "/abs/path/emlectomy-out/reply",
98
+ "stats": {
99
+ "emails_read": 3, "message_blocks_seen": 6, "messages_kept": 3,
100
+ "redundant_copies_removed": 3, "signatures_removed": 0,
101
+ "attachments_saved": 1, "duplicate_attachments_skipped": 2
102
+ },
103
+ "participants": [
104
+ {"name": "Alice Johnson", "email": "alice@example.com", "signature": "…"}
105
+ ],
106
+ "messages": [
107
+ {
108
+ "id": 3,
109
+ "from": "Alice Johnson <alice@example.com>",
110
+ "to": ["Bob Smith <bob@example.com>"],
111
+ "date": "2025-03-04T18:00:00+00:00",
112
+ "text": "Agreed with Bob on travel. I will cut it by 30 percent…",
113
+ "attachments": [
114
+ {"name": "budget.pdf", "path": "attachments/budget.pdf",
115
+ "mime": "application/pdf", "size": 45}
116
+ ],
117
+ "source": "email"
118
+ }
119
+ ]
120
+ }
121
+ ```
122
+
123
+ - Messages are oldest first; `id` is the position.
124
+ - Attachment `path`s are relative to the output folder; `base_dir` is its absolute path.
125
+ - `cc` and `subject` appear only when present, and `subject` only when it differs from `thread`.
126
+ - `source` is `email` (a file you gave it), `attached_email`, or `quoted_only` (the original
127
+ wasn't provided, so the message was rebuilt from a quote and its headers may be partial).
128
+ - `date` is `null` with a `date_text` when the date couldn't be parsed.
129
+ - `note` appears only on inline-reply messages.
130
+
131
+ ## Limits
132
+
133
+ - **Heuristics, not magic.** Unusual mail clients or heavily edited quotes can leave a bit of
134
+ repeated text or split a message in the wrong place. `stats` tells you what was removed.
135
+ - **A single `.eml` only contains what it quotes.** Replies on other branches of a
136
+ conversation aren't in it. Give emlectomy more files (or an `.mbox`) to cover more.
137
+ - **Formatting is plain text.** Colours and highlights (for example answers typed in yellow)
138
+ are lost.
139
+ - **`.msg`**: bodies come from the plain-text or HTML property; RTF-only messages aren't decoded.
140
+ - **`.pst` / `.ost`** archives aren't supported. Export to `.mbox` or `.eml` first.
141
+
142
+ ## Development
143
+
144
+ ```bash
145
+ python -m unittest discover -s tests # run the tests
146
+ python tests/fixtures.py # regenerate examples/
147
+ ```
148
+
149
+ The `.msg` tests use a small OLE writer in `tests/fixtures.py` rather than real Outlook files,
150
+ so real-world `.msg` bug reports (with a sample, if you can share one) are especially welcome.
151
+ Issues and pull requests are welcome.
152
+
153
+ ## License
154
+
155
+ [MIT](LICENSE)
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: emlectomy
3
+ Version: 0.1.0
4
+ Summary: Surgical removal of the redundancy in an email chain: a clean thread.json + thread.html + attachments from .eml/.msg/.emlx/.mbox
5
+ Author: Agustín Rojas
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/agustinrojas1/emlectomy
8
+ Project-URL: Issues, https://github.com/agustinrojas1/emlectomy/issues
9
+ Keywords: email,eml,msg,emlx,mbox,deduplication,email-thread,llm,ai-agents
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Communications :: Email
16
+ Classifier: Topic :: Text Processing
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Dynamic: license-file
21
+
22
+ # emlectomy
23
+
24
+ **Surgical removal of the redundancy in an email chain.**
25
+
26
+ [![tests](https://github.com/agustinrojas1/emlectomy/actions/workflows/tests.yml/badge.svg)](https://github.com/agustinrojas1/emlectomy/actions/workflows/tests.yml)
27
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
28
+ ![python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg)
29
+ ![dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen.svg)
30
+
31
+ Long reply-all chains repeat themselves. Every message quotes every earlier one, forwards
32
+ stack up, signatures and legal disclaimers pile on, and the same PDF gets attached five
33
+ times. That is painful to read and expensive to feed to an LLM.
34
+
35
+ `emlectomy` reads the mess and writes **one folder** with the conversation told once, in
36
+ order, containing only what each person actually added:
37
+
38
+ ```
39
+ python emlectomy.py reply.eml
40
+ ```
41
+
42
+ ```
43
+ emlectomy-out/reply/
44
+ ├── thread.json for agents: chronological messages, only each one's new text
45
+ ├── thread.html for humans: the same clean thread (attachments are links, never embedded)
46
+ └── attachments/ every attached file, safe names, identical files stored once
47
+ ```
48
+
49
+ <p align="center"><img src="https://raw.githubusercontent.com/agustinrojas1/emlectomy/main/docs/screenshot.png" alt="thread.html for a three-message budget chain" width="560"></p>
50
+
51
+ - **One file, zero dependencies.** Python 3.9+ standard library only. Copy `emlectomy.py` and run it.
52
+ - **Linux, macOS, Windows.** CI runs the tests on all three.
53
+ - **Reads** `.eml`, `.msg` (Outlook), `.emlx` (Apple Mail), `.mbox`, folders of them, or stdin.
54
+ - **Agent-friendly JSON.** Flat, chronological, stable field names, attachment paths that resolve.
55
+
56
+ ## Quick start
57
+
58
+ ```bash
59
+ pipx install emlectomy # or: pip install emlectomy
60
+ emlectomy reply.eml --open
61
+ ```
62
+
63
+ No install needed either: grab [`emlectomy.py`](emlectomy.py) and run `python emlectomy.py reply.eml`.
64
+ Try it on the samples in this repo:
65
+
66
+ ```bash
67
+ git clone https://github.com/agustinrojas1/emlectomy
68
+ cd emlectomy
69
+ python emlectomy.py examples/budget-thread.mbox --open
70
+ ```
71
+
72
+ ```
73
+ emlectomy FILE [FILE ...] [-o DIR] [--open] [--print-json] [--keep-signatures]
74
+ ```
75
+
76
+ | Option | |
77
+ |---|---|
78
+ | `FILE` | Mail files or folders. `-` reads one from stdin. Several files are merged into one thread. |
79
+ | `-o DIR` | Output folder. Default: `emlectomy-out/<file name>`. Re-running overwrites the previous output, and it refuses to write into a non-empty folder that isn't an earlier emlectomy output. |
80
+ | `--open` | Open `thread.html` when done. |
81
+ | `--print-json` | Also print `thread.json` to stdout (status goes to stderr). Handy for piping to an agent. |
82
+ | `--keep-signatures` | Don't strip signatures and disclaimers. |
83
+
84
+ ## What it does
85
+
86
+ **Peels quoted history into separate messages.** `>` quotes at any depth, `On … wrote:`
87
+ attributions (English, Spanish, French, German, Italian, Portuguese, Dutch), Outlook
88
+ `-----Original Message-----` and `From: / Sent: / To: / Subject:` blocks, forwarded-message
89
+ blocks, and HTML replies (`blockquote`, Outlook's header block). Each older message gets its
90
+ sender and date from the attribution or header block.
91
+
92
+ **Drops redundant copies.** A quoted message is removed when it is already in the thread,
93
+ matched on normalised text (ignoring re-wrapping, `>` marks and whitespace), near-duplicate
94
+ overlap and paragraph coverage, with sender and date as a sanity check. Two real emails are
95
+ only merged when they share a `Message-ID`, or have the same text, sender and timestamp, so
96
+ two different "Thanks!" replies stay separate.
97
+
98
+ **Strips boilerplate.** Signatures (`-- ` delimiter, or sign-off plus contact block), "Sent
99
+ from my iPhone", confidentiality disclaimers, `[cid:…]` placeholders, "external email"
100
+ banners, Outlook SafeLinks wrappers. Each person's signature is kept once under `participants`.
101
+
102
+ **Deduplicates attachments.** Identical files (SHA-256) are saved and listed once. Inline
103
+ images (e.g. Gmail screenshots) are attached to the message that shows them, and the text
104
+ points at the file: `[image: attachments/image (6).png]`.
105
+
106
+ **Handles inline replies.** When someone answers between quoted lines, the first quote level
107
+ stays next to the answers so they still make sense, and anything quoted deeper is peeled off
108
+ into its own older messages.
109
+
110
+ Emails attached to other emails (an `.eml` forwarded as an attachment, or embedded in a
111
+ `.msg`) are read as messages and merged into the thread rather than listed as files.
112
+
113
+ ## `thread.json`
114
+
115
+ ```json
116
+ {
117
+ "thread": "Q3 budget",
118
+ "base_dir": "/abs/path/emlectomy-out/reply",
119
+ "stats": {
120
+ "emails_read": 3, "message_blocks_seen": 6, "messages_kept": 3,
121
+ "redundant_copies_removed": 3, "signatures_removed": 0,
122
+ "attachments_saved": 1, "duplicate_attachments_skipped": 2
123
+ },
124
+ "participants": [
125
+ {"name": "Alice Johnson", "email": "alice@example.com", "signature": "…"}
126
+ ],
127
+ "messages": [
128
+ {
129
+ "id": 3,
130
+ "from": "Alice Johnson <alice@example.com>",
131
+ "to": ["Bob Smith <bob@example.com>"],
132
+ "date": "2025-03-04T18:00:00+00:00",
133
+ "text": "Agreed with Bob on travel. I will cut it by 30 percent…",
134
+ "attachments": [
135
+ {"name": "budget.pdf", "path": "attachments/budget.pdf",
136
+ "mime": "application/pdf", "size": 45}
137
+ ],
138
+ "source": "email"
139
+ }
140
+ ]
141
+ }
142
+ ```
143
+
144
+ - Messages are oldest first; `id` is the position.
145
+ - Attachment `path`s are relative to the output folder; `base_dir` is its absolute path.
146
+ - `cc` and `subject` appear only when present, and `subject` only when it differs from `thread`.
147
+ - `source` is `email` (a file you gave it), `attached_email`, or `quoted_only` (the original
148
+ wasn't provided, so the message was rebuilt from a quote and its headers may be partial).
149
+ - `date` is `null` with a `date_text` when the date couldn't be parsed.
150
+ - `note` appears only on inline-reply messages.
151
+
152
+ ## Limits
153
+
154
+ - **Heuristics, not magic.** Unusual mail clients or heavily edited quotes can leave a bit of
155
+ repeated text or split a message in the wrong place. `stats` tells you what was removed.
156
+ - **A single `.eml` only contains what it quotes.** Replies on other branches of a
157
+ conversation aren't in it. Give emlectomy more files (or an `.mbox`) to cover more.
158
+ - **Formatting is plain text.** Colours and highlights (for example answers typed in yellow)
159
+ are lost.
160
+ - **`.msg`**: bodies come from the plain-text or HTML property; RTF-only messages aren't decoded.
161
+ - **`.pst` / `.ost`** archives aren't supported. Export to `.mbox` or `.eml` first.
162
+
163
+ ## Development
164
+
165
+ ```bash
166
+ python -m unittest discover -s tests # run the tests
167
+ python tests/fixtures.py # regenerate examples/
168
+ ```
169
+
170
+ The `.msg` tests use a small OLE writer in `tests/fixtures.py` rather than real Outlook files,
171
+ so real-world `.msg` bug reports (with a sample, if you can share one) are especially welcome.
172
+ Issues and pull requests are welcome.
173
+
174
+ ## License
175
+
176
+ [MIT](LICENSE)
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ emlectomy.py
4
+ pyproject.toml
5
+ emlectomy.egg-info/PKG-INFO
6
+ emlectomy.egg-info/SOURCES.txt
7
+ emlectomy.egg-info/dependency_links.txt
8
+ emlectomy.egg-info/entry_points.txt
9
+ emlectomy.egg-info/top_level.txt
10
+ tests/test_emlectomy.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ emlectomy = emlectomy:main
@@ -0,0 +1 @@
1
+ emlectomy