mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
58 lines
1.9 KiB
Rust
58 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;
|
|
use clap::Parser;
|
|
use io_maildir::flag::Flags;
|
|
use pimalaya_cli::printer::{Message, Printer};
|
|
|
|
use crate::maildir::{
|
|
arg::{MaildirPathFlag, MessageIdsArg},
|
|
client::MaildirClient,
|
|
flag::arg::FlagArg,
|
|
};
|
|
|
|
/// Add MAILDIR flag(s) to message(s).
|
|
///
|
|
/// This command adds the given flags to messages identified by the
|
|
/// given sequence set.
|
|
#[derive(Debug, Parser)]
|
|
pub struct MaildirFlagAddCommand {
|
|
#[command(flatten)]
|
|
pub ids: MessageIdsArg,
|
|
|
|
#[command(flatten)]
|
|
pub maildir: MaildirPathFlag,
|
|
/// Flag(s) to add to the message
|
|
#[arg(long = "flag", short, num_args = 1..)]
|
|
pub flags: Vec<FlagArg>,
|
|
}
|
|
|
|
impl MaildirFlagAddCommand {
|
|
pub fn execute(self, printer: &mut impl Printer, client: MaildirClient) -> Result<()> {
|
|
let maildir = client.resolve_maildir(&self.maildir.inner)?;
|
|
|
|
let flags = Flags::from_iter(self.flags.into_iter().map(Into::into));
|
|
|
|
for id in self.ids.inner {
|
|
client.add_flags(maildir.clone(), id, flags.clone())?;
|
|
}
|
|
|
|
printer.out(Message::new("Flag(s) successfully added"))
|
|
}
|
|
}
|