diff --git a/imap/src/client/inner.rs b/imap/src/client/inner.rs index 4dcf258..6be5161 100644 --- a/imap/src/client/inner.rs +++ b/imap/src/client/inner.rs @@ -97,9 +97,11 @@ impl<'a, C> Future for ExecHandle<'a, C> { } async fn listen(conn: impl AsyncRead + Unpin) -> Result<()> { + debug!("amogus"); let mut reader = BufReader::new(conn); loop { let mut next_line = String::new(); reader.read_line(&mut next_line).await?; + debug!("line: {:?}", next_line); } } diff --git a/imap/src/client/mod.rs b/imap/src/client/mod.rs index 178e5f9..0012887 100644 --- a/imap/src/client/mod.rs +++ b/imap/src/client/mod.rs @@ -18,6 +18,8 @@ use tokio_rustls::{client::TlsStream, rustls::ClientConfig, webpki::DNSNameRef, use self::inner::Client; +pub type ClientBuilder = ClientNotConnectedBuilder; + /// An IMAP client that hasn't been connected yet. #[derive(Builder, Clone, Debug)] pub struct ClientNotConnected { diff --git a/src/config.rs b/src/config.rs index d60492f..e294fd8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -138,7 +138,16 @@ pub fn spawn_config_watcher_system() -> Result<(JoinHandle<()>, ConfigWatcher)> if !config_home.exists() { fs::create_dir_all(&config_home)?; } - inotify.add_watch(&config_home, WatchMask::all())?; + inotify + .add_watch(&config_home, WatchMask::all()) + .context("adding watch for config home")?; + + let config_file_path = config_home.join("panorama.toml"); + if config_file_path.exists() { + inotify + .add_watch(config_file_path, WatchMask::CLOSE) + .context("adding watch for config file")?; + } debug!("watching {:?}", config_home); let (config_tx, config_update) = watch::channel(Config::default()); diff --git a/src/mail/mod.rs b/src/mail/mod.rs index 1eca111..907d924 100644 --- a/src/mail/mod.rs +++ b/src/mail/mod.rs @@ -5,11 +5,11 @@ mod imap2; use anyhow::Result; use futures::stream::StreamExt; -use panorama_imap::builders::command::Command as ImapCommand; +use panorama_imap::{client::ClientBuilder, command::Command as ImapCommand}; use tokio::{sync::mpsc::UnboundedReceiver, task::JoinHandle}; use tokio_stream::wrappers::WatchStream; -use crate::config::{Config, ConfigWatcher}; +use crate::config::{Config, ConfigWatcher, MailAccountConfig, TlsMethod}; use self::imap2::open_imap_connection; @@ -48,7 +48,8 @@ pub async fn run_mail( let handle = tokio::spawn(async { for acct in config.mail_accounts.into_iter() { debug!("opening imap connection for {:?}", acct); - open_imap_connection(acct.imap).await.unwrap(); + osu(acct).await; + // open_imap_connection(acct.imap).await.unwrap(); } }); @@ -57,3 +58,17 @@ pub async fn run_mail( Ok(()) } + +async fn osu(acct: MailAccountConfig) -> Result<()> { + let builder = ClientBuilder::default() + .hostname(acct.imap.server.clone()) + .port(acct.imap.port) + .tls(matches!(acct.imap.tls, TlsMethod::On)) + .build() + .map_err(|err| anyhow!("err: {}", err))?; + + debug!("connecting to {}:{}", &acct.imap.server, acct.imap.port); + let unauth = builder.connect().await; + + Ok(()) +}