summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-28 11:53:39 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-28 12:19:22 +0300
commit47d60f480abe3827f66d59ae464867a228c58446 (patch)
treef65c1dd0000ac91381321e5cfaae19548511ccf4
parente35a93336a2c0ce081cd05f64986c6f6cdc59077 (diff)
Add path shell expansion to logging and attachments
-rw-r--r--melib/src/email/compose.rs7
-rw-r--r--melib/src/logging.rs2
2 files changed, 6 insertions, 3 deletions
diff --git a/melib/src/email/compose.rs b/melib/src/email/compose.rs
index c78c6ce4..58b583d8 100644
--- a/melib/src/email/compose.rs
+++ b/melib/src/email/compose.rs
@@ -1,11 +1,12 @@
use super::*;
use crate::backends::BackendOp;
use crate::email::attachments::AttachmentBuilder;
+use crate::shellexpand::ShellExpandTrait;
use chrono::{DateTime, Local};
use data_encoding::BASE64_MIME;
use std::ffi::OsStr;
use std::io::Read;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use std::str;
pub mod mime;
@@ -445,12 +446,12 @@ pub fn attachment_from_file<I>(path: &I) -> Result<AttachmentBuilder>
where
I: AsRef<OsStr>,
{
- let path: &Path = Path::new(path);
+ let path: PathBuf = Path::new(path).expand();
if !path.is_file() {
return Err(MeliError::new(format!("{} is not a file", path.display())));
}
- let mut file = std::fs::File::open(path)?;
+ let mut file = std::fs::File::open(&path)?;
let mut contents = Vec::new();
file.read_to_end(&mut contents)?;
let mut attachment = AttachmentBuilder::new(b"");
diff --git a/melib/src/logging.rs b/melib/src/logging.rs
index b3657ba6..37985516 100644
--- a/melib/src/logging.rs
+++ b/melib/src/logging.rs
@@ -19,6 +19,7 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
+use crate::shellexpand::ShellExpandTrait;
use chrono::offset::Local;
use std::fs::OpenOptions;
use std::io::{BufWriter, Write};
@@ -100,6 +101,7 @@ pub fn get_log_level() -> LoggingLevel {
pub fn change_log_dest(path: PathBuf) {
LOG.with(|f| {
+ let path = path.expand(); // expand shell stuff
let mut backend = f.lock().unwrap();
backend.dest = BufWriter::new(OpenOptions::new().append(true) /* writes will append to a file instead of overwriting previous contents */
.create(true) /* a new file will be created if the file does not yet already exist.*/