Compare commits
13 Commits
letterbox-
...
letterbox-
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cec8add5e | |||
| 0225dbde3a | |||
| f84b8fa6c2 | |||
| 979cbcd23e | |||
| b3070e1919 | |||
| e5fdde8f30 | |||
| 7de36bbc3d | |||
| 1c4f27902e | |||
| 7ee86f0d2f | |||
| a0b06fd5ef | |||
| 630bb20b35 | |||
| 17ea2a35cb | |||
| 7d9376d607 |
22
Cargo.lock
generated
22
Cargo.lock
generated
@@ -863,9 +863,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.36"
|
||||
version = "4.5.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2df961d8c8a0d08aa9945718ccf584145eee3f3aa06cddbeac12933781102e04"
|
||||
checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@@ -873,9 +873,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.36"
|
||||
version = "4.5.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "132dbda40fb6753878316a489d5a1242a8ef2f0d9e47ba01c951ea8aa7d013a5"
|
||||
checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@@ -2995,7 +2995,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-notmuch"
|
||||
version = "0.15.7"
|
||||
version = "0.15.11"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"log",
|
||||
@@ -3010,14 +3010,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-procmail2notmuch"
|
||||
version = "0.15.7"
|
||||
version = "0.15.11"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"serde",
|
||||
"sqlx",
|
||||
"tokio 1.44.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-server"
|
||||
version = "0.15.7"
|
||||
version = "0.15.11"
|
||||
dependencies = [
|
||||
"ammonia",
|
||||
"anyhow",
|
||||
@@ -3061,7 +3065,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-shared"
|
||||
version = "0.15.7"
|
||||
version = "0.15.11"
|
||||
dependencies = [
|
||||
"build-info",
|
||||
"letterbox-notmuch",
|
||||
@@ -3071,7 +3075,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "letterbox-web"
|
||||
version = "0.15.7"
|
||||
version = "0.15.11"
|
||||
dependencies = [
|
||||
"build-info",
|
||||
"build-info-build",
|
||||
|
||||
@@ -8,7 +8,7 @@ authors = ["Bill Thiede <git@xinu.tv>"]
|
||||
edition = "2021"
|
||||
license = "UNLICENSED"
|
||||
publish = ["xinu"]
|
||||
version = "0.15.7"
|
||||
version = "0.15.11"
|
||||
repository = "https://git.z.xinu.tv/wathiede/letterbox"
|
||||
|
||||
[profile.dev]
|
||||
|
||||
@@ -12,3 +12,7 @@ version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.69"
|
||||
clap = { version = "4.5.37", features = ["derive", "env"] }
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
sqlx = { version = "0.8.5", features = ["postgres", "runtime-tokio"] }
|
||||
tokio = { version = "1.44.2", features = ["rt", "macros", "rt-multi-thread"] }
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
use std::{convert::Infallible, io::Write, str::FromStr};
|
||||
use std::{collections::HashMap, convert::Infallible, io::Write, str::FromStr};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
use clap::{Parser, Subcommand};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{types::Json, PgPool};
|
||||
|
||||
#[derive(
|
||||
Copy, Clone, Debug, Default, PartialEq, Eq, Hash, Ord, PartialOrd, Serialize, Deserialize,
|
||||
)]
|
||||
enum MatchType {
|
||||
From,
|
||||
Sender,
|
||||
To,
|
||||
Cc,
|
||||
Subject,
|
||||
List,
|
||||
ListId,
|
||||
DeliveredTo,
|
||||
XForwardedTo,
|
||||
ReplyTo,
|
||||
@@ -17,16 +23,17 @@ enum MatchType {
|
||||
#[default]
|
||||
Unknown,
|
||||
}
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
struct Match {
|
||||
match_type: MatchType,
|
||||
needle: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
struct Rule {
|
||||
stop_on_match: bool,
|
||||
matches: Vec<Match>,
|
||||
tags: Vec<String>,
|
||||
tag: Option<String>,
|
||||
}
|
||||
|
||||
fn unescape(s: &str) -> String {
|
||||
@@ -38,6 +45,10 @@ fn cleanup_match(prefix: &str, s: &str) -> String {
|
||||
}
|
||||
|
||||
mod matches {
|
||||
// From https://linux.die.net/man/5/procmailrc
|
||||
// If the regular expression contains '^TO_' it will be substituted by '(^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope |Apparently(-Resent)?)-To):(.*[^-a-zA-Z0-9_.])?)'
|
||||
// If the regular expression contains '^TO' it will be substituted by '(^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope |Apparently(-Resent)?)-To):(.*[^a-zA-Z])?)', which should catch all destination specifications containing a specific word.
|
||||
|
||||
pub const TO: &'static str = "TO";
|
||||
pub const CC: &'static str = "Cc";
|
||||
pub const TOCC: &'static str = "(TO|Cc)";
|
||||
@@ -109,7 +120,7 @@ impl FromStr for Match {
|
||||
});
|
||||
} else if needle.starts_with(LIST_ID) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::List,
|
||||
match_type: MatchType::ListId,
|
||||
needle: cleanup_match(LIST_ID, needle),
|
||||
});
|
||||
} else if needle.starts_with(REPLY_TO) {
|
||||
@@ -149,13 +160,109 @@ impl FromStr for Match {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Mode {
|
||||
Debug,
|
||||
Notmuchrc,
|
||||
LoadSql {
|
||||
#[arg(short, long, default_value = env!("DATABASE_URL"))]
|
||||
dsn: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Simple program to greet a person
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[arg(short, long, default_value = "/home/wathiede/dotfiles/procmailrc")]
|
||||
input: String,
|
||||
|
||||
#[command(subcommand)]
|
||||
mode: Mode,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let args = Args::parse();
|
||||
let mut rules = Vec::new();
|
||||
let mut cur_rule = Rule::default();
|
||||
for l in std::fs::read_to_string(args.input)?.lines() {
|
||||
let l = if let Some(idx) = l.find('#') {
|
||||
&l[..idx]
|
||||
} else {
|
||||
l
|
||||
}
|
||||
.trim();
|
||||
if l.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if l.find('=').is_some() {
|
||||
// Probably a variable assignment, skip line
|
||||
continue;
|
||||
}
|
||||
let first = l.chars().nth(0).unwrap_or(' ');
|
||||
match first {
|
||||
':' => {
|
||||
// start of rule
|
||||
}
|
||||
'*' => {
|
||||
// add to current rule
|
||||
let m: Match = l.parse()?;
|
||||
cur_rule.matches.push(m);
|
||||
}
|
||||
'.' => {
|
||||
// delivery to folder
|
||||
cur_rule.tag = Some(cleanup_match(
|
||||
"",
|
||||
&l.replace('.', "/")
|
||||
.replace(' ', "")
|
||||
.trim_matches('/')
|
||||
.to_string(),
|
||||
));
|
||||
rules.push(cur_rule);
|
||||
cur_rule = Rule::default();
|
||||
}
|
||||
'/' => cur_rule = Rule::default(), // Ex. /dev/null
|
||||
'|' => cur_rule = Rule::default(), // external command
|
||||
'$' => {
|
||||
// TODO(wathiede): tag messages with no other tag as 'inbox'
|
||||
cur_rule.tag = Some(cleanup_match("", "inbox"));
|
||||
rules.push(cur_rule);
|
||||
cur_rule = Rule::default();
|
||||
} // variable, should only be $DEFAULT in my config
|
||||
_ => panic!("Unhandled first character '{}'\nLine: {}", first, l),
|
||||
}
|
||||
}
|
||||
match args.mode {
|
||||
Mode::Debug => print_rules(&rules),
|
||||
Mode::Notmuchrc => notmuch_from_rules(std::io::stdout(), &rules)?,
|
||||
Mode::LoadSql { dsn } => load_sql(&dsn, &rules).await?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_rules(rules: &[Rule]) {
|
||||
let mut tally = HashMap::new();
|
||||
for r in rules {
|
||||
for m in &r.matches {
|
||||
*tally.entry(m.match_type).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
let mut sorted: Vec<_> = tally.iter().map(|(k, v)| (v, k)).collect();
|
||||
sorted.sort();
|
||||
sorted.reverse();
|
||||
for (v, k) in sorted {
|
||||
println!("{k:?}: {v}");
|
||||
}
|
||||
}
|
||||
|
||||
fn notmuch_from_rules<W: Write>(mut w: W, rules: &[Rule]) -> anyhow::Result<()> {
|
||||
// TODO(wathiede): if reindexing this many tags is too slow, see if combining rules per tag is
|
||||
// faster.
|
||||
let mut lines = Vec::new();
|
||||
for r in rules {
|
||||
for m in &r.matches {
|
||||
for t in &r.tags {
|
||||
if let Some(t) = &r.tag {
|
||||
if let MatchType::Unknown = m.match_type {
|
||||
eprintln!("rule has unknown match {:?}", r);
|
||||
continue;
|
||||
@@ -168,7 +275,7 @@ fn notmuch_from_rules<W: Write>(mut w: W, rules: &[Rule]) -> anyhow::Result<()>
|
||||
MatchType::To => "to:",
|
||||
MatchType::Cc => "to:",
|
||||
MatchType::Subject => "subject:",
|
||||
MatchType::List => "List-ID:",
|
||||
MatchType::ListId => "List-ID:",
|
||||
MatchType::Body => "",
|
||||
// TODO(wathiede): these will probably require adding fields to notmuch
|
||||
// index. Handle them later.
|
||||
@@ -200,56 +307,25 @@ fn notmuch_from_rules<W: Write>(mut w: W, rules: &[Rule]) -> anyhow::Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let input = "/home/wathiede/dotfiles/procmailrc";
|
||||
let mut rules = Vec::new();
|
||||
let mut cur_rule = Rule::default();
|
||||
for l in std::fs::read_to_string(input)?.lines() {
|
||||
let l = if let Some(idx) = l.find('#') {
|
||||
&l[..idx]
|
||||
} else {
|
||||
l
|
||||
}
|
||||
.trim();
|
||||
if l.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if l.find('=').is_some() {
|
||||
// Probably a variable assignment, skip line
|
||||
continue;
|
||||
}
|
||||
let first = l.chars().nth(0).unwrap_or(' ');
|
||||
match first {
|
||||
':' => {
|
||||
// start of rule
|
||||
}
|
||||
'*' => {
|
||||
// add to current rule
|
||||
let m: Match = l.parse()?;
|
||||
cur_rule.matches.push(m);
|
||||
}
|
||||
'.' => {
|
||||
// delivery to folder
|
||||
cur_rule.tags.push(cleanup_match(
|
||||
"",
|
||||
&l.replace('.', "/")
|
||||
.replace(' ', "")
|
||||
.trim_matches('/')
|
||||
.to_string(),
|
||||
));
|
||||
rules.push(cur_rule);
|
||||
cur_rule = Rule::default();
|
||||
}
|
||||
'|' => cur_rule = Rule::default(), // external command
|
||||
'$' => {
|
||||
// TODO(wathiede): tag messages with no other tag as 'inbox'
|
||||
cur_rule.tags.push(cleanup_match("", "inbox"));
|
||||
rules.push(cur_rule);
|
||||
cur_rule = Rule::default();
|
||||
} // variable, should only be $DEFAULT in my config
|
||||
_ => panic!("Unhandled first character '{}' {}", first, l),
|
||||
}
|
||||
async fn load_sql(dsn: &str, rules: &[Rule]) -> anyhow::Result<()> {
|
||||
let pool = PgPool::connect(dsn).await?;
|
||||
println!("clearing email_rule table");
|
||||
sqlx::query!("DELETE FROM email_rule")
|
||||
.execute(&pool)
|
||||
.await?;
|
||||
|
||||
for (order, rule) in rules.iter().enumerate() {
|
||||
println!("inserting {order}: {rule:?}");
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO email_rule (sort_order, rule)
|
||||
VALUES ($1, $2)
|
||||
"#,
|
||||
order as i32,
|
||||
Json(rule) as _
|
||||
)
|
||||
.execute(&pool)
|
||||
.await?;
|
||||
}
|
||||
notmuch_from_rules(std::io::stdout(), &rules)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ css-inline = "0.14.0"
|
||||
futures = "0.3.31"
|
||||
headers = "0.4.0"
|
||||
html-escape = "0.2.13"
|
||||
letterbox-notmuch = { version = "0.15.7", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-shared = { version = "0.15.7", path = "../shared", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.15.11", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-shared = { version = "0.15.11", path = "../shared", registry = "xinu" }
|
||||
linkify = "0.10.0"
|
||||
log = "0.4.17"
|
||||
lol_html = "2.0.0"
|
||||
|
||||
3
server/migrations/20250419202131_email-rules.down.sql
Normal file
3
server/migrations/20250419202131_email-rules.down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
DROP TABLE IF NOT EXISTS email_rule;
|
||||
|
||||
-- Add down migration script here
|
||||
5
server/migrations/20250419202131_email-rules.up.sql
Normal file
5
server/migrations/20250419202131_email-rules.up.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS email_rule (
|
||||
id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
|
||||
sort_order integer NOT NULL,
|
||||
rule jsonb NOT NULL
|
||||
);
|
||||
@@ -29,7 +29,7 @@ use serde::Deserialize;
|
||||
use sqlx::postgres::PgPool;
|
||||
use tokio::{net::TcpListener, sync::Mutex};
|
||||
use tower_http::trace::{DefaultMakeSpan, TraceLayer};
|
||||
use tracing::info;
|
||||
use tracing::{info, warn};
|
||||
|
||||
// Make our own error that wraps `anyhow::Error`.
|
||||
struct AppError(letterbox_server::ServerError);
|
||||
@@ -142,6 +142,26 @@ async fn view_cid(
|
||||
Ok(inline_attachment_response(attachment))
|
||||
}
|
||||
|
||||
// TODO make this work with gitea message ids like `wathiede/letterbox/pulls/91@git.z.xinu.tv`
|
||||
async fn view_original(
|
||||
State(AppState { nm, .. }): State<AppState>,
|
||||
extract::Path(id): extract::Path<String>,
|
||||
) -> Result<impl IntoResponse, AppError> {
|
||||
info!("view_original {id}");
|
||||
let mid = if id.starts_with("id:") {
|
||||
id.to_string()
|
||||
} else {
|
||||
format!("id:{}", id)
|
||||
};
|
||||
let files = nm.files(&mid)?;
|
||||
let Some(path) = files.first() else {
|
||||
warn!("failed to find files for message {mid}");
|
||||
return Ok((StatusCode::NOT_FOUND, mid).into_response());
|
||||
};
|
||||
let str = std::fs::read_to_string(&path)?;
|
||||
Ok(str.into_response())
|
||||
}
|
||||
|
||||
async fn graphiql() -> impl IntoResponse {
|
||||
response::Html(
|
||||
GraphiQLSource::build()
|
||||
@@ -260,6 +280,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
get(download_attachment),
|
||||
)
|
||||
.route("/view/attachment/{id}/{idx}/{*rest}", get(view_attachment))
|
||||
.route("/original/{id}", get(view_original))
|
||||
.route("/cid/{id}/{cid}", get(view_cid))
|
||||
.route("/ws", any(start_ws))
|
||||
.route_service("/graphql/ws", GraphQLSubscription::new(schema.clone()))
|
||||
|
||||
@@ -12,6 +12,6 @@ version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
build-info = "0.0.40"
|
||||
letterbox-notmuch = { version = "0.15.7", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.15.11", path = "../notmuch", registry = "xinu" }
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
strum_macros = "0.27.1"
|
||||
|
||||
@@ -20,6 +20,13 @@ pub enum WebsocketMessage {
|
||||
|
||||
pub mod urls {
|
||||
pub const MOUNT_POINT: &'static str = "/api";
|
||||
pub fn view_original(host: Option<&str>, id: &str) -> String {
|
||||
if let Some(host) = host {
|
||||
format!("//{host}/api/original/{id}")
|
||||
} else {
|
||||
format!("/api/original/{id}")
|
||||
}
|
||||
}
|
||||
pub fn cid_prefix(host: Option<&str>, cid: &str) -> String {
|
||||
if let Some(host) = host {
|
||||
format!("//{host}/api/cid/{cid}/")
|
||||
|
||||
@@ -33,8 +33,8 @@ wasm-bindgen = "=0.2.100"
|
||||
uuid = { version = "1.13.1", features = [
|
||||
"js",
|
||||
] } # direct dep to set js feature, prevents Rng issues
|
||||
letterbox-shared = { version = "0.15.7", path = "../shared", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.15.7", path = "../notmuch", registry = "xinu" }
|
||||
letterbox-shared = { version = "0.15.11", path = "../shared", registry = "xinu" }
|
||||
letterbox-notmuch = { version = "0.15.11", path = "../notmuch", registry = "xinu" }
|
||||
seed_hooks = { version = "0.4.0", registry = "xinu" }
|
||||
strum_macros = "0.27.1"
|
||||
gloo-console = "0.3.0"
|
||||
@@ -50,9 +50,10 @@ features = [
|
||||
"Clipboard",
|
||||
"DomRect",
|
||||
"Element",
|
||||
"History",
|
||||
"MediaQueryList",
|
||||
"Navigator",
|
||||
"Window",
|
||||
"History",
|
||||
"Performance",
|
||||
"ScrollRestoration",
|
||||
"Window",
|
||||
]
|
||||
|
||||
@@ -263,81 +263,107 @@ fn search_results(
|
||||
} else {
|
||||
set_title(query);
|
||||
}
|
||||
let rows = results.iter().map(|r| {
|
||||
let tid = r.thread.clone();
|
||||
let check_tid = r.thread.clone();
|
||||
let datetime = human_age(r.timestamp as i64);
|
||||
let unread_idx = r.tags.iter().position(|e| e == &"unread");
|
||||
let mut tags = r.tags.clone();
|
||||
if let Some(idx) = unread_idx {
|
||||
tags.remove(idx);
|
||||
};
|
||||
let is_unread = unread_idx.is_some();
|
||||
let mut title_break = None;
|
||||
const TITLE_LENGTH_WRAP_LIMIT: usize = 40;
|
||||
for w in r.subject.split_whitespace() {
|
||||
if w.len() > TITLE_LENGTH_WRAP_LIMIT {
|
||||
title_break = Some(C!["break-all", "text-pretty"]);
|
||||
let rows: Vec<_> = results
|
||||
.iter()
|
||||
.map(|r| {
|
||||
let tid = r.thread.clone();
|
||||
let check_tid = r.thread.clone();
|
||||
let datetime = human_age(r.timestamp as i64);
|
||||
let unread_idx = r.tags.iter().position(|e| e == &"unread");
|
||||
let mut tags = r.tags.clone();
|
||||
if let Some(idx) = unread_idx {
|
||||
tags.remove(idx);
|
||||
};
|
||||
let is_unread = unread_idx.is_some();
|
||||
let mut title_break = None;
|
||||
const TITLE_LENGTH_WRAP_LIMIT: usize = 40;
|
||||
for w in r.subject.split_whitespace() {
|
||||
if w.len() > TITLE_LENGTH_WRAP_LIMIT {
|
||||
title_break = Some(C!["break-all", "text-pretty"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
div![
|
||||
C![
|
||||
"flex",
|
||||
"flex-nowrap",
|
||||
"w-auto",
|
||||
"flex-auto",
|
||||
"py-4",
|
||||
"border-b",
|
||||
"border-neutral-800"
|
||||
],
|
||||
div![
|
||||
C!["flex", "items-center", "mr-4"],
|
||||
input![
|
||||
C![&tw_classes::CHECKBOX],
|
||||
attrs! {
|
||||
At::Type=>"checkbox",
|
||||
At::Checked=>selected_threads.contains(&tid).as_at_value(),
|
||||
}
|
||||
C![
|
||||
"flex",
|
||||
"flex-nowrap",
|
||||
"w-auto",
|
||||
"flex-auto",
|
||||
"py-4",
|
||||
"border-b",
|
||||
"border-neutral-800"
|
||||
],
|
||||
ev(Ev::Input, move |e| {
|
||||
if let Some(input) = e
|
||||
.target()
|
||||
.as_ref()
|
||||
.expect("failed to get reference to target")
|
||||
.dyn_ref::<web_sys::HtmlInputElement>()
|
||||
{
|
||||
if input.checked() {
|
||||
Msg::SelectionAddThread(check_tid)
|
||||
} else {
|
||||
Msg::SelectionRemoveThread(check_tid)
|
||||
}
|
||||
} else {
|
||||
Msg::Noop
|
||||
}
|
||||
}),
|
||||
],
|
||||
a![
|
||||
C!["flex-grow"],
|
||||
IF!(is_unread => C!["font-bold"]),
|
||||
attrs! {
|
||||
At::Href => urls::thread(&tid)
|
||||
},
|
||||
div![title_break, &r.subject],
|
||||
span![C!["text-xs"], pretty_authors(&r.authors)],
|
||||
div![
|
||||
C!["flex", "flex-wrap", "justify-between"],
|
||||
span![tags_chiclet(&tags)],
|
||||
span![C!["text-sm"], datetime]
|
||||
C!["flex", "items-center", "mr-4"],
|
||||
input![
|
||||
C![&tw_classes::CHECKBOX],
|
||||
attrs! {
|
||||
At::Type=>"checkbox",
|
||||
At::Checked=>selected_threads.contains(&tid).as_at_value(),
|
||||
}
|
||||
],
|
||||
ev(Ev::Input, move |e| {
|
||||
if let Some(input) = e
|
||||
.target()
|
||||
.as_ref()
|
||||
.expect("failed to get reference to target")
|
||||
.dyn_ref::<web_sys::HtmlInputElement>()
|
||||
{
|
||||
if input.checked() {
|
||||
Msg::SelectionAddThread(check_tid)
|
||||
} else {
|
||||
Msg::SelectionRemoveThread(check_tid)
|
||||
}
|
||||
} else {
|
||||
Msg::Noop
|
||||
}
|
||||
}),
|
||||
],
|
||||
a![
|
||||
C!["flex-grow"],
|
||||
IF!(is_unread => C!["font-bold"]),
|
||||
attrs! {
|
||||
At::Href => urls::thread(&tid)
|
||||
},
|
||||
div![title_break, &r.subject],
|
||||
span![C!["text-xs"], pretty_authors(&r.authors)],
|
||||
div![
|
||||
C!["flex", "flex-wrap", "justify-between"],
|
||||
span![tags_chiclet(&tags)],
|
||||
span![C!["text-sm"], datetime]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
});
|
||||
})
|
||||
.collect();
|
||||
let show_bulk_edit = !selected_threads.is_empty();
|
||||
let all_selected = selected_threads.len() == results.len();
|
||||
let all_selected = (selected_threads.len() == results.len()) && !rows.is_empty();
|
||||
let content = if rows.is_empty() {
|
||||
let caught_up = query.contains("is:unread");
|
||||
let read_emoji = ["👻", "👽", "👾", "🤖", "💀"];
|
||||
let no_results_emoji = ["🙈", "👀", "🤦", "🤷", "🙅", "🛟", "🍩", "🌑", "💿", "🔍"];
|
||||
let now = seed::window()
|
||||
.performance()
|
||||
.map(|p| p.now() as usize)
|
||||
.unwrap_or(0);
|
||||
let (emoji, text) = if caught_up {
|
||||
let idx = now % read_emoji.len();
|
||||
(read_emoji[idx], "All caught up!")
|
||||
} else {
|
||||
let idx = now % no_results_emoji.len();
|
||||
(no_results_emoji[idx], "No results")
|
||||
};
|
||||
div![
|
||||
C!["text-center"],
|
||||
h1![C!["text-9xl"], emoji],
|
||||
p![C!["mt-8", "text-3xl", "font-semibold"], text]
|
||||
]
|
||||
} else {
|
||||
div![rows]
|
||||
};
|
||||
div![
|
||||
C!["flex", "flex-col", "flex-auto", "p-4"],
|
||||
search_toolbar(count, pager, show_bulk_edit, all_selected),
|
||||
div![rows],
|
||||
content,
|
||||
search_toolbar(count, pager, show_bulk_edit, all_selected),
|
||||
]
|
||||
}
|
||||
@@ -694,6 +720,8 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
||||
.collect();
|
||||
let show_x_original_to = !*to_xinu.borrow() && msg.x_original_to.is_some();
|
||||
let show_delivered_to = !*to_xinu.borrow() && !show_x_original_to && msg.delivered_to.is_some();
|
||||
let host = seed::window().location().host().expect("couldn't get host");
|
||||
let href = letterbox_shared::urls::view_original(Some(&host), &msg.id);
|
||||
div![
|
||||
C!["flex", "p-4", "bg-neutral-800"],
|
||||
div![avatar],
|
||||
@@ -775,20 +803,36 @@ fn render_open_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Node<
|
||||
C!["text-right"],
|
||||
msg.timestamp
|
||||
.map(|ts| div![C!["text-xs", "text-nowrap"], human_age(ts)]),
|
||||
i![C![
|
||||
"mx-4",
|
||||
"read-status",
|
||||
"far",
|
||||
if is_unread {
|
||||
"fa-envelope"
|
||||
} else {
|
||||
"fa-envelope-open"
|
||||
},
|
||||
]],
|
||||
ev(Ev::Click, move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::SetUnread(id, !is_unread)
|
||||
}),
|
||||
div![
|
||||
C!["p-2"],
|
||||
i![C![
|
||||
"mx-4",
|
||||
"read-status",
|
||||
"far",
|
||||
if is_unread {
|
||||
"fa-envelope"
|
||||
} else {
|
||||
"fa-envelope-open"
|
||||
},
|
||||
]],
|
||||
ev(Ev::Click, move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::SetUnread(id, !is_unread)
|
||||
}),
|
||||
],
|
||||
div![
|
||||
C!["text-xs"],
|
||||
span![a![
|
||||
attrs! {
|
||||
At::Href=>href,
|
||||
At::Target=>"_blank",
|
||||
},
|
||||
"View original",
|
||||
ev(Ev::Click, move |e| {
|
||||
e.stop_propagation();
|
||||
})
|
||||
]]
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -931,20 +975,23 @@ fn render_closed_header(msg: &ShowThreadQueryThreadOnEmailThreadMessages) -> Nod
|
||||
C!["text-right"],
|
||||
msg.timestamp
|
||||
.map(|ts| div![C!["text-xs", "text-nowrap"], human_age(ts)]),
|
||||
i![C![
|
||||
"mx-4",
|
||||
"read-status",
|
||||
"far",
|
||||
if is_unread {
|
||||
"fa-envelope"
|
||||
} else {
|
||||
"fa-envelope-open"
|
||||
},
|
||||
]],
|
||||
ev(Ev::Click, move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::SetUnread(id, !is_unread)
|
||||
}),
|
||||
div![
|
||||
C!["p-2"],
|
||||
i![C![
|
||||
"mx-4",
|
||||
"read-status",
|
||||
"far",
|
||||
if is_unread {
|
||||
"fa-envelope"
|
||||
} else {
|
||||
"fa-envelope-open"
|
||||
},
|
||||
]],
|
||||
ev(Ev::Click, move |e| {
|
||||
e.stop_propagation();
|
||||
Msg::SetUnread(id, !is_unread)
|
||||
})
|
||||
],
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -977,7 +1024,7 @@ fn message_render(msg: &ShowThreadQueryThreadOnEmailThreadMessages, open: bool)
|
||||
],
|
||||
IF!(open =>
|
||||
div![
|
||||
C!["bg-white", "text-black", "p-4", "min-w-full", "w-0","overflow-x-auto", from],
|
||||
C!["content", "bg-white", "text-black", "p-4", "min-w-full", "w-0","overflow-x-auto", from],
|
||||
match &msg.body {
|
||||
ShowThreadQueryThreadOnEmailThreadMessagesBody::UnhandledContentType(
|
||||
ShowThreadQueryThreadOnEmailThreadMessagesBodyOnUnhandledContentType { contents ,content_tree},
|
||||
@@ -1081,7 +1128,6 @@ fn render_attachements(
|
||||
]
|
||||
}
|
||||
|
||||
// TODO: add cathup_mode:bool and hide elements when true
|
||||
#[topo::nested]
|
||||
fn thread(
|
||||
thread: &ShowThreadQueryThreadOnEmailThread,
|
||||
@@ -1172,13 +1218,7 @@ fn thread(
|
||||
el_ref(content_el),
|
||||
messages,
|
||||
IF!(!catchup_mode => click_to_top())
|
||||
],
|
||||
/* TODO(wathiede): plumb in orignal id
|
||||
a![
|
||||
attrs! {At::Href=>api::original(&thread_node.0.as_ref().expect("message missing").id)},
|
||||
"Original"
|
||||
],
|
||||
*/
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -2,23 +2,23 @@ html {
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
.mail-thread a,
|
||||
.mail-thread .content a,
|
||||
.news-post a {
|
||||
color: var(--color-link) !important;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.mail-thread br,
|
||||
.mail-thread .content br,
|
||||
.news-post br {
|
||||
display: block;
|
||||
margin-top: 1em;
|
||||
content: " ";
|
||||
}
|
||||
|
||||
.mail-thread h1,
|
||||
.mail-thread h2,
|
||||
.mail-thread h3,
|
||||
.mail-thread h4,
|
||||
.mail-thread .content h1,
|
||||
.mail-thread .content h2,
|
||||
.mail-thread .content h3,
|
||||
.mail-thread .content h4,
|
||||
.news-post h1,
|
||||
.news-post h2,
|
||||
.news-post h3,
|
||||
@@ -27,12 +27,12 @@ html {
|
||||
margin-bottom: 1em !important;
|
||||
}
|
||||
|
||||
.mail-thread p,
|
||||
.mail-thread .content p,
|
||||
.news-post p {
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.mail-thread pre,
|
||||
.mail-thread .content pre,
|
||||
.news-post pre {
|
||||
font-family: monospace;
|
||||
background-color: #eee !important;
|
||||
@@ -40,28 +40,28 @@ html {
|
||||
white-space: break-spaces;
|
||||
}
|
||||
|
||||
.mail-thread code,
|
||||
.mail-thread .content code,
|
||||
.news-post code {
|
||||
font-family: monospace;
|
||||
white-space: break-spaces;
|
||||
background-color: #eee !important;
|
||||
}
|
||||
|
||||
.mail-thread blockquote {
|
||||
.mail-thread .content blockquote {
|
||||
padding-left: 1em;
|
||||
border-left: 2px solid #ddd;
|
||||
}
|
||||
|
||||
.mail-thread ol,
|
||||
.mail-thread ul {
|
||||
.mail-thread .content ol,
|
||||
.mail-thread .content ul {
|
||||
margin-left: 2em;
|
||||
}
|
||||
|
||||
.mail-thread .noreply-news-bloomberg-com a {
|
||||
.mail-thread .content .noreply-news-bloomberg-com a {
|
||||
background-color: initial !important;
|
||||
}
|
||||
|
||||
.mail-thread .noreply-news-bloomberg-com h2 {
|
||||
.mail-thread .content .noreply-news-bloomberg-com h2 {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user