fix envelope listing

This commit is contained in:
Clément DOUIN 2024-01-02 12:21:12 +01:00
parent 37c352ea7f
commit a8c6756f56
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
6 changed files with 102 additions and 10 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [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
Few major concepts changed:

2
Cargo.lock generated
View file

@ -1830,7 +1830,7 @@ dependencies = [
[[package]]
name = "himalaya"
version = "1.0.0-beta"
version = "1.0.0-beta.2"
dependencies = [
"anyhow",
"async-trait",

View file

@ -1,7 +1,7 @@
[package]
name = "himalaya"
description = "CLI to manage emails"
version = "1.0.0-beta"
version = "1.0.0-beta.2"
authors = ["soywod <clement.douin@posteo.net>"]
edition = "2021"
license = "MIT"

View file

@ -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 **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)].

View file

@ -84,13 +84,13 @@ impl ToString for BackendKind {
#[derive(Clone, Default)]
pub struct BackendContextBuilder {
maildir: Option<MaildirSessionBuilder>,
maildir_for_sync: Option<MaildirSessionBuilder>,
pub maildir: Option<MaildirSessionBuilder>,
pub maildir_for_sync: Option<MaildirSessionBuilder>,
#[cfg(feature = "imap")]
imap: Option<ImapSessionBuilder>,
pub imap: Option<ImapSessionBuilder>,
#[cfg(feature = "smtp")]
smtp: Option<SmtpClientBuilder>,
sendmail: Option<SendmailContext>,
pub smtp: Option<SmtpClientBuilder>,
pub sendmail: Option<SendmailContext>,
}
#[async_trait]
@ -699,6 +699,16 @@ impl Backend {
.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(
&self,
folder: &str,

View file

@ -1,10 +1,18 @@
use anyhow::Result;
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 crate::{
account::arg::name::AccountNameFlag,
backend::Backend,
backend::{Backend, BackendContextBuilder, BackendKind},
cache::arg::disable::CacheDisableFlag,
config::TomlConfig,
folder::arg::name::FolderNameOptionalArg,
@ -54,7 +62,77 @@ impl ListEnvelopesCommand {
let (toml_account_config, account_config) = config
.clone()
.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
.page_size