use new template cursor api

This commit is contained in:
Clément DOUIN 2024-03-21 13:57:26 +01:00
parent 1c23adc8a2
commit 799ee8b25b
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
12 changed files with 33 additions and 20 deletions

2
Cargo.lock generated
View file

@ -1212,7 +1212,7 @@ dependencies = [
[[package]]
name = "email-lib"
version = "0.22.3"
source = "git+https://git.sr.ht/~soywod/pimalaya#5774d5ac5176eb79543bb3bb075bbd026866559f"
source = "git+https://git.sr.ht/~soywod/pimalaya#ed7d5770064ed5e3409da426a954a5457f59d85a"
dependencies = [
"advisory-lock",
"anyhow",

View file

@ -17,6 +17,7 @@ use email::notmuch::config::NotmuchConfig;
use email::sendmail::config::SendmailConfig;
#[cfg(feature = "smtp")]
use email::smtp::config::SmtpConfig;
use email::template::config::TemplateConfig;
use serde::{Deserialize, Serialize};
use std::{collections::HashSet, path::PathBuf};
@ -46,6 +47,7 @@ pub struct TomlAccountConfig {
pub envelope: Option<EnvelopeConfig>,
pub flag: Option<FlagConfig>,
pub message: Option<MessageConfig>,
pub template: Option<TemplateConfig>,
#[cfg(feature = "imap")]
pub imap: Option<ImapConfig>,

View file

@ -257,6 +257,7 @@ impl TomlConfig {
#[cfg(feature = "account-sync")]
sync: c.sync,
}),
template: config.template,
#[cfg(feature = "account-sync")]
sync: config.sync,
#[cfg(feature = "pgp")]

View file

@ -76,7 +76,7 @@ impl MessageForwardCommand {
.await?
.first()
.ok_or(anyhow!("cannot find message"))?
.to_forward_tpl_builder(&account_config)
.to_forward_tpl_builder(account_config.clone())
.with_headers(self.headers.raw)
.with_body(self.body.raw())
.build()

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use email::backend::feature::BackendFeatureSource;
use log::{debug, info};
use log::info;
use mail_builder::MessageBuilder;
use url::Url;
@ -79,12 +79,8 @@ impl MessageMailtoCommand {
}
match account_config.find_full_signature() {
Ok(Some(ref signature)) => builder = builder.text_body(body + "\n\n" + signature),
Ok(None) => builder = builder.text_body(body),
Err(err) => {
debug!("cannot add signature to mailto message, skipping it: {err}");
debug!("{err:?}");
}
Some(ref sig) => builder = builder.text_body(body + "\n\n" + sig),
None => builder = builder.text_body(body),
}
let tpl = account_config
@ -92,7 +88,8 @@ impl MessageMailtoCommand {
.with_show_only_headers(account_config.get_message_write_headers())
.build()
.from_msg_builder(builder)
.await?;
.await?
.into();
editor::edit_tpl_with_editor(account_config, printer, &backend, tpl).await
}

View file

@ -78,7 +78,7 @@ impl MessageReplyCommand {
.await?
.first()
.ok_or(anyhow!("cannot find message {id}"))?
.to_reply_tpl_builder(&account_config)
.to_reply_tpl_builder(account_config.clone())
.with_headers(self.headers.raw)
.with_body(self.body.raw())
.with_reply_all(self.reply.all)

View file

@ -60,7 +60,7 @@ impl MessageWriteCommand {
)
.await?;
let tpl = Message::new_tpl_builder(&account_config)
let tpl = Message::new_tpl_builder(account_config.clone())
.with_headers(self.headers.raw)
.with_body(self.body.raw())
.build()

View file

@ -70,7 +70,7 @@ impl TemplateForwardCommand {
.await?
.first()
.ok_or(anyhow!("cannot find message {id}"))?
.to_forward_tpl_builder(&account_config)
.to_forward_tpl_builder(account_config)
.with_headers(self.headers.raw)
.with_body(self.body.raw())
.build()

View file

@ -74,7 +74,7 @@ impl TemplateReplyCommand {
.await?
.first()
.ok_or(anyhow!("cannot find message {id}"))?
.to_reply_tpl_builder(&account_config)
.to_reply_tpl_builder(account_config)
.with_headers(self.headers.raw)
.with_body(self.body.raw())
.with_reply_all(self.reply.all)

View file

@ -41,7 +41,7 @@ impl TemplateWriteCommand {
self.cache.disable,
)?;
let tpl = Message::new_tpl_builder(&account_config)
let tpl = Message::new_tpl_builder(account_config)
.with_headers(self.headers.raw)
.with_body(self.body.raw())
.build()

View file

@ -1,2 +1,14 @@
pub mod arg;
pub mod command;
use anyhow::Result;
use email::template::Template;
use crate::printer::{Print, WriteColor};
impl Print for Template {
fn print(&self, writer: &mut dyn WriteColor) -> Result<()> {
self.as_str().print(writer)?;
Ok(writer.reset()?)
}
}

View file

@ -5,6 +5,7 @@ use email::{
flag::{Flag, Flags},
folder::DRAFTS,
message::{add::AddMessage, send::SendMessageThenSaveCopy},
template::Template,
};
use log::debug;
use mml::MmlCompilerBuilder;
@ -17,7 +18,7 @@ use crate::{
ui::choice::{self, PostEditChoice, PreEditChoice},
};
pub async fn open_with_tpl(tpl: String) -> Result<String> {
pub async fn open_with_tpl(tpl: Template) -> Result<Template> {
let path = local_draft_path();
debug!("create draft");
@ -35,14 +36,14 @@ pub async fn open_with_tpl(tpl: String) -> Result<String> {
let content =
fs::read_to_string(&path).context(format!("cannot read local draft at {:?}", path))?;
Ok(content)
Ok(content.into())
}
pub async fn open_with_local_draft() -> Result<String> {
pub async fn open_with_local_draft() -> Result<Template> {
let path = local_draft_path();
let content =
fs::read_to_string(&path).context(format!("cannot read local draft at {:?}", path))?;
open_with_tpl(content).await
open_with_tpl(content.into()).await
}
#[allow(unused)]
@ -50,7 +51,7 @@ pub async fn edit_tpl_with_editor<P: Printer>(
config: Arc<AccountConfig>,
printer: &mut P,
backend: &Backend,
mut tpl: String,
mut tpl: Template,
) -> Result<()> {
let draft = local_draft_path();
if draft.exists() {