aboutsummaryrefslogtreecommitdiff
path: root/src/server.rs
blob: 8a9b7a356804118c8f54c4b62f2a2a083d459ce7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use anyhow::Result;
use std::sync::Arc;

use crate::config::*;
use crate::instance;
use crate::mailstore;

use boitalettres::server::accept::addr::AddrIncoming;
use boitalettres::server::Server as ImapServer;

pub struct Server {
    pub incoming: AddrIncoming,
    pub mailstore: Arc<mailstore::Mailstore>,
}
impl Server {
    pub async fn new(config: Config) -> Result<Self> {
        Ok(Self {
            incoming: AddrIncoming::new("127.0.0.1:4567").await?,
            mailstore: mailstore::Mailstore::new(config)?,
        })
    }

    pub async fn run(self: Self) -> Result<()> {
        tracing::info!("Starting server on {:#}", self.incoming.local_addr);

        let creds = self
            .mailstore
            .login_provider
            .login("quentin", "poupou")
            .await?;
        //let mut mailbox = Mailbox::new(&creds, "TestMailbox".to_string()).await?;
        //mailbox.test().await?;

        let server =
            ImapServer::new(self.incoming).serve(instance::Instance::new(self.mailstore.clone()));
        let _ = server.await?;

        Ok(())
    }
}