mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-16 12:47:55 +08:00
57 lines
1.9 KiB
Rust
57 lines
1.9 KiB
Rust
// This file is part of Himalaya, a CLI to manage emails.
|
|
//
|
|
// Copyright (C) 2022-2026 soywod <pimalaya.org@posteo.net>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify it under
|
|
// the terms of the GNU Affero General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option) any
|
|
// later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
// details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
use anyhow::{Result, bail};
|
|
use clap::Parser;
|
|
use io_jmap::rfc8621::email_set::JmapEmailSetArgs;
|
|
use pimalaya_cli::printer::{Message, Printer};
|
|
|
|
use crate::jmap::{client::JmapClient, error::format_set_error};
|
|
|
|
/// Delete JMAP emails (Email/set destroy).
|
|
#[derive(Debug, Parser)]
|
|
pub struct JmapEmailDestroyCommand {
|
|
/// Email ID(s) to delete.
|
|
#[arg(value_name = "ID", required = true)]
|
|
pub ids: Vec<String>,
|
|
}
|
|
|
|
impl JmapEmailDestroyCommand {
|
|
pub fn execute(self, printer: &mut impl Printer, mut client: JmapClient) -> Result<()> {
|
|
let mut args = JmapEmailSetArgs::default();
|
|
|
|
for id in self.ids {
|
|
args.destroy(id);
|
|
}
|
|
|
|
let output = client.email_set(args)?;
|
|
|
|
if !output.not_destroyed.is_empty() {
|
|
let mut msg = String::from("Destroy JMAP email(s) error");
|
|
|
|
for (id, err) in output.not_destroyed {
|
|
msg.push_str(&format!("\n `{id}`"));
|
|
msg.push_str(&format_set_error(&err));
|
|
}
|
|
|
|
bail!(msg)
|
|
}
|
|
|
|
printer.out(Message::new("Email(s) successfully deleted"))
|
|
}
|
|
}
|