begin loop

This commit is contained in:
Michael Zhang 2021-11-04 06:49:16 -05:00
parent b28d8db39b
commit ac592a9370
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
5 changed files with 44 additions and 23 deletions

View file

@ -37,32 +37,21 @@ use crate::mail::{mail_main, MailStore};
/// The panorama daemon runs in the background and communicates with other
/// panorama components over Unix sockets.
#[derive(Debug, Parser)]
struct Options {
pub struct Options {
/// Config file path (defaults to XDG)
#[clap(long = "config", short = 'c')]
config_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
/// Verbose mode (-v, -vv, -vvv, etc)
#[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
/// arguments.
/// Primary entrypoint; this is the function that is called by main.
///
/// The purpose of this function is to parse command line arguments
/// and set up config watching, then call [`run_with_config`] with the config.
pub async fn run() -> Result<()> {
let opt = Options::parse();
stderrlog::new()
.module(module_path!())
.module("panorama_daemon")
.module("panorama_imap")
.verbosity(opt.verbose)
.init()
.unwrap();
pub async fn run(opt: Options) -> Result<()> {
// if we're using a config-watcher, then start the watcher system
#[cfg(feature = "config-watch")]
{

View file

@ -68,15 +68,15 @@ pub async fn mail_main(
async fn run_sync_loop(mut conn: ClientAuthenticated) -> Result<()> {
// get the list of folders first
debug!(target: "run_sync_loop", "Retrieving folder list...");
debug!("Retrieving folder list...");
let folder_list = conn.list().await?;
debug!("Mailbox list: {:?}", folder_list);
// let _ = mail2ui_tx.send(MailEvent::FolderList(
// acct_name.clone(),
// folder_list.clone(),
// ));
debug!("mailbox list: {:?}", folder_list);
for folder in folder_list.iter() {
debug!("folder: {:?}", folder);
let select = conn.select("INBOX").await?;

View file

@ -1,4 +1,18 @@
use anyhow::Result;
use clap::Parser;
use panorama_daemon::Options;
#[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
}

View file

@ -57,7 +57,12 @@ impl ConfigBuilder {
let hostname = config.hostname.as_ref();
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?;
trace!("connected.");

View file

@ -6,8 +6,9 @@ use tokio::sync::Semaphore;
use crate::{interface::ImapClient, proto::response::Envelope};
use super::client::{ClientAuthenticated, Config};
use super::client::{ClientAuthenticated, Config, ConfigBuilder};
#[derive(Debug)]
pub struct PoolConfig {
pub max_connections: usize,
}
@ -33,6 +34,7 @@ impl ImapClient for ImapPool {
impl ImapPool {
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);
ImapPool(Arc::new(inner))
}
@ -54,12 +56,23 @@ impl InnerPool {
}
pub async fn acquire(&self) -> Result<ClientAuthenticated> {
debug!("Trying to acquire a connection from the pool...");
let guard = match self.connections.pop() {
// we can reuse
Some(conn) => {}
Some(conn) => {
return Ok(conn);
}
// 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!()