tuimail/proton-bridge/src/main.rs
Shautvast fc0eef0c31 Add ProtonMail API client (Step 3)
Implements typed async wrappers for the four endpoints tuimail needs:
- list_messages: GET /mail/v4/messages (paged inbox listing)
- get_message: GET /mail/v4/messages/{id} (full message with encrypted body)
- delete_messages: PUT /mail/v4/messages/delete (soft-delete to Trash)
- get_public_keys: GET /core/v4/keys (recipient keys for outbound mail)

All responses decoded through Envelope<T> with Code 1000 check.
main.rs smoke-tests the inbox listing after authentication.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-20 16:23:42 +01:00

42 lines
No EOL
1.3 KiB
Rust

mod api;
mod auth;
mod config;
mod srp;
use api::{ApiClient, LABEL_INBOX};
#[tokio::main]
async fn main() {
let config = match config::Config::load() {
Ok(c) => c,
Err(e) => { eprintln!("Failed to load bridge.toml: {}", e); std::process::exit(1); }
};
let client = match auth::build_client() {
Ok(c) => c,
Err(e) => { eprintln!("Failed to build HTTP client: {}", e); std::process::exit(1); }
};
let session = match auth::authenticate(&client, &config.proton).await {
Ok(s) => s,
Err(e) => { eprintln!("Authentication failed: {}", e); std::process::exit(1); }
};
println!("Session UID: {}", session.uid);
// Step 3 smoke-test: list the first page of inbox messages.
let api = ApiClient::new(&client, &session);
match api.list_messages(LABEL_INBOX, 0, 10).await {
Ok((messages, total)) => {
println!("\nInbox ({total} total):");
for m in &messages {
println!(
" [{:>5}] {:50}{}",
if m.unread == 1 { "UNREAD" } else { " read" },
m.subject,
m.sender.address,
);
}
}
Err(e) => eprintln!("list_messages failed: {}", e),
}
}