mygit

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

commit 6fdcb492097a53d512f37b9347f60ed2dd921985
parent 7214333bfde1bde5f7c8de8dcf2405729328e689
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon, 29 Mar 2021 18:14:18 -0700

Very sipmle listing of email subjects

Diffstat:
Msrc/mail.rs | 34++++++++++++++++++++++++----------
Mtemplates/list-threads.html | 3++-
2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/mail.rs b/src/mail.rs @@ -3,28 +3,42 @@ use askama::Template; use tide::Request; use std::fs; +use std::borrow::Cow; -use mailparse::{parse_mail, ParsedMail}; +use mailparse::{parse_mail, ParsedMail, MailHeaderMap}; /* 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>>, +struct ListThreadsTemplate { + emails: Vec<Email>, +} + +struct Email { + subject: String +} + +impl Email { + fn from_parsed(mail: &ParsedMail) -> Result<Self> { + Ok(Email { + subject: mail.headers.get_first_value("Subject").unwrap() + }) + } } /* 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); + for mail_file in mail_files { + let path = mail_file?.path(); + let bytes = fs::read(path)?; + let parsed = parse_mail(&bytes)?; + // we need to create a struct with relevant owned data + let mail = Email::from_parsed(&parsed)?; + result.push(mail); + } Ok(ListThreadsTemplate { emails: result }.into()) } diff --git a/templates/list-threads.html b/templates/list-threads.html @@ -3,5 +3,6 @@ My Mailing list: all my threads {% for email in emails %} -{{email.get_body().unwrap()}} +<br> +<a href="">{{email.subject}}</a> {% endfor %}