2022-06-03 15:26:25 +00:00
|
|
|
use anyhow::Result;
|
2022-05-19 12:33:49 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use crate::config::*;
|
2022-06-07 10:38:59 +00:00
|
|
|
use crate::service;
|
2022-06-03 15:37:39 +00:00
|
|
|
use crate::mailstore;
|
2022-05-19 12:33:49 +00:00
|
|
|
|
2022-06-03 15:26:25 +00:00
|
|
|
use boitalettres::server::accept::addr::AddrIncoming;
|
2022-06-01 16:00:56 +00:00
|
|
|
use boitalettres::server::Server as ImapServer;
|
|
|
|
|
2022-06-03 09:38:01 +00:00
|
|
|
pub struct Server {
|
|
|
|
pub incoming: AddrIncoming,
|
2022-06-03 15:26:25 +00:00
|
|
|
pub mailstore: Arc<mailstore::Mailstore>,
|
2022-06-03 09:38:01 +00:00
|
|
|
}
|
|
|
|
impl Server {
|
|
|
|
pub async fn new(config: Config) -> Result<Self> {
|
2022-06-03 15:37:39 +00:00
|
|
|
Ok(Self {
|
2022-06-03 09:38:01 +00:00
|
|
|
incoming: AddrIncoming::new("127.0.0.1:4567").await?,
|
2022-06-03 15:26:25 +00:00
|
|
|
mailstore: mailstore::Mailstore::new(config)?,
|
2022-06-03 09:38:01 +00:00
|
|
|
})
|
|
|
|
}
|
2022-06-01 16:00:56 +00:00
|
|
|
|
2022-06-03 09:38:01 +00:00
|
|
|
pub async fn run(self: Self) -> Result<()> {
|
2022-06-03 10:26:51 +00:00
|
|
|
tracing::info!("Starting server on {:#}", self.incoming.local_addr);
|
2022-06-03 12:11:00 +00:00
|
|
|
|
2022-06-03 18:45:14 +00:00
|
|
|
/*let creds = self
|
2022-06-03 15:37:39 +00:00
|
|
|
.mailstore
|
|
|
|
.login_provider
|
|
|
|
.login("quentin", "poupou")
|
2022-06-03 18:45:14 +00:00
|
|
|
.await?;*/
|
2022-06-03 12:23:34 +00:00
|
|
|
//let mut mailbox = Mailbox::new(&creds, "TestMailbox".to_string()).await?;
|
|
|
|
//mailbox.test().await?;
|
2022-06-03 12:11:00 +00:00
|
|
|
|
2022-06-03 15:37:39 +00:00
|
|
|
let server =
|
2022-06-07 10:38:59 +00:00
|
|
|
ImapServer::new(self.incoming).serve(service::Instance::new(self.mailstore.clone()));
|
2022-06-01 16:00:56 +00:00
|
|
|
let _ = server.await?;
|
|
|
|
|
2022-05-19 12:33:49 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|