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; valign: center;
title: "Server Information"; title: "Server Information";
description: "The information the server published on connection"; 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 sieverman::ConnectionInfo;
use tracing::info; use tracing::info;
@ -13,7 +12,13 @@ pub(crate) async fn run(
info!("connecting…"); info!("connecting…");
let future_info = info.connect(); let future_info = info.connect();
info!("waiting for the connection to be established"); 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:"); info!("Fully read the introduction:");
to_frontend_tx to_frontend_tx
@ -22,6 +27,5 @@ pub(crate) async fn run(
)) ))
.await .await
.unwrap(); .unwrap();
Ok(()) Ok(())
} }

View File

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