Compare commits

..

No commits in common. "f5e2be9651388cb062487cd8c9508d6bb1e6e030" and "a667c6d98b4332a5355fcf1239a5b737f8a0c0a8" have entirely different histories.

3 changed files with 51 additions and 54 deletions

View File

@ -33,15 +33,6 @@ Adw.ApplicationWindow window {
valign: center;
title: "Server Information";
description: "The information the server published on connection";
}
Adw.PreferencesGroup credentials {
vexpand: true;
valign: center;
title: "Login Information";
description: "The credentials that will be used to log in.";
Adw.EntryRow{title: "Username:";}
Adw.PasswordEntryRow{title: "Password:";}
}}
}

View File

@ -1,4 +1,3 @@
use anyhow::Context;
use sieverman::ConnectionInfo;
use tracing::info;
@ -13,7 +12,13 @@ pub(crate) async fn run(
info!("connecting…");
let future_info = info.connect();
info!("waiting for the connection to be established");
let mut connected = future_info.await.context("Something went wrong")?;
let mut connected = match future_info.await {
Ok(v) => v,
Err(e) => {
info!("Failed to connect: {:?}", e);
panic!("Something went wrong");
}
};
info!("Fully read the introduction:");
to_frontend_tx
@ -22,6 +27,5 @@ pub(crate) async fn run(
))
.await
.unwrap();
Ok(())
}

View File

@ -1,10 +1,9 @@
use std::{sync::Arc, time::Duration};
use anyhow::Context;
use managesieve::Capabilities;
use thiserror::Error;
use tokio::{
io::{split, AsyncBufReadExt, AsyncWriteExt, BufReader, WriteHalf},
io::{split, AsyncBufReadExt, BufReader, WriteHalf},
net::TcpStream,
sync::Mutex,
};
@ -94,7 +93,7 @@ impl ConnectionInfo {
trace!("Capabilities read: {:#?}", &caps);
Ok(ConnectionConnected {
info: self,
writer: Arc::new(Mutex::new(writer)),
writer: Arc::new(writer),
buffer,
server_settings: caps,
})
@ -105,7 +104,7 @@ impl ConnectionInfo {
pub struct ConnectionConnected {
info: ConnectionInfo,
//reader: Arc<ReadHalf<TlsStream<TcpStream>>>,
writer: Arc<Mutex<WriteHalf<TlsStream<TcpStream>>>>,
writer: Arc<WriteHalf<TlsStream<TcpStream>>>,
buffer: Arc<Mutex<String>>,
//pub join_handle: Arc<JoinHandle<()>>,
server_settings: Capabilities,
@ -131,51 +130,54 @@ impl ConnectionConnected {
pub async fn log_server_settings(&self) {
info!("Serversettings:\n{:?}", self.server_settings)
}
pub async fn list_scripts(self) -> anyhow::Result<(Vec<(String, bool)>, Self)> {
#[tracing::instrument(name = "gettin the intro")]
pub async fn read_introduction(self) -> Result<IsComplete<Self>, anyhow::Error> {
let Self {
info,
//reader: Arc<ReadHalf<TlsStream<TcpStream>>>,
writer,
buffer,
info,
server_settings,
} = self;
let command = managesieve::Command::list_scripts();
writer
.lock()
.await
.write_all(command.to_string().as_bytes())
.await
.context("Failed to write LISTSCRIPTS command")?;
let scriptslist = loop {
let mut buf = buffer.lock().await;
trace!("reading new input:\n{}", buf);
match managesieve::response_listscripts(&buf.to_string()) {
Ok((rest, scriptslist, resp)) => match resp.tag {
managesieve::OkNoBye::Ok => {
buf.clear();
buf.push_str(rest);
info!("Read the introduction");
break scriptslist;
}
managesieve::OkNoBye::No | managesieve::OkNoBye::Bye => {
trace!("Connection closed!");
//panic!("Invalid Response")
}
},
Err(e) => trace!("(temporary) error: {}", e),
}
tokio::time::sleep(Duration::from_millis(50)).await;
};
Ok((
scriptslist,
Self {
writer,
buffer,
let mut bf = buffer.lock().await;
let response = match managesieve::response_capability(&bf.to_string()) {
Ok((rest, capability, response)) => {
info!("Successfully read the introduction {:?}", response);
bf.clear();
bf.push_str(rest);
drop(bf);
Ok(IsComplete::Yes(Self {
info,
writer: writer.clone(),
buffer: buffer.clone(),
server_settings: capability,
}))
}
Err(managesieve::Error::IncompleteResponse) => {
trace!("incomplete introduction");
Ok(IsComplete::No(Self {
info,
writer,
buffer: buffer.clone(),
server_settings,
},
))
}))
}
Err(managesieve::Error::InvalidResponse) => {
error!("invalid response");
Err(managesieve::Error::InvalidResponse)?
}
Err(managesieve::Error::InvalidInput) => {
error!("invalid input");
Err(managesieve::Error::InvalidResponse)?
}
Err(managesieve::Error::MissingLine(line)) => {
error!("a capability line was missing: {:?}", line);
Err(managesieve::Error::InvalidResponse)?
}
};
response
}
pub fn get_greeting(&self) -> String {