himalaya-kit 0.2.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.
Files changed (44) hide show
  1. himalaya_kit-0.2.0/LICENSE +189 -0
  2. himalaya_kit-0.2.0/PKG-INFO +250 -0
  3. himalaya_kit-0.2.0/README.md +223 -0
  4. himalaya_kit-0.2.0/himalaya_kit/__init__.py +14 -0
  5. himalaya_kit-0.2.0/himalaya_kit/_lib/__init__.py +0 -0
  6. himalaya_kit-0.2.0/himalaya_kit/_lib/mail_compose.py +139 -0
  7. himalaya_kit-0.2.0/himalaya_kit/_lib/mail_message.py +320 -0
  8. himalaya_kit-0.2.0/himalaya_kit/_lib/mail_send.py +399 -0
  9. himalaya_kit-0.2.0/himalaya_kit/archive.py +301 -0
  10. himalaya_kit-0.2.0/himalaya_kit/cli.py +404 -0
  11. himalaya_kit-0.2.0/himalaya_kit/config.py +246 -0
  12. himalaya_kit-0.2.0/himalaya_kit/contacts/__init__.py +11 -0
  13. himalaya_kit-0.2.0/himalaya_kit/contacts/ai_todo.py +66 -0
  14. himalaya_kit-0.2.0/himalaya_kit/contacts/json_file.py +49 -0
  15. himalaya_kit-0.2.0/himalaya_kit/contacts/none.py +12 -0
  16. himalaya_kit-0.2.0/himalaya_kit/contacts/store.py +85 -0
  17. himalaya_kit-0.2.0/himalaya_kit/contacts/types.py +19 -0
  18. himalaya_kit-0.2.0/himalaya_kit/export.py +548 -0
  19. himalaya_kit-0.2.0/himalaya_kit/forward.py +158 -0
  20. himalaya_kit-0.2.0/himalaya_kit/i18n.py +104 -0
  21. himalaya_kit-0.2.0/himalaya_kit/locales/en_US.json +191 -0
  22. himalaya_kit-0.2.0/himalaya_kit/locales/zh_CN.json +191 -0
  23. himalaya_kit-0.2.0/himalaya_kit/reply.py +141 -0
  24. himalaya_kit-0.2.0/himalaya_kit/search.py +320 -0
  25. himalaya_kit-0.2.0/himalaya_kit/send.py +98 -0
  26. himalaya_kit-0.2.0/himalaya_kit/yearly_archive.py +90 -0
  27. himalaya_kit-0.2.0/himalaya_kit.egg-info/PKG-INFO +250 -0
  28. himalaya_kit-0.2.0/himalaya_kit.egg-info/SOURCES.txt +42 -0
  29. himalaya_kit-0.2.0/himalaya_kit.egg-info/dependency_links.txt +1 -0
  30. himalaya_kit-0.2.0/himalaya_kit.egg-info/entry_points.txt +2 -0
  31. himalaya_kit-0.2.0/himalaya_kit.egg-info/requires.txt +9 -0
  32. himalaya_kit-0.2.0/himalaya_kit.egg-info/top_level.txt +1 -0
  33. himalaya_kit-0.2.0/pyproject.toml +45 -0
  34. himalaya_kit-0.2.0/setup.cfg +4 -0
  35. himalaya_kit-0.2.0/tests/test_archive.py +204 -0
  36. himalaya_kit-0.2.0/tests/test_config.py +202 -0
  37. himalaya_kit-0.2.0/tests/test_contacts.py +123 -0
  38. himalaya_kit-0.2.0/tests/test_distribution.py +26 -0
  39. himalaya_kit-0.2.0/tests/test_export.py +291 -0
  40. himalaya_kit-0.2.0/tests/test_export_cli.py +69 -0
  41. himalaya_kit-0.2.0/tests/test_i18n.py +114 -0
  42. himalaya_kit-0.2.0/tests/test_mail_message.py +135 -0
  43. himalaya_kit-0.2.0/tests/test_mail_send.py +98 -0
  44. himalaya_kit-0.2.0/tests/test_yearly_archive.py +52 -0
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including
48
+ the original version of the Work and any modifications or additions
49
+ to that Work or Derivative Works thereof, that is intentionally
50
+ submitted to the Licensor for inclusion in the Work by the copyright owner
51
+ or by an individual or Legal Entity authorized to submit on behalf of
52
+ the copyright owner. For the purposes of this definition, "submitted"
53
+ means any form of electronic, verbal, or written communication sent
54
+ to the Licensor or its representatives, including but not limited to
55
+ communication on electronic mailing lists, source code control systems,
56
+ and issue tracking systems that are managed by, or on behalf of, the
57
+ Licensor for the purpose of discussing and improving the Work, but
58
+ excluding communication that is conspicuously marked or otherwise
59
+ designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity
62
+ on behalf of whom a Contribution has been received by the Licensor and
63
+ subsequently incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of
66
+ this License, each Contributor hereby grants to You a perpetual,
67
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
68
+ copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the
70
+ Work and such Derivative Works in Source or Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of
73
+ this License, each Contributor hereby grants to You a perpetual,
74
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
+ (except as stated in this section) patent license to make, have made,
76
+ use, offer to sell, sell, import, and otherwise transfer the Work,
77
+ where such license applies only to those patent claims licensable
78
+ by such Contributor that are necessarily infringed by their
79
+ Contribution(s) alone or by combination of their Contribution(s)
80
+ with the Work to which such Contribution(s) was submitted. If You
81
+ institute patent litigation against any entity (including a
82
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
83
+ or a Contribution incorporated within the Work constitutes direct
84
+ or contributory patent infringement, then any patent licenses
85
+ granted to You under this License for that Work shall terminate
86
+ as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the
89
+ Work or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You
91
+ meet the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or
94
+ Derivative Works a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works
100
+ that You distribute, all copyright, patent, trademark, and
101
+ attribution notices from the Source form of the Work,
102
+ excluding those notices that do not pertain to any part of
103
+ the Derivative Works; and
104
+
105
+ (d) If the Work includes a "NOTICE" text file as part of its
106
+ distribution, then any Derivative Works that You distribute must
107
+ include a readable copy of the attribution notices contained
108
+ within such NOTICE file, excluding any notices that do not
109
+ pertain to any part of the Derivative Works, in at least one
110
+ of the following places: within a NOTICE text file distributed
111
+ as part of the Derivative Works; within the Source form or
112
+ documentation, if provided along with the Derivative Works; or,
113
+ within a display generated by the Derivative Works, if and
114
+ wherever such third-party notices normally appear. The contents
115
+ of the NOTICE file are for informational purposes only and
116
+ do not modify the License. You may add Your own attribution
117
+ notices within Derivative Works that You distribute, alongside
118
+ or as an addendum to the NOTICE text from the Work, provided
119
+ that such additional attribution notices cannot be construed
120
+ as modifying the License.
121
+
122
+ You may add Your own copyright statement to Your modifications and
123
+ may provide additional or different license terms and conditions
124
+ for use, reproduction, or distribution of Your modifications, or
125
+ for any such Derivative Works as a whole, provided Your use,
126
+ reproduction, and distribution of the Work otherwise complies with
127
+ the conditions stated in this License.
128
+
129
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
130
+ any Contribution intentionally submitted for inclusion in the Work
131
+ by You to the Licensor shall be under the terms and conditions of
132
+ this License, without any additional terms or conditions.
133
+ Notwithstanding the above, nothing herein shall supersede or modify
134
+ the terms of any separate license agreement you may have executed
135
+ with Licensor regarding such Contributions.
136
+
137
+ 6. Trademarks. This License does not grant permission to use the trade
138
+ names, trademarks, service marks, or product names of the Licensor,
139
+ except as required for reasonable and customary use in describing the
140
+ origin of the Work and reproducing the content of the NOTICE file.
141
+
142
+ 7. Disclaimer of Warranty. Unless required by applicable law or
143
+ agreed to in writing, Licensor provides the Work (and each
144
+ Contributor provides its Contributions) on an "AS IS" BASIS,
145
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
146
+ implied, including, without limitation, any warranties or conditions
147
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
148
+ PARTICULAR PURPOSE. You are solely responsible for determining the
149
+ appropriateness of using or redistributing the Work and assume any
150
+ risks associated with Your exercise of permissions under this License.
151
+
152
+ 8. Limitation of Liability. In no event and under no legal theory,
153
+ whether in tort (including negligence), contract, or otherwise,
154
+ unless required by applicable law (such as deliberate and grossly
155
+ negligent acts) or agreed to in writing, shall any Contributor be
156
+ liable to You for damages, including any direct, indirect, special,
157
+ incidental, or consequential damages of any character arising as a
158
+ result of this License or out of the use or inability to use the
159
+ Work (including but not limited to damages for loss of goodwill,
160
+ work stoppage, computer failure or malfunction, or any and all
161
+ other commercial damages or losses), even if such Contributor
162
+ has been advised of the possibility of such damages.
163
+
164
+ 9. Accepting Warranty or Additional Liability. While redistributing
165
+ the Work or Derivative Works thereof, You may choose to offer,
166
+ and charge a fee for, acceptance of support, warranty, indemnity,
167
+ or other liability obligations and/or rights consistent with this
168
+ License. However, in accepting such obligations, You may act only
169
+ on Your own behalf and on Your sole responsibility, not on behalf
170
+ of any other Contributor, and only if You agree to indemnify,
171
+ defend, and hold each Contributor harmless for any liability
172
+ incurred by, or claims asserted against, such Contributor by reason
173
+ of your accepting any such warranty or additional liability.
174
+
175
+ END OF TERMS AND CONDITIONS
176
+
177
+ Copyright 2026 himalaya-kit contributors
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.4
2
+ Name: himalaya-kit
3
+ Version: 0.2.0
4
+ Summary: An extension toolkit for reliable multi-step himalaya email automation and agent workflows
5
+ Author: himalaya-kit contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/xiaolinstar/himalaya-kit
8
+ Project-URL: Repository, https://github.com/xiaolinstar/himalaya-kit
9
+ Project-URL: Issues, https://github.com/xiaolinstar/himalaya-kit/issues
10
+ Project-URL: Changelog, https://github.com/xiaolinstar/himalaya-kit/releases
11
+ Keywords: email,himalaya,cli,imap,smtp,agent
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Communications :: Email
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: tomli>=2.0; python_version < "3.11"
22
+ Provides-Extra: markdown
23
+ Requires-Dist: markdown-it-py~=4.2; extra == "markdown"
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # himalaya-kit
29
+
30
+ himalaya-kit is a Python toolkit that complements the [himalaya](https://github.com/pimalaya/himalaya) mail CLI for automation and AI-assisted workflows. It combines himalaya primitives into safer multi-step workflows for composing, sending, searching, batch-exporting, and optionally organizing mail.
31
+
32
+ > **Project status:** Alpha. The core workflows are usable, but command output and public interfaces may still evolve across `0.x` releases.
33
+
34
+ ## Why this project exists
35
+
36
+ himalaya already provides a solid foundation for mail access and folder management. himalaya-kit is designed to fill the gaps that often appear in scripted or agent-driven workflows by offering a small, reusable layer on top of himalaya rather than replacing it.
37
+
38
+ ## Features
39
+
40
+ | Command | Purpose |
41
+ |------|---------|
42
+ | `send` | Compose and send a new message |
43
+ | `reply` | Reply to an existing message |
44
+ | `forward` | Forward a message with optional attachments |
45
+ | `search` | Search archived mail and online mail by sender or keyword |
46
+ | `export` | Safely batch-export, validate, index, and resume local `.eml` backups |
47
+
48
+ Optional workflows:
49
+
50
+ | Command | Purpose |
51
+ |------|---------|
52
+ | `archive` | Apply the bundled five-level organization preset |
53
+ | `yearly-archive` | Run the legacy yearly export-and-delete workflow |
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ pip install himalaya-kit
59
+ ```
60
+
61
+ Or install from source:
62
+
63
+ ```bash
64
+ git clone https://github.com/xiaolinstar/himalaya-kit.git
65
+ cd himalaya-kit
66
+ pip install -e .
67
+ ```
68
+
69
+ ## Quick start
70
+
71
+ ```bash
72
+ # Send a message
73
+ himalaya-kit send -t "张三 <zhangsan@example.com>" -s "测试" -b "你好"
74
+
75
+ # Send Markdown mail
76
+ echo "# 报告" | himalaya-kit send -t user@example.com -s "周报" --markdown
77
+
78
+ # Reply to an existing message
79
+ himalaya-kit reply 12345 -b "收到,谢谢"
80
+
81
+ # Forward a message
82
+ himalaya-kit forward 12345 user@example.com --note "请查收"
83
+
84
+ # Search mail by sender
85
+ himalaya-kit search "Alice"
86
+
87
+ # Archive mail from the inbox
88
+ himalaya-kit archive --days 7
89
+
90
+ # Preview archive actions without moving mail
91
+ himalaya-kit archive --dry-run
92
+
93
+ # Preview a safe batch export (zero local writes and no server changes)
94
+ himalaya-kit export --before 2025-01-01 --dry-run
95
+
96
+ # Export one full message with native himalaya
97
+ himalaya message export --full -d message.eml 12345
98
+ ```
99
+
100
+ ## himalaya vs himalaya-kit
101
+
102
+ Use himalaya directly when one native command safely completes the task. Use himalaya-kit when the task needs batching, validation, durable state, recovery, or coordination across multiple himalaya commands.
103
+
104
+ | Goal | Recommended tool | Why |
105
+ |------|------------------|-----|
106
+ | Export one message | `himalaya message export` | Native primitive is sufficient |
107
+ | Copy or move known message IDs | `himalaya message copy/move` | Native batch operation is sufficient |
108
+ | Export a date range | `himalaya-kit export` | Adds pagination, validation, indexing, and recovery |
109
+ | Export then remove server copies | `himalaya-kit export --delete-after-export` | Enforces export → verify → save index → delete ordering |
110
+ | Apply the five-level inbox model | `himalaya-kit archive` | Optional bundled workflow, not a universal email model |
111
+
112
+ `archive` copies messages into priority folders and leaves the originals in place. `yearly-archive` is retained as a destructive compatibility workflow: after verified local export and index persistence, it marks server copies as deleted. Always run destructive workflows with `--dry-run` first.
113
+
114
+ ## Safe batch export
115
+
116
+ ```bash
117
+ # Strictly before the given date; defaults to INBOX
118
+ himalaya-kit export --before 2025-01-01 --dry-run
119
+
120
+ # Export a calendar year from multiple folders
121
+ himalaya-kit export --year 2025 \
122
+ --folder INBOX --folder Sent \
123
+ --output ~/email-archive/work
124
+
125
+ # Export an open/closed date range using strict boundaries
126
+ himalaya-kit export --after 2024-01-01 --before 2025-01-01
127
+
128
+ # Machine-readable plan for an Agent
129
+ himalaya-kit export --year 2025 --dry-run --json
130
+
131
+ # Destructive option: only delete after verified export and durable index save
132
+ himalaya-kit export --before 2025-01-01 --delete-after-export
133
+ ```
134
+
135
+ Exports use himalaya's native `envelope list` and `message export` commands. himalaya-kit adds atomic file writes, basic `.eml` validation, collision-resistant names, an atomic `archive-index.json`, and repeat-run recovery. `--dry-run` does not create the output directory or modify server state.
136
+
137
+ Human-facing runs emit stable line-oriented logs as folders are scanned and messages complete, followed by a summary. `--json` suppresses those text logs and writes one complete JSON result to stdout for Agents and scripts. Dynamic terminal progress bars are intentionally not used.
138
+
139
+ ## Requirements
140
+
141
+ - Python 3.10+
142
+ - The [himalaya](https://github.com/pimalaya/himalaya) CLI installed and configured
143
+ - A himalaya config file at `~/.config/himalaya/config.toml`
144
+
145
+ ## Internationalization (i18n)
146
+
147
+ himalaya-kit supports Chinese (default) and English interfaces. You can switch languages in three ways:
148
+
149
+ ### 1. Command-line argument
150
+
151
+ ```bash
152
+ himalaya-kit --lang en send --help
153
+ himalaya-kit --lang zh send --help
154
+ ```
155
+
156
+ ### 2. Environment variable
157
+
158
+ ```bash
159
+ export HIMALAYA_KIT_LANG=en
160
+ himalaya-kit send --help
161
+ ```
162
+
163
+ ### 3. Config file
164
+
165
+ ```toml
166
+ [himalaya_kit]
167
+ lang = "en_US"
168
+ ```
169
+
170
+ Supported language codes:
171
+ - `zh_CN` or `zh` - Chinese (default)
172
+ - `en_US` or `en` - English
173
+
174
+ ## Configuration
175
+
176
+ himalaya-kit reuses the existing himalaya account configuration and does not require a separate mail setup. A typical configuration looks like this:
177
+
178
+ ```toml
179
+ [accounts.work]
180
+ default = true
181
+ email = "yourname@company.com"
182
+ display-name = "Your Name"
183
+ # ... SMTP/IMAP settings
184
+ ```
185
+
186
+ Optional extensions can be added under the `[himalaya_kit]` section:
187
+
188
+ ```toml
189
+ [himalaya_kit]
190
+ backup-root = "~/email-archive"
191
+
192
+ my-email = "yourname@company.com"
193
+ priority-contacts = ["boss@company.com"]
194
+ system-accounts = ["noreply@company.com"]
195
+ internal-domains = ["company.com"]
196
+ timezone = "Asia/Shanghai"
197
+
198
+ notification-keywords = ["notification", "alert", "通知", "提醒"]
199
+
200
+ priority-folders = [
201
+ "Priority-1-Urgent",
202
+ "Priority-2-Internal",
203
+ "Priority-3-External",
204
+ "Priority-4-CC",
205
+ "Priority-5-Notifications",
206
+ ]
207
+
208
+ [himalaya_kit.contacts]
209
+ provider = "json" # none | json | ai-todo
210
+ file = "~/.config/himalaya/contacts.json"
211
+ ```
212
+
213
+ See [`examples/config.example.toml`](examples/config.example.toml) and [`examples/contacts.example.json`](examples/contacts.example.json) for full examples.
214
+
215
+ **Contacts**: himalaya has no built-in address book. Use a local JSON file (default provider when configured) or optionally plug in `ai-todo` as an external contact source. Contacts with `"tags": ["priority"]` are merged into high-priority classification alongside `priority-contacts`.
216
+
217
+ **Backward compatibility**: `leader-emails` is still read and merged into `priority-contacts`.
218
+
219
+ Environment variables:
220
+
221
+ | Variable | Description |
222
+ |------|------|
223
+ | `HIMALAYA_KIT_BACKUP_ROOT` | Override the archive backup directory |
224
+
225
+ ## Python API
226
+
227
+ himalaya-kit can also be used as a Python library:
228
+
229
+ ```python
230
+ from himalaya_kit.config import load_kit_config
231
+ from himalaya_kit.contacts import load_contact_store
232
+
233
+ config = load_kit_config("work")
234
+ store = load_contact_store(config.contacts)
235
+ print(config.account_email)
236
+ print(config.priority_folders)
237
+ print(store.lookup_by_email("boss@company.com"))
238
+ ```
239
+
240
+ ## Development
241
+
242
+ Run the test suite with:
243
+
244
+ ```bash
245
+ pytest -q
246
+ ```
247
+
248
+ ## License
249
+
250
+ Apache License 2.0
@@ -0,0 +1,223 @@
1
+ # himalaya-kit
2
+
3
+ himalaya-kit is a Python toolkit that complements the [himalaya](https://github.com/pimalaya/himalaya) mail CLI for automation and AI-assisted workflows. It combines himalaya primitives into safer multi-step workflows for composing, sending, searching, batch-exporting, and optionally organizing mail.
4
+
5
+ > **Project status:** Alpha. The core workflows are usable, but command output and public interfaces may still evolve across `0.x` releases.
6
+
7
+ ## Why this project exists
8
+
9
+ himalaya already provides a solid foundation for mail access and folder management. himalaya-kit is designed to fill the gaps that often appear in scripted or agent-driven workflows by offering a small, reusable layer on top of himalaya rather than replacing it.
10
+
11
+ ## Features
12
+
13
+ | Command | Purpose |
14
+ |------|---------|
15
+ | `send` | Compose and send a new message |
16
+ | `reply` | Reply to an existing message |
17
+ | `forward` | Forward a message with optional attachments |
18
+ | `search` | Search archived mail and online mail by sender or keyword |
19
+ | `export` | Safely batch-export, validate, index, and resume local `.eml` backups |
20
+
21
+ Optional workflows:
22
+
23
+ | Command | Purpose |
24
+ |------|---------|
25
+ | `archive` | Apply the bundled five-level organization preset |
26
+ | `yearly-archive` | Run the legacy yearly export-and-delete workflow |
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install himalaya-kit
32
+ ```
33
+
34
+ Or install from source:
35
+
36
+ ```bash
37
+ git clone https://github.com/xiaolinstar/himalaya-kit.git
38
+ cd himalaya-kit
39
+ pip install -e .
40
+ ```
41
+
42
+ ## Quick start
43
+
44
+ ```bash
45
+ # Send a message
46
+ himalaya-kit send -t "张三 <zhangsan@example.com>" -s "测试" -b "你好"
47
+
48
+ # Send Markdown mail
49
+ echo "# 报告" | himalaya-kit send -t user@example.com -s "周报" --markdown
50
+
51
+ # Reply to an existing message
52
+ himalaya-kit reply 12345 -b "收到,谢谢"
53
+
54
+ # Forward a message
55
+ himalaya-kit forward 12345 user@example.com --note "请查收"
56
+
57
+ # Search mail by sender
58
+ himalaya-kit search "Alice"
59
+
60
+ # Archive mail from the inbox
61
+ himalaya-kit archive --days 7
62
+
63
+ # Preview archive actions without moving mail
64
+ himalaya-kit archive --dry-run
65
+
66
+ # Preview a safe batch export (zero local writes and no server changes)
67
+ himalaya-kit export --before 2025-01-01 --dry-run
68
+
69
+ # Export one full message with native himalaya
70
+ himalaya message export --full -d message.eml 12345
71
+ ```
72
+
73
+ ## himalaya vs himalaya-kit
74
+
75
+ Use himalaya directly when one native command safely completes the task. Use himalaya-kit when the task needs batching, validation, durable state, recovery, or coordination across multiple himalaya commands.
76
+
77
+ | Goal | Recommended tool | Why |
78
+ |------|------------------|-----|
79
+ | Export one message | `himalaya message export` | Native primitive is sufficient |
80
+ | Copy or move known message IDs | `himalaya message copy/move` | Native batch operation is sufficient |
81
+ | Export a date range | `himalaya-kit export` | Adds pagination, validation, indexing, and recovery |
82
+ | Export then remove server copies | `himalaya-kit export --delete-after-export` | Enforces export → verify → save index → delete ordering |
83
+ | Apply the five-level inbox model | `himalaya-kit archive` | Optional bundled workflow, not a universal email model |
84
+
85
+ `archive` copies messages into priority folders and leaves the originals in place. `yearly-archive` is retained as a destructive compatibility workflow: after verified local export and index persistence, it marks server copies as deleted. Always run destructive workflows with `--dry-run` first.
86
+
87
+ ## Safe batch export
88
+
89
+ ```bash
90
+ # Strictly before the given date; defaults to INBOX
91
+ himalaya-kit export --before 2025-01-01 --dry-run
92
+
93
+ # Export a calendar year from multiple folders
94
+ himalaya-kit export --year 2025 \
95
+ --folder INBOX --folder Sent \
96
+ --output ~/email-archive/work
97
+
98
+ # Export an open/closed date range using strict boundaries
99
+ himalaya-kit export --after 2024-01-01 --before 2025-01-01
100
+
101
+ # Machine-readable plan for an Agent
102
+ himalaya-kit export --year 2025 --dry-run --json
103
+
104
+ # Destructive option: only delete after verified export and durable index save
105
+ himalaya-kit export --before 2025-01-01 --delete-after-export
106
+ ```
107
+
108
+ Exports use himalaya's native `envelope list` and `message export` commands. himalaya-kit adds atomic file writes, basic `.eml` validation, collision-resistant names, an atomic `archive-index.json`, and repeat-run recovery. `--dry-run` does not create the output directory or modify server state.
109
+
110
+ Human-facing runs emit stable line-oriented logs as folders are scanned and messages complete, followed by a summary. `--json` suppresses those text logs and writes one complete JSON result to stdout for Agents and scripts. Dynamic terminal progress bars are intentionally not used.
111
+
112
+ ## Requirements
113
+
114
+ - Python 3.10+
115
+ - The [himalaya](https://github.com/pimalaya/himalaya) CLI installed and configured
116
+ - A himalaya config file at `~/.config/himalaya/config.toml`
117
+
118
+ ## Internationalization (i18n)
119
+
120
+ himalaya-kit supports Chinese (default) and English interfaces. You can switch languages in three ways:
121
+
122
+ ### 1. Command-line argument
123
+
124
+ ```bash
125
+ himalaya-kit --lang en send --help
126
+ himalaya-kit --lang zh send --help
127
+ ```
128
+
129
+ ### 2. Environment variable
130
+
131
+ ```bash
132
+ export HIMALAYA_KIT_LANG=en
133
+ himalaya-kit send --help
134
+ ```
135
+
136
+ ### 3. Config file
137
+
138
+ ```toml
139
+ [himalaya_kit]
140
+ lang = "en_US"
141
+ ```
142
+
143
+ Supported language codes:
144
+ - `zh_CN` or `zh` - Chinese (default)
145
+ - `en_US` or `en` - English
146
+
147
+ ## Configuration
148
+
149
+ himalaya-kit reuses the existing himalaya account configuration and does not require a separate mail setup. A typical configuration looks like this:
150
+
151
+ ```toml
152
+ [accounts.work]
153
+ default = true
154
+ email = "yourname@company.com"
155
+ display-name = "Your Name"
156
+ # ... SMTP/IMAP settings
157
+ ```
158
+
159
+ Optional extensions can be added under the `[himalaya_kit]` section:
160
+
161
+ ```toml
162
+ [himalaya_kit]
163
+ backup-root = "~/email-archive"
164
+
165
+ my-email = "yourname@company.com"
166
+ priority-contacts = ["boss@company.com"]
167
+ system-accounts = ["noreply@company.com"]
168
+ internal-domains = ["company.com"]
169
+ timezone = "Asia/Shanghai"
170
+
171
+ notification-keywords = ["notification", "alert", "通知", "提醒"]
172
+
173
+ priority-folders = [
174
+ "Priority-1-Urgent",
175
+ "Priority-2-Internal",
176
+ "Priority-3-External",
177
+ "Priority-4-CC",
178
+ "Priority-5-Notifications",
179
+ ]
180
+
181
+ [himalaya_kit.contacts]
182
+ provider = "json" # none | json | ai-todo
183
+ file = "~/.config/himalaya/contacts.json"
184
+ ```
185
+
186
+ See [`examples/config.example.toml`](examples/config.example.toml) and [`examples/contacts.example.json`](examples/contacts.example.json) for full examples.
187
+
188
+ **Contacts**: himalaya has no built-in address book. Use a local JSON file (default provider when configured) or optionally plug in `ai-todo` as an external contact source. Contacts with `"tags": ["priority"]` are merged into high-priority classification alongside `priority-contacts`.
189
+
190
+ **Backward compatibility**: `leader-emails` is still read and merged into `priority-contacts`.
191
+
192
+ Environment variables:
193
+
194
+ | Variable | Description |
195
+ |------|------|
196
+ | `HIMALAYA_KIT_BACKUP_ROOT` | Override the archive backup directory |
197
+
198
+ ## Python API
199
+
200
+ himalaya-kit can also be used as a Python library:
201
+
202
+ ```python
203
+ from himalaya_kit.config import load_kit_config
204
+ from himalaya_kit.contacts import load_contact_store
205
+
206
+ config = load_kit_config("work")
207
+ store = load_contact_store(config.contacts)
208
+ print(config.account_email)
209
+ print(config.priority_folders)
210
+ print(store.lookup_by_email("boss@company.com"))
211
+ ```
212
+
213
+ ## Development
214
+
215
+ Run the test suite with:
216
+
217
+ ```bash
218
+ pytest -q
219
+ ```
220
+
221
+ ## License
222
+
223
+ Apache License 2.0
@@ -0,0 +1,14 @@
1
+ """himalaya-kit: himalaya 邮件 CLI 的增强工具箱"""
2
+
3
+ __version__ = "0.2.0"
4
+
5
+ from himalaya_kit.config import KitConfig, load_kit_config
6
+ from himalaya_kit.contacts import ContactStore, load_contact_store
7
+
8
+ __all__ = [
9
+ "__version__",
10
+ "KitConfig",
11
+ "load_kit_config",
12
+ "ContactStore",
13
+ "load_contact_store",
14
+ ]
File without changes