diff --git a/Cargo.lock b/Cargo.lock
index 7b06de5..6050c83 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -57,19 +57,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-[[package]]
-name = "chrono"
-version = "0.4.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
-dependencies = [
- "libc",
- "num-integer",
- "num-traits",
- "time",
- "winapi",
-]
-
[[package]]
name = "core-foundation"
version = "0.9.1"
@@ -277,15 +264,6 @@ dependencies = [
"wasi",
]
-[[package]]
-name = "hermit-abi"
-version = "0.1.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
-dependencies = [
- "libc",
-]
-
[[package]]
name = "hostname"
version = "0.1.5"
@@ -296,39 +274,6 @@ dependencies = [
"winutil",
]
-[[package]]
-name = "instant"
-version = "0.1.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
-dependencies = [
- "cfg-if",
-]
-
-[[package]]
-name = "irc"
-version = "0.15.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c5510c4c4631e53c57d6b05c44ab8447d1db6beef28fb9d12c4d6a46fad9dfcc"
-dependencies = [
- "chrono",
- "encoding",
- "futures-util",
- "irc-proto",
- "log",
- "native-tls",
- "parking_lot",
- "pin-project",
- "serde",
- "serde_derive",
- "thiserror",
- "tokio",
- "tokio-native-tls",
- "tokio-stream",
- "tokio-util",
- "toml",
-]
-
[[package]]
name = "irc-proto"
version = "0.15.0"
@@ -378,15 +323,6 @@ version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
-[[package]]
-name = "lock_api"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176"
-dependencies = [
- "scopeguard",
-]
-
[[package]]
name = "log"
version = "0.4.14"
@@ -407,31 +343,10 @@ name = "mention_2_mail"
version = "0.1.0"
dependencies = [
"futures",
- "irc",
+ "irc-proto",
"lettre",
- "tokio",
-]
-
-[[package]]
-name = "mio"
-version = "0.7.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956"
-dependencies = [
- "libc",
- "log",
- "miow",
- "ntapi",
- "winapi",
-]
-
-[[package]]
-name = "miow"
-version = "0.3.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
-dependencies = [
- "winapi",
+ "native-tls",
+ "toml",
]
[[package]]
@@ -462,44 +377,6 @@ dependencies = [
"version_check",
]
-[[package]]
-name = "ntapi"
-version = "0.3.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44"
-dependencies = [
- "winapi",
-]
-
-[[package]]
-name = "num-integer"
-version = "0.1.44"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
-dependencies = [
- "autocfg",
- "num-traits",
-]
-
-[[package]]
-name = "num-traits"
-version = "0.2.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
-dependencies = [
- "autocfg",
-]
-
-[[package]]
-name = "num_cpus"
-version = "1.13.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
-dependencies = [
- "hermit-abi",
- "libc",
-]
-
[[package]]
name = "once_cell"
version = "1.7.2"
@@ -539,51 +416,6 @@ dependencies = [
"vcpkg",
]
-[[package]]
-name = "parking_lot"
-version = "0.11.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
-dependencies = [
- "instant",
- "lock_api",
- "parking_lot_core",
-]
-
-[[package]]
-name = "parking_lot_core"
-version = "0.8.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
-dependencies = [
- "cfg-if",
- "instant",
- "libc",
- "redox_syscall",
- "smallvec",
- "winapi",
-]
-
-[[package]]
-name = "pin-project"
-version = "1.0.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4"
-dependencies = [
- "pin-project-internal",
-]
-
-[[package]]
-name = "pin-project-internal"
-version = "1.0.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
[[package]]
name = "pin-project-lite"
version = "0.2.6"
@@ -712,12 +544,6 @@ dependencies = [
"winapi",
]
-[[package]]
-name = "scopeguard"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
-
[[package]]
name = "security-framework"
version = "2.2.0"
@@ -746,9 +572,6 @@ name = "serde"
version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171"
-dependencies = [
- "serde_derive",
-]
[[package]]
name = "serde_derive"
@@ -772,27 +595,12 @@ dependencies = [
"serde",
]
-[[package]]
-name = "signal-hook-registry"
-version = "1.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6"
-dependencies = [
- "libc",
-]
-
[[package]]
name = "slab"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527"
-[[package]]
-name = "smallvec"
-version = "1.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
-
[[package]]
name = "syn"
version = "1.0.70"
@@ -838,16 +646,6 @@ dependencies = [
"syn",
]
-[[package]]
-name = "time"
-version = "0.1.43"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
-dependencies = [
- "libc",
- "winapi",
-]
-
[[package]]
name = "tokio"
version = "1.5.0"
@@ -855,49 +653,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5"
dependencies = [
"autocfg",
- "bytes",
- "libc",
- "memchr",
- "mio",
- "num_cpus",
- "once_cell",
- "parking_lot",
"pin-project-lite",
- "signal-hook-registry",
- "tokio-macros",
- "winapi",
-]
-
-[[package]]
-name = "tokio-macros"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "tokio-native-tls"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
-dependencies = [
- "native-tls",
- "tokio",
-]
-
-[[package]]
-name = "tokio-stream"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e177a5d8c3bf36de9ebe6d58537d8879e964332f93fb3339e43f618c81361af0"
-dependencies = [
- "futures-core",
- "pin-project-lite",
- "tokio",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 368a9cd..4240d07 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,7 +7,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-futures = "0.3.14"
-irc = "0.15.0"
-lettre = "0.9.5"
-tokio = { version = "1.5.0", features = ["full"] }
+futures = "0.3"
+irc-proto = "0.15"
+lettre = "0.9"
+toml = "0.5"
+native-tls = "0.2"
diff --git a/src/main.rs b/src/main.rs
index 4131585..efd072d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,25 +15,90 @@
* along with Mention2Mail. If not, see .
*/
-use std::env::args;
-use irc::client::prelude::*;
-use futures::prelude::*;
-
-#[tokio::main]
-async fn main() -> irc::error::Result<()> {
- let config_path = args().nth(1).expect("no config given");
-
- let mut client = Client::new(config_path).await?;
- let mut stream = client.stream()?;
- client.identify()?;
-
- println!("I'm");
+use std::{
+ format,
+ env::args,
+ path::Path,
+ io::{prelude::*,Read},
+ net::TcpStream,
+};
+use irc_proto;
+use toml::Value;
+use native_tls::{TlsConnector,TlsStream};
+/*
+fn lex_irc_messages(stream: &mut ClientStream) -> irc::error::Result<()> {
while let Some(message) = stream.next().await.transpose()? {
print!("{}", message);
}
- println!("a teapot");
-
Ok(())
}
+
+*/
+
+fn get_config>(config_path: P)
+ -> Result> {
+ let mut config = String::new();
+ std::fs::File::open(config_path)?
+ .read_to_string(&mut config);
+ let mut config = config.parse::()?;
+ if config.get("port") == None {
+ config["port"] = Value::from("6697");
+ }
+ if config.get("tls") == None {
+ if config["port"].as_integer() == Some(194) ||
+ config["port"].as_integer() == Some(6667) {
+ config["tls"] = Value::from(false);
+ }else if config["port"].as_integer() == Some(6696) ||
+ config["port"].as_integer() == Some(6697) {
+ config["tls"] = Value::from(true);
+ }
+ }
+
+ Ok(config)
+}
+
+fn connect_irc (config: &Value) -> Result> {
+ let adress = format!("{}:{}",
+ config["server"].as_str().ok_or("Could not get server adress from config")?,
+ config["port"].as_str().ok_or("Could not get port from config")?
+ );
+ Ok(TcpStream::connect("127.0.0.1:8080")?)
+}
+
+fn connect_irc_tls (config: &Value)
+ -> Result, Box> {
+ let connector = TlsConnector::new().unwrap();
+ let stream = connect_irc(config)?;
+ Ok(connector.connect(config["server"]
+ .as_str()
+ .ok_or("Could not get server adress from config")?,
+ stream)?
+ )
+}
+
+fn main() {
+ let config_path = args().nth(1)
+ .expect("no config given");
+ let config = get_config(config_path).expect("Could not get config");
+
+ // Weird workaround for multitrait dyn pointer
+ // https://github.com/rust-lang/rfcs/issues/2035
+ // would be a charm...
+ trait ReadWrite: Read + Write {}
+ impl ReadWrite for T {}
+ let mut stream: &dyn ReadWrite;
+
+ if config["tls"].as_bool().unwrap() == true {
+ stream = &connect_irc_tls(&config).unwrap();
+ } else {
+ stream = &connect_irc(&config).unwrap();
+ }
+
+ // TODO: Identify with irc server
+ //stream.write(irc_proto.Message{
+ // tags: None,
+ // prefix:
+
+}