mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
fix panic when downloads-dir does not exist (#100)
This commit is contained in:
parent
33185dba86
commit
2f018889e0
|
@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Save msg upon error [#59]
|
- Save msg upon error [#59]
|
||||||
|
- Answered flag not set [#50]
|
||||||
|
- Panic when downloads-dir does not exist [#100]
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -154,6 +156,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
[#39]: https://github.com/soywod/himalaya/issues/39
|
[#39]: https://github.com/soywod/himalaya/issues/39
|
||||||
[#40]: https://github.com/soywod/himalaya/issues/40
|
[#40]: https://github.com/soywod/himalaya/issues/40
|
||||||
[#41]: https://github.com/soywod/himalaya/issues/41
|
[#41]: https://github.com/soywod/himalaya/issues/41
|
||||||
|
[#50]: https://github.com/soywod/himalaya/issues/50
|
||||||
[#58]: https://github.com/soywod/himalaya/issues/58
|
[#58]: https://github.com/soywod/himalaya/issues/58
|
||||||
[#59]: https://github.com/soywod/himalaya/issues/59
|
[#59]: https://github.com/soywod/himalaya/issues/59
|
||||||
[#61]: https://github.com/soywod/himalaya/issues/61
|
[#61]: https://github.com/soywod/himalaya/issues/61
|
||||||
|
@ -164,3 +167,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
[#83]: https://github.com/soywod/himalaya/issues/83
|
[#83]: https://github.com/soywod/himalaya/issues/83
|
||||||
[#87]: https://github.com/soywod/himalaya/issues/87
|
[#87]: https://github.com/soywod/himalaya/issues/87
|
||||||
[#89]: https://github.com/soywod/himalaya/issues/89
|
[#89]: https://github.com/soywod/himalaya/issues/89
|
||||||
|
[#100]: https://github.com/soywod/himalaya/issues/100
|
||||||
|
|
|
@ -160,15 +160,12 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downloads_filepath(&self, account: &Account, filename: &str) -> PathBuf {
|
pub fn downloads_filepath(&self, account: &Account, filename: &str) -> PathBuf {
|
||||||
let temp_dir = env::temp_dir();
|
account
|
||||||
let mut full_path = account
|
|
||||||
.downloads_dir
|
.downloads_dir
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or(self.downloads_dir.as_ref().unwrap_or(&temp_dir))
|
.unwrap_or(self.downloads_dir.as_ref().unwrap_or(&env::temp_dir()))
|
||||||
.to_owned();
|
.to_owned()
|
||||||
|
.join(filename)
|
||||||
full_path.push(filename);
|
|
||||||
full_path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn address(&self, account: &Account) -> String {
|
pub fn address(&self, account: &Account) -> String {
|
||||||
|
|
|
@ -258,24 +258,25 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(matches) = matches.subcommand_matches("attachments") {
|
if let Some(matches) = matches.subcommand_matches("attachments") {
|
||||||
debug!("Subcommand matched: attachments");
|
debug!("[msg::cli] subcommand matched: attachments");
|
||||||
|
|
||||||
let mut imap_conn = ImapConnector::new(&account)?;
|
let mut imap_conn = ImapConnector::new(&account)?;
|
||||||
let uid = matches.value_of("uid").unwrap();
|
let uid = matches.value_of("uid").unwrap();
|
||||||
debug!("UID: {}", &uid);
|
debug!("[msg::cli] uid: {}", &uid);
|
||||||
|
|
||||||
let msg = imap_conn.read_msg(&mbox, &uid)?;
|
let msg = imap_conn.read_msg(&mbox, &uid)?;
|
||||||
let attachments = Attachments::from_bytes(&msg)?;
|
let attachments = Attachments::from_bytes(&msg)?;
|
||||||
debug!(
|
debug!(
|
||||||
"{} attachment(s) found for message {}",
|
"[msg::cli] {} attachment(s) found for message {}",
|
||||||
&attachments.0.len(),
|
&attachments.0.len(),
|
||||||
&uid
|
&uid
|
||||||
);
|
);
|
||||||
attachments.0.iter().for_each(|attachment| {
|
for attachment in attachments.0.iter() {
|
||||||
let filepath = config.downloads_filepath(&account, &attachment.filename);
|
let filepath = config.downloads_filepath(&account, &attachment.filename);
|
||||||
debug!("Downloading {}…", &attachment.filename);
|
debug!("[msg::cli] downloading {}…", &attachment.filename);
|
||||||
fs::write(filepath, &attachment.raw).unwrap()
|
fs::write(&filepath, &attachment.raw)
|
||||||
});
|
.chain_err(|| format!("Could not save attachment {:?}", filepath))?;
|
||||||
|
}
|
||||||
info!(&format!(
|
info!(&format!(
|
||||||
"{} attachment(s) successfully downloaded",
|
"{} attachment(s) successfully downloaded",
|
||||||
&attachments.0.len()
|
&attachments.0.len()
|
||||||
|
|
Loading…
Reference in a new issue