From d9738b4be2add82ff955f061c79316b0dc91768f Mon Sep 17 00:00:00 2001 From: Elvis Claros Castro Date: Sat, 26 Sep 2026 18:47:40 -0300 Subject: posta: generic IMAP/SMTP mail CLI with JSON output --- src/main.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a60226b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,61 @@ +mod cli; +mod client; +mod commands; +mod config; +mod mailurl; +mod message; +mod output; + +use anyhow::Result; +use clap::Parser; + +use cli::{Cli, Cmd}; + +fn main() -> Result<()> { + let cli = Cli::parse(); + + // `accounts` inspects the config file itself; everything else needs one + // resolved account. + if let Cmd::Accounts = cli.cmd { + return commands::accounts(&cli.config, cli.format); + } + let acc = config::load(&cli.config, &cli.account)?; + + match cli.cmd { + Cmd::Accounts => unreachable!("handled above"), + Cmd::Folders => commands::folders(&acc, cli.format), + Cmd::Status { folder } => commands::status(&acc, &folder, cli.format), + Cmd::List { + folder, + unread, + query, + max, + } => commands::list(&acc, &folder, unread, query, max, cli.format), + Cmd::Get { + uid, + folder, + raw, + html, + mark_read, + } => commands::get(&acc, uid, &folder, raw, html, mark_read, cli.format), + Cmd::Send { + to, + cc, + subject, + body, + body_file, + no_record, + } => commands::send(&acc, &to, &cc, &subject, body, body_file, no_record), + Cmd::Mark { + state, + uids, + folder, + } => commands::mark(&acc, state, &uids, &folder), + Cmd::Move { uids, to, folder } => commands::move_cmd(&acc, &uids, &to, &folder), + Cmd::Delete { uids, folder } => { + let trash = acc.trash_folder.clone(); + commands::move_cmd(&acc, &uids, &trash, &folder) + } + Cmd::Search { query, folder } => commands::search(&acc, &query, &folder, cli.format), + } +} -- cgit v1.2.3