replace xxx-folder config props by mailboxes

This commit is contained in:
Clément DOUIN
2022-02-25 21:56:48 +01:00
parent 34ab0f4fa5
commit b855c44508
8 changed files with 56 additions and 57 deletions
+14 -7
View File
@@ -10,7 +10,7 @@ use uuid::Uuid;
use crate::{
backends::Backend,
config::{AccountConfig, DEFAULT_SIG_DELIM},
config::{AccountConfig, DEFAULT_DRAFT_FOLDER, DEFAULT_SENT_FOLDER, DEFAULT_SIG_DELIM},
msg::{
from_addrs_to_sendable_addrs, from_addrs_to_sendable_mbox, from_slice_to_addrs, msg_utils,
Addrs, BinaryPart, Part, Parts, TextPlainPart, TplOverride,
@@ -340,7 +340,12 @@ impl Msg {
match choice::post_edit() {
Ok(PostEditChoice::Send) => {
let sent_msg = smtp.send_msg(account, &self)?;
backend.add_msg(&account.sent_folder, &sent_msg.formatted(), "seen")?;
let sent_folder = account
.mailboxes
.get("sent")
.map(|s| s.as_str())
.unwrap_or(DEFAULT_SENT_FOLDER);
backend.add_msg(&sent_folder, &sent_msg.formatted(), "seen")?;
msg_utils::remove_local_draft()?;
printer.print("Message successfully sent")?;
break;
@@ -355,12 +360,14 @@ impl Msg {
}
Ok(PostEditChoice::RemoteDraft) => {
let tpl = self.to_tpl(TplOverride::default(), account)?;
backend.add_msg(&account.draft_folder, tpl.as_bytes(), "seen draft")?;
let draft_folder = account
.mailboxes
.get("draft")
.map(|s| s.as_str())
.unwrap_or(DEFAULT_DRAFT_FOLDER);
backend.add_msg(&draft_folder, tpl.as_bytes(), "seen draft")?;
msg_utils::remove_local_draft()?;
printer.print(format!(
"Message successfully saved to {}",
account.draft_folder
))?;
printer.print(format!("Message successfully saved to {}", draft_folder))?;
break;
}
Ok(PostEditChoice::Discard) => {
+9 -3
View File
@@ -16,7 +16,7 @@ use url::Url;
use crate::{
backends::Backend,
config::AccountConfig,
config::{AccountConfig, DEFAULT_SENT_FOLDER},
msg::{Msg, Part, Parts, TextPlainPart},
output::{PrintTableOpts, PrinterService},
smtp::SmtpService,
@@ -312,6 +312,13 @@ pub fn send<'a, P: PrinterService, B: Backend<'a> + ?Sized, S: SmtpService>(
let is_json = printer.is_json();
debug!("is json: {}", is_json);
let sent_folder = config
.mailboxes
.get("sent")
.map(|s| s.as_str())
.unwrap_or(DEFAULT_SENT_FOLDER);
debug!("sent folder: {:?}", sent_folder);
let raw_msg = if is_tty || is_json {
raw_msg.replace("\r", "").replace("\n", "\r\n")
} else {
@@ -325,9 +332,8 @@ pub fn send<'a, P: PrinterService, B: Backend<'a> + ?Sized, S: SmtpService>(
trace!("raw message: {:?}", raw_msg);
let envelope: lettre::address::Envelope = Msg::from_tpl(&raw_msg)?.try_into()?;
trace!("envelope: {:?}", envelope);
smtp.send_raw_msg(&envelope, raw_msg.as_bytes())?;
backend.add_msg(&config.sent_folder, raw_msg.as_bytes(), "seen")?;
backend.add_msg(&sent_folder, raw_msg.as_bytes(), "seen")?;
Ok(())
}