|
@@ -1,7 +1,7 @@
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
use std::{io};
|
|
|
use std::convert::TryFrom;
|
|
|
-use std::fs::File;
|
|
|
+use std::fs::{create_dir_all, File};
|
|
|
use std::future::Future;
|
|
|
use std::path::{PathBuf};
|
|
|
use std::io::{BufReader, BufWriter, ErrorKind, Read, Write};
|
|
@@ -104,14 +104,17 @@ pub async fn list_imap_folders(session: &mut Session<TlsStream<TcpStream>>) -> a
|
|
|
|
|
|
/// download all emails from one mailbox
|
|
|
pub async fn fetch_and_store_emails(session: &mut Session<TlsStream<TcpStream>>, list: String) -> anyhow::Result<Vec<(u32, PathBuf)>> {
|
|
|
+ let out_dir_name = Config::global().out_dir.clone().join(list.clone());
|
|
|
+ if !out_dir_name.exists() { create_dir_all(out_dir_name).ok(); }
|
|
|
+
|
|
|
session.select(list.clone()).await?;
|
|
|
|
|
|
// Create directories for maildir
|
|
|
- std::fs::create_dir_all(Config::global().maildir.clone().join(list.clone()).join("new"))
|
|
|
+ create_dir_all(Config::global().maildir.clone().join(list.clone()).join("new"))
|
|
|
.expect(&*("Unable to create 'new' directory in ".to_owned() + &*list.clone()));
|
|
|
- std::fs::create_dir_all(Config::global().maildir.clone().join(list.clone()).join("cur"))
|
|
|
+ create_dir_all(Config::global().maildir.clone().join(list.clone()).join("cur"))
|
|
|
.expect(&*("Unable to create 'cur' directory in ".to_owned() + &*list.clone()));
|
|
|
- std::fs::create_dir_all(Config::global().maildir.clone().join(list.clone()).join("tmp"))
|
|
|
+ create_dir_all(Config::global().maildir.clone().join(list.clone()).join("tmp"))
|
|
|
.expect(&*("Unable to create 'tmp' directory in ".to_owned() + &*list.clone()));
|
|
|
|
|
|
let uids_path = Config::global().maildir.clone().join(".uids.json");
|
|
@@ -144,7 +147,10 @@ pub async fn fetch_and_store_emails(session: &mut Session<TlsStream<TcpStream>>,
|
|
|
if let Some(body) = msg.body() {
|
|
|
let mail_file = store(Config::global().maildir.clone().join(list.clone()), uid.clone().to_string(), "new".to_string(), body, "");
|
|
|
match mail_file {
|
|
|
- Ok(file) => stored_paths.push((uid.to_string().parse().unwrap(), file)),
|
|
|
+ Ok(file) => {
|
|
|
+ // TODO convert and persist html
|
|
|
+ stored_paths.push((uid.to_string().parse().unwrap(), file))
|
|
|
+ },
|
|
|
Err(e) => eprintln!("Failed to store email: {}", e),
|
|
|
}
|
|
|
} else {
|