|
@@ -29,6 +29,7 @@ use async_imap::extensions::idle::IdleResponse::NewData;
|
|
use async_imap_wasi::{Client, Session};
|
|
use async_imap_wasi::{Client, Session};
|
|
#[cfg(target_os = "wasi")]
|
|
#[cfg(target_os = "wasi")]
|
|
use async_imap_wasi::extensions::idle::IdleResponse::NewData;
|
|
use async_imap_wasi::extensions::idle::IdleResponse::NewData;
|
|
|
|
+use crate::indexes::Indexes;
|
|
|
|
|
|
/// create TLS connect with the IMAP server
|
|
/// create TLS connect with the IMAP server
|
|
pub async fn connect_to_imap() -> anyhow::Result<Client<TlsStream<TcpStream>>>{
|
|
pub async fn connect_to_imap() -> anyhow::Result<Client<TlsStream<TcpStream>>>{
|
|
@@ -149,7 +150,18 @@ pub async fn fetch_and_store_emails(session: &mut Session<TlsStream<TcpStream>>,
|
|
match mail_file {
|
|
match mail_file {
|
|
Ok(file) => {
|
|
Ok(file) => {
|
|
// TODO convert and persist html
|
|
// TODO convert and persist html
|
|
- stored_paths.push((uid.to_string().parse().unwrap(), file))
|
|
|
|
|
|
+ // persist to the maildir
|
|
|
|
+ stored_paths.push((uid.to_string().parse().unwrap(), file.clone()));
|
|
|
|
+
|
|
|
|
+ // persist to the output dir
|
|
|
|
+ match add_email(file.clone(), uid.clone()){
|
|
|
|
+ Ok(_) => {}
|
|
|
|
+ Err(_) => {println!("Error adding email from {:?}", file.clone())}
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // TODO adjust indexes
|
|
|
|
+ Indexes::persist_threads().expect("Unable to persist threads");
|
|
|
|
+ Indexes::persist_indexes(vec![list.clone()]).expect("Unable to persist indexes");
|
|
},
|
|
},
|
|
Err(e) => eprintln!("Failed to store email: {}", e),
|
|
Err(e) => eprintln!("Failed to store email: {}", e),
|
|
}
|
|
}
|
|
@@ -323,13 +335,14 @@ pub async fn check_for_updates(mailbox: String) -> anyhow::Result<()> {
|
|
// TODO add more cases like delete, move...
|
|
// TODO add more cases like delete, move...
|
|
NewData(data) => {
|
|
NewData(data) => {
|
|
// TODO do not update all emails (IMAP returns * {number} RECENT) and do it only for one mailbox
|
|
// TODO do not update all emails (IMAP returns * {number} RECENT) and do it only for one mailbox
|
|
- let new_paths = download_email_from_imap().await.expect("Cannot download new emails");
|
|
|
|
- for (uid, path) in new_paths.clone() {
|
|
|
|
- match add_email(path.clone(), uid.clone()){
|
|
|
|
- Ok(_) => {}
|
|
|
|
- Err(_) => {println!("Error adding email from {:?}", path.clone())}
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
|
|
+ // TODO CHANGE IT!!!
|
|
|
|
+ // let new_paths = download_email_from_imap().await.expect("Cannot download new emails");
|
|
|
|
+ // for (uid, path) in new_paths.clone() {
|
|
|
|
+ // match add_email(path.clone(), uid.clone()){
|
|
|
|
+ // Ok(_) => {}
|
|
|
|
+ // Err(_) => {println!("Error adding email from {:?}", path.clone())}
|
|
|
|
+ // };
|
|
|
|
+ // }
|
|
}
|
|
}
|
|
reason => {
|
|
reason => {
|
|
println!("IDLE failed {:?}", reason);
|
|
println!("IDLE failed {:?}", reason);
|