mygit

[UNMAINTAINED] A cgit/webgit alternative, written in Rust
Log | Files | Refs | README | LICENSE

commit 7214333bfde1bde5f7c8de8dcf2405729328e689
parent 0dea21aabc2cc89a294ee1d24ba14c920dd78f58
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 29 Mar 2021 17:32:58 -0700

Begin work on mail archive lister

This basically does nothing so far

Diffstat:
M.gitignore | 1+
MCargo.lock | 46++++++++++++++++++++++++++++++++++++++++++++++
MCargo.toml | 1+
Asrc/mail.rs | 37+++++++++++++++++++++++++++++++++++++
Msrc/main.rs | 2++
Atemplates/list-threads.html | 7+++++++
Mtemplates/tree.html | 2+-
7 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,3 @@ target/ repos/ +mail/ diff --git a/Cargo.lock b/Cargo.lock @@ -368,6 +368,15 @@ checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" [[package]] name = "base64" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +dependencies = [ + "byteorder", +] + +[[package]] +name = "base64" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" @@ -494,6 +503,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] +name = "charset" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f426e64df1c3de26cbf44593c6ffff5dbfd43bbf9de0d075058558126b3fc73" +dependencies = [ + "base64 0.10.1", + "encoding_rs", +] + +[[package]] name = "chrono" version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -679,6 +698,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" [[package]] +name = "encoding_rs" +version = "0.8.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] name = "event-listener" version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1132,6 +1160,17 @@ dependencies = [ ] [[package]] +name = "mailparse" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31de1f9043c582efde7dbd93de56600df12b6c4488a67eeaefa74ea364019b22" +dependencies = [ + "base64 0.12.3", + "charset", + "quoted_printable", +] + +[[package]] name = "matches" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1170,6 +1209,7 @@ dependencies = [ "async-trait", "chrono", "git2", + "mailparse", "once_cell", "percent-encoding", "pico-args", @@ -1415,6 +1455,12 @@ dependencies = [ ] [[package]] +name = "quoted_printable" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b080c5db639b292ac79cbd34be0cfc5d36694768d8341109634d90b86930e2" + +[[package]] name = "radium" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -15,6 +15,7 @@ async-std = { version = "1.8.0", features = ["attributes"] } async-trait = "0.1.48" chrono = "0.4" git2 = {version="0.13", default-features = false} +mailparse = "0.13" once_cell = "1.7.2" percent-encoding = "2.1" pico-args = "0.4" diff --git a/src/mail.rs b/src/mail.rs @@ -0,0 +1,37 @@ +use anyhow::Result; +use askama::Template; +use tide::Request; + +use std::fs; + +use mailparse::{parse_mail, ParsedMail}; +/* Mail related routes */ + +// TODO create a thread object, a collection of references to emails + +#[derive(Template)] +#[template(path = "list-threads.html")] // using the template in this path, relative +struct ListThreadsTemplate<'a> { + emails: Vec<&'a ParsedMail<'a>>, +} +/* This function handles a lot */ +pub async fn list_threads(req: Request<()>) -> tide::Result { + let mut mail_files = fs::read_dir("./mail")?; + let mut result = vec![]; + let test = mail_files.next().unwrap(); + let path = test?.path(); + let bytes = fs::read(path)?; + // Need to figure out out to do this parsing properly. + // parse_mail doesn't own its data + let parsed = parse_mail(&bytes)?; + result.push(&parsed); + Ok(ListThreadsTemplate { emails: result }.into()) +} + +async fn show_thread(req: Request<()>) -> tide::Result { + Ok("".into()) +} + +async fn raw_email(req: Request<()>) -> tide::Result { + Ok("".into()) +} diff --git a/src/main.rs b/src/main.rs @@ -11,6 +11,7 @@ use syntect::parsing::SyntaxSet; use tide::{Request, Response}; mod errorpage; +mod mail; #[derive(Deserialize, Debug)] pub struct Config { @@ -656,6 +657,7 @@ async fn main() -> Result<(), std::io::Error> { app.at("*").all(static_resource); // Raw files, patch files + app.at("/mail").get(mail::list_threads); app.listen(format!("[::]:{}", CONFIG.port)).await?; Ok(()) } diff --git a/templates/list-threads.html b/templates/list-threads.html @@ -0,0 +1,7 @@ +My Mailing list: + +all my threads + +{% for email in emails %} +{{email.get_body().unwrap()}} +{% endfor %} diff --git a/templates/tree.html b/templates/tree.html @@ -2,7 +2,7 @@ {% block content %} {% include "repo-navbar.html" %} - <div> + <div class="main"> {% if path.to_string_lossy() != "" %} <h3>{{path.to_string_lossy()}}/@<a href="/{{repo|repo_name|urlencode_strict}}/tree/{{spec}}">{{spec}}<a></h3> {% else %}