commit 0c163e6fa14b8deb11f2fa45632c2e8cca9a9913
parent 9e74817579f981c23d1fc2d6e0d1e02c23b53558
Author: alex wennerberg <alex@alexwennerberg.com>
Date: Wed, 15 Dec 2021 00:24:04 -0800
remove URL dependency
Diffstat:
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -160,7 +160,7 @@ dependencies = [
"pico-args",
"quick-xml",
"sha3",
- "url",
+ "urlencoding",
]
[[package]]
@@ -770,6 +770,12 @@ dependencies = [
]
[[package]]
+name = "urlencoding"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "68b90931029ab9b034b300b797048cf23723400aa757e8a2bfb9d748102f9821"
+
+[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -7,13 +7,13 @@ edition = "2018"
[features]
# Controversial, but HTML email is on by default (highly sanitized).
# Note that HTML emails massively expand the dependency tree
-default = ["html"]
+default = []
html = ["ammonia"]
[dependencies]
ammonia = {version = "3", optional = true}
anyhow = "1.0"
-askama = "0.10"
+askama = {version = "0.10", default_feature = false}
hex = "0.4"
linkify = "0.8.0"
mailparse = "0.13"
@@ -22,4 +22,4 @@ once_cell = "1.9"
pico-args = "0.4.1"
quick-xml = "0.22"
sha3 = "0.10"
-url = "2"
+urlencoding = "2.1.0"
diff --git a/src/main.rs b/src/main.rs
@@ -10,7 +10,7 @@ use sha3::{
use std::collections::HashMap;
use std::fs::OpenOptions;
use std::io::prelude::*;
-use url::Url;
+use urlencoding;
use config::{Config, INSTANCE};
mod config;
@@ -54,12 +54,17 @@ impl Email {
// mailto:... populated with everything you need
pub fn mailto(&self) -> String {
// TODO configurable
- let mut url = Url::parse(&format!("mailto:{}", Config::global().list_email)).unwrap();
- url.query_pairs_mut()
- .append_pair("cc", &self.from.to_string());
- url.query_pairs_mut().append_pair("in-reply-to", &self.id);
- // should get thread subject ideally
- url.query_pairs_mut().append_pair("subject", &self.subject);
+ let mut url = format!("mailto:{}?", Config::global().list_email);
+
+ let from = self.from.to_string();
+ // make sure k is already urlencoded
+ let mut pushencode = |k: &str, v| {
+ url.push_str(&format!("{}={}&", k, urlencoding::encode(v)));
+ };
+ pushencode("cc", &from);
+ pushencode("in-reply-to", &self.id);
+ pushencode("subject", &self.subject); // TODO Re:
+ url.pop();
url.into()
}