Compare commits
No commits in common. "f5e2be9651388cb062487cd8c9508d6bb1e6e030" and "a667c6d98b4332a5355fcf1239a5b737f8a0c0a8" have entirely different histories.
f5e2be9651
...
a667c6d98b
@ -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:";}
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
84
src/lib.rs
84
src/lib.rs
@ -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();
|
|
||||||
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;
|
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||||
};
|
let mut bf = buffer.lock().await;
|
||||||
Ok((
|
let response = match managesieve::response_capability(&bf.to_string()) {
|
||||||
scriptslist,
|
Ok((rest, capability, response)) => {
|
||||||
Self {
|
info!("Successfully read the introduction {:?}", response);
|
||||||
writer,
|
bf.clear();
|
||||||
buffer,
|
bf.push_str(rest);
|
||||||
|
drop(bf);
|
||||||
|
Ok(IsComplete::Yes(Self {
|
||||||
info,
|
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,
|
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 {
|
pub fn get_greeting(&self) -> String {
|
||||||
|
Loading…
Reference in New Issue
Block a user