begin loop
This commit is contained in:
parent
b28d8db39b
commit
ac592a9370
5 changed files with 44 additions and 23 deletions
|
@ -37,32 +37,21 @@ use crate::mail::{mail_main, MailStore};
|
||||||
/// The panorama daemon runs in the background and communicates with other
|
/// The panorama daemon runs in the background and communicates with other
|
||||||
/// panorama components over Unix sockets.
|
/// panorama components over Unix sockets.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
struct Options {
|
pub struct Options {
|
||||||
/// Config file path (defaults to XDG)
|
/// Config file path (defaults to XDG)
|
||||||
#[clap(long = "config", short = 'c')]
|
#[clap(long = "config", short = 'c')]
|
||||||
config_file: Option<PathBuf>,
|
pub config_file: Option<PathBuf>,
|
||||||
|
|
||||||
/// Verbose mode (-v, -vv, -vvv, etc)
|
/// Verbose mode (-v, -vv, -vvv, etc)
|
||||||
#[clap(short = 'v', long = "verbose", parse(from_occurrences))]
|
#[clap(short = 'v', long = "verbose", parse(from_occurrences))]
|
||||||
verbose: usize,
|
pub verbose: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Primary entrypoint; this is the function that is called by main with no
|
/// Primary entrypoint; this is the function that is called by main.
|
||||||
/// arguments.
|
|
||||||
///
|
///
|
||||||
/// The purpose of this function is to parse command line arguments
|
/// The purpose of this function is to parse command line arguments
|
||||||
/// and set up config watching, then call [`run_with_config`] with the config.
|
/// and set up config watching, then call [`run_with_config`] with the config.
|
||||||
pub async fn run() -> Result<()> {
|
pub async fn run(opt: Options) -> Result<()> {
|
||||||
let opt = Options::parse();
|
|
||||||
|
|
||||||
stderrlog::new()
|
|
||||||
.module(module_path!())
|
|
||||||
.module("panorama_daemon")
|
|
||||||
.module("panorama_imap")
|
|
||||||
.verbosity(opt.verbose)
|
|
||||||
.init()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// if we're using a config-watcher, then start the watcher system
|
// if we're using a config-watcher, then start the watcher system
|
||||||
#[cfg(feature = "config-watch")]
|
#[cfg(feature = "config-watch")]
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,15 +68,15 @@ pub async fn mail_main(
|
||||||
|
|
||||||
async fn run_sync_loop(mut conn: ClientAuthenticated) -> Result<()> {
|
async fn run_sync_loop(mut conn: ClientAuthenticated) -> Result<()> {
|
||||||
// get the list of folders first
|
// get the list of folders first
|
||||||
debug!(target: "run_sync_loop", "Retrieving folder list...");
|
debug!("Retrieving folder list...");
|
||||||
let folder_list = conn.list().await?;
|
let folder_list = conn.list().await?;
|
||||||
|
debug!("Mailbox list: {:?}", folder_list);
|
||||||
|
|
||||||
// let _ = mail2ui_tx.send(MailEvent::FolderList(
|
// let _ = mail2ui_tx.send(MailEvent::FolderList(
|
||||||
// acct_name.clone(),
|
// acct_name.clone(),
|
||||||
// folder_list.clone(),
|
// folder_list.clone(),
|
||||||
// ));
|
// ));
|
||||||
|
|
||||||
debug!("mailbox list: {:?}", folder_list);
|
|
||||||
for folder in folder_list.iter() {
|
for folder in folder_list.iter() {
|
||||||
debug!("folder: {:?}", folder);
|
debug!("folder: {:?}", folder);
|
||||||
let select = conn.select("INBOX").await?;
|
let select = conn.select("INBOX").await?;
|
||||||
|
|
|
@ -1,4 +1,18 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
|
use panorama_daemon::Options;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> { panorama_daemon::run().await }
|
async fn main() -> Result<()> {
|
||||||
|
let opt = Options::parse();
|
||||||
|
|
||||||
|
stderrlog::new()
|
||||||
|
.module(module_path!())
|
||||||
|
.module("panorama_daemon")
|
||||||
|
.module("panorama_imap")
|
||||||
|
.verbosity(opt.verbose)
|
||||||
|
.init()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
panorama_daemon::run(opt).await
|
||||||
|
}
|
||||||
|
|
|
@ -57,7 +57,12 @@ impl ConfigBuilder {
|
||||||
|
|
||||||
let hostname = config.hostname.as_ref();
|
let hostname = config.hostname.as_ref();
|
||||||
let port = config.port;
|
let port = config.port;
|
||||||
trace!("connecting to {}:{}...", hostname, port);
|
trace!(
|
||||||
|
"connecting to {}:{} {}...",
|
||||||
|
hostname,
|
||||||
|
port,
|
||||||
|
if config.tls { "(encrypted)" } else { "" }
|
||||||
|
);
|
||||||
let conn = TcpStream::connect((hostname, port)).await?;
|
let conn = TcpStream::connect((hostname, port)).await?;
|
||||||
trace!("connected.");
|
trace!("connected.");
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@ use tokio::sync::Semaphore;
|
||||||
|
|
||||||
use crate::{interface::ImapClient, proto::response::Envelope};
|
use crate::{interface::ImapClient, proto::response::Envelope};
|
||||||
|
|
||||||
use super::client::{ClientAuthenticated, Config};
|
use super::client::{ClientAuthenticated, Config, ConfigBuilder};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct PoolConfig {
|
pub struct PoolConfig {
|
||||||
pub max_connections: usize,
|
pub max_connections: usize,
|
||||||
}
|
}
|
||||||
|
@ -33,6 +34,7 @@ impl ImapClient for ImapPool {
|
||||||
|
|
||||||
impl ImapPool {
|
impl ImapPool {
|
||||||
pub fn new(config: Config, pool_config: PoolConfig) -> Self {
|
pub fn new(config: Config, pool_config: PoolConfig) -> Self {
|
||||||
|
debug!("Created new IMAP pool with config {:?}", pool_config);
|
||||||
let inner = InnerPool::init(config, pool_config);
|
let inner = InnerPool::init(config, pool_config);
|
||||||
ImapPool(Arc::new(inner))
|
ImapPool(Arc::new(inner))
|
||||||
}
|
}
|
||||||
|
@ -54,12 +56,23 @@ impl InnerPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn acquire(&self) -> Result<ClientAuthenticated> {
|
pub async fn acquire(&self) -> Result<ClientAuthenticated> {
|
||||||
|
debug!("Trying to acquire a connection from the pool...");
|
||||||
let guard = match self.connections.pop() {
|
let guard = match self.connections.pop() {
|
||||||
// we can reuse
|
// we can reuse
|
||||||
Some(conn) => {}
|
Some(conn) => {
|
||||||
|
return Ok(conn);
|
||||||
|
}
|
||||||
|
|
||||||
// no existing connection, time to make a new one
|
// no existing connection, time to make a new one
|
||||||
None => {}
|
None => {
|
||||||
|
let client = ConfigBuilder::default()
|
||||||
|
.hostname(self.config.hostname.clone())
|
||||||
|
.port(self.config.port)
|
||||||
|
.tls(self.config.tls)
|
||||||
|
.open()
|
||||||
|
.await?;
|
||||||
|
debug!("Client connected to {}", self.config.hostname);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
|
|
Loading…
Reference in a new issue