refactor new backend api

This commit is contained in:
Clément DOUIN
2024-01-27 11:15:03 +01:00
parent 16266dbc0b
commit 4f9705952a
37 changed files with 819 additions and 1897 deletions
+3 -37
View File
@@ -1,15 +1,7 @@
use anyhow::Result;
use clap::Parser;
#[cfg(feature = "imap")]
use email::folder::add::imap::AddImapFolder;
#[cfg(feature = "maildir")]
use email::folder::add::maildir::AddMaildirFolder;
#[cfg(feature = "notmuch")]
use email::folder::add::notmuch::AddNotmuchFolder;
use log::info;
#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))]
use crate::backend::BackendKind;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
use crate::{
@@ -48,36 +40,10 @@ impl AddFolderCommand {
let add_folder_kind = toml_account_config.add_folder_kind();
let backend = Backend::new(
&toml_account_config,
&account_config,
toml_account_config.clone(),
account_config,
add_folder_kind,
|builder| match add_folder_kind {
#[cfg(feature = "imap")]
Some(BackendKind::Imap) => {
builder.set_add_folder(|ctx| ctx.imap.as_ref().map(AddImapFolder::new_boxed));
}
#[cfg(feature = "maildir")]
Some(BackendKind::Maildir) => {
builder.set_add_folder(|ctx| {
ctx.maildir.as_ref().map(AddMaildirFolder::new_boxed)
});
}
#[cfg(feature = "account-sync")]
Some(BackendKind::MaildirForSync) => {
builder.set_add_folder(|ctx| {
ctx.maildir_for_sync
.as_ref()
.map(AddMaildirFolder::new_boxed)
});
}
#[cfg(feature = "notmuch")]
Some(BackendKind::Notmuch) => {
builder.set_add_folder(|ctx| {
ctx.notmuch.as_ref().map(AddNotmuchFolder::new_boxed)
});
}
_ => (),
},
|builder| builder.set_add_folder(Some(None)),
)
.await?;
+3 -40
View File
@@ -1,17 +1,9 @@
use anyhow::Result;
use clap::Parser;
use dialoguer::Confirm;
#[cfg(feature = "imap")]
use email::folder::delete::imap::DeleteImapFolder;
#[cfg(feature = "maildir")]
use email::folder::delete::maildir::DeleteMaildirFolder;
// #[cfg(feature = "notmuch")]
// use email::folder::delete::notmuch::DeleteNotmuchFolder;
use log::info;
use std::process;
#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))]
use crate::backend::BackendKind;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
use crate::{
@@ -61,39 +53,10 @@ impl FolderDeleteCommand {
let delete_folder_kind = toml_account_config.delete_folder_kind();
let backend = Backend::new(
&toml_account_config,
&account_config,
toml_account_config.clone(),
account_config,
delete_folder_kind,
|builder| match delete_folder_kind {
#[cfg(feature = "imap")]
Some(BackendKind::Imap) => {
builder.set_delete_folder(|ctx| {
ctx.imap.as_ref().map(DeleteImapFolder::new_boxed)
});
}
#[cfg(feature = "maildir")]
Some(BackendKind::Maildir) => {
builder.set_delete_folder(|ctx| {
ctx.maildir.as_ref().map(DeleteMaildirFolder::new_boxed)
});
}
#[cfg(feature = "account-sync")]
Some(BackendKind::MaildirForSync) => {
builder.set_delete_folder(|ctx| {
ctx.maildir_for_sync
.as_ref()
.map(DeleteMaildirFolder::new_boxed)
});
}
#[cfg(feature = "notmuch")]
Some(BackendKind::Notmuch) => {
// TODO
// builder.set_delete_folder(|ctx| {
// ctx.notmuch.as_ref().map(DeleteNotmuchFolder::new_boxed)
// });
}
_ => (),
},
|builder| builder.set_delete_folder(Some(None)),
)
.await?;
+3 -40
View File
@@ -1,15 +1,7 @@
use anyhow::Result;
use clap::Parser;
#[cfg(feature = "imap")]
use email::folder::expunge::imap::ExpungeImapFolder;
#[cfg(feature = "maildir")]
use email::folder::expunge::maildir::ExpungeMaildirFolder;
// #[cfg(feature = "notmuch")]
// use email::folder::expunge::notmuch::ExpungeNotmuchFolder;
use log::info;
#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))]
use crate::backend::BackendKind;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
use crate::{
@@ -49,39 +41,10 @@ impl FolderExpungeCommand {
let expunge_folder_kind = toml_account_config.expunge_folder_kind();
let backend = Backend::new(
&toml_account_config,
&account_config,
toml_account_config.clone(),
account_config,
expunge_folder_kind,
|builder| match expunge_folder_kind {
#[cfg(feature = "imap")]
Some(BackendKind::Imap) => {
builder.set_expunge_folder(|ctx| {
ctx.imap.as_ref().map(ExpungeImapFolder::new_boxed)
});
}
#[cfg(feature = "maildir")]
Some(BackendKind::Maildir) => {
builder.set_expunge_folder(|ctx| {
ctx.maildir.as_ref().map(ExpungeMaildirFolder::new_boxed)
});
}
#[cfg(feature = "account-sync")]
Some(BackendKind::MaildirForSync) => {
builder.set_expunge_folder(|ctx| {
ctx.maildir_for_sync
.as_ref()
.map(ExpungeMaildirFolder::new_boxed)
});
}
#[cfg(feature = "notmuch")]
Some(BackendKind::Notmuch) => {
// TODO
// builder.set_expunge_folder(|ctx| {
// ctx.notmuch.as_ref().map(ExpungeNotmuchFolder::new_boxed)
// });
}
_ => (),
},
|builder| builder.set_expunge_folder(Some(None)),
)
.await?;
+3 -39
View File
@@ -1,15 +1,7 @@
use anyhow::Result;
use clap::Parser;
#[cfg(feature = "imap")]
use email::folder::list::imap::ListImapFolders;
#[cfg(feature = "maildir")]
use email::folder::list::maildir::ListMaildirFolders;
#[cfg(feature = "notmuch")]
use email::folder::list::notmuch::ListNotmuchFolders;
use log::info;
#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))]
use crate::backend::BackendKind;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
use crate::{
@@ -50,38 +42,10 @@ impl FolderListCommand {
let list_folders_kind = toml_account_config.list_folders_kind();
let backend = Backend::new(
&toml_account_config,
&account_config,
toml_account_config.clone(),
account_config.clone(),
list_folders_kind,
|builder| match list_folders_kind {
#[cfg(feature = "imap")]
Some(BackendKind::Imap) => {
builder
.set_list_folders(|ctx| ctx.imap.as_ref().map(ListImapFolders::new_boxed));
}
#[cfg(feature = "maildir")]
Some(BackendKind::Maildir) => {
builder.set_list_folders(|ctx| {
ctx.maildir.as_ref().map(ListMaildirFolders::new_boxed)
});
}
#[cfg(feature = "account-sync")]
Some(BackendKind::MaildirForSync) => {
builder.set_list_folders(|ctx| {
ctx.maildir_for_sync
.as_ref()
.map(ListMaildirFolders::new_boxed)
});
}
#[cfg(feature = "notmuch")]
Some(BackendKind::Notmuch) => {
builder.set_list_folders(|ctx| {
ctx.notmuch.as_ref().map(ListNotmuchFolders::new_boxed)
});
}
_ => (),
},
|builder| builder.set_list_folders(Some(None)),
)
.await?;
+3 -41
View File
@@ -1,17 +1,9 @@
use anyhow::Result;
use clap::Parser;
use dialoguer::Confirm;
#[cfg(feature = "imap")]
use email::folder::purge::imap::PurgeImapFolder;
// #[cfg(feature = "maildir")]
// use email::folder::purge::maildir::PurgeMaildirFolder;
// #[cfg(feature = "notmuch")]
// use email::folder::purge::notmuch::PurgeNotmuchFolder;
use log::info;
use std::process;
#[cfg(any(feature = "imap", feature = "maildir", feature = "account-sync"))]
use crate::backend::BackendKind;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
use crate::{
@@ -61,40 +53,10 @@ impl FolderPurgeCommand {
let purge_folder_kind = toml_account_config.purge_folder_kind();
let backend = Backend::new(
&toml_account_config,
&account_config,
toml_account_config.clone(),
account_config,
purge_folder_kind,
|builder| match purge_folder_kind {
#[cfg(feature = "imap")]
Some(BackendKind::Imap) => {
builder
.set_purge_folder(|ctx| ctx.imap.as_ref().map(PurgeImapFolder::new_boxed));
}
#[cfg(feature = "maildir")]
Some(BackendKind::Maildir) => {
// TODO
// builder.set_purge_folder(|ctx| {
// ctx.maildir.as_ref().map(PurgeMaildirFolder::new_boxed)
// });
}
#[cfg(feature = "account-sync")]
Some(BackendKind::MaildirForSync) => {
// TODO
// builder.set_purge_folder(|ctx| {
// ctx.maildir_for_sync
// .as_ref()
// .map(PurgeMaildirFolder::new_boxed)
// });
}
#[cfg(feature = "notmuch")]
Some(BackendKind::Notmuch) => {
// TODO
// builder.set_purge_folder(|ctx| {
// ctx.notmuch.as_ref().map(PurgeNotmuchFolder::new_boxed)
// });
}
_ => (),
},
|builder| builder.set_purge_folder(Some(None)),
)
.await?;
+16 -16
View File
@@ -8,15 +8,15 @@ pub struct FolderConfig {
#[serde(alias = "aliases")]
pub alias: Option<HashMap<String, String>>,
#[cfg(feature = "folder-add")]
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
pub add: Option<FolderAddConfig>,
#[cfg(feature = "folder-list")]
#[cfg(any(feature = "account-sync", feature = "folder-list"))]
pub list: Option<FolderListConfig>,
#[cfg(feature = "folder-expunge")]
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
pub expunge: Option<FolderExpungeConfig>,
#[cfg(feature = "folder-purge")]
pub purge: Option<FolderPurgeConfig>,
#[cfg(feature = "folder-delete")]
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
pub delete: Option<FolderDeleteConfig>,
}
@@ -25,17 +25,17 @@ impl FolderConfig {
#[allow(unused_mut)]
let mut kinds = HashSet::default();
#[cfg(feature = "folder-add")]
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
if let Some(add) = &self.add {
kinds.extend(add.get_used_backends());
}
#[cfg(feature = "folder-list")]
#[cfg(any(feature = "account-sync", feature = "folder-list"))]
if let Some(list) = &self.list {
kinds.extend(list.get_used_backends());
}
#[cfg(feature = "folder-expunge")]
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
if let Some(expunge) = &self.expunge {
kinds.extend(expunge.get_used_backends());
}
@@ -45,7 +45,7 @@ impl FolderConfig {
kinds.extend(purge.get_used_backends());
}
#[cfg(feature = "folder-delete")]
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
if let Some(delete) = &self.delete {
kinds.extend(delete.get_used_backends());
}
@@ -54,13 +54,13 @@ impl FolderConfig {
}
}
#[cfg(feature = "folder-add")]
#[cfg(any(feature = "account-sync", feature = "folder-add"))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct FolderAddConfig {
pub backend: Option<BackendKind>,
}
#[cfg(feature = "folder-add")]
#[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 +73,7 @@ impl FolderAddConfig {
}
}
#[cfg(feature = "folder-list")]
#[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 +82,7 @@ pub struct FolderListConfig {
pub remote: email::folder::list::config::FolderListConfig,
}
#[cfg(feature = "folder-list")]
#[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 +95,13 @@ impl FolderListConfig {
}
}
#[cfg(feature = "folder-expunge")]
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct FolderExpungeConfig {
pub backend: Option<BackendKind>,
}
#[cfg(feature = "folder-expunge")]
#[cfg(any(feature = "account-sync", feature = "folder-expunge"))]
impl FolderExpungeConfig {
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
let mut kinds = HashSet::default();
@@ -133,13 +133,13 @@ impl FolderPurgeConfig {
}
}
#[cfg(feature = "folder-delete")]
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
pub struct FolderDeleteConfig {
pub backend: Option<BackendKind>,
}
#[cfg(feature = "folder-delete")]
#[cfg(any(feature = "account-sync", feature = "folder-delete"))]
impl FolderDeleteConfig {
pub fn get_used_backends(&self) -> HashSet<&BackendKind> {
let mut kinds = HashSet::default();