mirror of
https://github.com/pimalaya/himalaya.git
synced 2024-12-09 21:18:39 +03:00
71 lines
2.0 KiB
Rust
71 lines
2.0 KiB
Rust
use std::sync::Arc;
|
|
|
|
use clap::Parser;
|
|
use color_eyre::Result;
|
|
use email::{backend::feature::BackendFeatureSource, config::Config};
|
|
use pimalaya_tui::{
|
|
himalaya::backend::BackendBuilder,
|
|
terminal::{cli::printer::Printer, config::TomlConfig as _},
|
|
};
|
|
use tracing::info;
|
|
|
|
#[allow(unused)]
|
|
use crate::{
|
|
account::arg::name::AccountNameFlag,
|
|
config::TomlConfig,
|
|
envelope::arg::ids::EnvelopeIdsArgs,
|
|
folder::arg::name::{SourceFolderNameOptionalFlag, TargetFolderNameArg},
|
|
};
|
|
|
|
/// Move the message associated to the given envelope id(s) to the
|
|
/// given target folder.
|
|
#[derive(Debug, Parser)]
|
|
pub struct MessageMoveCommand {
|
|
#[command(flatten)]
|
|
pub source_folder: SourceFolderNameOptionalFlag,
|
|
|
|
#[command(flatten)]
|
|
pub target_folder: TargetFolderNameArg,
|
|
|
|
#[command(flatten)]
|
|
pub envelopes: EnvelopeIdsArgs,
|
|
|
|
#[command(flatten)]
|
|
pub account: AccountNameFlag,
|
|
}
|
|
|
|
impl MessageMoveCommand {
|
|
pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> {
|
|
info!("executing move message(s) command");
|
|
|
|
let source = &self.source_folder.name;
|
|
let target = &self.target_folder.name;
|
|
let ids = &self.envelopes.ids;
|
|
|
|
let (toml_account_config, account_config) = config
|
|
.clone()
|
|
.into_account_configs(self.account.name.as_deref(), |c: &Config, name| {
|
|
c.account(name).ok()
|
|
})?;
|
|
|
|
let backend = BackendBuilder::new(
|
|
Arc::new(toml_account_config),
|
|
Arc::new(account_config),
|
|
|builder| {
|
|
builder
|
|
.without_features()
|
|
.with_move_messages(BackendFeatureSource::Context)
|
|
},
|
|
)
|
|
.without_sending_backend()
|
|
.build()
|
|
.await?;
|
|
|
|
backend.move_messages(source, target, ids).await?;
|
|
|
|
printer.out(format!(
|
|
"Message(s) successfully moved from {source} to {target}!\n"
|
|
))
|
|
}
|
|
}
|