mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-25 04:20:22 +00:00
use new template cursor api
This commit is contained in:
parent
1c23adc8a2
commit
799ee8b25b
12 changed files with 33 additions and 20 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue