|
@@ -35,7 +35,8 @@ use async_imap_wasi::{Client, Session};
|
|
use async_imap_wasi::extensions::idle::IdleResponse::NewData;
|
|
use async_imap_wasi::extensions::idle::IdleResponse::NewData;
|
|
#[cfg(target_os = "wasi")]
|
|
#[cfg(target_os = "wasi")]
|
|
use async_imap_wasi::types::Uid;
|
|
use async_imap_wasi::types::Uid;
|
|
-use crate::api_broadcast_structure::{EmailRemoved, Message, NewEmail};
|
|
|
|
|
|
+use uuid::Uuid;
|
|
|
|
+use crate::api_broadcast_structure::{EmailRemoved, EmailStartDownload, EmailStopDownload, Message, NewEmail};
|
|
use crate::server::broadcast_message;
|
|
use crate::server::broadcast_message;
|
|
|
|
|
|
/// create TLS connect with the IMAP server
|
|
/// create TLS connect with the IMAP server
|
|
@@ -131,7 +132,15 @@ pub async fn list_imap_folders(session: &mut Session<TlsStream<TcpStream>>) -> a
|
|
|
|
|
|
/// download all emails from one mailbox
|
|
/// 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)>> {
|
|
pub async fn fetch_and_store_emails(session: &mut Session<TlsStream<TcpStream>>, list: String) -> anyhow::Result<Vec<(u32, PathBuf)>> {
|
|
- // TODO send a message to UI about start and end of the download
|
|
|
|
|
|
+ // send a message to UI about start and end of the download
|
|
|
|
+ let broadcast_id = Uuid::new_v4().to_string();
|
|
|
|
+ let message = Message::EmailStartDownload(EmailStartDownload {
|
|
|
|
+ list: list.clone(),
|
|
|
|
+ broadcast_id: broadcast_id.clone().to_string()
|
|
|
|
+ });
|
|
|
|
+ let json_message = serde_json::to_string(&message).unwrap();
|
|
|
|
+ broadcast_message(json_message).await;
|
|
|
|
+
|
|
let out_dir_name = Config::global().out_dir.clone().join(list.clone());
|
|
let out_dir_name = Config::global().out_dir.clone().join(list.clone());
|
|
if !out_dir_name.exists() { create_dir_all(out_dir_name).ok(); }
|
|
if !out_dir_name.exists() { create_dir_all(out_dir_name).ok(); }
|
|
|
|
|
|
@@ -211,6 +220,14 @@ pub async fn fetch_and_store_emails(session: &mut Session<TlsStream<TcpStream>>,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // send a message to UI about start and end of the download
|
|
|
|
+ let message = Message::EmailStopDownload(EmailStopDownload {
|
|
|
|
+ list: list.clone(),
|
|
|
|
+ broadcast_id: broadcast_id.clone().to_string()
|
|
|
|
+ });
|
|
|
|
+ let json_message = serde_json::to_string(&message).unwrap();
|
|
|
|
+ broadcast_message(json_message).await;
|
|
|
|
+
|
|
Ok(stored_paths)
|
|
Ok(stored_paths)
|
|
}
|
|
}
|
|
|
|
|