|
@@ -35,6 +35,8 @@ use async_imap_wasi::{Client, Session};
|
|
|
use async_imap_wasi::extensions::idle::IdleResponse::NewData;
|
|
|
#[cfg(target_os = "wasi")]
|
|
|
use async_imap_wasi::types::Uid;
|
|
|
+use crate::api_broadcast_structure::{EmailRemoved, Message, NewEmail};
|
|
|
+use crate::server::broadcast_message;
|
|
|
|
|
|
/// create TLS connect with the IMAP server
|
|
|
pub async fn connect_to_imap() -> anyhow::Result<Client<TlsStream<TcpStream>>>{
|
|
@@ -194,6 +196,12 @@ pub async fn fetch_and_store_emails(session: &mut Session<TlsStream<TcpStream>>,
|
|
|
}
|
|
|
|
|
|
println!("Downloaded message with UID {}", uid.to_string());
|
|
|
+
|
|
|
+ let message = Message::NewEmail(NewEmail {
|
|
|
+ list: list.clone()
|
|
|
+ });
|
|
|
+ let json_message = serde_json::to_string(&message).unwrap();
|
|
|
+ broadcast_message(json_message).await;
|
|
|
} else {
|
|
|
return Err(anyhow!("No message found with the given UID"));
|
|
|
}
|
|
@@ -326,6 +334,12 @@ pub async fn remove_deleted_emails(mailbox: String) -> anyhow::Result<u32> {
|
|
|
Some(message) => delete_email(message.id).await.unwrap()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ let message = Message::EmailRemoved(EmailRemoved {
|
|
|
+ list: mailbox.clone()
|
|
|
+ });
|
|
|
+ let json_message = serde_json::to_string(&message).unwrap();
|
|
|
+ broadcast_message(json_message).await;
|
|
|
|
|
|
Ok(deleted_uids.len() as u32)
|
|
|
}
|
|
@@ -378,9 +392,6 @@ pub fn check_for_updates(mailbox: String) -> JoinHandle<Result<(), anyhow::Error
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Ensure the idle handle is dropped before the next loop iteration
|
|
|
- // idle_handle.await.unwrap();
|
|
|
-
|
|
|
// Reassign session to prevent ownership issues in the next loop iteration
|
|
|
session = idle.done().await.unwrap();
|
|
|
}
|