pigeon/email/cli.rs
1use std::path::PathBuf;
2
3use clap::{Args, Subcommand, ValueEnum};
4
5use crate::email::provider::Provider;
6
7#[derive(Args, Debug)]
8pub struct EmailArgs {
9 #[command(subcommand)]
10 pub command: EmailCommands,
11}
12
13#[derive(Subcommand, Debug)]
14pub enum EmailCommands {
15 /// Authenticate an email identity and register it under a local alias
16 Authenticate {
17 /// Email address of the identity to authenticate, e.g. first.last@example.com
18 email: String,
19
20 /// Local alias to store this identity under (e.g. first-last).
21 /// Defaults to a sanitized form of the email's local part.
22 #[arg(long)]
23 alias: Option<String>,
24
25 /// Email provider. Auto-detected from the email's domain when
26 /// omitted, falling back to an interactive prompt if detection fails.
27 #[arg(long)]
28 provider: Option<Provider>,
29
30 /// IMAP host, e.g. imap.example.com. Required when --provider is
31 /// "custom" (or resolves to it); ignored for known providers, which
32 /// use their own well-known host.
33 #[arg(long)]
34 host: Option<String>,
35
36 /// IMAP port. Defaults to 993 for a custom provider when omitted;
37 /// ignored for known providers, which use their own well-known port.
38 #[arg(long)]
39 port: Option<u16>,
40 },
41
42 /// List all locally authenticated email identities
43 List,
44
45 /// Download and transform all mail for an authenticated identity in one step
46 Sync {
47 /// Alias of the identity to sync, as registered via `authenticate`.
48 /// Interactively selected from the authenticated identities when omitted.
49 alias: Option<String>,
50
51 /// Local directory to stage raw .eml files under `staging/` and
52 /// write transformed Markdown output under `result/`. The staging
53 /// side is transient by default: each message is deleted once its
54 /// transform is verified. Only persists when --debug sink is used
55 /// and the default flow is never run against it afterward. Defaults
56 /// to a per-alias directory under the OS temp directory when omitted.
57 #[arg(long)]
58 local_output: Option<PathBuf>,
59
60 /// Alias of a configured bucket-config (see `pigeon dataops
61 /// bucket-config new`) to upload each synced message's Markdown and
62 /// attachments to, in addition to --local-output. Rejected as a
63 /// usage error when combined with --debug (sink/transform stay
64 /// local-only).
65 #[arg(long)]
66 remote_output: Option<String>,
67
68 /// Run only one phase, exactly as it behaved standalone before this
69 /// command existed: "sink" fetches without transforming; "transform"
70 /// transforms without fetching. Both are non-destructive (never
71 /// delete the source .eml).
72 #[arg(long)]
73 debug: Option<DebugPhase>,
74
75 /// Maximum number of mailboxes to process concurrently. Rejected in
76 /// combination with --debug, which stays single-mailbox and
77 /// sequential.
78 #[arg(long, default_value_t = 4)]
79 concurrency: usize,
80 },
81}
82
83/// A single phase of `sync`, run in isolation via `--debug`.
84#[derive(Copy, Clone, Debug, ValueEnum)]
85pub enum DebugPhase {
86 /// Fetch-only: write raw .eml files, never transform or delete them.
87 Sink,
88 /// Transform-only: read existing .eml files, never fetch or delete them.
89 Transform,
90}