Use Context::current_dir() when saving files to relative paths

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/301/head
Manos Pitsidianakis 9 months ago
parent a4f0dbac26
commit 39e99770da
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -701,7 +701,11 @@ pub trait MailListingTrait: ListingTrait {
account.operation(env_hash).and_then(|mut op| op.as_bytes()) account.operation(env_hash).and_then(|mut op| op.as_bytes())
}) })
.collect::<Result<Vec<_>>>(); .collect::<Result<Vec<_>>>();
let mut path_ = path.to_path_buf(); let mut path = path.to_path_buf();
if path.is_relative() {
path = context.current_dir().join(&path);
}
let account = &mut context.accounts[&account_hash];
let format = (*format).unwrap_or_default(); let format = (*format).unwrap_or_default();
let collection = account.collection.clone(); let collection = account.collection.clone();
let (sender, mut receiver) = crate::jobs::oneshot::channel(); let (sender, mut receiver) = crate::jobs::oneshot::channel();
@ -715,16 +719,16 @@ pub trait MailListingTrait: ListingTrait {
.iter() .iter()
.map(|&env_hash| collection.get_env(env_hash)) .map(|&env_hash| collection.get_env(env_hash))
.collect(); .collect();
if path_.is_dir() { if path.is_dir() {
if envs.len() == 1 { if envs.len() == 1 {
path_.push(format!("{}.mbox", envs[0].message_id_raw())); path.push(format!("{}.mbox", envs[0].message_id_raw()));
} else { } else {
let now = datetime::timestamp_to_string( let now = datetime::timestamp_to_string(
datetime::now(), datetime::now(),
Some(datetime::formats::RFC3339_DATETIME), Some(datetime::formats::RFC3339_DATETIME),
false, false,
); );
path_.push(format!( path.push(format!(
"{}-{}-{}_envelopes.mbox", "{}-{}-{}_envelopes.mbox",
now, now,
envs[0].message_id_raw(), envs[0].message_id_raw(),
@ -732,7 +736,7 @@ pub trait MailListingTrait: ListingTrait {
)); ));
} }
} }
let mut file = BufWriter::new(File::create(&path_)?); let mut file = BufWriter::new(File::create(&path)?);
let mut iter = envs.iter().zip(bytes); let mut iter = envs.iter().zip(bytes);
let tags_lck = collection.tag_index.read().unwrap(); let tags_lck = collection.tag_index.read().unwrap();
if let Some((env, ref bytes)) = iter.next() { if let Some((env, ref bytes)) = iter.next() {
@ -770,7 +774,7 @@ pub trait MailListingTrait: ListingTrait {
)?; )?;
} }
file.flush()?; file.flush()?;
Ok(path_) Ok(path)
}; };
let r: Result<PathBuf> = cl.await; let r: Result<PathBuf> = cl.await;
let _ = sender.send(r); let _ = sender.send(r);

@ -1361,6 +1361,9 @@ impl Component for EnvelopeView {
if path.is_dir() { if path.is_dir() {
path.push(format!("{}.eml", self.mail.message_id_raw())); path.push(format!("{}.eml", self.mail.message_id_raw()));
} }
if path.is_relative() {
path = context.current_dir().join(&path);
}
match save_attachment(&path, &self.mail.bytes) { match save_attachment(&path, &self.mail.bytes) {
Err(err) => { Err(err) => {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
@ -1396,6 +1399,9 @@ impl Component for EnvelopeView {
)); ));
} }
} }
if path.is_relative() {
path = context.current_dir().join(&path);
}
match save_attachment(&path, &u.decode(Default::default())) { match save_attachment(&path, &u.decode(Default::default())) {
Err(err) => { Err(err) => {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
@ -1418,6 +1424,9 @@ impl Component for EnvelopeView {
if path.is_dir() { if path.is_dir() {
path.push(format!("{}.eml", self.mail.message_id_raw())); path.push(format!("{}.eml", self.mail.message_id_raw()));
} }
if path.is_relative() {
path = context.current_dir().join(&path);
}
match save_attachment(&path, &self.mail.bytes) { match save_attachment(&path, &self.mail.bytes) {
Err(err) => { Err(err) => {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(

Loading…
Cancel
Save