mirror of
https://github.com/pimalaya/himalaya.git
synced 2024-12-09 21:18:39 +03:00
update code for sendmail sender lib feature
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
# Cargo config directory
|
||||||
|
.cargo/
|
||||||
|
|
||||||
# Cargo build directory
|
# Cargo build directory
|
||||||
target/
|
target/
|
||||||
debug/
|
debug/
|
||||||
|
|||||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -519,7 +519,6 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "himalaya-lib"
|
name = "himalaya-lib"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
source = "git+https://git.sr.ht/~soywod/himalaya-lib?branch=develop#883b4d9217e52d67596eb73b5bf77f89abdea0f6"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ammonia",
|
"ammonia",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ clap = { version = "2.33.3", default-features = false, features = ["suggestions"
|
|||||||
convert_case = "0.5.0"
|
convert_case = "0.5.0"
|
||||||
env_logger = "0.8.3"
|
env_logger = "0.8.3"
|
||||||
erased-serde = "0.3.18"
|
erased-serde = "0.3.18"
|
||||||
himalaya-lib = { version = "=0.3.1", git = "https://git.sr.ht/~soywod/himalaya-lib", branch = "develop" }
|
himalaya-lib = "=0.3.1"
|
||||||
# himalaya-lib = "=0.3.1"
|
|
||||||
html-escape = "0.2.9"
|
html-escape = "0.2.9"
|
||||||
lettre = { version = "=0.10.0-rc.7", features = ["serde"] }
|
lettre = { version = "=0.10.0-rc.7", features = ["serde"] }
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
@@ -52,8 +51,7 @@ unicode-width = "0.1.7"
|
|||||||
url = "2.2.2"
|
url = "2.2.2"
|
||||||
uuid = { version = "0.8", features = ["v4"] }
|
uuid = { version = "0.8", features = ["v4"] }
|
||||||
|
|
||||||
# Optional dependencies:
|
# [dependencies.optional]
|
||||||
|
|
||||||
imap = { version = "=3.0.0-alpha.4", optional = true }
|
imap = { version = "=3.0.0-alpha.4", optional = true }
|
||||||
imap-proto = { version = "0.14.3", optional = true }
|
imap-proto = { version = "0.14.3", optional = true }
|
||||||
maildir = { version = "0.6.1", optional = true }
|
maildir = { version = "0.6.1", optional = true }
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ pub fn forward<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
|||||||
.into_forward(config)?
|
.into_forward(config)?
|
||||||
.add_attachments(attachments_paths)?
|
.add_attachments(attachments_paths)?
|
||||||
.encrypt(encrypt);
|
.encrypt(encrypt);
|
||||||
editor::edit_msg_with_editor(
|
editor::edit_email_with_editor(
|
||||||
msg,
|
msg,
|
||||||
TplOverride::default(),
|
TplOverride::default(),
|
||||||
config,
|
config,
|
||||||
@@ -184,7 +184,7 @@ pub fn mailto<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
|||||||
};
|
};
|
||||||
trace!("message: {:?}", msg);
|
trace!("message: {:?}", msg);
|
||||||
|
|
||||||
editor::edit_msg_with_editor(
|
editor::edit_email_with_editor(
|
||||||
msg,
|
msg,
|
||||||
TplOverride::default(),
|
TplOverride::default(),
|
||||||
config,
|
config,
|
||||||
@@ -248,7 +248,7 @@ pub fn reply<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
|||||||
.into_reply(all, config)?
|
.into_reply(all, config)?
|
||||||
.add_attachments(attachments_paths)?
|
.add_attachments(attachments_paths)?
|
||||||
.encrypt(encrypt);
|
.encrypt(encrypt);
|
||||||
editor::edit_msg_with_editor(
|
editor::edit_email_with_editor(
|
||||||
msg,
|
msg,
|
||||||
TplOverride::default(),
|
TplOverride::default(),
|
||||||
config,
|
config,
|
||||||
@@ -341,7 +341,7 @@ pub fn sort<'a, P: Printer, B: Backend<'a> + ?Sized>(
|
|||||||
|
|
||||||
/// Send a raw message.
|
/// Send a raw message.
|
||||||
pub fn send<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
pub fn send<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
||||||
raw_msg: &str,
|
raw_email: &str,
|
||||||
config: &AccountConfig,
|
config: &AccountConfig,
|
||||||
printer: &mut P,
|
printer: &mut P,
|
||||||
backend: &mut B,
|
backend: &mut B,
|
||||||
@@ -357,8 +357,8 @@ pub fn send<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
|||||||
let sent_folder = config.folder_alias("sent")?;
|
let sent_folder = config.folder_alias("sent")?;
|
||||||
debug!("sent folder: {:?}", sent_folder);
|
debug!("sent folder: {:?}", sent_folder);
|
||||||
|
|
||||||
let raw_msg = if is_tty || is_json {
|
let raw_email = if is_tty || is_json {
|
||||||
raw_msg.replace("\r", "").replace("\n", "\r\n")
|
raw_email.replace("\r", "").replace("\n", "\r\n")
|
||||||
} else {
|
} else {
|
||||||
io::stdin()
|
io::stdin()
|
||||||
.lock()
|
.lock()
|
||||||
@@ -367,10 +367,10 @@ pub fn send<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
|||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\r\n")
|
.join("\r\n")
|
||||||
};
|
};
|
||||||
trace!("raw message: {:?}", raw_msg);
|
trace!("raw message: {:?}", raw_email);
|
||||||
let msg = Email::from_tpl(&raw_msg)?;
|
let email = Email::from_tpl(&raw_email)?;
|
||||||
sender.send(&config, &msg)?;
|
sender.send(&email)?;
|
||||||
backend.email_add(&sent_folder, raw_msg.as_bytes(), "seen")?;
|
backend.email_add(&sent_folder, raw_email.as_bytes(), "seen")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,9 +384,9 @@ pub fn write<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
|||||||
backend: &mut B,
|
backend: &mut B,
|
||||||
sender: &mut S,
|
sender: &mut S,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let msg = Email::default()
|
let email = Email::default()
|
||||||
.add_attachments(attachments_paths)?
|
.add_attachments(attachments_paths)?
|
||||||
.encrypt(encrypt);
|
.encrypt(encrypt);
|
||||||
editor::edit_msg_with_editor(msg, tpl, config, printer, backend, sender)?;
|
editor::edit_email_with_editor(email, tpl, config, printer, backend, sender)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,16 +71,15 @@ pub fn save<'a, P: Printer, B: Backend<'a> + ?Sized>(
|
|||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
};
|
};
|
||||||
let msg = Email::from_tpl(&tpl)?.add_attachments(attachments_paths)?;
|
let email = Email::from_tpl(&tpl)?.add_attachments(attachments_paths)?;
|
||||||
let raw_msg = msg.into_sendable_msg(config)?.formatted();
|
let raw_email = email.into_sendable(config)?.formatted();
|
||||||
backend.email_add(mbox, &raw_msg, "seen")?;
|
backend.email_add(mbox, &raw_email, "seen")?;
|
||||||
printer.print_struct("Template successfully saved")
|
printer.print_struct("Template successfully saved")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a message based on a template.
|
/// Sends a message based on a template.
|
||||||
pub fn send<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
pub fn send<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
||||||
mbox: &str,
|
mbox: &str,
|
||||||
account: &AccountConfig,
|
|
||||||
attachments_paths: Vec<&str>,
|
attachments_paths: Vec<&str>,
|
||||||
tpl: &str,
|
tpl: &str,
|
||||||
printer: &mut P,
|
printer: &mut P,
|
||||||
@@ -97,8 +96,8 @@ pub fn send<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
|||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n")
|
.join("\n")
|
||||||
};
|
};
|
||||||
let msg = Email::from_tpl(&tpl)?.add_attachments(attachments_paths)?;
|
let email = Email::from_tpl(&tpl)?.add_attachments(attachments_paths)?;
|
||||||
let sent_msg = sender.send(account, &msg)?;
|
let sent_msg = sender.send(&email)?;
|
||||||
backend.email_add(mbox, &sent_msg, "seen")?;
|
backend.email_add(mbox, &sent_msg, "seen")?;
|
||||||
printer.print_struct("Template successfully sent")
|
printer.print_struct("Template successfully sent")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,7 +302,6 @@ fn main() -> Result<()> {
|
|||||||
Some(tpl::args::Cmd::Send(atts, tpl)) => {
|
Some(tpl::args::Cmd::Send(atts, tpl)) => {
|
||||||
return tpl::handlers::send(
|
return tpl::handlers::send(
|
||||||
&folder,
|
&folder,
|
||||||
&account_config,
|
|
||||||
atts,
|
atts,
|
||||||
tpl,
|
tpl,
|
||||||
&mut printer,
|
&mut printer,
|
||||||
|
|||||||
@@ -37,14 +37,18 @@ pub fn open_with_draft() -> Result<String> {
|
|||||||
open_with_tpl(tpl)
|
open_with_tpl(tpl)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _edit_msg_with_editor(msg: &Email, tpl: TplOverride, config: &AccountConfig) -> Result<Email> {
|
fn _edit_email_with_editor(
|
||||||
let tpl = msg.to_tpl(tpl, config)?;
|
email: &Email,
|
||||||
|
tpl: TplOverride,
|
||||||
|
config: &AccountConfig,
|
||||||
|
) -> Result<Email> {
|
||||||
|
let tpl = email.to_tpl(tpl, config)?;
|
||||||
let tpl = open_with_tpl(tpl)?;
|
let tpl = open_with_tpl(tpl)?;
|
||||||
Email::from_tpl(&tpl).context("cannot parse message from template")
|
Email::from_tpl(&tpl).context("cannot parse email from template")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn edit_msg_with_editor<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
pub fn edit_email_with_editor<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender + ?Sized>(
|
||||||
mut msg: Email,
|
mut email: Email,
|
||||||
tpl: TplOverride,
|
tpl: TplOverride,
|
||||||
config: &AccountConfig,
|
config: &AccountConfig,
|
||||||
printer: &mut P,
|
printer: &mut P,
|
||||||
@@ -60,11 +64,11 @@ pub fn edit_msg_with_editor<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender +
|
|||||||
Ok(choice) => match choice {
|
Ok(choice) => match choice {
|
||||||
PreEditChoice::Edit => {
|
PreEditChoice::Edit => {
|
||||||
let tpl = open_with_draft()?;
|
let tpl = open_with_draft()?;
|
||||||
msg.merge_with(Email::from_tpl(&tpl)?);
|
email.merge_with(Email::from_tpl(&tpl)?);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PreEditChoice::Discard => {
|
PreEditChoice::Discard => {
|
||||||
msg.merge_with(_edit_msg_with_editor(&msg, tpl.clone(), config)?);
|
email.merge_with(_edit_email_with_editor(&email, tpl.clone(), config)?);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PreEditChoice::Quit => return Ok(()),
|
PreEditChoice::Quit => return Ok(()),
|
||||||
@@ -76,35 +80,35 @@ pub fn edit_msg_with_editor<'a, P: Printer, B: Backend<'a> + ?Sized, S: Sender +
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
msg.merge_with(_edit_msg_with_editor(&msg, tpl.clone(), config)?);
|
email.merge_with(_edit_email_with_editor(&email, tpl.clone(), config)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match choice::post_edit() {
|
match choice::post_edit() {
|
||||||
Ok(PostEditChoice::Send) => {
|
Ok(PostEditChoice::Send) => {
|
||||||
printer.print_str("Sending message…")?;
|
printer.print_str("Sending email…")?;
|
||||||
let sent_msg: Vec<u8> = sender.send(config, &msg)?;
|
let sent_email: Vec<u8> = sender.send(&email)?;
|
||||||
let sent_folder = config.folder_alias("sent")?;
|
let sent_folder = config.folder_alias("sent")?;
|
||||||
printer.print_str(format!("Adding message to the {:?} folder…", sent_folder))?;
|
printer.print_str(format!("Adding email to the {:?} folder…", sent_folder))?;
|
||||||
backend.email_add(&sent_folder, &sent_msg, "seen")?;
|
backend.email_add(&sent_folder, &sent_email, "seen")?;
|
||||||
remove_local_draft()?;
|
remove_local_draft()?;
|
||||||
printer.print_struct("Done!")?;
|
printer.print_struct("Done!")?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(PostEditChoice::Edit) => {
|
Ok(PostEditChoice::Edit) => {
|
||||||
msg.merge_with(_edit_msg_with_editor(&msg, tpl.clone(), config)?);
|
email.merge_with(_edit_email_with_editor(&email, tpl.clone(), config)?);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ok(PostEditChoice::LocalDraft) => {
|
Ok(PostEditChoice::LocalDraft) => {
|
||||||
printer.print_struct("Message successfully saved locally")?;
|
printer.print_struct("Email successfully saved locally")?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(PostEditChoice::RemoteDraft) => {
|
Ok(PostEditChoice::RemoteDraft) => {
|
||||||
let tpl = msg.to_tpl(TplOverride::default(), config)?;
|
let tpl = email.to_tpl(TplOverride::default(), config)?;
|
||||||
let draft_folder = config.folder_alias("draft")?;
|
let draft_folder = config.folder_alias("drafts")?;
|
||||||
backend.email_add(&draft_folder, tpl.as_bytes(), "seen draft")?;
|
backend.email_add(&draft_folder, tpl.as_bytes(), "seen draft")?;
|
||||||
remove_local_draft()?;
|
remove_local_draft()?;
|
||||||
printer.print_struct(format!("Message successfully saved to {}", draft_folder))?;
|
printer.print_struct(format!("Email successfully saved to {}", draft_folder))?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Ok(PostEditChoice::Discard) => {
|
Ok(PostEditChoice::Discard) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user