Add path shell expansion to logging and attachments
parent
e35a93336a
commit
47d60f480a
|
@ -1,11 +1,12 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::backends::BackendOp;
|
use crate::backends::BackendOp;
|
||||||
use crate::email::attachments::AttachmentBuilder;
|
use crate::email::attachments::AttachmentBuilder;
|
||||||
|
use crate::shellexpand::ShellExpandTrait;
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use data_encoding::BASE64_MIME;
|
use data_encoding::BASE64_MIME;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
pub mod mime;
|
pub mod mime;
|
||||||
|
@ -445,12 +446,12 @@ pub fn attachment_from_file<I>(path: &I) -> Result<AttachmentBuilder>
|
||||||
where
|
where
|
||||||
I: AsRef<OsStr>,
|
I: AsRef<OsStr>,
|
||||||
{
|
{
|
||||||
let path: &Path = Path::new(path);
|
let path: PathBuf = Path::new(path).expand();
|
||||||
if !path.is_file() {
|
if !path.is_file() {
|
||||||
return Err(MeliError::new(format!("{} is not a file", path.display())));
|
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();
|
let mut contents = Vec::new();
|
||||||
file.read_to_end(&mut contents)?;
|
file.read_to_end(&mut contents)?;
|
||||||
let mut attachment = AttachmentBuilder::new(b"");
|
let mut attachment = AttachmentBuilder::new(b"");
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use crate::shellexpand::ShellExpandTrait;
|
||||||
use chrono::offset::Local;
|
use chrono::offset::Local;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::{BufWriter, Write};
|
use std::io::{BufWriter, Write};
|
||||||
|
@ -100,6 +101,7 @@ pub fn get_log_level() -> LoggingLevel {
|
||||||
|
|
||||||
pub fn change_log_dest(path: PathBuf) {
|
pub fn change_log_dest(path: PathBuf) {
|
||||||
LOG.with(|f| {
|
LOG.with(|f| {
|
||||||
|
let path = path.expand(); // expand shell stuff
|
||||||
let mut backend = f.lock().unwrap();
|
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 */
|
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.*/
|
.create(true) /* a new file will be created if the file does not yet already exist.*/
|
||||||
|
|
Loading…
Reference in New Issue