1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! # Himalaya
//!
//! A CLI to manage emails, and the crate architecture (header-001): the
//! behavioural contract lives in cairn/spec/, the manual provider test
//! reports in cairn/spec/testing/, the history in cairn/log/, the shared
//! conventions in the [Pimalaya ARCHITECTURE][pimalaya].
//!
//! [pimalaya]: https://github.com/pimalaya/.github/blob/master/ARCHITECTURE.md
//!
//! ## Place in the stack
//!
//! An application, the top of the Pimalaya stack: it writes no protocol
//! and no storage logic of its own and ships no library target, only this
//! binary. A thin shell driving the sans-I/O io-* libraries below it,
//! consuming their blocking `*Std` clients and rendering the results.
//!
//! ## Backends and plumbing
//!
//! The network backends are io-imap, io-jmap, io-gmail, io-msgraph,
//! io-smtp and io-managesieve, the local ones io-maildir, io-m2dir, io-mbox
//! and io-pimdir.
//! Account discovery comes from io-pim-discovery: Mozilla autoconfig,
//! PACC, RFC 6186 SRV, RFC 8620 JMAP resolve.
//!
//! The CLI plumbing, TOML loading and blocking stream runtime come from
//! pimalaya-cli, pimalaya-config and pimalaya-stream. Every backend sits
//! behind its own cargo feature, so a build ships only the protocols it
//! needs.
//!
//! ## Command families
//!
//! The command tree ([`cli`], `Command`) splits in three. The shared API
//! (mailbox, envelope, flag, message, attachment) is the cross-protocol
//! least-common-denominator surface, behaving the same whatever backend
//! serves the active account.
//!
//! The protocol-specific APIs (imap, jmap, gmail, msgraph, maildir,
//! m2dir, mbox, pimdir, smtp, sieve) each expose the full surface of one backend,
//! including operations the shared API cannot model. The meta commands
//! cover account configuration, completions, man pages and JSON Schemas.
//!
//! ## Shared commands and backend selection
//!
//! The shared commands run over a [`shared::client`] `EmailClient` owning
//! one `BackendClient` variant per compiled-in backend: the first
//! configured storage backend the global `--backend` flag allows, local
//! before network, plus an SMTP transport for those that cannot send.
//!
//! Each shared method matches the active backend and calls its
//! per-protocol adapter, which converts io-* results into the CLI's own
//! [`email`] shared types. The active [`account`] context is threaded as
//! a sibling argument through every `execute` chain.
//!
//! ## Protocol-specific commands
//!
//! Each protocol module builds its client via a `build_<proto>_client`
//! helper and a `<Proto>Client` wrapper that derefs onto the io-* `*Std`
//! client, ignoring `--backend`. Subcommands are clap-derived structs
//! with an `execute` method the module's command enum dispatches to.
//!
//! The imap command mirrors IMAP's flat command list, gmail and msgraph
//! track their REST resource domains one-to-one, and the filesystem
//! backends expose only what maps to their on-disk layout, leaving MIME
//! rendering to the shared commands.
//!
//! ## Configuration and output
//!
//! Config is loaded by pimalaya-config from the first existing canonical
//! path, or the `-c` override, later paths deep-merged on top. The schema
//! ([`config`]) is multi-account: a top-level block plus named account
//! blocks carrying optional per-backend sub-blocks.
//!
//! Bare `himalaya` runs the interactive [`wizard`], which discovers an
//! account and offers to save it, or prints it on stdout when redirected;
//! it is also proposed when a command finds no config. A config that
//! exists but lacks the requested account is a hard error.
//!
//! Output follows the Pimalaya rule: data and errors go to stdout through
//! the printer, `--json` switching every command to JSON, and stderr
//! carries logs only. Each command's doc comment is its `--help`, so
//! `himalaya <command> --help` is the canonical usage reference.
use ;
use Result;
use ;
use ;
use TomlConfig;
use crate::;
/// Meets a bare `himalaya`, which is where a newcomer lands.
///
/// A missing configuration raises the offer; anything else gets the help.
/// A broken file counts as a configuration, so the offer never writes over
/// one, and `--account` alone is a half-typed command, not a first run.