mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 17:15:12 +00:00
fix envelope listing
This commit is contained in:
parent
37c352ea7f
commit
a8c6756f56
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed bug when listing envelopes with `backend = "imap"`, `sync.enable = true` and `envelope.watch.backend = "imap"` led to unwanted IMAP connection creation (which slowed down the listing).
|
||||||
|
|
||||||
## [1.0.0-beta] - 2024-01-01
|
## [1.0.0-beta] - 2024-01-01
|
||||||
|
|
||||||
Few major concepts changed:
|
Few major concepts changed:
|
||||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1830,7 +1830,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "himalaya"
|
name = "himalaya"
|
||||||
version = "1.0.0-beta"
|
version = "1.0.0-beta.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "himalaya"
|
name = "himalaya"
|
||||||
description = "CLI to manage emails"
|
description = "CLI to manage emails"
|
||||||
version = "1.0.0-beta"
|
version = "1.0.0-beta.2"
|
||||||
authors = ["soywod <clement.douin@posteo.net>"]
|
authors = ["soywod <clement.douin@posteo.net>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -73,7 +73,7 @@ Please read the [documentation](https://pimalaya.org/himalaya/cli/latest/configu
|
||||||
|
|
||||||
If you want to **report a bug** that [does not exist yet](https://todo.sr.ht/~soywod/pimalaya), please send an email at [~soywod/pimalaya@todo.sr.ht](mailto:~soywod/pimalaya@todo.sr.ht).
|
If you want to **report a bug** that [does not exist yet](https://todo.sr.ht/~soywod/pimalaya), please send an email at [~soywod/pimalaya@todo.sr.ht](mailto:~soywod/pimalaya@todo.sr.ht).
|
||||||
|
|
||||||
If you want to **propose a feature** or **fix a bug**, please send a patch at [~soywod/pimalaya@lists.sr.ht](mailto:~soywod/pimalaya@lists.sr.ht) using [git send-email](https://git-scm.com/docs/git-send-email). Follow [this guide](https://git-send-email.io/) to configure git properly.
|
If you want to **propose a feature** or **fix a bug**, please open a [pull request](https://github.com/soywod/himalaya/pulls).
|
||||||
|
|
||||||
If you just want to **discuss** about the project, feel free to join the [Matrix](https://matrix.org/) workspace [#pimalaya.general](https://matrix.to/#/#pimalaya.general:matrix.org) or contact me directly [@soywod](https://matrix.to/#/@soywod:matrix.org). You can also use the mailing list [[send an email](mailto:~soywod/pimalaya@lists.sr.ht)|[subscribe](mailto:~soywod/pimalaya+subscribe@lists.sr.ht)|[unsubscribe](mailto:~soywod/pimalaya+unsubscribe@lists.sr.ht)].
|
If you just want to **discuss** about the project, feel free to join the [Matrix](https://matrix.org/) workspace [#pimalaya.general](https://matrix.to/#/#pimalaya.general:matrix.org) or contact me directly [@soywod](https://matrix.to/#/@soywod:matrix.org). You can also use the mailing list [[send an email](mailto:~soywod/pimalaya@lists.sr.ht)|[subscribe](mailto:~soywod/pimalaya+subscribe@lists.sr.ht)|[unsubscribe](mailto:~soywod/pimalaya+unsubscribe@lists.sr.ht)].
|
||||||
|
|
||||||
|
|
|
@ -84,13 +84,13 @@ impl ToString for BackendKind {
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct BackendContextBuilder {
|
pub struct BackendContextBuilder {
|
||||||
maildir: Option<MaildirSessionBuilder>,
|
pub maildir: Option<MaildirSessionBuilder>,
|
||||||
maildir_for_sync: Option<MaildirSessionBuilder>,
|
pub maildir_for_sync: Option<MaildirSessionBuilder>,
|
||||||
#[cfg(feature = "imap")]
|
#[cfg(feature = "imap")]
|
||||||
imap: Option<ImapSessionBuilder>,
|
pub imap: Option<ImapSessionBuilder>,
|
||||||
#[cfg(feature = "smtp")]
|
#[cfg(feature = "smtp")]
|
||||||
smtp: Option<SmtpClientBuilder>,
|
pub smtp: Option<SmtpClientBuilder>,
|
||||||
sendmail: Option<SendmailContext>,
|
pub sendmail: Option<SendmailContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -699,6 +699,16 @@ impl Backend {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn new_v2(
|
||||||
|
toml_account_config: TomlAccountConfig,
|
||||||
|
builder: email::backend::BackendBuilder<BackendContextBuilder>,
|
||||||
|
) -> Result<Self> {
|
||||||
|
Ok(Self {
|
||||||
|
toml_account_config,
|
||||||
|
backend: builder.build().await?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn build_id_mapper(
|
fn build_id_mapper(
|
||||||
&self,
|
&self,
|
||||||
folder: &str,
|
folder: &str,
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use email::backend::BackendBuilder;
|
||||||
|
#[cfg(feature = "imap")]
|
||||||
|
use email::{envelope::list::imap::ListEnvelopesImap, imap::ImapSessionBuilder};
|
||||||
|
#[cfg(feature = "maildir")]
|
||||||
|
use email::{
|
||||||
|
envelope::list::maildir::ListEnvelopesMaildir,
|
||||||
|
maildir::{config::MaildirConfig, MaildirSessionBuilder},
|
||||||
|
};
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
account::arg::name::AccountNameFlag,
|
account::arg::name::AccountNameFlag,
|
||||||
backend::Backend,
|
backend::{Backend, BackendContextBuilder, BackendKind},
|
||||||
cache::arg::disable::CacheDisableFlag,
|
cache::arg::disable::CacheDisableFlag,
|
||||||
config::TomlConfig,
|
config::TomlConfig,
|
||||||
folder::arg::name::FolderNameOptionalArg,
|
folder::arg::name::FolderNameOptionalArg,
|
||||||
|
@ -54,7 +62,77 @@ impl ListEnvelopesCommand {
|
||||||
let (toml_account_config, account_config) = config
|
let (toml_account_config, account_config) = config
|
||||||
.clone()
|
.clone()
|
||||||
.into_account_configs(some_account_name, self.cache.disable)?;
|
.into_account_configs(some_account_name, self.cache.disable)?;
|
||||||
let backend = Backend::new(toml_account_config, account_config.clone(), false).await?;
|
|
||||||
|
let backend_kind = toml_account_config.list_envelopes_kind();
|
||||||
|
let backend_ctx_builder = BackendContextBuilder {
|
||||||
|
maildir: toml_account_config
|
||||||
|
.maildir
|
||||||
|
.as_ref()
|
||||||
|
.filter(|_| matches!(backend_kind, Some(BackendKind::Maildir)))
|
||||||
|
.map(|mdir_config| {
|
||||||
|
MaildirSessionBuilder::new(account_config.clone(), mdir_config.clone())
|
||||||
|
}),
|
||||||
|
maildir_for_sync: Some(MaildirConfig {
|
||||||
|
root_dir: account_config.get_sync_dir()?,
|
||||||
|
})
|
||||||
|
.filter(|_| matches!(backend_kind, Some(BackendKind::MaildirForSync)))
|
||||||
|
.map(|mdir_config| MaildirSessionBuilder::new(account_config.clone(), mdir_config)),
|
||||||
|
#[cfg(feature = "imap")]
|
||||||
|
imap: {
|
||||||
|
let ctx_builder = toml_account_config
|
||||||
|
.imap
|
||||||
|
.as_ref()
|
||||||
|
.filter(|_| matches!(backend_kind, Some(BackendKind::Imap)))
|
||||||
|
.map(|imap_config| {
|
||||||
|
ImapSessionBuilder::new(account_config.clone(), imap_config.clone())
|
||||||
|
.with_prebuilt_credentials()
|
||||||
|
});
|
||||||
|
match ctx_builder {
|
||||||
|
Some(ctx_builder) => Some(ctx_builder.await?),
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
#[cfg(feature = "notmuch")]
|
||||||
|
notmuch: toml_account_config
|
||||||
|
.notmuch
|
||||||
|
.as_ref()
|
||||||
|
.filter(|_| matches!(backend_kind, Some(BackendKind::Notmuch)))
|
||||||
|
.map(|notmuch_config| {
|
||||||
|
NotmuchSessionBuilder::new(account_config.clone(), notmuch_config.clone())
|
||||||
|
}),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut backend_builder = BackendBuilder::new(account_config.clone(), backend_ctx_builder);
|
||||||
|
|
||||||
|
match toml_account_config.list_envelopes_kind() {
|
||||||
|
Some(BackendKind::Maildir) => {
|
||||||
|
backend_builder = backend_builder.with_list_envelopes(|ctx| {
|
||||||
|
ctx.maildir.as_ref().and_then(ListEnvelopesMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Some(BackendKind::MaildirForSync) => {
|
||||||
|
backend_builder = backend_builder.with_list_envelopes(|ctx| {
|
||||||
|
ctx.maildir_for_sync
|
||||||
|
.as_ref()
|
||||||
|
.and_then(ListEnvelopesMaildir::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
#[cfg(feature = "imap")]
|
||||||
|
Some(BackendKind::Imap) => {
|
||||||
|
backend_builder = backend_builder
|
||||||
|
.with_list_envelopes(|ctx| ctx.imap.as_ref().and_then(ListEnvelopesImap::new));
|
||||||
|
}
|
||||||
|
#[cfg(feature = "notmuch")]
|
||||||
|
Some(BackendKind::Notmuch) => {
|
||||||
|
backend_builder = backend_builder.with_list_envelopes(|ctx| {
|
||||||
|
ctx.notmuch.as_ref().and_then(ListEnvelopesNotmuch::new)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let backend = Backend::new_v2(toml_account_config.clone(), backend_builder).await?;
|
||||||
|
|
||||||
let page_size = self
|
let page_size = self
|
||||||
.page_size
|
.page_size
|
||||||
|
|
Loading…
Reference in a new issue