Compare commits
No commits in common. "e7a0e5b66201260e47a67fa86953e3d3ec135d30" and "3a47385be18147cdac47516b6dad07eda769c8a2" have entirely different histories.
e7a0e5b662
...
3a47385be1
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -52,12 +52,6 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
|
||||
|
||||
[[package]]
|
||||
name = "async-stream"
|
||||
version = "0.3.3"
|
||||
@ -1783,13 +1777,6 @@ dependencies = [
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "procmail2notmuch"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "0.6.13"
|
||||
|
||||
@ -3,7 +3,6 @@ members = [
|
||||
"web",
|
||||
"server",
|
||||
"notmuch",
|
||||
"procmail2notmuch",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
||||
2
dev.sh
2
dev.sh
@ -1,6 +1,6 @@
|
||||
tmux new-session -d -s letterbox-dev
|
||||
tmux rename-window web
|
||||
tmux send-keys "cd web; trunk serve --release --address 0.0.0.0 --port 6758 --proxy-backend http://localhost:9345/ --proxy-rewrite=/api/" C-m
|
||||
tmux send-keys "cd web; trunk serve --address 0.0.0.0 --port 6758 --proxy-backend http://localhost:9345/ --proxy-rewrite=/api/" C-m
|
||||
tmux new-window -n server
|
||||
tmux send-keys "cd server; cargo watch -x run" C-m
|
||||
tmux attach -d -t letterbox-dev
|
||||
|
||||
@ -5,11 +5,12 @@ use std::{
|
||||
};
|
||||
|
||||
use itertools::Itertools;
|
||||
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
||||
use rayon::iter::{ParallelBridge, ParallelIterator};
|
||||
|
||||
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
||||
|
||||
#[test]
|
||||
#[ignore] // it is too expensive, run with `cargo test -- --ignored`
|
||||
#[ignore] // it is too expensive
|
||||
fn parse_one() -> Result<(), Box<dyn Error>> {
|
||||
// take_hook() returns the default hook in case when a custom one is not set
|
||||
let orig_hook = std::panic::take_hook();
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
[package]
|
||||
name = "procmail2notmuch"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.69"
|
||||
@ -1,244 +0,0 @@
|
||||
use std::{convert::Infallible, io::Write, str::FromStr};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
enum MatchType {
|
||||
From,
|
||||
Sender,
|
||||
To,
|
||||
Subject,
|
||||
List,
|
||||
DeliveredTo,
|
||||
XForwardedTo,
|
||||
ReplyTo,
|
||||
XOriginalTo,
|
||||
XSpam,
|
||||
Body,
|
||||
#[default]
|
||||
Unknown,
|
||||
}
|
||||
#[derive(Debug, Default)]
|
||||
struct Match {
|
||||
match_type: MatchType,
|
||||
needle: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct Rule {
|
||||
matches: Vec<Match>,
|
||||
tags: Vec<String>,
|
||||
}
|
||||
|
||||
fn unescape(s: &str) -> String {
|
||||
s.replace('\\', "")
|
||||
}
|
||||
|
||||
fn cleanup_match(prefix: &str, s: &str) -> String {
|
||||
unescape(&s[prefix.len()..]).replace(".*", "")
|
||||
}
|
||||
|
||||
mod matches {
|
||||
pub const TO: &'static str = "TO";
|
||||
pub const CC: &'static str = "Cc";
|
||||
pub const TOCC: &'static str = "(TO|Cc)";
|
||||
pub const FROM: &'static str = "From";
|
||||
pub const SENDER: &'static str = "Sender";
|
||||
pub const SUBJECT: &'static str = "Subject";
|
||||
pub const DELIVERED_TO: &'static str = "Delivered-To";
|
||||
pub const X_FORWARDED_TO: &'static str = "X-Forwarded-To";
|
||||
pub const REPLY_TO: &'static str = "Reply-To";
|
||||
pub const X_ORIGINAL_TO: &'static str = "X-Original-To";
|
||||
pub const LIST_ID: &'static str = "List-ID";
|
||||
pub const X_SPAM: &'static str = "X-Spam";
|
||||
pub const X_SPAM_FLAG: &'static str = "X-Spam-Flag";
|
||||
}
|
||||
|
||||
impl FromStr for Match {
|
||||
type Err = Infallible;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// Examples:
|
||||
// "* 1^0 ^TOsonyrewards.com@xinu.tv"
|
||||
// "* ^TOsonyrewards.com@xinu.tv"
|
||||
let mut it = s.split_whitespace().skip(1);
|
||||
let mut needle = it.next().unwrap();
|
||||
if needle == "1^0" {
|
||||
needle = it.next().unwrap();
|
||||
}
|
||||
let mut needle = vec![needle];
|
||||
needle.extend(it);
|
||||
let needle = needle.join(" ");
|
||||
let first = needle.chars().nth(0).unwrap_or(' ');
|
||||
use matches::*;
|
||||
if first == '^' {
|
||||
let needle = &needle[1..];
|
||||
if needle.starts_with(TO) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::To,
|
||||
needle: cleanup_match(TO, needle),
|
||||
});
|
||||
} else if needle.starts_with(FROM) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::From,
|
||||
needle: cleanup_match(FROM, needle),
|
||||
});
|
||||
} else if needle.starts_with(TOCC) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::To,
|
||||
needle: cleanup_match(TOCC, needle),
|
||||
});
|
||||
} else if needle.starts_with(SENDER) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::From,
|
||||
needle: cleanup_match(SENDER, needle),
|
||||
});
|
||||
} else if needle.starts_with(SUBJECT) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::Subject,
|
||||
needle: cleanup_match(SUBJECT, needle),
|
||||
});
|
||||
} else if needle.starts_with(X_ORIGINAL_TO) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::XOriginalTo,
|
||||
needle: cleanup_match(X_ORIGINAL_TO, needle),
|
||||
});
|
||||
} else if needle.starts_with(LIST_ID) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::List,
|
||||
needle: cleanup_match(LIST_ID, needle),
|
||||
});
|
||||
} else if needle.starts_with(REPLY_TO) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::ReplyTo,
|
||||
needle: cleanup_match(REPLY_TO, needle),
|
||||
});
|
||||
} else if needle.starts_with(X_SPAM_FLAG) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::XSpam,
|
||||
needle: '*'.to_string(),
|
||||
});
|
||||
} else if needle.starts_with(X_SPAM) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::XSpam,
|
||||
needle: '*'.to_string(),
|
||||
});
|
||||
} else if needle.starts_with(DELIVERED_TO) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::DeliveredTo,
|
||||
needle: cleanup_match(DELIVERED_TO, needle),
|
||||
});
|
||||
} else if needle.starts_with(X_FORWARDED_TO) {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::XForwardedTo,
|
||||
needle: cleanup_match(X_FORWARDED_TO, needle),
|
||||
});
|
||||
} else {
|
||||
unreachable!("needle: '{needle}'")
|
||||
}
|
||||
} else {
|
||||
return Ok(Match {
|
||||
match_type: MatchType::Body,
|
||||
needle: cleanup_match("", &needle),
|
||||
});
|
||||
}
|
||||
Ok(Match::default())
|
||||
}
|
||||
}
|
||||
|
||||
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 MatchType::Unknown = m.match_type {
|
||||
eprintln!("rule has unknown match {:?}", r);
|
||||
continue;
|
||||
}
|
||||
lines.push(format!(
|
||||
// TODO(wathiede): this assumes `notmuch new` is configured to add
|
||||
// `tag:unprocessed` to all new mail.
|
||||
"-unprocessed +{} -- tag:unprocessed {}{}",
|
||||
t,
|
||||
match m.match_type {
|
||||
MatchType::From => "from:",
|
||||
// TODO(wathiede): something more specific?
|
||||
MatchType::Sender => "from:",
|
||||
MatchType::To => "to:",
|
||||
MatchType::Subject => "subject:",
|
||||
MatchType::List => "List-ID:",
|
||||
MatchType::Body => "",
|
||||
// TODO(wathiede): these will probably require adding fields to notmuch
|
||||
// index. Handle them later.
|
||||
MatchType::DeliveredTo
|
||||
| MatchType::XForwardedTo
|
||||
| MatchType::ReplyTo
|
||||
| MatchType::XOriginalTo
|
||||
| MatchType::XSpam => continue,
|
||||
MatchType::Unknown => unreachable!(),
|
||||
},
|
||||
m.needle
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
lines.sort();
|
||||
for l in lines {
|
||||
writeln!(w, "{l}")?;
|
||||
}
|
||||
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),
|
||||
}
|
||||
}
|
||||
notmuch_from_rules(std::io::stdout(), &rules)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -6,15 +6,13 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="modulepreload" href="/pkg/package.js" as="script" type="text/javascript">
|
||||
<link rel="preload" href="/pkg/package_bg.wasm" as="fetch" type="application/wasm" crossorigin="anonymous">
|
||||
<link rel="stylesheet", href="https://jenil.github.io/bulmaswatch/cyborg/bulmaswatch.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<style>
|
||||
.message {
|
||||
padding-left: 0.5em;
|
||||
}
|
||||
.body {
|
||||
background: white;
|
||||
color: black;
|
||||
padding-bottom: 1em;
|
||||
}
|
||||
.error {
|
||||
@ -58,19 +56,14 @@ iframe {
|
||||
animation-iteration-count: infinite;
|
||||
animation-timing-function: linear;
|
||||
}
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform:rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform:rotate(360deg);
|
||||
}
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.section {
|
||||
padding: 1.5em;
|
||||
}
|
||||
}
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform:rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform:rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||
}
|
||||
};
|
||||
orders.subscribe(|uc: subs::UrlChanged| {
|
||||
info!("uc {}", uc.0);
|
||||
info!("uc {:#?}", uc);
|
||||
});
|
||||
|
||||
info!("init query '{}'", query);
|
||||
@ -110,7 +110,6 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
}
|
||||
|
||||
Msg::SearchRequest(query) => {
|
||||
info!("searching for '{query}'");
|
||||
model.query = query.clone();
|
||||
let url = Url::new().set_hash_path(["s", &query]);
|
||||
orders.request_url(url);
|
||||
@ -281,11 +280,7 @@ fn view_part(part: &Part) -> Node<Msg> {
|
||||
"text/plain" => view_text_plain(&part.content),
|
||||
"text/html" => {
|
||||
if let Some(Content::String(html)) = &part.content {
|
||||
let inliner = css_inline::CSSInliner::options()
|
||||
.load_remote_stylesheets(false)
|
||||
.remove_style_tags(true)
|
||||
.build();
|
||||
let inlined = inliner.inline(html).expect("failed to inline CSS");
|
||||
let inlined = css_inline::inline(html).expect("failed to inline CSS");
|
||||
|
||||
return div![C!["view-part-text-html"], div!["TEST"], raw![&inlined]];
|
||||
} else {
|
||||
@ -356,24 +351,17 @@ fn set_title(title: &str) {
|
||||
seed::document().set_title(&format!("lb: {}", title));
|
||||
}
|
||||
|
||||
fn tags_chiclet(tags: &[String], is_mobile: bool) -> impl Iterator<Item = Node<Msg>> + '_ {
|
||||
tags.iter().map(move |tag| {
|
||||
fn tags_chiclet(tags: &[String]) -> impl Iterator<Item = Node<Msg>> + '_ {
|
||||
tags.iter().map(|tag| {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
tag.hash(&mut hasher);
|
||||
let hex = format!("#{:06x}", hasher.finish() % (1 << 24));
|
||||
let style = style! {St::BackgroundColor=>hex};
|
||||
let classes = C!["tag", IF!(is_mobile => "is-small")];
|
||||
let tag = tag.clone();
|
||||
a![
|
||||
match tag.as_str() {
|
||||
"attachment" => span![classes, style, "📎"],
|
||||
"replied" => span![classes, style, i![C!["fa-solid", "fa-reply"]]],
|
||||
_ => span![classes, style, &tag],
|
||||
},
|
||||
ev(Ev::Click, move |_| Msg::SearchRequest(
|
||||
Url::encode_uri_component(format!("tag:{tag}"))
|
||||
)),
|
||||
]
|
||||
match tag.as_str() {
|
||||
"attachment" => span![C!["tag"], style, "📎"],
|
||||
"replied" => span![C!["tag"], style, i![C!["fa-solid", "fa-reply"]]],
|
||||
_ => span![C!["tag"], style, tag],
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -422,16 +410,11 @@ fn view_mobile_search_results(query: &str, search_results: &SearchSummary) -> No
|
||||
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid)),
|
||||
]
|
||||
*/
|
||||
let tid = r.thread.clone();
|
||||
div![
|
||||
div![
|
||||
C!["subject"],
|
||||
&r.subject,
|
||||
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid)),
|
||||
],
|
||||
p![C!["subject"], &r.subject],
|
||||
div![
|
||||
span![C!["from"], pretty_authors(&r.authors)],
|
||||
span![C!["tags"], tags_chiclet(&r.tags, true)],
|
||||
span![C!["tags"], tags_chiclet(&r.tags)],
|
||||
],
|
||||
span![C!["date"], &r.date_relative],
|
||||
hr![],
|
||||
@ -454,16 +437,9 @@ fn view_search_results(query: &str, search_results: &SearchSummary) -> Node<Msg>
|
||||
pretty_authors(&r.authors),
|
||||
IF!(r.total>1 => small![" ", r.total.to_string()]),
|
||||
],
|
||||
td![
|
||||
C!["subject"],
|
||||
tags_chiclet(&r.tags, false),
|
||||
" ",
|
||||
span![
|
||||
&r.subject,
|
||||
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid))
|
||||
]
|
||||
],
|
||||
td![C!["date"], &r.date_relative]
|
||||
td![C!["subject"], tags_chiclet(&r.tags), " ", &r.subject],
|
||||
td![C!["date"], &r.date_relative],
|
||||
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid)),
|
||||
]
|
||||
});
|
||||
div![table![
|
||||
@ -616,7 +592,7 @@ fn view_mobile(model: &Model) -> Node<Msg> {
|
||||
};
|
||||
div![
|
||||
view_header(&model.query, &model.refreshing_state),
|
||||
section![C!["section"], div![C!["content"], content],]
|
||||
section![C!["section"], div![C!["container"], content],]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user