This commit is contained in:
Michael Zhang 2021-02-19 23:24:46 -06:00
parent 921e4b02d1
commit a53f6d7e28
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
4 changed files with 32 additions and 4 deletions

View file

@ -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);
}
}

View file

@ -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 {

View file

@ -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());

View file

@ -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(())
}