mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
refactor backend system, remove accouts flattening
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use email::{backend::feature::BackendFeatureSource, folder::add::AddFolder};
|
||||
use log::info;
|
||||
|
||||
#[cfg(feature = "account-sync")]
|
||||
@@ -43,7 +44,7 @@ impl AddFolderCommand {
|
||||
toml_account_config.clone(),
|
||||
account_config,
|
||||
add_folder_kind,
|
||||
|builder| builder.set_add_folder(Some(None)),
|
||||
|builder| builder.set_add_folder(BackendFeatureSource::Context),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use dialoguer::Confirm;
|
||||
use email::{backend::feature::BackendFeatureSource, folder::delete::DeleteFolder};
|
||||
use log::info;
|
||||
use std::process;
|
||||
|
||||
@@ -56,7 +57,7 @@ impl FolderDeleteCommand {
|
||||
toml_account_config.clone(),
|
||||
account_config,
|
||||
delete_folder_kind,
|
||||
|builder| builder.set_delete_folder(Some(None)),
|
||||
|builder| builder.set_delete_folder(BackendFeatureSource::Context),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use email::{backend::feature::BackendFeatureSource, folder::expunge::ExpungeFolder};
|
||||
use log::info;
|
||||
|
||||
#[cfg(feature = "account-sync")]
|
||||
@@ -44,7 +45,7 @@ impl FolderExpungeCommand {
|
||||
toml_account_config.clone(),
|
||||
account_config,
|
||||
expunge_folder_kind,
|
||||
|builder| builder.set_expunge_folder(Some(None)),
|
||||
|builder| builder.set_expunge_folder(BackendFeatureSource::Context),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use email::{backend::feature::BackendFeatureSource, folder::list::ListFolders};
|
||||
use log::info;
|
||||
|
||||
#[cfg(feature = "account-sync")]
|
||||
@@ -45,7 +46,7 @@ impl FolderListCommand {
|
||||
toml_account_config.clone(),
|
||||
account_config.clone(),
|
||||
list_folders_kind,
|
||||
|builder| builder.set_list_folders(Some(None)),
|
||||
|builder| builder.set_list_folders(BackendFeatureSource::Context),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
#[cfg(feature = "folder-add")]
|
||||
mod add;
|
||||
#[cfg(feature = "folder-delete")]
|
||||
mod delete;
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
mod expunge;
|
||||
#[cfg(feature = "folder-list")]
|
||||
mod list;
|
||||
#[cfg(feature = "folder-purge")]
|
||||
mod purge;
|
||||
|
||||
use anyhow::Result;
|
||||
@@ -14,16 +9,10 @@ use clap::Subcommand;
|
||||
|
||||
use crate::{config::TomlConfig, printer::Printer};
|
||||
|
||||
#[cfg(feature = "folder-add")]
|
||||
use self::add::AddFolderCommand;
|
||||
#[cfg(feature = "folder-delete")]
|
||||
use self::delete::FolderDeleteCommand;
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
use self::expunge::FolderExpungeCommand;
|
||||
#[cfg(feature = "folder-list")]
|
||||
use self::list::FolderListCommand;
|
||||
#[cfg(feature = "folder-purge")]
|
||||
use self::purge::FolderPurgeCommand;
|
||||
use self::{
|
||||
add::AddFolderCommand, delete::FolderDeleteCommand, expunge::FolderExpungeCommand,
|
||||
list::FolderListCommand, purge::FolderPurgeCommand,
|
||||
};
|
||||
|
||||
/// Manage folders.
|
||||
///
|
||||
@@ -31,23 +20,18 @@ use self::purge::FolderPurgeCommand;
|
||||
/// emails. This subcommand allows you to manage them.
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum FolderSubcommand {
|
||||
#[cfg(feature = "folder-add")]
|
||||
#[command(visible_alias = "create", alias = "new")]
|
||||
Add(AddFolderCommand),
|
||||
|
||||
#[cfg(feature = "folder-list")]
|
||||
#[command(alias = "lst")]
|
||||
List(FolderListCommand),
|
||||
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
#[command()]
|
||||
Expunge(FolderExpungeCommand),
|
||||
|
||||
#[cfg(feature = "folder-purge")]
|
||||
#[command()]
|
||||
Purge(FolderPurgeCommand),
|
||||
|
||||
#[cfg(feature = "folder-delete")]
|
||||
#[command(alias = "remove", alias = "rm")]
|
||||
Delete(FolderDeleteCommand),
|
||||
}
|
||||
@@ -56,15 +40,10 @@ impl FolderSubcommand {
|
||||
#[allow(unused)]
|
||||
pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> {
|
||||
match self {
|
||||
#[cfg(feature = "folder-add")]
|
||||
Self::Add(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-list")]
|
||||
Self::List(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
Self::Expunge(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-purge")]
|
||||
Self::Purge(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-delete")]
|
||||
Self::Delete(cmd) => cmd.execute(printer, config).await,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use dialoguer::Confirm;
|
||||
use email::{backend::feature::BackendFeatureSource, folder::purge::PurgeFolder};
|
||||
use log::info;
|
||||
use std::process;
|
||||
|
||||
@@ -56,7 +57,7 @@ impl FolderPurgeCommand {
|
||||
toml_account_config.clone(),
|
||||
account_config,
|
||||
purge_folder_kind,
|
||||
|builder| builder.set_purge_folder(Some(None)),
|
||||
|builder| builder.set_purge_folder(BackendFeatureSource::Context),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
+4
-22
@@ -1,3 +1,5 @@
|
||||
#[cfg(feature = "account-sync")]
|
||||
use email::folder::sync::config::FolderSyncConfig;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
@@ -7,45 +9,35 @@ use crate::backend::BackendKind;
|
||||
pub struct FolderConfig {
|
||||
#[serde(alias = "aliases")]
|
||||
pub alias: Option<HashMap<String, String>>,
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
|
||||
pub add: Option<FolderAddConfig>,
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-list"))]
|
||||
pub list: Option<FolderListConfig>,
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
|
||||
pub expunge: Option<FolderExpungeConfig>,
|
||||
#[cfg(feature = "folder-purge")]
|
||||
pub purge: Option<FolderPurgeConfig>,
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
|
||||
pub delete: Option<FolderDeleteConfig>,
|
||||
#[cfg(feature = "account-sync")]
|
||||
pub sync: Option<FolderSyncConfig>,
|
||||
}
|
||||
|
||||
impl FolderConfig {
|
||||
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
|
||||
#[allow(unused_mut)]
|
||||
let mut kinds = HashSet::default();
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
|
||||
if let Some(add) = &self.add {
|
||||
kinds.extend(add.get_used_backends());
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-list"))]
|
||||
if let Some(list) = &self.list {
|
||||
kinds.extend(list.get_used_backends());
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
|
||||
if let Some(expunge) = &self.expunge {
|
||||
kinds.extend(expunge.get_used_backends());
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-purge")]
|
||||
if let Some(purge) = &self.purge {
|
||||
kinds.extend(purge.get_used_backends());
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
|
||||
if let Some(delete) = &self.delete {
|
||||
kinds.extend(delete.get_used_backends());
|
||||
}
|
||||
@@ -54,13 +46,11 @@ impl FolderConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||
pub struct FolderAddConfig {
|
||||
pub backend: Option<BackendKind>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
|
||||
impl FolderAddConfig {
|
||||
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
|
||||
let mut kinds = HashSet::default();
|
||||
@@ -73,7 +63,6 @@ impl FolderAddConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-list"))]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||
pub struct FolderListConfig {
|
||||
pub backend: Option<BackendKind>,
|
||||
@@ -82,7 +71,6 @@ pub struct FolderListConfig {
|
||||
pub remote: email::folder::list::config::FolderListConfig,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-list"))]
|
||||
impl FolderListConfig {
|
||||
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
|
||||
let mut kinds = HashSet::default();
|
||||
@@ -95,13 +83,11 @@ impl FolderListConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||
pub struct FolderExpungeConfig {
|
||||
pub backend: Option<BackendKind>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
|
||||
impl FolderExpungeConfig {
|
||||
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
|
||||
let mut kinds = HashSet::default();
|
||||
@@ -114,13 +100,11 @@ impl FolderExpungeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-purge")]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||
pub struct FolderPurgeConfig {
|
||||
pub backend: Option<BackendKind>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-purge")]
|
||||
impl FolderPurgeConfig {
|
||||
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
|
||||
let mut kinds = HashSet::default();
|
||||
@@ -133,13 +117,11 @@ impl FolderPurgeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
|
||||
pub struct FolderDeleteConfig {
|
||||
pub backend: Option<BackendKind>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
|
||||
impl FolderDeleteConfig {
|
||||
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
|
||||
let mut kinds = HashSet::default();
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
pub mod arg;
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
pub mod command;
|
||||
pub mod config;
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
use anyhow::Result;
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
use serde::Serialize;
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
use std::ops;
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
use crate::{
|
||||
printer::{PrintTable, PrintTableOpts, WriteColor},
|
||||
ui::{Cell, Row, Table},
|
||||
};
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
pub struct Folder {
|
||||
pub name: String,
|
||||
pub desc: String,
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
impl From<&email::folder::Folder> for Folder {
|
||||
fn from(folder: &email::folder::Folder) -> Self {
|
||||
Folder {
|
||||
@@ -33,7 +26,6 @@ impl From<&email::folder::Folder> for Folder {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
impl Table for Folder {
|
||||
fn head() -> Row {
|
||||
Row::new()
|
||||
@@ -48,11 +40,9 @@ impl Table for Folder {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
#[derive(Clone, Debug, Default, Serialize)]
|
||||
pub struct Folders(Vec<Folder>);
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
impl ops::Deref for Folders {
|
||||
type Target = Vec<Folder>;
|
||||
|
||||
@@ -61,14 +51,12 @@ impl ops::Deref for Folders {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
impl From<email::folder::Folders> for Folders {
|
||||
fn from(folders: email::folder::Folders) -> Self {
|
||||
Folders(folders.iter().map(Folder::from).collect())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "folder-subcmd")]
|
||||
impl PrintTable for Folders {
|
||||
fn print_table(&self, writer: &mut dyn WriteColor, opts: PrintTableOpts) -> Result<()> {
|
||||
writeln!(writer)?;
|
||||
|
||||
Reference in New Issue
Block a user