// This file is part of Himalaya, a CLI to manage emails. // // Copyright (C) 2022-2026 soywod // // 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 . use anyhow::Result; use clap::Parser; use io_imap::types::mailbox::Mailbox; use pimalaya_cli::printer::{Message, Printer}; use crate::imap::{ client::ImapClient, mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag, TargetMailboxNameArg}, }; /// Move message(s) to the given mailbox. /// /// This command moves messages identified by the given sequence set /// from the source mailbox to the destination mailbox. Requires the /// MOVE IMAP extension. #[derive(Debug, Parser)] pub struct ImapMessageMoveCommand { #[command(flatten)] pub mailbox_name: MailboxNameOptionalFlag, #[command(flatten)] pub mailbox_no_select: MailboxNoSelectFlag, /// The sequence set of messages (e.g., "1", "1,2,3", "1:*"). #[arg(name = "sequence_set", value_name = "SEQUENCE")] pub sequence_set: String, #[command(flatten)] pub mailbox_dest_name: TargetMailboxNameArg, /// Use sequence numbers instead of UIDs. #[arg(long)] pub seq: bool, } impl ImapMessageMoveCommand { pub fn execute(self, printer: &mut impl Printer, client: &mut ImapClient) -> Result<()> { let mailbox = self.mailbox_name.inner.try_into()?; if !self.mailbox_no_select.inner { client.select(mailbox)?; } let sequence_set = self.sequence_set.as_str().try_into()?; let destination: Mailbox<'static> = self.mailbox_dest_name.inner.try_into()?; client.r#move(sequence_set, destination, !self.seq)?; printer.out(Message::new("Message(s) successfully moved")) } }